Hotwheels-Cluster 1.2
Creation of Cluster APP for SEA:ME project.
 
Loading...
Searching...
No Matches
CANMessageProcessor.cpp
Go to the documentation of this file.
1
23
25#include <stdexcept>
26
33
43 MessageHandler handler) {
44 if (!handler) {
45 throw std::invalid_argument("Handler cannot be null");
46 }
47 handlers[frameID] = handler;
48}
49
60 const std::vector<uint8_t> &data) {
61 auto it = handlers.find(frameID);
62 if (it != handlers.end()) {
63 it->second(data);
64 } else {
65 throw std::runtime_error("No handler registered for frame ID: " +
66 std::to_string(frameID));
67 }
68}
Definition of the CANMessageProcessor class.
void registerHandler(uint16_t frameID, MessageHandler handler)
Destroy the CANMessageProcessor::CANMessageProcessor object.
std::unordered_map< uint16_t, MessageHandler > handlers
Map of frame IDs to message handlers.
CANMessageProcessor()
Construct a new CANMessageProcessor::CANMessageProcessor object.
std::function< void(const std::vector< uint8_t > &)> MessageHandler
void processMessage(uint16_t frameID, const std::vector< uint8_t > &data)
Process a CAN message.