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-canopen
package 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) bool
func IsFloatType
func IsFloatType(t byte) bool
func IsIntegerType
func IsIntegerType(t byte) bool
func IsNumberType
func IsNumberType(t byte) bool
func IsSignedType
func IsSignedType(t byte) bool
func IsStringType
func IsStringType(t byte) bool
func IsUnsignedType
func IsUnsignedType(t byte) bool
type 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) DicObject
func (*DicArray) FindName
func (array *DicArray) FindName(name string) DicObject
func (*DicArray) GetBoolVal
func (array *DicArray) GetBoolVal() *bool
func (*DicArray) GetByteVal
func (array *DicArray) GetByteVal() *byte
func (*DicArray) GetData
func (array *DicArray) GetData() []byte
func (*DicArray) GetDataLen
func (array *DicArray) GetDataLen() int
func (*DicArray) GetDataType
func (array *DicArray) GetDataType() byte
func (*DicArray) GetFloatVal
func (array *DicArray) GetFloatVal() *float64
func (*DicArray) GetIndex
func (array *DicArray) GetIndex() uint16
func (*DicArray) GetIntVal
func (array *DicArray) GetIntVal() *int64
func (*DicArray) GetName
func (array *DicArray) GetName() string
func (*DicArray) GetOffset
func (array *DicArray) GetOffset() int
func (*DicArray) GetStringVal
func (array *DicArray) GetStringVal() *string
func (*DicArray) GetSubIndex
func (array *DicArray) GetSubIndex() uint8
func (*DicArray) GetUintVal
func (array *DicArray) GetUintVal() *uint64
func (*DicArray) IsDicVariable
func (array *DicArray) IsDicVariable() bool
func (*DicArray) Read
func (array *DicArray) Read() error
func (*DicArray) Save
func (array *DicArray) Save() error
func (*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) *DicObjectDic
func NewDicObjectDic
func NewDicObjectDic() *DicObjectDic
func (*DicObjectDic) AddObject
func (objectDic *DicObjectDic) AddObject(object DicObject)
func (*DicObjectDic) FindIndex
func (objectDic *DicObjectDic) FindIndex(index uint16) DicObject
func (*DicObjectDic) FindName
func (objectDic *DicObjectDic) FindName(name string) DicObject
type 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) DicObject
FindIndex find by index a DicObject in DicRecord
func (*DicRecord) FindName
func (record *DicRecord) FindName(name string) DicObject
FindName find by name a DicObject in DicRecord
func (*DicRecord) GetBoolVal
func (record *DicRecord) GetBoolVal() *bool
func (*DicRecord) GetByteVal
func (record *DicRecord) GetByteVal() *byte
func (*DicRecord) GetData
func (record *DicRecord) GetData() []byte
func (*DicRecord) GetDataLen
func (record *DicRecord) GetDataLen() int
func (*DicRecord) GetDataType
func (record *DicRecord) GetDataType() byte
func (*DicRecord) GetFloatVal
func (record *DicRecord) GetFloatVal() *float64
func (*DicRecord) GetIndex
func (record *DicRecord) GetIndex() uint16
GetIndex of DicRecord
func (*DicRecord) GetIntVal
func (record *DicRecord) GetIntVal() *int64
func (*DicRecord) GetName
func (record *DicRecord) GetName() string
GetName of DicRecord
func (*DicRecord) GetOffset
func (record *DicRecord) GetOffset() int
func (*DicRecord) GetStringVal
func (record *DicRecord) GetStringVal() *string
func (*DicRecord) GetSubIndex
func (record *DicRecord) GetSubIndex() uint8
GetSubIndex not applicable
func (*DicRecord) GetUintVal
func (record *DicRecord) GetUintVal() *uint64
func (*DicRecord) IsDicVariable
func (record *DicRecord) IsDicVariable() bool
func (*DicRecord) Read
func (record *DicRecord) Read() error
func (*DicRecord) Save
func (record *DicRecord) Save() error
func (*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) DicObject
func (*DicVariable) FindName
func (variable *DicVariable) FindName(name string) DicObject
func (*DicVariable) GetBoolVal
func (variable *DicVariable) GetBoolVal() *bool
func (*DicVariable) GetByteVal
func (variable *DicVariable) GetByteVal() *byte
func (*DicVariable) GetData
func (variable *DicVariable) GetData() []byte
func (*DicVariable) GetDataLen
func (variable *DicVariable) GetDataLen() int
func (*DicVariable) GetDataType
func (variable *DicVariable) GetDataType() byte
func (*DicVariable) GetFloatVal
func (variable *DicVariable) GetFloatVal() *float64
func (*DicVariable) GetIndex
func (variable *DicVariable) GetIndex() uint16
func (*DicVariable) GetIntVal
func (variable *DicVariable) GetIntVal() *int64
func (*DicVariable) GetName
func (variable *DicVariable) GetName() string
func (*DicVariable) GetOffset
func (variable *DicVariable) GetOffset() int
func (*DicVariable) GetStringVal
func (variable *DicVariable) GetStringVal() *string
func (*DicVariable) GetSubIndex
func (variable *DicVariable) GetSubIndex() uint8
func (*DicVariable) GetUintVal
func (variable *DicVariable) GetUintVal() *uint64
func (*DicVariable) IsDicVariable
func (variable *DicVariable) IsDicVariable() bool
func (*DicVariable) IsDomainDataType
func (variable *DicVariable) IsDomainDataType() bool
func (*DicVariable) Read
func (variable *DicVariable) Read() error
Read variable value using SDO
func (*DicVariable) Save
func (variable *DicVariable) Save() error
Save 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) error
Write 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) *NMTMaster
NewNMTMaster return a new instance of Master
func (*NMTMaster) GetStateString
func (master *NMTMaster) GetStateString() string
GetStateString for target node
func (*NMTMaster) ListenForHeartbeat
func (master *NMTMaster) ListenForHeartbeat() error
ListenForHeartbeat listen message on network
func (*NMTMaster) SendCommand
func (master *NMTMaster) SendCommand(code int) error
SendCommand to target node
func (*NMTMaster) SetState
func (master *NMTMaster) SetState(cmd string) error
SetState for target node, and send command
func (*NMTMaster) UnlistenForHeartbeat
func (master *NMTMaster) UnlistenForHeartbeat() error
UnlistenForHeartbeat listen message on network
func (*NMTMaster) WaitForBootup
func (master *NMTMaster) WaitForBootup(timeout *time.Duration) error
WaitForBootup 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) *NetworkFramesChan
AcquireFramesChan create a new FrameChan
func (*Network) AddNode
func (network *Network) AddNode(node *Node, objectDic *DicObjectDic, uploadEDS bool) *Node
AddNode 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() error
Run 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) error
Send a frame on network
func (*Network) Stop
func (network *Network) Stop() error
Stop 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) *Node
func (*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) *PDOMap
NewPDOMap return a PDOMap initialized
func (*PDOMap) AcquireChangesChan
func (m *PDOMap) AcquireChangesChan() *PDOMapChangeChan
AcquireChangesChan create a new PDOMapChangeChan
func (*PDOMap) FindIndex
func (m *PDOMap) FindIndex(idx int) DicObject
FindIndex find a object by index
func (*PDOMap) FindName
func (m *PDOMap) FindName(name string) DicObject
FindName find a object by name
func (*PDOMap) GetTotalSize
func (m *PDOMap) GetTotalSize() int
GetTotalSize of a map
func (*PDOMap) Listen
func (m *PDOMap) Listen() error
Listen for changes on map from network
func (*PDOMap) Read
func (m *PDOMap) Read() error
Read 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) error
ReleaseChangesChan release (close) a PDOMapChangeChan
func (*PDOMap) Save
func (m *PDOMap) Save() error
Save 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) error
Transmit 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) *PDOMaps
NewPDOMaps create a new Maps
func (*PDOMaps) FindIndex
func (maps *PDOMaps) FindIndex(idx int) *PDOMap
FindIndex a map by index
func (*PDOMaps) FindName
func (maps *PDOMaps) FindName(name string) *PDOMap
FindName a map
type PDONode
type PDONode struct {
Node *Node
RX *PDOMaps
TX *PDOMaps
}
func NewPDONode
func NewPDONode(n *Node) *PDONode
func (*PDONode) FindName
func (node *PDONode) FindName(name string) *PDOMap
func (*PDONode) Read
func (node *PDONode) Read() error
func (*PDONode) Save
func (node *PDONode) Save() error
type SDOClient
SDOClient represent an SDO client
type SDOClient struct {
Node *Node
RXCobID uint32
TXCobID uint32
SendQueue []string
}
func NewSDOClient
func NewSDOClient(node *Node) *SDOClient
func (*SDOClient) FindName
func (sdoClient *SDOClient) FindName(name string) DicObject
FindName 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) error
SendRequest to network bus
func (*SDOClient) Write
func (sdoClient *SDOClient) Write(index uint16, subIndex uint8, forceSegment bool, data []byte) error
Write 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) *SDOReader
func (*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) *SDOWriter
func (*SDOWriter) RequestDownload
func (writer *SDOWriter) RequestDownload(data []byte) error
RequestDownload returns data if EXPEDITED, else nil
func (*SDOWriter) Write
func (writer *SDOWriter) Write(data []byte) error
Write data to sdo client
Generated by gomarkdoc