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.
PROTOCOL.md (in devel/drewtech) for the full derivation; the notable facts:
- framing check word is length^0x51E6 (LE), not a constant magic byte
- RX arrives as unsolicited 0x09 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
- 0x11 is a multiplexed control op (subtype at payload[8:12]): GetStatus, clear-TX=2, clear-RX=3, become-master=4
- 0x10 clears filters (subtype 2 = clear all)
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 SubCmdClearFilters uint8 = 0x10 // also single stop-filter 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 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 ¶ added in v1.4.8
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 ¶ added in v1.4.8
BecomeMaster issues the "become master" control command (0x11 subtype 4).
func (*Device) ClearMsgFilters ¶ added in v1.4.8
ClearMsgFilters removes all installed filters (wire op 0x10 subtype 2).
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 ¶ added in v1.4.8
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 ¶ added in v1.4.8
PassThruGetLastError returns the most recent error observed by the device (read loop, tx faults, rx overflow), or "" if none.
func (*Device) PassThruIoctl ¶ added in v1.4.8
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 full device initialization handshake (matching the DLL's open sequence) and caches firmware/serial info for PassThruReadVersion.
func (*Device) PassThruReadDetails ¶ added in v1.4.8
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 ¶ added in v1.4.8
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 ¶ added in v1.4.8
func (d *Device) PassThruReadVersion() VersionInfo
PassThruReadVersion returns cached firmware/bootloader/serial (from PassThruOpen) plus the reference DLL/API version strings.
func (*Device) PassThruSetIncomingMsgCallback ¶ added in v1.4.8
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 ¶ added in v1.4.8
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 ¶ added in v1.4.8
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 filter by id.
func (*Device) PassThruStopPeriodicMsg ¶ added in v1.4.8
PassThruStopPeriodicMsg stops a periodic message by id.
func (*Device) PassThruWriteMsgs ¶
PassThruWriteMsgs transmits a CAN frame (fire-and-forget; the device replies with 0x08/0x0A confirmations that the read loop consumes). 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.
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 0x09 RX push. Real frames vary in length (a 2-byte-data frame is 0x1e); GetDeviceInfo replies also use op 0x09 but are much longer, so gate on the RX length window.
func (*Packet) ParseCANFrame ¶
func (*Packet) SubCommand ¶
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser handles streaming packet parsing.
type VersionInfo ¶ added in v1.4.8
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.