From 26062cec876925d33d6065eec2c4ebea20532673 Mon Sep 17 00:00:00 2001 From: "@CarlWachter" Date: Tue, 2 Jan 2024 11:50:00 +0100 Subject: [PATCH] Moved AlpakaCanBus to .hpp here --- include/sta/rtos/system/can_bus.hpp | 76 +++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/include/sta/rtos/system/can_bus.hpp b/include/sta/rtos/system/can_bus.hpp index e9855f1..642f32d 100644 --- a/include/sta/rtos/system/can_bus.hpp +++ b/include/sta/rtos/system/can_bus.hpp @@ -27,7 +27,11 @@ #ifdef STA_RTOS_CAN_BUS_ENABLE #include +#include #include +#include +#include +#include #include @@ -116,6 +120,78 @@ namespace sta } // namespace rtos } // namespace sta +namespace sta +{ + + class AlpakaCanBus + { + public: + using SysMsgHandler = void (*)(const CanRxHeader &, const uint8_t *); + using DataMsgHandler = void (*)(const IsotpMessage &); + + static const uint8_t FIFO_SYS = 0; + static const uint8_t FIFO_DATA = 1; + + public: + AlpakaCanBus(CanController * controller, TimeMsFn timeMs, SysMsgHandler sysMsgHandler, DataMsgHandler dataMsgHandler); + + + /** + * @brief Send system message. + * + * @param msg Message + */ + void send(const CanSysMsg & msg); + + /** + * @brief Send data message. + * + * @param msg Message + */ + void send(const CanDataMsg & msg); + + + /** + * @brief Process transmissions. + * + * Call regularly to advance transmission. + */ + void processTx(); + + /** + * @brief Process received CAN messages. + */ + void processRx(); + + /** + * @brief Display ISOTP TX/RX statistics. + */ + void showStatistics(); + + private: + /** + * @brief Configure CAN filters. + */ + void setupSubscriptions(); + + /** + * @brief Handle received data message CAN frames. + * + * @param header CAN frame header + * @param payload Payload buffer + */ + void receiveDataFrame(const CanRxHeader & header, const uint8_t * payload); + + private: + CanController * controller_; + IsotpTransmitter tx_; + IsotpReceiver rx_; + SysMsgHandler handleSysMsg_; + DataMsgHandler handleDataMsg_; + }; + +} // namespace sta + #endif // STA_RTOS_CAN_BUS_ENABLE