grace perriode added to prevent resetting
This commit is contained in:
+8
-7
@@ -7,7 +7,7 @@ add_subdirectory(submodule/mepicsca)
|
||||
add_compile_options(
|
||||
-Wall
|
||||
-Wformat=2
|
||||
-O3
|
||||
-g
|
||||
-Wno-format-nonliteral
|
||||
-Wno-strict-aliasing
|
||||
-Wuninitialized
|
||||
@@ -49,19 +49,20 @@ find_package(Midas REQUIRED)
|
||||
################################################################################
|
||||
|
||||
add_library(
|
||||
ePowerSwitchEquipment
|
||||
src/device/ePowerSwitchEquipment.cpp
|
||||
powerSwitch
|
||||
src/device/powerSwitch.cpp
|
||||
src/utils/outlet.cpp
|
||||
)
|
||||
|
||||
set_property(
|
||||
TARGET
|
||||
ePowerSwitchEquipment
|
||||
powerSwitch
|
||||
PROPERTY
|
||||
CXX_STANDARD 17
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
ePowerSwitchEquipment
|
||||
powerSwitch
|
||||
PRIVATE
|
||||
midas::mfe
|
||||
m_epics_ca
|
||||
@@ -69,7 +70,7 @@ target_link_libraries(
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
ePowerSwitchEquipment
|
||||
powerSwitch
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
PRIVATE
|
||||
@@ -113,7 +114,7 @@ target_include_directories(
|
||||
target_link_libraries(
|
||||
ePowerSwitchFrontend
|
||||
PRIVATE
|
||||
ePowerSwitchEquipment
|
||||
powerSwitch
|
||||
midas::mfe
|
||||
m_epics_ca
|
||||
${LIBS}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
#ifndef EPOWERSWITCH_FRONTEND_H
|
||||
#define EPOWERSWITCH_FRONTEND_H
|
||||
|
||||
#include "m_epics_ca.h"
|
||||
#include "tmfe.h"
|
||||
#include <vector>
|
||||
|
||||
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<mEpicsCa<std::string> *> outletSetRecords;
|
||||
std::vector<mEpicsCa<std::string> *> outletGetRecords;
|
||||
mEpicsCa<int> 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();
|
||||
};
|
||||
|
||||
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
|
||||
@@ -1,217 +0,0 @@
|
||||
#include "ePowerSwitchEquipment.h"
|
||||
#include "ePowerSwitchEquipmentConfig.h"
|
||||
#include "tmfe.h"
|
||||
#include <sstream>
|
||||
|
||||
/**
|
||||
* @brief Insert a integer value between two string
|
||||
* @param str1 first string
|
||||
* @param int value to insert
|
||||
* @param str2 second string
|
||||
*
|
||||
* @return a new string instance
|
||||
*/
|
||||
std::string insert(const std::string *str1, int value,
|
||||
const std::string *str2) {
|
||||
return *str1 + std::to_string(value) + *str2;
|
||||
}
|
||||
|
||||
ePowerSwitchEquipment::ePowerSwitchEquipment(std::string equipmentName,
|
||||
const char *equipmentFileName)
|
||||
: TMFeEquipment(equipmentName.c_str(), equipmentFileName),
|
||||
outletNumberRecord(mEpicsCa<int>(
|
||||
std::string_view(EPOWERSWITCH_OUTLETNUMBER_INFO_PREFIX))) {
|
||||
|
||||
fEqConfPeriodMilliSec = 1000; // refresh rate of midas frontend
|
||||
fEqConfLogHistory =
|
||||
60; // enable history system, generate one event per minutes
|
||||
fEqConfReadOnlyWhenRunning = false; // allow to write values when running
|
||||
fEqConfWriteEventsToOdb = true; // allow to write event to the odb
|
||||
|
||||
this->numberOfOutlet = 0;
|
||||
}
|
||||
|
||||
void ePowerSwitchEquipment::HandlePeriodic() {
|
||||
updateOutletNumber();
|
||||
refreshAllOutlets();
|
||||
}
|
||||
|
||||
void ePowerSwitchEquipment::refreshOutlet(int outletId) {
|
||||
|
||||
std::string usernameVarname;
|
||||
{
|
||||
static const std::string str1 = "Outlet ";
|
||||
static const std::string str2 = " name";
|
||||
usernameVarname = insert(&str1, outletId + 1, &str2);
|
||||
}
|
||||
std::string requestedVarname;
|
||||
{
|
||||
static const std::string str1 = "|-> ";
|
||||
static const std::string str2 = " requested";
|
||||
requestedVarname = insert(&str1, outletId + 1, &str2);
|
||||
}
|
||||
std::string currentVarname;
|
||||
{
|
||||
static const std::string str1 = "\\-> ";
|
||||
static const std::string str2 = " current";
|
||||
currentVarname = insert(&str1, outletId + 1, &str2);
|
||||
}
|
||||
std::string midasUsername;
|
||||
{
|
||||
static const std::string str1 = "Outlet ";
|
||||
static const std::string str2 = "";
|
||||
midasUsername = insert(&str1, outletId, &str2);
|
||||
}
|
||||
std::string midasRequestedOutletState = std::string("Off");
|
||||
MVOdbError ovbError;
|
||||
fOdbEqVariables->RS(usernameVarname.c_str(), &midasUsername, true,
|
||||
midasUsername.length() + 1, &ovbError);
|
||||
if (ovbError.fError) {
|
||||
fMfe->Msg(MERROR, __FUNCTION__, ovbError.fErrorString);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
fOdbEqVariables->RS(requestedVarname.c_str(), &midasRequestedOutletState,
|
||||
true, midasRequestedOutletState.length() + 1,
|
||||
&ovbError);
|
||||
|
||||
if (ovbError.fError) {
|
||||
fMfe->Msg(MERROR, __FUNCTION__, ovbError.fErrorString);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::string defaultCurrentState = "unknow";
|
||||
fOdbEqVariables->RS(currentVarname.c_str(), &defaultCurrentState, true,
|
||||
defaultCurrentState.length() + 1, &ovbError);
|
||||
|
||||
if (ovbError.fError) {
|
||||
fMfe->Msg(MERROR, __FUNCTION__, ovbError.fErrorString);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::string epicsCurrentOutletState;
|
||||
int mepicscaReturnCode =
|
||||
this->outletGetRecords.at(outletId)->get(&epicsCurrentOutletState);
|
||||
|
||||
if (mepicscaReturnCode != CM_SUCCESS)
|
||||
return;
|
||||
|
||||
if (epicsCurrentOutletState != midasRequestedOutletState) {
|
||||
mepicscaReturnCode = this->outletSetRecords.at(outletId)->put(
|
||||
&midasRequestedOutletState);
|
||||
|
||||
if (mepicscaReturnCode != CM_SUCCESS)
|
||||
return;
|
||||
}
|
||||
|
||||
fOdbEqVariables->WS(currentVarname.c_str(), epicsCurrentOutletState.c_str(),
|
||||
epicsCurrentOutletState.length() + 1, &ovbError);
|
||||
|
||||
if (ovbError.fError) {
|
||||
fMfe->Msg(MERROR, __FUNCTION__, ovbError.fErrorString);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
void ePowerSwitchEquipment::refreshAllOutlets() {
|
||||
for (int i = 0; i < this->numberOfOutlet; i++) {
|
||||
refreshOutlet(i);
|
||||
}
|
||||
}
|
||||
|
||||
void ePowerSwitchEquipment::updateOutletNumber() {
|
||||
int epicsOutletNumber = 0;
|
||||
|
||||
int returnCode = outletNumberRecord.get(&epicsOutletNumber);
|
||||
|
||||
if (returnCode != CM_SUCCESS)
|
||||
return;
|
||||
|
||||
if (this->numberOfOutlet < epicsOutletNumber)
|
||||
fMfe->Msg(MDEBUG, __FUNCTION__,
|
||||
"Outlet number increasing, creating %d new outlet(s)",
|
||||
epicsOutletNumber - this->numberOfOutlet);
|
||||
|
||||
/*
|
||||
This for loop will only iterate if the condition on top of this
|
||||
comment is true
|
||||
*/
|
||||
for (int i = this->numberOfOutlet; i < epicsOutletNumber; i++) {
|
||||
std::string epicsSetRecordName;
|
||||
{
|
||||
static const std::string *str1 = &EPOWERSWITCH_OUTLET_SET_PREFIX;
|
||||
static const std::string str2 = "";
|
||||
epicsSetRecordName = insert(str1, i, &str2);
|
||||
}
|
||||
|
||||
this->outletSetRecords.push_back(
|
||||
std::make_unique<mEpicsCa<std::string>>(
|
||||
epicsSetRecordName.c_str()));
|
||||
|
||||
std::string epicsGetRecordName;
|
||||
{
|
||||
static const std::string *str1 = &EPOWERSWITCH_OUTLET_GET_PREFIX;
|
||||
static const std::string str2 = "";
|
||||
epicsGetRecordName = insert(str1, i, &str2);
|
||||
}
|
||||
|
||||
this->outletGetRecords.push_back(
|
||||
std::make_unique<mEpicsCa<std::string>>(
|
||||
epicsGetRecordName.c_str()));
|
||||
}
|
||||
|
||||
if (this->numberOfOutlet > epicsOutletNumber)
|
||||
fMfe->Msg(MDEBUG, __FUNCTION__,
|
||||
"Outlet number decreasing, destroying %d outlet(s)",
|
||||
this->numberOfOutlet - epicsOutletNumber);
|
||||
/*
|
||||
This for loop will only iterate if the condition on top of this
|
||||
comment is true
|
||||
*/
|
||||
for (int i = epicsOutletNumber; i < this->numberOfOutlet; i++) {
|
||||
|
||||
std::string usernameVarname;
|
||||
{
|
||||
static const std::string str1 = "Outlet ";
|
||||
static const std::string str2 = " name";
|
||||
usernameVarname = insert(&str1, i + 1, &str2);
|
||||
}
|
||||
std::string requestedVarname;
|
||||
{
|
||||
static const std::string str1 = "|-> ";
|
||||
static const std::string str2 = " requested";
|
||||
requestedVarname = insert(&str1, i + 1, &str2);
|
||||
}
|
||||
std::string currentVarname;
|
||||
{
|
||||
static const std::string str1 = "\\-> ";
|
||||
static const std::string str2 = " current";
|
||||
currentVarname = insert(&str1, i + 1, &str2);
|
||||
}
|
||||
|
||||
MVOdbError ovbError;
|
||||
|
||||
fOdbEqVariables->Delete(usernameVarname.c_str(), &ovbError);
|
||||
if (ovbError.fError) {
|
||||
fMfe->Msg(MERROR, __FUNCTION__, ovbError.fErrorString);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
fOdbEqVariables->Delete(requestedVarname.c_str(), &ovbError);
|
||||
if (ovbError.fError) {
|
||||
fMfe->Msg(MERROR, __FUNCTION__, ovbError.fErrorString);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
fOdbEqVariables->Delete(currentVarname.c_str(), &ovbError);
|
||||
if (ovbError.fError) {
|
||||
fMfe->Msg(MERROR, __FUNCTION__, ovbError.fErrorString);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
this->outletSetRecords.pop_back();
|
||||
this->outletGetRecords.pop_back();
|
||||
}
|
||||
|
||||
this->numberOfOutlet = epicsOutletNumber;
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
#ifndef EPOWERSWITCH_EQUIPMENT_H
|
||||
#define EPOWERSWITCH_EQUIPMENT_H
|
||||
|
||||
#include "m_epics_ca.h"
|
||||
#include "tmfe.h"
|
||||
#include <vector>
|
||||
|
||||
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<std::unique_ptr<mEpicsCa<std::string>>> outletSetRecords;
|
||||
std::vector<std::unique_ptr<mEpicsCa<std::string>>> outletGetRecords;
|
||||
std::vector<std::string> outletNames;
|
||||
mEpicsCa<int> outletNumberRecord;
|
||||
int numberOfOutlet;
|
||||
|
||||
/**
|
||||
* @brief refresh information about the given outlet ID
|
||||
*
|
||||
* @param outletId which outlet to refresh
|
||||
*/
|
||||
void refreshOutlet(int outletId);
|
||||
|
||||
/**
|
||||
* @brief refresh information about all the available outlets
|
||||
*/
|
||||
void refreshAllOutlets();
|
||||
|
||||
/**
|
||||
* @brief detect and modify the current outlet pool in case of change
|
||||
*/
|
||||
void updateOutletNumber();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,13 +0,0 @@
|
||||
#ifndef EPOWERSWITCH_CONFIG_H
|
||||
#define EPOWERSWITCH_CONFIG_H
|
||||
#include <string>
|
||||
|
||||
const std::string EPOWERSWITCH_OUTLET_SET_PREFIX = "ePowerSwitch_set_outlet_";
|
||||
const std::string EPOWERSWITCH_OUTLET_GET_PREFIX = "ePowerSwitch_get_outlet_";
|
||||
const std::string EPOWERSWITCH_OUTLETNUMBER_INFO_PREFIX =
|
||||
"ePowerSwitch_config_maxOutlet";
|
||||
|
||||
const std::string EPOWERSWITCH_DEFAULT_OUTLET_NAME = "Outlet";
|
||||
const std::string EPOWERSWITCH_DEFAULT_OUTLET_STATUS = "Off";
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "ePowerSwitchFrontend.h"
|
||||
#include "../device/ePowerSwitchEquipment.h"
|
||||
#include "../device/powerSwitch.h"
|
||||
#include "ePowerSwitchFrontendConfig.h"
|
||||
#include "tmfe.h"
|
||||
|
||||
@@ -45,5 +45,5 @@ int main(int argc, char *argv[]) {
|
||||
ePowerSwitchFrontend::ePowerSwitchFrontend(std::string frontendName,
|
||||
std::string equipmentName) {
|
||||
FeSetName(frontendName.c_str());
|
||||
FeAddEquipment(new ePowerSwitchEquipment(equipmentName.c_str(), __FILE__));
|
||||
FeAddEquipment(new powerSwitch(equipmentName.c_str(), __FILE__));
|
||||
}
|
||||
+1
-1
Submodule submodule/mepicsca updated: 419df88dde...b6aca4174e
Reference in New Issue
Block a user