ReduxLib C++ 2026.1.2
Loading...
Searching...
No Matches
MessageBus.h
1// Copyright (c) Bagholders of Redux Robotics and other contributors.
2// This is open source and can be modified and shared under the Mozilla Public License v2.0.
3
4#pragma once
5#include <stdint.h>
6#include <string>
7
8namespace redux::canand {
9/**
10 * Class representing message buses that may exist on a robot.
11 *
12*/
14 public:
15
16 /**
17 * Constructs a new bus from a descriptor value.
18 *
19 * 0 is the Rio's onboard bus, and 0 through 4 inclusive are can_s0 through can_s4 on SystemCore.
20 * @param descriptorId the bus descriptor value.
21 */
22 inline MessageBus(uint16_t descriptorId) { fd = descriptorId; }
23 virtual ~MessageBus() = default;
24
25 /**
26 * Returns the descriptor ID associated with the CAN bus object.
27 * Generally not needed to be used directly.
28 * @return the descriptor ID.
29 */
30 inline uint16_t GetDescriptor() { return fd; }
31
32 /**
33 * Returns whether two MessageBus objects refer to the same bus.
34 * @param other other MessageBus object to compare against
35 * @return whether or not they refer to the same bus
36 */
37 inline bool Equals(MessageBus other) { return GetDescriptor() == other.GetDescriptor(); }
38
39 /**
40 * Constructs or fetches a bus by its bus string.
41 * If the bus is not opened, it will attempt to be opened.
42 *
43 * If the bus cannot be opened, an error will be thrown.
44 * @param busString bus string, e.g. "halcan", "socketcan:can_s0", or "slcan:115200:/dev/ttyAMA0"
45 * @return bus instance
46 */
47 static MessageBus ByBusString(std::string busString);
48 private:
49 uint16_t fd;
50};
51}
Definition MessageBus.h:13
uint16_t GetDescriptor()
Definition MessageBus.h:30
bool Equals(MessageBus other)
Definition MessageBus.h:37
MessageBus(uint16_t descriptorId)
Definition MessageBus.h:22
static MessageBus ByBusString(std::string busString)
Definition Namespaces.h:17