/** * Bluetooth data parsers for Bota device protocol */ import { Buffer } from 'buffer'; import type { DeviceType, PairingState, DeviceState, DeviceStatus, DeviceFlags, LteStatus, WifiStatus, StorageInfo, DeviceCapabilities, WiFiStatus, WiFiStatusInfo, WiFiConfigResult, DeviceWiFiScanResult, DeviceConnectionSettings } from '../models/Device'; import type { DeviceRecording, AudioCodec, TransferPacket } from '../models/Recording'; /** * Parse device type from manufacturer data byte */ export declare function parseDeviceType(byte: number): DeviceType; /** * Parse pairing state from manufacturer data byte */ export declare function parsePairingState(byte: number): PairingState; /** * Parse firmware version from major/minor bytes */ export declare function parseFirmwareVersion(major: number, minor: number): string; /** * Parse device state from status byte */ export declare function parseDeviceState(byte: number): DeviceState; /** * Parse device flags from 1-byte bitmask * See: FIRMWARE_INTEGRATION_GUIDE_ZH.md section 3.1 — DeviceFlags enum */ export declare function parseDeviceFlags(value: number): DeviceFlags; /** * Parse LTE/4G modem status from byte value */ export declare function parseLteStatus(byte: number): LteStatus; /** * Parse WiFi radio status from byte value */ export declare function parseWifiStatus(byte: number): WifiStatus; /** * Parse device status from characteristic value * * Firmware format (15 bytes, backwards-compatible with 14): * Byte 0: Battery % (0-100) * Byte 1: LTE status (BOTA_LTE_* code) * Byte 2: Device state * Byte 3: Pending recordings count * Bytes 4-7: Last sync timestamp (Unix seconds) * Byte 8: Flags (1-byte bitmask) * Bytes 9-10: Storage total MB (uint16LE) * Bytes 11-12: Storage used MB (uint16LE) * Byte 13: LTE signal quality (CSQ 0-31, 99=unknown) * Byte 14: WiFi status (BOTA_WIFI_* code) — optional, firmware >= 1.1 */ export declare function parseDeviceStatus(data: Buffer): DeviceStatus; /** * Parse storage info from 16-byte characteristic value * * Format: * Bytes 0-3: Total storage (KB) * Bytes 4-7: Used storage (KB) * Bytes 8-9: Total recording count * Bytes 10-11: Pending sync count * Bytes 12-15: Reserved */ export declare function parseStorageInfo(data: Buffer): StorageInfo; /** * Parse audio codec from byte value */ export declare function parseAudioCodec(byte: number): AudioCodec; /** * Parse recording list from notification data * Each recording entry is 24 bytes: * - file_id: bytes [0:4] (4-byte file ID, bytes [4:16] zero-padded) * - flags: byte [4] (bit 0 = encrypted at rest, P4) * - reserved: bytes [5:16] * - timestamp: bytes [16:20] (u32 LE, Unix seconds) * - duration: bytes [20:22] (u16 LE, seconds) * - size_kb: bytes [22:24] (u16 LE, kilobytes) */ export declare function parseRecordingList(data: Buffer): DeviceRecording[]; /** * Parse transfer packet from device * * Format: * Byte 0: Packet type (0x01=data, 0x02=EOF, 0xFF=error) * Bytes 1-2: Sequence number * Bytes 3-4: Chunk size (data) or CRC32 start (EOF) * Bytes 5+: Audio data (data) or CRC32 remainder (EOF) */ export declare function parseTransferPacket(data: Buffer): TransferPacket; /** * Parse trigger device upload response from TRANSFER_STATUS notification. * Format: [0x03, status_code] * Returns null if not a trigger response (different opcode). */ export interface TriggerDeviceUploadResponse { accepted: boolean; errorCode?: number; } export declare function parseTriggerDeviceUploadResponse(data: Buffer): TriggerDeviceUploadResponse | null; /** * Create time sync data buffer * * Format: * Bytes 0-3: Unix timestamp (seconds) * Bytes 4-5: Milliseconds (0-999) * Bytes 6-7: Timezone offset (signed, minutes from UTC) */ export declare function createTimeSyncData(date?: Date): Buffer; /** * Create ACK packet for transfer * * Format: * Byte 0: ACK type (0x10=ACK, 0x11=NACK, 0x12=Abort) * Bytes 1-2: Sequence number */ export declare function createAckPacket(ackType: 'ack' | 'nack' | 'abort', sequenceNumber: number): Buffer; /** * Create transfer control command * * Format: * Byte 0: Command (0x01=list, 0x02=start, 0x07=confirm) * Bytes 1+: Recording UUID (for start/confirm) */ export declare function createTransferCommand(command: 'list' | 'start' | 'triggerDeviceUpload' | 'confirm', recordingUuid?: string): Buffer; /** * Parse device capabilities from byte value */ export declare function parseDeviceCapabilities(byte: number): DeviceCapabilities; /** * Parse WiFi status from byte value */ export declare function parseWiFiStatus(byte: number): WiFiStatus; /** * Parse WiFi status information from characteristic value * * Format: * Byte 0: Status (0x00=idle, 0x01=connecting, 0x02=connected, 0x03=failed, 0x04=disconnected) * Byte 1: Signal strength (0-100) * Byte 2: SSID length * Bytes 3-34: SSID (max 32 bytes) * Bytes 35+: Error message (if status=failed) */ export declare function parseWiFiStatusInfo(data: Buffer): WiFiStatusInfo; /** * Parse WiFi configuration result from characteristic value * * Format: * Byte 0: Result code (0x00=success, 0x01=invalid_grant, 0x02=grant_expired, 0x03=decryption_error, 0x04=storage_error) */ export declare function parseWiFiConfigResult(data: Buffer): WiFiConfigResult; /** * Create WiFi grant submission packet * * Format: * Bytes 0-N: Grant blob (JWT token as UTF-8 string) */ export declare function createWiFiGrantPacket(grantBlob: string): Buffer; /** * Create WiFi scan start command */ export declare function createWiFiScanCommand(): Buffer; /** * Parse device-side WiFi scan result from characteristic notification. * * Format: * Byte 0: Status (0x01=scanning, 0x02=done, 0x03=error) * Byte 1: Network count (when status=done) * For each network: * Byte 0: SSID length * Bytes 1-N: SSID (UTF-8) * Byte N+1: Signal quality (0-100) * Byte N+2: Flags (bit 0 = isCurrent) * * Returns null if status is not 'done' (still scanning). */ export declare function parseWiFiScanResult(data: Buffer): DeviceWiFiScanResult | null; /** * Serialize connection settings to 12-byte buffer for Bluetooth DEVICE_SETTINGS characteristic. * * Layout (v0x02): * Byte 0: version (0x02) * Byte 1: enabled_mask — bit 0: WiFi, bit 1: 4G (BLE always on) * Byte 2: upload_network_preference[0] — 1=WiFi, 2=BLE, 3=4G, 0=end * Byte 3: upload_network_preference[1] * Byte 4: upload_network_preference[2] * Byte 5: power_cfg_4g — 0=default(180s), 1-254=value×10s, 255=always-on * Byte 6: power_cfg_wifi — 0=default(180s), 1-254=value×10s, 255=always-on * Byte 7: streaming_enabled (0x00=off, 0x01=on) * Byte 8: chunk_flush_interval_s (0=disabled, 1-128=seconds, default 60) * Bytes 9-11: reserved (0x00) */ export declare function serializeConnectionSettings(settings: DeviceConnectionSettings): Buffer; /** * Parse buffer from Bluetooth DEVICE_SETTINGS characteristic into connection settings. * Accepts v0x01 (8 bytes) and v0x02 (12 bytes). Returns defaults for unknown versions. */ export declare function parseConnectionSettings(data: Buffer): DeviceConnectionSettings; //# sourceMappingURL=parsers.d.ts.map