From aa68b59731b343c0d008afd5a0f990cb1533415e Mon Sep 17 00:00:00 2001 From: Evgeny Gagua Date: Sat, 29 Aug 2026 04:03:09 +0300 Subject: [PATCH] Fixed Multimodule Logic of ModBud (SCADA) Modules per platform --- Projects/la_serva/build | 2 +- lib/App/common/serverDataBinder.h | 10 +- lib/App/common/serverMySQL_dataBinder.cpp | 161 ++++-------- lib/App/common/serverMySQL_dataBinder.h | 2 +- lib/App/serva/servaModBusManager.cpp | 285 ++++++++++++---------- 5 files changed, 221 insertions(+), 239 deletions(-) diff --git a/Projects/la_serva/build b/Projects/la_serva/build index 7efee7e2..8d62327c 100755 --- a/Projects/la_serva/build +++ b/Projects/la_serva/build @@ -4,7 +4,7 @@ #make clean -e "CFG=Debug" #make -e "CFG=Debug" -j$(nproc) -#make clean -e "CFG=Debug86" +make clean -e "CFG=Debug86" make -e "CFG=Debug86" -j$(nproc) #make clean -e "CFG=Release86" diff --git a/lib/App/common/serverDataBinder.h b/lib/App/common/serverDataBinder.h index 75b0124e..63f4b47a 100644 --- a/lib/App/common/serverDataBinder.h +++ b/lib/App/common/serverDataBinder.h @@ -283,11 +283,6 @@ class serverDataBinder return NULL; } - virtual MODBUS_RTU_INFO * getModBusRTU_Platform(uint64_t id) - { - return NULL; - } - virtual DBC_IS_MODULE_DATA * getModuleData(uint64_t id) { return NULL; @@ -393,6 +388,11 @@ class serverDataBinder return NULL; } + virtual DBC_UINT64_LIST * listPlatformModBusRTU(uint64_t platform_id, char mode = 'E') + { + return NULL; + } + virtual DBC_UINT64_LIST * listPlatformModules(uint64_t id) { return NULL; diff --git a/lib/App/common/serverMySQL_dataBinder.cpp b/lib/App/common/serverMySQL_dataBinder.cpp index d316abfd..1e3aa053 100644 --- a/lib/App/common/serverMySQL_dataBinder.cpp +++ b/lib/App/common/serverMySQL_dataBinder.cpp @@ -430,88 +430,6 @@ MODBUS_RTU_INFO * servaMySQLDBC::getModBusRTU(uint64_t id) return RetVal; } -MODBUS_RTU_INFO * servaMySQLDBC::getModBusRTU_Platform(uint64_t id) -{ - MODBUS_RTU_INFO * RetVal = NULL; - if (m_bIsConnected) - { - char tQBuf[MAX_PATH_LEN]; - AAssoc * result; - sprintf(tQBuf, "SELECT * FROM `modbus_modules` WHERE `platform_id`=%" PRIu64, id); -#ifdef DEBUG_ALL - LOG(tQBuf); -#endif - result = m_pDatabase->Query(tQBuf); - if (result != NULL) - { - if (result->size() > 0) - { - RetVal = (MODBUS_RTU_INFO *) malloc(sizeof(MODBUS_RTU_INFO)); - if (RetVal) - { - memset(RetVal, 0, sizeof(MODBUS_RTU_INFO)); - - RetVal->id = id; - RetVal->input_base_addr = 0x00; - RetVal->output_base_addr = 0x10; - - Assoc * cArr; - Assoc::iterator it; - cArr = result->at(0); - it = cArr->find("platform_id"); - if (it != cArr->end()) - { - RetVal->platform_id = atoll(it->second.c_str()); - }; - it = cArr->find("ip4"); - if (it != cArr->end()) - { - strncpy(RetVal->ip, it->second.c_str(), 15); - RetVal->ip[15] = (char) 0; - }; - it = cArr->find("port"); - if (it != cArr->end()) - { - RetVal->port = atoi(it->second.c_str()); - }; - it = cArr->find("status"); - if (it != cArr->end()) - { - RetVal->status = atoi(it->second.c_str()); - }; - it = cArr->find("values"); - if (it != cArr->end()) - { - RetVal->c_OutBits = atoi(it->second.c_str()) & 0xFF; - RetVal->c_InBits = (atoi(it->second.c_str()) >> 8) & 0xFF; - }; - it = cArr->find("crossbar_a"); - if (it != cArr->end()) - { - RetVal->crossbar[0] = atoi(it->second.c_str()) & 0xFF; - }; - it = cArr->find("crossbar_b"); - if (it != cArr->end()) - { - RetVal->crossbar[1] = atoi(it->second.c_str()) & 0xFF; - }; - it = cArr->find("crossbar_c"); - if (it != cArr->end()) - { - RetVal->crossbar[2] = atoi(it->second.c_str()) & 0xFF; - }; - it = cArr->find("crossbar_d"); - if (it != cArr->end()) - { - RetVal->crossbar[3] = atoi(it->second.c_str()) & 0xFF; - }; - }; - }; - deleteResult(result); - }; - }; - return RetVal; -} DBC_IS_MODULE_DATA * servaMySQLDBC::getModuleData(uint64_t id) { @@ -1548,22 +1466,17 @@ DBC_UINT64_LIST * servaMySQLDBC::listMetroModules(char status) }; return tVal; } - -DBC_UINT64_LIST * servaMySQLDBC::listModBusRTUs(uint8_t status, char mode) -{ - DBC_UINT64_LIST * tVal = NULL; +DBC_UINT64_LIST * servaMySQLDBC::listPlatformModBusRTU(uint64_t platform_id, char mode ){ + DBC_UINT64_LIST * tVal = NULL; if (m_bIsConnected) { char tQBuf[MAX_PATH_LEN]; AAssoc * result; - if (status) - { - sprintf(tQBuf, "SELECT `id` FROM `modbus_modules` WHERE `wm`='%c', `status`=%d", mode, status); - } - else - { - sprintf(tQBuf, "SELECT `id` FROM `modbus_modules` WHERE `wm`='%c'", mode); - }; + if ( mode == 'A' ) { // All Modules + sprintf(tQBuf, "SELECT `id` FROM `modbus_modules` WHERE `platform_id`=%" PRIu64, platform_id); + } else { + sprintf(tQBuf, "SELECT `id` FROM `modbus_modules` WHERE `wm`='%c' AND `platform_id`=%" PRIu64, mode, platform_id); + } #ifdef DEBUG_ALL LOG(tQBuf); #endif @@ -1593,12 +1506,49 @@ DBC_UINT64_LIST * servaMySQLDBC::listModBusRTUs(uint8_t status, char mode) }; return tVal; } - -DBC_UINT64_LIST * servaMySQLDBC::listPlatformModules(uint64_t id) +DBC_UINT64_LIST * servaMySQLDBC::listModBusRTUs(uint8_t status, char mode) { DBC_UINT64_LIST * tVal = NULL; - if (m_bIsConnected) - { + if (m_bIsConnected){ + char tQBuf[MAX_PATH_LEN]; + AAssoc * result; + if (status) { + sprintf(tQBuf, "SELECT `id` FROM `modbus_modules` WHERE `wm`='%c' AND `status`=%d", mode, status); + } else { + if ( mode == 'A' ) { + sprintf(tQBuf, "SELECT `id` FROM `modbus_modules`"); + } else { + sprintf(tQBuf, "SELECT `id` FROM `modbus_modules` WHERE `wm`='%c'", mode); + }; + }; +#ifdef DEBUG_ALL + LOG(tQBuf); +#endif + result = m_pDatabase->Query(tQBuf); + if (result != NULL){ + if (result->size() > 0){ + Assoc * cArr; + tVal = new DBC_UINT64_LIST(); + if (tVal != NULL){ + Assoc::iterator it; + for (int i = 0; i < result->size(); i++){ + cArr = result->at(i); + it = cArr->find("id"); + if (it != cArr->end()){ + tVal->push_back(atoll(it->second.c_str())); + }; + }; + }; + }; + }; + deleteResult(result); + }; + return tVal; +} + +DBC_UINT64_LIST * servaMySQLDBC::listPlatformModules(uint64_t id){ + DBC_UINT64_LIST * tVal = NULL; + if (m_bIsConnected){ char tQBuf[MAX_PATH_LEN]; AAssoc * result; sprintf(tQBuf, "SELECT `mod`.`id` FROM `metro_modules` `mod` LEFT JOIN `metro_tracks` `tra` ON ( `tra`.`id` = `mod`.`track_id` ) WHERE `mod`.`status`='E' AND `tra`.`platform_id`=%" PRIu64, id); @@ -1607,21 +1557,16 @@ DBC_UINT64_LIST * servaMySQLDBC::listPlatformModules(uint64_t id) LOG(tQBuf); #endif result = m_pDatabase->Query(tQBuf); - if (result != NULL) - { - if (result->size() > 0) - { + if (result != NULL){ + if (result->size() > 0){ Assoc * cArr; tVal = new DBC_UINT64_LIST(); - if (tVal != NULL) - { + if (tVal != NULL){ Assoc::iterator it; - for (int i = 0; i < result->size(); i++) - { + for (int i = 0; i < result->size(); i++){ cArr = result->at(i); it = cArr->find("id"); - if (it != cArr->end()) - { + if (it != cArr->end()){ tVal->push_back(atoll(it->second.c_str())); }; }; diff --git a/lib/App/common/serverMySQL_dataBinder.h b/lib/App/common/serverMySQL_dataBinder.h index b3b5ac16..6daccf5b 100644 --- a/lib/App/common/serverMySQL_dataBinder.h +++ b/lib/App/common/serverMySQL_dataBinder.h @@ -46,7 +46,6 @@ class servaMySQLDBC : public serverDataBinder virtual CSTR getMediaUUID(uint64_t id); virtual MODBUS_MANAGER_DATA * getModBusManagerData(); virtual MODBUS_RTU_INFO * getModBusRTU(uint64_t id); - virtual MODBUS_RTU_INFO * getModBusRTU_Platform(uint64_t id); virtual DBC_IS_MODULE_DATA * getModuleData(uint64_t id); virtual char getMojoWM(uint64_t id); virtual DBC_RPC_MEDIA_INFO * getRemoteMediaInfo(uint64_t id); @@ -68,6 +67,7 @@ class servaMySQLDBC : public serverDataBinder virtual DBC_UINT64_LIST * listMediaQueueItems(uint8_t status); virtual DBC_UINT64_LIST * listMetroModules(char status); virtual DBC_UINT64_LIST * listModBusRTUs(uint8_t status = 0, char mode = 'E'); + virtual DBC_UINT64_LIST * listPlatformModBusRTU(uint64_t platform_id, char mode = 'E'); virtual DBC_UINT64_LIST * listPlatformModules(uint64_t id); virtual DBC_UINT64_LIST * listPlatforms(char mode = 'E'); virtual bool putIntoLog(CSTR type, CSTR TS, CSTR Msg); diff --git a/lib/App/serva/servaModBusManager.cpp b/lib/App/serva/servaModBusManager.cpp index 7b49e4aa..333f4938 100644 --- a/lib/App/serva/servaModBusManager.cpp +++ b/lib/App/serva/servaModBusManager.cpp @@ -300,19 +300,25 @@ bool servaModBusManager::dispatchEvent( EVENT_CONTAINER *Evt ){ //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 ); - 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(); + //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(); + }; + free( tRTU ); + }; }; - free( tRTU ); }; free( tData ); }; @@ -322,36 +328,42 @@ bool servaModBusManager::dispatchEvent( EVENT_CONTAINER *Evt ){ case EVT_SRV_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 ); - if ( tRTU ) { - uint8_t bON = ( 1 << tRTU->crossbar[((tData->side == 'U')?MBUS_CROSSBAR_UPPER_TRACK:MBUS_CROSSBAR_BOTTOM_TRACK)] ); - uint8_t bOFF = ~( 1 << tRTU->crossbar[((tData->side == 'U')?MBUS_CROSSBAR_UPPER_TRACK:MBUS_CROSSBAR_BOTTOM_TRACK)] ); - //Remove Scheduled Signal change - m_mProtector.lock(); - for ( V_MODBUS_ACION_ITEMS::iterator idx=m_vActioItems.begin(); idx!=m_vActioItems.end(); ){ - if( (*idx)->module_id == tRTU->id ) { - //check if shceduled signal is current - if( (((*idx)->value & bON ) == bON ) || (((*idx)->mask & bOFF ) == bOFF ) ){ - free((*idx)); - m_vActioItems.erase( idx ); - } else idx++; - //break; - } else idx++; - }; - m_mProtector.unlock(); + //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 bON = ( 1 << tRTU->crossbar[((tData->side == 'U')?MBUS_CROSSBAR_UPPER_TRACK:MBUS_CROSSBAR_BOTTOM_TRACK)] ); + uint8_t bOFF = ~( 1 << tRTU->crossbar[((tData->side == 'U')?MBUS_CROSSBAR_UPPER_TRACK:MBUS_CROSSBAR_BOTTOM_TRACK)] ); + //Remove Scheduled Signal change + m_mProtector.lock(); + for ( V_MODBUS_ACION_ITEMS::iterator idx=m_vActioItems.begin(); idx!=m_vActioItems.end(); ){ + if( (*idx)->module_id == tRTU->id ) { + //check if shceduled signal is current + if( (((*idx)->value & bON ) == bON ) || (((*idx)->mask & bOFF ) == bOFF ) ){ + free((*idx)); + m_vActioItems.erase( idx ); + } else idx++; + //break; + } else idx++; + }; + 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 ); + //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 ); + }; + }; + + free( tRTU ); }; }; - - free( tRTU ); }; free( tData ); }; @@ -363,47 +375,53 @@ bool servaModBusManager::dispatchEvent( EVENT_CONTAINER *Evt ){ SESSION_RATE_DATA *tSRD = (SESSION_RATE_DATA *)Evt->m_pEvtData; SCADA_TRACK_INFO *tData = m_pDBC->getTrackSCADA( tSRD->track_id ); if ( tData ) { - MODBUS_RTU_INFO *tRTU = m_pDBC->getModBusRTU_Platform( tData->platform_id ); - if ( tRTU ) { - uint8_t bON = ( 1 << tRTU->crossbar[((tData->side == 'U')?MBUS_CROSSBAR_UPPER_TRACK:MBUS_CROSSBAR_BOTTOM_TRACK)] ); - uint8_t bOFF = ~( 1 << tRTU->crossbar[((tData->side == 'U')?MBUS_CROSSBAR_UPPER_TRACK:MBUS_CROSSBAR_BOTTOM_TRACK)] ); - //Remove Scheduled Signal change - m_mProtector.lock(); - for ( V_MODBUS_ACION_ITEMS::iterator idx=m_vActioItems.begin(); idx!=m_vActioItems.end(); ){ - //check if shceduled ActionItem is Assigned to Current RTU - if( (*idx)->module_id == tRTU->id ) { - if( (((*idx)->value & bON ) == bON ) || (((*idx)->mask & bOFF ) == bOFF ) ){ - free((*idx)); - m_vActioItems.erase( idx ); - } else idx++; - } else idx++; - }; - m_mProtector.unlock(); - - if ( tSRD->level < m_sManagerData.hazardSignalLevel ) { - //Clear Signal if Set - 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 ); + //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 bON = ( 1 << tRTU->crossbar[((tData->side == 'U')?MBUS_CROSSBAR_UPPER_TRACK:MBUS_CROSSBAR_BOTTOM_TRACK)] ); + uint8_t bOFF = ~( 1 << tRTU->crossbar[((tData->side == 'U')?MBUS_CROSSBAR_UPPER_TRACK:MBUS_CROSSBAR_BOTTOM_TRACK)] ); + //Remove Scheduled Signal change + m_mProtector.lock(); + for ( V_MODBUS_ACION_ITEMS::iterator idx=m_vActioItems.begin(); idx!=m_vActioItems.end(); ){ + //check if shceduled ActionItem is Assigned to Current RTU + if( (*idx)->module_id == tRTU->id ) { + if( (((*idx)->value & bON ) == bON ) || (((*idx)->mask & bOFF ) == bOFF ) ){ + free((*idx)); + m_vActioItems.erase( idx ); + } else idx++; + } else idx++; }; - }; - } else { - //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 ); + m_mProtector.unlock(); + + if ( tSRD->level < m_sManagerData.hazardSignalLevel ) { + //Clear Signal if Set + 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 ); + }; + }; } else { - m_pDBC->updateModBusRTU( tRTU->id, MBUS_STATUS_ONLINE, tRTU->c_InBits, tRTU->c_OutBits ); + //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 ); + }; + }; }; + free( tRTU ); }; }; - free( tRTU ); }; free( tData ); }; @@ -413,20 +431,26 @@ bool servaModBusManager::dispatchEvent( EVENT_CONTAINER *Evt ){ case EVT_SRV_TEST_MODBUS:{ MODBUS_TEST_DATA *tData = (MODBUS_TEST_DATA *)Evt->m_pEvtData; if ( tData ) { - MODBUS_RTU_INFO *tRTU = m_pDBC->getModBusRTU_Platform( tData->platform_id ); - if ( tRTU ) { -#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 - 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 ); + //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 ) { + #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 + 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 ); + }; + free( tRTU ); + }; }; - free( tRTU ); }; }; return false; // No need Propogate this Evt @@ -436,48 +460,61 @@ bool servaModBusManager::dispatchEvent( EVENT_CONTAINER *Evt ){ if ( m_sManagerData.helthSignalLevel ) { MODULE_HEALTH_STATUS *tData = (MODULE_HEALTH_STATUS *)Evt->m_pEvtData; if ( tData->status >= m_sManagerData.helthSignalLevel ) { - MODBUS_RTU_INFO *tRTU = m_pDBC->getModBusRTU_Platform( tData->platform_id ); - if ( tRTU ) { - uint8_t bON = ( 1 << tRTU->crossbar[MBUS_CROSSBAR_HEALTH] ); - uint8_t bOFF = ~( 1 << tRTU->crossbar[MBUS_CROSSBAR_HEALTH] ); -#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 ); + //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 bON = ( 1 << tRTU->crossbar[MBUS_CROSSBAR_HEALTH] ); + uint8_t bOFF = ~( 1 << tRTU->crossbar[MBUS_CROSSBAR_HEALTH] ); + #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 ); + }; + }; + free( tRTU ); }; }; - free( tRTU ); + delete( tIDS ); }; } else { //Below Level - MODBUS_RTU_INFO *tRTU = m_pDBC->getModBusRTU_Platform( tData->platform_id ); - if ( tRTU ) { - uint8_t bON = ( 1 << tRTU->crossbar[MBUS_CROSSBAR_HEALTH] ); - uint8_t bOFF = ~( 1 << tRTU->crossbar[MBUS_CROSSBAR_HEALTH] ); -#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 ); + //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 bON = ( 1 << tRTU->crossbar[MBUS_CROSSBAR_HEALTH] ); + uint8_t bOFF = ~( 1 << tRTU->crossbar[MBUS_CROSSBAR_HEALTH] ); + #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 ); + }; + }; + free( tRTU ); }; }; - free( tRTU ); }; }; };