Documentation
¶
Index ¶
- func WithAddressExtension(ae byte) func(*Address)
- func WithRxID(id uint32) func(*Address)
- func WithSourceAddress(sa byte) func(*Address)
- func WithTargetAddress(ta byte) func(*Address)
- func WithTxID(id uint32) func(*Address)
- type Address
- type AddressType
- type AddressingMode
- type CanMessage
- type Config
- type ConsecutiveFrame
- type FirstFrame
- type FlowControlFrame
- type FlowStatus
- type ISOTPFrame
- type SingleFrame
- type State
- type Transport
- func (t *Transport) ProcessRx(msg CanMessage, txChan chan<- CanMessage)
- func (t *Transport) Recv() ([]byte, bool)
- func (t *Transport) Run(ctx context.Context, rxChan <-chan CanMessage, txChan chan<- CanMessage)
- func (t *Transport) RunEventLoop(ctx context.Context, rxChan <-chan CanMessage, txChan chan<- CanMessage)
- func (t *Transport) Send(data []byte)
- func (t *Transport) SetFDMode(isFD bool)
- func (t *Transport) SetTxAddress(addr *Address)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithAddressExtension ¶
func WithSourceAddress ¶
func WithTargetAddress ¶
Types ¶
type Address ¶
type Address struct {
AddressingMode AddressingMode
// 用于 Normal, Extended, Mixed 模式
TxID uint32
RxID uint32
// 用于 NormalFixed, Mixed 模式
TargetAddress byte // 目标ECU地址 (TA)
SourceAddress byte // 源ECU地址 (SA)
// 用于 Extended, Mixed 模式
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) 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)。
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 FirstFrame ¶
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 Transport ¶
type Transport struct {
IsFD bool
MaxDataLength int
// Error Channel
ErrorChan chan error
// contains filtered or unexported fields
}
Transport 是ISOTP协议栈的核心结构
func NewTransport ¶
func (*Transport) ProcessRx ¶
func (t *Transport) ProcessRx(msg CanMessage, txChan chan<- CanMessage)
ProcessRx 处理接收到的单个CAN报文 Modified to take txChan to allow sending FlowControl frames directly
func (*Transport) Recv ¶
Recv receives data. It matches the old signature but now pulls from channel.
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) SetTxAddress ¶
SetTxAddress allows switching the transmit address without affecting RX filtering. When nil, the transport uses the base address provided at construction time.