3 #include "otsdaq-components/FEInterfaces/FEOtsUDPTemplateInterface.h"
4 #include "otsdaq-core/Macros/CoutMacros.h"
5 #include "otsdaq-core/Macros/InterfacePluginMacros.h"
6 #include "otsdaq-core/MessageFacility/MessageFacility.h"
11 FEOtsUDPTemplateInterface::FEOtsUDPTemplateInterface(
12 const std::string& interfaceUID,
13 const ConfigurationTree& theXDAQContextConfigTree,
14 const std::string& interfaceConfigurationPath)
15 : Socket(theXDAQContextConfigTree.getNode(interfaceConfigurationPath)
16 .getNode(
"HostIPAddress")
17 .getValue<std::string>(),
18 theXDAQContextConfigTree.getNode(interfaceConfigurationPath)
20 .getValue<unsigned int>())
21 , FEVInterface(interfaceUID, theXDAQContextConfigTree, interfaceConfigurationPath)
22 ,
OtsUDPHardware(theXDAQContextConfigTree.getNode(interfaceConfigurationPath)
23 .getNode(
"InterfaceIPAddress")
24 .getValue<std::string>(),
25 theXDAQContextConfigTree.getNode(interfaceConfigurationPath)
26 .getNode(
"InterfacePort")
27 .getValue<unsigned int>())
29 .getNode(
"FirmwareVersion")
30 .getValue<unsigned int>())
32 universalAddressSize_ = 8;
33 universalDataSize_ = 8;
40 FEVInterface::registerFEMacroFunction(
42 static_cast<FEVInterface::frontEndMacroFunction_t>(
43 &FEOtsUDPTemplateInterface::varTest2),
44 std::vector<std::string>{
"myOtherArg"},
45 std::vector<std::string>{
"myArg",
"outArg1"},
50 FEVInterface::registerFEMacroFunction(
52 static_cast<FEVInterface::frontEndMacroFunction_t>(
53 &FEOtsUDPTemplateInterface::varTest),
54 std::vector<std::string>{
"myOtherArg"},
55 std::vector<std::string>{
"myArg",
"outArg1"},
58 std::vector<frontEndMacroArg_t> argsIn;
59 __SET_ARG_IN__(
"myOtherArg", (
unsigned int)5);
61 std::vector<frontEndMacroArg_t> argsOut;
63 __FE_COUTV__(StringMacros::vectorToString(argsIn));
65 runSelfFrontEndMacro(
"varTest2", argsIn, argsOut);
67 __FE_COUTV__(StringMacros::vectorToString(argsOut));
68 __FE_COUTV__(FEVInterface::getFEMacroArgument(argsOut,
"outArg1"));
71 std::string a = FEVInterface::getFEMacroArgument(argsOut,
"myArg");
72 double b = getFEMacroArgumentValue<double>(argsOut,
"outArg1");
74 getFEMacroArgumentValue<unsigned short>(argsOut,
"outArg1");
84 FEOtsUDPTemplateInterface::~FEOtsUDPTemplateInterface(
void) {}
87 void FEOtsUDPTemplateInterface::configure(
void)
181 __FE_COUT__ <<
"configure" << __E__;
182 __FE_COUT__ <<
"Clearing receive socket buffer: " << OtsUDPHardware::clearReadSocket()
183 <<
" packets cleared." << __E__;
185 std::string sendBuffer;
186 std::string recvBuffer;
187 uint64_t readQuadWord;
190 <<
"Configuration Path Table: "
191 << theXDAQContextConfigTree_.getNode(theConfigurationPath_).getTableName() <<
"-v"
192 << theXDAQContextConfigTree_.getNode(theConfigurationPath_).getTableVersion()
195 __FE_COUT__ <<
"Interface name: "
196 << theXDAQContextConfigTree_.getNode(theConfigurationPath_) << __E__;
198 __FE_COUT__ <<
"Configured Firmware Version: "
199 << theXDAQContextConfigTree_.getNode(theConfigurationPath_)
200 .getNode(
"FirmwareVersion")
201 .getValue<
unsigned int>()
204 __FE_COUT__ <<
"Setting Destination IP: "
205 << theXDAQContextConfigTree_.getNode(theConfigurationPath_)
206 .getNode(
"StreamToIPAddress")
207 .getValue<std::string>()
209 __FE_COUT__ <<
"And Destination Port: "
210 << theXDAQContextConfigTree_.getNode(theConfigurationPath_)
211 .getNode(
"StreamToPort")
212 .getValue<
unsigned int>()
215 OtsUDPFirmwareCore::setDataDestination(
217 theXDAQContextConfigTree_.getNode(theConfigurationPath_)
218 .getNode(
"StreamToIPAddress")
219 .getValue<std::string>(),
220 theXDAQContextConfigTree_.getNode(theConfigurationPath_)
221 .getNode(
"StreamToPort")
222 .getValue<uint64_t>());
223 OtsUDPHardware::write(sendBuffer);
225 __FE_COUT__ <<
"Reading back burst dest MAC/IP/Port: " << __E__;
227 OtsUDPFirmwareCore::readDataDestinationMAC(sendBuffer);
228 OtsUDPHardware::read(sendBuffer, readQuadWord);
230 OtsUDPFirmwareCore::readDataDestinationIP(sendBuffer);
231 OtsUDPHardware::read(sendBuffer, readQuadWord);
233 OtsUDPFirmwareCore::readDataDestinationPort(sendBuffer);
234 OtsUDPHardware::read(sendBuffer, readQuadWord);
236 OtsUDPFirmwareCore::readControlDestinationPort(sendBuffer);
237 OtsUDPHardware::read(sendBuffer, readQuadWord);
240 FEVInterface::runSequenceOfCommands(
"LinkToConfigureSequence");
242 __FE_COUT__ <<
"Done with ots Template configuring." << __E__;
252 void FEOtsUDPTemplateInterface::halt(
void)
254 __FE_COUT__ <<
"\tHalt" << __E__;
259 void FEOtsUDPTemplateInterface::pause(
void)
261 __FE_COUT__ <<
"\tPause" << __E__;
266 void FEOtsUDPTemplateInterface::resume(
void)
268 __FE_COUT__ <<
"\tResume" << __E__;
273 void FEOtsUDPTemplateInterface::start(std::string)
275 __FE_COUT__ <<
"\tStart" << __E__;
294 FEVInterface::runSequenceOfCommands(
"LinkToStartSequence");
296 std::string sendBuffer;
297 OtsUDPFirmwareCore::startBurst(sendBuffer);
298 OtsUDPHardware::write(sendBuffer);
302 void FEOtsUDPTemplateInterface::stop(
void)
304 __FE_COUT__ <<
"\tStop" << __E__;
308 FEVInterface::runSequenceOfCommands(
"LinkToStopSequence");
310 std::string sendBuffer;
311 OtsUDPFirmwareCore::stopBurst(sendBuffer);
312 OtsUDPHardware::write(sendBuffer);
316 bool FEOtsUDPTemplateInterface::running(
void)
318 __FE_COUT__ <<
"\tRunning" << __E__;
324 while(WorkLoop::continueWorkLoop_)
389 void ots::FEOtsUDPTemplateInterface::universalRead(
char* address,
char* returnValue)
391 __FE_COUT__ <<
"address size " << universalAddressSize_ << __E__;
393 __FE_COUT__ <<
"Universal Read Address: 0x";
394 for(
unsigned int i = 0; i < universalAddressSize_; ++i)
395 printf(
"%2.2X", (
unsigned char)address[universalAddressSize_ - 1 - i]);
398 std::string readBuffer, sendBuffer;
399 OtsUDPFirmwareCore::readAdvanced(sendBuffer, address, 1 );
401 OtsUDPHardware::read(sendBuffer, readBuffer);
403 __FE_COUT__ <<
"Result SIZE: " << readBuffer.size() << __E__;
404 std::memcpy(returnValue, readBuffer.substr(2).c_str(), universalDataSize_);
406 __FE_COUT__ <<
"Universal Read Data: 0x";
407 for(
unsigned int i = 0; i < universalDataSize_; ++i)
408 printf(
"%2.2X", (
unsigned char)returnValue[universalDataSize_ - 1 - i]);
416 void ots::FEOtsUDPTemplateInterface::universalWrite(
char* address,
char* writeValue)
418 __FE_COUT__ <<
"address size " << universalAddressSize_ << __E__;
419 __FE_COUT__ <<
"data size " << universalDataSize_ << __E__;
420 __FE_COUT__ <<
"Universal Write Address: 0x";
421 for(
unsigned int i = 0; i < universalAddressSize_; ++i)
422 printf(
"%2.2X", (
unsigned char)address[universalAddressSize_ - 1 - i]);
424 __FE_COUT__ <<
"Universal Write Data: 0x";
425 for(
unsigned int i = 0; i < universalDataSize_; ++i)
426 printf(
"%2.2X", (
unsigned char)writeValue[universalDataSize_ - 1 - i]);
429 std::string sendBuffer;
430 OtsUDPFirmwareCore::writeAdvanced(sendBuffer, address, writeValue, 1 );
431 OtsUDPHardware::write(sendBuffer);
438 void FEOtsUDPTemplateInterface::varTest(__ARGS__)
440 __FE_COUT__ <<
"# of input args = " << argsIn.size() << __E__;
441 __FE_COUT__ <<
"# of output args = " << argsOut.size() << __E__;
442 for(
auto& argIn : argsIn)
443 __FE_COUT__ << argIn.first <<
": " << argIn.second << __E__;
447 char* address =
new char[universalAddressSize_]{
449 char* data =
new char[universalDataSize_]{
451 uint64_t macroAddress;
453 std::map<std::string , uint64_t >
457 macroAddress = 0x1002;
458 memcpy(address, ¯oAddress, 8);
459 universalRead(address, data);
460 memcpy(¯oArgs[
"myArg"], data, 8);
461 __SET_ARG_OUT__(
"myArg", macroArgs[
"myArg"]);
464 macroAddress = 0x1001;
465 memcpy(address, ¯oAddress, 8);
466 universalRead(address, data);
467 memcpy(¯oArgs[
"outArg1"], data, 8);
468 __SET_ARG_OUT__(
"outArg1", macroArgs[
"outArg1"]);
472 macroAddress = 0x1002;
473 memcpy(address, ¯oAddress, 8);
474 macroArgs[
"myOtherArg"] = __GET_ARG_IN__(
477 memcpy(data, ¯oArgs[
"myOtherArg"], 8);
478 universalWrite(address, data);
481 macroAddress = 0x1001;
485 memcpy(data, ¯oArgs[
"myArg"], 8);
486 universalWrite(address, data);
489 __FE_COUT__ <<
"Sleeping for... " << 4 <<
" milliseconds " << __E__;
496 for(
auto& argOut : argsOut)
497 __FE_COUT__ << argOut.first <<
": " << argOut.second << __E__;
505 void FEOtsUDPTemplateInterface::varTest2(__ARGS__)
507 __FE_COUT__ <<
"# of input args = " << argsIn.size() << __E__;
508 __FE_COUT__ <<
"# of output args = " << argsOut.size() << __E__;
509 for(
auto& argIn : argsIn)
510 __FE_COUT__ << argIn.first <<
": " << argIn.second << __E__;
512 __SET_ARG_OUT__(
"myArg",
"hello2");
513 uint64_t macroData = __GET_ARG_IN__(
"myOtherArg", uint64_t);
515 __SET_ARG_OUT__(
"outArg1", macroData);
517 for(
auto& argOut : argsOut)
518 __FE_COUT__ << argOut.first <<
": " << argOut.second << __E__;