|
2 | 2 | #define CAN_CORE_HPP |
3 | 3 |
|
4 | 4 | #include "rclcpp/rclcpp.hpp" |
| 5 | +#include <cstdint> |
5 | 6 | #include <string> |
6 | 7 | #include <vector> |
7 | | -#include <cstdint> |
8 | 8 |
|
9 | | -namespace autonomy |
10 | | -{ |
| 9 | +namespace autonomy { |
11 | 10 |
|
12 | 11 | struct CanMessage { |
13 | | - uint32_t id; // CAN message ID |
14 | | - std::vector<uint8_t> data; // Message data (up to 8 bytes for classic CAN) |
15 | | - uint8_t dlc; // Data Length Code |
16 | | - bool is_extended_id; // Extended frame format flag |
17 | | - bool is_remote_frame; // Remote transmission request flag |
18 | | - uint64_t timestamp_us; // Timestamp in microseconds |
| 12 | + uint32_t id; // CAN message ID |
| 13 | + std::vector<uint8_t> data; // Message data (up to 8 bytes for classic CAN) |
| 14 | + uint8_t dlc; // Data Length Code |
| 15 | + bool is_extended_id; // Extended frame format flag |
| 16 | + bool is_remote_frame; // Remote transmission request flag |
| 17 | + uint64_t timestamp_us; // Timestamp in microseconds |
19 | 18 | }; |
20 | 19 |
|
21 | 20 | struct CanConfig { |
22 | | - std::string interface_name; // CAN interface name (e.g., "can0") |
23 | | - std::string device_path; // Device path for SLCAN (e.g., "/dev/ttyACM0") |
24 | | - std::string bustype; // Bus type: "socketcan" or "slcan" |
25 | | - uint32_t bitrate; // Bitrate in bps for arbitration phase |
26 | | - uint32_t data_bitrate; // Data bitrate in bps for CAN-FD data phase |
27 | | - uint32_t receive_timeout_ms; // Receive timeout in milliseconds |
| 21 | + std::string interface_name; // CAN interface name (e.g., "can0") |
| 22 | + std::string device_path; // Device path for SLCAN (e.g., "/dev/ttyACM0") |
| 23 | + std::string bustype; // Bus type: "socketcan" or "slcan" |
| 24 | + uint32_t bitrate; // Bitrate in bps for arbitration phase |
| 25 | + uint32_t data_bitrate; // Data bitrate in bps for CAN-FD data phase |
| 26 | + uint32_t receive_timeout_ms; // Receive timeout in milliseconds |
28 | 27 | }; |
29 | 28 |
|
30 | 29 | class CanCore { |
31 | 30 | public: |
32 | | - CanCore(const rclcpp::Logger& logger); |
33 | | - |
34 | | - // CAN Interface Management |
35 | | - bool initialize(const CanConfig& config); |
36 | | - bool shutdown(); |
37 | | - bool isInitialized() const; |
38 | | - |
39 | | - // Message Transmission |
40 | | - bool sendMessage(const CanMessage& message); |
41 | | - |
42 | | - // Message Reception |
43 | | - bool receiveMessage(CanMessage& message); |
44 | | - |
| 31 | + CanCore(const rclcpp::Logger &logger); |
| 32 | + |
| 33 | + // CAN Interface Management |
| 34 | + bool initialize(const CanConfig &config); |
| 35 | + bool shutdown(); |
| 36 | + bool isInitialized() const; |
| 37 | + |
| 38 | + // Message Transmission |
| 39 | + bool sendMessage(const CanMessage &message); |
| 40 | + |
| 41 | + // Message Reception |
| 42 | + bool receiveMessage(CanMessage &message); |
| 43 | + |
45 | 44 | private: |
46 | | - rclcpp::Logger logger_; |
47 | | - |
48 | | - // Internal state |
49 | | - int socket_fd_; |
50 | | - bool initialized_; |
51 | | - bool connected_; |
52 | | - CanConfig config_; |
53 | | - |
54 | | - // Internal helper methods |
55 | | - bool setupSocketCan(); |
56 | | - bool setupSlcan(); |
| 45 | + rclcpp::Logger logger_; |
| 46 | + |
| 47 | + // Internal state |
| 48 | + int socket_fd_; |
| 49 | + bool initialized_; |
| 50 | + bool connected_; |
| 51 | + CanConfig config_; |
| 52 | + |
| 53 | + // Internal helper methods |
| 54 | + bool setupSocketCan(); |
| 55 | + bool setupSlcan(); |
57 | 56 | }; |
58 | 57 |
|
59 | | -} |
| 58 | +} // namespace autonomy |
60 | 59 |
|
61 | 60 | #endif // CAN_CORE_HPP |
0 commit comments