STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
ElodinProtocol.hpp
Go to the documentation of this file.
1#ifndef DAQ_ELODIN_PROTOCOL_HPP
2#define DAQ_ELODIN_PROTOCOL_HPP
3
4#include <array>
5#include <cstdint>
6#include <string>
7#include <string_view>
8#include <vector>
9
10namespace fsw {
11namespace elodin {
12
13// Elodin packet types
14enum class PacketType : uint8_t { MSG = 0, TABLE = 1, TIME_SERIES = 2 };
15
16// Packet header structure
18 uint32_t len; // Length of payload + 4
19 PacketType ty; // Packet type
20 std::array<uint8_t, 2> packet_id; // Packet identifier
21 uint8_t request_id; // Request ID (usually 0)
22};
23
24// Hash functions for Elodin IDs (FNV-1a)
25inline uint32_t fnv1a_hash_32(std::string_view str) {
26 uint32_t hash = 0x811c9dc5;
27 size_t i = 0;
28 for (auto c : str) {
29 if (++i >= 32)
30 break;
31 hash ^= static_cast<uint8_t>(c);
32 hash *= 0x01000193;
33 }
34 return hash;
35}
36
37inline uint64_t fnv1a_hash_64(std::string_view str) {
38 uint64_t hash = 0xcbf29ce484222325;
39 size_t i = 0;
40 for (auto c : str) {
41 if (++i >= 64)
42 break;
43 hash ^= static_cast<uint8_t>(c);
44 hash *= 0x00000100000001B3;
45 }
46 return hash;
47}
48
49inline uint16_t fnv1a_hash_16_xor(std::string_view str) {
50 auto hash = fnv1a_hash_32(str);
51 uint16_t upper = static_cast<uint16_t>((hash >> 16) & 0xFFFF);
52 uint16_t lower = static_cast<uint16_t>(hash & 0xFFFF);
53 return upper ^ lower;
54}
55
56inline std::array<uint8_t, 2> msg_id(std::string_view str) {
57 auto hash = fnv1a_hash_16_xor(str);
58 return {static_cast<uint8_t>(hash & 0xff), static_cast<uint8_t>((hash >> 8) & 0xff)};
59}
60
61inline uint64_t component_id(std::string_view str) {
62 auto hash = fnv1a_hash_64(str) & ~(1ul << 63);
63 return hash;
64}
65
66} // namespace elodin
67} // namespace fsw
68
69#endif // DAQ_ELODIN_PROTOCOL_HPP
uint16_t fnv1a_hash_16_xor(std::string_view str)
uint64_t fnv1a_hash_64(std::string_view str)
uint64_t component_id(std::string_view str)
std::array< uint8_t, 2 > msg_id(std::string_view str)
uint32_t fnv1a_hash_32(std::string_view str)
Motorized ball valve position: raw ADC counts -> % open.
std::array< uint8_t, 2 > packet_id