$treeview $search $mathjax $extrastylesheet
artdaq_demo
v3_04_01
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #ifndef artdaq_ots_Generators_UDPTFGTest_hh 00002 #define artdaq_ots_Generators_UDPTFGTest_hh 00003 00004 // The UDP Receiver class recieves UDP data from an OtSDAQ applicance and 00005 // puts that data into UDPFragments for further ARTDAQ analysis. 00006 // 00007 // It currently assumes two things to be true: 00008 // 1. The first word of the UDP packet is an 8-bit flag with information 00009 // about the status of the sender 00010 // 2. The second word is an 8-bit sequence ID, used for detecting 00011 // dropped UDP datagrams 00012 00013 // Some C++ conventions used: 00014 00015 // -Append a "_" to every private member function and variable 00016 #include "fhiclcpp/fwd.h" 00017 #include "artdaq-core/Data/Fragment.hh" 00018 #include "artdaq/Application/CommandableFragmentGenerator.hh" 00019 00020 #include <arpa/inet.h> 00021 #include <netinet/in.h> 00022 #include <sys/types.h> 00023 #include <sys/socket.h> 00024 #include <unistd.h> 00025 00026 #include <array> 00027 #include <list> 00028 #include <queue> 00029 #include <atomic> 00030 00031 namespace demo 00032 { 00036 enum class CommandType : uint8_t 00037 { 00038 Read = 0, 00039 Write = 1, 00040 Start_Burst = 2, 00041 Stop_Burst = 3, 00042 }; 00043 00047 enum class ReturnCode : uint8_t 00048 { 00049 Read = 0, 00050 First = 1, 00051 Middle = 2, 00052 Last = 3, 00053 }; 00054 00058 enum class DataType : uint8_t 00059 { 00060 Raw = 0, 00061 JSON = 1, 00062 String = 2, 00063 }; 00064 00068 struct CommandPacket 00069 { 00070 CommandType type; 00071 uint8_t dataSize; 00072 uint64_t address; 00073 uint64_t data[182]; 00074 }; 00075 00076 typedef std::array<uint8_t, 1500> packetBuffer_t; 00077 typedef std::list<packetBuffer_t> packetBuffer_list_t; 00078 00082 class UDPReceiver : public artdaq::CommandableFragmentGenerator 00083 { 00084 public: 00098 explicit UDPReceiver(fhicl::ParameterSet const& ps); 00099 00100 private: 00101 00102 // The "getNext_" function is used to implement user-specific 00103 // functionality; it's a mandatory override of the pure virtual 00104 // getNext_ function declared in CommandableFragmentGenerator 00105 00106 bool getNext_(artdaq::FragmentPtrs& output) override; 00107 00108 void start() override; 00109 00110 void stop() override; 00111 00112 void stopNoMutex() override {} // nothing special needs to be done in this method 00113 void pause() override; 00114 00115 void resume() override; 00116 00117 DataType getDataType(uint8_t byte) { return static_cast<DataType>((byte & 0xF0) >> 4); } 00118 ReturnCode getReturnCode(uint8_t byte) { return static_cast<ReturnCode>(byte & 0xF); } 00119 00120 void send(CommandType flag); 00121 00122 // FHiCL-configurable variables. Note that the C++ variable names 00123 // are the FHiCL variable names with a "_" appended 00124 00125 int dataport_; 00126 std::string ip_; 00127 00128 //The packet number of the next packet. Used to discover dropped packets 00129 uint8_t expectedPacketNumber_; 00130 00131 //Socket parameters 00132 struct sockaddr_in si_data_; 00133 int datasocket_; 00134 bool sendCommands_; 00135 00136 packetBuffer_list_t packetBuffers_; 00137 00138 bool rawOutput_; 00139 std::string rawPath_; 00140 }; 00141 } 00142 00143 #endif /* artdaq_demo_Generators_ToySimulator_hh */