00001 #ifndef artdaq_ots_Generators_UDPTFGTest_hh
00002 #define artdaq_ots_Generators_UDPTFGTest_hh
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
00103
00104
00105
00106 bool getNext_(artdaq::FragmentPtrs& output) override;
00107
00108 void start() override;
00109
00110 void stop() override;
00111
00112 void stopNoMutex() override {}
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
00123
00124
00125 int dataport_;
00126 std::string ip_;
00127
00128
00129 uint8_t expectedPacketNumber_;
00130
00131
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