node

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2025 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NodeInit     uint8 = 0
	NodeRunning  uint8 = 1
	NodeReseting uint8 = 2
	NodeExit     uint8 = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseNode

type BaseNode struct {
	*canopen.BusManager
	*sdo.SDOClient
	// contains filtered or unexported fields
}

func (*BaseNode) Configurator

func (node *BaseNode) Configurator() *config.NodeConfigurator

func (*BaseNode) Export added in v1.3.0

func (node *BaseNode) Export(filename string) error

Export EDS file with current state

func (*BaseNode) GetID

func (node *BaseNode) GetID() uint8

func (*BaseNode) GetOD

func (node *BaseNode) GetOD() *od.ObjectDictionary

func (*BaseNode) Read

func (node *BaseNode) Read(index any, subindex any) (value any, e error)

[Deprecated] use ReadAny instead

func (*BaseNode) ReadAny added in v1.4.2

func (node *BaseNode) ReadAny(index any, subindex any) (any, error)

Read an entry using a base sdo client index and subindex can either be strings or integers this method requires the corresponding node OD to be loaded returned value can be either string, uint64, int64 or float64

func (*BaseNode) ReadAnyExact added in v1.4.2

func (node *BaseNode) ReadAnyExact(index any, subindex any) (any, error)

Read an entry using a base sdo client index and subindex can either be strings or integers this method requires the corresponding node OD to be loaded returned value corresponds to the exact datatype (uint8,uint16,...,int8,int16,...,float32,float64,...)

func (*BaseNode) ReadFloat

func (node *BaseNode) ReadFloat(index any, subindex any) (value float64, e error)

Same as [ReadAny] but enforces the returned type as float64

func (*BaseNode) ReadFloat32 added in v1.4.2

func (node *BaseNode) ReadFloat32(index any, subindex any) (value float32, e error)

Same as [ReadAny] but enforces the returned type as float32

func (*BaseNode) ReadInt

func (node *BaseNode) ReadInt(index any, subindex any) (value int64, e error)

Same as [ReadAny] but enforces the returned type as int64

func (*BaseNode) ReadInt16 added in v1.4.2

func (node *BaseNode) ReadInt16(index any, subindex any) (value int16, e error)

Same as [ReadAny] but enforces the returned type as int16

func (*BaseNode) ReadInt32 added in v1.4.2

func (node *BaseNode) ReadInt32(index any, subindex any) (value int32, e error)

Same as [ReadAny] but enforces the returned type as int32

func (*BaseNode) ReadInt8 added in v1.4.2

func (node *BaseNode) ReadInt8(index any, subindex any) (value int8, e error)

Same as [ReadAny] but enforces the returned type as int8

func (*BaseNode) ReadRaw

func (node *BaseNode) ReadRaw(index uint16, subIndex uint8, data []byte) (int, error)

Read an entry from a remote node this method does not require corresponding OD to be loaded value will be read as a raw byte slice does not support block transfer

func (*BaseNode) ReadString

func (node *BaseNode) ReadString(index any, subindex any) (value string, e error)

Same as [ReadAny] but enforces the returned type as string

func (*BaseNode) ReadUint

func (node *BaseNode) ReadUint(index any, subindex any) (value uint64, e error)

Same as [ReadAny] but enforces the returned type as uint64

func (*BaseNode) ReadUint16 added in v1.4.2

func (node *BaseNode) ReadUint16(index any, subindex any) (value uint16, e error)

Same as [ReadAny] but enforces the returned type as uint16

func (*BaseNode) ReadUint32 added in v1.4.2

func (node *BaseNode) ReadUint32(index any, subindex any) (value uint32, e error)

Same as [ReadAny] but enforces the returned type as uint32

func (*BaseNode) ReadUint8 added in v1.4.2

func (node *BaseNode) ReadUint8(index any, subindex any) (value uint8, e error)

Same as [ReadAny] but enforces the returned type as uint8

func (*BaseNode) Write

func (node *BaseNode) Write(index any, subindex any, value any) error

[Deprecated] use WriteAny instead

func (*BaseNode) WriteAny added in v1.4.2

func (node *BaseNode) WriteAny(index any, subindex any, value any) error

Write an entry to a remote node index and subindex can either be strings or integers this method requires the corresponding node OD to be loaded value should correspond to the expected datatype

func (*BaseNode) WriteRaw

func (node *BaseNode) WriteRaw(index uint16, subIndex uint8, data []byte) error

Write an entry to a remote node this method does not require corresponding OD to be loaded value will be written as a raw byte slice does not support block transfer

type LocalNode

type LocalNode struct {
	*BaseNode
	NodeIdUnconfigured bool
	NMT                *nmt.NMT
	HBConsumer         *heartbeat.HBConsumer
	SDOclients         []*sdo.SDOClient
	SDOServers         []*sdo.SDOServer
	TPDOs              []*pdo.TPDO
	RPDOs              []*pdo.RPDO
	SYNC               *s.SYNC
	EMCY               *emergency.EMCY
	TIME               *t.TIME
}

A LocalNode is a CiA 301 compliant CANopen node It supports all the standard CANopen objects. These objects will be loaded depending on the given EDS file. For configuration of the different CANopen objects see [NodeConfigurator].

func NewLocalNode

func NewLocalNode(
	bm *canopen.BusManager,
	logger *slog.Logger,
	odict *od.ObjectDictionary,
	nm *nmt.NMT,
	emcy *emergency.EMCY,
	nodeId uint8,
	nmtControl uint16,
	firstHbTimeMs uint16,
	sdoServerTimeoutMs uint32,
	sdoClientTimeoutMs uint32,
	blockTransferEnabled bool,
	statusBits *od.Entry,

) (*LocalNode, error)

Create a new local node

func (*LocalNode) ProcessMain

func (node *LocalNode) ProcessMain(enableGateway bool, timeDifferenceUs uint32, timerNextUs *uint32) uint8

Process canopen objects that are not RT Does not process SYNC and PDOs

func (*LocalNode) ProcessPDO added in v1.4.2

func (node *LocalNode) ProcessPDO(syncWas bool, timeDifferenceUs uint32)

func (*LocalNode) ProcessSYNC

func (node *LocalNode) ProcessSYNC(timeDifferenceUs uint32) bool

func (*LocalNode) Servers added in v1.4.0

func (node *LocalNode) Servers() []*sdo.SDOServer

type Node

type Node interface {
	// Cyclic tasks
	ProcessPDO(syncWas bool, timeDifferenceUs uint32)
	ProcessSYNC(timeDifferenceUs uint32) bool
	ProcessMain(enableGateway bool, timeDifferenceUs uint32, timerNextUs *uint32) uint8
	// Internal servers
	Servers() []*sdo.SDOServer
	GetOD() *od.ObjectDictionary
	GetID() uint8
	Export(filename string) error
}

A Node handles the CANopen stack.

type NodeProcessor added in v1.4.0

type NodeProcessor struct {
	// contains filtered or unexported fields
}

NodeProcessor is responsible for handling the node internal CANopen stack processing.

func NewNodeProcessor added in v1.4.0

func NewNodeProcessor(n Node, logger *slog.Logger, processingPeriod time.Duration) *NodeProcessor

func (*NodeProcessor) AddResetHandler added in v1.4.0

func (c *NodeProcessor) AddResetHandler(handler func(node Node, cmd uint8) error)

Add a specific handler to be called on reset events

func (*NodeProcessor) GetNode added in v1.4.0

func (c *NodeProcessor) GetNode() Node

Get underlying Node object

func (*NodeProcessor) Start added in v1.4.0

func (c *NodeProcessor) Start(ctx context.Context) error

Start node processing, this will be run inside of a go routine Call Stop() to stop processing or cancel the context Call Wait() to wait for end of execution

func (*NodeProcessor) Stop added in v1.4.0

func (c *NodeProcessor) Stop() error

Stop node processing i.e. stop all tasks Wait should be called in order to make sure that all routines have been stopped

func (*NodeProcessor) Wait added in v1.4.0

func (c *NodeProcessor) Wait() error

Wait for processing to finish (blocking)

type RemoteNode

type RemoteNode struct {
	*BaseNode
	// contains filtered or unexported fields
}

A RemoteNode is a bit different from a LocalNode. It is a local representation of a remote node on the CAN bus and does not have the same standard CiA objects. Its goal is to simplify master control by providing some general features :

  • SDOClient for reading / writing to remote node with given EDS
  • RPDO for updating a local OD with the TPDOs from the remote node
  • SYNC consumer

A RemoteNode has the same id as the remote node that it controls however, being a direct local representation it may only be accessed locally.

func NewRemoteNode

func NewRemoteNode(
	bm *canopen.BusManager,
	logger *slog.Logger,
	remoteOd *od.ObjectDictionary,
	remoteNodeId uint8,
) (*RemoteNode, error)

Create a remote node

func (*RemoteNode) ProcessMain

func (node *RemoteNode) ProcessMain(enableGateway bool, timeDifferenceUs uint32, timerNextUs *uint32) uint8

func (*RemoteNode) ProcessPDO added in v1.4.2

func (node *RemoteNode) ProcessPDO(syncWas bool, timeDifferenceUs uint32)

func (*RemoteNode) ProcessSYNC

func (node *RemoteNode) ProcessSYNC(timeDifferenceUs uint32) bool

func (*RemoteNode) Servers added in v1.4.0

func (node *RemoteNode) Servers() []*sdo.SDOServer

func (*RemoteNode) StartPDOs

func (node *RemoteNode) StartPDOs(useLocal bool) error

Initialize PDOs according to either local OD mapping or remote OD mapping A TPDO from the distant node corresponds to an RPDO on this node and vice-versa

Jump to

Keyboard shortcuts

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