Help us shape the future of Go! Take the 2026 Go Developer Survey

canopen

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 10 Imported by: 0

README

go-canopen - CANopen (CiA 301) for Go

Go Version Go Reference CI Status Code Coverage

A pure Go implementation of CANopen (CiA 301 application layer and communication profile): the object dictionary, SDO client and server with block transfer, NMT master and slave, heartbeat and node guarding, PDOs and multiplexed PDOs, SYNC (with the synchronous window), EMCY and TIME, LSS (CiA 305), CANopen FD (CiA 1301: USDO, 64-byte PDOs, FD emergencies), store and restore of parameters, a complete device (node) built from an object dictionary, a network manager (master) with the CiA 302 network boot-up, configuration manager and program download, EDS/DCF (CiA 306) files, a Go code generator, the CiA 402 drive profile and a frame dissector. No cgo.

It is layered on go-canbus v0.7.0: every service runs on a canbus.Bus, so the same code runs on Linux SocketCAN, slcan USB adapters (any OS) and go-canbus's in-process virtual bus, which the tests and examples use.

Package What it does
canopen Node-IDs, COB-IDs and the predefined connection set, CANopen data types and their encoding, SDO abort codes, NMT states and commands, the Bus interface, sentinel errors
od The object dictionary: objects, access rights, limits, defaults (node-ID relative), read/write hooks and watchers, od.Standard for the CiA 301 communication objects
sdo SDO client and server: expedited, segmented and block transfer (CRC, block size, protocol switch), timeouts, retries
nmt NMT commands, the NMT slave state machine with both resets, heartbeat producer and consumer, node guarding and life guarding
pdo Bit-exact mapping, TPDO and RPDO services (all transmission types, inhibit time, event timer, RTR, deadline monitoring), the CiA 301 reconfiguration rules, remote configuration, decoding and sending
sync (package syncobj), emcy, timestamp SYNC producer and consumer (counter), emergency producer (error register, error history, inhibit time) and consumer, TIME producer and consumer with TIME_OF_DAY
mpdo Multiplexed PDOs: DAM and SAM producer and consumer, object scanner and dispatcher lists (0x1FA0..0x1FFF)
lss Layer setting services (CiA 305): LSS master (switch, configure node-ID and bit timing, store, inquire, identify, Fastscan, AssignAll) and slave
usdo The universal SDO of CANopen FD (CiA 1301): client (unicast, group, broadcast, several sessions) and server; expedited, segmented and bulk transfers
store, cdcf, program Parameter persistence behind 0x1010/0x1011 (memory, file); the concise DCF of CiA 302-3; the program download objects of CiA 302-3 (device side)
node A complete device: chooses its services from the dictionary (PDOs, MPDOs, LSS, CANopen FD with USDO), gates them by NMT state, raises the CiA 301 emergencies on its own, stores its parameters, serves program download
master A network manager: NMT, heartbeat supervision, EMCY, SDO (or, in CANopen FD, USDO) access to every node, scan, configuration from entries, a DCF or a concise DCF, boot procedure, CiA 302 manager (network boot-up with an optional LSS step, 0x1F80..0x1F89, program download), LSS master, MPDO list configuration, remote PDOs, SYNC/TIME, CiA 402 drive control, one ordered event stream
eds EDS and DCF (CiA 306-1): parse, validate, write (round trip), to and from an object dictionary
codegen Typed Go code from an EDS (deterministic, golden-tested)
cia402 CiA 402 drive profile: state machine, modes of operation, a simulated drive (device side) and a controller (master side)
dissect Decoding of CAN frames as CANopen messages (NMT, SYNC, TIME, EMCY including the 20-byte CANopen FD emergency, PDO, SDO with transfer tracking, USDO, heartbeat, node guarding, LSS), checked against Wireshark's dissector for classical CAN

CiA 301 services

