CbmRoot
Loading...
Searching...
No Matches
MimosisMessage.cxx
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#include "MimosisMessage.h"
6
7#include <iomanip>
8#include <sstream>
9
10namespace mimosis
11{
12
14 {
15 uint16_t w = fWord;
16 if (w == 0xFCAA) return WordType::Empty; // Strictly for empty word
17 if ((w & 0xFF00) == 0xFE00) return WordType::FrameHeader;
18 if ((w & 0xFF00) == 0xFD00) return WordType::RegionHeader;
19 if ((w & 0xFF00) == 0xFF00) return WordType::FrameTrailer;
20 if (w <= 0xFBFF) return WordType::PixelData;
21 if ((w & 0xFF80) == 0xFC00) return WordType::Spare; // Spare words in 0xFC00 - 0xFC7F, except 0xFCAA
22 return WordType::Unknown;
23 }
24
25 uint16_t Message::GetPixelAddress() const
26 {
27 // Only valid if type is PixelData (0..504)
28 return fWord & 0x03FF; // bits 0-9
29 }
30
31 uint8_t Message::GetPEAddress() const
32 {
33 return (fWord >> 10) & 0x07; // bits 10-12
34 }
35
36 uint8_t Message::GetCode() const
37 {
38 return (fWord >> 13) & 0x07; // bits 13-15
39 }
40
42 {
43 // Only valid for PixelData type
45 }
46
48 {
49 // Valid if region header
50 return fWord & 0x3F; // bits 0-5
51 }
52
54
55 uint32_t Message::GetFrameNumber() const
56 {
57 // Frame number is in bits 0-23 of the correct frame header word (see ![image2](image2))
58 // You need to invoke this only on the right header word in the frame header sequence.
59 // Typically, the last of the 8 header words is the one holding the frame number.
60 return static_cast<uint32_t>(fWord & 0x00FF) | (static_cast<uint32_t>((fWord & 0xFF00) >> 8) << 8);
61 // Note: For full 24-bit, you may need to assemble from multiple header words
62 // depending on the actual frame header sequence; please check your data format.
63 }
64
66
67 uint16_t Message::GetCRC() const
68 {
69 // In context: CRC is second-to-last word in trailer; just returns value
70 return fWord;
71 }
72
74 {
75 // Only valid for last word in trailer: upper byte = 0xFF, lower byte = flags
76 return (fWord & 0xFF); // flags are in low byte
77 }
78
81 bool Message::IsEmptyWord() const { return GetWordType() == WordType::Empty; }
82 bool Message::IsSpareWord() const { return GetWordType() == WordType::Spare; }
83
85 {
86 switch (type) {
87 case WordType::Empty: return "Empty";
88 case WordType::FrameHeader: return "FrameHeader";
89 case WordType::RegionHeader: return "RegionHeader";
90 case WordType::PixelData: return "PixelData";
91 case WordType::FrameTrailer: return "FrameTrailer";
92 case WordType::Spare: return "Spare";
93 default: return "Unknown";
94 }
95 }
96
97 std::string Message::ToString() const
98 {
99 std::ostringstream ss;
100 ss << "[0x" << std::hex << std::setw(4) << std::setfill('0') << fWord << "] ";
101 auto t = GetWordType();
102 ss << PrintWordType(t);
103
104 switch (t) {
106 ss << " FrameHeader";
107 ss << " (Raw: 0x" << std::hex << fWord << ")";
108 break;
109 case WordType::RegionHeader: ss << " Region#" << static_cast<int>(GetRegionNumber()); break;
111 ss << " PixelAddr=" << static_cast<int>(GetPixelAddress()) << " PE=" << static_cast<int>(GetPEAddress())
112 << " Code=" << static_cast<int>(GetCode()) << (IsValidPixelAddress() ? " [VALID]" : " [INVALID]");
113 break;
115 ss << " Trailer ";
116 ss << " Flags=0x" << std::hex << static_cast<int>(GetTrailerFlags());
117 break;
118 case WordType::Empty: ss << " Empty"; break;
119 case WordType::Spare: ss << " Spare"; break;
120 default: ss << " Unknown"; break;
121 }
122 return ss.str();
123 }
124
125} // namespace mimosis
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
static std::string PrintWordType(WordType type)
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.
bool IsEmptyWord() const
uint8_t GetPEAddress() const
static constexpr uint16_t kMaxPixelAddress
uint8_t GetRegionNumber() const
— Region header (valid if RegionHeader)
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)