2023-08-08 21:00:41 +00:00
|
|
|
#include <cstddef>
|
2023-08-07 20:27:10 +00:00
|
|
|
#include <cstdint>
|
2023-08-08 21:00:41 +00:00
|
|
|
#include <cstring>
|
2023-08-07 20:27:10 +00:00
|
|
|
|
|
|
|
#define START_OF_HEADER_MARKER 0xee1234ee
|
|
|
|
|
|
|
|
typedef struct Header {
|
|
|
|
uint32_t startOfHeaderMarker = START_OF_HEADER_MARKER;
|
|
|
|
uint32_t headerSize;
|
|
|
|
uint32_t fragmentSize;
|
2023-08-09 21:10:42 +00:00
|
|
|
uint32_t sourceIdentifier;
|
2023-08-07 20:27:10 +00:00
|
|
|
uint32_t runNumber;
|
|
|
|
uint32_t detectorEventNumber;
|
|
|
|
uint32_t numberOfStatusElements;
|
|
|
|
uint32_t *statusElementsArray;
|
|
|
|
/*friend std::ostream& operator <<(std::ostream& os, Header const& header)
|
|
|
|
{
|
|
|
|
return os << std::setw(8) << std::setfill('0') << header.startOfHeaderMarker << '\n'
|
|
|
|
<< std::setw(8) << std::setfill('0') << header.headerSize << '\n'
|
|
|
|
<< std::setw(8) << std::setfill('0') << header.fragmentSize << '\n'
|
|
|
|
<< std::setw(8) << std::setfill('0') << header.runNumber << '\n'
|
|
|
|
<< std::setw(8) << std::setfill('0') << header.detectorEventNumber << '\n'
|
|
|
|
<< std::setw(8) << std::setfill('0') << header.numberOfStatusElements << '\n';
|
|
|
|
}*/
|
|
|
|
} Header;
|
|
|
|
|
|
|
|
typedef struct Fragment {
|
|
|
|
Header header;
|
|
|
|
uint32_t *payloadElements;
|
|
|
|
} Fragment;
|
|
|
|
|
|
|
|
enum ERROR_CODES {
|
|
|
|
INCORRECT_ERROR = (1 << 0),
|
|
|
|
CORRUPTED_ERROR = (1 << 1),
|
|
|
|
MISSING_DATA_ERROR = (1 << 2),
|
|
|
|
TIMEOUT_ERROR = (1 << 3)
|
|
|
|
};
|
|
|
|
|
2023-08-08 21:00:41 +00:00
|
|
|
void encode_header(uint32_t *buffer, const Header &header) {
|
|
|
|
buffer[0] = header.startOfHeaderMarker;
|
|
|
|
buffer[1] = header.headerSize;
|
|
|
|
buffer[2] = header.fragmentSize;
|
2023-08-09 21:10:42 +00:00
|
|
|
buffer[3] = header.sourceIdentifier;
|
|
|
|
buffer[4] = header.runNumber;
|
|
|
|
buffer[5] = header.detectorEventNumber;
|
|
|
|
buffer[6] = header.numberOfStatusElements;
|
2023-08-08 21:00:41 +00:00
|
|
|
|
2023-08-09 21:10:42 +00:00
|
|
|
std::memcpy(&buffer[7], header.statusElementsArray, header.numberOfStatusElements * sizeof(uint32_t));
|
2023-08-08 21:00:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void encode_fragment(uint32_t *buffer, const Fragment &fragment){
|
|
|
|
encode_header(buffer, fragment.header);
|
|
|
|
std::memcpy(&buffer[fragment.header.headerSize], fragment.payloadElements, (fragment.header.fragmentSize - fragment.header.headerSize) * sizeof(uint32_t));
|
|
|
|
}
|
|
|
|
|
2023-08-07 20:27:10 +00:00
|
|
|
|