Categorygithub.com/sitec-systems/can
modulepackage
0.1.1
Repository: https://github.com/sitec-systems/can.git
Documentation: pkg.go.dev

# README

can

Origin

The project was originally created by brutella.

can provides an interface to a CAN bus to read and write frames. The library is based on the SocketCAN network stack on Linux.

##Usage

Setup the CAN bus

bus, _ := can.NewBusForInterfaceWithName("can0")
bus.ConnectAndPublish()

Send a CAN frame

frm := can.Frame{
	ID:     0x701,
	Length: 1,
	Flags:  0,
	Res0:   0,
	Res1:   0,
	Data:   [8]uint8{0x05},
}

bus.Publish(frm)

Receive a CAN frame

bus.SubscribeFunc(handleCANFrame)

func handleCANFrame(frm can.Frame) {    
    ...
}

There is more to learn from the documentation.

License

can is available under the MIT license. See the LICENSE file for more info.

# Packages

This program logs can frames to the console similar to candump from can-utils[1].

# Functions

Marshal returns the byte encoding of frm.
NewBus returns a new CAN bus.
NewBusForInterfaceWithName returns a bus from the network interface with name ifaceName.
NewEchoReadWriteCloser returns a ReadWriteCloser which echoes received bytes.
NewHandler returns a new handler which calls fn when a frame is received.
NewReadWriteCloser returns a ReadWriteCloser for an `io.ReadWriteCloser`.
No description provided by the author
No description provided by the author
Unmarshal parses the bytes b and stores the result in the value pointed to by frm.
Wait returns a channel, which receives a frame or an error, if the frame with the expected id didn't arrive on time.

# Constants

No description provided by the author
MaskEff is used to extract the eff flag (0 = standard frame, 1 = extended frame) from the frame ID.
MaskErr is used to extract the the error flag (0 = data frame, 1 = error message) from the frame ID.
MaskIDEff is used to extract the valid 29-bit CAN identifier bits from the frame ID of an extended frame format.
MaskIDSff is used to extract the valid 11-bit CAN identifier bits from the frame ID of a standard frame format.
MaskRtr is used to extract the rtr flag (1 = rtr frame) from the frame ID.
MaxExtFrameDataLength defines the max length of an CAN extended data frame defined in ISO ISO 11898-7.
MaxFrameDataLength defines the max length of a CAN data frame defined in ISO 11898-1.

# Variables

ErrorKernelFilterNotSupported is returned if the socket attribute is 0.

# Structs

Bus represents the CAN bus.
Frame represents a standard CAN data frame.
A WaitResponse encapsulates the response of waiting for a frame.

# Interfaces

The Handler interfaces defines a method to receive a frame.
The Reader interface extends the `io.Reader` interface by method to read a frame.
The ReadWriteCloser interface combines the Reader and Writer and `io.Closer` interface.
The Writer interface extends the `io.Writer` interface by method to write a frame.

# Type aliases

HandlerFunc defines the function type to handle a frame.