1 #include "otsdaq-components/FEInterfaces/FECommanderInterface.h"
3 #include "otsdaq/Macros/InterfacePluginMacros.h"
17 ots::FECommanderInterface::FECommanderInterface(
18 const std::string& interfaceUID,
19 const ConfigurationTree& theXDAQContextConfigTree,
20 const std::string& interfaceConfigurationPath)
21 : Socket(theXDAQContextConfigTree.getNode(interfaceConfigurationPath)
22 .getNode(
"HostIPAddress")
23 .getValue<std::string>(),
24 theXDAQContextConfigTree.getNode(interfaceConfigurationPath)
26 .getValue<unsigned int>())
27 , FEVInterface(interfaceUID, theXDAQContextConfigTree, interfaceConfigurationPath)
28 , interfaceSocket_(theXDAQContextConfigTree.getNode(interfaceConfigurationPath)
29 .getNode(
"RemoteInterfaceIPAddress")
30 .getValue<std::string>(),
31 theXDAQContextConfigTree.getNode(interfaceConfigurationPath)
32 .getNode(
"RemoteInterfacePort")
33 .getValue<unsigned int>())
34 , stateMachineName_(theXDAQContextConfigTree.getNode(interfaceConfigurationPath)
35 .getNode(
"StateMachineName")
36 .getValue<std::string>())
37 , configurationAlias_(theXDAQContextConfigTree.getNode(interfaceConfigurationPath)
38 .getNode(
"ConfigurationAlias")
39 .getValue<std::string>())
40 , onlyRunTransitions_(false)
41 , monitorRemoteAppStatus_(false)
46 universalAddressSize_ = 8;
47 universalDataSize_ = 8;
51 onlyRunTransitions_ = theXDAQContextConfigTree.getNode(interfaceConfigurationPath)
52 .getNode(
"OnlyRunTransitions")
57 __COUTV__(onlyRunTransitions_);
61 monitorRemoteAppStatus_ = theXDAQContextConfigTree.getNode(interfaceConfigurationPath)
62 .getNode(
"MonitorRemoteAppStatus")
67 __COUTV__(monitorRemoteAppStatus_);
71 expectTransitionAck_ = theXDAQContextConfigTree.getNode(interfaceConfigurationPath)
72 .getNode(
"ExpectTransitionAck")
77 __COUTV__(expectTransitionAck_);
81 if(monitorRemoteAppStatus_)
83 __COUT__ <<
"Enabling App Status checking..." << __E__;
84 std::thread([](
FECommanderInterface* s) { FECommanderInterface::AppStatusWorkLoop(s); },
this).detach();
88 __COUT__ <<
"App Status checking is disabled." << __E__;
91 std::lock_guard<std::mutex> lock(remoteAppStatusMutex_);
92 remoteAppStatus_ = SupervisorInfo::APP_STATUS_NOT_MONITORED;
98 ots::FECommanderInterface::~FECommanderInterface(
void)
100 __COUT__ <<
"Destructor" << __E__;
108 __COUT__ <<
"Started remote status checking loop..." << __E__;
111 while(!fePtr->halted_)
117 status = fePtr->sendAndReceive(fePtr->interfaceSocket_,
"GetRemoteAppStatus",
120 catch(
const std::exception& e)
122 __COUT_WARN__ <<
"No remote app status received. Trying to ignore." << __E__;
127 __COUTT__ <<
"Remote app status: " << status << __E__;
129 std::lock_guard<std::mutex> lock(fePtr->remoteAppStatusMutex_);
130 fePtr->remoteAppStatus_ =
"Remote:" + status;
132 __COUT__ <<
"Exited remote status checking loop." << __E__;
142 std::lock_guard<std::mutex> lock(remoteAppStatusMutex_);
143 return remoteAppStatus_;
147 void ots::FECommanderInterface::send(std::string buffer)
151 bool verbose =
false;
152 __FE_COUT__ <<
"Sending: '" << buffer <<
"' " <<
153 (expectTransitionAck_?
"and waiting for Ack":
"") << std::endl;
155 if(!expectTransitionAck_)
157 if(TransceiverSocket::send(interfaceSocket_, buffer, verbose) < 0)
159 __FE_SS__ <<
"Send failed to IP:Port " << interfaceSocket_.getIPAddress() <<
":"
160 << interfaceSocket_.getPort() << __E__;
166 std::string response = TransceiverSocket::sendAndReceive(interfaceSocket_, buffer,
169 if(
"Done" != response)
171 __FE_SS__ <<
"Send-and-Receive failed to remote IP:Port " << interfaceSocket_.getIPAddress() <<
":"
172 << interfaceSocket_.getPort() <<
". Here is response received from the remote target = \n'" << response <<
173 "\n'... - expecting 'Done.'" << __E__;
180 __FE_SS__ <<
"Failed to send command '" << buffer <<
"' to remote state machine. ";
185 catch(
const std::exception& e)
187 ss <<
"Here is the error: " << e.what() << __E__;
191 ss <<
"Unrecognized exception caught!" << __E__;
199 void ots::FECommanderInterface::halt(
void)
202 if(onlyRunTransitions_)
204 __FE_COUT__ <<
"Only executing run transitions - skipping Halt transition." << __E__;
209 __FE_COUTV__(inRun_);
211 send(stateMachineName_ +
",Abort");
213 send(stateMachineName_ +
",Halt");
217 void ots::FECommanderInterface::pause(
void) { send(stateMachineName_ +
",Pause"); }
220 void ots::FECommanderInterface::resume(
void) { send(stateMachineName_ +
",Resume"); }
222 void ots::FECommanderInterface::start(std::string runNumber)
225 send(stateMachineName_ +
",Start," + runNumber);
230 void ots::FECommanderInterface::stop(
void)
233 send(stateMachineName_ +
",Stop");
238 void ots::FECommanderInterface::configure(
void)
241 if(onlyRunTransitions_)
243 __FE_COUT__ <<
"Only executing run transitions - skipping Configure transition." << __E__;
247 __FE_COUT__ <<
"Configure" << __E__;
249 send(stateMachineName_ +
",Configure," + configurationAlias_);
virtual std::string getStatusProgressDetail(void) override
overriding VStateMachine::getStatusProgressDetail