tp_layer

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithAddressExtension

func WithAddressExtension(ae byte) func(*Address)

func WithRxID

func WithRxID(id uint32) func(*Address)

func WithSourceAddress

func WithSourceAddress(sa byte) func(*Address)

func WithTargetAddress

func WithTargetAddress(ta byte) func(*Address)

func WithTxID

func WithTxID(id uint32) func(*Address)

Types

type Address

type Address struct {
	AddressingMode   AddressingMode
	TxID             uint32
	RxID             uint32
	TargetAddress    byte
	SourceAddress    byte
	AddressExtension byte
	TxPayloadPrefix  []byte
	RxPrefixSize     int
	// contains filtered or unexported fields
}

Address 存储了所有与寻址相关的信息

func NewAddress

func NewAddress(mode AddressingMode, opts ...func(*Address)) (*Address, error)

NewAddress 是一个灵活的构造函数,用于创建地址对象

func (*Address) GetTxArbitrationID

func (a *Address) GetTxArbitrationID(addrType AddressType) uint32

GetTxArbitrationID 根据寻址模式和类型(物理/功能)动态计算发送ID

func (*Address) Is29Bit

func (a *Address) Is29Bit() bool

Is29Bit 返回当前模式是否为29位

func (*Address) IsForMe

func (a *Address) IsForMe(msg *CanMessage) bool

IsForMe 检查收到的CAN报文是否是发给本ECU的

type AddressType

type AddressType int

AddressType 定义了寻址类型:物理或功能

const (
	Physical AddressType = iota
	Functional
)

type AddressingMode

type AddressingMode int

AddressingMode 定义了ISOTP支持的寻址模式

const (
	Normal11Bit      AddressingMode = iota // 11位ID,无地址扩展
	Normal29Bit                            // 29位ID,无地址扩展
	NormalFixed29Bit                       // 29位ID,目标/源地址在ID中
	Extended11Bit                          // 11位ID,目标地址在数据负载第一字节
	Extended29Bit                          // 29位ID,目标地址在数据负载第一字节
	Mixed11Bit                             // 11位ID,地址扩展在数据负载第一字节
	Mixed29Bit                             // 29位ID,目标/源地址在ID中,地址扩展在数据负载第一字节
)

type CanMessage

type CanMessage struct {
	ArbitrationID uint32
	Data          []byte
	IsExtendedID  bool
	IsFD          bool
	BitrateSwitch bool
}

CanMessage 代表一个 CAN 报文 (ISO-11898)。

func (*CanMessage) String

func (m *CanMessage) String() string

String 方法提供了 CanMessage 的字符串表示形式。

type Config

type Config struct {
	// PaddingByte, if not nil, is used to pad frames to declared length (8 or 64).
	PaddingByte *byte

	// Transmitter Side Timeouts
	TimeoutN_As time.Duration // Time for transmission of N_PDU on sender side
	TimeoutN_Bs time.Duration // Time until reception of FlowControl
	TimeoutN_Cs time.Duration // Time until transmission of next CF

	// Receiver Side Timeouts
	TimeoutN_Ar time.Duration // Time for transmission of N_PDU on receiver side
	TimeoutN_Br time.Duration // Time until transmission of FlowControl
	TimeoutN_Cr time.Duration // Time until reception of next CF

	// Parameters
	BlockSize int
	StMin     int
}

Config defines the configuration for the ISO-TP Transport.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the standard ISO-15765-2 default messages.

type ConsecutiveFrame

type ConsecutiveFrame struct {
	SequenceNumber int
	Data           []byte
}

type FirstFrame

type FirstFrame struct {
	TotalSize int
	Data      []byte
}

type FlowControlFrame

type FlowControlFrame struct {
	FlowStatus FlowStatus
	BlockSize  int
	STmin      time.Duration
}

type FlowStatus

type FlowStatus uint8

FlowStatus 定义了流控帧的状态。

const (
	FlowStatusContinueToSend FlowStatus = 0x00
	FlowStatusWait           FlowStatus = 0x01
	FlowStatusOverflow       FlowStatus = 0x02
)

type ISOTPFrame

type ISOTPFrame interface{}

func ParseFrame

func ParseFrame(msg *CanMessage, rxPrefixSize int) (ISOTPFrame, error)

type SingleFrame

type SingleFrame struct{ Data []byte }

type State

type State uint8

State 定义了收发状态机的状态。

const (
	StateIdle State = iota
	StateWaitFC
	StateWaitCF
	StateTransmit
)

type Transport

type Transport struct {
	IsFD          bool
	MaxDataLength int

	// Error Channel
	ErrorChan chan error
	// contains filtered or unexported fields
}

Transport 是ISOTP协议栈的核心结构

func NewTransport

func NewTransport(address *Address, cfg Config) *Transport

func (*Transport) ProcessRx

func (t *Transport) ProcessRx(msg CanMessage, txChan chan<- CanMessage)

ProcessRx Modified to take txChan to allow sending FlowControl frames directly

func (*Transport) Recv

func (t *Transport) Recv() ([]byte, bool)

Recv receives data. It matches the old signature but now pulls from channel.

func (*Transport) RecvChan added in v1.3.4

func (t *Transport) RecvChan() <-chan []byte

RecvChan returns a receive-only channel for blocking reads by callers.

func (*Transport) Run

func (t *Transport) Run(ctx context.Context, rxChan <-chan CanMessage, txChan chan<- CanMessage)

Run starts the protocol stack event loop.

func (*Transport) RunEventLoop

func (t *Transport) RunEventLoop(ctx context.Context, rxChan <-chan CanMessage, txChan chan<- CanMessage)

RunOptimized is the loop with proper state handling

func (*Transport) Send

func (t *Transport) Send(data []byte)

Send sends data. It might block if the send buffer is full.

func (*Transport) SetFDMode

func (t *Transport) SetFDMode(isFD bool)

func (*Transport) SetTxAddress

func (t *Transport) SetTxAddress(addr *Address)

SetTxAddress allows switching the transmit address without affecting RX filtering. When nil, the transport uses the base address provided at construction time.

Jump to

Keyboard shortcuts

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