I am trying to generate C++ code from a .dbc file.
e.g. A message is defined like following in .dbc file
BO_ 500 IO_DEBUG: 5 IO
SG_ IO_DEBUG_test_unsigned : 0|8@1+ (1,0) [0|0] "" DBG
SG_ IO_DEBUG_test_signed : 8|8@1- (1,-128) [0|0] "" DBG
SG_ IO_DEBUG_test_float1 : 16|8@1+ (0.1,0) [0|0] "" DBG
SG_ IO_DEBUG_test_float2 : 24|12@1+ (0.01,-20.48) [-20.48|20.47] "" DBG
SG_ IO_DEBUG_test_enum : 38|2@1+ (1,0) [0|0] "" DBG
BA_ "FieldType" SG_ 500 IO_DEBUG_test_enum "IO_DEBUG_test_enum";
VAL_ 500 IO_DEBUG_test_enum 2 "IO_DEBUG_test2_enum_two" 1 "IO_DEBUG_test2_enum_one" ;
I am trying to generate C++ code something like this. Message name will become the Class name and all signals should become the members of the class along with data-types.
//IoDebug.h -- ProcessMessageInterface is an interface.
class IoDebug : public ProcessMessageInterface {
pubic:
// ProcessMessageInterface implementation
void processMessage();
private:
uint8_t testUnSigned;
int8_t testSigned;
float testFloat1;
float testFloat2;
IO_DEBUG_test_enum testEnum;
};
//IoDebug.cpp
#include "IoDebug.h"
IoDebug::processMessage()
{
}
Is there any dbc parser and code generation tool(s) exists which can generate code like above?
Here is a python script which generates C++ code. You need to install cantools packages to run following script.
run it as
Above script will generate following header and cpp files.
IoDEBUG.h
IoDEBUG.cpp