EduArt Sensor Ring Library 4.0.0
Loading...
Searching...
No Matches
ComEndpoint.hpp
Go to the documentation of this file.
1// Copyright (c) 2026 EduArt Robotik GmbH
2
9
10#pragma once
11
12#include <cstdint>
13#include <string>
14
15#include "sensorring/platform/SensorringExport.hpp"
16
17namespace eduart {
18
19namespace sensorring {
20
21namespace com {
22
27enum class Direction : std::uint8_t {
28 Input = 0,
30 Output = 1
31};
32
37struct SENSORRING_EXPORT ComEndpoint {
39 std::uint8_t boardAddress;
40 std::uint8_t deviceId;
41
43 bool operator==(const ComEndpoint& other) const;
44
46 bool operator!=(const ComEndpoint& other) const;
47
52 std::string toString() const;
53
55 static constexpr std::uint8_t BROADCAST = 0x00;
56
58 static constexpr std::uint8_t ANY_BOARD = 0xFF;
59};
60
67inline bool endpointMatches(const ComEndpoint& subscription, const ComEndpoint& incoming) {
68 return subscription.direction == incoming.direction && (subscription.boardAddress == incoming.boardAddress || subscription.boardAddress == ComEndpoint::ANY_BOARD) && subscription.deviceId == incoming.deviceId;
69}
70
71} // namespace com
72
73} // namespace sensorring
74
75} // namespace eduart
76
77namespace std {
78
80template <> struct hash<eduart::sensorring::com::ComEndpoint> {
82 std::size_t operator()(const eduart::sensorring::com::ComEndpoint& ep) const {
83 std::uint32_t packed = (static_cast<std::uint32_t>(ep.direction) << 16) | (static_cast<std::uint32_t>(ep.boardAddress) << 8) | static_cast<std::uint32_t>(ep.deviceId);
84 return std::hash<std::uint32_t>{}(packed);
85 }
86};
87
88} // namespace std
Direction
Communication direction on the CAN bus, from the board's perspective.
Definition ComEndpoint.hpp:27
@ Output
Board -> Host (board sends).
Definition ComEndpoint.hpp:30
@ Input
Host -> Board (board receives).
Definition ComEndpoint.hpp:28
@ Broadcast
Alias for Input; used with broadcast board address.
Definition ComEndpoint.hpp:29
bool endpointMatches(const ComEndpoint &subscription, const ComEndpoint &incoming)
Check whether a subscription endpoint matches an incoming endpoint.
Definition ComEndpoint.hpp:67
Uniquely identifies a communication endpoint as a (Direction, BoardAddress, DeviceId) tuple.
Definition ComEndpoint.hpp:37
bool operator!=(const ComEndpoint &other) const
Inequality comparison for ComEndpoint.
std::uint8_t deviceId
0x00 = board, 0x01 = ToF, 0x02 = Thermal, 0x03 = WS2812b
Definition ComEndpoint.hpp:40
bool operator==(const ComEndpoint &other) const
Equality comparison for ComEndpoint (compares direction, board address, and device ID).
std::uint8_t boardAddress
0 = broadcast, 1-126 = individual board (board_index + 1)
Definition ComEndpoint.hpp:39
Direction direction
Host->Board (Input) or Board->Host (Output).
Definition ComEndpoint.hpp:38
static constexpr std::uint8_t BROADCAST
Broadcast board address (node ID 0x00 per existing CAN convention).
Definition ComEndpoint.hpp:55
static constexpr std::uint8_t ANY_BOARD
Subscription wildcard: matches any board address during dispatch.
Definition ComEndpoint.hpp:58
std::string toString() const
Human-readable representation for logging.
std::size_t operator()(const eduart::sensorring::com::ComEndpoint &ep) const
Compute hash value for a ComEndpoint.
Definition ComEndpoint.hpp:82