react-native-obd-retriver
Version:
A React Native hook library to manage Bluetooth Low Energy connections and communication with ELM327 OBD-II adapters.
97 lines • 4.74 kB
TypeScript
/**
* Cleans ELM327 response string more aggressively.
* Removes prompt (>), ELM ID (ELM327), OK, SEARCHING..., whitespace, control chars.
* Keeps data-related parts like hex values and potentially meaningful keywords (NO DATA, ERROR).
* Based on ElmProtocolInit.getResponseId and cleaning logic in JS files.
*/
export declare const cleanResponse: (response: string | null | undefined) => string;
/**
* Checks if the response from the OBD device indicates a successful command execution
* @param response The response string from the OBD device
* @returns true if the response contains 'OK' or valid data
*/
export declare const isResponseOk: (response: string) => boolean;
/**
* Checks for common *ELM* error keywords in the response using constants.
* Does *not* check for OBD "NO DATA" as an error by default here.
* Based on ElmProtocolInit.isErrorResponse and ERROR_RESPONSES list in BaseDTCRetriever.
*/
export declare const isResponseError: (response: string | null | undefined) => boolean;
/**
* Extracts voltage if present in response (e.g., "12.3V").
* Based on logic in connectionService.
*/
export declare const extractVoltage: (response: string | null | undefined) => string | null;
/**
* Extracts protocol number from ATDPN response (e.g., "A6" -> 6, "3" -> 3).
* Based on logic in ProtocolManager.
*/
export declare const extractProtocolNumber: (response: string | null | undefined) => number | null;
/**
* Extracts potential ECU addresses (CAN/ISO/KWP headers) from a response string.
* Can handle multi-line responses. Returns a unique list of found addresses.
* Combines logic from ElmProtocolHelper.extractEcuAddress and connectionService.extractEcuAddresses.
* Prioritizes headers appearing at the start of a line or after a frame number (e.g., 0:, 1:).
*/
export declare function extractEcuAddresses(rawResponse: string | null | undefined): string[];
/**
* Checks if a cleaned response line looks like a VIN multi-frame indicator.
* (Unchanged from connectionService - keep as is)
*/
export declare const isVinResponseFrame: (cleanedResponse: string) => boolean;
/**
* Assembles data from a potentially multi-line/multi-frame ELM response.
* Removes frame counters (like '0:', '1:'), ISO-TP indicators (like '10xx', '2x'), prompts, whitespace.
* Assumes the input `rawResponse` contains all frames concatenated by newlines/CRs.
* (Unchanged from connectionService - keep as is, added logging)
*/
export declare const assembleMultiFrameResponse: (rawResponse: string | null | undefined) => string;
/**
* Parses VIN string from fully assembled OBD response hex data.
* Expects data *after* multi-frame assembly & cleaning.
* @param assembledHexData - Concatenated hex string from all relevant frames.
* (Unchanged from connectionService - keep as is, added logging)
*/
export declare const parseVinFromResponse: (assembledHexData: string | null | undefined) => string | null;
/** Parses DTC codes from assembled OBD response data */
/**
* Transforms raw OBD response data into standardized Diagnostic Trouble Codes
*
* This function parses the raw hexadecimal data returned from the vehicle's
* diagnostic system and converts it into standard DTC format codes (e.g., "P0123").
* It handles various OBD response formats including:
*
* - Responses with or without headers
* - Single and multi-ECU responses
* - Different service modes (03, 07, 0A for current/pending/permanent DTCs)
* - Zero-DTC cases
* - Various byte order conventions
*
* DTC Format Translation:
* - First character: P (Powertrain), C (Chassis), B (Body), U (Network)
* - Second character: 0 (standard), 1-3 (manufacturer-specific)
* - Last three characters: Specific fault code number
*
* @param responseData - Raw response string from OBD adapter
* @param modePrefix - Expected response prefix for the mode (e.g., "43" for mode 03)
* @returns Array of standardized DTC strings, empty array if no DTCs, or null if parsing failed
*
* @example
* ```typescript
* // For Mode 03 (current DTCs) with raw response "43 02 01 43 80 13"
* const dtcs = parseDtcsFromResponse(rawResponse, "43");
* // Returns: ["P0143", "B0013"]
*
* // For response with no DTCs: "43 00"
* const emptyDtcs = parseDtcsFromResponse("43 00", "43");
* // Returns: [] (empty array)
* ```
*/
export declare const parseDtcsFromResponse: (responseData: string | null | undefined, modePrefix: string) => string[] | null;
/**
* Checks if a cleaned response line looks like a standard ISO-TP multi-frame indicator.
* Used by assembleMultiFrameResponse.
* (Unchanged from connectionService - keep as is)
*/
export declare const isIsoTpFrameIndicator: (cleanedLine: string) => boolean;
//# sourceMappingURL=helpers.d.ts.map