TsctlCANRxDesc

From embeddedTS Manuals

Blocks until a message is received from CAN. The message is put into the CANmessage buffer passed by the caller.

In direct mode all available CPU will be used to poll for a message to be received. If this is a problem it is recommended to use the CAN server which uses interrupts.

Returns a positive return value if a message was received into the buffer provided, or a negative value if the receive was aborted. The latter could occur if Abort was explicitly called before the message was received, or if another error such as a Bus Off condition occurred.

struct CANMessage {
  unsigned flags;
  unsigned id;
  unsigned t_sec;
  unsigned t_usec;
  unsigned length;
  unsigned char data[8];
};


typedef enum CANFlags{
  FLAG_BUS_ERROR=1,
  FLAG_ERROR_PASSIVE=2,
  FLAG_DATA_OVERRUN=4,
  FLAG_ERROR_WARNING=8,
  FLAG_RTR=16,
  FLAG_EXT_ID=32,
  FLAG_LOCAL=64,
  FLAG_CONTROL=128
} CANFlags;


The timestamp fields (t_sec, t_usec) contain the server time when the CAN packet was received. For performance reasons some servers may not implement this and may fill these fields with 0.

The length field indicates how many bytes of data are in this CAN frame, and consequently, how many sequential bytes in the data field is valid.