Skip to content

File CANProtocol.h

FileList > CANProtocol > CANProtocol.h

Go to the source code of this file

Shared CAN bus types, frame IDs, and runtime API for OpenSkyhawk STM32 nodes.More...

  • #include <stdint.h>
  • #include <HIDControls.h>
  • #include <NodeStatus.h>

Namespaces

Type Name
namespace CANProtocol

Public Types

Type Name
typedef void(*)(uint32_t canId, const uint8_t *data, uint8_t len) CanRxCallback
Fired when a CAN frame is received. Register via onReceive().
enum CanStatus
CAN bus health states. Reported to STM32Board via onStatusChange().
typedef void(*)(CanStatus status) CanStatusCallback
Fired when CAN bus status changes. Register via onStatusChange().
typedef void(*)() CanSyncReqCallback
Fired when SYNC_REQ is received. Register via onSyncReq().
enum uint8_t ReadyFlag
ReadyPayload flags bits (#383).

Public Static Attributes

Type Name
constexpr uint32_t CAN_ID_CTRL_BCAST = 0x7E0
constexpr uint32_t CAN_ID_SYNC_REQ = 0x012
Request nodes to re-send their state (see below)
constexpr uint32_t CAN_ID_TEST_SEQ = 0x011
RTT throughput test.
constexpr uint16_t CTRL_ID_DCS_MAX = 0x86FF
DCS-BIOS range end.
constexpr uint16_t CTRL_ID_DCS_MIN = 0x8000
DCS-BIOS range start.
constexpr uint8_t DIAG_ERR = 0x03
CAN error counter frame.
constexpr uint8_t DIAG_EVT = 0x04
Sub-node input event forwarded upstream.
constexpr uint8_t DIAG_HB = 0x02
Sub-node heartbeat frame.
constexpr uint8_t DIAG_MAGIC = 0xAA
Frame sync byte.
constexpr uint8_t DIAG_RTT = 0x01
Round-trip time measurement frame.
constexpr uint8_t SYNC_REQ_LEN_TARGETED = 1

Public Functions

Type Name
struct __attribute__ ((packed))
Primary input/output routing packet. 4 bytes; two are batched for CTRL_BCAST/EVT_n.
constexpr uint32_t canIdEcho (uint8_t n)
TEST_SEQ echo frame ID for node n. Range 0x301-0x33F.
constexpr uint32_t canIdEvt (uint8_t n)
Input event frame ID for node n. Range 0x201-0x23F.
constexpr uint32_t canIdEvtAction (uint8_t n)
Action-input event frame ID for node n. ActionButton: the payload value is a selector, not a magnitude — 0 means TOGGLE , the only argument DCS-BIOS's action interface defines. Any other value is malformed and the bridge drops it. Range 0x701-0x73F.
constexpr uint32_t canIdEvtDir (uint8_t n)
Directional-input event frame ID for node n. RotaryEncoder DIR mode: payload value is a signed ±1 (int16); the bridge formats it INC /DEC for a DCS-BIOS fixed_step control. Range 0x601-0x63F.
constexpr uint32_t canIdEvtRel (uint8_t n)
Relative-input event frame ID for node n. RotaryEncoder REL mode: payload value is a signed ±step (int16); the bridge formats it %+d for a DCS-BIOS variable_step control. Range 0x501-0x53F.
constexpr uint32_t canIdHb (uint8_t n)
Heartbeat frame ID for node n. Range 0x100-0x13F; n=GATEWAY_NODE_ID (0) is PanelBridge .
constexpr uint32_t canIdHealth (uint8_t n)
Node-health/thermal telemetry frame ID for node n. Range 0x140-0x17F; n=0 is PanelBridge . Carries NodeHealthPayload (internal die temp; degraded/faultId once #163 lands).
constexpr uint32_t canIdReady (uint8_t n)
Boot-complete READY frame ID for node n. Range 0x401-0x43F.
constexpr uint32_t canIdTelem (uint8_t n)
Paged node-telemetry frame ID for node n (TelemPayload, #216). Range 0x181-0x1BF. Sits with HB (0x100) and HEALTH (0x140) in the node-status block; PanelBridge forwards it to the host unread as_NODE_TELEM .

Detailed Description

Owns all CAN bus interaction for PanelGroup and PanelBridge nodes. Types and constants (ControlPacket, CanStatus, frame IDs, CAN ID functions) are platform-agnostic. The runtime namespace (filters, lifecycle, send, callbacks, diagnostics) is STM32-only and guarded by ARDUINO_ARCH_STM32. CAN arbitration IDs (CAN_ID_*, canId*()) and payload ControlPacket::controlId values are separate namespaces; equal numeric values do not conflict because they occupy different CAN frame fields.

Dependency: STM32Board::begin() must be called before CANProtocol::start(). CANProtocol owns CAN bus operation; STM32Board owns peripheral hardware init.

Copyright:

GPL-2.0-only — see Firmware/LICENSE

Public Types Documentation

typedef CanRxCallback

Fired when a CAN frame is received. Register via onReceive().

using CanRxCallback =  void(*)(uint32_t canId, const uint8_t* data, uint8_t len);


enum CanStatus

CAN bus health states. Reported to STM32Board via onStatusChange().

enum CanStatus {
    STARTING,
    NORMAL,
    TX_ERROR,
    BUS_OFF
};


typedef CanStatusCallback

Fired when CAN bus status changes. Register via onStatusChange().

using CanStatusCallback =  void(*)(CanStatus status);


typedef CanSyncReqCallback

Fired when SYNC_REQ is received. Register via onSyncReq().

using CanSyncReqCallback =  void(*)();


enum ReadyFlag

ReadyPayload flags bits (#383).

enum ReadyFlag {
    RESYNC = 0x01
};


Public Static Attributes Documentation

variable CAN_ID_CTRL_BCAST

constexpr uint32_t CAN_ID_CTRL_BCAST;

Broadcast ControlPacketPair to all panels: the sim's export stream. The lowest-priority frame on the bus (#389) — every input, heartbeat and update frame wins arbitration against it. An input is one-shot; a sim value comes back by itself (each change on the next DCS-BIOS frame, and autosync re-sends every value every few seconds), so the sim yields, not the cockpit. Was 0x010 (the top).


variable CAN_ID_SYNC_REQ

Request nodes to re-send their state (see below)

constexpr uint32_t CAN_ID_SYNC_REQ;


variable CAN_ID_TEST_SEQ

RTT throughput test.

constexpr uint32_t CAN_ID_TEST_SEQ;


variable CTRL_ID_DCS_MAX

DCS-BIOS range end.

constexpr uint16_t CTRL_ID_DCS_MAX;


variable CTRL_ID_DCS_MIN

DCS-BIOS range start.

constexpr uint16_t CTRL_ID_DCS_MIN;


variable DIAG_ERR

CAN error counter frame.

constexpr uint8_t DIAG_ERR;


variable DIAG_EVT

Sub-node input event forwarded upstream.

constexpr uint8_t DIAG_EVT;


variable DIAG_HB

Sub-node heartbeat frame.

constexpr uint8_t DIAG_HB;


variable DIAG_MAGIC

Frame sync byte.

constexpr uint8_t DIAG_MAGIC;


variable DIAG_RTT

Round-trip time measurement frame.

constexpr uint8_t DIAG_RTT;


variable SYNC_REQ_LEN_TARGETED

constexpr uint8_t SYNC_REQ_LEN_TARGETED;

SYNC_REQ payload (#387): byte 0 = the NODE_ID it is for — only that node answers. An empty SYNC_REQ (DLC 0) is for every node; PanelBridge no longer sends one (it syncs one node at a time), but nodes still honour it.


Public Functions Documentation

function __attribute__

Primary input/output routing packet. 4 bytes; two are batched for CTRL_BCAST/EVT_n.

struct __attribute__ (
    (packed)
) 

8-byte payload carried by READY_n — the node's boot announcement (#295).

8-byte payload carried by TELEM_n frames — paged node telemetry (#216).

8-byte payload carried by HEALTH_n frames — per-node health telemetry.

8-byte payload carried by HB_n heartbeat frames.

Two ControlPackets packed into one 8-byte input/output CAN frame.

Used by CTRL_BCAST and EVT_n only. Slot B controlId == 0x0000 signals an empty/padding slot.

Sent every 500 ms by every node through serviceNodeStatus() (#340). PanelBridge reads HB_1–HB_63 to track node health and populate diagnostics; its own HB_0 is the master liveness beacon every other node watches (#93).

Sent every 1000 ms by every STM32 node. This is the shared node-health wire contract; separate features populate their own fields, all within the fixed 8 bytes: * Temperature (#213): dieTempC, flags bit0 — read from the MCU's built-in internal temperature sensor (ADC ch16); no external parts, no PCB change. * Degraded state (#163): flags bit1 + faultId — a node that is alive but has a faulted FaultSource reporting a NodeFaultCode (NodeStatus.h). aggregateFaults() picks the primary faultId, makeNodeHealthPayload derives DEGRADED. faultMask stays 0 (reserved, see below). * Board kind (#344): nodeKind — a NodeKind (NodeStatus.h) set by the node's firmware role, never derived from NODE_ID. Pre-#344 firmware sends 0 here = NodeKind::UNKNOWN. PanelBridge caches HEALTH_1–HEALTH_63 per node and forwards them in _NODE_STATUS, together with its own HEALTH_0 as the node-0 row.

Note:

The STM32F103 internal sensor is UNCALIBRATED (no factory trim): ~±few °C absolute, measures DIE temperature (not ambient) with a self-heat offset. Use for relative trend and per-node overheat flagging, not precise ambient measurement.

Note:

Rail voltage/current is intentionally NOT here — that is the PDU's dedicated power telemetry (TELEM_n / TelemPayload, #216; INA180A2 current sense on #202), not generic per-node health.

Byte 0 is a TelemPage (NodeStatus.h) naming the layout of the other seven bytes; page ids are global and append-only, so a page means the same thing whichever node sends it. Multi-byte fields inside a page are little-endian. PanelBridge forwards every TELEM_n frame to the host unread (_NODE_TELEM), so a new page type needs no bridge change — the client owns the decode.

First user: the PDU monitoring node — pages PDU_RAIL_12V / PDU_RAIL_5V / PDU_STATUS. Generic node health (die temp, fault id) stays in HEALTH_n and is never repeated here.

Sent once per boot, after the boot EVT burst, so every reflash, reset or power cycle announces the firmware the node now runs. PanelBridge caches the version per node and reports it in _NODE_STATUS (v4). Firmware older than this payload sends READY_n empty (DLC 0): the bridge then reports the version as not reported (0.0.0).

Sent again, flagged ReadyFlag::RESYNC, in answer to every SYNC_REQ after that (#383): a bridge that booted after the node missed its boot READY and would otherwise never learn its version.


function canIdEcho

TEST_SEQ echo frame ID for node n. Range 0x301-0x33F.

constexpr uint32_t canIdEcho (
    uint8_t n
) 


function canIdEvt

Input event frame ID for node n. Range 0x201-0x23F.

constexpr uint32_t canIdEvt (
    uint8_t n
) 


function canIdEvtAction

Action-input event frame ID for node n. ActionButton: the payload value is a selector, not a magnitude — 0 means TOGGLE , the only argument DCS-BIOS's action interface defines. Any other value is malformed and the bridge drops it. Range 0x701-0x73F.

constexpr uint32_t canIdEvtAction (
    uint8_t n
) 

This frame exists because an action is a keyword, not a number: the ABS value space is already spoken for as literal set_state values, so TOGGLE has no integer to ride on — the same reason DIR exists for INC/DEC.


function canIdEvtDir

Directional-input event frame ID for node n. RotaryEncoder DIR mode: payload value is a signed ±1 (int16); the bridge formats it INC /DEC for a DCS-BIOS fixed_step control. Range 0x601-0x63F.

constexpr uint32_t canIdEvtDir (
    uint8_t n
) 


function canIdEvtRel

Relative-input event frame ID for node n. RotaryEncoder REL mode: payload value is a signed ±step (int16); the bridge formats it %+d for a DCS-BIOS variable_step control. Range 0x501-0x53F.

constexpr uint32_t canIdEvtRel (
    uint8_t n
) 


function canIdHb

Heartbeat frame ID for node n. Range 0x100-0x13F; n=GATEWAY_NODE_ID (0) is PanelBridge .

constexpr uint32_t canIdHb (
    uint8_t n
) 


function canIdHealth

Node-health/thermal telemetry frame ID for node n. Range 0x140-0x17F; n=0 is PanelBridge . Carries NodeHealthPayload (internal die temp; degraded/faultId once #163 lands).

constexpr uint32_t canIdHealth (
    uint8_t n
) 


function canIdReady

Boot-complete READY frame ID for node n. Range 0x401-0x43F.

constexpr uint32_t canIdReady (
    uint8_t n
) 


function canIdTelem

Paged node-telemetry frame ID for node n (TelemPayload, #216). Range 0x181-0x1BF. Sits with HB (0x100) and HEALTH (0x140) in the node-status block; PanelBridge forwards it to the host unread as_NODE_TELEM .

constexpr uint32_t canIdTelem (
    uint8_t n
) 



The documentation for this class was generated from the following file Firmware/Libraries/CANProtocol/CANProtocol.h