|
|
|
@ -216,7 +216,7 @@ void servaModBusManager::m_fThreadProc( void ){ |
|
|
|
m_pDBC->updateModBusRTU( (*idx)->id, (*idx)->status, (*idx)->c_InBits, (*idx)->c_OutBits ); |
|
|
|
//Input Handling
|
|
|
|
if ( (*idx)->c_InBits ) { |
|
|
|
LOG("Have DI Signal!!"); |
|
|
|
bool had_some_assignments = false; |
|
|
|
//Testing Bits
|
|
|
|
for ( uint8_t bi = 0; bi < 4; bi++ ) { |
|
|
|
if ( ((*idx)->c_InBits & ( 1 << bi ) ) == ( 1 << bi ) ) { |
|
|
|
@ -225,51 +225,23 @@ void servaModBusManager::m_fThreadProc( void ){ |
|
|
|
// check functionality
|
|
|
|
switch ( (*idx)->crossbar[4 + bi] ) { |
|
|
|
case MBUS_FUNC_ACK_UPPER_TRACK:{ |
|
|
|
LOG("In: Upper Track ACK"); |
|
|
|
uint64_t cTID = m_pDBC->getTrackIdByPlatform( (*idx)->platform_id, 'U' ); |
|
|
|
if ( cTID ) { |
|
|
|
SESSION_DATA *tSData = servaSessionManager::getInstance()->getActiveSessionByTrack( cTID ); |
|
|
|
if ( tSData ) { |
|
|
|
//Rate Session
|
|
|
|
m_pDBC->updateSessionStatus( tSData->db_id, 1 ); |
|
|
|
// Create Event?? or just Disable Scada Signal
|
|
|
|
DBC_UINT64_LIST *tIDS = m_pDBC->listPlatformModBusRTU( (*idx)->platform_id ); |
|
|
|
if ( tIDS ) { |
|
|
|
for ( DBC_UINT64_LIST::iterator idd=tIDS->begin(); idd != tIDS->end(); idd++ ) { |
|
|
|
MODBUS_RTU_INFO *tRTU = m_pDBC->getModBusRTU( *idd ); |
|
|
|
if ( tRTU ) { |
|
|
|
uint8_t CBV = tRTU->crossbar[MBUS_CROSSBAR_UPPER_TRACK]; |
|
|
|
if ( CBV ) { |
|
|
|
CBV --; |
|
|
|
uint8_t bON = (1 << CBV); |
|
|
|
uint8_t bOFF = ~( 1 << CBV ); |
|
|
|
//Remove Scheduled Signal change
|
|
|
|
m_mProtector.lock(); |
|
|
|
for ( V_MODBUS_ACION_ITEMS::iterator idz=m_vActioItems.begin(); idz!=m_vActioItems.end(); ){ |
|
|
|
if( (*idz)->module_id == tRTU->id ) { |
|
|
|
//check if shceduled signal is current
|
|
|
|
if( (((*idz)->value & bON ) == bON ) || (((*idz)->mask & bOFF ) == bOFF ) ){ |
|
|
|
free((*idx)); |
|
|
|
m_vActioItems.erase( idz ); |
|
|
|
} else idz++; |
|
|
|
//break;
|
|
|
|
} else idz++; |
|
|
|
}; |
|
|
|
m_mProtector.unlock(); |
|
|
|
//Mitigate Signal if sent
|
|
|
|
if ( (tRTU->c_OutBits & bON ) == bON ) { |
|
|
|
tRTU->c_OutBits &= bOFF; |
|
|
|
int rv = modbus_set_rtu( tRTU->ip, tRTU->port, tRTU->output_base_addr, tRTU->c_OutBits ); |
|
|
|
if ( rv < 0 ) { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_OFFLINE, 0, 0 ); |
|
|
|
} else { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_ONLINE, tRTU->c_InBits, tRTU->c_OutBits ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
};//Crossbar check
|
|
|
|
free( tRTU ); |
|
|
|
}; |
|
|
|
m_pDBC->updateSessionStatus( tSData->db_id, SCADA_ACK_SESSION_RATING ); |
|
|
|
SESSION_RATE_DATA *tData = (SESSION_RATE_DATA *) malloc( sizeof( SESSION_RATE_DATA ) ); |
|
|
|
if ( tData ) { |
|
|
|
tData->level = SCADA_ACK_SESSION_RATING; |
|
|
|
tData->track_id = (*idx)->platform_id; |
|
|
|
EVENT_CONTAINER * tEvt = createBasicEvent( 0, EVT_CLASS_SYSTEM, EVT_SRV_SESSION_RATED, NULL, NULL, tData ); |
|
|
|
if ( tEvt ) { |
|
|
|
basicEventHeap::getInstance()->broadcast( tEvt ); |
|
|
|
} else { |
|
|
|
free( tData ); |
|
|
|
}; |
|
|
|
delete( tIDS ); |
|
|
|
}; |
|
|
|
free( tSData ); |
|
|
|
}; |
|
|
|
@ -277,105 +249,57 @@ void servaModBusManager::m_fThreadProc( void ){ |
|
|
|
break; |
|
|
|
}; |
|
|
|
case MBUS_FUNC_ACK_BOTTOM_TRACK:{//Bottom Track
|
|
|
|
LOG("In: Bottom Track ACK"); |
|
|
|
uint64_t cTID = m_pDBC->getTrackIdByPlatform( (*idx)->platform_id, 'B' ); |
|
|
|
if ( cTID ) { |
|
|
|
SESSION_DATA *tSData = servaSessionManager::getInstance()->getActiveSessionByTrack( cTID ); |
|
|
|
if ( tSData ) { |
|
|
|
//Rate Session
|
|
|
|
m_pDBC->updateSessionStatus( tSData->db_id, 1 ); |
|
|
|
// Create Event?? or just Disable Scada Signal
|
|
|
|
DBC_UINT64_LIST *tIDS = m_pDBC->listPlatformModBusRTU( (*idx)->platform_id ); |
|
|
|
if ( tIDS ) { |
|
|
|
for ( DBC_UINT64_LIST::iterator idd=tIDS->begin(); idd != tIDS->end(); idd++ ) { |
|
|
|
MODBUS_RTU_INFO *tRTU = m_pDBC->getModBusRTU( *idd ); |
|
|
|
if ( tRTU ) { |
|
|
|
uint8_t CBV = tRTU->crossbar[MBUS_CROSSBAR_BOTTOM_TRACK]; |
|
|
|
if ( CBV ) { |
|
|
|
CBV --; |
|
|
|
uint8_t bON = (1 << CBV ); |
|
|
|
uint8_t bOFF = ~( 1 << CBV ); |
|
|
|
//Remove Scheduled Signal change
|
|
|
|
m_mProtector.lock(); |
|
|
|
for ( V_MODBUS_ACION_ITEMS::iterator idz=m_vActioItems.begin(); idz!=m_vActioItems.end(); ){ |
|
|
|
if( (*idz)->module_id == tRTU->id ) { |
|
|
|
//check if shceduled signal is current
|
|
|
|
if( (((*idz)->value & bON ) == bON ) || (((*idz)->mask & bOFF ) == bOFF ) ){ |
|
|
|
free((*idx)); |
|
|
|
m_vActioItems.erase( idz ); |
|
|
|
} else idz++; |
|
|
|
//break;
|
|
|
|
} else idz++; |
|
|
|
}; |
|
|
|
m_mProtector.unlock(); |
|
|
|
//Mitigate Signal if sent
|
|
|
|
if ( (tRTU->c_OutBits & bON ) == bON ) { |
|
|
|
tRTU->c_OutBits &= bOFF; |
|
|
|
int rv = modbus_set_rtu( tRTU->ip, tRTU->port, tRTU->output_base_addr, tRTU->c_OutBits ); |
|
|
|
if ( rv < 0 ) { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_OFFLINE, 0, 0 ); |
|
|
|
} else { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_ONLINE, tRTU->c_InBits, tRTU->c_OutBits ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; // Crossbar check
|
|
|
|
free( tRTU ); |
|
|
|
}; |
|
|
|
m_pDBC->updateSessionStatus( tSData->db_id, SCADA_ACK_SESSION_RATING ); |
|
|
|
SESSION_RATE_DATA *tData = (SESSION_RATE_DATA *) malloc( sizeof( SESSION_RATE_DATA ) ); |
|
|
|
if ( tData ) { |
|
|
|
tData->level = SCADA_ACK_SESSION_RATING; |
|
|
|
tData->track_id = (*idx)->platform_id; |
|
|
|
EVENT_CONTAINER * tEvt = createBasicEvent( 0, EVT_CLASS_SYSTEM, EVT_SRV_SESSION_RATED, NULL, NULL, tData ); |
|
|
|
if ( tEvt ) { |
|
|
|
basicEventHeap::getInstance()->broadcast( tEvt ); |
|
|
|
} else { |
|
|
|
free( tData ); |
|
|
|
}; |
|
|
|
delete( tIDS ); |
|
|
|
}; |
|
|
|
free( tSData ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
break; |
|
|
|
}; |
|
|
|
case MBUS_FUNC_ACK_BOTH_TRACKS:{//Both Tracks
|
|
|
|
case MBUS_FUNC_ACK_PLATFORM_ALARMS:{//Both Tracks
|
|
|
|
LOG("In: All Tracks ACK"); |
|
|
|
bool triggered_by_direct_event = false; |
|
|
|
uint64_t cTID = m_pDBC->getTrackIdByPlatform( (*idx)->platform_id, 'U' ); |
|
|
|
if ( cTID ) { |
|
|
|
SESSION_DATA *tSData = servaSessionManager::getInstance()->getActiveSessionByTrack( cTID ); |
|
|
|
if ( tSData ) { |
|
|
|
//Rate Session
|
|
|
|
m_pDBC->updateSessionStatus( tSData->db_id, 1 ); |
|
|
|
// Create Event?? or just Disable Scada Signal
|
|
|
|
DBC_UINT64_LIST *tIDS = m_pDBC->listPlatformModBusRTU( (*idx)->platform_id ); |
|
|
|
if ( tIDS ) { |
|
|
|
for ( DBC_UINT64_LIST::iterator idd=tIDS->begin(); idd != tIDS->end(); idd++ ) { |
|
|
|
MODBUS_RTU_INFO *tRTU = m_pDBC->getModBusRTU( *idd ); |
|
|
|
if ( tRTU ) { |
|
|
|
uint8_t CBV = tRTU->crossbar[MBUS_CROSSBAR_UPPER_TRACK]; |
|
|
|
if ( CBV ) { |
|
|
|
CBV --; |
|
|
|
uint8_t bON = (1 << CBV ); |
|
|
|
uint8_t bOFF = ~( 1 << CBV ); |
|
|
|
//Remove Scheduled Signal change
|
|
|
|
m_mProtector.lock(); |
|
|
|
for ( V_MODBUS_ACION_ITEMS::iterator idz=m_vActioItems.begin(); idz!=m_vActioItems.end(); ){ |
|
|
|
if( (*idz)->module_id == tRTU->id ) { |
|
|
|
//check if shceduled signal is current
|
|
|
|
if( (((*idz)->value & bON ) == bON ) || (((*idz)->mask & bOFF ) == bOFF ) ){ |
|
|
|
free((*idx)); |
|
|
|
m_vActioItems.erase( idz ); |
|
|
|
} else idz++; |
|
|
|
//break;
|
|
|
|
} else idz++; |
|
|
|
}; |
|
|
|
m_mProtector.unlock(); |
|
|
|
//Mitigate Signal if sent
|
|
|
|
if ( (tRTU->c_OutBits & bON ) == bON ) { |
|
|
|
tRTU->c_OutBits &= bOFF; |
|
|
|
int rv = modbus_set_rtu( tRTU->ip, tRTU->port, tRTU->output_base_addr, tRTU->c_OutBits ); |
|
|
|
if ( rv < 0 ) { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_OFFLINE, 0, 0 ); |
|
|
|
} else { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_ONLINE, tRTU->c_InBits, tRTU->c_OutBits ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; // Crossbar check
|
|
|
|
free( tRTU ); |
|
|
|
}; |
|
|
|
m_pDBC->updateSessionStatus( tSData->db_id, SCADA_ACK_SESSION_RATING ); |
|
|
|
SESSION_RATE_DATA *tData = (SESSION_RATE_DATA *) malloc( sizeof( SESSION_RATE_DATA ) ); |
|
|
|
if ( tData ) { |
|
|
|
tData->level = SCADA_ACK_SESSION_RATING; |
|
|
|
tData->track_id = (*idx)->platform_id; |
|
|
|
EVENT_CONTAINER * tEvt = createBasicEvent( 0, EVT_CLASS_SYSTEM, EVT_SRV_SESSION_RATED, NULL, NULL, tData ); |
|
|
|
if ( tEvt ) { |
|
|
|
basicEventHeap::getInstance()->broadcast( tEvt ); |
|
|
|
} else { |
|
|
|
free( tData ); |
|
|
|
}; |
|
|
|
delete( tIDS ); |
|
|
|
}; |
|
|
|
free( tSData ); |
|
|
|
} else { |
|
|
|
// Use Just Clear Signals Event if no Active Session
|
|
|
|
EVENT_CONTAINER * tEvt = createBasicEvent( (*idx)->platform_id, EVT_CLASS_SYSTEM, EVT_SRV_MODBUS_CLEAR_S ); |
|
|
|
if ( tEvt ) { |
|
|
|
basicEventHeap::getInstance()->broadcast( tEvt ); |
|
|
|
triggered_by_direct_event = true; |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
cTID = m_pDBC->getTrackIdByPlatform( (*idx)->platform_id, 'B' ); |
|
|
|
@ -383,112 +307,69 @@ void servaModBusManager::m_fThreadProc( void ){ |
|
|
|
SESSION_DATA *tSData = servaSessionManager::getInstance()->getActiveSessionByTrack( cTID ); |
|
|
|
if ( tSData ) { |
|
|
|
//Rate Session
|
|
|
|
m_pDBC->updateSessionStatus( tSData->db_id, 1 ); |
|
|
|
// Create Event?? or just Disable Scada Signal
|
|
|
|
DBC_UINT64_LIST *tIDS = m_pDBC->listPlatformModBusRTU( (*idx)->platform_id ); |
|
|
|
if ( tIDS ) { |
|
|
|
for ( DBC_UINT64_LIST::iterator idd=tIDS->begin(); idd != tIDS->end(); idd++ ) { |
|
|
|
MODBUS_RTU_INFO *tRTU = m_pDBC->getModBusRTU( *idd ); |
|
|
|
if ( tRTU ) { |
|
|
|
uint8_t CBV = tRTU->crossbar[MBUS_CROSSBAR_BOTTOM_TRACK]; |
|
|
|
if ( CBV ) { |
|
|
|
uint8_t bON = (1 << CBV ); |
|
|
|
uint8_t bOFF = ~( 1 << CBV ); |
|
|
|
//Remove Scheduled Signal change
|
|
|
|
m_mProtector.lock(); |
|
|
|
for ( V_MODBUS_ACION_ITEMS::iterator idz=m_vActioItems.begin(); idz!=m_vActioItems.end(); ){ |
|
|
|
if( (*idz)->module_id == tRTU->id ) { |
|
|
|
//check if shceduled signal is current
|
|
|
|
if( (((*idz)->value & bON ) == bON ) || (((*idz)->mask & bOFF ) == bOFF ) ){ |
|
|
|
free((*idx)); |
|
|
|
m_vActioItems.erase( idz ); |
|
|
|
} else idz++; |
|
|
|
//break;
|
|
|
|
} else idz++; |
|
|
|
}; |
|
|
|
m_mProtector.unlock(); |
|
|
|
//Mitigate Signal if sent
|
|
|
|
if ( (tRTU->c_OutBits & bON ) == bON ) { |
|
|
|
tRTU->c_OutBits &= bOFF; |
|
|
|
int rv = modbus_set_rtu( tRTU->ip, tRTU->port, tRTU->output_base_addr, tRTU->c_OutBits ); |
|
|
|
if ( rv < 0 ) { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_OFFLINE, 0, 0 ); |
|
|
|
} else { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_ONLINE, tRTU->c_InBits, tRTU->c_OutBits ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; // Crossbar check
|
|
|
|
free( tRTU ); |
|
|
|
}; |
|
|
|
m_pDBC->updateSessionStatus( tSData->db_id, SCADA_ACK_SESSION_RATING ); |
|
|
|
SESSION_RATE_DATA *tData = (SESSION_RATE_DATA *) malloc( sizeof( SESSION_RATE_DATA ) ); |
|
|
|
if ( tData ) { |
|
|
|
tData->level = SCADA_ACK_SESSION_RATING; |
|
|
|
tData->track_id = (*idx)->platform_id; |
|
|
|
EVENT_CONTAINER * tEvt = createBasicEvent( 0, EVT_CLASS_SYSTEM, EVT_SRV_SESSION_RATED, NULL, NULL, tData ); |
|
|
|
if ( tEvt ) { |
|
|
|
basicEventHeap::getInstance()->broadcast( tEvt ); |
|
|
|
} else { |
|
|
|
free( tData ); |
|
|
|
}; |
|
|
|
delete( tIDS ); |
|
|
|
}; |
|
|
|
free( tSData ); |
|
|
|
} else { |
|
|
|
// Use Just Clear Signals Event if no Active Session
|
|
|
|
// But no need to do it twice!
|
|
|
|
if ( !triggered_by_direct_event ) { |
|
|
|
EVENT_CONTAINER * tEvt = createBasicEvent( (*idx)->platform_id, EVT_CLASS_SYSTEM, EVT_SRV_MODBUS_CLEAR_S ); |
|
|
|
if ( tEvt ) { |
|
|
|
basicEventHeap::getInstance()->broadcast( tEvt ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
break; |
|
|
|
}; |
|
|
|
case MBUS_FUNC_SIG_STROBE_LIGHT:{ // Set TCC AUX signal
|
|
|
|
DBC_UINT64_LIST *tIDS = m_pDBC->listPlatformModBusRTU( (*idx)->platform_id ); |
|
|
|
if ( tIDS ) { |
|
|
|
for ( DBC_UINT64_LIST::iterator idd=tIDS->begin(); idd != tIDS->end(); idd++ ) { |
|
|
|
MODBUS_RTU_INFO *tRTU = m_pDBC->getModBusRTU( *idd ); |
|
|
|
if ( tRTU ) { |
|
|
|
//AUX crossbar record used as additional functionality
|
|
|
|
uint8_t CBV = tRTU->crossbar[MBUS_CROSSBAR_AUX]; |
|
|
|
// check if TCC Module
|
|
|
|
if( tRTU->func == 3 && CBV ) { |
|
|
|
// check if was not snoozed by operator
|
|
|
|
int c_status = m_pDBC->getScadaPostStatus( (*idx)->platform_id, SCADA_POST_TYPE_HELTH_STROBE, (*idx)->func ); |
|
|
|
if( c_status < 1 ){ // Not Snoozed by Operator
|
|
|
|
CBV--; |
|
|
|
uint8_t bON = (1 << CBV ); |
|
|
|
uint8_t bOFF = ~( 1 << CBV ); |
|
|
|
//Remove Scheduled Signal change
|
|
|
|
m_mProtector.lock(); |
|
|
|
for ( V_MODBUS_ACION_ITEMS::iterator idz=m_vActioItems.begin(); idz!=m_vActioItems.end(); ){ |
|
|
|
if( (*idz)->module_id == tRTU->id ) { |
|
|
|
//check if shceduled signal is current
|
|
|
|
if( (((*idz)->value & bON ) == bON ) || (((*idz)->mask & bOFF ) == bOFF ) ){ |
|
|
|
free((*idx)); |
|
|
|
m_vActioItems.erase( idz ); |
|
|
|
} else idz++; |
|
|
|
//break;
|
|
|
|
} else idz++; |
|
|
|
}; |
|
|
|
m_mProtector.unlock(); |
|
|
|
//Skeep Signal if Allready Set
|
|
|
|
if ( (tRTU->c_OutBits & bON ) == 0 ) { |
|
|
|
tRTU->c_OutBits |= bON; |
|
|
|
int rv = modbus_set_rtu( tRTU->ip, tRTU->port, tRTU->output_base_addr, tRTU->c_OutBits ); |
|
|
|
if ( rv < 0 ) { |
|
|
|
tRTU->c_OutBits &= bOFF; |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_OFFLINE, tRTU->c_InBits, tRTU->c_OutBits ); |
|
|
|
} else { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_ONLINE, tRTU->c_InBits, tRTU->c_OutBits ); |
|
|
|
m_pDBC->addScadaPost( (*idx)->platform_id, SCADA_POST_TYPE_HELTH_STROBE, (*idx)->func ); |
|
|
|
}; |
|
|
|
} else { |
|
|
|
m_pDBC->addScadaPost( (*idx)->platform_id, SCADA_POST_TYPE_HELTH_STROBE, (*idx)->func ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
free( tRTU ); |
|
|
|
}; |
|
|
|
case MBUS_FUNC_SIG_STROBE_LIGHT:{ // Set TCC AUX signal
|
|
|
|
LOG("In: Strobe"); |
|
|
|
MODBUS_POST_DATA *tData =(MODBUS_POST_DATA *) malloc( sizeof( MODBUS_POST_DATA ) ); |
|
|
|
if ( tData ) { |
|
|
|
tData->type = SCADA_POST_TYPE_HELTH_STROBE; |
|
|
|
tData->status = 0; |
|
|
|
tData->src = (*idx)->func; |
|
|
|
tData->platform_id = (*idx)->platform_id; |
|
|
|
EVENT_CONTAINER * tEvt = createBasicEvent( 0, EVT_CLASS_SYSTEM, EVT_SRV_MODBUS_STROBE, NULL, NULL, tData ); |
|
|
|
if ( tEvt ) { |
|
|
|
basicEventHeap::getInstance()->broadcast( tEvt ); |
|
|
|
} else { |
|
|
|
free( tData ); |
|
|
|
}; |
|
|
|
delete( tIDS ); |
|
|
|
}; |
|
|
|
break; |
|
|
|
}; |
|
|
|
case MBUS_FUNC_ACK_ALL_SIGNALS:{ |
|
|
|
// Do we need to search an active SESSION in that case ??
|
|
|
|
LOG("In: Dismiss Platform"); |
|
|
|
EVENT_CONTAINER * tEvt = createBasicEvent( (*idx)->platform_id, EVT_CLASS_SYSTEM, EVT_SRV_MODBUS_CLEAR_P ); |
|
|
|
if ( tEvt ) { |
|
|
|
basicEventHeap::getInstance()->broadcast( tEvt ); |
|
|
|
}; |
|
|
|
break; |
|
|
|
}; |
|
|
|
}; |
|
|
|
had_some_assignments = true; |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
//Reset Latch
|
|
|
|
//rv = modbus_set_rtu_bit( (*idx)->ip, (*idx)->port, 36, 0 );
|
|
|
|
rv = modbus_set_rtu( (*idx)->ip, (*idx)->port, 40, 0 ); |
|
|
|
if ( rv == -1 ) { |
|
|
|
LOG_ERROR("Error clear latch flag on RTU"); |
|
|
|
//Reset Latch - Only If the Crossbar has function for that
|
|
|
|
if ( had_some_assignments ) { |
|
|
|
rv = modbus_set_rtu((*idx)->ip, (*idx)->port, 40, 0); |
|
|
|
if ( rv == -1 ) { |
|
|
|
LOG_ERROR("Error clear latch flag on RTU"); |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
continue; |
|
|
|
@ -498,7 +379,7 @@ void servaModBusManager::m_fThreadProc( void ){ |
|
|
|
#endif
|
|
|
|
} |
|
|
|
#ifdef DEBUG_EXTRA
|
|
|
|
else LOG_ERROR("Read DO Failure"); |
|
|
|
else LOG_ERROR("RTU Communication Failure"); |
|
|
|
#endif
|
|
|
|
(*idx)->status = MBUS_STATUS_OFFLINE; |
|
|
|
m_pDBC->updateModBusRTU( (*idx)->id, (*idx)->status, (*idx)->c_InBits, (*idx)->c_OutBits ); |
|
|
|
@ -517,9 +398,20 @@ void servaModBusManager::m_fThreadProc( void ){ |
|
|
|
if ( m_vActioItems.size() ) { |
|
|
|
for( V_MODBUS_ACION_ITEMS::iterator idx = m_vActioItems.begin(); idx != m_vActioItems.end(); ){ |
|
|
|
if( (*idx)->scheduled_on < cts ) { |
|
|
|
handleRTU( (*idx)->module_id, (*idx)->value, (*idx)->mask ); |
|
|
|
free( *idx ); |
|
|
|
m_vActioItems.erase( idx ); |
|
|
|
MODBUS_RTU_INFO *tRTU = m_pDBC->getModBusRTU( (*idx)->module_id ); |
|
|
|
if ( tRTU ) { |
|
|
|
if( handleRTU( tRTU, (*idx)->value, (*idx)->mask) ) { |
|
|
|
free( *idx ); |
|
|
|
m_vActioItems.erase( idx ); |
|
|
|
} else { |
|
|
|
LOG_ERROR("Cannot Issue SCADA Signal!"); |
|
|
|
idx++; |
|
|
|
}; |
|
|
|
free( tRTU ); |
|
|
|
} else { |
|
|
|
LOG_ERROR("Cannot Get SCADA RTU info!"); |
|
|
|
idx++; |
|
|
|
}; |
|
|
|
} else idx++; |
|
|
|
}; |
|
|
|
}; |
|
|
|
@ -540,36 +432,32 @@ void servaModBusManager::m_fThreadProc( void ){ |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
bool servaModBusManager::handleRTU( uint64_t rtu_id, uint8_t value, uint8_t mask ){ |
|
|
|
bool servaModBusManager::handleRTU( MODBUS_RTU_INFO *tRTU, uint8_t value, uint8_t mask ){ |
|
|
|
bool rVal = false; |
|
|
|
if ( m_pDBC == NULL ) return rVal; |
|
|
|
MODBUS_RTU_INFO *tRTU = m_pDBC->getModBusRTU( rtu_id ); |
|
|
|
if ( tRTU ) { |
|
|
|
if( ( tRTU->c_OutBits & value ) == 0 ) { |
|
|
|
//Set
|
|
|
|
tRTU->c_OutBits |= value; |
|
|
|
int rv = modbus_set_rtu( tRTU->ip, tRTU->port, tRTU->output_base_addr, tRTU->c_OutBits ); |
|
|
|
if ( rv < 0 ) { |
|
|
|
// Do we need clear Database values on failure??
|
|
|
|
//m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_OFFLINE, 0, 0 );
|
|
|
|
} else { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_ONLINE, tRTU->c_InBits, tRTU->c_OutBits ); |
|
|
|
rVal = true; |
|
|
|
if ( tRTU->status == MBUS_STATUS_ONLINE ) { |
|
|
|
bool act = false; |
|
|
|
if( ( tRTU->c_OutBits & value ) != value ) { |
|
|
|
//Set
|
|
|
|
tRTU->c_OutBits |= value; |
|
|
|
act = true; |
|
|
|
}; |
|
|
|
}; |
|
|
|
if( ( tRTU->c_OutBits & mask ) != 0 ) { |
|
|
|
//Clear
|
|
|
|
tRTU->c_OutBits &= ~mask; |
|
|
|
int rv = modbus_set_rtu( tRTU->ip, tRTU->port, tRTU->output_base_addr, tRTU->c_OutBits ); |
|
|
|
if ( rv < 0 ) { |
|
|
|
// Do we need clear Database values on failure??
|
|
|
|
//m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_OFFLINE, 0, 0 );
|
|
|
|
} else { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_ONLINE, tRTU->c_InBits, tRTU->c_OutBits ); |
|
|
|
rVal = true; |
|
|
|
if( ( tRTU->c_OutBits & mask ) != 0 ) { |
|
|
|
//Clear
|
|
|
|
tRTU->c_OutBits &= ~mask; |
|
|
|
act = true; |
|
|
|
}; |
|
|
|
// Apply Changes at once
|
|
|
|
if ( act ) { |
|
|
|
int rv = modbus_set_rtu(tRTU->ip, tRTU->port, tRTU->output_base_addr, tRTU->c_OutBits); |
|
|
|
if ( rv < 0 ) { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_OFFLINE, 0, 0 ); |
|
|
|
} else { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_ONLINE, tRTU->c_InBits, tRTU->c_OutBits ); |
|
|
|
rVal = true; |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
free(tRTU); |
|
|
|
}; |
|
|
|
return rVal; |
|
|
|
}; |
|
|
|
@ -684,40 +572,7 @@ bool servaModBusManager::dispatchEvent( EVENT_CONTAINER *Evt ){ |
|
|
|
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 ) { |
|
|
|
uint8_t CBV = tRTU->crossbar[((tData->side == 'U')?MBUS_CROSSBAR_UPPER_TRACK:MBUS_CROSSBAR_BOTTOM_TRACK)]; |
|
|
|
if ( CBV ) { |
|
|
|
CBV--; |
|
|
|
uint8_t bON = (1 << CBV ); |
|
|
|
uint8_t bOFF = ~( 1 << CBV ); |
|
|
|
//Remove Scheduled Signal change
|
|
|
|
m_mProtector.lock(); |
|
|
|
for ( V_MODBUS_ACION_ITEMS::iterator idd=m_vActioItems.begin(); idd!=m_vActioItems.end(); ){ |
|
|
|
if( (*idd)->module_id == tRTU->id ) { |
|
|
|
//check if shceduled signal is current
|
|
|
|
if( (((*idd)->value & bON ) == bON ) || (((*idd)->mask & bOFF ) == bOFF ) ){ |
|
|
|
free((*idd)); |
|
|
|
m_vActioItems.erase( idd ); |
|
|
|
} else idd++; |
|
|
|
//break;
|
|
|
|
} else idd++; |
|
|
|
}; |
|
|
|
m_mProtector.unlock(); |
|
|
|
|
|
|
|
//Mitigate Signal if sent
|
|
|
|
if ( (tRTU->c_OutBits & bON ) == bON ) { |
|
|
|
tRTU->c_OutBits &= bOFF; |
|
|
|
int rv = modbus_set_rtu( tRTU->ip, tRTU->port, tRTU->output_base_addr, tRTU->c_OutBits ); |
|
|
|
if ( rv < 0 ) { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_OFFLINE, 0, 0 ); |
|
|
|
} else { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_ONLINE, tRTU->c_InBits, tRTU->c_OutBits ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; // checking crossbar
|
|
|
|
free( tRTU ); |
|
|
|
}; |
|
|
|
mitigateCoil( *idx, ((tData->side == 'U')?MBUS_CROSSBAR_UPPER_TRACK:MBUS_CROSSBAR_BOTTOM_TRACK )); |
|
|
|
}; |
|
|
|
delete( tIDS ); |
|
|
|
}; |
|
|
|
@ -789,6 +644,7 @@ bool servaModBusManager::dispatchEvent( EVENT_CONTAINER *Evt ){ |
|
|
|
}; |
|
|
|
break; |
|
|
|
}; |
|
|
|
// Do we need that functionality ??
|
|
|
|
case EVT_SRV_MODBUS_TEST_P:{ |
|
|
|
MODBUS_TEST_DATA *tData = (MODBUS_TEST_DATA *)Evt->m_pEvtData; |
|
|
|
if ( tData ) { |
|
|
|
@ -811,6 +667,7 @@ bool servaModBusManager::dispatchEvent( EVENT_CONTAINER *Evt ){ |
|
|
|
free( tRTU ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
delete( tIDS ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
return false; // No need Propogate this Evt
|
|
|
|
@ -825,201 +682,120 @@ bool servaModBusManager::dispatchEvent( EVENT_CONTAINER *Evt ){ |
|
|
|
sprintf( tB, "%s:%d 0x%02x 0x%02x", tRTU->ip, tRTU->port, tRTU->output_base_addr, tData->c_OutBits ); |
|
|
|
LOG( tB ); |
|
|
|
#endif
|
|
|
|
int rv = modbus_set_rtu( tRTU->ip, tRTU->port, tRTU->output_base_addr, tData->c_OutBits ); |
|
|
|
if ( rv < 0 ) { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_OFFLINE, 0, 0 ); |
|
|
|
} else { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_ONLINE, tRTU->c_InBits, tData->c_OutBits ); |
|
|
|
}; |
|
|
|
handleRTU( tRTU, tData->c_OutBits, ~tData->c_OutBits ); |
|
|
|
free( tRTU ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
return false; // No need Propogate this Evt
|
|
|
|
}; |
|
|
|
case CMD_KRN_SCADA_SNOOZE_POST_MESSAGE:{ |
|
|
|
MODBUS_PB_DATA *tData = (MODBUS_PB_DATA *)Evt->m_pEvtData; |
|
|
|
if ( tData ) { |
|
|
|
MODBUS_PM_DATA *sData = m_pDBC->getScadaPostData( tData->id ); |
|
|
|
if ( sData ) { |
|
|
|
bool mitigate = false; |
|
|
|
if ( sData->type == 6 ) { |
|
|
|
mitigate = true; |
|
|
|
} else { |
|
|
|
if ( sData->type >= m_sManagerData.helthSignalLevel ) mitigate = true; |
|
|
|
case EVT_SRV_MODBUS_CLEAR_S:{ |
|
|
|
//Create ActionItems For all Modules
|
|
|
|
LOG("Clear ALARMS Only"); |
|
|
|
uint64_t platform_id = Evt->m_nSourceNodeID; |
|
|
|
if ( platform_id ) { |
|
|
|
DBC_UINT64_LIST *tIDS = m_pDBC->listPlatformModBusRTU( platform_id ); |
|
|
|
if ( tIDS ) { |
|
|
|
for ( DBC_UINT64_LIST::iterator idx=tIDS->begin(); idx != tIDS->end(); idx++ ) { |
|
|
|
mitigateCoil( *idx, MBUS_CROSSBAR_UPPER_TRACK ); |
|
|
|
mitigateCoil( *idx, MBUS_CROSSBAR_BOTTOM_TRACK ); |
|
|
|
}; |
|
|
|
if ( mitigate ) { |
|
|
|
DBC_UINT64_LIST *tIDS = m_pDBC->listPlatformModBusRTU( sData->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 ) { |
|
|
|
uint8_t CBV = tRTU->crossbar[((sData->type == 6)?MBUS_CROSSBAR_AUX:MBUS_CROSSBAR_HEALTH)]; |
|
|
|
//check only TCC modules
|
|
|
|
if ( tRTU->func == 3 && CBV ) { |
|
|
|
CBV --; |
|
|
|
uint8_t bON = (1 << CBV ); |
|
|
|
uint8_t bOFF = ~( 1 << CBV ); |
|
|
|
#ifdef DEBUG_EXTRA
|
|
|
|
char tB[200]; |
|
|
|
sprintf( tB, "%s:%d 0x%02x 0x%02x", tRTU->ip, tRTU->port, tRTU->output_base_addr, tData->c_OutBits ); |
|
|
|
LOG( tB ); |
|
|
|
#endif
|
|
|
|
//Mitigate Signal if sent
|
|
|
|
if ( (tRTU->c_OutBits & bON ) == bON ) { |
|
|
|
tRTU->c_OutBits &= bOFF; |
|
|
|
int rv = modbus_set_rtu( tRTU->ip, tRTU->port, tRTU->output_base_addr, tRTU->c_OutBits ); |
|
|
|
if ( rv < 0 ) { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_OFFLINE, 0, 0 ); |
|
|
|
} else { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_ONLINE, tRTU->c_InBits, tRTU->c_OutBits ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; // Crossbar Check
|
|
|
|
free( tRTU ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
delete( tIDS ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
return false;// No need Propogate this Evt ??
|
|
|
|
}; |
|
|
|
case EVT_SRV_MODBUS_CLEAR_P:{ |
|
|
|
//Create ActionItems For all Modules
|
|
|
|
LOG("Clear ALL SIGNALS and SNOOZE POSTBOXES"); |
|
|
|
uint64_t platform_id = Evt->m_nSourceNodeID; |
|
|
|
if ( platform_id ) { |
|
|
|
DBC_UINT64_LIST *tIDS = m_pDBC->listPlatformModBusRTU( platform_id ); |
|
|
|
if ( tIDS ) { |
|
|
|
for ( DBC_UINT64_LIST::iterator idx=tIDS->begin(); idx != tIDS->end(); idx++ ) { |
|
|
|
mitigateCoil( *idx, MBUS_CROSSBAR_UPPER_TRACK ); |
|
|
|
mitigateCoil( *idx, MBUS_CROSSBAR_BOTTOM_TRACK ); |
|
|
|
mitigateCoil( *idx, MBUS_CROSSBAR_HEALTH, (SERVER_SCADA_POST_TYPE) 0 ); |
|
|
|
mitigateCoil( *idx, MBUS_CROSSBAR_AUX, (SERVER_SCADA_POST_TYPE) 6 ); |
|
|
|
}; |
|
|
|
delete( tIDS ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
return false; // No need Propogate this Evt ??
|
|
|
|
}; |
|
|
|
case EVT_SRV_MODBUS_S_POSTBOX:{ |
|
|
|
LOG("Snooze PBOX"); |
|
|
|
MODBUS_POST_DATA *sData = (MODBUS_POST_DATA *)Evt->m_pEvtData; |
|
|
|
if ( sData ) { |
|
|
|
bool mitigate = false; |
|
|
|
if ( sData->type == 6 ) { |
|
|
|
mitigate = true; |
|
|
|
} else { |
|
|
|
if ( sData->type >= m_sManagerData.helthSignalLevel ) mitigate = true; |
|
|
|
}; |
|
|
|
if ( mitigate ) { |
|
|
|
DBC_UINT64_LIST *tIDS = m_pDBC->listPlatformModBusRTU( sData->platform_id ); |
|
|
|
if ( tIDS ) { |
|
|
|
for ( DBC_UINT64_LIST::iterator idx=tIDS->begin(); idx != tIDS->end(); idx++ ) { |
|
|
|
mitigateCoil( *idx, ((sData->type == SCADA_POST_TYPE_HELTH_STROBE)?MBUS_CROSSBAR_AUX:MBUS_CROSSBAR_HEALTH) ); |
|
|
|
}; |
|
|
|
delete( tIDS ); |
|
|
|
}; |
|
|
|
m_pDBC->updateScadaPostStatus(tData->id, 1); |
|
|
|
}; |
|
|
|
}; |
|
|
|
return false; // No need Propogate this Evt
|
|
|
|
break; |
|
|
|
}; |
|
|
|
case EVT_SRV_MODBUS_D_POSTBOX:{ |
|
|
|
MODBUS_PB_DATA *tData = (MODBUS_PB_DATA *)Evt->m_pEvtData; |
|
|
|
if ( tData ) { |
|
|
|
MODBUS_PM_DATA *sData = m_pDBC->getScadaPostData( tData->id ); |
|
|
|
if ( sData ) { |
|
|
|
bool mitigate = false; |
|
|
|
if ( sData->type == 6 ) { |
|
|
|
mitigate = true; |
|
|
|
} else { |
|
|
|
if ( sData->type >= m_sManagerData.helthSignalLevel ) mitigate = true; |
|
|
|
}; |
|
|
|
if ( mitigate ) { |
|
|
|
DBC_UINT64_LIST *tIDS = m_pDBC->listPlatformModBusRTU( sData->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 ) { |
|
|
|
uint8_t CBV = tRTU->crossbar[((sData->type == 6)?MBUS_CROSSBAR_AUX:MBUS_CROSSBAR_HEALTH)]; |
|
|
|
//check only TCC modules
|
|
|
|
if ( tRTU->func == 3 && CBV ) { |
|
|
|
CBV --; |
|
|
|
uint8_t bON = (1 << CBV ); |
|
|
|
uint8_t bOFF = ~( 1 << CBV ); |
|
|
|
#ifdef DEBUG_EXTRA
|
|
|
|
char tB[200]; |
|
|
|
sprintf( tB, "%s:%d 0x%02x 0x%02x", tRTU->ip, tRTU->port, tRTU->output_base_addr, tData->c_OutBits ); |
|
|
|
LOG( tB ); |
|
|
|
#endif
|
|
|
|
//Mitigate Signal if sent
|
|
|
|
if ( (tRTU->c_OutBits & bON ) == bON ) { |
|
|
|
tRTU->c_OutBits &= bOFF; |
|
|
|
int rv = modbus_set_rtu( tRTU->ip, tRTU->port, tRTU->output_base_addr, tRTU->c_OutBits ); |
|
|
|
if ( rv < 0 ) { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_OFFLINE, 0, 0 ); |
|
|
|
} else { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_ONLINE, tRTU->c_InBits, tRTU->c_OutBits ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; // Crossbar Check
|
|
|
|
free( tRTU ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
LOG("Dismiss PBOX"); |
|
|
|
MODBUS_POST_DATA *sData = (MODBUS_POST_DATA *)Evt->m_pEvtData; |
|
|
|
if ( sData ) { |
|
|
|
bool mitigate = false; |
|
|
|
if ( sData->type == 6 ) { |
|
|
|
mitigate = true; |
|
|
|
} else { |
|
|
|
if ( sData->type >= m_sManagerData.helthSignalLevel ) mitigate = true; |
|
|
|
}; |
|
|
|
if ( mitigate ) { |
|
|
|
DBC_UINT64_LIST *tIDS = m_pDBC->listPlatformModBusRTU( sData->platform_id ); |
|
|
|
if ( tIDS ) { |
|
|
|
for ( DBC_UINT64_LIST::iterator idx=tIDS->begin(); idx != tIDS->end(); idx++ ) { |
|
|
|
mitigateCoil( *idx, ((sData->type == SCADA_POST_TYPE_HELTH_STROBE)?MBUS_CROSSBAR_AUX:MBUS_CROSSBAR_HEALTH) ); |
|
|
|
}; |
|
|
|
delete( tIDS ); |
|
|
|
}; |
|
|
|
m_pDBC->deleteScadaPost( tData->id ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
return false; // No need Propogate this Evt
|
|
|
|
}; |
|
|
|
case EVT_SRV_MODULE_HEALTH:{ |
|
|
|
LOG("Module Helth Changed!"); |
|
|
|
if ( Evt->m_pEvtData == NULL ) return false; |
|
|
|
if ( m_sManagerData.helthSignalLevel ) { |
|
|
|
MODULE_HEALTH_STATUS *tData = (MODULE_HEALTH_STATUS *)Evt->m_pEvtData; |
|
|
|
//checking if Snoozed
|
|
|
|
int c_status = m_pDBC->getScadaPostStatus( tData->platform_id, (SERVER_SCADA_POST_TYPE) tData->status, tData->module_id ); |
|
|
|
if( c_status < 1 ){ |
|
|
|
if( c_status < 0 && tData->status ) { // No Record in MBox
|
|
|
|
// Add status regardless of
|
|
|
|
m_pDBC->addScadaPost( tData->platform_id, (SERVER_SCADA_POST_TYPE) tData->status, tData->module_id ); |
|
|
|
c_status = 0; // Set Enabled Signal Status
|
|
|
|
}; |
|
|
|
// clear all abowe Health statuses as not relevant
|
|
|
|
// do we need a module ID ?? since the zone is whole platform
|
|
|
|
// If tData->status == 0 then the Health status will be cleared
|
|
|
|
m_pDBC->deleteScadaPostsAbowe( tData->platform_id, (SERVER_SCADA_POST_TYPE) tData->status ); |
|
|
|
|
|
|
|
if( tData->status >= m_sManagerData.helthSignalLevel && c_status == 0 ){ |
|
|
|
//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) { |
|
|
|
uint8_t CBV = tRTU->crossbar[MBUS_CROSSBAR_HEALTH]; |
|
|
|
//Check Only TCC modules
|
|
|
|
if ( tRTU->func == 3 && CBV ) { |
|
|
|
CBV --; |
|
|
|
uint8_t bON = (1 << CBV ); |
|
|
|
uint8_t bOFF = ~( 1 << CBV ); |
|
|
|
#ifdef DEBUG_EXTRA
|
|
|
|
char tB[200]; |
|
|
|
sprintf( tB, "%s:%d 0x%02x 0x%02x", tRTU->ip, tRTU->port, tRTU->output_base_addr, tData->c_OutBits ); |
|
|
|
LOG( tB ); |
|
|
|
#endif
|
|
|
|
//Set Signal if was Cleared
|
|
|
|
if ( (tRTU->c_OutBits & bON ) == 0 ) { |
|
|
|
tRTU->c_OutBits |= bON; |
|
|
|
int rv = modbus_set_rtu( tRTU->ip, tRTU->port, tRTU->output_base_addr, tRTU->c_OutBits ); |
|
|
|
if ( rv < 0 ) { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_OFFLINE, 0, 0 ); |
|
|
|
} else { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_ONLINE, tRTU->c_InBits, tRTU->c_OutBits ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; // Crossbar check
|
|
|
|
free( tRTU ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
delete( tIDS ); |
|
|
|
}; |
|
|
|
} else { //Below Level
|
|
|
|
//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 ) { |
|
|
|
uint8_t CBV = tRTU->crossbar[MBUS_CROSSBAR_HEALTH]; |
|
|
|
//check only TCC modules
|
|
|
|
if ( tRTU->func == 3 && CBV ) { |
|
|
|
CBV --; |
|
|
|
uint8_t bON = (1 << CBV ); |
|
|
|
uint8_t bOFF = ~( 1 << CBV ); |
|
|
|
#ifdef DEBUG_EXTRA
|
|
|
|
char tB[200]; |
|
|
|
sprintf( tB, "%s:%d 0x%02x 0x%02x", tRTU->ip, tRTU->port, tRTU->output_base_addr, tData->c_OutBits ); |
|
|
|
LOG( tB ); |
|
|
|
#endif
|
|
|
|
//Mitigate Signal if sent
|
|
|
|
if ( (tRTU->c_OutBits & bON ) == bON ) { |
|
|
|
tRTU->c_OutBits &= bOFF; |
|
|
|
int rv = modbus_set_rtu( tRTU->ip, tRTU->port, tRTU->output_base_addr, tRTU->c_OutBits ); |
|
|
|
if ( rv < 0 ) { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_OFFLINE, 0, 0 ); |
|
|
|
} else { |
|
|
|
m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_ONLINE, tRTU->c_InBits, tRTU->c_OutBits ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; // Crossbar Check
|
|
|
|
free( tRTU ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
DBC_UINT64_LIST *tIDS = m_pDBC->listPlatformModBusRTU( tData->platform_id ); |
|
|
|
if ( tIDS ) { |
|
|
|
for ( DBC_UINT64_LIST::iterator idx=tIDS->begin(); idx != tIDS->end(); idx++ ) { |
|
|
|
if( tData->status >= m_sManagerData.helthSignalLevel ){ |
|
|
|
activateCoil( *idx, MBUS_CROSSBAR_HEALTH, tData->module_id, (SERVER_SCADA_POST_TYPE) tData->status ); |
|
|
|
} else { |
|
|
|
mitigateCoil( *idx, MBUS_CROSSBAR_HEALTH, (SERVER_SCADA_POST_TYPE) tData->status ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
delete( tIDS ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
break; |
|
|
|
}; |
|
|
|
case EVT_SRV_MODBUS_STROBE:{ |
|
|
|
LOG("Activate Strobe Signal"); |
|
|
|
MODBUS_POST_DATA *tData = (MODBUS_POST_DATA *) Evt->m_pEvtData; |
|
|
|
if ( tData ) { |
|
|
|
DBC_UINT64_LIST *tIDS = m_pDBC->listPlatformModBusRTU( tData->platform_id ); |
|
|
|
if ( tIDS ) { |
|
|
|
for ( DBC_UINT64_LIST::iterator idx=tIDS->begin(); idx != tIDS->end(); idx++ ) { |
|
|
|
activateCoil( *idx, MBUS_CROSSBAR_AUX, tData->src, (SERVER_SCADA_POST_TYPE) tData->type ); |
|
|
|
}; |
|
|
|
delete( tIDS ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
break; |
|
|
|
}; |
|
|
|
@ -1027,6 +803,96 @@ bool servaModBusManager::dispatchEvent( EVENT_CONTAINER *Evt ){ |
|
|
|
return true; |
|
|
|
}; |
|
|
|
|
|
|
|
void servaModBusManager::activateCoil( uint64_t rtu_id, uint8_t function_id, uint64_t src, SERVER_SCADA_POST_TYPE pt ){ |
|
|
|
if( function_id > MBUS_CROSSBAR_AUX ) return; // No such Function
|
|
|
|
MODBUS_RTU_INFO *tRTU = m_pDBC->getModBusRTU( rtu_id ); |
|
|
|
if ( tRTU ) { |
|
|
|
uint8_t CBV = tRTU->crossbar[function_id]; |
|
|
|
if( CBV ) { |
|
|
|
bool module_is_ok = true; |
|
|
|
if( pt && tRTU->func != 3 && tRTU->func != 0 && CBV ) module_is_ok = false; |
|
|
|
// check if TCC or Default Module
|
|
|
|
if( module_is_ok ) { |
|
|
|
int c_status = 0; |
|
|
|
// check if was not snoozed by operator
|
|
|
|
if( pt ) c_status = m_pDBC->getScadaPostStatus( tRTU->platform_id, pt, src ); |
|
|
|
if ( function_id == MBUS_CROSSBAR_HEALTH ) { |
|
|
|
// clear all abowe Health statuses as not relevant
|
|
|
|
// do we need a module ID ?? since the zone is whole platform
|
|
|
|
// If tData->status == 0 then the Health status will be cleared
|
|
|
|
m_pDBC->deleteScadaPostsAbowe( tRTU->platform_id, pt ); |
|
|
|
}; |
|
|
|
|
|
|
|
if( c_status < 1) { // Not Snoozed by Operator
|
|
|
|
if ( c_status < 0 ) { // Not Founud in MBOX but must have record!
|
|
|
|
m_pDBC->addScadaPost( tRTU->platform_id, pt, src ); |
|
|
|
}; |
|
|
|
CBV--; |
|
|
|
//Actual Setting modbus signal
|
|
|
|
uint8_t bON = (1 << CBV ); |
|
|
|
uint8_t bOFF = ~( 1 << CBV ); |
|
|
|
//Remove Scheduled Signal change
|
|
|
|
m_mProtector.lock(); |
|
|
|
for ( V_MODBUS_ACION_ITEMS::iterator idz=m_vActioItems.begin(); idz!=m_vActioItems.end(); ){ |
|
|
|
if( (*idz)->module_id == tRTU->id ) { |
|
|
|
//check if shceduled signal is current
|
|
|
|
if( (((*idz)->value & bON ) == bON ) || (((*idz)->mask & bOFF ) == bOFF ) ){ |
|
|
|
free((*idz)); |
|
|
|
m_vActioItems.erase( idz ); |
|
|
|
} else idz++; |
|
|
|
//break;
|
|
|
|
} else idz++; |
|
|
|
}; |
|
|
|
m_mProtector.unlock(); |
|
|
|
//Since Activation need to set only SET
|
|
|
|
handleRTU( tRTU, bON, 0x00 ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
free( tRTU ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
void servaModBusManager::mitigateCoil( uint64_t rtu_id, uint8_t function_id, SERVER_SCADA_POST_TYPE pt ){ |
|
|
|
if( function_id > MBUS_CROSSBAR_AUX ) return; // No such Function
|
|
|
|
MODBUS_RTU_INFO *tRTU = m_pDBC->getModBusRTU( rtu_id ); |
|
|
|
if ( tRTU ) { |
|
|
|
uint8_t CBV = tRTU->crossbar[function_id]; |
|
|
|
if ( CBV ) { |
|
|
|
if (function_id == MBUS_CROSSBAR_HEALTH) { |
|
|
|
// clear all abowe Health statuses as not relevant
|
|
|
|
// do we need a module ID ?? since the zone is whole platform
|
|
|
|
// If tData->status == 0 then the Health status will be cleared
|
|
|
|
if ( pt ) { |
|
|
|
m_pDBC->deleteScadaPostsAbowe(tRTU->platform_id, (SERVER_SCADA_POST_TYPE)( pt - 1 ) ); |
|
|
|
} else { |
|
|
|
m_pDBC->deleteScadaPostsAbowe(tRTU->platform_id, SCADA_POST_TYPE_NA ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
CBV--; |
|
|
|
//Actual Setting modbus signal
|
|
|
|
uint8_t bON = (1 << CBV ); |
|
|
|
uint8_t bOFF = ~bON; |
|
|
|
//Remove Scheduled Signal change
|
|
|
|
m_mProtector.lock(); |
|
|
|
for ( V_MODBUS_ACION_ITEMS::iterator idz=m_vActioItems.begin(); idz!=m_vActioItems.end(); ){ |
|
|
|
if( (*idz)->module_id == tRTU->id ) { |
|
|
|
//check if shceduled signal is current
|
|
|
|
if( (((*idz)->value & bON ) == bON ) || (((*idz)->mask & bOFF ) == bOFF ) ){ |
|
|
|
free((*idz)); |
|
|
|
m_vActioItems.erase( idz ); |
|
|
|
} else idz++; |
|
|
|
//break;
|
|
|
|
} else idz++; |
|
|
|
}; |
|
|
|
m_mProtector.unlock(); |
|
|
|
//Since Mitigation need to set only mask
|
|
|
|
handleRTU( tRTU, 0x00, bON ); |
|
|
|
}; |
|
|
|
free( tRTU ); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
#undef LOG
|
|
|
|
#undef LOG_ERROR
|
|
|
|
|