Library to decode proprietary data from the CAN bus of a vehicle and relate it to standard OBD-II parameters (PIDs). The library will require access to the hardware peripheral's filter configuration and the main loop shall pass the relevant packets to the library when received. The library will update the PID pointer value as it receives new data.
The CAN bus decode packet manager requires a single callback; filter
. This function is called whenever the library needs a hardware filter enabled in order to obtain the requested PID data.
Future updates should allow the filter to be disabled.
The callback will pass the arbitration ID that the library is requesting to receive:
typedef void (*CAN_DECODE_FILTER)( uint16_t id );
Therefore, the callback will be configured as seen below:
void add_can_bus_filter( uint16_t id )
{
/* Add hardware filter here */
}
/* Declare a CAN Bus decode packet manager */
static CAN_DECODE_PACKET_MANAGER decode;
int main( void )
{
/* Assign the callback to the filter */
decode.filter = &add_can_bus_filter;
...
Once the callback is configured, the library is ready to be initialized:
void add_can_bus_filter( uint16_t id )
{
/* Add hardware filter here */
}
/* Declare a CAN Bus decode packet manager */
static CAN_DECODE_PACKET_MANAGER decode;
int main( void )
{
/* Assign the callback to the filter */
decode.filter = &add_can_bus_filter;
/* Initalize the library */
CAN_Decode_Initialize( &decode );
}
To check if a PID can be decoded, the function CAN_Decode_Supported( pid )
needs to be called. A PID pointer with the mode and pid assigned is all that is needed, the other variables of the struct are ignored. The function will return PID_SUPPORTED
or PID_NOT_SUPPORTED
.
At this point, no PID is actually assigned, the library is only indicating if the PID can be added to the library.
A PID can be added with the function CAN_Decode_Add_PID( dev, pid )
. This function will require a CAN Decode Packet Manager pointer and a PID pointer. Just like the PID supported check, the function will either return PID_SUPPORTED
or PID_NOT_SUPPORTED
.
At this point, a PID is assigned to the packet manager and the PID value will be updated as data is received.
Note, adding a PID will automatically verify if the PID is supported, so a PID supported check does not NEED to be called before assingment.
To Do: For now, reset the app if PIDs need to be removed and then re-add the PIDs you wish to keep.
Once the CAN bus decode packet manager has been initialized, all recieved CAN bus packets should be passed to the library using CAN_Decode_Add_Packet( dev, id, data )
. The function will process the data and update any relevant PID value(s) if possible.
The CAN Decode library will copy the address of the PID when the PID is added to the packet manager using CAN_Decode_Add_PID()
. From then on it will use that address to assign the PID value. Therefore other libraries can access the information by referencing the same address containing that PID struct.