diff --git a/lib/App/serva/servaModBusManager.cpp b/lib/App/serva/servaModBusManager.cpp index ec7c4889..e58e7ce1 100644 --- a/lib/App/serva/servaModBusManager.cpp +++ b/lib/App/serva/servaModBusManager.cpp @@ -594,37 +594,86 @@ bool servaModBusManager::dispatchEvent( EVENT_CONTAINER *Evt ){ if ( Evt == NULL ) return false; switch ( Evt->m_eType ) { case EVT_SRV_SESSION_STARTED:{ + LOG("EVT Session Start"); if( m_sManagerData.automaticAlarmRisingTO ) { //setup Schedule - SCADA_TRACK_INFO *tData = m_pDBC->getTrackSCADA( Evt->m_nSourceNodeID ); - if ( tData ) { - //MODBUS_RTU_INFO *tRTU = m_pDBC->getModBusRTU_Platform( tData->platform_id ); - DBC_UINT64_LIST *tIDS = m_pDBC->listPlatformModBusRTU( tData->platform_id ); - if ( tIDS ) { - for ( DBC_UINT64_LIST::iterator idx=tIDS->begin(); idx != tIDS->end(); idx++ ) { - MODBUS_RTU_INFO *tRTU = m_pDBC->getModBusRTU( *idx ); - if ( tRTU ) { - MODBUS_ACION_ITEM *tAI = (MODBUS_ACION_ITEM *)malloc(sizeof(MODBUS_ACION_ITEM)); - if ( tAI ) { - memset( tAI, 0, sizeof(MODBUS_ACION_ITEM) ); - tAI->scheduled_on = getMilliseconds() + ( m_sManagerData.automaticAlarmRisingTO * 1000 ); - tAI->module_id = tRTU->id; - tAI->value = ( 1 << tRTU->crossbar[((tData->side == 'U')?MBUS_CROSSBAR_UPPER_TRACK:MBUS_CROSSBAR_BOTTOM_TRACK)] ); - m_mProtector.lock(); - m_vActioItems.push_back( tAI ); - m_mProtector.unlock(); + LOG("Setup Scheduled Signal"); + SERVA_SESSION_EVT_DATA *tSData = (SERVA_SESSION_EVT_DATA *)Evt->m_pEvtData; + if( tSData ) { + LOG("Have Session Evt Data"); + SCADA_TRACK_INFO *tData = m_pDBC->getTrackSCADA(Evt->m_nSourceNodeID); + if ( tData ) { + LOG("Have Track Info"); + //MODBUS_RTU_INFO *tRTU = m_pDBC->getModBusRTU_Platform( tData->platform_id ); + uint8_t expected_module_functionality = 0; + if ( tSData->side == 'L' || tSData->side == 'B' ) { + expected_module_functionality |= 1; + }; + if ( tSData->side == 'R' || tSData->side == 'B' ) { + expected_module_functionality |= 2; + }; + if ( expected_module_functionality ) { + LOG("Expect Module Function"); + }; + DBC_UINT64_LIST *tIDS = m_pDBC->listPlatformModBusRTU(tData->platform_id); + if ( tIDS ) { + for ( DBC_UINT64_LIST::iterator idx=tIDS->begin(); idx != tIDS->end(); idx++ ) { + LOG("Check Module!"); + MODBUS_RTU_INFO *tRTU = m_pDBC->getModBusRTU( *idx ); + if ( tRTU ) { + // 1 = left 2 = right 3 = tcc + if( ( tRTU->func == 1 ) && ( ( expected_module_functionality & 1 ) == 1 ) ) { + LOG("Using Left Module!"); + MODBUS_ACION_ITEM *tAI = (MODBUS_ACION_ITEM *)malloc(sizeof(MODBUS_ACION_ITEM)); + if ( tAI ) { + memset( tAI, 0, sizeof(MODBUS_ACION_ITEM) ); + tAI->scheduled_on = getMilliseconds() + ( m_sManagerData.automaticAlarmRisingTO * 1000 ); + tAI->module_id = tRTU->id; + tAI->value = ( 1 << tRTU->crossbar[((tData->side == 'U')?MBUS_CROSSBAR_UPPER_TRACK:MBUS_CROSSBAR_BOTTOM_TRACK)] ); + m_mProtector.lock(); + m_vActioItems.push_back( tAI ); + m_mProtector.unlock(); + }; + }; + if( ( tRTU->func == 2 ) && ( ( expected_module_functionality & 2 ) == 2 ) ) { + LOG("Using Right Module!"); + MODBUS_ACION_ITEM *tAI = (MODBUS_ACION_ITEM *)malloc(sizeof(MODBUS_ACION_ITEM)); + if ( tAI ) { + memset( tAI, 0, sizeof(MODBUS_ACION_ITEM) ); + tAI->scheduled_on = getMilliseconds() + ( m_sManagerData.automaticAlarmRisingTO * 1000 ); + tAI->module_id = tRTU->id; + tAI->value = ( 1 << tRTU->crossbar[((tData->side == 'U')?MBUS_CROSSBAR_UPPER_TRACK:MBUS_CROSSBAR_BOTTOM_TRACK)] ); + m_mProtector.lock(); + m_vActioItems.push_back( tAI ); + m_mProtector.unlock(); + }; + }; + if( tRTU->func == 3 ) { // TCC does always + LOG("Have TCC Module!"); + MODBUS_ACION_ITEM *tAI = (MODBUS_ACION_ITEM *)malloc(sizeof(MODBUS_ACION_ITEM)); + if ( tAI ) { + memset( tAI, 0, sizeof(MODBUS_ACION_ITEM) ); + tAI->scheduled_on = getMilliseconds() + ( m_sManagerData.automaticAlarmRisingTO * 1000 ); + tAI->module_id = tRTU->id; + tAI->value = ( 1 << tRTU->crossbar[((tData->side == 'U')?MBUS_CROSSBAR_UPPER_TRACK:MBUS_CROSSBAR_BOTTOM_TRACK)] ); + m_mProtector.lock(); + m_vActioItems.push_back( tAI ); + m_mProtector.unlock(); + }; + }; + free( tRTU ); }; - free( tRTU ); }; + delete( tIDS ); }; - delete( tIDS ); + free( tData ); }; - free( tData ); }; }; break; }; case EVT_SRV_SESSION_ENDED:{ + LOG("EVT Session Ended"); SCADA_TRACK_INFO *tData = m_pDBC->getTrackSCADA( Evt->m_nSourceNodeID ); if ( tData ) { //MODBUS_RTU_INFO *tRTU = m_pDBC->getModBusRTU_Platform( tData->platform_id ); diff --git a/lib/App/serva/servaSessionManager.cpp b/lib/App/serva/servaSessionManager.cpp index 642a9955..55d0e503 100644 --- a/lib/App/serva/servaSessionManager.cpp +++ b/lib/App/serva/servaSessionManager.cpp @@ -547,9 +547,35 @@ SESSION_DATA *servaSessionManager::updateSession( uint64_t tack_id, uint64_t mod LOG_ERROR("Cannot Allocate Session Data [malloc]!"); }; if ( tData ) { - // Session is New + LOG("Session is New"); if ( tData->db_id == 0 ) { - //LOG("All Seems to be good!"); + DBC_IS_MODULE_DATA *tMData = m_pDBC->getModuleData( module_id ); + if ( tMData ) { + DBC_IS_TRACK_DATA *tTData = m_pDBC->getTrackData( tack_id ); + if ( tTData ) { + if ( tTData->side == 'U') { + if (tMData->side == 'F') { + tData->src = 'L'; + } else { + tData->src = 'R'; + }; + } else { + if (tMData->side == 'F') { + tData->src = 'R'; + } else { + tData->src = 'L'; + }; + }; + free(tTData); + }; + free(tMData); + }; + + char tB[128]; + LOG("All Seems to be good!"); + sprintf( tB, "Session Source is: [%c]", tData->src ); + LOG( tB ); + tData->db_id = m_pDBC->sessionCreate( tData->track_id, tData->sts, tData->sms, tData->uuid, tData->src ); if ( tData->db_id == 0 ) { LOG_ERROR("Cannot Create Session!"); @@ -557,14 +583,22 @@ SESSION_DATA *servaSessionManager::updateSession( uint64_t tack_id, uint64_t mod free( tData ); tData = NULL; } else { + LOG("Session Registered at Database"); + //Propogate Event ->Session Start + SERVA_SESSION_EVT_DATA *tSData = (SERVA_SESSION_EVT_DATA*) malloc( sizeof(SERVA_SESSION_EVT_DATA)); + if ( tSData ) { + tSData->side = tData->src; + tSData->track_id = tData->track_id; + EVENT_CONTAINER *tEvt = createBasicEvent( tack_id, EVT_CLASS_SYSTEM, EVT_SRV_SESSION_STARTED, NULL, NULL, tSData ); + if ( tEvt ) basicEventHeap::getInstance()->broadcast( tEvt ); + }; + // Put Session into collection m_mSessionProtector.lock(); m_mSessions[tack_id] = tData; m_mSessionProtector.unlock(); - //Propogate Event ->Session Start - EVENT_CONTAINER *tEvt = createBasicEvent( tack_id, EVT_CLASS_SYSTEM, EVT_SRV_SESSION_STARTED ); - if ( tEvt ) basicEventHeap::getInstance()->broadcast( tEvt ); }; } else { + LOG("Session is Old"); char cSRC = ' '; DBC_IS_MODULE_DATA *tMData = m_pDBC->getModuleData( module_id ); if ( tMData ) { @@ -588,14 +622,23 @@ SESSION_DATA *servaSessionManager::updateSession( uint64_t tack_id, uint64_t mod free(tMData); }; if ( cSRC != ' ' ) { - // Have side info + LOG("Have side info"); if ( ( tData->src != 'B' ) && ( tData->src != cSRC ) ) { - tData->src = 'B'; + LOG("This is additional side!"); + tData->src = 'B'; // Change Status to 'B' = 'Both' (R+L) m_pDBC->updateSessionSource( tData->db_id, tData->src ); - // Create Event for other side - EVENT_CONTAINER *tEvt = createBasicEvent( tack_id, EVT_CLASS_SYSTEM, EVT_SRV_SESSION_STARTED ); - if ( tEvt ) basicEventHeap::getInstance()->broadcast( tEvt ); + // Create Event for other side + // sending EVT_SRV_SESSION_STARTED - > to signalize SCADA + // that another side of platform also become active + + SERVA_SESSION_EVT_DATA *tSData = (SERVA_SESSION_EVT_DATA*) malloc( sizeof(SERVA_SESSION_EVT_DATA)); + if ( tSData ) { + tSData->side = tData->src; + tSData->track_id = tData->track_id; + EVENT_CONTAINER *tEvt = createBasicEvent( tack_id, EVT_CLASS_SYSTEM, EVT_SRV_SESSION_STARTED, NULL, NULL, tSData ); + if ( tEvt ) basicEventHeap::getInstance()->broadcast( tEvt ); + }; }; }; }; diff --git a/lib/components/base/basicEvent.h b/lib/components/base/basicEvent.h index ee17c6a8..cb91a33e 100644 --- a/lib/components/base/basicEvent.h +++ b/lib/components/base/basicEvent.h @@ -256,6 +256,11 @@ typedef struct S_SERVA_VIDEO_TRANSFER_INFO uint8_t perc; } SERVA_VIDEO_TRANSFER_INFO; +typedef struct S_SERVA_SESSION_EVT_DATA{ + uint64_t track_id; + char side; +}SERVA_SESSION_EVT_DATA; + // typedef std::queue EventsFIFO; void utilizeBasicEvent(EVENT_CONTAINER & Evt); diff --git a/lib/data/media/video/videoLive555AVLibSource.cpp b/lib/data/media/video/videoLive555AVLibSource.cpp index 2febe573..db1272ce 100644 --- a/lib/data/media/video/videoLive555AVLibSource.cpp +++ b/lib/data/media/video/videoLive555AVLibSource.cpp @@ -1147,7 +1147,8 @@ void videoLIVE555Source::shutdownStream(RTSPClient * rtspClient, int exitCode) //}; //UsageEnvironment & env = rtspClient->envir(); MLOG("sendTearDown"); - rtspClient->sendTeardownCommand(*streamClientState.session, NULL); + //Must be checked if Client is connected before sending TearDown!!! + //rtspClient->sendTeardownCommand(*streamClientState.session, NULL); MLOG("Close Client"); Medium::close(rtspClient); MLOG("SetLOOP");