diff --git a/build/submodule/mepicsca/CTestTestfile.cmake b/build/submodule/mepicsca/CTestTestfile.cmake new file mode 100644 index 0000000..9ad0d79 --- /dev/null +++ b/build/submodule/mepicsca/CTestTestfile.cmake @@ -0,0 +1,8 @@ +# CMake generated Testfile for +# Source directory: /home/ponsin_h/midas_frontends/ePowerSwitch_frontend/submodule/mepicsca +# Build directory: /home/ponsin_h/midas_frontends/ePowerSwitch_frontend/build/submodule/mepicsca +# +# This file includes the relevant testing commands required for +# testing this directory and lists subdirectories to be tested as well. +add_test(m_epics_ca_test "/home/ponsin_h/midas_frontends/ePowerSwitch_frontend/submodule/mepicsca/run_test.sh" "/home/ponsin_h/midas_frontends/ePowerSwitch_frontend/build/submodule/mepicsca/m_epics_ca_test") +set_tests_properties(m_epics_ca_test PROPERTIES RUN_SERIAL "TRUE" WORKING_DIRECTORY "/home/ponsin_h/midas_frontends/ePowerSwitch_frontend/submodule/mepicsca" _BACKTRACE_TRIPLES "/home/ponsin_h/midas_frontends/ePowerSwitch_frontend/submodule/mepicsca/CMakeLists.txt;113;add_test;/home/ponsin_h/midas_frontends/ePowerSwitch_frontend/submodule/mepicsca/CMakeLists.txt;0;") diff --git a/build/submodule/mepicsca/m_epics_ca_test b/build/submodule/mepicsca/m_epics_ca_test new file mode 100755 index 0000000..3fd2a90 Binary files /dev/null and b/build/submodule/mepicsca/m_epics_ca_test differ diff --git a/include/ePowerSwitchConfig.h b/include/ePowerSwitchConfig.h index 3e1dea1..933e254 100644 --- a/include/ePowerSwitchConfig.h +++ b/include/ePowerSwitchConfig.h @@ -1,7 +1,8 @@ #ifndef EPOWERSWITCH_CONFIG_H #define EPOWERSWITCH_CONFIG_H -#define EPOWERSWITCH_SOCKET_COMMAND_PREFIX "ePowerSwitch_command_outlet_" +#define EPOWERSWITCH_SOCKET_SET_PREFIX "ePowerSwitch_set_outlet_" +#define EPOWERSWITCH_SOCKET_GET_PREFIX "ePowerSwitch_get_outlet_" #define EPOWERSWITCH_SOCKETNUMBER_INFO_PREFIX "ePowerSwitch_config_maxOutlet" #define DEFAULT_FRONTEND_NAME "ePowerSwitch" diff --git a/include/ePowerSwitchFront.h b/include/ePowerSwitchFront.h index 3160d3a..53783e3 100644 --- a/include/ePowerSwitchFront.h +++ b/include/ePowerSwitchFront.h @@ -23,8 +23,8 @@ class ePowerSwitchEquipment : public TMFeEquipment { void HandlePeriodic(); private: - std::vector *> outletCommandRecords; - std::vector outletLastState; + std::vector *> outletSetRecords; + std::vector *> outletGetRecords; mEpicsCa outletNumberRecord; int numberOfOutlet; diff --git a/src/ePowerSwitchFront.cpp b/src/ePowerSwitchFront.cpp index 1a4e606..c1a81aa 100644 --- a/src/ePowerSwitchFront.cpp +++ b/src/ePowerSwitchFront.cpp @@ -77,21 +77,24 @@ void ePowerSwitchEquipment::HandlePeriodic() { } void ePowerSwitchEquipment::refreshSocket(int socketId) { - std::string varname = format("Socket ", socketId); + std::string requestedVarname = + format("Socket ", socketId) + std::string(" requested"); + std::string currentVarname = + format("Socket ", socketId) + std::string(" current"); - int midasSocketState = 0; // default => turn off - fOdbEqVariables->RI(varname.c_str(), &midasSocketState, true); + std::string midasRequestedSocketState = std::string("Off"); + fOdbEqVariables->RS(requestedVarname.c_str(), &midasRequestedSocketState, + true, midasRequestedSocketState.length() + 1); - if (midasSocketState != this->outletLastState.at(socketId)) { - int errorCode = - this->outletCommandRecords.at(socketId)->put(&midasSocketState); - if (errorCode < 0) { - fMfe->Msg(MERROR, __FUNCTION__, - "Couldn't put new value into socket n° %d", socketId); - } else { - this->outletLastState.at(socketId) = midasSocketState; - } + std::string epicsCurrentSocketState; + this->outletGetRecords.at(socketId)->get(&epicsCurrentSocketState); + + if (epicsCurrentSocketState != midasRequestedSocketState) { + this->outletSetRecords.at(socketId)->put(&midasRequestedSocketState); } + + fOdbEqVariables->WS(currentVarname.c_str(), epicsCurrentSocketState.c_str(), + epicsCurrentSocketState.length() + 1); } void ePowerSwitchEquipment::refreshAllSockets() { @@ -124,12 +127,16 @@ void ePowerSwitchEquipment::updateSocketNumber() { epicsOutletNumber - this->numberOfOutlet); for (int i = this->numberOfOutlet; i < epicsOutletNumber; i++) { - std::string epicsRecordName = - format(EPOWERSWITCH_SOCKET_COMMAND_PREFIX, i); + std::string epicsSetRecordName = + format(EPOWERSWITCH_SOCKET_SET_PREFIX, i); - this->outletCommandRecords.push_back( - new mEpicsCa(epicsRecordName.c_str(), true)); - this->outletLastState.push_back(0); + this->outletSetRecords.push_back( + new mEpicsCa(epicsSetRecordName.c_str())); + + std::string epicsGetRecordName = + format(EPOWERSWITCH_SOCKET_GET_PREFIX, i); + this->outletGetRecords.push_back( + new mEpicsCa(epicsGetRecordName.c_str())); } if (this->numberOfOutlet > epicsOutletNumber) @@ -138,11 +145,13 @@ void ePowerSwitchEquipment::updateSocketNumber() { this->numberOfOutlet - epicsOutletNumber); for (int i = epicsOutletNumber; i < this->numberOfOutlet; i++) { - mEpicsCa *ptr = this->outletCommandRecords.back(); - delete ptr; + mEpicsCa *setRecord = this->outletSetRecords.back(); + delete setRecord; + mEpicsCa *getRecord = this->outletGetRecords.back(); + delete getRecord; - this->outletCommandRecords.pop_back(); - this->outletLastState.pop_back(); + this->outletSetRecords.pop_back(); + this->outletGetRecords.pop_back(); } this->numberOfOutlet = epicsOutletNumber; diff --git a/submodule/mepicsca b/submodule/mepicsca index d9e1789..abc5781 160000 --- a/submodule/mepicsca +++ b/submodule/mepicsca @@ -1 +1 @@ -Subproject commit d9e17892ba2e85beff98690d4c4b10d7b93821f3 +Subproject commit abc57815eb9992d489d30fd315f93ded52ebc5a0