CAN Interpreter Module workflow
Initialization
The interpreter module for DBC format is initialized as follows:
DW_API_PUBLIC dwStatus dwCANInterpreter_buildFromDBC(dwCANInterpreterHandle_t *interpreter, const char8_t *inputDBC, dwContextHandle_t ctx)
Creates a CAN data interpreter based on DBC file format.
struct dwCANInterpreterObject * dwCANInterpreterHandle_t
CAN message interpreter handle.
The DBC message and signals definition file will be parsed to initialize the interpreter. Please refer to a DBC file format documentation for additional details on the expected syntax.
An interpreter for user-defined format is initialized as follows:
dwCANInterpreterGetSignalInfoFunc_t getSignalInfo
dwCANInterpreterAddMessageFunc_t addMessage
dwCANInterpreterGetDatai32Func_t getDatai32
dwCANInterpreterGetDataf32Func_t getDataf32
dwCANInterpreterGetNumAvailableFunc_t getNumAvailableSignals
dwCANInterpreterGetDataf64Func_t getDataf64
DW_API_PUBLIC dwStatus dwCANInterpreter_buildFromCallbacks(dwCANInterpreterHandle_t *interpreter, dwCANInterpreterInterface callbacks, void *userData, dwContextHandle_t context)
Creates a CAN data interpreter based on user provided callbacks.
Interface for callback based CAN data interpreter.
The dwCANInterpreterInterface
structure is populated with pointers to the callbacks implemented by the user. The expected callback signatures are detailed in Interpreter.h. The callbacks are used as follows:
The following callbacks are required to be implemented:
addMessage
getNumAvailableSignals
getSignalInfo
The following callbacks are optional and have to be implemented only if a signal data type requires them:
getDataf32
getDataf64
getDatai32
An example implementation of those callbacks is provided in CAN Message Interpreter Sample
Consuming messages
CAN messages can be provided to the interpreter for parsing as follows:
DW_API_PUBLIC dwStatus dwCANInterpreter_consume(const dwCANMessage *msg, dwCANInterpreterHandle_t interpreter)
Pushes a new message to the interpreter.
Then used as follows:
uint32_t num;
if (status == DW_SUCCESS && num > 0)
{
int32_t int_value = 0;
const char* name;
for (uint32_t i = 0; i < num; ++i)
{
{
if (strcmp(name, "some_signal_int") == 0)
{
std::cout << "some_signal_int value: " << int_value << std::endl;
else
std::cerr << "error getting value for some_signal_int" << std::endl;
}
elseif (strcmp(name, "some_signal_float") == 0)
{
std::cout << "some_signal_float value: " << float_value << std::endl;
else
std::cerr << "error getting value for some_signal_float" << std::endl;
}
else std::cerr << "unhandled signal name" << std::endl;
}
}
}
dwStatus
Status definition.
float float32_t
Specifies POD types.
int64_t dwTime_t
Specifies a timestamp unit, in microseconds.
DW_API_PUBLIC dwStatus dwCANInterpreter_getSignalName(const char8_t **name, uint32_t idx, dwCANInterpreterHandle_t interpreter)
Gets the name of a signal available for consumption by the application as a string.
DW_API_PUBLIC dwStatus dwCANInterpreter_geti32(int32_t *value, dwTime_t *timestamp_us, uint32_t idx, dwCANInterpreterHandle_t interpreter)
Same as dwCANInterpreter_getf32, but for int32 types.
DW_API_PUBLIC dwStatus dwCANInterpreter_getNumberSignals(uint32_t *num, dwCANInterpreterHandle_t interpreter)
Gets the number of signals decoded and available for consumption by the application side.
DW_API_PUBLIC dwStatus dwCANInterpreter_getf32(float32_t *value, dwTime_t *timestamp_us, uint32_t idx, dwCANInterpreterHandle_t interpreter)
Gets a 'float32_t' value from the available values.
The above snippet iterates over all signals handled by the intepreter, and attempts to read a value for each signal, in the latest consumed dwCANMessage
.
Note that in general the number of signals as returned by dwCANInterpreter_getNumberSignals()
is the number of valid signals found in last consumed CAN message. However this does not have to be true in user-provided callback based interpreters, as it is implementation dependent.
Releasing the interpreter
The interpreter can be released as follows:
DW_API_PUBLIC dwStatus dwCANInterpreter_release(dwCANInterpreterHandle_t interpreter)
Closes previously opened interpreter.
For more details see CAN Message Interpreter Sample