Documentation
¶
Index ¶
- Constants
- Variables
- func Marshal(frm Frame) (b []byte, err error)
- func Unmarshal(b []byte, frm *Frame) (err error)
- func Wait(bus *Bus, id uint32, timeout time.Duration) <-chan WaitResponse
- type Bus
- func (b *Bus) ConnectAndPublish() error
- func (b *Bus) DeleteFilter() error
- func (b *Bus) Disconnect() error
- func (b *Bus) Publish(frame Frame) error
- func (b *Bus) PublishLocal(frame Frame)
- func (b *Bus) PublishMinDuration(frame Frame, min time.Duration) error
- func (b *Bus) Reconnect() error
- func (b *Bus) SetBlockFilter(diallowedIds []uint32) error
- func (b *Bus) SetPassFilter(allowedIds []uint32) error
- func (b *Bus) Subscribe(handler Handler)
- func (b *Bus) SubscribeFunc(fn HandlerFunc)
- func (b *Bus) Unsubscribe(handler Handler)
- type Frame
- type Handler
- type HandlerFunc
- type ReadWriteCloser
- type Reader
- type WaitResponse
- type Writer
Constants ¶
const ( // MaxFrameDataLength defines the max length of a CAN data frame defined in ISO 11898-1. MaxFrameDataLength = 8 // MaxExtFrameDataLength defines the max length of an CAN extended data frame defined in ISO ISO 11898-7. MaxExtFrameDataLength = 64 )
Variables ¶
var ErrorKernelFilterNotSupported = errors.New("not possible to set kernel filter")
ErrorKernelFilterNotSupported is returned if the socket attribute is 0. Then the method setsockopt can't be called.
var ErrorKernelFilterTooMany = errors.New("too many kernel filters")
Functions ¶
Types ¶
type Bus ¶
type Bus struct {
// contains filtered or unexported fields
}
Bus represents the CAN bus. Handlers can subscribe to receive frames. Frame are sent using the *Publish* method.
func NewBusForInterfaceWithName ¶
NewBusForInterfaceWithName returns a bus from the network interface with name ifaceName.
func (*Bus) ConnectAndPublish ¶
ConnectAndPublish starts handling CAN frames to publish them to handlers.
func (*Bus) DeleteFilter ¶
DeleteFilter deltes all kernel filter.
func (*Bus) Publish ¶
Publish publishes a frame on the bus.
Frames published with the Publish methods are not received by handlers.
func (*Bus) PublishLocal ¶ added in v0.0.9
PublishLocal publishes a frame to handlers
Frames published with the PublishLocal method are ONLY received by handlers.
func (*Bus) PublishMinDuration ¶ added in v0.1.5
func (*Bus) SetBlockFilter ¶ added in v0.1.0
SetFilter set's can filter on kernel level. This has the advantage that the application is doesn't need to receive all frames to filter the interesting out.
func (*Bus) SetPassFilter ¶ added in v0.1.0
SetFilter set's can filter on kernel level. This has the advantage that the application is doesn't need to receive all frames to filter the interesting out.
func (*Bus) SubscribeFunc ¶
func (b *Bus) SubscribeFunc(fn HandlerFunc)
SubscribeFunc adds a function as handler.
type Frame ¶
type Frame struct { // bit 0-28: CAN identifier (11/29 bit) // bit 29: error message flag (ERR) // bit 30: remote transmision request (RTR) // bit 31: extended frame format (EFF) ID uint32 Length uint8 Flags uint8 Res0 uint8 Res1 uint8 Data [MaxFrameDataLength]uint8 }
Frame represents a standard CAN data frame
type Handler ¶
type Handler interface {
Handle(frame Frame)
}
The Handler interfaces defines a method to receive a frame.
func NewHandler ¶
func NewHandler(fn HandlerFunc) Handler
NewHandler returns a new handler which calls fn when a frame is received.
type HandlerFunc ¶
type HandlerFunc func(frame Frame)
HandlerFunc defines the function type to handle a frame.
type ReadWriteCloser ¶
type ReadWriteCloser interface { Reader Writer io.Closer // contains filtered or unexported methods }
The ReadWriteCloser interface combines the Reader and Writer and `io.Closer` interface.
func NewReadWriteCloser ¶
func NewReadWriteCloser(rwc io.ReadWriteCloser) ReadWriteCloser
NewReadWriteCloser returns a ReadWriteCloser for an `io.ReadWriteCloser`.
func NewReadWriteCloserForInterface ¶
func NewReadWriteCloserForInterface(i *net.Interface) (ReadWriteCloser, error)
type WaitResponse ¶
A WaitResponse encapsulates the response of waiting for a frame.