4.5.1.4.1. DBC Parsing
There are two methods available - realtime and code generation.
4.5.1.4.1.1. Realtime approach
The real-time approach assumes that DBC files will be parsed in real time.
The following development approach is proposed:
At the application startup stage (StartupModule()), it is necessary to register the necessary DBC files, for example:
FString DBCDirectory = FPaths::Combine(IPluginManager::Get().FindPlugin(TEXT("SodaContrib"))->GetBaseDir(), TEXT("/DBC"));
SodaApp.RegisterDBC(TEXT("ARS408"), DBCDirectory / TEXT("ARS408_can_database.dbc"));
Place all messages for one component on one CAN bus in one structure of the form:
struct UARS408SensorComponent::FCANFMessageMap : public dbc::FMessageMap
{
DEFINE_DBC_MSG_DYNAMIC(Cluster_0_Status, CANID_DEFAULT, ECanFrameDir::Output, , ECanFrameType::Std, Cluster_MeasCounter, Cluster_NofClustersNear, Cluster_NofClustersFar, Cluster_InterfaceVersion);
DEFINE_DBC_MSG_DYNAMIC(Cluster_1_General, CANID_DEFAULT, ECanFrameDir::Output, , ECanFrameType::Std, Cluster_DynProp, Cluster_VrelLat, Cluster_RCS, Cluster_DistLong, Cluster_ID, Cluster_VrelLong, Cluster_DistLat);
DEFINE_DBC_MSG_DYNAMIC(Obj_0_Status, CANID_DEFAULT, ECanFrameDir::Output, , ECanFrameType::Std, Obj_NofObjects, Obj_MeasCounter, Obj_InterfaceVersion);
DEFINE_DBC_MSG_DYNAMIC(Obj_1_General, CANID_DEFAULT, ECanFrameDir::Output, , ECanFrameType::Std, Obj_DynProp, Obj_RCS, Obj_VrelLat, Obj_ID, Obj_DistLong, Obj_VrelLong, Obj_DistLat);
DEFINE_DBC_MSG_DYNAMIC(Obj_2_Quality, CANID_DEFAULT, ECanFrameDir::Output, , ECanFrameType::Std, Obj_ProbOfExist, Obj_MeasState, Obj_ArelLong_rms, Obj_ArelLat_rms, Obj_VrelLong_rms, Obj_VrelLat_rms, Obj_Orientation_rms, Obj_DistLong_rms, Obj_DistLat_rms, Obj_ID);
DEFINE_DBC_MSG_DYNAMIC(Obj_3_Extended, CANID_DEFAULT, ECanFrameDir::Output, , ECanFrameType::Std, Obj_Class, Obj_ArelLat, Obj_ID, Obj_OrientationAngle, Obj_Width, Obj_Length, Obj_ArelLong);
DEFINE_DBC_MSG_DYNAMIC(RadarState, CANID_DEFAULT, ECanFrameDir::Output, , ECanFrameType::Std, RadarState_Voltage_Error, RadarState_Temporary_Error, RadarState_Temperature_Error, RadarState_Interference, RadarState_Persistent_Error, RadarState_SortIndex, RadarState_RCS_Threshold, RadarState_CtrlRelayCfg, RadarState_SendQualityCfg, RadarState_SendExtInfoCfg, RadarState_MotionRxState, RadarState_SensorID, RadarState_OutputTypeCfg, RadarState_RadarPowerCfg, RadarState_NVMReadStatus, RadarState_NVMwriteStatus, RadarState_MaxDistanceCfg);
DEFINE_DBC_MSG_DYNAMIC(RadarConfiguration, CANID_DEFAULT, ECanFrameDir::Input, ECanFrameType::Std, RadarCfg_RCS_Threshold_Valid, RadarCfg_RCS_Threshold, RadarCfg_StoreInNVM_valid, RadarCfg_SortIndex_valid, RadarCfg_SortIndex, RadarCfg_StoreInNVM, RadarCfg_SendExtInfo_valid, RadarCfg_SendExtInfo, RadarCfg_CtrlRelay_valid, RadarCfg_CtrlRelay, RadarCfg_SendQuality_valid, RadarCfg_SendQuality, RadarCfg_MaxDistance_valid, RadarCfg_RadarPower_valid, RadarCfg_OutputType_valid, RadarCfg_SensorID_valid, RadarCfg_MaxDistance, RadarCfg_RadarPower, RadarCfg_OutputType, RadarCfg_SensorID);
DEFINE_DBC_MSG_DYNAMIC(YawRateInformation, CANID_DEFAULT, ECanFrameDir::Input, ECanFrameType::Std, RadarDevice_YawRate);
};
The DEFINE_DBC_MSG_DYNAMIC macro instantiates one type of CAN message from signal sets specified in the parameter list. If a component is expected to connect to more than one bus, then it is necessary to create a separate FMessageMap structure for each bus.
Next, in the component initialization code, an instance of the previously declared structure is declared and all its messages are registered in UCANBusComponent:
Messages = MakeShared< UARS408SensorComponent::FCANFMessageMap>();
Messages->RegisterMessages(CANBus)
Write a signal in a message:
Messages->Cluster_0_Status.Cluster_MeasCounter.Set(3);
Reading a signal from a message:
int Value = Messages->Cluster_0_Status.Cluster_MeasCounter.Get<int>();
Sending a message:
Messages->Cluster_0_Status.SendMessage();
4.5.1.4.1.2. Code generation approach
The code generation approach assumes that C++ will first be generated based on the DBC file, which will perform serialization/deserialization of the corresponding CAN messages.
Generation is carried out using the dbc_processor tool.
This part of the guide is under development