1 #include "otsdaq-components/FEInterfaces/FEOtsUDPTemplateInterface.h"
2 #include "otsdaq-core/MessageFacility/MessageFacility.h"
3 #include "otsdaq-core/Macros/CoutMacros.h"
4 #include "otsdaq-core/Macros/InterfacePluginMacros.h"
11 #define __MF_SUBJECT__ "FE-FEOtsUDPTemplateInterface"
14 FEOtsUDPTemplateInterface::FEOtsUDPTemplateInterface(
const std::string& interfaceUID,
const ConfigurationTree& theXDAQContextConfigTree,
const std::string& interfaceConfigurationPath)
16 theXDAQContextConfigTree.getNode(interfaceConfigurationPath).getNode(
"HostIPAddress").getValue<std::string>()
17 , theXDAQContextConfigTree.getNode(interfaceConfigurationPath).getNode(
"HostPort").getValue<unsigned int>())
18 , FEVInterface (interfaceUID, theXDAQContextConfigTree, interfaceConfigurationPath)
19 ,
OtsUDPHardware (theXDAQContextConfigTree.getNode(interfaceConfigurationPath).getNode(
"InterfaceIPAddress").getValue<std::string>()
20 , theXDAQContextConfigTree.getNode(interfaceConfigurationPath).getNode(
"InterfacePort").getValue<unsigned int>())
21 ,
OtsUDPFirmwareDataGen(theXDAQContextConfigTree.getNode(interfaceConfigurationPath).getNode(
"FirmwareVersion").getValue<unsigned int>())
23 universalAddressSize_ = 8;
24 universalDataSize_ = 8;
28 FEOtsUDPTemplateInterface::~FEOtsUDPTemplateInterface(
void)
32 void FEOtsUDPTemplateInterface::configure(
void)
34 __CFG_COUT__ <<
"configure" << std::endl;
35 __CFG_COUT__ <<
"Clearing receive socket buffer: " << OtsUDPHardware::clearReadSocket() <<
" packets cleared." << std::endl;
37 std::string sendBuffer;
38 std::string recvBuffer;
39 uint64_t readQuadWord;
41 __CFG_COUT__ <<
"Configuration Path Table: " <<
42 theXDAQContextConfigTree_.getNode(theConfigurationPath_).getConfigurationName() <<
44 theXDAQContextConfigTree_.getNode(theConfigurationPath_).getConfigurationVersion() <<
47 __CFG_COUT__ <<
"Interface name: " <<
48 theXDAQContextConfigTree_.getNode(theConfigurationPath_) << __E__;
50 __CFG_COUT__ <<
"Configured Firmware Version: " <<
51 theXDAQContextConfigTree_.getNode(theConfigurationPath_).getNode(
"FirmwareVersion").getValue<
unsigned int>()
54 __CFG_COUT__ <<
"Setting Destination IP: " <<
55 theXDAQContextConfigTree_.getNode(theConfigurationPath_).getNode(
"StreamToIPAddress").getValue<std::string>()
57 __CFG_COUT__ <<
"And Destination Port: " <<
58 theXDAQContextConfigTree_.getNode(theConfigurationPath_).getNode(
"StreamToPort").getValue<
unsigned int>()
61 OtsUDPFirmwareCore::setDataDestination(sendBuffer,
62 theXDAQContextConfigTree_.getNode(theConfigurationPath_).getNode(
"StreamToIPAddress").getValue<std::string>(),
63 theXDAQContextConfigTree_.getNode(theConfigurationPath_).getNode(
"StreamToPort").getValue<uint64_t>()
65 OtsUDPHardware::write(sendBuffer);
67 __CFG_COUT__ <<
"Reading back burst dest MAC/IP/Port: " << std::endl;
69 OtsUDPFirmwareCore::readDataDestinationMAC(sendBuffer);
70 OtsUDPHardware::read(sendBuffer,readQuadWord);
72 OtsUDPFirmwareCore::readDataDestinationIP(sendBuffer);
73 OtsUDPHardware::read(sendBuffer,readQuadWord);
75 OtsUDPFirmwareCore::readDataDestinationPort(sendBuffer);
76 OtsUDPHardware::read(sendBuffer,readQuadWord);
80 OtsUDPFirmwareCore::readControlDestinationPort(sendBuffer);
81 OtsUDPHardware::read(sendBuffer,readQuadWord);
84 FEVInterface::runSequenceOfCommands(
"LinkToConfigureSequence");
86 __CFG_COUT__ <<
"Done with ots Template configuring." << std::endl;
96 void FEOtsUDPTemplateInterface::halt(
void)
98 __CFG_COUT__ <<
"\tHalt" << std::endl;
103 void FEOtsUDPTemplateInterface::pause(
void)
105 __CFG_COUT__ <<
"\tPause" << std::endl;
110 void FEOtsUDPTemplateInterface::resume(
void)
112 __CFG_COUT__ <<
"\tResume" << std::endl;
117 void FEOtsUDPTemplateInterface::start(std::string )
119 __CFG_COUT__ <<
"\tStart" << std::endl;
123 FEVInterface::runSequenceOfCommands(
"LinkToStartSequence");
125 std::string sendBuffer;
126 OtsUDPFirmwareCore::startBurst(sendBuffer);
127 OtsUDPHardware::write(sendBuffer);
131 void FEOtsUDPTemplateInterface::stop(
void)
133 __CFG_COUT__ <<
"\tStop" << std::endl;
137 FEVInterface::runSequenceOfCommands(
"LinkToStopSequence");
139 std::string sendBuffer;
140 OtsUDPFirmwareCore::stopBurst(sendBuffer);
141 OtsUDPHardware::write(sendBuffer);
145 bool FEOtsUDPTemplateInterface::running(
void)
147 __CFG_COUT__ <<
"\tRunning" << std::endl;
150 while(WorkLoop::continueWorkLoop_)
208 int ots::FEOtsUDPTemplateInterface::universalRead(
char *address,
char *returnValue)
210 __CFG_COUT__ <<
"address size " << universalAddressSize_ << std::endl;
212 __CFG_COUT__ <<
"Request: ";
213 for(
unsigned int i=0;i<universalAddressSize_;++i)
214 printf(
"%2.2X",(
unsigned char)address[i]);
215 std::cout << std::endl;
217 std::string readBuffer, sendBuffer;
218 OtsUDPFirmwareCore::readAdvanced(sendBuffer,address,1 );
223 OtsUDPHardware::read(sendBuffer, readBuffer);
225 catch(std::runtime_error &e)
227 __CFG_COUT__ <<
"Caught it! This is when it's getting time out error" << std::endl;
228 __CFG_COUT_ERR__ << e.what() << std::endl;
232 __CFG_COUT__ <<
"Result SIZE: " << readBuffer.size() << std::endl;
233 std::memcpy(returnValue,readBuffer.substr(2).c_str(),universalDataSize_);
240 void ots::FEOtsUDPTemplateInterface::universalWrite(
char* address,
char* writeValue)
242 __CFG_COUT__ <<
"address size " << universalAddressSize_ << std::endl;
243 __CFG_COUT__ <<
"data size " << universalDataSize_ << std::endl;
244 __CFG_COUT__ <<
"Sending: ";
245 for(
unsigned int i=0;i<universalAddressSize_;++i)
246 printf(
"%2.2X",(
unsigned char)address[i]);
247 std::cout << std::endl;
249 std::string sendBuffer;
250 OtsUDPFirmwareCore::writeAdvanced(sendBuffer,address,writeValue,1 );
251 OtsUDPHardware::write(sendBuffer);