1 #ifndef artdaq_ots_Generators_UDPReceiver_hh
2 #define artdaq_ots_Generators_UDPReceiver_hh
17 #include "artdaq-core/Data/Fragment.hh"
18 #include "artdaq/Generators/CommandableFragmentGenerator.hh"
19 #include "fhiclcpp/fwd.h"
21 #include <arpa/inet.h>
22 #include <netinet/in.h>
23 #include <sys/socket.h>
24 #include <sys/types.h>
37 enum class CommandType : uint8_t
45 enum class ReturnCode : uint8_t
53 enum class DataType : uint8_t
68 typedef std::string packetBuffer_t;
69 typedef std::list<packetBuffer_t> packetBuffer_list_t;
71 class UDPReceiver :
public artdaq::CommandableFragmentGenerator
74 explicit UDPReceiver(fhicl::ParameterSet
const& ps);
82 bool getNext_(artdaq::FragmentPtrs& output)
override;
83 void start(
void)
override;
84 virtual void start_();
85 virtual void stop(
void)
override;
86 virtual void stopNoMutex(
void)
override;
88 virtual void ProcessData_(artdaq::FragmentPtrs& output,
size_t totalSize);
90 DataType getDataType(uint8_t byte) {
return static_cast<DataType
>((byte & 0xF0) >> 4); }
91 ReturnCode getReturnCode(uint8_t byte) {
return static_cast<ReturnCode
>(byte & 0xF); }
92 void send(CommandType flag);
94 packetBuffer_list_t packetBuffers_;
107 uint8_t expectedPacketNumber_;
110 struct sockaddr_in si_data_;
116 bool isTimerExpired_();
118 std::unique_ptr<std::thread> receiverThread_;
119 std::mutex receiveBufferLock_;
120 packetBuffer_list_t receiveBuffers_;
125 double fragmentWindow_;
126 std::chrono::high_resolution_clock::time_point lastFrag_;