adding a new field to outlet name
This commit is contained in:
@@ -4,25 +4,16 @@
|
||||
#include <sstream>
|
||||
|
||||
/**
|
||||
* @brief local function: append an integer to the end of a string.
|
||||
* @param str string prefix
|
||||
* @param value integer to append
|
||||
* @return "str" + integer
|
||||
* @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 format(std::string str, int value) {
|
||||
std::stringstream ss;
|
||||
ss << str;
|
||||
ss << 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;
|
||||
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,
|
||||
@@ -31,12 +22,11 @@ ePowerSwitchEquipment::ePowerSwitchEquipment(std::string equipmentName,
|
||||
outletNumberRecord(mEpicsCa<int>(
|
||||
std::string_view(EPOWERSWITCH_SOCKETNUMBER_INFO_PREFIX))) {
|
||||
|
||||
fEqConfReadConfigFromOdb = false; /// i don't know what this parameter does
|
||||
fEqConfPeriodMilliSec = 1000; /// refresh rate of midas frontend
|
||||
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; /// i don't know
|
||||
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;
|
||||
}
|
||||
@@ -44,19 +34,44 @@ 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 =
|
||||
format("Socket ", socketId) + std::string(" current");
|
||||
|
||||
std::string usernameVarname;
|
||||
{
|
||||
static const std::string str1 = "Socket ";
|
||||
static const std::string str2 = " name";
|
||||
usernameVarname = insert(&str1, socketId, &str2);
|
||||
}
|
||||
std::string requestedVarname;
|
||||
{
|
||||
static const std::string str1 = "|-> ";
|
||||
static const std::string str2 = " requested";
|
||||
requestedVarname = insert(&str1, socketId, &str2);
|
||||
}
|
||||
std::string currentVarname;
|
||||
{
|
||||
static const std::string str1 = "\\-> ";
|
||||
static const std::string str2 = " current";
|
||||
currentVarname = insert(&str1, socketId, &str2);
|
||||
}
|
||||
std::string midasUsername;
|
||||
{
|
||||
static const std::string str1 = "Socket ";
|
||||
static const std::string str2 = "";
|
||||
midasUsername = insert(&str1, socketId, &str2);
|
||||
}
|
||||
std::string midasRequestedSocketState = std::string("Off");
|
||||
MVOdbError ovbError;
|
||||
int mepicscaReturnCode;
|
||||
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(), &midasRequestedSocketState,
|
||||
true, midasRequestedSocketState.length() + 1,
|
||||
&ovbError);
|
||||
@@ -66,6 +81,15 @@ void ePowerSwitchEquipment::refreshSocket(int socketId) {
|
||||
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 epicsCurrentSocketState;
|
||||
mepicscaReturnCode =
|
||||
this->outletGetRecords.at(socketId)->get(&epicsCurrentSocketState);
|
||||
@@ -130,20 +154,27 @@ void ePowerSwitchEquipment::updateSocketNumber() {
|
||||
epicsOutletNumber - this->numberOfOutlet);
|
||||
|
||||
for (int i = this->numberOfOutlet; i < epicsOutletNumber; i++) {
|
||||
std::string epicsSetRecordName =
|
||||
format(EPOWERSWITCH_SOCKET_SET_PREFIX, i);
|
||||
std::string epicsSetRecordName;
|
||||
{
|
||||
static const std::string *str1 = &EPOWERSWITCH_SOCKET_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 =
|
||||
format(EPOWERSWITCH_SOCKET_GET_PREFIX, i);
|
||||
std::string epicsGetRecordName;
|
||||
{
|
||||
static const std::string *str1 = &EPOWERSWITCH_SOCKET_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()));
|
||||
|
||||
this->socketNames.push_back(getDefaultSocketName(i));
|
||||
}
|
||||
|
||||
if (this->numberOfOutlet > epicsOutletNumber)
|
||||
@@ -153,10 +184,15 @@ void ePowerSwitchEquipment::updateSocketNumber() {
|
||||
|
||||
for (int i = epicsOutletNumber; i < this->numberOfOutlet; i++) {
|
||||
|
||||
std::string requestedVarname =
|
||||
format("Socket ", i) + std::string(" requested");
|
||||
std::string currentVarname =
|
||||
format("Socket ", i) + std::string(" current");
|
||||
std::string requestedVarname;
|
||||
std::string currentVarname;
|
||||
{
|
||||
static const std::string str1 = "Socket ";
|
||||
static const std::string str2a = " current";
|
||||
static const std::string str2b = " requested";
|
||||
requestedVarname = insert(&str1, i, &str2a);
|
||||
currentVarname = insert(&str1, i, &str2b);
|
||||
}
|
||||
|
||||
MVOdbError ovbError;
|
||||
|
||||
@@ -170,31 +206,7 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,11 +45,6 @@ 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
|
||||
@@ -1,11 +1,13 @@
|
||||
#ifndef EPOWERSWITCH_CONFIG_H
|
||||
#define EPOWERSWITCH_CONFIG_H
|
||||
#include <string>
|
||||
|
||||
#define EPOWERSWITCH_SOCKET_SET_PREFIX "ePowerSwitch_set_outlet_"
|
||||
#define EPOWERSWITCH_SOCKET_GET_PREFIX "ePowerSwitch_get_outlet_"
|
||||
#define EPOWERSWITCH_SOCKETNUMBER_INFO_PREFIX "ePowerSwitch_config_maxOutlet"
|
||||
const std::string EPOWERSWITCH_SOCKET_SET_PREFIX = "ePowerSwitch_set_outlet_";
|
||||
const std::string EPOWERSWITCH_SOCKET_GET_PREFIX = "ePowerSwitch_get_outlet_";
|
||||
const std::string EPOWERSWITCH_SOCKETNUMBER_INFO_PREFIX =
|
||||
"ePowerSwitch_config_maxOutlet";
|
||||
|
||||
#define EPOWERSWITCH_DEFAULT_SOCKET_NAME "Socket "
|
||||
#define EPOWERSWITCH_SOCKET_NAME_SETTINGS "Socket n name"
|
||||
const std::string EPOWERSWITCH_DEFAULT_SOCKET_NAME = "Socket";
|
||||
const std::string EPOWERSWITCH_DEFAULT_SOCKET_STATUS = "Off";
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user