canbus

package module
v0.0.0-...-7cd9721 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2022 License: BSD-3-Clause Imports: 6 Imported by: 0

README

canbus

Build Status GoDoc

canbus provides high-level facilities to interact with CAN sockets.

can-dump

can-dump prints data flowing on CAN bus.

Usage of can-dump:

sh> can-dump [options] <CAN interface>
   (use CTRL-C to terminate can-dump)

Examples:

 can-dump vcan0
$> can-dump vcan0
  vcan0  080 00000000  00 DE AD BE EF            |.....|
  vcan0  080 00000000  01 DE AD BE EF            |.....|
  vcan0  080 00000000  02 DE AD BE EF            |.....|
  vcan0  080 00000000  03 DE AD BE EF            |.....|
  vcan0  080 00000000  04 DE AD BE EF            |.....|
  vcan0  080 00000000  05 DE AD BE EF            |.....|
  vcan0  080 00000000  06 DE AD BE EF            |.....|
  vcan0  080 00000000  07 DE AD BE EF            |.....|
  vcan0  080 00000000  08 DE AD BE EF            |.....|
  vcan0  080 00000000  09 DE AD BE EF            |.....|
  vcan0  712 00000000  11 22 33 44 55 66 77 88   |."3DUFW.|
  vcan0  7fa 00000000  DE AD BE EF               |....|
[...]

can-send

can-send sends data on the CAN bus.

Usage of can-send:

sh> can-send [options] <CAN interface> <CAN frame>

where <CAN frame> is of the form: <ID-hex>#<frame data-hex>.

Examples:

 can-send vcan0 f12#1122334455667788
 can-send vcan0 ffa#deadbeef
$> can-dump vcan0 &
$> can-send vcan0 f12#1122334455667788
  vcan0  712 00000000  11 22 33 44 55 66 77 88   |."3DUFW.|
$> can-send vcan0 ffa#deadbeef
  vcan0  7fa 00000000  DE AD BE EF               |....|

References

$> modprobe can
$> modprobe can_raw
$> modprobe vcan

## setup vcan network devices
$> ip link add type vcan
$> ip link add dev vcan0 type vcan
$> ip link set vcan0 up

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 {
    id, data, err := sck.Recv()
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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) ApplyFilters

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

ApplyFilters sets the CAN_RAW_FILTER option of the socket and stores the new filters in the Socket object for use by other methods such as Recv.

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() (id uint32, data []byte, err error)

Recv receives data from the CAN socket. id is the CAN_frame id the data was originated from.

func (*Socket) Send

func (sck *Socket) Send(id uint32, idMask uint32, data []byte) (int, error)

Send sends data with a CAN_frame id to the CAN bus. idMask should be a mask such as unix.CAN_EFF_MASK.

Directories

Path Synopsis
cmd
can-dump
can-dump prints data flowing on CAN bus.
can-dump prints data flowing on CAN bus.
can-send
can-send sends data on the CAN bus.
can-send sends data on the CAN bus.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL