gaps-online-software 0.10
online software for the TOF system for the GAPS experiment
Loading...
Searching...
No Matches
tof_packet.h
1#ifndef TOFPACKET_H_INCLUDED
2#define TOFPACKET_H_INCLUDED
3
4#include <cstdint>
5#include <vector>
6
7#include "tof_typedefs.h"
8
9static const u8 UNKNOWN = 0;
10static const u8 COMMAND = 10;
11static const u8 RBEVENT = 20;
12static const u8 TOFEVENT = 21;
13static const u8 RBWAVEFORM = 22;
14static const u8 TOFEVENTSUMMARY = 23;
15static const u8 HEARTBEAT = 40;
16static const u8 SCALAR = 50;
17static const u8 MT = 60;
18static const u8 RBHEADER = 70;
19static const u8 CPUMONIDATA = 80;
20static const u8 MTB_MONI = 90;
21static const u8 RB_MONI = 100;
22static const u8 PBMONIDATA = 101;
23static const u8 LTBMONIDATA = 102;
24static const u8 PAMONIDATA = 103;
25static const u8 RBEVENTPAYLOAD = 110;
26static const u8 RBEVENTMEMORYVIEW = 120;
27static const u8 RBCALIBRATION = 130;
28
32enum class PacketType : u8 {
33 Unknown = UNKNOWN ,
34 Command = COMMAND ,
35 RBEvent = RBEVENT ,
36 TofEvent = TOFEVENT ,
37 RBWaveform = RBWAVEFORM ,
38 TofEventSummary = TOFEVENTSUMMARY ,
39 HeartBeat = HEARTBEAT ,
40 Scalar = SCALAR ,
41 MasterTrigger = MT ,
42 RBHeader = RBHEADER ,
43 CPUMoniData = CPUMONIDATA ,
44 MTBMoni = MTB_MONI ,
45 RBMoni = RB_MONI ,
46 PBMoniData = PBMONIDATA ,
47 LTBMoniData = LTBMONIDATA ,
48 PAMoniData = PAMONIDATA ,
49 RBEventPayload = RBEVENTPAYLOAD ,
50 RBEventMemoryView = RBEVENTMEMORYVIEW ,
51 RBCalibration = RBCALIBRATION ,
52};
53
54
55
57std::string packet_type_to_string(PacketType pt);
58
59std::ostream& operator<<(std::ostream& os, const PacketType& pck);
60
62template<typename T>
63concept HasFromByteStream = requires(const Vec<u8>& stream, usize &pos) {
64 { T::from_bytestream(stream, pos) } -> std::same_as<T>;
65};
66
81struct TofPacket {
82 static const u16 HEAD = 0xAAAA;
83 static const u16 TAIL = 0x5555;
84
85 u16 head = 0xAAAA;
86 u16 tail = 0x5555;
87
88 // head (2) + tail (2) + type (1) + payload size (4)
89 PacketType packet_type;
90 // just the size of the payload,
91 // not including type, header or tail
92 u32 payload_size;
93
94 Vec<u8> payload;
95
96 TofPacket();
97
100 static TofPacket from_bytestream(const Vec<u8> &bytestream,
101 u64 &pos);
102
105 std::string to_string() const;
106
112 template <HasFromByteStream T>
113 T unpack() {
114 usize pos = 0;
115 return T::from_bytestream(payload, pos);
116 }
117}; // end TofPacket
118
119std::ostream& operator<<(std::ostream& os, const TofPacket& pck);
120
121#endif
Ensures that <T> has a method ::from_bytestream.
Definition tof_packet.h:63
Definition monitoring.h:216
Definition monitoring.h:19
Definition monitoring.h:148
Definition monitoring.h:116
Definition calibration.h:33
Definition events.h:227
Definition events.h:598
Definition events.h:621
Definition events.h:434
Definition tof_packet.h:81
std::string to_string() const
T unpack()
Definition tof_packet.h:113
static TofPacket from_bytestream(const Vec< u8 > &bytestream, u64 &pos)