|
Fang-Robotics-MCB
Fang Robotics Team Codebase
|
#include <can_rx_handler.hpp>

Public Member Functions | |
| CanRxHandler (Drivers *drivers) | |
| mockable | ~CanRxHandler ()=default |
| mockable void | attachReceiveHandler (CanRxListener *const listener) |
| mockable void | pollCanData () |
| mockable void | removeReceiveHandler (const CanRxListener &rxListener) |
Static Public Member Functions | |
| static uint16_t | binIndexForCanId (uint16_t canId) |
Static Public Attributes | |
| static constexpr uint8_t | CAN_BINS = 8 |
Protected Member Functions | |
| void | attachReceiveHandler (CanRxListener *const canRxListener, CanRxListener **messageHandlerStore) |
| void | processReceivedCanData (const modm::can::Message &rxMessage, CanRxListener *const *messageHandlerStore) |
| void | removeReceiveHandler (const CanRxListener &canRxListener, CanRxListener **messageHandlerStore) |
| CanRxListener ** | getHandlerStore (CanBus bus) |
Protected Attributes | |
| Drivers * | drivers |
| CanRxListener * | messageHandlerStoreCan1 [CAN_BINS] |
| CanRxListener * | messageHandlerStoreCan2 [CAN_BINS] |
A handler that stores pointers to CanRxListener and that watches CAN 1 and CAN 2 for messages. If messages are received, it checks its internal maps for a CanRxListener that matches the message identifier and CAN bus and calls the listener's processMessage function.
Interfaces with modm receive data from CAN1 and CAN2 buses.
To use, extend CanRxListener class and create a method called processMessage. Next, call the function attachReceiveHandler, which will add the class you instantiated to a list of classes that will be handled on receive. The class you created and attached will be called by the pollCanData function every time there is a message available that has the CAN identifier matching the identifier specified in the CanRxListener constructor.
For proper closed loop motor control, it is necessary to have the pollCanData function be called at a very high frequency, so call this in a high frequency thread.
0x201, 0x20B] are used by the DjiMotor objects to receive data from DJI branded motors. If you would like to define your own protocol, it is recommended to avoid avoid using CAN ids in this range. 0x1FF and 0x200 for commanding motors, and thus you should not attach listeners for these ids.CanRxListener for information about how to properly create add a listener to the handler. Can for modm CAN wrapper functions. | tap::can::CanRxHandler::CanRxHandler | ( | Drivers * | drivers | ) |
|
default |
|
protected |
| void tap::can::CanRxHandler::attachReceiveHandler | ( | CanRxListener *const | listener | ) |
Call this function to add a CanRxListener to the list of CanRxListener's that are referenced when a new CAN message is received.
CanRxHandler, an error will be added to the ErrorController and the handler does not add the listener. CanRxListener| [in] | listener | the listener to be attached ot the handler. |
|
inlinestatic |
Given a CAN identifier, returns the bin index between [0, NUM_CAN_IDS) for the identifier.
|
inlineprotected |
| void tap::can::CanRxHandler::pollCanData | ( | ) |
Function handles receiving messages and calling the appropriate processMessage function given the CAN bus and can identifier.
|
protected |
|
protected |
| void tap::can::CanRxHandler::removeReceiveHandler | ( | const CanRxListener & | rxListener | ) |
Removes the passed in CanRxListener from the CanRxHandler. If the listener isn't in the handler, an error will be added to the ErrorController and the state of the CanRxHandler will not change.
| [in] | rxListener | The listener to remove from the handler. |
|
staticconstexpr |
The number of "hash" bins to store listeners in. 8 is choosen as most users will only have DJI Motors on their can bus, reducing any unnecessary overhead storing empty bins. The bus also become saturated near this limit, so the performance hit of a linked list traversal is minimal.
|
protected |
|
protected |
Stores pointers to the CanRxListeners for CAN 1, referenced when a new message is received.
|
protected |
Stores pointers to the CanRxListeners for CAN 2, referenced when a new message is received.