Documentation
¶
Overview ¶
Package drewtech is a native (no Windows DLL) J2534 client for the DrewTech Mongoose Pro GM II. It speaks the Mongoose wire protocol directly over the device's virtual COM port at 115200 baud.
The wire protocol is decoded from the Windows DLL in devel/drewtech (re/*.md; PROTOCOL.md there predates it and is wrong about 0x10). The libj2534_mongoose C driver implements the same protocol in full and is the reference when the two disagree. The notable facts:
- framing check word is length^0x51E6 (LE), not a constant magic byte
- replies carry the command with 0x8000 set and echo the request's sequence, a 1..255 byte counter; status is a u32 at body[12:16]
- RX arrives as unsolicited 0x0009 pushes; there is no "read messages" command
- 0x08/0x0A are Tx confirmations carrying the Tx sequence, not RX
- a pass filter (0x0D) per CAN id is required or you receive nothing; 0x0E removes one by the handle the 0x0D reply gave, 0x10 all of a type
- 0x11 is a multiplexed control op (subtype at payload[8:12]): GetStatus, clear-TX=2, clear-RX=3, become-master=4
This file is the wire layer (framing + device transport + CAN data path). The J2534 API facade lives in j2534.go.
Index ¶
- Constants
- Variables
- func PassThruGetNextCarDAQ() ([]string, error)
- type CANFrame
- type Device
- func (d *Device) BecomeMaster(pollID byte) error
- func (d *Device) ClearMsgFilters() error
- func (d *Device) Close() error
- func (d *Device) GetChannelConfig(param uint32) (uint32, 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) PassThruFirmwareUpdate(image []byte) error
- func (d *Device) PassThruGetLastError() string
- func (d *Device) PassThruIoctl(ioctlID, param uint32) (uint32, error)
- func (d *Device) PassThruOpen() error
- func (d *Device) PassThruReadDetails() VersionInfo
- func (d *Device) PassThruReadMsgs(max int, timeout time.Duration) ([]*CANFrame, error)
- func (d *Device) PassThruReadVersion() VersionInfo
- func (d *Device) PassThruSetIncomingMsgCallback(cb func(*CANFrame))
- func (d *Device) PassThruSetProgrammingVoltage(pin, millivolts uint32) error
- func (d *Device) PassThruStartMsgFilter(filterType, pattern, mask uint32) (uint32, error)
- func (d *Device) PassThruStartPeriodicMsg(canID uint32, data []byte, interval time.Duration) (uint32, error)
- func (d *Device) PassThruStopMsgFilter(filterID uint32) error
- func (d *Device) PassThruStopPeriodicMsg(id uint32) error
- func (d *Device) PassThruWriteMsgs(canID uint32, data []byte) error
- type FirmwareInfo
- type Option
- type Packet
- type Parser
- type Version
- type VersionInfo
Constants ¶
const ( MagicByte uint8 = 0x51 ChecksumXOR uint8 = 0xE6 ChecksumWord uint16 = 0x51E6 // check = length ^ 0x51E6 (LE) 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 SubCmdTxStatus uint8 = 0x0A // device->host Tx completion status SubCmdDeleteObject uint8 = 0x0E // remove one filter or periodic: type, device handle SubCmdClearFilters uint8 = 0x10 // remove every object of one type SubCmdGetConfig uint8 = 0x0C // get config (there is no runtime set) SubCmdStartMsgFilter uint8 = 0x0D SubCmdControl uint8 = 0x11 // multiplexed: status / clear buffers / master SubCmdSetProtocol uint8 = 0x12 SubCmdGetSerial uint8 = 0x13 ProtocolCAN uint32 = 6 ParamDataRate uint32 = 0x04 ParamBitSamplePoint uint32 = 0x14 ParamSyncJumpWidth uint32 = 0x15 )
const ( GET_CONFIG uint32 = 0x01 SET_CONFIG uint32 = 0x02 READ_VBATT uint32 = 0x03 FIVE_BAUD_INIT uint32 = 0x04 FAST_INIT uint32 = 0x05 CLEAR_TX_BUFFER uint32 = 0x07 CLEAR_RX_BUFFER uint32 = 0x08 CLEAR_PERIODIC_MSGS uint32 = 0x09 CLEAR_MSG_FILTERS uint32 = 0x0A CLEAR_FUNCT_MSG_LOOKUP_TABLE uint32 = 0x0B ADD_TO_FUNCT_MSG_LOOKUP_TABLE uint32 = 0x0C DELETE_FROM_FUNCT_MSG_LOOKUP uint32 = 0x0D READ_PROG_VOLTAGE uint32 = 0x0E )
J2534 IOCTL ids (SAE J2534-1).
const ( PASS_FILTER uint32 = 0x01 BLOCK_FILTER uint32 = 0x02 FLOW_CONTROL_FILTER uint32 = 0x03 )
J2534 filter types (SAE J2534-1) for PassThruStartMsgFilter.
Variables ¶
var ErrDeviceGone = errors.New("drewtech: device gone")
ErrDeviceGone is reported to the error handler when reading the port fails, which ends the read loop: the device was unplugged or the port broke.
var ErrNotSupported = errors.New("drewtech: operation not supported")
ErrNotSupported is returned by J2534 operations the Mongoose firmware or this native client does not implement (see PROTOCOL.md for why each is out).
Functions ¶
func PassThruGetNextCarDAQ ¶
PassThruGetNextCarDAQ enumerates candidate device serial ports. The J2534 DLL discovers Mongoose units over USB/SetupDi; here we return the OS serial-port list for the caller to pick from.
Types ¶
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device represents a DrewTech J2534 device.
func (*Device) BecomeMaster ¶
BecomeMaster issues the "become master" control command (0x11 subtype 4).
func (*Device) ClearMsgFilters ¶
ClearMsgFilters removes all pass and block filters, one wire op 0x10 per object type.
func (*Device) GetChannelConfig ¶
GetChannelConfig reads a config param from the connected channel. The reply echoes the param at [16:20] and returns the value at [20:24]. Only DATA_RATE (0x04), BIT_SAMPLE_POINT (0x14) and SYNC_JUMP_WIDTH (0x15) are supported; there is no runtime set (0x0C is get-only). See PROTOCOL.md.
func (*Device) PassThruClose ¶
PassThruClose sends the wire close command and tears down the transport.
func (*Device) PassThruConnect ¶
PassThruConnect connects the CAN channel at the given bit rate and selects the CAN protocol. The device accepts off-table rates (e.g. 615384); the rate whitelist lived only in the Windows DLL, which this client bypasses.
func (*Device) PassThruDisconnect ¶
PassThruDisconnect disconnects the channel from the bus.
func (*Device) PassThruFirmwareUpdate ¶
PassThruFirmwareUpdate is intentionally not implemented. The reflash images live encrypted in the DLL's RCDATA resources and the streaming protocol is untested here; a wrong write can brick the dongle. See PROTOCOL.md.
func (*Device) PassThruGetLastError ¶
PassThruGetLastError returns the most recent error observed by the device (read loop, tx faults, rx overflow), or "" if none.
func (*Device) PassThruIoctl ¶
PassThruIoctl dispatches the standard J2534 ioctls. For GET_CONFIG, param is the config id and the returned value is the config value; other ioctls ignore param and return 0.
func (*Device) PassThruOpen ¶
PassThruOpen runs the DLL's device handshake and caches firmware/serial info for PassThruReadVersion. Like the DLL it only requires the board info, the jump to firmware and the open; the other answers go unused.
func (*Device) PassThruReadDetails ¶
func (d *Device) PassThruReadDetails() VersionInfo
PassThruReadDetails returns the cached version/serial details of the open device (there is no separate wire query; PassThruOpen already fetched them).
func (*Device) PassThruReadMsgs ¶
PassThruReadMsgs drains up to max frames from the host-side RX FIFO, waiting up to timeout for the first one. There is no wire "read" command: the device pushes 0x09 frames unsolicited and the read loop queues them.
func (*Device) PassThruReadVersion ¶
func (d *Device) PassThruReadVersion() VersionInfo
PassThruReadVersion returns cached firmware/bootloader/serial (from PassThruOpen) plus the reference DLL/API version strings.
func (*Device) PassThruSetIncomingMsgCallback ¶
PassThruSetIncomingMsgCallback registers a callback invoked for every RX frame (in addition to the FIFO and any WithCANChannel). Safe to call while the read loop is running.
func (*Device) PassThruSetProgrammingVoltage ¶
PassThruSetProgrammingVoltage is not implemented: the wire encoding is buried in the DLL's per-pin C++ dispatch and untestable without hardware, and wrong bytes on a voltage pin are a hardware risk. See PROTOCOL.md.
func (*Device) PassThruStartMsgFilter ¶
PassThruStartMsgFilter installs a message filter and returns its id. A PASS filter per CAN id is required: with none installed you receive nothing. Pass mask 0xFFFFFFFF for an exact match on pattern. Only PASS_FILTER is implemented: BLOCK is wire kind 2 in the same message (PROTOCOL.md §8) but untested on hardware, and FLOW_CONTROL needs the ISO15765 3-message variant.
func (*Device) PassThruStartPeriodicMsg ¶
func (d *Device) PassThruStartPeriodicMsg(canID uint32, data []byte, interval time.Duration) (uint32, error)
PassThruStartPeriodicMsg sends canID/data every interval and returns a message id for PassThruStopPeriodicMsg. Implemented host-side (a ticker calling WriteMsgs); the firmware has no periodic-message wire command.
func (*Device) PassThruStopMsgFilter ¶
PassThruStopMsgFilter removes a pass filter by the id PassThruStartMsgFilter returned.
func (*Device) PassThruStopPeriodicMsg ¶
PassThruStopPeriodicMsg stops a periodic message by id.
func (*Device) PassThruWriteMsgs ¶
PassThruWriteMsgs queues a CAN frame on the device, returning once the device has queued it, as the DLL does with a zero timeout. A full device queue is retried for up to a second. The wire frame is the fixed-size 0x24 layout the DLL sends: payload padded to 32 bytes, actual data length carried at [16:18].
type FirmwareInfo ¶
func ExtractVersions ¶
func ExtractVersions(data []byte) FirmwareInfo
type Option ¶
type Option func(*Device)
Option configures the device.
func WithCANChannel ¶
WithCANChannel sets a channel for receiving CAN frames.
func WithCANFrameHandler ¶
WithCANFrameHandler sets the CAN frame callback. Frames pushed to a handler or channel are not also queued for PassThruReadMsgs.
func WithErrorHandler ¶
WithErrorHandler sets the error callback.
type Packet ¶
Packet represents a protocol packet. Payload starts at the command opcode (wire offset 8): Payload[0]=opcode, Payload[1]=flag, Payload[2:4]=sequence.
func (*Packet) IsCANRx ¶
IsCANRx reports whether this is an unsolicited RX push, command 0x0009. Board-info replies share the opcode but carry the reply flag (0x8109).
func (*Packet) ParseCANFrame ¶
func (*Packet) SubCommand ¶
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser handles streaming packet parsing.
type VersionInfo ¶
type VersionInfo struct {
Firmware string // device firmware, e.g. "1.2.4.0"
Bootloader string // device bootloader
Serial string // device serial number
DLL string // reference DLL version string
API string // J2534 API version the reference DLL implements
}
VersionInfo is what PassThruReadVersion reports.