# openxc/vi-firmware architecture

> Architecture diagram of the GitHub repository openxc/vi-firmware, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openxc/vi-firmware
- Repository: https://github.com/openxc/vi-firmware

## Overview

#### 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: [`src/vi_firmware.cpp`](https://github.com/openxc/vi-firmware/blob/master/src/vi_firmware.cpp) (Firmware lifecycle), [`src/payload/payload.cpp`](https://github.com/openxc/vi-firmware/blob/master/src/payload/payload.cpp) (Payload selection), [`src/pipeline.cpp`](https://github.com/openxc/vi-firmware/blob/master/src/pipeline.cpp) (Processing pipeline), [`src/can/canread.cpp`](https://github.com/openxc/vi-firmware/blob/master/src/can/canread.cpp) (CAN I/O)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_build["Build &amp; deployment"]
  node_make["Firmware build<br/>Make build"]
  node_flash["Flashing tools<br/>deployment scripts"]
end

subgraph group_runtime["Firmware runtime"]
  node_main["Startup entry<br/>C++ entrypoint<br/>[main.cpp]"]
  node_firmware["Firmware lifecycle<br/>runtime orchestration<br/>[vi_firmware.cpp]"]
  node_config["Runtime configuration<br/>signal configuration<br/>[config.cpp]"]
  node_pipeline["Processing pipeline<br/>flow coordinator<br/>[pipeline.cpp]"]
end

subgraph group_vehicle["Vehicle data &amp; control"]
  node_can["CAN I/O<br/>CAN abstraction<br/>[canread.cpp]"]
  node_signals["Signal definitions<br/>frame decoder"]
  node_emulator["Data emulator<br/>development input<br/>[data_emulator.cpp]"]
  node_commands["Command dispatcher<br/>control plane<br/>[commands.cpp]"]
  node_diagnostics["Diagnostics &amp; OBD-II<br/>vehicle diagnostics<br/>[diagnostics.cpp]"]
  node_uds["UDS-C library<br/>diagnostic dependency"]
end

subgraph group_io["Payload &amp; interfaces"]
  node_payload["Payload selection<br/>serialization boundary<br/>[payload.cpp]"]
  node_json["JSON serializer<br/>payload format<br/>[json.cpp]"]
  node_protobuf["Protobuf serializer<br/>payload format<br/>[protobuf.cpp]"]
  node_interfaces["Interface abstraction<br/>transport boundary<br/>[interface.cpp]"]
  node_transports["USB, UART &amp; network<br/>transport implementations<br/>[usb.cpp]"]
end

subgraph group_platform["Platform targets"]
  node_platform["Platform contract<br/>hardware abstraction<br/>[platform.cpp]"]
  node_lpc17xx["LPC17xx target<br/>ARM board implementation<br/>[platform.cpp]"]
  node_pic32["PIC32 target<br/>chipKIT/C5 implementation<br/>[platform.cpp]"]
end

node_make -->|"builds"| node_firmware
node_flash -->|"deploys build"| node_make
node_main -->|"starts"| node_firmware
node_firmware -->|"loads"| node_config
node_firmware -->|"initializes"| node_pipeline
node_firmware -->|"uses"| node_platform
node_platform -->|"implemented by"| node_lpc17xx
node_platform -->|"implemented by"| node_pic32
node_lpc17xx -->|"provides CAN driver"| node_can
node_pic32 -->|"provides CAN driver"| node_can
node_can -->|"frames decoded by"| node_signals
node_config -->|"configures"| node_signals
node_signals -->|"normalized events"| node_pipeline
node_emulator -.->|"development events"| node_pipeline
node_pipeline -->|"serializes events"| node_payload
node_payload -->|"format option"| node_json
node_payload -->|"format option"| node_protobuf
node_payload -->|"sends encoded messages"| node_interfaces
node_interfaces -->|"implemented by"| node_transports
node_interfaces -->|"receives commands"| node_commands
node_commands -->|"requests CAN writes"| node_can
node_commands -->|"dispatches requests"| node_diagnostics
node_diagnostics -->|"uses"| node_uds

