package module
Version: v0.0.0-...-0bc8d3e Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2021 License: Apache-2.0 Imports: 4 Imported by: 0



Go client to read NMEA 2000 messages from canbus interfaces or usb devices

WORK IN PROGRESS Only public because including private Go library is too much of a hustle for CI

Relies heavily on work done by https://github.com/canboat/canboat developers


Research/check following libraries:

  • CAN libraries
  1. https://github.com/algleason/canlib (7) (socketcan) BSD2
  2. https://github.com/angelodlfrtr/go-can (4) (serial, socketcan) MIT?
    uses https://github.com/brutella/can
  3. https://github.com/brutella/can (133) (socketcan) MIT
  4. https://github.com/go-daq/canbus (16) BSD3 (socketcan) no deps
  5. https://github.com/einride/can-go (socketcan) MIT

NMEA libraries:

  1. https://github.com/canboat/canboat (307) Apache2 (nmea2000)
  2. https://github.com/adrianmo/go-nmea (147) MIT (nmea0183 only)
  3. https://github.com/pilebones/go-nmea (2) GPL3 (nmea0183 only)
  4. https://github.com/BertoldVdb/go-ais (18) MIT (nmea0183 only)




View Source
const FastRawPacketMaxSize = 223

FastRawPacketMaxSize is maximum size of fast packet multiple packets total length TODO: Canboat notes: NMEA 2000 uses the 8 'data' bytes as follows: data[0] is an 'order' that increments, or not (depending a bit on implementation). If the size of the packet <= 7 then the data follows in data[1..7] If the size of the packet > 7 then the next byte data[1] is the size of the payload and data[0] is divided into 5 bits index into the fast packet, and 3 bits 'order that increases. This means that for 'fast packets' the first bucket (sub-packet) contains 6 payload bytes and 7 for remaining. Since the max index is 31, the maximal payload is 6 + 31 * 7 = 223 bytes


This section is empty.


This section is empty.


type CustomPGN

type CustomPGN struct {
	PGN         uint32      `json:"pgn"`
	Destination uint8       `json:"destination"`
	Source      uint8       `json:"source"`
	Fields      FieldValues `json:"fields"`

CustomPGN is generic PGN structure that can contain any arbitrary field values

func ParsePGN

func ParsePGN(pgnConf canboat.PGN, raw RawMessage) (CustomPGN, error)

ParsePGN parses message into CustomPGN

type FieldValue

type FieldValue struct {
	ID    string      `json:"id"`
	Type  string      `json:"type"`
	Value interface{} `json:"value"` // normalize to: string, float64, int64, uint64, []byte, []uint8

FieldValue hold extracted and processed value for PGN field

func ParseField

func ParseField(field canboat.Field, rawData []byte) (FieldValue, error)

ParseField parses field from message data

type FieldValues

type FieldValues []FieldValue

FieldValues is slice of FieldValue

type RawMessage

type RawMessage struct {
	// Time is when message was read from NMEA bus. Filled by the library.
	Time        time.Time
	Priority    uint8
	PGN         uint32 // note: not unique, some messages have same PGN but different fields (messages are used in sequence, see pgn 126208)
	Destination uint8
	Source      uint8
	Timestamp   uint32
	Length      uint8
	Data        []byte

RawMessage is raw message read from device containing NMEA message

Source Files


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL