canbus

package
v0.0.0-...-a95a1be Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package canbus is built around the Channel structure, which represents a single canbus channel for sending/receiving CAN frames

Index

Constants

View Source
const DefaultBitRate = 250000

DefaultBitRate is the bitrate that Channel defaults to using.

Variables

This section is empty.

Functions

func GetCanInterfaceNameForSpiDevice

func GetCanInterfaceNameForSpiDevice(spiName string) (string, error)

GetCanInterfaceNameForSpiDevice returns the can interface name (i.e. can0/can1) for a given spi device (i.e. "spi0.0").

Types

type Channel

type Channel struct {
	ChannelOptions ChannelOptions
	// contains filtered or unexported fields
}

Channel represents a single canbus channel for sending/receiving CAN frames

func NewChannel

func NewChannel(ctx context.Context, log *logrus.Logger, ChannelOptions ChannelOptions, opts ...ChannelOption) (*Channel, error)

NewChannel returns a Channel object based on the given options. ChannelOptions are required settings, and then you can optionally add more ChannelOption objects for various optional options.

func (*Channel) Close

func (c *Channel) Close(ctx context.Context) error

Close shuts down the channel

func (*Channel) WriteFrame

func (c *Channel) WriteFrame(frame can.Frame) error

WriteFrame will send a CAN frame to the channel

type ChannelOption

type ChannelOption func(*Channel)

ChannelOption is the type used to apply function options to Channel.

func WithBitRate

func WithBitRate(br int32) ChannelOption

WithBitRate overrides the DefaultBitRate set on Channel.

type ChannelOptions

type ChannelOptions struct {
	CanInterfaceName string
	MessageHandler   can.HandlerFunc
}

ChannelOptions is a type that contains required options on a Channel.

Jump to

Keyboard shortcuts

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