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 "result/result.h"
8#include "tof_typedefs.h"
9#include "errors.hpp"
10
11namespace r = result;
12
13static const u8 UNKNOWN = 0;
14static const u8 COMMAND = 10;
15static const u8 RBEVENT = 20;
16static const u8 TOFEVENT = 21;
17static const u8 RBWAVEFORM = 22;
18static const u8 TOFEVENTSUMMARY = 23;
19static const u8 HEARTBEAT = 40;
20static const u8 SCALAR = 50;
21static const u8 MT = 60;
22static const u8 RBHEADER = 70;
23static const u8 CPUMONIDATA = 80;
24static const u8 MTB_MONI = 90;
25static const u8 RB_MONI = 100;
26static const u8 PBMONIDATA = 101;
27static const u8 LTBMONIDATA = 102;
28static const u8 PAMONIDATA = 103;
29static const u8 RBEVENTPAYLOAD = 110;
30static const u8 RBEVENTMEMORYVIEW = 120;
31static const u8 RBCALIBRATION = 130;
32
36enum class PacketType : u8 {
37 Unknown = UNKNOWN ,
38 Command = COMMAND ,
39 RBEvent = RBEVENT ,
40 TofEvent = TOFEVENT ,
41 RBWaveform = RBWAVEFORM ,
42 TofEventSummary = TOFEVENTSUMMARY ,
43 HeartBeat = HEARTBEAT ,
44 Scalar = SCALAR ,
45 MasterTrigger = MT ,
46 RBHeader = RBHEADER ,
47 CPUMoniData = CPUMONIDATA ,
48 MTBMoni = MTB_MONI ,
49 RBMoni = RB_MONI ,
50 PBMoniData = PBMONIDATA ,
51 LTBMoniData = LTBMONIDATA ,
52 PAMoniData = PAMONIDATA ,
53 RBEventPayload = RBEVENTPAYLOAD ,
54 RBEventMemoryView = RBEVENTMEMORYVIEW ,
55 RBCalibration = RBCALIBRATION ,
56};
57
59auto packet_type_to_string(PacketType pt) -> std::string;
60
61std::ostream& operator<<(std::ostream& os, const PacketType& pck);
62
64template<typename T>
65concept HasFromByteStream = requires(const Vec<u8>& stream, usize &pos) {
66 { T::from_bytestream(stream, pos) } -> std::same_as<T>;
67};
68
83struct TofPacket {
84 static constexpr u16 HEAD = 0xAAAA;
85 static constexpr u16 TAIL = 0x5555;
86
87 u16 head = 0xAAAA;
88 u16 tail = 0x5555;
89
90 // head (2) + tail (2) + type (1) + payload size (4)
91 PacketType packet_type;
92 // just the size of the payload,
93 // not including type, header or tail
94 u32 payload_size;
95
96 Vec<u8> payload;
97
98 TofPacket();
99
102 static auto from_bytestream(const Vec<u8> &bytestream, u64 &pos)
103 -> r::Result<TofPacket, Gaps::IOError>;
104
107 auto to_string() const -> std::string;
108
114 template <HasFromByteStream T>
115 T unpack() {
116 usize pos = 0;
117 return T::from_bytestream(payload, pos);
118 }
119}; // end TofPacket
120
121std::ostream& operator<<(std::ostream& os, const TofPacket& pck);
122
123#endif
Ensures that <T> has a method ::from_bytestream.
Definition tof_packet.h:65
Definition monitoring.h:210
Definition monitoring.h:19
Definition monitoring.h:148
Definition monitoring.h:116
Definition calibration.h:34
Definition events.h:321
Definition events.h:626
Definition events.h:647
Definition events.h:528
Definition tof_packet.h:83
static auto from_bytestream(const Vec< u8 > &bytestream, u64 &pos) -> r::Result< TofPacket, Gaps::IOError >
T unpack()
Definition tof_packet.h:115
auto to_string() const -> std::string