From 6bac7a5e7b352124d5e1be9063cc96379b475650 Mon Sep 17 00:00:00 2001 From: Hugo Jean Ponsin Date: Thu, 30 Apr 2026 15:46:07 +0200 Subject: [PATCH] spliting in progress --- CMakeLists.txt | 67 +++++++++++++++---- .../ePowerSwitchEquipment.cpp} | 50 +------------- src/device/ePowerSwitchEquipment.h | 49 ++++++++++++++ .../device/ePowerSwitchEquipmentConfig.h | 3 - src/frontend/ePowerSwitchFrontend.cpp | 49 ++++++++++++++ src/frontend/ePowerSwitchFrontend.h | 17 +++++ src/frontend/ePowerSwitchFrontendConfig.h | 7 ++ 7 files changed, 179 insertions(+), 63 deletions(-) rename src/{ePowerSwitchFront.cpp => device/ePowerSwitchEquipment.cpp} (76%) create mode 100644 src/device/ePowerSwitchEquipment.h rename include/ePowerSwitchConfig.h => src/device/ePowerSwitchEquipmentConfig.h (75%) create mode 100644 src/frontend/ePowerSwitchFrontend.cpp create mode 100644 src/frontend/ePowerSwitchFrontend.h create mode 100644 src/frontend/ePowerSwitchFrontendConfig.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d543d87..cb5ecd8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.03) -project(ePowerSwitchFront VERSION 1.0) +project(ePowerSwitchFrontend VERSION 1.0) add_subdirectory(submodule/mepicsca) @@ -44,20 +44,32 @@ set(LIBS find_package(Midas REQUIRED) -add_executable(ePowerSwitchFront - src/ePowerSwitchFront.cpp +################################################################################ +## Device Library +################################################################################ + +add_library( + ePowerSwitchEquipment + src/device/ePowerSwitchEquipment.cpp ) set_property( TARGET - ePowerSwitchFront + ePowerSwitchEquipment PROPERTY CXX_STANDARD 17 ) +target_link_libraries( + ePowerSwitchEquipment + PRIVATE + midas::mfe + m_epics_ca + ${LIBS} +) target_include_directories( - ePowerSwitchFront + ePowerSwitchEquipment PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE @@ -68,15 +80,46 @@ target_include_directories( ${EPICSSYS}/include/compiler/clang ) -target_link_libraries(ePowerSwitchFront + + +################################################################################ +## Frontend +################################################################################ + +add_executable(ePowerSwitchFrontend + src/frontend/ePowerSwitchFrontend.cpp +) + +set_property( + TARGET + ePowerSwitchFrontend + PROPERTY + CXX_STANDARD 17 +) + + +target_include_directories( + ePowerSwitchFrontend + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE + ${EPICSSYS}/include + ${EPICSSYS}/include/os/Linux + ${EPICSSYS}/include/os/Darwin + ${EPICSSYS}/include/compiler/gcc + ${EPICSSYS}/include/compiler/clang +) + +target_link_libraries( + ePowerSwitchFrontend + PRIVATE + ePowerSwitchEquipment midas::mfe m_epics_ca ${LIBS} ) - -install( - TARGETS - ePowerSwitchFront - RUNTIME DESTINATION bin -) +# install( +# TARGETS +# ePowerSwitchFrontend +# RUNTIME DESTINATION bin +# ) diff --git a/src/ePowerSwitchFront.cpp b/src/device/ePowerSwitchEquipment.cpp similarity index 76% rename from src/ePowerSwitchFront.cpp rename to src/device/ePowerSwitchEquipment.cpp index 79ca831..42ff785 100644 --- a/src/ePowerSwitchFront.cpp +++ b/src/device/ePowerSwitchEquipment.cpp @@ -1,6 +1,5 @@ -#include "../include/ePowerSwitchFront.h" -#include "../include/ePowerSwitchConfig.h" -#include "m_epics_ca.h" +#include "ePowerSwitchEquipment.h" +#include "ePowerSwitchEquipmentConfig.h" #include "tmfe.h" #include @@ -17,45 +16,6 @@ std::string format(std::string str, int value) { return ss.str(); } -int main(int argc, char *argv[]) { - - if (argv[0][0] == '.') { - TMFE::Instance()->Msg(MERROR, __FUNCTION__, - "Relative paths are strongly discouraged; " - "please use an absolute path."); - } - - std::string frontendName; - std::string equipmentName; - - if (argc == 1) { - frontendName = DEFAULT_FRONTEND_NAME; - TMFE::Instance()->Msg(MINFO, __FUNCTION__, - "No frontend name provided; %s will be used", - DEFAULT_FRONTEND_NAME); - equipmentName = DEFAULT_EQUIPMENT_NAME; - TMFE::Instance()->Msg(MINFO, __FUNCTION__, - "No equipment name provided; %s will be used", - DEFAULT_EQUIPMENT_NAME); - } - if (argc == 2) { - frontendName = std::string(argv[1]); - argv++; - argc--; - TMFE::Instance()->Msg(MINFO, __FUNCTION__, - "No equipment name provided; %s will be use", - DEFAULT_EQUIPMENT_NAME); - } else if (argc == 3) { - frontendName = std::string(argv[1]); - equipmentName = std::string(argv[2]); - argv += 2; - argc -= 2; - } - - auto front = new ePowerSwitchFrontend(frontendName, equipmentName); - front->FeMain(argc, argv); -} - ePowerSwitchEquipment::ePowerSwitchEquipment(std::string equipmentName, const char *equipmentFileName) : TMFeEquipment(equipmentName.c_str(), equipmentFileName), @@ -203,9 +163,3 @@ void ePowerSwitchEquipment::updateSocketNumber() { this->numberOfOutlet = epicsOutletNumber; } - -ePowerSwitchFrontend::ePowerSwitchFrontend(std::string frontendName, - std::string equipmentName) { - FeSetName(frontendName.c_str()); - FeAddEquipment(new ePowerSwitchEquipment(equipmentName.c_str(), __FILE__)); -} \ No newline at end of file diff --git a/src/device/ePowerSwitchEquipment.h b/src/device/ePowerSwitchEquipment.h new file mode 100644 index 0000000..651732f --- /dev/null +++ b/src/device/ePowerSwitchEquipment.h @@ -0,0 +1,49 @@ +#ifndef EPOWERSWITCH_EQUIPMENT_H +#define EPOWERSWITCH_EQUIPMENT_H + +#include "m_epics_ca.h" +#include "tmfe.h" +#include + +class ePowerSwitchEquipment : public TMFeEquipment { + + public: + /** + * @brief constructor + * + * @param equipmentName name show on Midas for the equipment + * @param equipmentFileName file name for automatically tagged message + */ + ePowerSwitchEquipment(std::string equipmentName, + const char *equipmentFileName); + + /** + * @brief called periodically by Midas + */ + void HandlePeriodic(); + + private: + std::vector *> outletSetRecords; + std::vector *> outletGetRecords; + mEpicsCa outletNumberRecord; + int numberOfOutlet; + + /** + * @brief refresh information about the given socket ID + * + * @param socketId which socket to refresh + */ + void refreshSocket(int socketId); + + /** + * @brief refresh information about all the available sockets + */ + void refreshAllSockets(); + + /** + * @brief detect and modify the current socket pool in case of change + */ + void updateSocketNumber(); +}; + +#endif \ No newline at end of file diff --git a/include/ePowerSwitchConfig.h b/src/device/ePowerSwitchEquipmentConfig.h similarity index 75% rename from include/ePowerSwitchConfig.h rename to src/device/ePowerSwitchEquipmentConfig.h index 933e254..e0a407e 100644 --- a/include/ePowerSwitchConfig.h +++ b/src/device/ePowerSwitchEquipmentConfig.h @@ -5,7 +5,4 @@ #define EPOWERSWITCH_SOCKET_GET_PREFIX "ePowerSwitch_get_outlet_" #define EPOWERSWITCH_SOCKETNUMBER_INFO_PREFIX "ePowerSwitch_config_maxOutlet" -#define DEFAULT_FRONTEND_NAME "ePowerSwitch" -#define DEFAULT_EQUIPMENT_NAME "powerswitch" - #endif diff --git a/src/frontend/ePowerSwitchFrontend.cpp b/src/frontend/ePowerSwitchFrontend.cpp new file mode 100644 index 0000000..56ec3f8 --- /dev/null +++ b/src/frontend/ePowerSwitchFrontend.cpp @@ -0,0 +1,49 @@ +#include "ePowerSwitchFrontend.h" +#include "../device/ePowerSwitchEquipment.h" +#include "ePowerSwitchFrontendConfig.h" +#include "tmfe.h" + +int main(int argc, char *argv[]) { + + if (argv[0][0] == '.') { + TMFE::Instance()->Msg(MERROR, __FUNCTION__, + "Relative paths are strongly discouraged; " + "please use an absolute path."); + } + + std::string frontendName; + std::string equipmentName; + + if (argc == 1) { + frontendName = DEFAULT_FRONTEND_NAME; + TMFE::Instance()->Msg(MINFO, __FUNCTION__, + "No frontend name provided; %s will be used", + DEFAULT_FRONTEND_NAME); + equipmentName = DEFAULT_EQUIPMENT_NAME; + TMFE::Instance()->Msg(MINFO, __FUNCTION__, + "No equipment name provided; %s will be used", + DEFAULT_EQUIPMENT_NAME); + } + if (argc == 2) { + frontendName = std::string(argv[1]); + argv++; + argc--; + TMFE::Instance()->Msg(MINFO, __FUNCTION__, + "No equipment name provided; %s will be use", + DEFAULT_EQUIPMENT_NAME); + } else if (argc == 3) { + frontendName = std::string(argv[1]); + equipmentName = std::string(argv[2]); + argv += 2; + argc -= 2; + } + + auto front = new ePowerSwitchFrontend(frontendName, equipmentName); + front->FeMain(argc, argv); +} + +ePowerSwitchFrontend::ePowerSwitchFrontend(std::string frontendName, + std::string equipmentName) { + FeSetName(frontendName.c_str()); + FeAddEquipment(new ePowerSwitchEquipment(equipmentName.c_str(), __FILE__)); +} \ No newline at end of file diff --git a/src/frontend/ePowerSwitchFrontend.h b/src/frontend/ePowerSwitchFrontend.h new file mode 100644 index 0000000..7649d92 --- /dev/null +++ b/src/frontend/ePowerSwitchFrontend.h @@ -0,0 +1,17 @@ +#ifndef EPOWERSWITCH_FRONTEND_H +#define EPOWERSWITCH_FRONTEND_H + +#include "tmfe.h" + +class ePowerSwitchFrontend : public TMFrontend { + public: + /** + * @brief constructor + * + * @param frontendName name shown on Midas for the frontend + * @param equipmentName name shown on Midas for the equipment + */ + ePowerSwitchFrontend(std::string frontendName, std::string equipmentName); +}; + +#endif \ No newline at end of file diff --git a/src/frontend/ePowerSwitchFrontendConfig.h b/src/frontend/ePowerSwitchFrontendConfig.h new file mode 100644 index 0000000..8df2e9b --- /dev/null +++ b/src/frontend/ePowerSwitchFrontendConfig.h @@ -0,0 +1,7 @@ +#ifndef EPOWERSWITCH_CONFIG_H +#define EPOWERSWITCH_CONFIG_H + +#define DEFAULT_FRONTEND_NAME "ePowerSwitch" +#define DEFAULT_EQUIPMENT_NAME "powerswitch" + +#endif \ No newline at end of file