Documentation
¶
Index ¶
- Constants
- Variables
- func CANUSBAccept11(ids []uint32) (ac, am [4]byte, err error)
- func CANUSBCmds11(ids []uint32) (mCmd, maskCmd string, err error)
- func ListAdapterNames() []string
- func NewGRPCClient() (*grpc.ClientConn, proto.GocanClient, error)
- func NewScantoolVCP(name string) func(cfg *AdapterConfig) (Adapter, error)
- func NewTxbridge(name string) func(cfg *AdapterConfig) (Adapter, error)
- func RegisterAdapter(adapter *AdapterInfo) error
- func SetLatencyTimer(device string, latency int) error
- type ADCCapable
- type Adapter
- func NewAdapter(adapterName string, cfg *AdapterConfig) (Adapter, error)
- func NewCanusb(cfg *AdapterConfig) (Adapter, error)
- func NewDrewtech(cfg *AdapterConfig) (Adapter, error)
- func NewELM327(cfg *AdapterConfig) (Adapter, error)
- func NewJust4Trionic(cfg *AdapterConfig) (Adapter, error)
- func NewMock(name string, cfg *AdapterConfig) (Adapter, error)
- func NewOBDXProWifi(cfg *AdapterConfig) (Adapter, error)
- func NewSLCan(cfg *AdapterConfig) (Adapter, error)
- func NewTemplate(name string, cfg *AdapterConfig) (Adapter, error)
- func NewYACA(cfg *AdapterConfig) (Adapter, error)
- type AdapterCapabilities
- type AdapterConfig
- type AdapterInfo
- type BaseAdapter
- func (base *BaseAdapter) Close()
- func (base *BaseAdapter) Debug(debug string)
- func (base *BaseAdapter) Err() <-chan error
- func (base *BaseAdapter) Error(err error)
- func (base *BaseAdapter) Event() <-chan Event
- func (base *BaseAdapter) Fatal(err error)
- func (base *BaseAdapter) Info(info string)
- func (base *BaseAdapter) Name() string
- func (base *BaseAdapter) Recv() <-chan *CANFrame
- func (base *BaseAdapter) Send() chan<- *CANFrame
- func (base *BaseAdapter) Warn(warn string)
- type CANFrame
- type CANFrameType
- type Canusb
- type Client
- func (c *Client) Adapter() Adapter
- func (c *Client) AdapterName() string
- func (c *Client) Close() (err error)
- func (c *Client) Context() context.Context
- func (c *Client) Done() <-chan struct{}
- func (c *Client) Err() error
- func (c *Client) OnEvent(fn func(Event)) (cancel func())
- func (c *Client) Recv(ctx context.Context, timeout time.Duration, identifiers ...uint32) (*CANFrame, error)
- func (c *Client) Send(identifier uint32, data []byte, f CANFrameType) error
- func (c *Client) SendAndWait(ctx context.Context, frame *CANFrame, timeout time.Duration, ...) (*CANFrame, error)
- func (c *Client) SendExtended(identifier uint32, data []byte, f CANFrameType) error
- func (c *Client) SendFrame(msg *CANFrame) error
- func (c *Client) Subscribe(ctx context.Context, identifiers ...uint32) *Subscriber
- func (c *Client) SubscribeChan(ctx context.Context, channel chan *CANFrame, identifiers ...uint32) *Subscriber
- func (c *Client) SubscribeFunc(ctx context.Context, fn func(*CANFrame), identifiers ...uint32) *Subscriber
- func (c *Client) Wait(ctx context.Context) error
- type Device
- func (d *Device) Close() error
- func (d *Device) GetChannelConfig(param uint32) (uint32, error)
- func (d *Device) GetConfig(param uint32) (uint32, error)
- func (d *Device) GetDeviceInfo(param uint16) error
- func (d *Device) GetFirmwareVersion() (string, error)
- func (d *Device) GetSerial() (string, error)
- func (d *Device) GetStatus() error
- func (d *Device) Init() error
- func (d *Device) Open(portName string) error
- func (d *Device) PassThruClose() error
- func (d *Device) PassThruConnect(baudRate uint32) error
- func (d *Device) PassThruDisconnect() error
- func (d *Device) PassThruOpen() error
- func (d *Device) PassThruStartMsgFilter(patern, mask uint32) (uint32, error)
- func (d *Device) PassThruStopMsgFilter(filterID uint32) error
- func (d *Device) PassThruWriteMsgs(canID uint32, data []byte) error
- func (d *Device) SetChannelConfig(param, value uint32) error
- type Drewtech
- type ELM327
- type Event
- type EventType
- type FirmwareInfo
- type GWClient
- type Just4Trionic
- type Mock
- type OBDXProWifi
- type Opt
- type Option
- type Packet
- type Parser
- type ResponseType
- type SLCan
- type ScantoolVCP
- type Subscriber
- type Template
- type TimeoutError
- type Txbridge
- type Version
- type YACA
Constants ¶
const ( MagicByte uint8 = 0x51 ChecksumXOR uint8 = 0xE6 DirectionOut uint8 = 0x01 DirectionIn uint8 = 0x00 FlagRequest uint8 = 0x01 FlagRequestFinal uint8 = 0x00 FlagResponse uint8 = 0x81 FlagResponseFinal uint8 = 0x80 SubCmdInit uint8 = 0x00 SubCmdGetVersion uint8 = 0x03 SubCmdClose uint8 = 0x05 SubCmdConnect uint8 = 0x06 SubCmdDisconnect uint8 = 0x07 SubCmdCANTx uint8 = 0x08 SubCmdCANRx uint8 = 0x09 SubCmdSetConfig uint8 = 0x0B SubCmdGetConfig uint8 = 0x0C SubCmdStartMsgFilter uint8 = 0x0D SubCmdStopMsgFilter uint8 = 0x10 SubCmdGetStatus uint8 = 0x11 SubCmdSetProtocol uint8 = 0x12 SubCmdGetSerial uint8 = 0x13 ProtocolCAN uint32 = 6 ParamDataRate uint32 = 0x04 ParamBitSamplePoint uint32 = 0x14 ParamSyncJumpWidth uint32 = 0x15 )
const ( ELM327_OK = "OK\r\r" ELM327_UNKNOWN = "?\r\r" )
const ( OBDLinkSX = "OBDLink SX" OBDLinkEX = "OBDLink EX" STN1170 = "STN1170" STN2120 = "STN2120" )
const ( SystemMsg uint32 = 0x80000000 + iota SystemMsgError SystemMsgUnrecoverableError SystemMsgWBLReading SystemMsgDataResponse SystemMsgDataRequest SystemMsgWriteResponse SystemMsgUnknown )
We have 3 bits allowing 8 different system messages hidden in a 29bit can id stored in a uint32
Variables ¶
var ( Incoming = CANFrameType{Type: ResponseTypeIncoming, Responses: 0} Outgoing = CANFrameType{Type: ResponseTypeOutgoing, Responses: 0} ResponseRequired = CANFrameType{Type: ResponseTypeResponseRequired, Responses: 1} // Used for ELM and STN adapters to signal we want the adapter to wait for a response )
var ( ErrErrorChannelFull = errors.New("error channel full") ErrNillAdapter = errors.New("adapter is nil") ErrDroppedFrame = errors.New("adapter incoming channel full") ErrFramhandlerRegisterSub = errors.New("failed to register subscription, framehandler is full") ErrSendTimeout = errors.New("timeout sending frame") ErrResponsechannelClosed = errors.New("response channel closed") )
var ErrClosed = errors.New("gocan: client closed")
ErrClosed is the context cause set when a client is shut down via Close. It is reported as a clean shutdown (Client.Err returns nil) rather than a fatal error.
Functions ¶
func CANUSBAccept11 ¶ added in v1.0.7
func CANUSBCmds11 ¶ added in v1.0.7
Helper to produce the actual CANUSB ASCII commands for 11-bit IDs. Example output for ids 0x300..0x3FF:
M00006000 m00001FF0
func ListAdapterNames ¶ added in v1.0.7
func ListAdapterNames() []string
func NewGRPCClient ¶ added in v1.0.7
func NewGRPCClient() (*grpc.ClientConn, proto.GocanClient, error)
func NewScantoolVCP ¶ added in v1.0.7
func NewScantoolVCP(name string) func(cfg *AdapterConfig) (Adapter, error)
func NewTxbridge ¶ added in v1.0.7
func NewTxbridge(name string) func(cfg *AdapterConfig) (Adapter, error)
func RegisterAdapter ¶ added in v1.0.7
func RegisterAdapter(adapter *AdapterInfo) error
func SetLatencyTimer ¶ added in v1.3.4
Types ¶
type ADCCapable ¶ added in v1.0.7
type Adapter ¶
type Adapter interface {
Name() string
Open(context.Context) error
Close() error
Send() chan<- *CANFrame
Recv() <-chan *CANFrame
Err() <-chan error
Event() <-chan Event
}
func NewAdapter ¶ added in v1.0.7
func NewAdapter(adapterName string, cfg *AdapterConfig) (Adapter, error)
func NewCanusb ¶ added in v1.4.2
func NewCanusb(cfg *AdapterConfig) (Adapter, error)
func NewDrewtech ¶ added in v1.3.4
func NewDrewtech(cfg *AdapterConfig) (Adapter, error)
func NewELM327 ¶ added in v1.0.7
func NewELM327(cfg *AdapterConfig) (Adapter, error)
func NewJust4Trionic ¶ added in v1.0.7
func NewJust4Trionic(cfg *AdapterConfig) (Adapter, error)
func NewMock ¶ added in v1.0.7
func NewMock(name string, cfg *AdapterConfig) (Adapter, error)
Create a new Mock adapter used for testing. Frames written to Send() are echoed back on Recv() as Incoming frames.
func NewOBDXProWifi ¶ added in v1.0.7
func NewOBDXProWifi(cfg *AdapterConfig) (Adapter, error)
func NewSLCan ¶ added in v1.0.7
func NewSLCan(cfg *AdapterConfig) (Adapter, error)
func NewTemplate ¶ added in v1.0.7
func NewTemplate(name string, cfg *AdapterConfig) (Adapter, error)
func NewYACA ¶ added in v1.0.7
func NewYACA(cfg *AdapterConfig) (Adapter, error)
type AdapterCapabilities ¶ added in v1.0.7
func (*AdapterCapabilities) String ¶ added in v1.0.7
func (a *AdapterCapabilities) String() string
type AdapterConfig ¶
type AdapterConfig struct {
Debug bool // enable debug logging
Port string // port name or path to dll/so/dylib
PortBaudrate int // port baudrate in bps (only used for serial based adapters)
CANRate float64 // CAN bus rate in kbit/s
CANFilter []uint32 // CAN ID filters
UseExtendedID bool // only used for j2534 when setting upp frame filters
PrintVersion bool // print adapter version info on open
AdditionalConfig map[string]string // Key value pairs for adapter specific configuration
}
type AdapterInfo ¶ added in v1.0.7
type AdapterInfo struct {
Name string
Description string
RequiresSerialPort bool
Capabilities AdapterCapabilities
New func(*AdapterConfig) (Adapter, error)
}
func ListAdapters ¶ added in v1.0.7
func ListAdapters() []AdapterInfo
func (*AdapterInfo) String ¶ added in v1.0.7
func (a *AdapterInfo) String() string
type BaseAdapter ¶ added in v1.0.7
type BaseAdapter struct {
// contains filtered or unexported fields
}
func NewBaseAdapter ¶ added in v1.0.7
func NewBaseAdapter(name string, cfg *AdapterConfig) *BaseAdapter
func (*BaseAdapter) Close ¶ added in v1.0.7
func (base *BaseAdapter) Close()
func (*BaseAdapter) Debug ¶ added in v1.0.7
func (base *BaseAdapter) Debug(debug string)
Send a debug event
func (*BaseAdapter) Err ¶ added in v1.0.7
func (base *BaseAdapter) Err() <-chan error
Return the error channel for the adapter
func (*BaseAdapter) Error ¶ added in v1.0.7
func (base *BaseAdapter) Error(err error)
Send an error event
func (*BaseAdapter) Event ¶ added in v1.0.7
func (base *BaseAdapter) Event() <-chan Event
func (*BaseAdapter) Fatal ¶ added in v1.0.7
func (base *BaseAdapter) Fatal(err error)
Set a fatal adapter error, meaning communication is broken and cannot continue.
func (*BaseAdapter) Info ¶ added in v1.0.7
func (base *BaseAdapter) Info(info string)
Send an info event
func (*BaseAdapter) Name ¶ added in v1.0.7
func (base *BaseAdapter) Name() string
Name returns the adapter name.
func (*BaseAdapter) Recv ¶ added in v1.0.7
func (base *BaseAdapter) Recv() <-chan *CANFrame
Return the receive channel for the adapter
func (*BaseAdapter) Send ¶ added in v1.0.7
func (base *BaseAdapter) Send() chan<- *CANFrame
Return the send channel for the adapter
func (*BaseAdapter) Warn ¶ added in v1.0.7
func (base *BaseAdapter) Warn(warn string)
Send a warning event
type CANFrame ¶
type CANFrame struct {
Identifier uint32
Extended bool
RTR bool
Data []byte
FrameType CANFrameType
Timeout uint32
}
func NewExtendedFrame ¶ added in v1.0.7
func NewExtendedFrame(identifier uint32, data []byte, frameType CANFrameType) *CANFrame
NewExtendedFrame creates a new CANFrame and copies the data slice
func NewFrame ¶
func NewFrame(identifier uint32, data []byte, frameType CANFrameType) *CANFrame
NewFrame creates a new CANFrame and copies the data slice
func (*CANFrame) Bytes ¶ added in v1.0.7
returns the frame as a byte slice, 4 bytes for the identifier, 1 byte for the length and the data if holding more than 8 bytes of data, it will be truncated
func (*CANFrame) ColorString ¶ added in v1.0.7
type CANFrameType ¶
type CANFrameType struct {
Type ResponseType
Responses int
}
func ResponseRequiredWithResponses ¶ added in v1.0.7
func ResponseRequiredWithResponses(responses int) CANFrameType
type Canusb ¶ added in v1.4.2
type Canusb struct {
*BaseAdapter
// contains filtered or unexported fields
}
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewWithOpts ¶
Create a new CAN client with given adapter and options
func (*Client) AdapterName ¶ added in v1.0.7
Return the name of the underlying adapter
func (*Client) Context ¶ added in v1.4.1
Context returns the client context. It is cancelled when the client is closed or the adapter fails fatally; context.Cause reports why (ErrClosed on a clean shutdown, otherwise the fatal adapter error).
func (*Client) Done ¶ added in v1.4.1
func (c *Client) Done() <-chan struct{}
Done returns a channel that is closed when the client terminates, for use in a select alongside your own work.
func (*Client) Err ¶
Err returns the fatal adapter error that terminated the client, or nil if it is still running or was shut down cleanly (via Close or context cancellation).
func (*Client) OnEvent ¶ added in v1.4.1
OnEvent registers fn to receive subsequent events and returns a function that unregisters it. Unlike the construction-time options it can be called at any time and supports multiple independent listeners.
func (*Client) Recv ¶ added in v1.0.7
func (c *Client) Recv(ctx context.Context, timeout time.Duration, identifiers ...uint32) (*CANFrame, error)
Receive a single CAN frame with specific identifier and timeout
func (*Client) Send ¶
func (c *Client) Send(identifier uint32, data []byte, f CANFrameType) error
Shortcommand to send a standard 11bit frame
func (*Client) SendAndWait ¶
func (c *Client) SendAndWait(ctx context.Context, frame *CANFrame, timeout time.Duration, identifiers ...uint32) (*CANFrame, error)
Send and wait up to <timeout> for a answer on given identifiers
func (*Client) SendExtended ¶ added in v1.0.7
func (c *Client) SendExtended(identifier uint32, data []byte, f CANFrameType) error
Shortcommand to send a extended 29bit frame
func (*Client) Subscribe ¶
func (c *Client) Subscribe(ctx context.Context, identifiers ...uint32) *Subscriber
Subscribe to CAN identifiers and return a message channel
func (*Client) SubscribeChan ¶
func (c *Client) SubscribeChan(ctx context.Context, channel chan *CANFrame, identifiers ...uint32) *Subscriber
Subscribe to CAN identifiers with provided channel
func (*Client) SubscribeFunc ¶
func (c *Client) SubscribeFunc(ctx context.Context, fn func(*CANFrame), identifiers ...uint32) *Subscriber
Subscribe to CAN identifiers with a callback function
type Device ¶ added in v1.3.4
type Device struct {
// contains filtered or unexported fields
}
Device represents a DrewTech J2534 device
func NewDrewtechDevice ¶ added in v1.3.4
NewDrewtechDevice creates a new Device
func (*Device) GetChannelConfig ¶ added in v1.3.4
GetChannelConfig gets a config parameter from the current channel
func (*Device) GetDeviceInfo ¶ added in v1.3.4
func (*Device) GetFirmwareVersion ¶ added in v1.3.4
func (*Device) PassThruClose ¶ added in v1.3.4
PassThruClose closes the device connection
func (*Device) PassThruConnect ¶ added in v1.3.4
PassThruConnect connects to CAN bus
func (*Device) PassThruDisconnect ¶ added in v1.3.4
PassThruDisconnect disconnects from CAN bus
func (*Device) PassThruOpen ¶ added in v1.3.4
PassThruOpen performs the full device initialization sequence
func (*Device) PassThruStartMsgFilter ¶ added in v1.3.4
PassThruStartMsgFilter starts a pass-all filter
func (*Device) PassThruStopMsgFilter ¶ added in v1.3.4
PassThruStopMsgFilter stops the current filter
func (*Device) PassThruWriteMsgs ¶ added in v1.3.4
PassThruWriteMsgs transmits a CAN frame
func (*Device) SetChannelConfig ¶ added in v1.3.4
SetChannelConfig sets a config parameter on the current channel
type Drewtech ¶ added in v1.3.4
type Drewtech struct {
*BaseAdapter
// contains filtered or unexported fields
}
type ELM327 ¶ added in v1.0.7
type ELM327 struct {
*BaseAdapter
// contains filtered or unexported fields
}
type Event ¶ added in v1.0.7
type Event struct {
Type EventType
Details string
// Err holds the underlying error for EventTypeError and EventTypeFatal
// events. It may be nil for events raised from a plain message.
Err error
}
func (Event) IsFatal ¶ added in v1.4.1
IsFatal reports whether the event signals an unrecoverable adapter failure.
type EventType ¶ added in v1.0.7
type EventType int
type FirmwareInfo ¶ added in v1.3.4
func ExtractVersions ¶ added in v1.3.4
func ExtractVersions(data []byte) FirmwareInfo
type GWClient ¶ added in v1.0.7
type GWClient struct {
*BaseAdapter
// contains filtered or unexported fields
}
func NewGWClient ¶ added in v1.0.7
func NewGWClient(adapterName string, cfg *AdapterConfig) (*GWClient, error)
type Just4Trionic ¶ added in v1.0.7
type Just4Trionic struct {
*BaseAdapter
// contains filtered or unexported fields
}
func (*Just4Trionic) Close ¶ added in v1.0.7
func (a *Just4Trionic) Close() error
func (*Just4Trionic) SetFilter ¶ added in v1.0.7
func (a *Just4Trionic) SetFilter(filters []uint32) error
type Mock ¶ added in v1.0.7
type Mock struct {
*BaseAdapter
}
type OBDXProWifi ¶ added in v1.0.7
type OBDXProWifi struct {
*BaseAdapter
// contains filtered or unexported fields
}
func (*OBDXProWifi) Close ¶ added in v1.0.7
func (a *OBDXProWifi) Close() error
func (*OBDXProWifi) SetFilter ¶ added in v1.0.7
func (a *OBDXProWifi) SetFilter(filters []uint32) error
type Opt ¶ added in v1.0.7
type Opt func(*Client)
func WithEventChan ¶ added in v1.4.1
WithEventChan forwards every adapter event to ch. Sends are non-blocking: if ch is full the event is dropped, so size the buffer for your consumer. The channel is never closed by the client; range with a select on Client.Done.
func WithEventFunc ¶ added in v1.4.1
WithEventFunc registers fn as a synchronous event handler. It is called in order, from a single goroutine, for every adapter event (including the final fatal event). Keep it quick; a slow handler delays subsequent events.
func WithEventHandler
deprecated
added in
v1.0.7
func WithLogger ¶ added in v1.4.1
WithLogger forwards every adapter event to l at the matching slog level. Error and fatal events attach the underlying error under the "err" key.
type Option ¶ added in v1.3.4
type Option func(*Device)
Option configures the device
func WithCANChannel ¶ added in v1.3.4
WithCANChannel sets a channel for receiving CAN frames
func WithCANFrameHandler ¶ added in v1.3.4
WithCANFrameHandler sets the CAN frame callback
func WithErrorHandler ¶ added in v1.3.4
WithErrorHandler sets the error callback
type Packet ¶ added in v1.3.4
Packet represents a protocol packet
func (*Packet) ParseCANFrame ¶ added in v1.3.4
func (*Packet) SubCommand ¶ added in v1.3.4
type Parser ¶ added in v1.3.4
type Parser struct {
// contains filtered or unexported fields
}
Parser handles streaming packet parsing
type ResponseType ¶ added in v1.0.7
type ResponseType int
const ( ResponseTypeIncoming ResponseType = 0 ResponseTypeOutgoing ResponseType = 1 ResponseTypeResponseRequired ResponseType = 2 // Used for ELM and STN adapters to signal we want the adapter to wait for a response )
type SLCan ¶ added in v1.0.7
type SLCan struct {
*BaseAdapter
// contains filtered or unexported fields
}
type ScantoolVCP ¶ added in v1.0.7
type ScantoolVCP struct {
*BaseAdapter
// contains filtered or unexported fields
}
func (*ScantoolVCP) Close ¶ added in v1.0.7
func (stn *ScantoolVCP) Close() error
func (*ScantoolVCP) SetFilter ¶ added in v1.0.7
func (stn *ScantoolVCP) SetFilter(filters []uint32) error
type Subscriber ¶ added in v1.0.7
type Subscriber struct {
// contains filtered or unexported fields
}
func (*Subscriber) Chan ¶ added in v1.0.7
func (s *Subscriber) Chan() <-chan *CANFrame
func (*Subscriber) Close ¶ added in v1.0.7
func (s *Subscriber) Close()
type Template ¶ added in v1.0.7
type Template struct {
*BaseAdapter
}
type TimeoutError ¶ added in v1.0.7
func (*TimeoutError) Error ¶ added in v1.0.7
func (e *TimeoutError) Error() string
type Txbridge ¶ added in v1.0.7
type Txbridge struct {
*BaseAdapter
// contains filtered or unexported fields
}
type YACA ¶ added in v1.0.7
type YACA struct {
*BaseAdapter
// contains filtered or unexported fields
}
Source Files
¶
- adapter.go
- adapter_base.go
- adapter_canusb.go
- adapter_canusb_vcp.go
- adapter_client.go
- adapter_client_linux.go
- adapter_drewtech_linux.go
- adapter_elm327.go
- adapter_just4trionic.go
- adapter_obdx_wifi.go
- adapter_scantool.go
- adapter_scantool_manager.go
- adapter_scantool_vcp.go
- adapter_slcan.go
- adapter_template.go
- adapter_txbridge.go
- adapter_virtual.go
- adapter_yaca.go
- canframe.go
- error.go
- event.go
- gocan.go
- handler.go
- subscriber.go
- vcp.go
- vcp_linux.go
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
testsuite
command
|
|
|
examples
|
|
|
gmlan/read_vin_from_uec
command
|
|
|
list_adapters
command
|
|
|
passthru
command
|
|
|
passthru/dice_vin
command
|
|
|
passthru/trionic8_vin
command
|
|
|
pingpong/client
command
|
|
|
pingpong/server
command
|
|
|
pkg
|
|
|
drewtech
Package drewtech provides a client for DrewTech J2534 devices
|
Package drewtech provides a client for DrewTech J2534 devices |
|
gmlan
see GMW3110 gmw3110-2010.pdf
|
see GMW3110 gmw3110-2010.pdf |
|
pcan/cmd
command
|
|