UNPKG

react-native-obd-retriver

Version:

A React Native hook library to manage Bluetooth Low Energy connections and communication with ELM327 OBD-II adapters.

71 lines 2.36 kB
/** * Convert hex string to byte array (Uint8Array). * * @param hex - Hex string to convert (can include spaces, non-hex chars filtered) * @returns Uint8Array containing decoded bytes * @example * ```typescript * // Convert hex string to bytes * const bytes = hexToBytes('48 65 6C 6C 6F'); * console.log(bytes); // Uint8Array [72, 101, 108, 108, 111] * ``` */ export declare const hexToBytes: (hex: string) => Uint8Array; /** * Convert byte array to hex string. * Always returns uppercase hex with padding. * * @param bytes - Array of byte values to convert * @returns Uppercase hex string * @example * ```typescript * // Convert bytes to hex string * const hex = bytesToHex([72, 101, 108, 108, 111]); * console.log(hex); // "48656C6C6F" * ``` */ export declare const bytesToHex: (bytes: Uint8Array | number[]) => string; /** * Convert byte array to string using UTF-8 or ISO-8859-1. * Handles potential errors during decoding. * Tries UTF-8 first, falls back to ISO-8859-1 which covers more byte values. * * @param bytes - Array of byte values to convert to string * @returns Decoded string, empty string on error * @example * ```typescript * // Convert bytes to string * const text = bytesToString(new Uint8Array([72, 101, 108, 108, 111])); * console.log(text); // "Hello" * ``` */ export declare const bytesToString: (bytes: Uint8Array | number[] | null | undefined) => string; /** * Convert string to byte array using UTF-8. * Includes fallback to basic ASCII if UTF-8 encoding fails. * * @param str - String to convert to bytes * @returns Uint8Array containing encoded bytes * @example * ```typescript * // Convert string to bytes * const bytes = stringToBytes("Hello"); * console.log(bytes); // Uint8Array [72, 101, 108, 108, 111] * ``` */ export declare const stringToBytes: (str: string | null | undefined) => Uint8Array; /** * Format number as hex string with padding. * * @param num - Number to convert to hex * @param width - Minimum width for padding with zeros * @returns Uppercase hex string padded to specified width * @example * ```typescript * // Convert number to padded hex * const hex = toHexString(26, 4); * console.log(hex); // "001A" * ``` */ export declare const toHexString: (num: number | null | undefined, width?: number) => string; //# sourceMappingURL=ecuUtils.d.ts.map