Service CiA 301 Status Where
Object dictionary, data types 7.1, 7.4 Implemented: all basic types (BOOLEAN to UNSIGNED64, REAL32/64, strings, DOMAIN, TIME_OF_DAY, TIME_DIFFERENCE), access rights, limits, $NODEID defaults canopen, od
SDO (expedited, segmented, block) 7.2.4 Implemented, client and server, one server channel (0x1200) per node sdo
PDO 7.2.2 Implemented: synchronous (cyclic, acyclic), event-driven, RTR, inhibit time, event timer, SYNC start value, RPDO deadline monitoring; classical CAN (64 bits) and CANopen FD (512 bits) pdo
SYNC 7.2.5 Implemented, producer and consumer with counter; the synchronous window (0x1007) is enforced for synchronous PDOs in a node (late TPDOs discarded, RPDOs received after the window discarded) sync, pdo, node
TIME 7.2.6 Implemented, producer and consumer timestamp
EMCY 7.2.7 Implemented, producer (0x1001, 0x1003, 0x1014, 0x1015) and consumer emcy
NMT module control 7.2.8 Implemented, master and slave (both resets, pending node-ID) nmt
Heartbeat 7.2.8 Implemented, producer (0x1017) and consumer (0x1016) nmt
Node guarding, life guarding 7.2.8 Implemented, master and responder (0x100C, 0x100D) nmt
Error behaviour (0x1029) 7.5 Implemented in node (sub-index 1) node
Store/restore parameters (0x1010, 0x1011) 7.5 Implemented: groups all, communication, application, manufacturer; memory or file store; verify configuration 0x1020 store, node
Multiplexed PDO (MPDO, SAM/DAM) 7.2.3 Implemented: DAM and SAM producer and consumer, object scanner (0x1FA0..) and dispatcher (0x1FD0..) lists, EMCY 0x8230; created by node for every PDO configured as an MPDO; classical 8-byte frames mpdo, node, master
LSS (CiA 305) — Implemented: master (switch state global/selective, configure node-ID and bit timing, activate bit timing, store, inquire identity and node-ID, identify (non-)configured slaves, Fastscan, AssignAll) and slave; node.WithLSS starts a device unconfigured (node-ID 0xFF) and persists the node-ID; LSS step in the CiA 302 boot-up (master.WithLSSBoot) lss, node, master
CANopen FD (CiA 1301) — Implemented from public sources: USDO client and server (expedited, segmented, bulk; unicast, group and broadcast), PDOs up to 64 bytes, 20-byte FD emergency, SYNC/NMT/heartbeat in CAN FD frames, node.WithFD and master.WithFD; segmented USDO layouts inferred, remote (routed) USDO not supported usdo, pdo, emcy, sync, nmt, node, master
CiA 302 network management — Implemented: NMT master objects 0x1F80..0x1F89 (start-up, slave assignment, NMT and guarding requests, expected identification, boot time), the network boot-up and boot slave process of CiA 302-2 with error status letters A..O, configuration manager (concise DCF 0x1F22, 0x1F26/0x1F27 configuration date and time, restore 0x1F8A) and program download (CiA 302-3, 0x1F50..0x1F58); not implemented: flying master and redundancy, SDO manager (CiA 302-5), DCF storage 0x1F20, 0x1F52..0x1F54 master, cdcf, program
CiA 306 EDS/DCF — Implemented (modular-device sections kept, not interpreted) eds
CiA 402 drives — Implemented: state machine, PP, PV, PT, HM, CSP, CSV, CST (simulated drive and controller) cia402

Details and every limitation: LIMITATIONS.md.

Install

go get github.com/otfabric/go-canopen

Go 1.23 or later. The one dependency is go-canbus (pure Go).

Quick start

A device and a network manager on two ports of a virtual bus (the package example node.Example, run by go test):

vb := virtual.New(virtual.Config{Name: "quickstart"})
p1, _ := vb.Open()
p2, _ := vb.Open()
deviceBus, _ := canbus.NewBus(p1)
masterBus, _ := canbus.NewBus(p2)

// The device: the CiA 301 communication objects and a node-ID.
d, _ := od.Standard(od.Config{NodeID: 5, DeviceType: 0x000F0191, VendorID: 0xF7A, DeviceName: "quickstart", HeartbeatMs: 100})
dev, _ := node.New(deviceBus, d)

// The network manager.
m, _ := master.New(masterBus)
_ = m.Start()
defer m.Close()

since := time.Now()
_ = dev.Start() // boot-up message, Pre-operational
defer dev.Close()
_ = m.WaitBootUp(ctx, 5, since)

c, _ := m.SDO(5)
devType, _ := c.ReadUint(ctx, od.IndexDeviceType, 0)
name, _ := c.ReadString(ctx, od.IndexDeviceName, 0)
fmt.Printf("node 5: device type 0x%08X, %q\n", devType, name)

_ = m.StartNode(ctx, 5)
_ = m.WaitState(ctx, 5, canopen.StateOperational)

On a real network, open the bus with go-canbus instead (socketcan.Open("can0") on Linux, or an slcan adapter); the CANopen code does not change.

More in examples/: a node and a master exchanging PDOs, SDO block transfer, a CiA 402 drive, a device built from an EDS and configured from a DCF, LSS node-ID assignment, a CANopen FD network, the CiA 302 network boot-up, and a node on SocketCAN.

Documentation

API.md · ARCHITECTURE.md · ERRORS.md · OBSERVABILITY.md · INTEROPERABILITY.md · TESTING.md · LIMITATIONS.md · ROADMAP.md · SECURITY.md · CHANGELOG.md · RELEASE.md · CONTRIBUTING.md · PROGRESS.md

Related: go-canbus (the CAN layer), canopen-interop (independent CANopen stacks in containers for interoperability tests).

Standards

