Defines the CAN sensor methods.
Data Structures | |
struct | dwCANMessage |
Holds a CAN package. More... | |
Modules | |
Interpreter | |
Defines the CAN message interpreter methods. | |
Vehicle Data Interface | |
Defines the methods used to obtain and store vehicle data. | |
Macros | |
#define | DW_SENSORS_CAN_MAX_FILTERS 255 |
Maximum number of filter that can be specified. More... | |
#define | DW_SENSORS_CAN_MAX_ID_LEN 29 |
This module provides access to the CAN bus typically used for communication between different ECUs in a vehicle. More... | |
#define | DW_SENSORS_CAN_MAX_MESSAGE_LEN 64 |
Maximal length of the supported CAN payload [bytes]. More... | |
Functions | |
DW_API_PUBLIC dwStatus | dwSensorCAN_popMessage (dwCANMessage *msg, dwSensorHandle_t sensor) |
Returns any CAN data previously processed through a RAW data stream. More... | |
DW_API_PUBLIC dwStatus | dwSensorCAN_processRawData (const uint8_t *data, size_t size, dwSensorHandle_t sensor) |
Decodes CAN data previously read as a RAW data stream into internal queue. More... | |
DW_API_PUBLIC dwStatus | dwSensorCAN_readMessage (dwCANMessage *const msg, dwTime_t const timeoutUs, dwSensorHandle_t const sensor) |
Reads a CAN packet (raw data and process it) within a given timeout from the CAN bus. More... | |
DW_API_PUBLIC dwStatus | dwSensorCAN_sendMessage (const dwCANMessage *const msg, dwTime_t const timeoutUs, dwSensorHandle_t const sensor) |
Sends a message over the CAN bus within a specified timeout. More... | |
DW_API_PUBLIC dwStatus | dwSensorCAN_setMessageFilter (const uint32_t *ids, const uint32_t *masks, uint16_t num, dwSensorHandle_t sensor) |
Specifes a set of CAN IDs to be filtered. More... | |
DW_API_PUBLIC dwStatus | dwSensorCAN_setUseHwTimestamps (bool const flag, dwSensorHandle_t const sensor) |
Enables or disables hardware timestamp of the CAN messages. More... | |
struct dwCANMessage |
Data Fields | ||
---|---|---|
uint8_t | data[DW_SENSORS_CAN_MAX_MESSAGE_LEN] | Payload. |
uint32_t | id | CAN ID of the message sender. |
uint16_t | size | Number of bytes of the payload. |
dwTime_t | timestamp_us | Timestamp of the message in microseconds from system epoch (using clock of the context). |
#define DW_SENSORS_CAN_MAX_FILTERS 255 |
#define DW_SENSORS_CAN_MAX_ID_LEN 29 |
This module provides access to the CAN bus typically used for communication between different ECUs in a vehicle.
The implementation provides an abstracted layer over any implemented sensor drivers, supporting receive, send and filtering routines.
CAN data packet as of ISO 11898-1:
If you have a real CAN device, activate it with this command:
A virtual device is created using following commands:
In order to send data from console to the virtual CAN bus, the cansend tool (from the can-utils package) can be used.
Maximal length of the supported CAN message id [bits].
#define DW_SENSORS_CAN_MAX_MESSAGE_LEN 64 |
DW_API_PUBLIC dwStatus dwSensorCAN_popMessage | ( | dwCANMessage * | msg, |
dwSensorHandle_t | sensor | ||
) |
Returns any CAN data previously processed through a RAW data stream.
This happens on the CPU thread where the function is called, incurring on additional load on that thread.
[out] | msg | Container for the decoded message. |
[in] | sensor | Sensor handle of the sensor previously created with 'dwSAL_createSensor()'. |
DW_API_PUBLIC dwStatus dwSensorCAN_processRawData | ( | const uint8_t * | data, |
size_t | size, | ||
dwSensorHandle_t | sensor | ||
) |
Decodes CAN data previously read as a RAW data stream into internal queue.
[in] | data | Undecoded CAN data. |
[in] | size | Size in bytes of the raw data. |
[in] | sensor | Sensor handle of the sensor previously created with 'dwSAL_createSensor()'. |
DW_API_PUBLIC dwStatus dwSensorCAN_readMessage | ( | dwCANMessage *const | msg, |
dwTime_t const | timeoutUs, | ||
dwSensorHandle_t const | sensor | ||
) |
Reads a CAN packet (raw data and process it) within a given timeout from the CAN bus.
The method blocks until either a new valid message is received on the bus or the given timeout exceeds.
[out] | msg | A pointer to a CAN message structure to be filled with new data. |
[in] | timeoutUs | Specifies a timeout, in us, to wait for a new message. Special values: DW_TIMEOUT_INFINITE - to wait infinitly. Zero - means polling of internal queue. |
[in] | sensor | Specifies a sensor handle of the CAN sensor previously created with 'dwSAL_createSensor()'. |
DW_API_PUBLIC dwStatus dwSensorCAN_sendMessage | ( | const dwCANMessage *const | msg, |
dwTime_t const | timeoutUs, | ||
dwSensorHandle_t const | sensor | ||
) |
Sends a message over the CAN bus within a specified timeout.
A message is guaranteed to have been sent when this method returns 'DW_SUCCESS'. The method can block for up-to the specified amount of time if a bus is blocked or previous dwSensorCAN_readMessage() operation has not yet finished. The way the message is packed and sent to the sensor depends on the specific CAN class implementation used.
[in] | msg | A pointer to the message to be sent. |
[in] | timeoutUs | Specifies the timeout, in microseconds from system epoch, to wait at most before giving up. |
[in] | sensor | Specifies a CAN bus sensor to send the message over. |
DW_API_PUBLIC dwStatus dwSensorCAN_setMessageFilter | ( | const uint32_t * | ids, |
const uint32_t * | masks, | ||
uint16_t | num, | ||
dwSensorHandle_t | sensor | ||
) |
Specifes a set of CAN IDs to be filtered.
The filter is active if it contains at least one sender ID.
[in] | ids | A pointer to an array of CAN IDs to be filtered. Any matching CAN ID is used together with the mask to filter. |
[in] | masks | A pointer to an array of filter masks to be applied. A mask is applied together with the ID as 'id & mask'. If mask is set to NULL, a default mask of '1FFFFFFF' is used. |
[in] | num | Specifies the number of elements passed in the array. To remove the filter, pass 0. |
[in] | sensor | Specifies the sensor handle of the CAN sensor previously created with 'dwSAL_createSensor()'. |
DW_API_PUBLIC dwStatus dwSensorCAN_setUseHwTimestamps | ( | bool const | flag, |
dwSensorHandle_t const | sensor | ||
) |
Enables or disables hardware timestamp of the CAN messages.
Hardware timestamps are used per default when supported by the sensor. If HW timestamps are not supported, SW timestamps are used per default and no operation shall be performed. HW timestamps can be turned off if the default behavior is not working properly with the current hardware stack. If any result different from DW_SUCCESS is returned, no operation shall be performed by this method.
[in] | flag | Specifies either 'true' or 'false' to enable or disable hardware timestamping. |
[in] | sensor | Specifies the sensor handle of the CAN sensor previously created with 'dwSAL_createSensor()'. |