REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
ident.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <unordered_set>
5
6// iRedac
7struct StackId {
8 uint8_t id;
9
10 bool operator==(const StackId &other) const { return id == other.id; }
11
12 bool operator!=(const StackId &other) const { return !(*this == other); }
13
14 static StackId from(uint8_t stack) { return StackId{.id = stack}; }
15};
16
17// mRedac
18struct CarrierId {
20 uint8_t id;
21
22 bool operator==(const CarrierId &other) const { return stack == other.stack && id == other.id; }
23
24 bool operator!=(const CarrierId &other) const { return !(*this == other); }
25
26 bool is_lhs() const { return id < 3; }
27
28 static CarrierId from(uint8_t stack, uint8_t carrier) {
29 return CarrierId{.stack = StackId::from(stack), .id = carrier};
30 }
31};
32
33// Cluster
34struct ClusterId {
36 uint8_t id;
37
38 bool operator==(const ClusterId &other) const { return id == other.id && carrier == other.carrier; }
39
40 bool operator!=(const ClusterId &other) const { return !(*this == other); }
41
42 static ClusterId from(uint8_t stack, uint8_t carrier, uint8_t node) {
43 return ClusterId{.carrier = CarrierId::from(stack, carrier), .id = node};
44 }
45};
46
47struct SignalId {
48 ClusterId cluster; // carrier cluster
49 uint8_t id;
50
51 bool operator==(const SignalId &other) const { return id == other.id && cluster == other.cluster; }
52
53 bool operator!=(const SignalId &other) const { return !(*this == other); }
54
55 static SignalId from(uint8_t stack, uint8_t carrier, uint8_t node, uint8_t lane) {
56 return SignalId{.cluster = ClusterId::from(stack, carrier, node), .id = lane};
57 }
58};
59
60namespace std {
61template <> struct hash<StackId> {
62 size_t operator()(const StackId &c) const noexcept { return hash<uint8_t>{}(c.id); }
63};
64
65template <> struct hash<CarrierId> {
66 size_t operator()(const CarrierId &c) const noexcept {
67 size_t h1 = hash<StackId>{}(c.stack);
68 size_t h2 = hash<uint8_t>{}(c.id);
69 return (h1 ^ (h2 << 1));
70 }
71};
72
73template <> struct hash<ClusterId> {
74 size_t operator()(const ClusterId &c) const noexcept {
75 size_t h1 = hash<CarrierId>{}(c.carrier);
76 size_t h2 = hash<uint8_t>{}(c.id);
77 return (h1 ^ (h2 << 1));
78 }
79};
80
81template <> struct hash<SignalId> {
82 size_t operator()(const SignalId &s) const noexcept {
83 size_t h1 = hash<ClusterId>{}(s.cluster);
84 size_t h2 = hash<uint8_t>{}(s.id);
85 return (h1 ^ (h2 << 1));
86 }
87};
88
89} // namespace std
STL namespace.
uint8_t id
Definition ident.hpp:20
bool operator!=(const CarrierId &other) const
Definition ident.hpp:24
bool is_lhs() const
Definition ident.hpp:26
static CarrierId from(uint8_t stack, uint8_t carrier)
Definition ident.hpp:28
StackId stack
Definition ident.hpp:19
bool operator==(const CarrierId &other) const
Definition ident.hpp:22
static ClusterId from(uint8_t stack, uint8_t carrier, uint8_t node)
Definition ident.hpp:42
uint8_t id
Definition ident.hpp:36
CarrierId carrier
Definition ident.hpp:35
bool operator!=(const ClusterId &other) const
Definition ident.hpp:40
bool operator==(const ClusterId &other) const
Definition ident.hpp:38
ClusterId cluster
Definition ident.hpp:48
bool operator!=(const SignalId &other) const
Definition ident.hpp:53
uint8_t id
Definition ident.hpp:49
bool operator==(const SignalId &other) const
Definition ident.hpp:51
static SignalId from(uint8_t stack, uint8_t carrier, uint8_t node, uint8_t lane)
Definition ident.hpp:55
bool operator!=(const StackId &other) const
Definition ident.hpp:12
bool operator==(const StackId &other) const
Definition ident.hpp:10
static StackId from(uint8_t stack)
Definition ident.hpp:14
uint8_t id
Definition ident.hpp:8
size_t operator()(const CarrierId &c) const noexcept
Definition ident.hpp:66
size_t operator()(const ClusterId &c) const noexcept
Definition ident.hpp:74
size_t operator()(const SignalId &s) const noexcept
Definition ident.hpp:82
size_t operator()(const StackId &c) const noexcept
Definition ident.hpp:62