click node_make "https://github.com/openxc/vi-firmware/blob/master/src/Makefile"
click node_flash "https://github.com/openxc/vi-firmware/blob/master/script/bootloader-flash.sh"
click node_main "https://github.com/openxc/vi-firmware/blob/master/src/main.cpp"
click node_firmware "https://github.com/openxc/vi-firmware/blob/master/src/vi_firmware.cpp"
click node_config "https://github.com/openxc/vi-firmware/blob/master/src/config.cpp"
click node_pipeline "https://github.com/openxc/vi-firmware/blob/master/src/pipeline.cpp"
click node_can "https://github.com/openxc/vi-firmware/blob/master/src/can/canread.cpp"
click node_signals "https://github.com/openxc/vi-firmware/blob/master/src/can/default_signals.cpp"
click node_emulator "https://github.com/openxc/vi-firmware/blob/master/src/data_emulator.cpp"
click node_commands "https://github.com/openxc/vi-firmware/blob/master/src/commands/commands.cpp"
click node_diagnostics "https://github.com/openxc/vi-firmware/blob/master/src/diagnostics.cpp"
click node_uds "https://github.com/openxc/vi-firmware/tree/master/src/libs/uds-c"
click node_payload "https://github.com/openxc/vi-firmware/blob/master/src/payload/payload.cpp"
click node_json "https://github.com/openxc/vi-firmware/blob/master/src/payload/json.cpp"
click node_protobuf "https://github.com/openxc/vi-firmware/blob/master/src/payload/protobuf.cpp"
click node_interfaces "https://github.com/openxc/vi-firmware/blob/master/src/interface/interface.cpp"
click node_transports "https://github.com/openxc/vi-firmware/blob/master/src/interface/usb.cpp"
click node_platform "https://github.com/openxc/vi-firmware/blob/master/src/platform/platform.cpp"
click node_lpc17xx "https://github.com/openxc/vi-firmware/blob/master/src/platform/lpc17xx/platform.cpp"
click node_pic32 "https://github.com/openxc/vi-firmware/blob/master/src/platform/pic32/platform.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_make,node_flash toneBlue
class node_main,node_firmware,node_config,node_pipeline toneAmber
class node_can,node_signals,node_emulator,node_commands,node_diagnostics,node_uds toneMint
class node_payload,node_json,node_protobuf,node_interfaces,node_transports toneRose
class node_platform,node_lpc17xx,node_pic32 toneIndigo
```

## Components

### Build & deployment

- [Firmware build](https://github.com/openxc/vi-firmware/blob/master/src/Makefile): Make build · Selects target toolchains and linker layouts. · `src/Makefile`
- [Flashing tools](https://github.com/openxc/vi-firmware/blob/master/script/bootloader-flash.sh): deployment scripts · `script/bootloader-flash.sh`

### Firmware runtime

- [Startup entry](https://github.com/openxc/vi-firmware/blob/master/src/main.cpp): C++ entrypoint · `src/main.cpp`
- [Firmware lifecycle](https://github.com/openxc/vi-firmware/blob/master/src/vi_firmware.cpp): runtime orchestration · `src/vi_firmware.cpp`
- [Runtime configuration](https://github.com/openxc/vi-firmware/blob/master/src/config.cpp): signal configuration · `src/config.cpp`
- [Processing pipeline](https://github.com/openxc/vi-firmware/blob/master/src/pipeline.cpp): flow coordinator · Coordinates normalized message processing. · `src/pipeline.cpp`

### Vehicle data & control

- [CAN I/O](https://github.com/openxc/vi-firmware/blob/master/src/can/canread.cpp): CAN abstraction · Receives vehicle frames and sends requested writes. · `src/can/canread.cpp`
- [Signal definitions](https://github.com/openxc/vi-firmware/blob/master/src/can/default_signals.cpp): frame decoder · Maps vehicle frames into generic OpenXC signals. · `src/can/default_signals.cpp`
- [Data emulator](https://github.com/openxc/vi-firmware/blob/master/src/data_emulator.cpp): development input · `src/data_emulator.cpp`
- [Command dispatcher](https://github.com/openxc/vi-firmware/blob/master/src/commands/commands.cpp): control plane · `src/commands/commands.cpp`
- [Diagnostics & OBD-II](https://github.com/openxc/vi-firmware/blob/master/src/diagnostics.cpp): vehicle diagnostics · `src/diagnostics.cpp`
- [UDS-C library](https://github.com/openxc/vi-firmware/tree/master/src/libs/uds-c): diagnostic dependency · `src/libs/uds-c`

### Payload & interfaces

- [Payload selection](https://github.com/openxc/vi-firmware/blob/master/src/payload/payload.cpp): serialization boundary · `src/payload/payload.cpp`
- [JSON serializer](https://github.com/openxc/vi-firmware/blob/master/src/payload/json.cpp): payload format · `src/payload/json.cpp`
- [Protobuf serializer](https://github.com/openxc/vi-firmware/blob/master/src/payload/protobuf.cpp): payload format · `src/payload/protobuf.cpp`
- [Interface abstraction](https://github.com/openxc/vi-firmware/blob/master/src/interface/interface.cpp): transport boundary · `src/interface/interface.cpp`
- [USB, UART & network](https://github.com/openxc/vi-firmware/blob/master/src/interface/usb.cpp): transport implementations · `src/interface/usb.cpp`

### Platform targets

- [Platform contract](https://github.com/openxc/vi-firmware/blob/master/src/platform/platform.cpp): hardware abstraction · `src/platform/platform.cpp`
- [LPC17xx target](https://github.com/openxc/vi-firmware/blob/master/src/platform/lpc17xx/platform.cpp): ARM board implementation · `src/platform/lpc17xx/platform.cpp`
- [PIC32 target](https://github.com/openxc/vi-firmware/blob/master/src/platform/pic32/platform.cpp): chipKIT/C5 implementation · Includes cellular modem integration. · `src/platform/pic32/platform.cpp`

## Connections

- 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
