uds_client

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PositiveResponse                                  = 0x00
	GeneralReject                                     = 0x10
	ServiceNotSupported                               = 0x11
	SubFunctionNotSupported                           = 0x12
	IncorrectMessageLengthOrInvalidFormat             = 0x13
	ResponseTooLong                                   = 0x14
	BusyRepeatRequest                                 = 0x21
	ConditionsNotCorrect                              = 0x22
	RequestSequenceError                              = 0x24
	NoResponseFromSubnetComponent                     = 0x25
	FailurePreventsExecutionOfRequestedAction         = 0x26
	RequestOutOfRange                                 = 0x31
	SecurityAccessDenied                              = 0x33
	AuthenticationRequired                            = 0x34
	InvalidKey                                        = 0x35
	ExceedNumberOfAttempts                            = 0x36
	RequiredTimeDelayNotExpired                       = 0x37
	SecureDataTransmissionRequired                    = 0x38
	SecureDataTransmissionNotAllowed                  = 0x39
	SecureDataVerificationFailed                      = 0x3A
	CertificateVerificationFailed_InvalidTimePeriod   = 0x50
	CertificateVerificationFailed_InvalidSignature    = 0x51
	CertificateVerificationFailed_InvalidChainOfTrust = 0x52
	CertificateVerificationFailed_InvalidType         = 0x53
	CertificateVerificationFailed_InvalidFormat       = 0x54
	CertificateVerificationFailed_InvalidContent      = 0x55
	CertificateVerificationFailed_InvalidScope        = 0x56
	CertificateVerificationFailed_InvalidCertificate  = 0x57
	OwnershipVerificationFailed                       = 0x58
	ChallengeCalculationFailed                        = 0x59
	SettingAccessRightsFailed                         = 0x5A
	SessionKeyCreationDerivationFailed                = 0x5B
	ConfigurationDataUsageFailed                      = 0x5C
	DeAuthenticationFailed                            = 0x5D
	UploadDownloadNotAccepted                         = 0x70
	TransferDataSuspended                             = 0x71
	GeneralProgrammingFailure                         = 0x72
	WrongBlockSequenceCounter                         = 0x73
	RequestCorrectlyReceived_ResponsePending          = 0x78
	SubFunctionNotSupportedInActiveSession            = 0x7E
	ServiceNotSupportedInActiveSession                = 0x7F
	RpmTooHigh                                        = 0x81
	RpmTooLow                                         = 0x82
	EngineIsRunning                                   = 0x83
	EngineIsNotRunning                                = 0x84
	EngineRunTimeTooLow                               = 0x85
	TemperatureTooHigh                                = 0x86
	TemperatureTooLow                                 = 0x87
	VehicleSpeedTooHigh                               = 0x88
	VehicleSpeedTooLow                                = 0x89
	ThrottlePedalTooHigh                              = 0x8A
	ThrottlePedalTooLow                               = 0x8B
	TransmissionRangeNotInNeutral                     = 0x8C
	TransmissionRangeNotInGear                        = 0x8D
	BrakeSwitchNotClosed                              = 0x8F
	ShifterLeverNotInPark                             = 0x90
	TorqueConverterClutchLocked                       = 0x91
	VoltageTooHigh                                    = 0x92
	VoltageTooLow                                     = 0x93
	ResourceTemporarilyNotAvailable                   = 0x94
	TerminationWithSignatureRequested                 = 0x3B
	AccessDenied                                      = 0x3C
	VersionNotSupported                               = 0x3D
	SecuredLinkNotSupported                           = 0x3E
	CertificateNotAvailable                           = 0x3F
	AuditTrailInformationNotAvailable                 = 0x40
)

UDS 负响应码 (Negative Response Code)

Variables

This section is empty.

Functions

This section is empty.

Types

type AddressingMode

type AddressingMode int

AddressingMode 控制发送请求时使用物理/功能寻址。

