How openxc/vi-firmware works
Purpose and execution model
OpenXC VI Firmware is C/C++ embedded firmware for a microcontroller attached to one or more vehicle CAN buses. It translates raw or filtered vehicle traffic into generic OpenXC messages, primarily exposed over USB, with optional BLE, network, cellular, SD, and diagnostic capabilities. Firmware startup and application orchestration are centered in src/main.cpp, src/vi_firmware.cpp, and src/Makefile.
Firmware orchestration and pipeline
The core runtime initializes platform services, configuration, interfaces, CAN handling, and a processing pipeline. src/pipeline.cpp is the central flow coordinator; src/vi_firmware.cpp hosts firmware-level lifecycle behavior; src/config.cpp loads/represents runtime signal and feature configuration. This separates generic message processing from board-specific implementations.
CAN ingestion and signal translation
CAN receive/transmit and utility abstractions are in src/can/canread.cpp, src/can/canwrite.cpp, and src/can/canutil.cpp. Incoming frames are decoded against configured/default signal definitions (src/can/default_signals.cpp, src/signals.h), allowing unit conversion, factoring, and mapping from vehicle-specific frames to generic OpenXC signals. A data emulator path in src/data_emulator.cpp and src/emulator_signals.cpp supports non-vehicle development.
Payload serialization and external interfaces
Normalized vehicle events cross a payload boundary before transport. src/payload/payload.cpp selects the representation, with JSON and Protocol Buffers implementations in src/payload/json.cpp and src/payload/protobuf.cpp. Transport-facing interfaces are abstracted by src/interface/interface.cpp, then implemented for USB, UART, BLE, filesystem, and network in src/interface/usb.cpp, src/interface/uart.cpp, and src/interface/network.cpp. The OpenXC message format is supplied as src/libs/openxc-message-format.
Command and diagnostics control plane
Inbound interface commands are dispatched through src/commands/commands.cpp. Commands control CAN writes, payload format, passthrough mode, device identity/version, modem/RTC configuration, and diagnostics; representative handlers are src/commands/can_message_write_command.cpp, src/commands/passthrough_command.cpp, and src/commands/diagnostic_request_command.cpp. Vehicle diagnostic and OBD-II behavior resides in src/diagnostics.cpp and src/obd2.cpp, backed by the bundled src/libs/uds-c dependency.
Platform boundary and hardware targets
Generic firmware depends on platform interfaces in src/platform/platform.h and src/platform/platform.cpp. Board-specific implementations split into LPC17xx ARM (src/platform/lpc17xx/platform.cpp, src/platform/lpc17xx/canread.cpp) and PIC32/chipKIT/C5 (src/platform/pic32/platform.cpp, src/platform/pic32/canread.cpp, src/platform/pic32/telit_he910.cpp). These layers own MCU startup, CAN drivers, GPIO, timers, power, USB/UART/network, storage, BLE, and cellular modem integration.
Build, flashing, and operational infrastructure
The source Makefile and per-platform make fragments select target toolchains and linker layouts: src/Makefile, src/platform/lpc17xx/lpc17xx.mk, and src/platform/pic32/pic32.mk. Hardware flashing/debugging is configured through OpenOCD/avrdude assets in conf/openocd/ and scripts such as script/bootloader-flash.sh. The project incorporates vendor SDKs and embedded libraries under src/libs/, including USB, BLE, JSON, HTTP parsing, queues, and MCU board support packages.
Main entry points: vi_firmware.cpp Firmware lifecycle · payload.cpp Payload selection · pipeline.cpp Processing pipeline · canread.cpp CAN I/O
Components 20
Build & deployment
- Firmware build · Selects target toolchains and linker layouts.
src/Makefile - Flashing tools
script/bootloader-flash.sh
Firmware runtime
- Startup entry
src/main.cpp - Firmware lifecycle
src/vi_firmware.cpp - Runtime configuration
src/config.cpp - Processing pipeline · Coordinates normalized message processing.
src/pipeline.cpp
Vehicle data & control
- CAN I/O · Receives vehicle frames and sends requested writes.
src/can/canread.cpp - Signal definitions · Maps vehicle frames into generic OpenXC signals.
src/can/default_signals.cpp - Data emulator
src/data_emulator.cpp - Command dispatcher
src/commands/commands.cpp - Diagnostics & OBD-II
src/diagnostics.cpp - UDS-C library
src/libs/uds-c
Payload & interfaces
- Payload selection
src/payload/payload.cpp - JSON serializer
src/payload/json.cpp - Protobuf serializer
src/payload/protobuf.cpp - Interface abstraction
src/interface/interface.cpp - USB, UART & network
src/interface/usb.cpp
Platform targets
- Platform contract
src/platform/platform.cpp - LPC17xx target
src/platform/lpc17xx/platform.cpp - PIC32 target · Includes cellular modem integration.
src/platform/pic32/platform.cpp
Connections 23
- Firmware build → Firmware lifecycle: builds
- Flashing tools → Firmware build: deploys build
- Startup entry → Firmware lifecycle: starts
- Firmware lifecycle → Runtime configuration: loads
- Firmware lifecycle → Processing pipeline: initializes
- Firmware lifecycle → Platform contract: uses
- Platform contract → LPC17xx target: implemented by
- Platform contract → PIC32 target: implemented by
- LPC17xx target → CAN I/O: provides CAN driver
- PIC32 target → CAN I/O: provides CAN driver
- CAN I/O → Signal definitions: frames decoded by
- Runtime configuration → Signal definitions: configures
- Signal definitions → Processing pipeline: normalized events
- Data emulator → Processing pipeline: development events
- Processing pipeline → Payload selection: serializes events
- Payload selection → JSON serializer: format option
- Payload selection → Protobuf serializer: format option
- Payload selection → Interface abstraction: sends encoded messages
- Interface abstraction → USB, UART & network: implemented by
- Interface abstraction → Command dispatcher: receives commands
- Command dispatcher → CAN I/O: requests CAN writes
- Command dispatcher → Diagnostics & OBD-II: dispatches requests
- Diagnostics & OBD-II → UDS-C library: uses