Skip to content

Instantly share code, notes, and snippets.

@makcuk
Created July 16, 2026 18:14
Show Gist options
  • Select an option

  • Save makcuk/2f8d971b352069ba016c97b3b4b70117 to your computer and use it in GitHub Desktop.

Select an option

Save makcuk/2f8d971b352069ba016c97b3b4b70117 to your computer and use it in GitHub Desktop.
static void send_circuit_status(uint16_t circuit_id, float voltage, float current, bool online)
{
if (!online) {
return; /* Don't send status if sensor is offline */
}
fdcan_frame_t frame;
/* CAN ID: Priority = 6, Message ID = 1091 (0x443), Source Node ID = global_cfg.node_id */
frame.id = (6U << 26) | (1091U << 8) | global_cfg.node_id;
frame.is_extended = true;
frame.dlc = 8; /* 7 payload bytes + 1 tail byte */
uint16_t voltage_f16 = float32_to_float16(voltage);
uint16_t current_f16 = float32_to_float16(current);
uint8_t error_flags = 0;
frame.data[0] = circuit_id & 0xFF;
frame.data[1] = (circuit_id >> 8) & 0xFF;
frame.data[2] = voltage_f16 & 0xFF;
frame.data[3] = (voltage_f16 >> 8) & 0xFF;
frame.data[4] = current_f16 & 0xFF;
frame.data[5] = (current_f16 >> 8) & 0xFF;
frame.data[6] = error_flags;
/* Tail Byte: Start=1, End=1, Toggle=0, Transfer ID */
static uint8_t circuit_transfer_ids[4] = {0, 0, 0, 0};
uint8_t tf_id = 0;
if (circuit_id <= 3) {
tf_id = circuit_transfer_ids[circuit_id];
circuit_transfer_ids[circuit_id] = (circuit_transfer_ids[circuit_id] + 1) & 0x1F;
}
frame.data[7] = 0xC0 | tf_id;
(void)fdcan_tx_timeout(&frame, 5);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment