diff --git a/CMakeLists.txt b/CMakeLists.txt index cb5ecd8..70ce644 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,7 +113,7 @@ target_include_directories( target_link_libraries( ePowerSwitchFrontend PRIVATE - ePowerSwitchEquipment + ePowerSwitchEquipment midas::mfe m_epics_ca ${LIBS} diff --git a/src/device/ePowerSwitchEquipment.cpp b/src/device/ePowerSwitchEquipment.cpp index dbd29ea..2c408a2 100644 --- a/src/device/ePowerSwitchEquipment.cpp +++ b/src/device/ePowerSwitchEquipment.cpp @@ -16,6 +16,15 @@ std::string format(std::string str, int value) { return ss.str(); } +std::string getDefaultSocketName(int socketId) { + std::string res = std::string(EPOWERSWITCH_DEFAULT_SOCKET_NAME) + .append(std::to_string(socketId)); + + printf("get default %s\n", res.c_str()); + + return res; +} + ePowerSwitchEquipment::ePowerSwitchEquipment(std::string equipmentName, const char *equipmentFileName) : TMFeEquipment(equipmentName.c_str(), equipmentFileName), @@ -35,9 +44,11 @@ ePowerSwitchEquipment::ePowerSwitchEquipment(std::string equipmentName, void ePowerSwitchEquipment::HandlePeriodic() { updateSocketNumber(); refreshAllSockets(); + updateSocketNames(); } void ePowerSwitchEquipment::refreshSocket(int socketId) { + std::string requestedVarname = format("Socket ", socketId) + std::string(" requested"); std::string currentVarname = @@ -131,6 +142,8 @@ void ePowerSwitchEquipment::updateSocketNumber() { this->outletGetRecords.push_back( std::make_unique>( epicsGetRecordName.c_str())); + + this->socketNames.push_back(getDefaultSocketName(i)); } if (this->numberOfOutlet > epicsOutletNumber) @@ -157,7 +170,31 @@ void ePowerSwitchEquipment::updateSocketNumber() { this->outletSetRecords.pop_back(); this->outletGetRecords.pop_back(); + this->socketNames.pop_back(); } this->numberOfOutlet = epicsOutletNumber; } + +void ePowerSwitchEquipment::updateSocketNames() { + std::string varname = EPOWERSWITCH_SOCKET_NAME_SETTINGS; + varname.reserve(varname.length() + 1); + + MVOdbError ovbError; + + for (int i = 0; i < this->numberOfOutlet; i++) { + std::string socketName = getDefaultSocketName(i); + varname[7] = '0' + i; + fOdbEqSettings->RS(varname.c_str(), &socketName, true, + socketName.length() + 1, &ovbError); + if (ovbError.fError) + fMfe->Msg(MERROR, __FUNCTION__, ovbError.fErrorString); + + printf("%s as the name %s\n", varname.c_str(), socketName.c_str()); + + if (this->socketNames.at(i) != socketName) { + printf("new name %s\n", socketName.c_str()); + this->socketNames.at(i) = socketName; + } + } +} diff --git a/src/device/ePowerSwitchEquipment.h b/src/device/ePowerSwitchEquipment.h index 751a4ef..a3c65f3 100644 --- a/src/device/ePowerSwitchEquipment.h +++ b/src/device/ePowerSwitchEquipment.h @@ -25,6 +25,7 @@ class ePowerSwitchEquipment : public TMFeEquipment { private: std::vector>> outletSetRecords; std::vector>> outletGetRecords; + std::vector socketNames; mEpicsCa outletNumberRecord; int numberOfOutlet; @@ -44,6 +45,11 @@ class ePowerSwitchEquipment : public TMFeEquipment { * @brief detect and modify the current socket pool in case of change */ void updateSocketNumber(); + + /** + * @brief update socketNames by reading settings ODB + */ + void updateSocketNames(); }; #endif \ No newline at end of file diff --git a/src/device/ePowerSwitchEquipmentConfig.h b/src/device/ePowerSwitchEquipmentConfig.h index e0a407e..1ab55ee 100644 --- a/src/device/ePowerSwitchEquipmentConfig.h +++ b/src/device/ePowerSwitchEquipmentConfig.h @@ -5,4 +5,7 @@ #define EPOWERSWITCH_SOCKET_GET_PREFIX "ePowerSwitch_get_outlet_" #define EPOWERSWITCH_SOCKETNUMBER_INFO_PREFIX "ePowerSwitch_config_maxOutlet" +#define EPOWERSWITCH_DEFAULT_SOCKET_NAME "Socket " +#define EPOWERSWITCH_SOCKET_NAME_SETTINGS "Socket n name" + #endif