Skip to content

ApexCorse/vera

Repository files navigation

Vera

A lightweight DBC file parser and C code generator for CAN bus message decoding.

Vera is mainly a code generation tool that parses DBC (Database Container) files and generates C source code for decoding CAN (Controller Area Network) bus messages. It simplifies the process of implementing CAN message decoders in embedded systems by automating the conversion of message definitions into efficient C code.

It can also be used as a package for parsing DBC files (although very feature-limited).

Features

  • DBC Parsing: Reads and parses DBC files containing CAN message and signal definitions
  • C Code Generation: Generates header (.h) and source (.c) files with decoding functions
  • Type Safety: Generates strongly-typed structures for messages and signals
  • MQTT Topic Mapping: Supports defining MQTT topics per signal using TP_ instruction
  • Signal Decoding: Handles various signal properties including:
    • Little-endian byte ordering (only little-endian is currently supported)
    • Signed/unsigned values
    • Scaling factors and offsets
    • Min/max validation
    • Units
  • Support for embedded SDKs: ESP-IDF, STM32 HAL, AutoDevKit

Warning

The ESP-IDF integration is not currently available

Installation

Prerequisites

  • Go 1.25.1 or later

Install

# Install from source
git clone https://github.com/ApexCorse/vera.git
cd vera
go install github.com/ApexCorse/vera/cmd/vera

You can also find the standalone binaries here.

Usage

vera [options] <build_path>

Options

  • -f <file>: Path to the DBC file (default: config.dbc)
  • -sdk <sdk>: The SDK to generate specific code for (esp-idf, stm32hal, autodevkit)

Arguments

  • <build_path>: Directory where the generated C files will be created

Example

# Generate C code from a DBC file
vera -f network.dbc ./output

# This creates:
# - output/vera.h (header file with type definitions)
# - output/vera.c (source file with decoding functions)
# SDK integration
vera -f network.dbc -sdk autodevkit ./output

# This creates:
# - output/vera.h (header file with type definitions)
# - output/vera.c (source file with decoding functions)
# - output/vera_autodevkit.h (header file AutoDevKit specific)
# - output/vera_autodevkit.c (source file AutoDevKit specific)

DBC File Format

Vera expects DBC files with the following format:

BO_ <message_id> <message_name>: <dlc> <transmitter>
    SG_ <signal_name> : <start_bit>|<length>@<endianness><sign>(<integer_figures>,<decimal_figures>) (<factor>,<offset>) [<min>|<max>] "<unit>" <receivers>
TP_ <signal_name> <mqtt_topic>

Note

Start Bit, and Length are all expressed in bits, while DLC is expressed in bytes.

Note

Receivers are currently parsed but not used in code generation.

Note

The TP_ instruction is used to associate an MQTT topic with a specific signal (referenced by <signal_name>). It is placed at the same level as BO_ instructions, not indented under them.

Example DBC File

BO_ 123 EngineSpeed: 6 Engine
    SG_ EngineSpeed : 0|32@1+ (0.1,0) [0|8000] "RPM" DriverGateway
    SG_ BatteryTemperature : 32|16@1+(12,4) (1,0) [0|8000] "ºC" DriverGateway
TP_ EngineSpeed vehicle/engine/speed
TP_ BatteryTemperature vehicle/battery/temperature

Generated Code

The generated C code provides:

  • Type definitions for CAN frames, messages, and signals
  • Decoding functions that extract and convert signal values from raw CAN data
  • Error handling for allocation failures and out-of-bounds values

Example Usage of Generated Code

#include "vera.h"

vera_can_rx_frame_t frame = {
    .id = 0x7B,
    .dlc = 6,
    .data = {0x10, 0x20, 0x30, 0x40, 0x50, 0x60}
};

vera_decoding_result_t result;
vera_err_t err = vera_decode_can_frame(&frame, &result);

if (err == vera_err_ok) {
    for (int i = 0; i < result.n_signals; i++) {
        printf("Signal: %s = %.2f %s\n",
               result.decoded_signals[i].name,
               result.decoded_signals[i].value,
               result.decoded_signals[i].unit);
    }
    free(result.decoded_signals);
}

Development

Running Tests

go test ./...

Building from Source

go build ./cmd/vera

Creating a Release

Releases are automatically created when a tag is pushed to the repository:

git tag -a v1.0.0 -m "Release v1.0.0"
git push origin v1.0.0

The GitHub Actions workflow will automatically:

  • Build binaries for Linux (amd64), Windows (amd64), macOS Intel (amd64), and macOS Apple Silicon (arm64)
  • Create a GitHub release with auto-generated release notes
  • Upload all platform binaries as release assets

Project Structure

.
├── README.md
├── cmd/                  # Command-line interface
│   └── vera.go
├── gentest/              # Test files and examples
│   ├── CMakeLists.txt
│   ├── config-test.dbc
│   ├── test.c
│   ├── test.sh
│   └── unity/           # Unity test framework
├── go.mod
├── go.sum
└── internal/
    ├── codegen/         # C code generator
    │   ├── codegen.go
    │   └── templates.go
    └── parser/          # DBC file parser
        ├── errors.go
        ├── parser.go
        ├── parser_test.go
        ├── types.go
        ├── utils.go
        └── validator.go

License

This project is part of the ApexCorse organization.

About

C code generator for CAN DBC files

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •