adding error code and retrying if cannot put value into the given record
This commit is contained in:
@@ -61,7 +61,7 @@ ePowerSwitchEquipment::ePowerSwitchEquipment(std::string equipmentName,
|
||||
const char *equipmentFileName)
|
||||
: TMFeEquipment(equipmentName.c_str(), equipmentFileName),
|
||||
outletNumberRecord(mEpicsCa<int>(
|
||||
std::string_view(EPOWERSWITCH_SOCKETNUMBER_INFO_PREFIX), true)) {
|
||||
std::string_view(EPOWERSWITCH_SOCKETNUMBER_INFO_PREFIX))) {
|
||||
fEqConfReadConfigFromOdb = false;
|
||||
fEqConfPeriodMilliSec = 1000;
|
||||
fEqConfLogHistory = 1;
|
||||
@@ -83,10 +83,15 @@ void ePowerSwitchEquipment::refreshSocket(int socketId) {
|
||||
fOdbEqVariables->RI(varname.c_str(), &midasSocketState, true);
|
||||
|
||||
if (midasSocketState != this->outletLastState.at(socketId)) {
|
||||
this->outletCommandRecords.at(socketId)->put(&midasSocketState);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
this->outletLastState.at(socketId) = midasSocketState;
|
||||
}
|
||||
|
||||
void ePowerSwitchEquipment::refreshAllSockets() {
|
||||
@@ -98,15 +103,26 @@ void ePowerSwitchEquipment::refreshAllSockets() {
|
||||
void ePowerSwitchEquipment::updateSocketNumber() {
|
||||
int epicsOutletNumber = 0;
|
||||
|
||||
if (!outletNumberRecord.connected())
|
||||
if (!outletNumberRecord.connected()) {
|
||||
fMfe->Msg(MERROR, __FUNCTION__,
|
||||
"Couldn't connect to outlet number record.");
|
||||
return;
|
||||
}
|
||||
int returnCode = outletNumberRecord.get(&epicsOutletNumber);
|
||||
|
||||
if (returnCode < 0) {
|
||||
printf("error\n");
|
||||
fMfe->Msg(MERROR, __FUNCTION__,
|
||||
"Couldn't get outlet number record. [ERROR_CODE : %d]\n "
|
||||
"skipping function execution",
|
||||
returnCode);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->numberOfOutlet < epicsOutletNumber)
|
||||
fMfe->Msg(MDEBUG, __FUNCTION__,
|
||||
"socket number increasing, creating %d new socket(s)",
|
||||
epicsOutletNumber - this->numberOfOutlet);
|
||||
|
||||
for (int i = this->numberOfOutlet; i < epicsOutletNumber; i++) {
|
||||
std::string epicsRecordName =
|
||||
format(EPOWERSWITCH_SOCKET_COMMAND_PREFIX, i);
|
||||
@@ -114,17 +130,19 @@ void ePowerSwitchEquipment::updateSocketNumber() {
|
||||
this->outletCommandRecords.push_back(
|
||||
new mEpicsCa<int>(epicsRecordName.c_str(), true));
|
||||
this->outletLastState.push_back(0);
|
||||
|
||||
printf("new socket created\n");
|
||||
}
|
||||
|
||||
if (this->numberOfOutlet > epicsOutletNumber)
|
||||
fMfe->Msg(MDEBUG, __FUNCTION__,
|
||||
"socket number decreasing, destroying %d socket(s)",
|
||||
this->numberOfOutlet - epicsOutletNumber);
|
||||
|
||||
for (int i = epicsOutletNumber; i < this->numberOfOutlet; i++) {
|
||||
mEpicsCa<int> *ptr = this->outletCommandRecords.back();
|
||||
delete ptr;
|
||||
|
||||
this->outletCommandRecords.pop_back();
|
||||
this->outletLastState.pop_back();
|
||||
printf("old socket destroyed\n");
|
||||
}
|
||||
|
||||
this->numberOfOutlet = epicsOutletNumber;
|
||||
|
||||
Reference in New Issue
Block a user