Documentation ¶
Index ¶
- Constants
- Variables
- func Marshal(frm Frame) (b []byte, err error)
- func Produce(frame Frame, bus *can.Bus, timeout time.Duration) chan<- struct{}
- func ProduceHeartbeat(nodeID uint8, state uint8, bus *can.Bus, timeout time.Duration) chan<- struct{}
- func Unmarshal(b []byte, frm *Frame) error
- type Client
- type Frame
- type Index
- type ObjectIndex
- type Request
- type Response
Constants ¶
const ( MessageTypeNMT uint16 = 0x000 MessageTypeSync uint16 = 0x080 MessageTypeTimestamp uint16 = 0x100 MessageTypeTPDO1 uint16 = 0x180 MessageTypeRPDO1 uint16 = 0x200 MessageTypeTPDO2 uint16 = 0x280 MessageTypeRPDO2 uint16 = 0x300 MessageTypeTPDO3 uint16 = 0x380 MessageTypeRPDO3 uint16 = 0x400 MessageTypeTPDO4 uint16 = 0x480 MessageTypeRPDO4 uint16 = 0x500 // MessageTypeTSDO represents the type of SDO server response messages MessageTypeTSDO uint16 = 0x580 // MessageTypeRSDO represents the type of SDO client request messages MessageTypeRSDO uint16 = 0x600 MessageTypeHeartbeat uint16 = 0x700 )
const ( // MaskCobID is used to get 11 bits from an uint16 for the COB-ID MaskCobID = 0x7FF // MaskNodeID is used to extract the 7-bit node id from the COB-ID MaskNodeID = 0x7F // MaskMessageType is used to extract the 4-bit message type from the COB-ID MaskMessageType = 0x780 )
const ( GoToOperational uint8 = 0x1 GoToStopped uint8 = 0x2 GoToPreOperation uint8 = 0x80 GoToResetNode uint8 = 0x81 GoToResetCommunication uint8 = 0x82 )
const ( BootUp uint8 = 0x0 Stopped uint8 = 0x04 Operational uint8 = 0x05 PreOperational uint8 = 0x7f )
const MaxNodeID uint8 = 0x7F
MaxNodeID defines the highest node id
Variables ¶
var RefDate = time.Date( 1984, 1, 1, 0, 0, 0, 0, time.UTC, )
RefDate is the reference date of CAN timestamp messages.
Functions ¶
func Produce ¶
Produce repeatedly sends a frame on a bus after a timeout. The sending can be stopped by using the returned channel.
Types ¶
type Client ¶
A Client handles message communication by sending a request and waiting for the response.
type Frame ¶
type Frame struct { // CobID is the 11-bit communication object identifier – CANopen only uses 11-bit identifiers. // Bits 0-6 represent the 7-bit node ID. Bits 7-11 represent the 4-bit message type. CobID uint16 // Rtr represents the Remote Transmit Request flag. Rtr bool // Data contains 8 bytes Data []uint8 }
A Frame represents a CANopen frame.
func CANopenFrame ¶
CANopenFrame returns a CANopen frame from a CAN frame.
func NewHeartbeatFrame ¶
NewHeartbeatFrame returns a new CANopen heartbeat frame containing the node id and state.
func (Frame) CANFrame ¶
CANFrame returns a CAN frame representing the CANopen frame.
CANopen frames are encoded as follows:
------------------------------------------------------- CAN | ID | Length | Flags | Res0 | Res1 | Data | ------------------------------------------------------- CANopen | COB-ID + Rtr | len(Data) | | | | Data | -------------------------------------------------------
func (Frame) MessageType ¶
MessageType returns the message type.
type ObjectIndex ¶
ObjectIndex represents the index of an object.
func NewObjectIndex ¶
func NewObjectIndex(index uint16, subIndex uint8) ObjectIndex
NewObjectIndex returns an object index from a 2-byte index and 1-byte sub index.
type Request ¶
type Request struct { // The Frame of the request Frame Frame // The ResponseID of the response frame ResponseID uint32 }
A Request represents a CANopen request published on a CAN bus and received by another CANopen node.
func NewRequest ¶
NewRequest returns a request containing the frame to be sent and the expected response frame id.