canbus

package
v0.0.0-...-a6598b8 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

CAN Bus support package This package provides functions to setup physical and/or create virtual CAN interfaces

Index

Constants

View Source
const (
	// LinkVCAN Virtual CAN interface type
	LinkVCAN = "vcan"
	// LinkCAN Physical CAN interface type
	LinkCAN = "can"
)

Types of CAN interfaces

View Source
const (
	IFLA_CAN_TDC          = unix.IFLA_CAN_BITRATE_MAX + 1
	IFLA_CAN_TDC_TDCV_MIN = 0x1
	IFLA_CAN_TDC_TDCV_MAX = 0x2
	IFLA_CAN_TDC_TDCO_MIN = 0x3
	IFLA_CAN_TDC_TDCO_MAX = 0x4
	IFLA_CAN_TDC_TDCF_MIN = 0x5
	IFLA_CAN_TDC_TDCF_MAX = 0x6
	IFLA_CAN_TDC_TDCV     = 0x7
	IFLA_CAN_TDC_TDCO     = 0x8
	IFLA_CAN_TDC_TDCF     = 0x9
)

The following constants are related to TDC (Transmitter Delay Compensation) and were taken from Linux's kernel header: include/uapi/linux/can/netlink.h (version 6.6) PS: All of them are treated as uint32 in netlink packages

Variables

This section is empty.

Functions

func DelVCANLink(name string) error

DelVCANLink deletes a Virtual CAN interface name: Interface's name, e.g. "vcan0", "vcan1"

func GetCANLinks() ([]netlink.Link, error)

GetCANLinks fetches all CAN interfaces (virtual or physical)

func LinkSetDown

func LinkSetDown(link *CAN) error

LinkSetDown brings down a CAN interface

func LinkSetUp

func LinkSetUp(link *CAN) error

LinkSetUp brings up a CAN interface

func SetBitTiming

func SetBitTiming(link *CAN, bitTiming unix.CANBitTiming) error

SetBitTiming sets bit timing properties of a CAN interface

func SetBitTimingConst

func SetBitTimingConst(link *CAN, bitTimingConst unix.CANBitTimingConst) error

SetBitTimingConst sets bit timing constant properties of a CAN interface

func SetCtrlMode

func SetCtrlMode(link *CAN, ctrlMode unix.CANCtrlMode) error

SetCtrlMode sets control mode flags of a CAN interface

func SetDataBitTiming

func SetDataBitTiming(link *CAN, dataBitTiming unix.CANBitTiming) error

SetDataBitTiming sets data bit timing properties of a CAN interface

func SetDataBitTimingConst

func SetDataBitTimingConst(link *CAN, dataBitTimingConst unix.CANBitTimingConst) error

SetDataBitTimingConst sets data bit timing constant properties of a CAN interface

func SetRestart

func SetRestart(link *CAN, restart uint32) error

SetRestart sets restart property of a CAN interface

func SetRestartMs

func SetRestartMs(link *CAN, restartMs uint32) error

SetRestartMs sets restart-ms property of a CAN interface

func SetTDC

func SetTDC(link *CAN, tdcv uint32, tdco uint32, tdcf uint32) error

SetTDC sets TDC parameters

func SetTermination

func SetTermination(link *CAN, termination uint16) error

SetTermination sets termination property of a CAN interface

func SetupCAN

func SetupCAN(link *CAN, properties map[string]string) error

SetupCAN setup CAN interface from a map of properties described as strings, e.g.:

properties := map[string]string{
 "bitrate": "125000",
 "sample-point": "0.875",
 "tq": "29",
 "prop_seg": "118",
 "phase_seg1": "119",
 "phase_seg2": "34",
 "sjw": "1",
}

func StateToString

func StateToString(state uint32) string

StateToString returns the string corresponding to a CAN State

Types

type CAN

type CAN struct {
	LinkAttrs          netlink.LinkAttrs
	CanType            string
	State              uint32
	BitTiming          unix.CANBitTiming
	DataBitTiming      unix.CANBitTiming
	BitTimingConst     unix.CANBitTimingConst
	DataBitTimingConst unix.CANBitTimingConst
	ErrorCounters      unix.CANBusErrorCounters
	Clock              unix.CANClock
	CtrlMode           unix.CANCtrlMode
	DeviceStats        unix.CANDeviceStats
	Restart            uint32
	RestartMs          uint32
	Termination        uint16
	TDCV               uint32
	TDCO               uint32
	TDCF               uint32
}

CAN Interface, it implements netlink.Link interface

func AddVCANLink(name string) (*CAN, error)

AddVCANLink adds a new Virtual CAN interface name: Interface's name, e.g. "vcan0", "vcan1"

func GetCANLink(name string) (*CAN, error)

GetCANLink returns a CAN interface from the interface's name (e.g. "can0", "vcan0"). All the information about the interface will be fetched from the system

func (CAN) Attrs

func (d CAN) Attrs() *netlink.LinkAttrs

Attrs returns Link attributes

func (CAN) Type

func (d CAN) Type() string

Type returns the type of the CAN interface, i.e. "can" or "vcan"

Jump to

Keyboard shortcuts

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