The CiA specifications (CiA 301, 302, 305, 306, 402, 1301) are documents of CAN in Automation, available to its members. This library is implemented from public material (public descriptions of the protocol, the behaviour of open-source stacks such as CANopenNode, Lely CANopen and python canopen, and Wireshark's CANopen dissector) and is tested against independent implementations: Wireshark's dissector, and CANopenNode, Lely CANopen and python canopen through the canopen-interop containers in both directions (INTEROPERABILITY.md has the matrix and the known differences). It makes no claim of CiA conformance and has not been certified.

License

MIT, see LICENSE.

Documentation

Overview

Package canopen is the shared core of go-canopen, a CANopen (CiA 301) implementation on top of go-canbus: node identifiers, COB-IDs and the predefined connection set, the CANopen data types and their encoding, SDO abort codes and the NMT states and commands.

The services live in subpackages and all run on a canbus.Bus, so they work on every go-canbus transport (Linux SocketCAN, slcan adapters, the virtual bus):

  • od: the object dictionary, with access rules, limits and hooks
  • sdo: SDO client and server (expedited, segmented and block transfer)
  • nmt: NMT master commands, the NMT slave state machine, heartbeat producer and consumer, node guarding
  • pdo: PDO mapping, transmit and receive PDOs
  • sync, emcy, timestamp: the SYNC, EMCY and TIME objects
  • node: a complete CANopen device built from an object dictionary
  • master: a network manager (NMT, heartbeat supervision, SDO clients, network scan, configuration from a DCF, remote PDOs)
  • eds: EDS and DCF (CiA 306) reader, validator and writer
  • codegen: typed Go code from an EDS
  • cia402: the CiA 402 drive profile (state machine, modes of operation)
  • dissect: decoding of CAN frames as CANopen messages

Index

Constants

View Source
const (
	FuncNMT       canbus.ID = 0x000 // NMT module control (no node-ID)
	FuncSYNC      canbus.ID = 0x080 // SYNC (no node-ID)
	FuncEMCY      canbus.ID = 0x080 // EMCY, + node-ID
	FuncTIME      canbus.ID = 0x100 // TIME stamp (no node-ID)
	FuncTPDO1     canbus.ID = 0x180
	FuncRPDO1     canbus.ID = 0x200
	FuncTPDO2     canbus.ID = 0x280
	FuncRPDO2     canbus.ID = 0x300
	FuncTPDO3     canbus.ID = 0x380
	FuncRPDO3     canbus.ID = 0x400
	FuncTPDO4     canbus.ID = 0x480
	FuncRPDO4     canbus.ID = 0x500
	FuncSDOTx     canbus.ID = 0x580 // SDO server to client, + node-ID
	FuncSDORx     canbus.ID = 0x600 // SDO client to server, + node-ID
	FuncHeartbeat canbus.ID = 0x700 // NMT error control (boot-up, heartbeat, guarding), + node-ID
	LSSMasterID   canbus.ID = 0x7E5 // LSS master to slaves (CiA 305)
	LSSSlaveID    canbus.ID = 0x7E4 // LSS slave to master (CiA 305)
)

Function codes of the predefined connection set (CiA 301 7.3.5): the CAN identifier of a node's default COB is the function code plus the node-ID.

Variables

View Source
var (
	// ErrInvalidNodeID reports a node-ID outside 1..127.
	ErrInvalidNodeID = errors.New("canopen: invalid node-ID")

	// ErrTimeout reports a protocol timeout (an SDO response, a heartbeat,
	// a boot-up message that did not arrive in time). A context deadline is
	// reported as the context's error instead.
	ErrTimeout = errors.New("canopen: timeout")

	// ErrClosed reports an operation on a closed service.
	ErrClosed = errors.New("canopen: closed")

	// ErrDataType reports a value that does not fit its CANopen data type.
	ErrDataType = errors.New("canopen: data type mismatch")

	// ErrProtocol reports a message that violates the protocol (an
	// unexpected SDO command specifier, a wrong toggle bit, a short frame).
	ErrProtocol = errors.New("canopen: protocol error")

	// ErrBusy reports a service that is already running a transfer.
	ErrBusy = errors.New("canopen: busy")
)

Sentinel errors. They are usually wrapped with detail; test with errors.Is. SDO aborts are AbortCode values (errors.As).

Functions

func Classify

func Classify(id canbus.ID) (s Service, node NodeID, pdo int)

Classify maps an 11-bit CAN identifier to its service in the predefined connection set, the node-ID it carries (0 for NMT, SYNC, TIME and LSS) and, for PDOs, the PDO number 1..4. Devices may move any COB to another identifier, so the answer is the default interpretation only.

func Decode

func Decode(t DataType, b []byte) (any, error)

Decode converts the bus encoding of t to a Go value: bool for BOOLEAN, int64 for signed and uint64 for unsigned integers of every width, float32/float64 for REAL32/REAL64, string for VISIBLE_STRING and UNICODE_STRING, []byte for everything else.

func DecodeInt

func DecodeInt(b []byte) int64

DecodeInt decodes a little-endian two's complement integer of 1..8 bytes.

func DecodeUint

func DecodeUint(b []byte) uint64

DecodeUint decodes a little-endian unsigned integer of 1..8 bytes.

func DefaultRPDO

func DefaultRPDO(n int, id NodeID) canbus.ID

DefaultRPDO returns the default CAN identifier of RPDO n (1..4) of a node; 0 when n is out of range.

func DefaultTPDO

func DefaultTPDO(n int, id NodeID) canbus.ID

DefaultTPDO returns the default CAN identifier of TPDO n (1..4) of a node; 0 when n is out of range.

func Encode

func Encode(t DataType, v any) ([]byte, error)

Encode converts a Go value to the bus encoding of t. Integers accept any Go integer type (range-checked), floats float32/float64, BOOLEAN bool or an integer 0/1, strings string, OCTET_STRING and DOMAIN []byte or a string. A []byte is accepted for every type when its length matches.

func EncodeInt

func EncodeInt(t DataType, i int64, u uint64, neg bool) ([]byte, error)

EncodeInt encodes an integer of type t, with a range check. neg tells whether the value is negative (then i holds it); otherwise u holds it.

func FormatValue

func FormatValue(t DataType, b []byte) string

FormatValue formats an encoded value of type t for display: decimal for signed integers and floats, 0x hexadecimal for unsigned integers, the text for strings, hexadecimal bytes otherwise.

func ParseInt

func ParseInt(s string, bits int) (int64, error)

ParseInt parses a signed integer literal (decimal, 0x hexadecimal, or octal with a leading 0; an optional sign). A hexadecimal literal may also give the two's complement pattern of a negative value, as EDS tools write them ("0xFFFFFFFF" for an INTEGER32 -1).

func ParseUint

func ParseUint(s string, bits int) (uint64, error)

ParseUint parses an unsigned integer literal as EDS files write them: decimal, hexadecimal with 0x, or octal with a leading 0 (CiA 306 4.6.3).

func ParseValue

func ParseValue(t DataType, s string, node NodeID) ([]byte, error)

ParseValue parses a value literal of type t as EDS and DCF files write them (CiA 306): integers in decimal, 0x hexadecimal or octal, optionally with $NODEID added ("$NODEID+0x180", "0x180+$NODEID"), which evaluates to node; floats in decimal notation; VISIBLE_STRING as the text itself; OCTET_STRING and DOMAIN as hexadecimal digit pairs (spaces allowed); UNICODE_STRING as text. An empty literal of an integer or float type is zero.

Types

type AbortCode

type AbortCode uint32

AbortCode is an SDO abort code (CiA 301 7.2.4.3.17). It is also the error type the object dictionary returns for refused accesses, so that an SDO server can pass the reason on unchanged. Test with errors.As.

const (
	AbortToggle            AbortCode = 0x05030000 // toggle bit not alternated
	AbortTimeout           AbortCode = 0x05040000 // SDO protocol timed out
	AbortCommand           AbortCode = 0x05040001 // command specifier not valid or unknown
	AbortBlockSize         AbortCode = 0x05040002 // invalid block size (block mode)
	AbortSequence          AbortCode = 0x05040003 // invalid sequence number (block mode)
	AbortCRC               AbortCode = 0x05040004 // CRC error (block mode)
	AbortOutOfMemory       AbortCode = 0x05040005 // out of memory
	AbortUnsupported       AbortCode = 0x06010000 // unsupported access to an object
	AbortWriteOnly         AbortCode = 0x06010001 // attempt to read a write-only object
	AbortReadOnly          AbortCode = 0x06010002 // attempt to write a read-only object
	AbortNoObject          AbortCode = 0x06020000 // object does not exist
	AbortNotMappable       AbortCode = 0x06040041 // object cannot be mapped to the PDO
	AbortPDOLength         AbortCode = 0x06040042 // mapped objects exceed the PDO length
	AbortParamIncompatible AbortCode = 0x06040043 // general parameter incompatibility
	AbortInternal          AbortCode = 0x06040047 // general internal incompatibility in the device
	AbortHardware          AbortCode = 0x06060000 // access failed due to a hardware error
	AbortLength            AbortCode = 0x06070010 // data type or length does not match
	AbortLengthHigh        AbortCode = 0x06070012 // length of service parameter too high
	AbortLengthLow         AbortCode = 0x06070013 // length of service parameter too low
	AbortNoSubIndex        AbortCode = 0x06090011 // sub-index does not exist
	AbortInvalidValue      AbortCode = 0x06090030 // invalid value for parameter
	AbortValueHigh         AbortCode = 0x06090031 // value written too high
	AbortValueLow          AbortCode = 0x06090032 // value written too low
	AbortMaxLessMin        AbortCode = 0x06090036 // maximum value is less than minimum value
	AbortNoResource        AbortCode = 0x060A0023 // resource not available: SDO connection
	AbortGeneral           AbortCode = 0x08000000 // general error
	AbortTransfer          AbortCode = 0x08000020 // data cannot be transferred or stored
	AbortLocalControl      AbortCode = 0x08000021 // ... because of local control
	AbortDeviceState       AbortCode = 0x08000022 // ... because of the present device state
	AbortNoDictionary      AbortCode = 0x08000023 // no object dictionary present
	AbortNoData            AbortCode = 0x08000024 // no data available
)

SDO abort codes.

func (AbortCode) Error

func (c AbortCode) Error() string

Error implements error.

func (AbortCode) Text

func (c AbortCode) Text() string

Text describes the code; empty for codes CiA 301 does not define.

type AbortError

type AbortError struct {
	Code     AbortCode
	Index    uint16
	SubIndex uint8
	// Remote is true when the peer sent the abort, false when this side
	// aborted the transfer.
	Remote bool
}

AbortError is an SDO abort with the object it concerns, as reported by the SDO client. It unwraps to its AbortCode.

func (*AbortError) Error

func (e *AbortError) Error() string

Error implements error.

func (*AbortError) Unwrap

func (e *AbortError) Unwrap() error

Unwrap returns the abort code.

type Bus

type Bus interface {
	Send(ctx context.Context, f *canbus.Frame) error
	Subscribe(opts ...canbus.SubscribeOption) (*canbus.Subscription, error)
}

Bus is what the CANopen services need from the CAN layer: sending frames and subscribing to received ones. *canbus.Bus implements it, on every go-canbus transport. A node does not receive its own transmissions (as on a real bus), so two services that talk to each other in one process need two buses (two ports of a virtual bus, or two SocketCAN sockets).

type COBID

type COBID uint32

COBID is the value of a COB-ID object (0x1005, 0x1014, 0x1200 sub 1/2, 0x1400 and 0x1800 sub 1, ...): the CAN identifier in bits 0..28 and flag bits above it.

const (
	// COBInvalid (bit 31) disables the object: a PDO or EMCY that does not
	// exist or is not valid, an SDO channel that is not used.
	COBInvalid COBID = 1 << 31
	// COBNoRTR (bit 30) of a PDO COB-ID: no remote transmission request
	// allowed. Of the SYNC COB-ID (0x1005) this bit is "generate": the
	// device is the SYNC producer.
	COBNoRTR COBID = 1 << 30
	// COBGenerate is bit 30 of the SYNC (0x1005) and TIME (0x1012) COB-IDs:
	// the device produces the object.
	COBGenerate COBID = 1 << 30
	// COBConsume is bit 31 of the TIME COB-ID (0x1012): the device consumes
	// TIME stamps. (For SYNC, bit 31 has no meaning.)
	COBConsume COBID = 1 << 31
	// COBExtended (bit 29) selects a 29-bit CAN identifier.
	COBExtended COBID = 1 << 29
)

COB-ID flag bits (CiA 301 7.5.2).

func NewCOBID

func NewCOBID(id canbus.ID) COBID

NewCOBID returns the COB-ID of a CAN identifier (extended when id does not fit in 11 bits).

func (COBID) Extended

func (c COBID) Extended() bool

Extended reports whether the identifier is a 29-bit one.

func (COBID) Filter

func (c COBID) Filter() canbus.Filter

Filter returns the go-canbus receive filter for this COB-ID.

func (COBID) ID

func (c COBID) ID() canbus.ID

ID returns the CAN identifier.

func (COBID) Matches

func (c COBID) Matches(f *canbus.Frame) bool

Matches reports whether the frame carries this COB-ID's identifier in the same format.

func (COBID) String

func (c COBID) String() string

String formats the COB-ID in hexadecimal, with its flags.

func (COBID) Valid

func (c COBID) Valid() bool

Valid reports whether bit 31 (invalid) is clear.

type DataType

type DataType uint16

DataType is a CANopen data type index (CiA 301 7.4.7.1, the objects at 0x0001..0x0025 of the object dictionary).

const (
	Boolean        DataType = 0x0001
	Integer8       DataType = 0x0002
	Integer16      DataType = 0x0003
	Integer32      DataType = 0x0004
	Unsigned8      DataType = 0x0005
	Unsigned16     DataType = 0x0006
	Unsigned32     DataType = 0x0007
	Real32         DataType = 0x0008
	VisibleString  DataType = 0x0009
	OctetString    DataType = 0x000A
	UnicodeString  DataType = 0x000B
	TimeOfDay      DataType = 0x000C
	TimeDifference DataType = 0x000D
	Domain         DataType = 0x000F
	Integer24      DataType = 0x0010
	Real64         DataType = 0x0011
	Integer40      DataType = 0x0012
	Integer48      DataType = 0x0013
	Integer56      DataType = 0x0014
	Integer64      DataType = 0x0015
	Unsigned24     DataType = 0x0016
	Unsigned40     DataType = 0x0018
	Unsigned48     DataType = 0x0019
	Unsigned56     DataType = 0x001A
	Unsigned64     DataType = 0x001B

	// Complex (structured) types of the communication profile.
	PDOCommParam DataType = 0x0020
	PDOMapping   DataType = 0x0021
	SDOParam     DataType = 0x0022
	Identity     DataType = 0x0023
)

Static data types. Multi-byte values are little-endian on the bus.

func ParseDataType

func ParseDataType(s string) (DataType, error)

ParseDataType parses a CiA 301 type name ("UNSIGNED32") or a type index ("0x0007").

func (DataType) Bits

func (t DataType) Bits() int

Bits returns the size in bits of a value of the type in a PDO: 1 for BOOLEAN (CiA 301 encodes it as one bit), 8 times Size otherwise, 0 for variable-length types.

func (DataType) IsFloat

func (t DataType) IsFloat() bool

IsFloat reports whether t is REAL32 or REAL64.

func (DataType) IsInteger

func (t DataType) IsInteger() bool

IsInteger reports whether t is a signed or unsigned integer type (not BOOLEAN).

func (DataType) IsSigned

func (t DataType) IsSigned() bool

IsSigned reports whether t is a signed integer type.

func (DataType) IsVariable

func (t DataType) IsVariable() bool

IsVariable reports whether values of t have no fixed size (VISIBLE_STRING, OCTET_STRING, UNICODE_STRING, DOMAIN).

func (DataType) Known

func (t DataType) Known() bool

Known reports whether t is a data type this package knows.

func (DataType) Size

func (t DataType) Size() int

Size returns the encoded size in bytes, 0 for variable-length types (strings, DOMAIN) and unknown types.

func (DataType) String

func (t DataType) String() string

String returns the CiA 301 name, e.g. "UNSIGNED32".

type NMTCommand

type NMTCommand uint8

NMTCommand is the command specifier of an NMT module control message (CAN-ID 0x000: command, node-ID).

const (
	NMTStart               NMTCommand = 0x01 // enter operational
	NMTStop                NMTCommand = 0x02 // enter stopped
	NMTEnterPreOperational NMTCommand = 0x80
	NMTResetNode           NMTCommand = 0x81 // reset application
	NMTResetCommunication  NMTCommand = 0x82
)

NMT commands.

func ParseNMTCommand

func ParseNMTCommand(s string) (NMTCommand, error)

ParseNMTCommand parses a command name as String returns it.

func (NMTCommand) String

func (c NMTCommand) String() string

String names the command.

func (NMTCommand) Valid

func (c NMTCommand) Valid() bool

Valid reports whether c is one of the five NMT commands.

type NMTState

type NMTState uint8

NMTState is a node's NMT state as it reports it in heartbeat and node guarding messages (CiA 301 7.2.8.3.2). Boot-up is reported as StateInitialising (0x00).

const (
	StateInitialising   NMTState = 0x00
	StateStopped        NMTState = 0x04
	StateOperational    NMTState = 0x05
	StatePreOperational NMTState = 0x7F
	// StateUnknown is no state a node reports: a consumer's state before
	// it has heard from the node, or after a heartbeat timeout.
	StateUnknown NMTState = 0xFF
)

NMT states.

func ParseNMTState

func ParseNMTState(s string) (NMTState, error)

ParseNMTState parses a state name as String returns it.

func (NMTState) String

func (s NMTState) String() string

String names the state as CiA 301 does.

type NodeID

type NodeID uint8

NodeID is a CANopen node-ID: 1..127. 0 addresses all nodes in NMT commands and is not a valid node-ID otherwise.

const (
	BroadcastNodeID NodeID = 0   // all nodes, in NMT commands only
	MinNodeID       NodeID = 1   // lowest valid node-ID
	MaxNodeID       NodeID = 127 // highest valid node-ID
)

Node-ID limits.

func (NodeID) Check

func (id NodeID) Check() error

Check returns ErrInvalidNodeID unless id is valid.

func (NodeID) Valid

func (id NodeID) Valid() bool

Valid reports whether id is a node-ID a device can have (1..127).

type Service

type Service uint8

Service is the CANopen service a CAN identifier belongs to in the predefined connection set.

const (
	ServiceUnknown Service = iota
	ServiceNMT
	ServiceSYNC
	ServiceEMCY
	ServiceTIME
	ServiceTPDO
	ServiceRPDO
	ServiceSDOTx // server to client (response)
	ServiceSDORx // client to server (request)
	ServiceHeartbeat
	ServiceLSS
)

Services of the predefined connection set.

func (Service) String

func (s Service) String() string

String names the service.

Directories

Path Synopsis
Package cdcf is the concise DCF of CiA 302-3: the binary form of a node configuration that a CANopen manager keeps in its object 0x1F22 (one DOMAIN sub-object per node) and writes to the node at boot-up.
Package cdcf is the concise DCF of CiA 302-3: the binary form of a node configuration that a CANopen manager keeps in its object 0x1F22 (one DOMAIN sub-object per node) and writes to the node at boot-up.
Package cia402 implements the CiA 402 drive profile (IEC 61800-7-201): the power drive state machine, the modes of operation and the common 0x6xxx objects, a device-side drive model and a master-side controller.
Package cia402 implements the CiA 402 drive profile (IEC 61800-7-201): the power drive state machine, the modes of operation and the common 0x6xxx objects, a device-side drive model and a master-side controller.
Package codegen generates typed Go code from an EDS or DCF (eds.File): index and sub-index constants for every object, a NewDictionary function that builds the object dictionary without parsing anything at run time, a typed local accessor over an od.Dictionary and a typed remote accessor over an SDO client.
Package codegen generates typed Go code from an EDS or DCF (eds.File): index and sub-index constants for every object, a NewDictionary function that builds the object dictionary without parsing anything at run time, a typed local accessor over an od.Dictionary and a typed remote accessor over an SDO client.
Package dissect interprets CAN frames as CANopen messages by the predefined connection set (CiA 301 7.3.5, canopen.Classify): NMT, SYNC, TIME, EMCY, PDOs, SDO requests and responses, NMT error control (heartbeat, boot-up, node guarding) and LSS (CiA 305).
Package dissect interprets CAN frames as CANopen messages by the predefined connection set (CiA 301 7.3.5, canopen.Classify): NMT, SYNC, TIME, EMCY, PDOs, SDO requests and responses, NMT error control (heartbeat, boot-up, node guarding) and LSS (CiA 305).
Package e2e holds the end-to-end tests of go-canopen: a master and several nodes (I/O modules and a CiA 402 drive) running the whole stack (NMT, boot procedure, SDO, PDO, SYNC, heartbeat, EMCY, resets) over the virtual bus, and on Linux also over SocketCAN (vcan0, or the interface CANOPEN_TEST_IFACE names).
Package e2e holds the end-to-end tests of go-canopen: a master and several nodes (I/O modules and a CiA 402 drive) running the whole stack (NMT, boot procedure, SDO, PDO, SYNC, heartbeat, EMCY, resets) over the virtual bus, and on Linux also over SocketCAN (vcan0, or the interface CANOPEN_TEST_IFACE names).
Package eds reads, validates and writes CANopen electronic data sheets (EDS) and device configuration files (DCF) as CiA 306-1 specifies them, and converts them to and from an od.Dictionary.
Package eds reads, validates and writes CANopen electronic data sheets (EDS) and device configuration files (DCF) as CiA 306-1 specifies them, and converts them to and from an od.Dictionary.
Package emcy implements the CANopen emergency object (CiA 301 7.2.7).
Package emcy implements the CANopen emergency object (CiA 301 7.2.7).
examples
canopen-fd command
Command canopen-fd runs a CANopen FD network (CiA 1301) on a virtual CAN FD bus: a master and a device in FD mode.
Command canopen-fd runs a CANopen FD network (CiA 1301) on a virtual CAN FD bus: a master and a device in FD mode.
cia402-drive command
Command cia402-drive runs a simulated CiA 402 drive as a CANopen node on a virtual CAN bus and operates it from a master over SDO: enable (walking the state machine), profile position moves, a fault with its emergency message, fault reset, and disable.
Command cia402-drive runs a simulated CiA 402 drive as a CANopen node on a virtual CAN bus and operates it from a master over SDO: enable (walking the state machine), profile position moves, a fault with its emergency message, fault reset, and disable.
eds-dictionary command
Command eds-dictionary builds a CANopen device from an EDS (a CiA 401 I/O module), runs it on a virtual CAN bus, configures it from a DCF with the master, and exports its configuration as a DCF again.
Command eds-dictionary builds a CANopen device from an EDS (a CiA 401 I/O module), runs it on a virtual CAN bus, configures it from a DCF with the master, and exports its configuration as a DCF again.
lss-assign command
Command lss-assign starts three CANopen devices without node-ID (LSS, CiA 305) on a virtual CAN bus.
Command lss-assign starts three CANopen devices without node-ID (LSS, CiA 305) on a virtual CAN bus.
network-boot command
Command network-boot runs the CiA 302-2 network boot-up on a virtual CAN bus: a CANopen manager (master.WithDictionary) whose dictionary lists two slaves in 0x1F81 with their expected identity, a concise DCF each (0x1F22) and heartbeat supervision (0x1016).
Command network-boot runs the CiA 302-2 network boot-up on a virtual CAN bus: a CANopen manager (master.WithDictionary) whose dictionary lists two slaves in 0x1F81 with their expected identity, a concise DCF each (0x1F22) and heartbeat supervision (0x1016).
node-master command
Command node-master runs a CANopen device and a network manager on a virtual CAN bus: the master waits for the boot-up, reads the device's identity by SDO, maps a TPDO and an RPDO, starts the node and exchanges process data with it.
Command node-master runs a CANopen device and a network manager on a virtual CAN bus: the master waits for the boot-up, reads the device's identity by SDO, maps a TPDO and an RPDO, starts the node and exchanges process data with it.
sdo-block command
Command sdo-block transfers a 64 KiB DOMAIN to and from a CANopen node with SDO block transfer (CRC-checked) on a virtual CAN bus, and compares it with segmented transfer.
Command sdo-block transfers a 64 KiB DOMAIN to and from a CANopen node with SDO block transfer (CRC-checked) on a virtual CAN bus, and compares it with segmented transfer.
socketcan-node command
Command socketcan-node runs a CANopen device on a Linux SocketCAN interface (a real adapter, or vcan for experiments) until interrupted: boot-up, heartbeat, SDO server, EMCY and four TPDOs/RPDOs, with a counter mapped into TPDO 1 by default (send NMT start to see it).
Command socketcan-node runs a CANopen device on a Linux SocketCAN interface (a real adapter, or vcan for experiments) until interrupted: boot-up, heartbeat, SDO server, EMCY and four TPDOs/RPDOs, with a counter mapped into TPDO 1 by default (send NMT start to see it).
internal
cmd/gengolden command
Command gengolden regenerates the code generator's golden output, internal/golden/*, from the EDS and DCF fixtures (go generate ./...).
Command gengolden regenerates the code generator's golden output, internal/golden/*, from the EDS and DCF fixtures (go generate ./...).
golden/compact
Package compact is the object dictionary of Compact demo (OT Fabric), generated from compact.eds.
Package compact is the object dictionary of Compact demo (OT Fabric), generated from compact.eds.
golden/drive402
Package drive402 is the object dictionary of Servo 402 (OT Fabric), generated from drive402.eds.
Package drive402 is the object dictionary of Servo 402 (OT Fabric), generated from drive402.eds.
golden/ds301
Package ds301 is the object dictionary of New Product, generated from canopennode_ds301_profile.eds.
Package ds301 is the object dictionary of New Product, generated from canopennode_ds301_profile.eds.
golden/io401
Package io401 is the object dictionary of IO-401 (OT Fabric), generated from io401.eds.
Package io401 is the object dictionary of IO-401 (OT Fabric), generated from io401.eds.
golden/node37
Package node37 is the object dictionary of IO-401 (OT Fabric), generated from node37.dcf.
Package node37 is the object dictionary of IO-401 (OT Fabric), generated from node37.dcf.
nettest
Package nettest provides what the network-level tests (node, master, e2e) share: a device dictionary with application objects, contexts, polling and a goroutine leak check.
Package nettest provides what the network-level tests (node, master, e2e) share: a device dictionary with application objects, contexts, polling and a goroutine leak check.
testbus
Package testbus provides CAN buses for tests: ports of one virtual bus, and two virtual buses joined by a fault-injecting chaos bridge.
Package testbus provides CAN buses for tests: ports of one virtual bus, and two virtual buses joined by a fault-injecting chaos bridge.
Package interop tests go-canopen against the independent CANopen stacks of the otfabric/canopen-interop images (CANopenNode, Lely CANopen, python canopen), through their container contract only:
Package interop tests go-canopen against the independent CANopen stacks of the otfabric/canopen-interop images (CANopenNode, Lely CANopen, python canopen), through their container contract only:
Package lss implements the CANopen layer setting services (CiA 305): an LSS Master that inquires and configures the node-ID and the bit timing of devices identified by their 128-bit LSS address (the identity object 0x1018), and finds unconfigured devices with Fastscan; and an LSS Slave, the LSS state machine of a device.
Package lss implements the CANopen layer setting services (CiA 305): an LSS Master that inquires and configures the node-ID and the bit timing of devices identified by their 128-bit LSS address (the identity object 0x1018), and finds unconfigured devices with Fastscan; and an LSS Slave, the LSS state machine of a device.
Package master is a CANopen network manager (an NMT master with the services a CiA 302 manager uses): NMT commands, heartbeat supervision, emergency reception, SDO clients for every node, network scan, node configuration (from entries or a DCF), a boot procedure, remote PDOs, SYNC and TIME production, CiA 402 drive control, an LSS master, MPDO configuration, CANopen FD (USDO) and the CiA 302 manager.
Package master is a CANopen network manager (an NMT master with the services a CiA 302 manager uses): NMT commands, heartbeat supervision, emergency reception, SDO clients for every node, network scan, node configuration (from entries or a DCF), a boot procedure, remote PDOs, SYNC and TIME production, CiA 402 drive control, an LSS master, MPDO configuration, CANopen FD (USDO) and the CiA 302 manager.
Package mpdo implements CANopen multiplexed PDOs (MPDOs, CiA 301 7.2.2.4 and the object scanner and dispatcher lists 0x1FA0..0x1FFF): PDOs that carry one value of up to 4 bytes together with the object it belongs to, so that one COB-ID can transport many objects.
Package mpdo implements CANopen multiplexed PDOs (MPDOs, CiA 301 7.2.2.4 and the object scanner and dispatcher lists 0x1FA0..0x1FFF): PDOs that carry one value of up to 4 bytes together with the object it belongs to, so that one COB-ID can transport many objects.
Package nmt implements CANopen network management (CiA 301 7.2.8 and 7.3.2): NMT module control and NMT error control.
Package nmt implements CANopen network management (CiA 301 7.2.8 and 7.3.2): NMT module control and NMT error control.
Package node is a complete CANopen device (CiA 301) built from an object dictionary: New chooses the communication services from the objects the dictionary has, Node.Start starts them and sends the boot-up message, and the NMT state machine enables and disables them.
Package node is a complete CANopen device (CiA 301) built from an object dictionary: New chooses the communication services from the objects the dictionary has, Node.Start starts them and sends the boot-up message, and the NMT state machine enables and disables them.
Package od is the CANopen object dictionary (CiA 301 7.4): objects addressed by a 16-bit index and an 8-bit sub-index, with data types, access rights, PDO mappability, default values and limits.
Package od is the CANopen object dictionary (CiA 301 7.4): objects addressed by a 16-bit index and an 8-bit sub-index, with data types, access rights, PDO mappability, default values and limits.
Package pdo implements CANopen process data objects (CiA 301 7.2.2, 7.5.2.35..38): mapping entries and the bit-exact packing of mapped values, the transmit and receive PDOs of a device, and a master's tools to configure a node's PDOs over SDO and to decode and produce PDOs.
Package pdo implements CANopen process data objects (CiA 301 7.2.2, 7.5.2.35..38): mapping entries and the bit-exact packing of mapped values, the transmit and receive PDOs of a device, and a master's tools to configure a node's PDOs over SDO and to decode and produce PDOs.
Package program is the program download of CiA 302-3 on the device side: the objects through which a CANopen manager replaces the application software of a device over SDO.
Package program is the program download of CiA 302-3 on the device side: the objects through which a CANopen manager replaces the application software of a device over SDO.
Package sdo implements the CANopen service data object (CiA 301 7.2.4): a Client that reads (uploads) and writes (downloads) sub-objects of a remote object dictionary, and a Server that serves an od.Dictionary.
Package sdo implements the CANopen service data object (CiA 301 7.2.4): a Client that reads (uploads) and writes (downloads) sub-objects of a remote object dictionary, and a Server that serves an od.Dictionary.
Package store keeps the parameters of a CANopen device across restarts: the persistence behind the store parameters (0x1010) and restore default parameters (0x1011) objects of CiA 301.
Package store keeps the parameters of a CANopen device across restarts: the persistence behind the store parameters (0x1010) and restore default parameters (0x1011) objects of CiA 301.
Package syncobj implements the CANopen SYNC object (CiA 301 7.2.5).
Package syncobj implements the CANopen SYNC object (CiA 301 7.2.5).
Package timestamp implements the CANopen TIME object (CiA 301 7.2.6) and the TIME_OF_DAY and TIME_DIFFERENCE data types (CiA 301 7.1.6.5).
Package timestamp implements the CANopen TIME object (CiA 301 7.2.6) and the TIME_OF_DAY and TIME_DIFFERENCE data types (CiA 301 7.1.6.5).
Package usdo implements the universal service data object (USDO) of CANopen FD (CiA 1301), which replaces the SDO: a Client reads and writes the object dictionaries of [Server]s over CAN FD frames, to one node, to a group or to all nodes, with several transfers at once.
Package usdo implements the universal service data object (USDO) of CANopen FD (CiA 1301), which replaces the SDO: a Client reads and writes the object dictionaries of [Server]s over CAN FD frames, to one node, to a group or to all nodes, with several transfers at once.

Jump to

Keyboard shortcuts

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