elm327
Version:
Node.js/TypeScript library for ELM327 OBD2 adapters over USB, Bluetooth and WiFi
79 lines • 2.75 kB
TypeScript
import { DiagnosticMode, DiagnosticRequestConfig, DiagnosticResponse } from './types';
/**
* Re-export types for convenience
*/
export { DiagnosticMode };
export type { DiagnosticRequestConfig, DiagnosticResponse };
/**
* Builds OBD-II diagnostic requests in hex format.
* Similar to OpenXC's DiagnosticRequest builder.
*/
export declare class DiagnosticRequestBuilder {
private config;
constructor(config: DiagnosticRequestConfig);
/**
* Builds the hex command string for this diagnostic request.
* Format: <mode><pid> (if pid is present)
*/
build(): string;
/**
* Returns atomic command for specific CAN ID.
* For ELM327, we combine AT SH + command as a single string
* to prevent header from being "forgotten" between commands.
* Uses semicolon to chain commands in ELM327.
*/
getCommandsForSpecificId(): string[];
/**
* Converts a number to 2-char hex string
*/
private toHex;
/**
* Gets the configuration
*/
getConfig(): DiagnosticRequestConfig;
/**
* Static helper to create a simple mode 1 request
*/
static mode1Request(pid: number, name?: string): DiagnosticRequestBuilder;
/**
* Static helper to create a vehicle info request (mode 9)
*/
static vehicleInfoRequest(pid: number): DiagnosticRequestBuilder;
/**
* Static helper to get VIN (Mode 9 PID 02)
*/
static vinRequest(): DiagnosticRequestBuilder;
}
/**
* Parses raw ELM327 responses into DiagnosticResponse objects
*/
export declare class DiagnosticResponseParser {
/**
* Parses a typical ELM327 response line
* Example: "41 0C 1A F8" (RPM response)
*
* Handles negative responses (7F) and extracts NRC codes.
* For multiple ECUs, parses each line separately.
*/
static parse(rawResponse: string, request: DiagnosticRequestConfig): DiagnosticResponse;
/**
* Parses a single response line
*/
private static parseLine;
/**
* Maps NRC (Negative Response Code) to human-readable message
*/
private static getNRCMessage;
/**
* Parses multiple responses (for broadcast requests)
*/
static parseMultipleResponses(rawResponse: string, request: DiagnosticRequestConfig): DiagnosticResponse[];
/**
* Parses a multi-line response (for multi-frame messages like VIN)
* Removes PCI (Protocol Control Information) bytes from each frame:
* - First Frame: byte 0 = PCI (0x0N where N = length)
* - Consecutive Frames: byte 0 = PCI (0x2N where N = sequence number)
*/
static parseMultiFrame(rawResponses: string[], request: DiagnosticRequestConfig): DiagnosticResponse;
}
//# sourceMappingURL=diagnostic-request.d.ts.map