项目作者: code2love

项目描述 :
Library for publish/subscribe communication via CAN with the teensy 3.2 board.
高级语言: C
项目地址: git://github.com/code2love/CommunicationManager.git
创建时间: 2019-03-01T13:30:01Z
项目社区:https://github.com/code2love/CommunicationManager

开源协议:

下载


CommunicationManager

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.

Required Hardware

You need a teensy 3.2 board and a CAN transreceiver (e.g. SN65HVD230) to use this library.

How 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:

  • ORDER_MSB
  • ORDER_LSB

Cycle Time values:

  • CYCLE_10 (10ms)
  • CYCLE_20 (20ms)
  • CYCLE_40 (40ms)
  • CYCLE_80 (80ms)
  • CYCLE_100 (100ms)