Exploring DBC Autogenerated API

 

DBC Encode API
void can_transmitter_option1(void) {
  dbc_DRIVER_HEARTBEAT_s heartbeat={};
  dbc_SENSOR_SONARS_s sensor_values={};

  dbc_message_header_t header;
  can__msg_t can_msg = {};

  header = dbc_encode_SENSOR_SONARS(can_msg.data.bytes, &sensor_values);
  can_msg.msg_id = header.message_id;
  can_msg.frame_fields.data_len = header.message_dlc;
  can__tx(can1, &can_msg, 0);

  header = dbc_encode_DRIVER_HEARTBEAT(can_msg.data.bytes, &heartbeat);
  can_msg.msg_id = header.message_id;
  can_msg.frame_fields.data_len = header.message_dlc;
  can__tx(can1, &can_msg, 0);
}

 

DBC Encode and Send API
void can_transmitter_option2(void) {
  dbc_DRIVER_HEARTBEAT_s heartbeat={};
  dbc_SENSOR_SONARS_s sensor_values={};

  void *unused = NULL;
  dbc_encode_and_send_DRIVER_HEARTBEAT(unused, &sensor_values);
  dbc_encode_and_send_DRIVER_HEARTBEAT(unused, &heartbeat);
}

bool dbc_send_can_message(void * argument_from_dbc_encode_and_send, uint32_t message_id, const uint8_t bytes[8], uint8_t dlc) {
  can__msg_t can_msg = {};
  
  can_msg.msg_id = message_id;
  can_msg.frame_fields.data_len = dlc;
  memcpy(can_msg.data.bytes, bytes, sizeof(can_msg.data.bytes));
 
  can__tx(can1, &can_msg, 0);
}
Back to top