CbmRoot
Loading...
Searching...
No Matches
MimosisMessage.h
Go to the documentation of this file.
1/* Copyright (C) 2025 IKF Frankfurt University, Frankfurt am Main
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Ajit Kumar [committer], Jan Michel*/
4
5#ifndef MIMOSISMESSAGE_H
6#define MIMOSISMESSAGE_H
7
8#include <cstdint>
9#include <iostream>
10#include <string>
11
12namespace mimosis
13{
14
26
28 enum class TrailerFlags : uint8_t
29 {
30 FrameOverflow = 1 << 0,
33 BufferFull = 1 << 3
34 // Bits 4..7 unused
35 };
36
38 struct WordField {
39 uint8_t shift;
40 uint8_t width;
41 constexpr WordField(uint8_t s, uint8_t w) : shift(s), width(w) {}
42 };
43
44 static constexpr WordField kPixelAddrField(0, 10); // bits 0-9: pixel address (0..504 used)
45 static constexpr WordField kPEAddrField(10, 3); // bits 10-12: PE (double col) address
46 static constexpr WordField kCodeField(13, 3); // bits 13-15: code (cluster, etc)
47 static constexpr WordField kRegionNumField(0, 6); // bits 0-5: region number (region header)
48 static constexpr WordField kFrameNumField(0, 24); // bits 0-23: frame number (in header)
49 static constexpr WordField kTrailerFlagsField(8, 8); // bits 8-15: trailer flags
50
52 class Message {
53 public:
54 Message() : fWord(0) {}
55 explicit Message(uint16_t word) : fWord(word) {}
56 Message(const Message&) = default;
57 Message& operator=(const Message&) = default;
58
59 uint16_t GetRaw() const { return fWord; }
60 void SetRaw(uint16_t w) { fWord = w; }
61
63 WordType GetWordType() const;
64
66 uint16_t GetPixelAddress() const; // 0..504 used
67 uint8_t GetPEAddress() const;
68 uint8_t GetCode() const;
69 bool IsValidPixelAddress() const;
70
72 uint8_t GetRegionNumber() const;
73
75 bool IsFrameHeader() const;
76 uint32_t GetFrameNumber() const;
77
79 bool IsFrameTrailer() const;
80 uint16_t GetCRC() const; // For use in parsing context
81 uint8_t GetTrailerFlags() const;
82
83 bool IsRegionHeader() const;
84 bool IsPixelData() const;
85 bool IsEmptyWord() const;
86 bool IsSpareWord() const;
87
88 static std::string PrintWordType(WordType type);
89
91 std::string ToString() const;
92
93 private:
94 uint16_t fWord;
95 static constexpr uint16_t kMaxPixelAddress = 504; // MIMOSIS spec: addresses 0..504 used
96 };
97
98} // namespace mimosis
99
100#endif // MIMOSISMESSAGE_H
uint16_t GetCRC() const
WordType GetWordType() const
– Type
uint8_t GetCode() const
bool IsPixelData() const
uint16_t GetPixelAddress() const
— Pixel address data (valid if PixelData)
bool IsSpareWord() const
std::string ToString() const
— For debugging: human readable string
Message(const Message &)=default
static std::string PrintWordType(WordType type)
uint16_t GetRaw() const
bool IsRegionHeader() const
uint8_t GetTrailerFlags() const
bool IsFrameHeader() const
— Frame header helpers
bool IsValidPixelAddress() const
True if pixel address is 0..504.
bool IsFrameTrailer() const
— Frame trailer
uint32_t GetFrameNumber() const
Only valid on the correct header word.
Message(uint16_t word)
bool IsEmptyWord() const
uint8_t GetPEAddress() const
static constexpr uint16_t kMaxPixelAddress
uint8_t GetRegionNumber() const
— Region header (valid if RegionHeader)
Message & operator=(const Message &)=default
void SetRaw(uint16_t w)
WordType
— Word Types
@ FrameHeader
0xFE00 - 0xFEFF, part of 8-word frame header
@ PixelData
0x0000 - 0xFBFF, pixel address (0..504 used, up to 0xFBFF)
@ FrameTrailer
0xFF00 - 0xFFFF, trailer (checksum, flags)
@ Spare
0xFC00 - 0xFC7F, unused, reserved (excluding 0xFCAA)
@ Empty
0xFCAA, specific empty word for padding
@ RegionHeader
0xFD00 - 0xFD3F, region header (region # in 6 lsb)
static constexpr WordField kCodeField(13, 3)
TrailerFlags
— Frame Trailer Flags (see format image)
static constexpr WordField kFrameNumField(0, 24)
static constexpr WordField kRegionNumField(0, 6)
static constexpr WordField kTrailerFlagsField(8, 8)
static constexpr WordField kPixelAddrField(0, 10)
static constexpr WordField kPEAddrField(10, 3)
Helper for word field decoding (bit ranges)
constexpr WordField(uint8_t s, uint8_t w)