Documentation
¶
Overview ¶
Package kwp decodes KWP2000 (Keyword Protocol 2000, ISO 14230-3) diagnostic messages — the predecessor to UDS still spoken by many pre-CAN / early-CAN ECUs and ELM327 adapters. It names the service, classifies the message as a request / positive response / negative response, and decodes the negative-response code.
Wrap-vs-native judgement ¶
Native. KWP2000 shares UDS's application framing (positive response = request SID + 0x40; negative response = 0x7F <SID> <NRC>) but has a DISTINCT service-ID table — the local-identifier services (0x21 ReadDataByLocalIdentifier, 0x30 InputOutputControlByLocalIdentifier, 0x31 StartRoutineByLocalIdentifier, 0x3B WriteDataByLocalIdentifier, …) and the communication-control services (0x81 StartCommunication, 0x82 StopCommunication) do not exist in UDS, and some shared SID numbers carry different meanings. Decoding KWP traffic with uds_decode would therefore mislabel it; this is the dedicated, correct table. The service-ID and NRC assignments are a public ISO standard (ISO 14230-3), reproduced identically by ELM327 tooling, CaringCaribou and Wireshark. It is a static lookup over the application PDU — no bus, no ISO-TP reassembly, no hardware (the caller brings the assembled message, e.g. from a canbus / isotp capture). The j1850 decoder explicitly lists KWP2000 as out of scope; this fills that gap.
No confidently-wrong output ¶
Only ISO-14230-assigned service IDs and NRCs are named; an unknown service or NRC is surfaced with its raw hex and numeric value, never guessed. The byte after the SID is surfaced with a per-service label (diagnostic session, local identifier, access mode, …) but its value enum is NOT guessed — KWP sub-function/identifier values are largely manufacturer-defined, so the raw byte plus the remaining payload are surfaced for the operator to interpret.
Index ¶
Constants ¶
const NegativeResponseSID = 0x7F
NegativeResponseSID introduces a negative response: 0x7F <SID> <NRC>.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KWP ¶
type KWP struct {
Direction string `json:"direction"` // request | positive_response | negative_response
ServiceID int `json:"service_id"`
ServiceIDHex string `json:"service_id_hex"`
Service string `json:"service"`
ParamByte *int `json:"param_byte,omitempty"`
ParamLabel string `json:"param_label,omitempty"`
NRC *int `json:"nrc,omitempty"`
NRCName string `json:"nrc_name,omitempty"`
PayloadHex string `json:"payload_hex,omitempty"`
Notes []string `json:"notes,omitempty"`
}
KWP is the decoded view of a KWP2000 message.
func Decode ¶
Decode parses a hex-encoded KWP2000 application PDU. Separators and a 0x prefix are tolerated.
func DecodeBytes ¶
DecodeBytes parses a KWP2000 application PDU from raw bytes.