fd

package module
v0.0.0-...-b1a4977 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2023 License: GPL-3.0 Imports: 7 Imported by: 0

README

can

介绍

基于Kvaser提供的驱动/socketCAN进行简单封装, 提供基本的can接口

软件架构

该库很大程度上参考了https://github.com/linklayer/go-socketcan

安装教程

windows: gcc -c ./Csrc/GACcanlib.c -I ./inc ar crv -o ./lib/GACcanlib.lib ./GACcanlib.o ./lib/canlib32.lib DEL ./GACcanlib.o

linux: pass

使用说明
直接作为go库引用相关go API即可
参与贡献
  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request
特技
  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. Gitee 官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解 Gitee 上的优秀开源项目
  4. GVP 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
  5. Gitee 官方提供的使用手册 https://gitee.com/help
  6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 https://gitee.com/gitee-stars/

Documentation

Index

Constants

View Source
const (
	CanFrameWithoutData  = 8
	CanFrameMaxDlc       = 8
	CanFdFrameMaxDlc     = 64
	CanInterfaceMaxBuf   = 16
	CanFdInterfaceMaxBuf = 72
)
View Source
const (
	CAN_RAW_FILTER        /* set 0 .. n can_filter(s)          */
	CAN_RAW_ERR_FILTER    /* set filter for error frames       */
	CAN_RAW_LOOPBACK      /* local loopback (default:on)       */
	CAN_RAW_RECV_OWN_MSGS /* receive my own msgs (default:off) */
	CAN_RAW_FD_FRAMES     /* allow CAN FD frames (default:off) */
	CAN_RAW_JOIN_FILTERS  /* all filters must match to trigger */
)

从can-utils里看到的定义

View Source
const (
	CAN_RAW   /* RAW sockets */
	CAN_BCM   /* Broadcast Manager */
	CAN_TP16  /* VAG Transport Protocol v1.6 */
	CAN_TP20  /* VAG Transport Protocol v2.0 */
	CAN_MCNET /* Bosch MCNet */
	CAN_ISOTP /* ISO 15765-2 Transport Protocol */
	CAN_J1939 /* SAE J1939 */
	CAN_NPROTO
)

从can-utils里看到的定义, 可以在unix包里找到: particular protocols of the protocol family PF_CAN

View Source
const (
	IF_TYPE_RAW_FD = iota
	IF_TYPE_ISOTP
)
View Source
const (
	SOL_CAN_BASE = 100
	SOL_CAN_RAW  = 101
)
View Source
const CAN_EFF_FLAG = 0x80000000
View Source
const CAN_ISOTP_EXTEND_ADDR = 0x002
View Source
const CAN_ISOTP_OPTS = 1
View Source
const CAN_ISOTP_RX_PADDING = 0x008
View Source
const CAN_ISOTP_TX_PADDING = 0x004
View Source
const SOL_CAN_ISOTP = 106
View Source
const SYS_SETSOCKOPT = 54

Variables

This section is empty.

Functions

This section is empty.

Types

type CanIsotpOptions

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

type Interface

type Interface struct {
	IfName   string
	SocketFd int

	Interface int32
	// contains filtered or unexported fields
}

func NewIsotpInterface

func NewIsotpInterface(ifName string, rxID uint32, txID uint32) (Interface, error)

func NewRawFdInterface

func NewRawFdInterface(cfg InterfaceCfg) (Interface, error)

func (Interface) Close

func (i Interface) Close() error

func (Interface) Rebind

func (i Interface) Rebind(rxID uint32, txID uint32) error

func (Interface) RecvBuf

func (i Interface) RecvBuf() ([]byte, error)

func (Interface) RecvFrame

func (i Interface) RecvFrame() (RawFrame, error)

func (Interface) SendBuf

func (i Interface) SendBuf(data []byte) error

func (Interface) SendFrame

func (i Interface) SendFrame(f RawFrame) error

func (Interface) SetLoopback

func (i Interface) SetLoopback(enable bool) error

func (Interface) SetRecvTimeout

func (i Interface) SetRecvTimeout(timeout time.Duration) error

func (Interface) SetSendTimeout

func (i Interface) SetSendTimeout(timeout time.Duration) error

func (Interface) SetTxPadding

func (i Interface) SetTxPadding(on bool, value uint8) error

type InterfaceCfg

type InterfaceCfg struct {
	IfName   string // for linux
	Channel  int32  // for windows
	Flag     int32  // for windows
	BitrateA int32  // for windows
	BitrateD int32  // for windows
}

type RawFrame

type RawFrame struct {
	Interface int32
	ArbId     int32
	Time      uint32
	Dlc       byte
	Extend    bool

	Data [64]byte
	// contains filtered or unexported fields
}

RawFrame 这个结构和[RawFrameSize]byte一一对应, 和C lib部分一一对应

type TrueCanFdFrame

type TrueCanFdFrame struct {
	ArbId uint32
	Dlc   byte
	Flags byte

	Data []byte
	// contains filtered or unexported fields
}

TrueCanFdFrame 从can-utils里看到的真实fd帧结构体, 到时write的时候按照这个位置进行写入

type TrueCanFrame

type TrueCanFrame struct {
	ArbId uint32
	Dlc   byte

	Data []byte
	// contains filtered or unexported fields
}

TrueCanFrame

1.从can-utils里看到的真实can帧结构体, 到时write的时候按照这个位置进行写入

2.从socketcan里看感觉并不是这个结构, 而是和TrueCanFdFrame一样的结构 这样看来可以直接混合写入了

Jump to

Keyboard shortcuts

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