canbus

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 1 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package canbus provides shared NMEA 2000 / CAN bus types and functions importable by both the server internals and client tools.

Index

Constants

This section is empty.

Variables

View Source
var Manufacturers = map[uint16]string{}/* 140 elements not displayed */

Manufacturers maps NMEA 2000 manufacturer codes to names.

Functions

func BuildCANID

func BuildCANID(h CANHeader) uint32

BuildCANID constructs a 29-bit CAN identifier from a CANHeader. Inverse of ParseCANID: BuildCANID(ParseCANID(x)) == x for valid IDs.

func EncodeName added in v0.4.0

func EncodeName(f NameEncodeFields) uint64

EncodeName encodes the fields into a 64-bit ISO NAME.

func LookupManufacturer

func LookupManufacturer(code uint16) string

LookupManufacturer returns a human-readable manufacturer name for common NMEA 2000 codes.

Types

type CANHeader

type CANHeader struct {
	Priority    uint8
	PGN         uint32
	Source      uint8
	Destination uint8 // 0xFF for broadcast (PDU2)
}

CANHeader holds the parsed fields from a 29-bit CAN ID.

func ParseCANID

func ParseCANID(id uint32) CANHeader

ParseCANID extracts priority, PGN, source address, and destination from a 29-bit CAN identifier per NMEA 2000 / ISO 11783.

CAN ID bit layout (29 bits):

bits 28-26: priority (3 bits)
bit  25:    reserved (always 0 on NMEA 2000)
bit  24:    data page (DP)
bits 23-16: PDU format (PF)
bits 15-8:  PDU specific (PS)
bits 7-0:   source address

PF >= 240 (PDU2, broadcast): PGN = DP<<16 | PF<<8 | PS PF < 240 (PDU1, addressed): PGN = DP<<16 | PF<<8, PS = destination

type NameEncodeFields added in v0.4.0

type NameEncodeFields struct {
	UniqueNumber            uint32
	ManufacturerCode        uint16
	DeviceInstance          uint8
	DeviceFunction          uint8
	DeviceClass             uint8
	SystemInstance          uint8
	IndustryGroup           uint8
	ArbitraryAddressCapable bool
}

EncodeName builds a 64-bit ISO NAME from individual fields. Inverse of DecodeNAME (at the numeric level; manufacturer string is ignored).

Fields map to the same bit layout documented on DecodeNAME:

bits  0-20:  UniqueNumber (21 bits)
bits 21-31:  ManufacturerCode (11 bits)
bits 32-34:  DeviceInstance lower 3 bits
bits 35-39:  DeviceInstance upper 5 bits
bits 40-47:  DeviceFunction (8 bits)
bit  48:     reserved (0)
bits 49-55:  DeviceClass (7 bits)
bits 56-59:  SystemInstance (4 bits)
bits 60-62:  IndustryGroup (3 bits)
bit  63:     ArbitraryAddressCapable

type NameFields

type NameFields struct {
	NAMEHex          string
	Manufacturer     string
	ManufacturerCode uint16
	DeviceClass      uint8
	DeviceFunction   uint8
	DeviceInstance   uint8
	UniqueNumber     uint32
}

NameFields holds the decoded fields from a 64-bit ISO NAME (PGN 60928).

func DecodeNAME

func DecodeNAME(name uint64) NameFields

DecodeNAME parses the 64-bit ISO NAME field from PGN 60928.

NAME field bit layout (64 bits, little-endian):

bits  0-20:  unique number (21 bits)
bits 21-31:  manufacturer code (11 bits)
bits 32-34:  device instance lower (3 bits)
bits 35-39:  device instance upper (5 bits)
bits 40-47:  device function (8 bits)
bit  48:     reserved
bits 49-55:  device class (7 bits)
bits 56-59:  system instance (4 bits)
bits 60-62:  industry group (3 bits)
bit  63:     arbitrary address capable

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL