UNPKG

@hangtime/grip-connect

Version:

Griptonite Motherboard, Tindeq Progressor, PitchSix Force Board, CTS500, WHC-06, Entralpi, Climbro, mySmartBoard: Bluetooth API Force-Sensing strength analysis for climbers

128 lines 6.76 kB
import { Device } from "./device.model.js"; import type { Service } from "../interfaces/device.interface.js"; import type { INordicDfuDevice } from "../interfaces/nordic.interface.js"; /** * Creates a fresh Nordic Secure DFU service definition. * Characteristics are mutable at runtime, so each device instance needs its own copy. * @returns {Service} A new DFU service descriptor with control, packet, and buttonless characteristics. */ export declare function createNordicDfuService(): Service; /** * Shared Nordic Secure DFU implementation for devices exposing the FE59 service. */ export declare abstract class NordicDfuDevice extends Device implements INordicDfuDevice { /** * Returns a cached DFU characteristic discovered during the current GATT session. * @param {"control" | "packet" | "buttonless"} characteristicId - The DFU characteristic identifier. * @returns {BluetoothRemoteGATTCharacteristic | undefined} The discovered characteristic, if available. */ private getDfuCharacteristic; /** * Checks whether the connected device is already exposing the DFU bootloader characteristics. * @returns {boolean} `true` when both control and packet characteristics are available. */ private hasDfuBootloaderCharacteristics; /** * Wraps the shared connect flow so DFU callers get a rejected promise when connection setup fails. * @returns {Promise<void>} Resolves when discovery is complete. */ private connectForDfu; /** * Prompts for a Bluetooth device matching the provided filters, then runs the normal service discovery flow. * @param {BluetoothLEScanFilter[]} filters - Alternative device filters to pass to `requestDevice`. * @returns {Promise<void>} Resolves after the selected device is connected and characteristics are cached. */ private requestAndConnectDfuDevice; /** * Ensures there is an active connection to either the application or DFU bootloader variant of the device. * @returns {Promise<void>} Resolves after a DFU-capable device has been connected and discovered. */ private ensureDfuCapableConnection; /** * Prompts for the rebooted Nordic DFU bootloader after the application switches into buttonless DFU mode. * @returns {Promise<void>} Resolves after the bootloader device is selected and connected. */ private connectDfuBootloader; /** * Normalizes DFU payload inputs to `Uint8Array` so packet slicing and CRC calculation use one byte representation. * @param {Uint8Array | ArrayBuffer} data - Raw DFU payload bytes. * @returns {Uint8Array} The payload as a `Uint8Array`. */ private toDfuBytes; /** * Calculates the Nordic Secure DFU CRC32 for the given payload prefix. * @param {Uint8Array} data - The bytes to checksum. * @returns {number} The signed 32-bit CRC value returned by Nordic DFU checksum responses. */ private dfuCrc32; /** * Formats a signed CRC value as an unsigned hexadecimal string for error messages. * @param {number} crc - The CRC value to format. * @returns {string} The CRC formatted as `0x????????`. */ private formatDfuCrc; /** * Transfers one Nordic Secure DFU object type, handling resume, chunking, checksum validation, and execute steps. * @param {"command" | "data"} objectType - The DFU object type to transfer. * @param {Uint8Array | ArrayBuffer} data - The full payload for that object type. * @returns {Promise<void>} Resolves when the payload has been fully transferred and validated. */ private dfuTransferObject; /** * Switches the device from application mode into the Nordic DFU bootloader. * @returns {Promise<void>} Resolves after the device reboots into DFU mode and reconnects to the bootloader. */ dfuSwitch: () => Promise<void>; /** * Sends a raw Nordic Secure DFU control operation and resolves with the response payload bytes. * Call after dfuSwitch() has reconnected to the DFU bootloader. * @param {Uint8Array} operation - The DFU control opcode bytes to send. * @param {ArrayBuffer} [payload] - Optional payload appended to the opcode. * @returns {Promise<Uint8Array>} Resolves with the response payload bytes after the 3-byte Nordic response header. */ dfuControl: (operation: Uint8Array, payload?: ArrayBuffer) => Promise<Uint8Array>; /** * Sends Nordic Secure DFU SELECT for command or data objects and returns the bootloader state. * @param {"command" | "data"} objectType - The object type to query. * @returns {Promise<{ maxSize: number; offset: number; crc: number }>} The bootloader's object size, offset, and CRC state. */ dfuSelect: (objectType: "command" | "data") => Promise<{ maxSize: number; offset: number; crc: number; }>; /** * Sends Nordic Secure DFU CREATE for command or data objects. * @param {"command" | "data"} objectType - The object type to create. * @param {number} size - The size of the object chunk to allocate in bytes. * @returns {Promise<void>} Resolves when the bootloader accepts the object allocation request. */ dfuCreate: (objectType: "command" | "data", size: number) => Promise<void>; /** * Writes raw bytes to the Nordic Secure DFU packet characteristic. * @param {Uint8Array | ArrayBuffer} data - The packet payload bytes to send. * @returns {Promise<void>} Resolves after the packet has been written. */ dfuWritePacket: (data: Uint8Array | ArrayBuffer) => Promise<void>; /** * Sends Nordic Secure DFU CALCULATE_CHECKSUM and returns the bootloader state. * @returns {Promise<{ offset: number; crc: number }>} The bootloader's transferred offset and CRC for the current object stream. */ dfuChecksum: () => Promise<{ offset: number; crc: number; }>; /** * Sends Nordic Secure DFU EXECUTE for the currently created object. * @returns {Promise<void>} Resolves when the bootloader executes the current DFU object. */ dfuExecute: () => Promise<void>; /** * Runs a complete Nordic Secure DFU upload: switch to bootloader, send init packet, then send firmware. * @param {Uint8Array | ArrayBuffer} initPacket - The Nordic Secure DFU init packet bytes. * @param {Uint8Array | ArrayBuffer} firmware - The firmware image bytes to upload. * @returns {Promise<void>} Resolves after the firmware upload completes and the bootloader disconnects to reboot. */ dfuUpload: (initPacket: Uint8Array | ArrayBuffer, firmware: Uint8Array | ArrayBuffer) => Promise<void>; } //# sourceMappingURL=nordic.model.d.ts.map