Implement canopen protocol with https://github.com/angelodlfrtr/go-can
Port of https://github.com/christiansandberg/canopen written in Python
go get github.com/angelodlfrtr/go-canopenpackage main
import (
"github.com/angelodlfrtr/go-can"
"github.com/angelodlfrtr/go-canopen"
"github.com/angelodlfrtr/go-can/transports"
"log"
)
func main() {
}Copyright (c) 2019 The go-canopen contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import "github.com/angelodlfrtr/go-canopen"Package canopen implement canopen protocol over github.com/angelodlfrtr/go-can
- Constants
- Variables
- func IsDataType(t byte) bool
- func IsFloatType(t byte) bool
- func IsIntegerType(t byte) bool
- func IsNumberType(t byte) bool
- func IsSignedType(t byte) bool
- func IsStringType(t byte) bool
- func IsUnsignedType(t byte) bool
- type DicArray
- func (array *DicArray) AddMember(object DicObject)
- func (array *DicArray) FindIndex(index uint16) DicObject
- func (array *DicArray) FindName(name string) DicObject
- func (array *DicArray) GetBoolVal() *bool
- func (array *DicArray) GetByteVal() *byte
- func (array *DicArray) GetData() []byte
- func (array *DicArray) GetDataLen() int
- func (array *DicArray) GetDataType() byte
- func (array *DicArray) GetFloatVal() *float64
- func (array *DicArray) GetIndex() uint16
- func (array *DicArray) GetIntVal() *int64
- func (array *DicArray) GetName() string
- func (array *DicArray) GetOffset() int
- func (array *DicArray) GetStringVal() *string
- func (array *DicArray) GetSubIndex() uint8
- func (array *DicArray) GetUintVal() *uint64
- func (array *DicArray) IsDicVariable() bool
- func (array *DicArray) Read() error
- func (array *DicArray) Save() error
- func (array *DicArray) SetBoolVal(a bool)
- func (array *DicArray) SetByteVal(a byte)
- func (array *DicArray) SetData(data []byte)
- func (array *DicArray) SetFloatVal(a float64)
- func (array *DicArray) SetIntVal(a int64)
- func (array *DicArray) SetOffset(s int)
- func (array *DicArray) SetSDO(sdo *SDOClient)
- func (array *DicArray) SetSize(s int)
- func (array *DicArray) SetStringVal(a string)
- func (array *DicArray) SetUintVal(a uint64)
- type DicObject
- type DicObjectDic
- func DicEDSParse(in interface{}) (*DicObjectDic, error)
- func DicMustParse(a *DicObjectDic, err error) *DicObjectDic
- func NewDicObjectDic() *DicObjectDic
- func (objectDic *DicObjectDic) AddObject(object DicObject)
- func (objectDic *DicObjectDic) FindIndex(index uint16) DicObject
- func (objectDic *DicObjectDic) FindName(name string) DicObject
- type DicRecord
- func (record *DicRecord) AddMember(object DicObject)
- func (record *DicRecord) FindIndex(index uint16) DicObject
- func (record *DicRecord) FindName(name string) DicObject
- func (record *DicRecord) GetBoolVal() *bool
- func (record *DicRecord) GetByteVal() *byte
- func (record *DicRecord) GetData() []byte
- func (record *DicRecord) GetDataLen() int
- func (record *DicRecord) GetDataType() byte
- func (record *DicRecord) GetFloatVal() *float64
- func (record *DicRecord) GetIndex() uint16
- func (record *DicRecord) GetIntVal() *int64
- func (record *DicRecord) GetName() string
- func (record *DicRecord) GetOffset() int
- func (record *DicRecord) GetStringVal() *string
- func (record *DicRecord) GetSubIndex() uint8
- func (record *DicRecord) GetUintVal() *uint64
- func (record *DicRecord) IsDicVariable() bool
- func (record *DicRecord) Read() error
- func (record *DicRecord) Save() error
- func (record *DicRecord) SetBoolVal(a bool)
- func (record *DicRecord) SetByteVal(a byte)
- func (record *DicRecord) SetData(data []byte)
- func (record *DicRecord) SetFloatVal(a float64)
- func (record *DicRecord) SetIntVal(a int64)
- func (record *DicRecord) SetOffset(s int)
- func (record *DicRecord) SetSDO(sdo *SDOClient)
- func (record *DicRecord) SetSize(s int)
- func (record *DicRecord) SetStringVal(a string)
- func (record *DicRecord) SetUintVal(a uint64)
- type DicVariable
- func (variable *DicVariable) AddBitDefinition(name string, bits []byte)
- func (variable *DicVariable) AddMember(object DicObject)
- func (variable *DicVariable) AddValueDescription(name string, des string)
- func (variable *DicVariable) FindIndex(index uint16) DicObject
- func (variable *DicVariable) FindName(name string) DicObject
- func (variable *DicVariable) GetBoolVal() *bool
- func (variable *DicVariable) GetByteVal() *byte
- func (variable *DicVariable) GetData() []byte
- func (variable *DicVariable) GetDataLen() int
- func (variable *DicVariable) GetDataType() byte
- func (variable *DicVariable) GetFloatVal() *float64
- func (variable *DicVariable) GetIndex() uint16
- func (variable *DicVariable) GetIntVal() *int64
- func (variable *DicVariable) GetName() string
- func (variable *DicVariable) GetOffset() int
- func (variable *DicVariable) GetStringVal() *string
- func (variable *DicVariable) GetSubIndex() uint8
- func (variable *DicVariable) GetUintVal() *uint64
- func (variable *DicVariable) IsDicVariable() bool
- func (variable *DicVariable) IsDomainDataType() bool
- func (variable *DicVariable) Read() error
- func (variable *DicVariable) Save() error
- func (variable *DicVariable) SetBoolVal(a bool)
- func (variable *DicVariable) SetByteVal(a byte)
- func (variable *DicVariable) SetData(data []byte)
- func (variable *DicVariable) SetFloatVal(a float64)
- func (variable *DicVariable) SetIntVal(a int64)
- func (variable *DicVariable) SetOffset(s int)
- func (variable *DicVariable) SetSDO(sdo *SDOClient)
- func (variable *DicVariable) SetSize(s int)
- func (variable *DicVariable) SetStringVal(a string)
- func (variable *DicVariable) SetUintVal(a uint64)
- func (variable *DicVariable) Write(data []byte) error
- type NMTMaster
- func NewNMTMaster(nodeID int, network *Network) *NMTMaster
- func (master *NMTMaster) GetStateString() string
- func (master *NMTMaster) ListenForHeartbeat() error
- func (master *NMTMaster) SendCommand(code int) error
- func (master *NMTMaster) SetState(cmd string) error
- func (master *NMTMaster) UnlistenForHeartbeat() error
- func (master *NMTMaster) WaitForBootup(timeout *time.Duration) error
- type Network
- func NewNetwork(bus can.Bus) (*Network, error)
- func (network *Network) AcquireFramesChan(filterFunc networkFramesChanFilterFunc) *NetworkFramesChan
- func (network *Network) AddNode(node *Node, objectDic *DicObjectDic, uploadEDS bool) *Node
- func (network *Network) GetNode(nodeID int) (*Node, error)
- func (network *Network) ReleaseFramesChan(id string)
- func (network *Network) Run() error
- func (network *Network) Search(limit int, timeout time.Duration) ([]*Node, error)
- func (network *Network) Send(arbID uint32, data []byte) error
- func (network *Network) Stop() error
- type NetworkFramesChan
- type Node
- type PDOMap
- func NewPDOMap(pdoNode *PDONode, comRecord, mapArray DicObject) *PDOMap
- func (m *PDOMap) AcquireChangesChan() *PDOMapChangeChan
- func (m *PDOMap) FindIndex(idx int) DicObject
- func (m *PDOMap) FindName(name string) DicObject
- func (m *PDOMap) GetTotalSize() int
- func (m *PDOMap) Listen() error
- func (m *PDOMap) Read() error
- func (m *PDOMap) RebuildData()
- func (m *PDOMap) ReleaseChangesChan(id string) error
- func (m *PDOMap) Save() error
- func (m *PDOMap) SetData(data []byte)
- func (m *PDOMap) Transmit(rebuild bool) error
- func (m *PDOMap) Unlisten()
- func (m *PDOMap) UpdateDataSize()
- type PDOMapChangeChan
- type PDOMaps
- type PDONode
- type SDOClient
- func NewSDOClient(node *Node) *SDOClient
- func (sdoClient *SDOClient) FindName(name string) DicObject
- func (sdoClient *SDOClient) Read(index uint16, subIndex uint8) ([]byte, error)
- func (sdoClient *SDOClient) Send( req []byte, expectFunc networkFramesChanFilterFunc, timeout *time.Duration, retryCount *int, ) (*can.Frame, error)
- func (sdoClient *SDOClient) SendRequest(req []byte) error
- func (sdoClient *SDOClient) Write(index uint16, subIndex uint8, forceSegment bool, data []byte) error
- type SDOReader
- type SDOWriter
const (
DicVar byte = 0x07
DicArr byte = 0x08
DicRec byte = 0x09
)const (
Boolean byte = 0x1
Integer8 byte = 0x2
Integer16 byte = 0x3
Integer32 byte = 0x4
Integer64 byte = 0x15
Unsigned8 byte = 0x5
Unsigned16 byte = 0x6
Unsigned32 byte = 0x7
Unsigned64 byte = 0x1b
Real32 byte = 0x8
Real64 byte = 0x11
VisibleString byte = 0x9
OctetString byte = 0xa
UnicodeString byte = 0xb
Domain byte = 0xf
)const (
MapPDONotValid int64 = 1 << 31
MapRTRNotAllowed int = 1 << 30
)const (
SDORequestUpload uint8 = 2 << 5
SDOResponseUpload uint8 = 2 << 5
SDORequestDownload uint8 = 1 << 5
SDOResponseDownload uint8 = 3 << 5
SDORequestSegmentUpload uint8 = 3 << 5
SDOResponseSegmentUpload uint8 = 0 << 5
SDORequestSegmentDownload uint8 = 0 << 5
SDOResponseSegmentDownload uint8 = 1 << 5
SDOExpedited uint8 = 0x2
SDOSizeSpecified uint8 = 0x1
SDOToggleBit uint8 = 0x10
SDONoMoreData uint8 = 0x1
)var NMTCommandToState = map[int]int{
1: 5,
2: 4,
80: 80,
96: 96,
128: 127,
129: 0,
130: 0,
}var NMTCommands = map[string]int{
"OPERATIONAL": 1,
"STOPPED": 2,
"SLEEP": 80,
"STANDBY": 96,
"PRE-OPERATIONAL": 128,
"INITIALISING": 129,
"RESET": 129,
"RESET COMMUNICATION": 130,
}var NMTStates = map[int]string{
0: "INITIALISING",
4: "STOPPED",
5: "OPERATIONAL",
80: "SLEEP",
96: "STANDBY",
127: "PRE-OPERATIONAL",
}func IsDataType
func IsDataType(t byte) boolfunc IsFloatType
func IsFloatType(t byte) boolfunc IsIntegerType
func IsIntegerType(t byte) boolfunc IsNumberType
func IsNumberType(t byte) boolfunc IsSignedType
func IsSignedType(t byte) boolfunc IsStringType
func IsStringType(t byte) boolfunc IsUnsignedType
func IsUnsignedType(t byte) booltype DicArray
type DicArray struct {
Description string
Index uint16
Name string
SDOClient *SDOClient
SubIndexes map[uint8]DicObject
SubNames map[string]uint8
}func (*DicArray) AddMember
func (array *DicArray) AddMember(object DicObject)AddMember to SubIndexes
func (*DicArray) FindIndex
func (array *DicArray) FindIndex(index uint16) DicObjectfunc (*DicArray) FindName
func (array *DicArray) FindName(name string) DicObjectfunc (*DicArray) GetBoolVal
func (array *DicArray) GetBoolVal() *boolfunc (*DicArray) GetByteVal
func (array *DicArray) GetByteVal() *bytefunc (*DicArray) GetData
func (array *DicArray) GetData() []bytefunc (*DicArray) GetDataLen
func (array *DicArray) GetDataLen() intfunc (*DicArray) GetDataType
func (array *DicArray) GetDataType() bytefunc (*DicArray) GetFloatVal
func (array *DicArray) GetFloatVal() *float64func (*DicArray) GetIndex
func (array *DicArray) GetIndex() uint16func (*DicArray) GetIntVal
func (array *DicArray) GetIntVal() *int64func (*DicArray) GetName
func (array *DicArray) GetName() stringfunc (*DicArray) GetOffset
func (array *DicArray) GetOffset() intfunc (*DicArray) GetStringVal
func (array *DicArray) GetStringVal() *stringfunc (*DicArray) GetSubIndex
func (array *DicArray) GetSubIndex() uint8func (*DicArray) GetUintVal
func (array *DicArray) GetUintVal() *uint64func (*DicArray) IsDicVariable
func (array *DicArray) IsDicVariable() boolfunc (*DicArray) Read
func (array *DicArray) Read() errorfunc (*DicArray) Save
func (array *DicArray) Save() errorfunc (*DicArray) SetBoolVal
func (array *DicArray) SetBoolVal(a bool)func (*DicArray) SetByteVal
func (array *DicArray) SetByteVal(a byte)func (*DicArray) SetData
func (array *DicArray) SetData(data []byte)func (*DicArray) SetFloatVal
func (array *DicArray) SetFloatVal(a float64)func (*DicArray) SetIntVal
func (array *DicArray) SetIntVal(a int64)func (*DicArray) SetOffset
func (array *DicArray) SetOffset(s int)func (*DicArray) SetSDO
func (array *DicArray) SetSDO(sdo *SDOClient)func (*DicArray) SetSize
func (array *DicArray) SetSize(s int)func (*DicArray) SetStringVal
func (array *DicArray) SetStringVal(a string)func (*DicArray) SetUintVal
func (array *DicArray) SetUintVal(a uint64)type DicObject
type DicObject interface {
GetIndex() uint16
GetSubIndex() uint8
GetName() string
AddMember(DicObject)
FindIndex(uint16) DicObject
FindName(string) DicObject
GetDataType() byte
GetDataLen() int
SetSize(int)
SetOffset(int)
GetOffset() int
Read() error
Save() error
GetData() []byte
SetData([]byte)
GetStringVal() *string
GetFloatVal() *float64
GetUintVal() *uint64
GetIntVal() *int64
GetBoolVal() *bool
GetByteVal() *byte
SetStringVal(string)
SetFloatVal(float64)
SetUintVal(uint64)
SetIntVal(int64)
SetBoolVal(bool)
SetByteVal(byte)
IsDicVariable() bool
SetSDO(*SDOClient)
}type DicObjectDic
type DicObjectDic struct {
Baudrate int
NodeID int
// Map of Object ids to objects
Indexes map[uint16]DicObject
// Index to map objects names to objects indexs
NamesIndex map[string]uint16
}func DicEDSParse
func DicEDSParse(in interface{}) (*DicObjectDic, error)DicEDSParse If in is string, it must be a path to a file else if in must be eds data as []byte
func DicMustParse
func DicMustParse(a *DicObjectDic, err error) *DicObjectDicfunc NewDicObjectDic
func NewDicObjectDic() *DicObjectDicfunc (*DicObjectDic) AddObject
func (objectDic *DicObjectDic) AddObject(object DicObject)func (*DicObjectDic) FindIndex
func (objectDic *DicObjectDic) FindIndex(index uint16) DicObjectfunc (*DicObjectDic) FindName
func (objectDic *DicObjectDic) FindName(name string) DicObjecttype DicRecord
type DicRecord struct {
Description string
Index uint16
Name string
SDOClient *SDOClient
SubIndexes map[uint8]DicObject
SubNames map[string]uint8
}func (*DicRecord) AddMember
func (record *DicRecord) AddMember(object DicObject)AddMember to DicRecord
func (*DicRecord) FindIndex
func (record *DicRecord) FindIndex(index uint16) DicObjectFindIndex find by index a DicObject in DicRecord
func (*DicRecord) FindName
func (record *DicRecord) FindName(name string) DicObjectFindName find by name a DicObject in DicRecord
func (*DicRecord) GetBoolVal
func (record *DicRecord) GetBoolVal() *boolfunc (*DicRecord) GetByteVal
func (record *DicRecord) GetByteVal() *bytefunc (*DicRecord) GetData
func (record *DicRecord) GetData() []bytefunc (*DicRecord) GetDataLen
func (record *DicRecord) GetDataLen() intfunc (*DicRecord) GetDataType
func (record *DicRecord) GetDataType() bytefunc (*DicRecord) GetFloatVal
func (record *DicRecord) GetFloatVal() *float64func (*DicRecord) GetIndex
func (record *DicRecord) GetIndex() uint16GetIndex of DicRecord
func (*DicRecord) GetIntVal
func (record *DicRecord) GetIntVal() *int64func (*DicRecord) GetName
func (record *DicRecord) GetName() stringGetName of DicRecord
func (*DicRecord) GetOffset
func (record *DicRecord) GetOffset() intfunc (*DicRecord) GetStringVal
func (record *DicRecord) GetStringVal() *stringfunc (*DicRecord) GetSubIndex
func (record *DicRecord) GetSubIndex() uint8GetSubIndex not applicable
func (*DicRecord) GetUintVal
func (record *DicRecord) GetUintVal() *uint64func (*DicRecord) IsDicVariable
func (record *DicRecord) IsDicVariable() boolfunc (*DicRecord) Read
func (record *DicRecord) Read() errorfunc (*DicRecord) Save
func (record *DicRecord) Save() errorfunc (*DicRecord) SetBoolVal
func (record *DicRecord) SetBoolVal(a bool)func (*DicRecord) SetByteVal
func (record *DicRecord) SetByteVal(a byte)func (*DicRecord) SetData
func (record *DicRecord) SetData(data []byte)func (*DicRecord) SetFloatVal
func (record *DicRecord) SetFloatVal(a float64)func (*DicRecord) SetIntVal
func (record *DicRecord) SetIntVal(a int64)func (*DicRecord) SetOffset
func (record *DicRecord) SetOffset(s int)func (*DicRecord) SetSDO
func (record *DicRecord) SetSDO(sdo *SDOClient)SetSDO to DicRecord
func (*DicRecord) SetSize
func (record *DicRecord) SetSize(s int)func (*DicRecord) SetStringVal
func (record *DicRecord) SetStringVal(a string)func (*DicRecord) SetUintVal
func (record *DicRecord) SetUintVal(a uint64)type DicVariable
type DicVariable struct {
Unit string
Factor int
Min int
Max int
Default []byte
DataType byte
AccessType string
Description string
SDOClient *SDOClient
Data []byte
Offset int
Size int
Index uint16
SubIndex uint8
Name string
ValueDescriptions map[string]string
BitDefinitions map[string][]byte
}func (*DicVariable) AddBitDefinition
func (variable *DicVariable) AddBitDefinition(name string, bits []byte)func (*DicVariable) AddMember
func (variable *DicVariable) AddMember(object DicObject)func (*DicVariable) AddValueDescription
func (variable *DicVariable) AddValueDescription(name string, des string)func (*DicVariable) FindIndex
func (variable *DicVariable) FindIndex(index uint16) DicObjectfunc (*DicVariable) FindName
func (variable *DicVariable) FindName(name string) DicObjectfunc (*DicVariable) GetBoolVal
func (variable *DicVariable) GetBoolVal() *boolfunc (*DicVariable) GetByteVal
func (variable *DicVariable) GetByteVal() *bytefunc (*DicVariable) GetData
func (variable *DicVariable) GetData() []bytefunc (*DicVariable) GetDataLen
func (variable *DicVariable) GetDataLen() intfunc (*DicVariable) GetDataType
func (variable *DicVariable) GetDataType() bytefunc (*DicVariable) GetFloatVal
func (variable *DicVariable) GetFloatVal() *float64func (*DicVariable) GetIndex
func (variable *DicVariable) GetIndex() uint16func (*DicVariable) GetIntVal
func (variable *DicVariable) GetIntVal() *int64func (*DicVariable) GetName
func (variable *DicVariable) GetName() stringfunc (*DicVariable) GetOffset
func (variable *DicVariable) GetOffset() intfunc (*DicVariable) GetStringVal
func (variable *DicVariable) GetStringVal() *stringfunc (*DicVariable) GetSubIndex
func (variable *DicVariable) GetSubIndex() uint8func (*DicVariable) GetUintVal
func (variable *DicVariable) GetUintVal() *uint64func (*DicVariable) IsDicVariable
func (variable *DicVariable) IsDicVariable() boolfunc (*DicVariable) IsDomainDataType
func (variable *DicVariable) IsDomainDataType() boolfunc (*DicVariable) Read
func (variable *DicVariable) Read() errorRead variable value using SDO
func (*DicVariable) Save
func (variable *DicVariable) Save() errorSave variable.Data using SDO
func (*DicVariable) SetBoolVal
func (variable *DicVariable) SetBoolVal(a bool)func (*DicVariable) SetByteVal
func (variable *DicVariable) SetByteVal(a byte)func (*DicVariable) SetData
func (variable *DicVariable) SetData(data []byte)func (*DicVariable) SetFloatVal
func (variable *DicVariable) SetFloatVal(a float64)func (*DicVariable) SetIntVal
func (variable *DicVariable) SetIntVal(a int64)func (*DicVariable) SetOffset
func (variable *DicVariable) SetOffset(s int)func (*DicVariable) SetSDO
func (variable *DicVariable) SetSDO(sdo *SDOClient)func (*DicVariable) SetSize
func (variable *DicVariable) SetSize(s int)func (*DicVariable) SetStringVal
func (variable *DicVariable) SetStringVal(a string)func (*DicVariable) SetUintVal
func (variable *DicVariable) SetUintVal(a uint64)func (*DicVariable) Write
func (variable *DicVariable) Write(data []byte) errorWrite variable value using SDO
type NMTMaster
type NMTMaster struct {
NodeID int
Network *Network
State int
StateReceived *int
Timestamp *time.Time
Listening bool
// contains filtered or unexported fields
}func NewNMTMaster
func NewNMTMaster(nodeID int, network *Network) *NMTMasterNewNMTMaster return a new instance of Master
func (*NMTMaster) GetStateString
func (master *NMTMaster) GetStateString() stringGetStateString for target node
func (*NMTMaster) ListenForHeartbeat
func (master *NMTMaster) ListenForHeartbeat() errorListenForHeartbeat listen message on network
func (*NMTMaster) SendCommand
func (master *NMTMaster) SendCommand(code int) errorSendCommand to target node
func (*NMTMaster) SetState
func (master *NMTMaster) SetState(cmd string) errorSetState for target node, and send command
func (*NMTMaster) UnlistenForHeartbeat
func (master *NMTMaster) UnlistenForHeartbeat() errorUnlistenForHeartbeat listen message on network
func (*NMTMaster) WaitForBootup
func (master *NMTMaster) WaitForBootup(timeout *time.Duration) errorWaitForBootup return when the node has *StateReceived == 0 with a default timeout of 10s
type Network
Network represent the global nodes network
type Network struct {
// mutex for FramesChans access
sync.Mutex
// Bus is the go-can bus
Bus can.Bus
// Nodes contain the network nodes
Nodes map[int]*Node
// FramesChans contains a list of chan when is sent each frames from network bus.
FramesChans []*NetworkFramesChan
// NMTMaster contain nmt control struct
NMTMaster *NMTMaster
// BusReadErrChan @TODO on go-can
BusReadErrChan chan error
// contains filtered or unexported fields
}func NewNetwork
func NewNetwork(bus can.Bus) (*Network, error)NewNetwork a new Network with given bus
func (*Network) AcquireFramesChan
func (network *Network) AcquireFramesChan(filterFunc networkFramesChanFilterFunc) *NetworkFramesChanAcquireFramesChan create a new FrameChan
func (*Network) AddNode
func (network *Network) AddNode(node *Node, objectDic *DicObjectDic, uploadEDS bool) *NodeAddNode add a node to the network
func (*Network) GetNode
func (network *Network) GetNode(nodeID int) (*Node, error)GetNode by node id. Return error if node dont exist in network.Nodes
func (*Network) ReleaseFramesChan
func (network *Network) ReleaseFramesChan(id string)ReleaseFramesChan release (close) a FrameChan
func (*Network) Run
func (network *Network) Run() errorRun listen handlers for frames on bus
func (*Network) Search
func (network *Network) Search(limit int, timeout time.Duration) ([]*Node, error)Search send data to network and wait for nodes response
func (*Network) Send
func (network *Network) Send(arbID uint32, data []byte) errorSend a frame on network
func (*Network) Stop
func (network *Network) Stop() errorStop handlers for frames on bus
type NetworkFramesChan
NetworkFramesChan contain a Chan, and ID and a Filter function Each FrameChan can have a filter function which return a boolean, and for each frame, the filter func is called. If func return true, the frame is returned, else dont send frame.
type NetworkFramesChan struct {
ID string
C chan *can.Frame
Filter networkFramesChanFilterFunc
}func (*NetworkFramesChan) Publish
func (networkFramesCh *NetworkFramesChan) Publish(frm *can.Frame)type Node
Node is a canopen node
type Node struct {
// Each node has an id, which is ArbitrationID & 0x7F
ID int
Network *Network
ObjectDic *DicObjectDic
SDOClient *SDOClient
PDONode *PDONode
NMTMaster *NMTMaster
}func NewNode
func NewNode(id int, network *Network, objectDic *DicObjectDic) *Nodefunc (*Node) Init
func (node *Node) Init()Init create sdo clients, pdo nodes, nmt master
func (*Node) SetNetwork
func (node *Node) SetNetwork(network *Network)SetNetwork set node.Network to the desired network
func (*Node) SetObjectDic
func (node *Node) SetObjectDic(objectDic *DicObjectDic)SetObjectDic set node.ObjectDic to the desired ObjectDic
func (*Node) Stop
func (node *Node) Stop()Stop node
type PDOMap
type PDOMap struct {
sync.Mutex
PDONode *PDONode
ComRecord DicObject
MapArray DicObject
Enabled bool
CobID int
RTRAllowed bool
TransType byte
EventTimer byte
Map map[int]DicObject
OldData []byte
Data []byte
Timestamp *time.Time
Period *time.Duration
IsReceived bool
ChangeChans []*PDOMapChangeChan
// contains filtered or unexported fields
}func NewPDOMap
func NewPDOMap(pdoNode *PDONode, comRecord, mapArray DicObject) *PDOMapNewPDOMap return a PDOMap initialized
func (*PDOMap) AcquireChangesChan
func (m *PDOMap) AcquireChangesChan() *PDOMapChangeChanAcquireChangesChan create a new PDOMapChangeChan
func (*PDOMap) FindIndex
func (m *PDOMap) FindIndex(idx int) DicObjectFindIndex find a object by index
func (*PDOMap) FindName
func (m *PDOMap) FindName(name string) DicObjectFindName find a object by name
func (*PDOMap) GetTotalSize
func (m *PDOMap) GetTotalSize() intGetTotalSize of a map
func (*PDOMap) Listen
func (m *PDOMap) Listen() errorListen for changes on map from network
func (*PDOMap) Read
func (m *PDOMap) Read() errorRead map values
func (*PDOMap) RebuildData
func (m *PDOMap) RebuildData()RebuildData rebuild map data object from map variables
func (*PDOMap) ReleaseChangesChan
func (m *PDOMap) ReleaseChangesChan(id string) errorReleaseChangesChan release (close) a PDOMapChangeChan
func (*PDOMap) Save
func (m *PDOMap) Save() errorSave pdo map @TODO: Not Working, DO NOT USE
func (*PDOMap) SetData
func (m *PDOMap) SetData(data []byte)func (*PDOMap) Transmit
func (m *PDOMap) Transmit(rebuild bool) errorTransmit map data
func (*PDOMap) Unlisten
func (m *PDOMap) Unlisten()Unlisten for changes on map from network
func (*PDOMap) UpdateDataSize
func (m *PDOMap) UpdateDataSize()type PDOMapChangeChan
type PDOMapChangeChan struct {
ID string
C chan []byte
}type PDOMaps
PDOMaps define a PDO map
type PDOMaps struct {
PDONode *PDONode
Maps map[int]*PDOMap
}func NewPDOMaps
func NewPDOMaps(comOffset, mapOffset int, pdoNode *PDONode) *PDOMapsNewPDOMaps create a new Maps
func (*PDOMaps) FindIndex
func (maps *PDOMaps) FindIndex(idx int) *PDOMapFindIndex a map by index
func (*PDOMaps) FindName
func (maps *PDOMaps) FindName(name string) *PDOMapFindName a map
type PDONode
type PDONode struct {
Node *Node
RX *PDOMaps
TX *PDOMaps
}func NewPDONode
func NewPDONode(n *Node) *PDONodefunc (*PDONode) FindName
func (node *PDONode) FindName(name string) *PDOMapfunc (*PDONode) Read
func (node *PDONode) Read() errorfunc (*PDONode) Save
func (node *PDONode) Save() errortype SDOClient
SDOClient represent an SDO client
type SDOClient struct {
Node *Node
RXCobID uint32
TXCobID uint32
SendQueue []string
}func NewSDOClient
func NewSDOClient(node *Node) *SDOClientfunc (*SDOClient) FindName
func (sdoClient *SDOClient) FindName(name string) DicObjectFindName find an sdo object from object dictionary by name
func (*SDOClient) Read
func (sdoClient *SDOClient) Read(index uint16, subIndex uint8) ([]byte, error)Read sdo
func (*SDOClient) Send
func (sdoClient *SDOClient) Send(
req []byte,
expectFunc networkFramesChanFilterFunc,
timeout *time.Duration,
retryCount *int,
) (*can.Frame, error)Send message and optionaly wait for response
func (*SDOClient) SendRequest
func (sdoClient *SDOClient) SendRequest(req []byte) errorSendRequest to network bus
func (*SDOClient) Write
func (sdoClient *SDOClient) Write(index uint16, subIndex uint8, forceSegment bool, data []byte) errorWrite sdo
type SDOReader
type SDOReader struct {
SDOClient *SDOClient
Index uint16
SubIndex uint8
Toggle uint8
Pos int
Size uint32
Data []byte
}func NewSDOReader
func NewSDOReader(sdoClient *SDOClient, index uint16, subIndex uint8) *SDOReaderfunc (*SDOReader) Read
func (reader *SDOReader) Read() (*can.Frame, error)Read segmented uploads
func (*SDOReader) ReadAll
func (reader *SDOReader) ReadAll() ([]byte, error)ReadAll ..
func (*SDOReader) RequestUpload
func (reader *SDOReader) RequestUpload() ([]byte, error)RequestUpload returns data if EXPEDITED, else nil
type SDOWriter
type SDOWriter struct {
SDOClient *SDOClient
Index uint16
SubIndex uint8
Done bool
Toggle uint8
Pos int
Size uint32
ForceSegment bool
}func NewSDOWriter
func NewSDOWriter(sdoClient *SDOClient, index uint16, subIndex uint8, forceSegment bool) *SDOWriterfunc (*SDOWriter) RequestDownload
func (writer *SDOWriter) RequestDownload(data []byte) errorRequestDownload returns data if EXPEDITED, else nil
func (*SDOWriter) Write
func (writer *SDOWriter) Write(data []byte) errorWrite data to sdo client
Generated by gomarkdoc