00001 #include "otsdaq-components/FEInterfaces/FEOtsUDPTemplateInterface.h"
00002 #include "otsdaq-core/MessageFacility/MessageFacility.h"
00003 #include "otsdaq-core/Macros/CoutMacros.h"
00004 #include "otsdaq-core/Macros/InterfacePluginMacros.h"
00005 #include <iostream>
00006 #include <set>
00007
00008 using namespace ots;
00009
00010 #undef __MF_SUBJECT__
00011 #define __MF_SUBJECT__ "FE-FEOtsUDPTemplateInterface"
00012
00013
00014 FEOtsUDPTemplateInterface::FEOtsUDPTemplateInterface(const std::string& interfaceUID, const ConfigurationTree& theXDAQContextConfigTree, const std::string& interfaceConfigurationPath)
00015 : Socket (
00016 theXDAQContextConfigTree.getNode(interfaceConfigurationPath).getNode("HostIPAddress").getValue<std::string>()
00017 , theXDAQContextConfigTree.getNode(interfaceConfigurationPath).getNode("HostPort").getValue<unsigned int>())
00018 , FEVInterface (interfaceUID, theXDAQContextConfigTree, interfaceConfigurationPath)
00019 , OtsUDPHardware (theXDAQContextConfigTree.getNode(interfaceConfigurationPath).getNode("InterfaceIPAddress").getValue<std::string>()
00020 , theXDAQContextConfigTree.getNode(interfaceConfigurationPath).getNode("InterfacePort").getValue<unsigned int>())
00021 , OtsUDPFirmwareDataGen(theXDAQContextConfigTree.getNode(interfaceConfigurationPath).getNode("FirmwareVersion").getValue<unsigned int>())
00022 {
00023 universalAddressSize_ = 8;
00024 universalDataSize_ = 8;
00025 }
00026
00027
00028 FEOtsUDPTemplateInterface::~FEOtsUDPTemplateInterface(void)
00029 {}
00030
00031
00032 void FEOtsUDPTemplateInterface::configure(void)
00033 {
00034 __CFG_COUT__ << "configure" << std::endl;
00035 __CFG_COUT__ << "Clearing receive socket buffer: " << OtsUDPHardware::clearReadSocket() << " packets cleared." << std::endl;
00036
00037 std::string sendBuffer;
00038 std::string recvBuffer;
00039 uint64_t readQuadWord;
00040
00041 __CFG_COUT__ << "Configuration Path Table: " <<
00042 theXDAQContextConfigTree_.getNode(theConfigurationPath_).getConfigurationName() <<
00043 "-v" <<
00044 theXDAQContextConfigTree_.getNode(theConfigurationPath_).getConfigurationVersion() <<
00045 std::endl;
00046
00047 __CFG_COUT__ << "Interface name: " <<
00048 theXDAQContextConfigTree_.getNode(theConfigurationPath_) << __E__;
00049
00050 __CFG_COUT__ << "Configured Firmware Version: " <<
00051 theXDAQContextConfigTree_.getNode(theConfigurationPath_).getNode("FirmwareVersion").getValue<unsigned int>()
00052 << std::endl;
00053
00054 __CFG_COUT__ << "Setting Destination IP: " <<
00055 theXDAQContextConfigTree_.getNode(theConfigurationPath_).getNode("StreamToIPAddress").getValue<std::string>()
00056 << std::endl;
00057 __CFG_COUT__ << "And Destination Port: " <<
00058 theXDAQContextConfigTree_.getNode(theConfigurationPath_).getNode("StreamToPort").getValue<unsigned int>()
00059 << std::endl;
00060
00061 OtsUDPFirmwareCore::setDataDestination(sendBuffer,
00062 theXDAQContextConfigTree_.getNode(theConfigurationPath_).getNode("StreamToIPAddress").getValue<std::string>(),
00063 theXDAQContextConfigTree_.getNode(theConfigurationPath_).getNode("StreamToPort").getValue<uint64_t>()
00064 );
00065 OtsUDPHardware::write(sendBuffer);
00066
00067 __CFG_COUT__ << "Reading back burst dest MAC/IP/Port: " << std::endl;
00068
00069 OtsUDPFirmwareCore::readDataDestinationMAC(sendBuffer);
00070 OtsUDPHardware::read(sendBuffer,readQuadWord);
00071
00072 OtsUDPFirmwareCore::readDataDestinationIP(sendBuffer);
00073 OtsUDPHardware::read(sendBuffer,readQuadWord);
00074
00075 OtsUDPFirmwareCore::readDataDestinationPort(sendBuffer);
00076 OtsUDPHardware::read(sendBuffer,readQuadWord);
00077
00078
00079
00080 OtsUDPFirmwareCore::readControlDestinationPort(sendBuffer);
00081 OtsUDPHardware::read(sendBuffer,readQuadWord);
00082
00083
00084 FEVInterface::runSequenceOfCommands("LinkToConfigureSequence");
00085
00086 __CFG_COUT__ << "Done with ots Template configuring." << std::endl;
00087 }
00088
00089
00090
00091
00092
00093
00094
00095
00096 void FEOtsUDPTemplateInterface::halt(void)
00097 {
00098 __CFG_COUT__ << "\tHalt" << std::endl;
00099 stop();
00100 }
00101
00102
00103 void FEOtsUDPTemplateInterface::pause(void)
00104 {
00105 __CFG_COUT__ << "\tPause" << std::endl;
00106 stop();
00107 }
00108
00109
00110 void FEOtsUDPTemplateInterface::resume(void)
00111 {
00112 __CFG_COUT__ << "\tResume" << std::endl;
00113 start("");
00114 }
00115
00116
00117 void FEOtsUDPTemplateInterface::start(std::string )
00118 {
00119 __CFG_COUT__ << "\tStart" << std::endl;
00120
00121
00122
00123 FEVInterface::runSequenceOfCommands("LinkToStartSequence");
00124
00125 std::string sendBuffer;
00126 OtsUDPFirmwareCore::startBurst(sendBuffer);
00127 OtsUDPHardware::write(sendBuffer);
00128 }
00129
00130
00131 void FEOtsUDPTemplateInterface::stop(void)
00132 {
00133 __CFG_COUT__ << "\tStop" << std::endl;
00134
00135
00136
00137 FEVInterface::runSequenceOfCommands("LinkToStopSequence");
00138
00139 std::string sendBuffer;
00140 OtsUDPFirmwareCore::stopBurst(sendBuffer);
00141 OtsUDPHardware::write(sendBuffer);
00142 }
00143
00144
00145 bool FEOtsUDPTemplateInterface::running(void)
00146 {
00147 __CFG_COUT__ << "\tRunning" << std::endl;
00148
00149 int state = -1;
00150 while(WorkLoop::continueWorkLoop_)
00151 {
00152
00153
00154
00155 ++state;
00156 if(state < 8)
00157 sleep(1);
00158 else
00159 break;
00160 }
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 return false;
00203 }
00204
00205
00206
00207
00208 int ots::FEOtsUDPTemplateInterface::universalRead(char *address, char *returnValue)
00209 {
00210 __CFG_COUT__ << "address size " << universalAddressSize_ << std::endl;
00211
00212 __CFG_COUT__ << "Request: ";
00213 for(unsigned int i=0;i<universalAddressSize_;++i)
00214 printf("%2.2X",(unsigned char)address[i]);
00215 std::cout << std::endl;
00216
00217 std::string readBuffer, sendBuffer;
00218 OtsUDPFirmwareCore::readAdvanced(sendBuffer,address,1 );
00219
00220
00221 try
00222 {
00223 OtsUDPHardware::read(sendBuffer, readBuffer);
00224 }
00225 catch(std::runtime_error &e)
00226 {
00227 __CFG_COUT__ << "Caught it! This is when it's getting time out error" << std::endl;
00228 __CFG_COUT_ERR__ << e.what() << std::endl;
00229 return -1;
00230 }
00231
00232 __CFG_COUT__ << "Result SIZE: " << readBuffer.size() << std::endl;
00233 std::memcpy(returnValue,readBuffer.substr(2).c_str(),universalDataSize_);
00234 return 0;
00235 }
00236
00237
00238
00239
00240 void ots::FEOtsUDPTemplateInterface::universalWrite(char* address, char* writeValue)
00241 {
00242 __CFG_COUT__ << "address size " << universalAddressSize_ << std::endl;
00243 __CFG_COUT__ << "data size " << universalDataSize_ << std::endl;
00244 __CFG_COUT__ << "Sending: ";
00245 for(unsigned int i=0;i<universalAddressSize_;++i)
00246 printf("%2.2X",(unsigned char)address[i]);
00247 std::cout << std::endl;
00248
00249 std::string sendBuffer;
00250 OtsUDPFirmwareCore::writeAdvanced(sendBuffer,address,writeValue,1 );
00251 OtsUDPHardware::write(sendBuffer);
00252 }
00253
00254 DEFINE_OTS_INTERFACE(FEOtsUDPTemplateInterface)