Class that handles message listening over a SocketCAN interface.
More...
#include <can_listener.h>
Class that handles message listening over a SocketCAN interface.
This class is responsible listening to CAN messages and updating a JSON file This class shall cache the latest data and update the JSON every UPDATE_CAN_JSON_PERIOD_MS
◆ CanListener()
Constructs a CanListener object.
Initializes the CanListener. The constructor sets up internal variables The constructor shall intialize the mutex
◆ ~CanListener()
Destructs a CanListener object.
Initializes the CanListener. The constructor sets up internal variables The destructor shall release the mutex
◆ canMessageHandler()
void canMessageHandler |
( |
uint32_t |
id, |
|
|
const uint8_t * |
data |
|
) |
| |
|
private |
Handles receiving new CAN messages.
Main CAN message Handler.
Boolean flag to track the CAN bus connection status
This function is called by the listeningCanBusProcedure This function is autogenerated
This function shall dynamically allocate a struct based on the CAN ID This function shall decode the data, then update the CAN Cache 'm_canInfo' with JSON data
- Parameters
-
id | Can message ID |
data | Pointer to the CAN message data |
◆ listenCanBus()
Initiate the CAN Bus listener on a Raw SocketCAN port.
This shall start the listenCanBusProcedure and updateJSONProcedure
◆ listenCanBusProcedure()
void listenCanBusProcedure |
( |
| ) |
|
Thread procedure for listening to the CAN bus.
This thread shall store the latest CAN data in the m_canInfo unordered map
◆ updateJSONProcedure()
void updateJSONProcedure |
( |
| ) |
|
Thread procedure for updating the global JSON object.
This thread shall update the JSON at UPDATE_CAN_JSON_PERIOD_MS
◆ CAN_INTERFACE_NAME
const std::string CAN_INTERFACE_NAME = "vcan0" |
|
private |
◆ CAN_JSON_NAME
const std::string CAN_JSON_NAME = "CANListener" |
|
private |
◆ m_canInfo
std::unordered_map<std::string, nlohmann::json> m_canInfo |
|
private |
Hash-map to cache the latest CAN data
◆ m_listenCanBusId
pthread_t m_listenCanBusId |
|
private |
Thread Id for listening to the CAN bus
◆ m_mutex
Mutex to protect m_canInfo
◆ m_rawCanSocket
◆ m_updateJSONId
Thread Id for updating the CAN JSON
◆ UPDATE_CAN_JSON_PERIOD_MS
const constexpr unsigned int UPDATE_CAN_JSON_PERIOD_MS = 1000U |
|
staticconstexprprivate |
JSON Update period in milliseconds
The documentation for this class was generated from the following files:
- simulation/server/app/inc/can_listener.h
- simulation/server/app/src/can_listener.cc
- simulation/server/app/src/can_message_handler.cc