#ifndef __GENEARTED_DBC_PARSER
#define __GENERATED_DBC_PARSER
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
/// Extern function needed for dbc_encode_and_send()
extern bool dbc_app_send_can_msg(uint32_t mid, uint8_t dlc, uint8_t bytes[8]);
/// Missing in Action structure
typedef struct {
uint32_t is_mia : 1; ///< Missing in action flag
uint32_t mia_counter_ms : 31; ///< Missing in action counter
} dbc_mia_info_t;
/// CAN message header structure
typedef struct {
uint32_t mid; ///< Message ID of the message
uint8_t dlc; ///< Data length of the message
} dbc_msg_hdr_t;
static const dbc_msg_hdr_t DBC_TEST1_HDR = { 0x1f4, 8 };
static const dbc_msg_hdr_t DBC_TEST2_HDR = { 0x1f5, 8 };
static const dbc_msg_hdr_t DBC_TEST3_HDR = { 0x1f6, 8 };
// static const dbc_msg_hdr_t DRIVER_HEARTBEAT_HDR = { 0x64, 1 };
// static const dbc_msg_hdr_t MOTOR_CMD_HDR = { 0x65, 1 };
static const dbc_msg_hdr_t MOTOR_STATUS_HDR = { 0x190, 3 };
static const dbc_msg_hdr_t SENSOR_SONARS_HDR = { 0xc8, 8 };
static const dbc_msg_hdr_t DBC_TEST4_HDR = { 0x1f7, 8 };
/// Message: DBC_TEST1 from 'IO', DLC: 8 byte(s), MID: 0x1f4
typedef struct {
uint32_t DBC_TEST1_unsigned1 : 8; ///< B7:0 Destination: DBG
uint32_t DBC_TEST1_unsigned_minmax : 8; ///< B15:8 Min: 0 Max: 100 Destination: DBG
uint32_t DBC_TEST1_enum : 8; ///< B39:32 Destination: DBG
uint32_t DBC_TEST1_float : 8; ///< B47:40 Destination: DBG
uint32_t DBC_TEST1_float_signed : 16; ///< B63:48 Min: 0 Max: 65.535 Destination: DBG
// No dbc_mia_info_t for a message that we will send
} DBC_TEST1_t;
/// Message: DBC_TEST2 from 'IO', DLC: 8 byte(s), MID: 0x1f5
typedef struct {
uint32_t DBC_TEST2_real_signed1 : 12; ///< B17:6 Destination: DBG
uint32_t DBC_TEST2_real_signed2 : 18; ///< B35:18 Destination: DBG
uint32_t DBC_TEST2_signed : 8; ///< B43:36 Destination: DBG
uint32_t DBC_TEST2_signed_minmax : 16; ///< B59:44 Min: -32768 Max: 32767 Destination: DBG
// No dbc_mia_info_t for a message that we will send
} DBC_TEST2_t;
/// Message: DBC_TEST3 from 'IO', DLC: 8 byte(s), MID: 0x1f6
typedef struct {
uint32_t DBC_TEST3_real_signed1 : 4; ///< B5:2 Destination: DBG
uint32_t DBC_TEST3_real_signed2 : 8; ///< B15:8 Destination: DBG
// No dbc_mia_info_t for a message that we will send
} DBC_TEST3_t;
/// Message: MOTOR_STATUS from 'MOTOR', DLC: 3 byte(s), MID: 0x190
typedef struct {
uint32_t MOTOR_STATUS_wheel_error : 1; ///< B0:0 Destination: DRIVER,IO
uint32_t MOTOR_STATUS_speed_kph : 16; ///< B23:8 Destination: DRIVER,IO
dbc_mia_info_t mia_info;
} MOTOR_STATUS_t;
/// @{ MUX'd message: SENSOR_SONARS
/// Struct for MUX: m0 (used for transmitting)
typedef struct {
uint32_t SENSOR_SONARS_err_count : 12; ///< B15:4 Destination: DRIVER,IO
uint32_t SENSOR_SONARS_left : 12; ///< B27:16 Destination: DRIVER,IO
uint32_t SENSOR_SONARS_middle : 12; ///< B39:28 Destination: DRIVER,IO
uint32_t SENSOR_SONARS_right : 12; ///< B51:40 Destination: DRIVER,IO
uint32_t SENSOR_SONARS_rear : 12; ///< B63:52 Destination: DRIVER,IO
dbc_mia_info_t mia_info;
} SENSOR_SONARS_m0_t;
/// Struct for MUX: m1 (used for transmitting)
typedef struct {
uint32_t SENSOR_SONARS_err_count : 12; ///< B15:4 Destination: DRIVER,IO
uint32_t SENSOR_SONARS_no_filt_left : 12; ///< B27:16 Destination: DBG
uint32_t SENSOR_SONARS_no_filt_middle : 12; ///< B39:28 Destination: DBG
uint32_t SENSOR_SONARS_no_filt_right : 12; ///< B51:40 Destination: DBG
uint32_t SENSOR_SONARS_no_filt_rear : 12; ///< B63:52 Destination: DBG
dbc_mia_info_t mia_info;
} SENSOR_SONARS_m1_t;
/// Struct with all the child MUX'd signals (Used for receiving)
typedef struct {
SENSOR_SONARS_m0_t m0; ///< MUX'd structure
SENSOR_SONARS_m1_t m1; ///< MUX'd structure
} SENSOR_SONARS_t;
/// @} MUX'd message
/// Message: DBC_TEST4 from 'IO', DLC: 8 byte(s), MID: 0x1f7
typedef struct {
uint32_t DBC_TEST4_real_signed1 : 32; ///< B31:0 Destination: DBG
uint32_t DBC_TEST4_real_signed2 : 16; ///< B47:32 Min: -32768 Max: 32767 Destination: DBG
uint32_t DBC_TEST4_real_overflow : 16; ///< B63:48 Destination: DBG
// No dbc_mia_info_t for a message that we will send
} DBC_TEST4_t;
/// @{ These 'externs' need to be defined in a source file of your project
extern const uint32_t MOTOR_STATUS__MIA_MS;
extern const MOTOR_STATUS_t MOTOR_STATUS__MIA_MSG;
extern const uint32_t SENSOR_SONARS_m0__MIA_MS;
extern const SENSOR_SONARS_m0_t SENSOR_SONARS_m0__MIA_MSG;
extern const uint32_t SENSOR_SONARS_m1__MIA_MS;
extern const SENSOR_SONARS_m1_t SENSOR_SONARS_m1__MIA_MSG;
/// @}
/// Encode IO's 'DBC_TEST1' message
/// @returns the message header of this message
static inline dbc_msg_hdr_t dbc_encode_DBC_TEST1(uint8_t frame[8], DBC_TEST1_t *msg)
{
uint32_t raw;
frame[0]=frame[1]=frame[2]=frame[3]=frame[4]=frame[5]=frame[6]=frame[7]=0;
// Stuff a SIG into the DBC 8-bit signal
///< bit(s) starting from BBitStart:0BitSize:8
set_frame_data(frame, MOTOROLA_MSB, 0, 8, msg->DBC_TEST1_unsigned1);
// Stuff a SIG into the DBC 8-bit signal
///< bit(s) starting from BBitStart:8BitSize:8
set_frame_data(frame, MOTOROLA_MSB, 8, 8, msg->DBC_TEST1_unsigned_minmax);
// Stuff a SIG into the DBC 8-bit signal
///< bit(s) starting from BBitStart:32BitSize:8
set_frame_data(frame, MOTOROLA_MSB, 32, 8, msg->DBC_TEST1_enum);
// Stuff a SIG into the DBC 8-bit signal
///< bit(s) starting from BBitStart:40BitSize:8
set_frame_data(frame, MOTOROLA_MSB, 40, 8, msg->DBC_TEST1_float);
// Stuff a SIG into the DBC 16-bit signal
///< bit(s) starting from BBitStart:48BitSize:16
set_frame_data(frame, MOTOROLA_MSB, 48, 16, msg->DBC_TEST1_float_signed);
return DBC_TEST1_HDR;
}
/// Encode and send for dbc_encode_DBC_TEST1() message
static inline bool dbc_encode_and_send_DBC_TEST1(DBC_TEST1_t *from)
{
uint8_t bytes[8];
const dbc_msg_hdr_t hdr = dbc_encode_DBC_TEST1(bytes, from);
return dbc_app_send_can_msg(hdr.mid, hdr.dlc, bytes);
}
/// Encode IO's 'DBC_TEST2' message
/// @returns the message header of this message
static inline dbc_msg_hdr_t dbc_encode_DBC_TEST2(uint8_t frame[8], DBC_TEST2_t *msg)
{
uint32_t raw;
frame[0]=frame[1]=frame[2]=frame[3]=frame[4]=frame[5]=frame[6]=frame[7]=0;
// Stuff a SIG into the DBC 12-bit signal
///< bit(s) starting from BBitStart:6BitSize:12
set_frame_data(frame, MOTOROLA_MSB, 6, 12, msg->DBC_TEST2_real_signed1);
// Stuff a SIG into the DBC 18-bit signal
///< bit(s) starting from BBitStart:18BitSize:18
set_frame_data(frame, MOTOROLA_MSB, 18, 18, msg->DBC_TEST2_real_signed2);
// Stuff a SIG into the DBC 8-bit signal
///< bit(s) starting from BBitStart:36BitSize:8
set_frame_data(frame, MOTOROLA_MSB, 36, 8, msg->DBC_TEST2_signed);
// Stuff a SIG into the DBC 16-bit signal
///< bit(s) starting from BBitStart:44BitSize:16
set_frame_data(frame, MOTOROLA_MSB, 44, 16, msg->DBC_TEST2_signed_minmax);
return DBC_TEST2_HDR;
}
/// Encode and send for dbc_encode_DBC_TEST2() message
static inline bool dbc_encode_and_send_DBC_TEST2(DBC_TEST2_t *from)
{
uint8_t bytes[8];
const dbc_msg_hdr_t hdr = dbc_encode_DBC_TEST2(bytes, from);
return dbc_app_send_can_msg(hdr.mid, hdr.dlc, bytes);
}
/// Encode IO's 'DBC_TEST3' message
/// @returns the message header of this message
static inline dbc_msg_hdr_t dbc_encode_DBC_TEST3(uint8_t frame[8], DBC_TEST3_t *msg)
{
uint32_t raw;
frame[0]=frame[1]=frame[2]=frame[3]=frame[4]=frame[5]=frame[6]=frame[7]=0;
// Stuff a SIG into the DBC 4-bit signal
///< bit(s) starting from BBitStart:2BitSize:4
set_frame_data(frame, MOTOROLA_MSB, 2, 4, msg->DBC_TEST3_real_signed1);
// Stuff a SIG into the DBC 8-bit signal
///< bit(s) starting from BBitStart:8BitSize:8
set_frame_data(frame, MOTOROLA_MSB, 8, 8, msg->DBC_TEST3_real_signed2);
return DBC_TEST3_HDR;
}
/// Encode and send for dbc_encode_DBC_TEST3() message
static inline bool dbc_encode_and_send_DBC_TEST3(DBC_TEST3_t *from)
{
uint8_t bytes[8];
const dbc_msg_hdr_t hdr = dbc_encode_DBC_TEST3(bytes, from);
return dbc_app_send_can_msg(hdr.mid, hdr.dlc, bytes);
}
/// Not generating code for dbc_encode_DRIVER_HEARTBEAT() since the sender is DRIVER and we are IO
/// Not generating code for dbc_encode_MOTOR_CMD() since the sender is DRIVER and we are IO
/// Not generating code for dbc_encode_MOTOR_STATUS() since the sender is MOTOR and we are IO
/// Not generating code for dbc_encode_SENSOR_SONARS() since the sender is SENSOR and we are IO
/// Encode IO's 'DBC_TEST4' message
/// @returns the message header of this message
static inline dbc_msg_hdr_t dbc_encode_DBC_TEST4(uint8_t frame[8], DBC_TEST4_t *msg)
{
uint32_t raw;
frame[0]=frame[1]=frame[2]=frame[3]=frame[4]=frame[5]=frame[6]=frame[7]=0;
// Stuff a SIG into the DBC 32-bit signal
///< bit(s) starting from BBitStart:0BitSize:32
set_frame_data(frame, MOTOROLA_MSB, 0, 32, msg->DBC_TEST4_real_signed1);
// Stuff a SIG into the DBC 16-bit signal
///< bit(s) starting from BBitStart:32BitSize:16
set_frame_data(frame, MOTOROLA_MSB, 32, 16, msg->DBC_TEST4_real_signed2);
// Stuff a SIG into the DBC 16-bit signal
///< bit(s) starting from BBitStart:48BitSize:16
set_frame_data(frame, MOTOROLA_MSB, 48, 16, msg->DBC_TEST4_real_overflow);
return DBC_TEST4_HDR;
}
/// Encode and send for dbc_encode_DBC_TEST4() message
static inline bool dbc_encode_and_send_DBC_TEST4(DBC_TEST4_t *from)
{
uint8_t bytes[8];
const dbc_msg_hdr_t hdr = dbc_encode_DBC_TEST4(bytes, from);
return dbc_app_send_can_msg(hdr.mid, hdr.dlc, bytes);
}
/// Not generating code for dbc_decode_DBC_TEST1() since 'IO' is not the recipient of any of the signals
/// Not generating code for dbc_decode_DBC_TEST2() since 'IO' is not the recipient of any of the signals
/// Not generating code for dbc_decode_DBC_TEST3() since 'IO' is not the recipient of any of the signals
/// Not generating code for dbc_decode_DRIVER_HEARTBEAT() since 'IO' is not the recipient of any of the signals
/// Not generating code for dbc_decode_MOTOR_CMD() since 'IO' is not the recipient of any of the signals
/// Decode MOTOR's 'MOTOR_STATUS' message
/// @param hdr The header of the message to validate its DLC and MID; this can be NULL to skip this check
static inline bool dbc_decode_MOTOR_STATUS(MOTOR_STATUS_t *msg, const uint8_t frame[8], const dbc_msg_hdr_t *hdr)
{
const bool success = true;
// If msg header is provided, check if the DLC and the MID match
if (NULL != hdr && (hdr->dlc != MOTOR_STATUS_HDR.dlc || hdr->mid != MOTOR_STATUS_HDR.mid)) {
return !success;
}
uint32_t raw;
// Stuff a SIG from the DBC 1-bit signal
///< bit(s) starting from BBitStart:0BitSize:1
get_frame_data(frame, MOTOROLA_MSB, 0, 1, msg->MOTOR_STATUS_wheel_error);
// Stuff a SIG from the DBC 16-bit signal
///< bit(s) starting from BBitStart:8BitSize:16
get_frame_data(frame, MOTOROLA_MSB, 8, 16, msg->MOTOR_STATUS_speed_kph);
msg->mia_info.mia_counter_ms = 0; ///< Reset the MIA counter
return success;
}
/// Decode SENSOR's 'SENSOR_SONARS' message
/// @param hdr The header of the message to validate its DLC and MID; this can be NULL to skip this check
static inline bool dbc_decode_SENSOR_SONARS(SENSOR_SONARS_t *msg, const uint8_t frame[8], const dbc_msg_hdr_t *hdr)
{
const bool success = true;
// If msg header is provided, check if the DLC and the MID match
if (NULL != hdr && (hdr->dlc != SENSOR_SONARS_HDR.dlc || hdr->mid != SENSOR_SONARS_HDR.mid)) {
return !success;
}
uint32_t raw;
// Decode the MUX
uint8_t MUX = 0; // Stuff a SIG from the DBC 4-bit signal
///< bit(s) starting from BBitStart:0BitSize:4
get_frame_data(frame, MOTOROLA_MSB, 0, 4, &MUX);
if (0 == MUX) {
// Non Muxed signals (part of all MUX'd structures)
// Stuff a SIG from the DBC 12-bit signal
///< bit(s) starting from BBitStart:4BitSize:12
get_frame_data(frame, MOTOROLA_MSB, 4, 12, &msg->m0.SENSOR_SONARS_err_count);
// Stuff a SIG from the DBC 12-bit signal
///< bit(s) starting from BBitStart:16BitSize:12
get_frame_data(frame, MOTOROLA_MSB, 16, 12, &msg->m0.SENSOR_SONARS_left);
// Stuff a SIG from the DBC 12-bit signal
///< bit(s) starting from BBitStart:28BitSize:12
get_frame_data(frame, MOTOROLA_MSB, 28, 12, &msg->m0.SENSOR_SONARS_middle);
// Stuff a SIG from the DBC 12-bit signal
///< bit(s) starting from BBitStart:40BitSize:12
get_frame_data(frame, MOTOROLA_MSB, 40, 12, &msg->m0.SENSOR_SONARS_right);
// Stuff a SIG from the DBC 12-bit signal
///< bit(s) starting from BBitStart:52BitSize:12
get_frame_data(frame, MOTOROLA_MSB, 52, 12, &msg->m0.SENSOR_SONARS_rear);
msg->m0.mia_info.mia_counter_ms = 0; ///< Reset the MIA counter
}
else if (1 == MUX) {
// Non Muxed signals (part of all MUX'd structures)
// Stuff a SIG from the DBC 12-bit signal
///< bit(s) starting from BBitStart:4BitSize:12
get_frame_data(frame, MOTOROLA_MSB, 4, 12, &msg->m1.SENSOR_SONARS_err_count);
// Stuff a SIG from the DBC 12-bit signal
///< bit(s) starting from BBitStart:16BitSize:12
get_frame_data(frame, MOTOROLA_MSB, 16, 12, &msg->m1.SENSOR_SONARS_no_filt_left);
// Stuff a SIG from the DBC 12-bit signal
///< bit(s) starting from BBitStart:28BitSize:12
get_frame_data(frame, MOTOROLA_MSB, 28, 12, &msg->m1.SENSOR_SONARS_no_filt_middle);
// Stuff a SIG from the DBC 12-bit signal
///< bit(s) starting from BBitStart:40BitSize:12
get_frame_data(frame, MOTOROLA_MSB, 40, 12, &msg->m1.SENSOR_SONARS_no_filt_right);
// Stuff a SIG from the DBC 12-bit signal
///< bit(s) starting from BBitStart:52BitSize:12
get_frame_data(frame, MOTOROLA_MSB, 52, 12, &msg->m1.SENSOR_SONARS_no_filt_rear);
msg->m1.mia_info.mia_counter_ms = 0; ///< Reset the MIA counter
}
else {
return !success;
}
return success;
}
/// Not generating code for dbc_decode_DBC_TEST4() since 'IO' is not the recipient of any of the signals
/// Handle the MIA for MOTOR's MOTOR_STATUS message
/// @param time_incr_ms The time to increment the MIA counter with
/// @returns true if the MIA just occurred
/// @post If the MIA counter reaches the MIA threshold, MIA struct will be copied to *msg
static inline bool dbc_handle_mia_MOTOR_STATUS(MOTOR_STATUS_t *msg, uint32_t time_incr_ms)
{
bool mia_occurred = false;
const dbc_mia_info_t old_mia = msg->mia_info;
msg->mia_info.is_mia = (msg->mia_info.mia_counter_ms >= MOTOR_STATUS__MIA_MS);
if (!msg->mia_info.is_mia) { // Not MIA yet, so keep incrementing the MIA counter
msg->mia_info.mia_counter_ms += time_incr_ms;
}
else if(!old_mia.is_mia) { // Previously not MIA, but it is MIA now
// Copy MIA struct, then re-write the MIA counter and is_mia that is overwriten
*msg = MOTOR_STATUS__MIA_MSG;
msg->mia_info.mia_counter_ms = MOTOR_STATUS__MIA_MS;
msg->mia_info.is_mia = true;
mia_occurred = true;
}
return mia_occurred;
}
/// Handle the MIA for SENSOR's SENSOR_SONARS for MUX "m0" message
/// @param time_incr_ms The time to increment the MIA counter with
/// @returns true if the MIA just occurred
/// @post If the MIA counter reaches the MIA threshold, MIA struct will be copied to *msg
static inline bool dbc_handle_mia_SENSOR_SONARS_m0(SENSOR_SONARS_m0_t *msg, uint32_t time_incr_ms)
{
bool mia_occurred = false;
const dbc_mia_info_t old_mia = msg->mia_info;
msg->mia_info.is_mia = (msg->mia_info.mia_counter_ms >= SENSOR_SONARS_m0__MIA_MS);
if (!msg->mia_info.is_mia) { // Not MIA yet, so keep incrementing the MIA counter
msg->mia_info.mia_counter_ms += time_incr_ms;
}
else if(!old_mia.is_mia) { // Previously not MIA, but it is MIA now
// Copy MIA struct, then re-write the MIA counter and is_mia that is overwriten
*msg = SENSOR_SONARS_m0__MIA_MSG;
msg->mia_info.mia_counter_ms = SENSOR_SONARS_m0__MIA_MS;
msg->mia_info.is_mia = true;
mia_occurred = true;
}
return mia_occurred;
}
/// Handle the MIA for SENSOR's SENSOR_SONARS for MUX "m1" message
/// @param time_incr_ms The time to increment the MIA counter with
/// @returns true if the MIA just occurred
/// @post If the MIA counter reaches the MIA threshold, MIA struct will be copied to *msg
static inline bool dbc_handle_mia_SENSOR_SONARS_m1(SENSOR_SONARS_m1_t *msg, uint32_t time_incr_ms)
{
bool mia_occurred = false;
const dbc_mia_info_t old_mia = msg->mia_info;
msg->mia_info.is_mia = (msg->mia_info.mia_counter_ms >= SENSOR_SONARS_m1__MIA_MS);
if (!msg->mia_info.is_mia) { // Not MIA yet, so keep incrementing the MIA counter
msg->mia_info.mia_counter_ms += time_incr_ms;
}
else if(!old_mia.is_mia) { // Previously not MIA, but it is MIA now
// Copy MIA struct, then re-write the MIA counter and is_mia that is overwriten
*msg = SENSOR_SONARS_m1__MIA_MSG;
msg->mia_info.mia_counter_ms = SENSOR_SONARS_m1__MIA_MS;
msg->mia_info.is_mia = true;
mia_occurred = true;
}
return mia_occurred;
}
#endif
2019最新四脚猫高级PHP培训课程(完整)
猜你喜欢
转载自blog.csdn.net/Laoyan9/article/details/89763856
今日推荐
周排行