3 #include "otsdaq-demo/FEInterfaces/myNewInterface.h"
4 #include "otsdaq/Macros/CoutMacros.h"
5 #include "otsdaq/Macros/InterfacePluginMacros.h"
6 #include "otsdaq/MessageFacility/MessageFacility.h"
11 #define __MF_SUBJECT__ "FE-myNewInterface"
14 myNewInterface::myNewInterface(
const std::string& interfaceUID,
15 const ConfigurationTree& theXDAQContextConfigTree,
16 const std::string& interfaceConfigurationPath)
17 : Socket(theXDAQContextConfigTree.getNode(interfaceConfigurationPath)
18 .getNode(
"HostIPAddress")
19 .getValue<std::string>(),
20 theXDAQContextConfigTree.getNode(interfaceConfigurationPath)
22 .getValue<unsigned int>())
23 , FEOtsUDPTemplateInterface(
24 interfaceUID, theXDAQContextConfigTree, interfaceConfigurationPath)
27 registerFEMacroFunction(
29 static_cast<FEVInterface::frontEndMacroFunction_t>(
30 &myNewInterface::testFunction),
31 std::vector<std::string>{
"arg1",
"arg2",
"arg3"},
32 std::vector<std::string>{
"oarg1",
"oarg2"},
34 registerFEMacroFunction(
36 static_cast<FEVInterface::frontEndMacroFunction_t>(&myNewInterface::testFunction),
37 std::vector<std::string>{
"targ1"},
38 std::vector<std::string>{
"toarg1"},
41 std::vector<frontEndMacroInArg_t> argsIn;
42 argsIn.push_back(frontEndMacroInArg_t(
"arg1",
"val1"));
43 argsIn.push_back(frontEndMacroInArg_t(
"arg2",
"val2"));
44 argsIn.push_back(frontEndMacroInArg_t(
"arg3",
"val3"));
46 __COUT__ << std::endl;
47 __COUT__ << argsIn[0].first << std::endl;
49 __COUT__ << std::endl;
51 __COUT__ << __COUT_HDR_P__ <<
"# of args = " << argsIn.size() << std::endl;
52 for(
auto& argIn : argsIn)
53 __COUT__ << argIn.first <<
": " << argIn.second << std::endl;
55 std::vector<std::string> returnStrings;
56 std::vector<frontEndMacroOutArg_t> argsOut;
58 std::string outputArgs =
"oarg1,oarg2,";
60 std::istringstream inputStream(outputArgs);
62 while(getline(inputStream, argName,
','))
64 __COUT__ <<
"argName " << argName << std::endl;
66 returnStrings.push_back(std::string(
"test"));
67 argsOut.push_back(FEVInterface::frontEndMacroOutArg_t(
68 argName, returnStrings[returnStrings.size() - 1]));
75 auto mapOfFEMacroIt = mapOfFEMacroFunctions_.find(
"testFunction");
76 if(mapOfFEMacroIt != mapOfFEMacroFunctions_.end())
78 (this->*(mapOfFEMacroIt->second.macroFunction_))(argsIn, argsOut);
79 __COUT__ <<
"Made it " << std::endl;
80 for(
auto& arg : argsOut)
81 __COUT__ << arg.first <<
": " << arg.second << std::endl;
89 myNewInterface::~myNewInterface(
void) {}
92 void myNewInterface::testFunction(__ARGS__)
95 << __COUT_HDR_P__ <<
"# of input args = " << argsIn.size() << std::endl;
97 << __COUT_HDR_P__ <<
"# of output args = " << argsOut.size() << std::endl;
98 for(
auto& argIn : argsIn)
99 __COUT__ << argIn.first <<
": " << argIn.second << std::endl;
120 for(
unsigned int i = 0; i < argsOut.size(); ++i)
121 argsOut[i].second = argsOut[i].first +
"-NewValue";
125 void myNewInterface::configure(
void)
127 __COUT__ <<
"configure" << std::endl;
128 __COUT__ <<
"Clearing receive socket buffer: " << OtsUDPHardware::clearReadSocket()
129 <<
" packets cleared." << std::endl;
131 std::string writeBuffer;
134 __COUT__ <<
"Setting Destination IP: "
135 << theXDAQContextConfigTree_.getNode(theConfigurationPath_)
136 .getNode(
"StreamToIPAddress")
137 .getValue<std::string>()
139 __COUT__ <<
"And Destination Port: "
140 << theXDAQContextConfigTree_.getNode(theConfigurationPath_)
141 .getNode(
"StreamToPort")
142 .getValue<
unsigned int>()
145 writeBuffer.resize(0);
146 OtsUDPFirmwareCore::setDataDestination(
148 theXDAQContextConfigTree_.getNode(theConfigurationPath_)
149 .getNode(
"StreamToIPAddress")
150 .getValue<std::string>(),
151 theXDAQContextConfigTree_.getNode(theConfigurationPath_)
152 .getNode(
"StreamToPort")
153 .getValue<uint64_t>());
154 OtsUDPHardware::write(writeBuffer);
183 __COUT__ <<
"Done with configuring." << std::endl;
193 void myNewInterface::halt(
void)
195 __COUT__ <<
"\tHalt" << std::endl;
200 void myNewInterface::pause(
void)
202 __COUT__ <<
"\tPause" << std::endl;
207 void myNewInterface::resume(
void)
209 __COUT__ <<
"\tResume" << std::endl;
214 void myNewInterface::start(std::string)
216 __COUT__ <<
"\tStart" << std::endl;
217 OtsUDPHardware::write(OtsUDPFirmware::startBurst());
221 void myNewInterface::stop(
void)
223 __COUT__ <<
"\tStop" << std::endl;
224 OtsUDPHardware::write(OtsUDPFirmware::stopBurst());
228 bool myNewInterface::running(
void)
230 __COUT__ <<
"\running" << std::endl;
235 bool flashLEDsWhileRunning =
false;
236 if(flashLEDsWhileRunning)
238 std::string writeBuffer;
240 while(WorkLoop::continueWorkLoop_)
248 writeBuffer.resize(0);
249 OtsUDPFirmware::write(writeBuffer, 0x1003, 1 << state);
250 OtsUDPHardware::write(writeBuffer);
252 else if(state % 2 == 1 && state < 11)
254 writeBuffer.resize(0);
255 OtsUDPFirmware::write(writeBuffer, 0x1003, 0xFF);
256 OtsUDPHardware::write(writeBuffer);
258 else if(state % 2 == 0 && state < 11)
260 writeBuffer.resize(0);
261 OtsUDPFirmware::write(writeBuffer, 0x1003, 0);
262 OtsUDPHardware::write(writeBuffer);
277 int ots::myNewInterface::universalRead(
char* address,
char* returnValue)
279 __COUT__ <<
"address size " << universalAddressSize_ << std::endl;
281 __COUT__ <<
"Request: ";
282 for(
unsigned int i = 0; i < universalAddressSize_; ++i)
283 printf(
"%2.2X", (
unsigned char)address[i]);
284 std::cout << std::endl;
286 std::string readBuffer(universalDataSize_, 0);
289 if(OtsUDPHardware::read(OtsUDPFirmware::universalRead(address), readBuffer) <
292 __COUT__ <<
"Caught it! This is when it's getting time out error" << std::endl;
295 __COUT__ <<
"Result SIZE: " << readBuffer.size() << std::endl;
296 std::memcpy(returnValue, readBuffer.substr(2).c_str(), universalDataSize_);
303 void ots::myNewInterface::universalWrite(
char* address,
char* writeValue)
305 __COUT__ <<
"address size " << universalAddressSize_ << std::endl;
306 __COUT__ <<
"data size " << universalDataSize_ << std::endl;
307 __COUT__ <<
"Sending: ";
308 for(
unsigned int i = 0; i < universalAddressSize_; ++i)
309 printf(
"%2.2X", (
unsigned char)address[i]);
310 std::cout << std::endl;
312 OtsUDPHardware::write(
313 OtsUDPFirmware::universalWrite(address, writeValue));