const (
	AddressPhysical AddressingMode = iota
	AddressFunctional
)

type RequestOptions

type RequestOptions struct {
	Timeout    time.Duration // 单次请求超时
	MaxRetries int           // 最大重试次数 (仅对可重试错误生效)
	RetryDelay time.Duration // 重试间隔
}

RequestOptions 请求配置选项

func DefaultRequestOptions

func DefaultRequestOptions() RequestOptions

DefaultRequestOptions 返回默认请求选项

type Transport

type Transport interface {
	Send(data []byte)
	Recv() ([]byte, bool)
	SetTxAddress(addr *isotp.Address)
	SetFDMode(isFD bool)
	Run(ctx context.Context, rxChan <-chan isotp.CanMessage, txChan chan<- isotp.CanMessage)
}

Transport 定义了 UDS 客户端所需的 ISO-TP 传输层接口 这允许我们在测试中注入 Mock 对象

type UDSClient

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

UDSClient 是一个高级客户端,封装了所有初始化和通信的复杂性

func NewUDSClient

func NewUDSClient(dev driver.CANDriver, addr *isotp.Address, cfg isotp.Config) (*UDSClient, error)

NewUDSClient 是新的构造函数,负责完成所有组件的初始化和连接。 它接收一个CAN驱动实例和ISOTP配置。

func (*UDSClient) Close

func (c *UDSClient) Close()

Close 优雅地关闭客户端,释放所有资源。

func (*UDSClient) IsClosed

func (c *UDSClient) IsClosed() bool

IsClosed 检查客户端是否已关闭

func (*UDSClient) Request

func (c *UDSClient) Request(payload []byte) ([]byte, error)

Request 简化版请求函数,使用默认选项

func (*UDSClient) RequestWithContext

func (c *UDSClient) RequestWithContext(ctx context.Context, payload []byte, opts RequestOptions) ([]byte, error)

RequestWithContext 发送 UDS 请求并等待响应,支持 Context 取消。 这是更健壮的请求函数,支持:

  • Context 取消
  • 完整的 NRC 错误处理
  • 自动重试机制 (仅对可重试错误)
  • 响应 SID 验证

func (*UDSClient) RequestWithTimeout

func (c *UDSClient) RequestWithTimeout(payload []byte, timeout time.Duration) ([]byte, error)

RequestWithTimeout 带自定义超时的请求函数

func (*UDSClient) SendAndRecv

func (c *UDSClient) SendAndRecv(payload []byte, timeout time.Duration) ([]byte, error)

SendAndRecv 发送一个请求并阻塞等待响应,内置超时处理。

func (*UDSClient) SetAddressingMode

func (c *UDSClient) SetAddressingMode(mode AddressingMode) error

SetAddressingMode switches between physical and functional addressing for requests.

func (*UDSClient) SetFDMode

func (c *UDSClient) SetFDMode(isFD bool)

SetFDMode 允许动态切换CAN FD模式。

func (*UDSClient) SetFunctionalAddress

func (c *UDSClient) SetFunctionalAddress(addr *isotp.Address) error

SetFunctionalAddress sets the functional address used when AddressFunctional is active.

func (*UDSClient) UseFunctionalAddress

func (c *UDSClient) UseFunctionalAddress() error

UseFunctionalAddress is a convenience wrapper for SetAddressingMode(AddressFunctional).

func (*UDSClient) UsePhysicalAddress

func (c *UDSClient) UsePhysicalAddress() error

UsePhysicalAddress is a convenience wrapper for SetAddressingMode(AddressPhysical).

type UDSError

type UDSError struct {
	ServiceID byte   // 原始服务 ID
	NRC       byte   // 负响应码
	Message   string // 错误描述
}

func (*UDSError) Error

func (e *UDSError) Error() string

func (*UDSError) IsRetryable

func (e *UDSError) IsRetryable() bool

IsRetryable 判断该错误是否可以重试

Jump to

Keyboard shortcuts

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