canbus

package
v0.0.0-...-f549e0c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package canbus provides high-level access to CAN bus sockets.

A typical usage might look like:

sck, err := canbus.New()
err = sck.Bind("vcan0")
for {
    msg, err := sck.Recv()
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Frame

type Frame struct {
	ID   uint32
	Data []byte
	Kind Kind
}

Frame is exchanged over a CAN bus.

type Kind

type Kind uint8
const (
	SFF     Kind = iota // Standard frame format
	EFF                 // Extended frame format
	RTR_SFF             // Remote transmission request, SFF
	RTR_EFF             // Remote transmission request, EFF
	ERR                 // Error message frame
)

type Socket

type Socket struct {
	// contains filtered or unexported fields
}

Socket is a high-level representation of a CANBus socket.

func New

func New() (*Socket, error)

New returns a new CAN bus socket.

func (*Socket) Bind

func (sck *Socket) Bind(addr string) error

Bind binds the socket on the CAN bus with the given address.

Example:

err = sck.Bind("vcan0")

func (*Socket) Close

func (sck *Socket) Close() error

Close closes the CAN bus socket.

func (*Socket) Name

func (sck *Socket) Name() string

Name returns the device name the socket is bound to.

func (*Socket) Recv

func (sck *Socket) Recv() (msg Frame, err error)

Recv receives data from the CAN socket.

func (*Socket) Send

func (sck *Socket) Send(msg Frame) (int, error)

Send sends the provided frame on the CAN bus.

func (*Socket) SetFilters

func (sck *Socket) SetFilters(filters []unix.CanFilter) error

SetFilters sets the CAN_RAW_FILTER option and applies the provided filters to the underlying socket.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