Library for publish/subscribe communication via CAN with the teensy 3.2 board.
The CommunicationManager provides a simple interface to communicate over CAN. It follows the Publisher-Subscriber pattern.
A publisher is offering messages to all other network nodes. Subscribers can subscribe to messages which they are interested in.
The library is built on top of FlexCAN.
You need a teensy 3.2 board and a CAN transreceiver (e.g. SN65HVD230) to use this library.
Just take a look into the examples to see how to use the CommunicationManager class. Please keep in mind that the maximum message size is limited to 8 bytes.
Provided functions:
Function | Parameters | Return value | Description |
---|---|---|---|
static CommunicationManager GetInstance(); | - | Pointer to the class instance | |
void Initialize(uint32_t baud = 500000, COMMUNICATION_BYTE_ORDER byteOrder = ORDER_MSB); | baud: Speed in bits per second byteOrder: Data byte order | - | Initializes the CommunicationManager. Should be called in the setup() method of your sketch |
void Update(); | - | - | Call this function in the loop() method of your sketch |
bool Fire(unsigned int canId); | canId: CAN Identifier | False if an error occured, otherwise true | Writes a CAN message immediately into the message queue |
bool Fire(void val, unsigned int bytes, unsigned int canId); | val: Pointer to value bytes: Number of bytes canId: CAN Identifier | False if an error occured, otherwise true | Writes a CAN message immediately into the message queue |
bool Publish(void val, unsigned int bytes, unsigned int canId, unsigned char txFlag, COM_CYCLE cycle); | val: Pointer to value bytes: Number of bytes canId: CAN Identifier txFlag: Pointer to transmitted flag cycle: Send cycletime | False if an error occured, otherwise true | Publishes value with the given CAN Identifier with specified cycle time. The flag gets set to ‘1’ everytime the value was sent |
bool Subscribe(void val, unsigned int bytes, unsigned int canId, unsigned char rxFlag); | val: Pointer to value bytes: Number of bytes canId: CAN Identifier rxFlag: Pointer to received flag | False if an error occured, otherwise true | Subscribes to a CAN message and writes the received payload into value. The flag gets set to ‘1’ everytime a message was received |
Byte Order values:
Cycle Time values: