network

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

This package is a pure golang implementation of the CANopen protocol

Index

Constants

This section is empty.

Variables

View Source
var ErrIdConflict = errors.New("id already exists on network, this will create conflicts")
View Source
var ErrInvalidNodeType = errors.New("invalid node type")
View Source
var ErrNoNodesFound = errors.New("no nodes found on network when performing SDO scan")
View Source
var ErrNotFound = errors.New("node id not found on network, add or create it first")

Functions

func NewBus

func NewBus(canInterfaceName string, channel string, bitrate int) (canopen.Bus, error)

Create a new CAN bus with given interface

Types

type Network

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

A Network is the main object of this package It should be created before doint anything else It acts as scheduler for locally created CANopen nodes But can also be used for controlling remote CANopen nodes

func NewNetwork

func NewNetwork(bus canopen.Bus) Network

Create a new Network using the given CAN bus

func (*Network) AddRemoteNode

func (network *Network) AddRemoteNode(nodeId uint8, odict any) (*n.RemoteNode, error)

Add a [RemoteNode] with a given OD for master control od can be either a string : path to OD or OD object useLocal is used to define whether the supplied OD should be used or the remote node should be read to create PDO mapping If remote nodes PDO mapping is static and known, use useLocal = true otherwise, if PDO mapping is dynamic, use useLocal = false

func (*Network) Command

func (network *Network) Command(nodeId uint8, nmtCommand nmt.Command) error

Command can be used to send an NMT command to a specific nodeId nodeId = 0 is used as a broadcast command i.e. affects all nodes on the network

network.Command(0,nmt.CommandResetNode) // resets all nodes
network.Command(12,nmt.CommandResetNode) // resets nodeId 12

func (*Network) Configurator

func (network *Network) Configurator(nodeId uint8) *config.NodeConfigurator

Configurator creates a [NodeConfigurator] object for a given id using the networks internal sdo client

func (*Network) Connect

func (network *Network) Connect(args ...any) error

Connects to CAN bus, this should be called before anything else. Custom CAN backend is possible using a custom "Bus" interface. Otherwise it expects an interface name, channel and bitrate. Currently only socketcan and virtualcan are supported.

func (*Network) CreateLocalNode

func (network *Network) CreateLocalNode(nodeId uint8, odict any) (*n.LocalNode, error)

Create a [LocalNode] a CiA 301 compliant node with a given OD od can be either a string : path to OD or an OD object. Processing is started immediately after creating the node. By default, node automatically goes to operational state if no errors are detected. First heartbeat, if enabled is started after 500ms

func (*Network) Disconnect

func (network *Network) Disconnect()

Disconnects from the CAN bus and stops processing of CANopen stack

func (*Network) GetOD

func (network *Network) GetOD(nodeId uint8) (*od.ObjectDictionary, error)

Get OD for a specific node id

func (*Network) Local

func (network *Network) Local(nodeId uint8) (*n.LocalNode, error)

Get a local node object in network, based on its id

func (*Network) ReadEDS

func (network *Network) ReadEDS(nodeId uint8, edsFormatHandler od.EDSFormatHandler) (*od.ObjectDictionary, error)

Read object dictionary using object 1021 (EDS storage) of a remote node Optional callback can be provided to perform manufacturer specific parsing in case a custom format is used (format type != 0). By default, regular uncompressed ASCII will be used (format type of 0).

func (*Network) Remote

func (network *Network) Remote(nodeId uint8) (*n.RemoteNode, error)

Get a remote node object in network, based on its id

func (*Network) RemoveNode

func (network *Network) RemoveNode(nodeId uint8) error

RemoveNode gracefully exits any running go routine for this node It also removes any object associated with the node, including OD

func (*Network) Scan

func (network *Network) Scan(timeoutMs uint32) (map[uint8]NodeInformation, error)

Scan network for nodes via SDO, and return map of found node ids and respective node information. Scanning is done in parallel and requires that the scanned nodes have an SDO server and that the identity object is implemented (0x1018) which is mandatory per CiA standard.

type NodeInformation

type NodeInformation struct {
	config.ManufacturerInformation
	config.Identity
}

NodeInformation contains manufacturer information and identity object

type ObjectDictionaryInformation

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

Jump to

Keyboard shortcuts

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