import type { HybridObject } from 'react-native-nitro-modules'; // ─── DFU State ─────────────────────────────────────────────────────────────── export enum DfuState { Connecting = 0, Starting = 1, EnablingDfuMode = 2, Uploading = 3, Validating = 4, Disconnecting = 5, Completed = 6, Aborted = 7, } // ─── DFU Error ─────────────────────────────────────────────────────────────── // Unified error codes covering both iOS (DFUError) and Android (DfuBaseService). // iOS values are used as canonical; native implementations map platform codes. export enum DfuError { // Remote errors — Legacy DFU (1–6) RemoteLegacyDfuInvalidState = 2, RemoteLegacyDfuNotSupported = 3, RemoteLegacyDfuDataExceedsLimit = 4, RemoteLegacyDfuCrcError = 5, RemoteLegacyDfuOperationFailed = 6, // Remote errors — Secure DFU (11–21) RemoteSecureDfuOpCodeNotSupported = 12, RemoteSecureDfuInvalidParameter = 13, RemoteSecureDfuInsufficientResources = 14, RemoteSecureDfuInvalidObject = 15, RemoteSecureDfuSignatureMismatch = 16, RemoteSecureDfuUnsupportedType = 17, RemoteSecureDfuOperationNotPermitted = 18, RemoteSecureDfuOperationFailed = 20, RemoteSecureDfuExtendedError = 21, // Remote errors — Secure DFU Extended (22–33) RemoteExtendedErrorWrongCommandFormat = 22, RemoteExtendedErrorUnknownCommand = 23, RemoteExtendedErrorInitCommandInvalid = 24, RemoteExtendedErrorFwVersionFailure = 25, RemoteExtendedErrorHwVersionFailure = 26, RemoteExtendedErrorSdVersionFailure = 27, RemoteExtendedErrorSignatureMissing = 28, RemoteExtendedErrorWrongHashType = 29, RemoteExtendedErrorHashFailed = 30, RemoteExtendedErrorWrongSignatureType = 31, RemoteExtendedErrorVerificationFailed = 32, RemoteExtendedErrorInsufficientSpace = 33, // Remote errors — Buttonless DFU (91–97) RemoteButtonlessDfuOpCodeNotSupported = 92, RemoteButtonlessDfuOperationFailed = 94, RemoteButtonlessDfuInvalidAdvertisementName = 95, RemoteButtonlessDfuBusy = 96, RemoteButtonlessDfuNotBonded = 97, // Remote errors — Experimental Buttonless DFU (9001–9004) RemoteExperimentalButtonlessDfuOpCodeNotSupported = 9002, RemoteExperimentalButtonlessDfuOperationFailed = 9004, // File / Firmware errors (101–109) FileNotSpecified = 101, FileInvalid = 102, ExtendedInitPacketRequired = 103, InitPacketRequired = 104, FileSizeInvalid = 105, FileTypeUnsupported = 106, FileIOError = 107, // Connection errors (201–209) FailedToConnect = 201, DeviceDisconnected = 202, BluetoothDisabled = 203, DeviceNotBonded = 204, // Service / Protocol errors (301–309, 500) ServiceDiscoveryFailed = 301, DeviceNotSupported = 302, ReadingVersionFailed = 303, EnablingControlPointFailed = 304, WritingCharacteristicFailed = 305, ReceivingNotificationFailed = 306, UnsupportedResponse = 307, BytesLost = 308, CrcError = 309, InvalidInternalState = 500, } // ─── Firmware Type ─────────────────────────────────────────────────────────── export enum DfuFirmwareType { Application = 0, Bootloader = 1, SoftDevice = 2, SoftDeviceBootloader = 3, SoftDeviceBootloaderApplication = 4, } // ─── DFU Options ───────────────────────────────────────────────────────────── export interface DfuOptions { deviceId: string; filePath: string; firmwareType?: DfuFirmwareType; packetReceiptNotificationParameter?: number; forceDfu?: boolean; enableUnsafeExperimentalButtonlessDfu?: boolean; forceScanningForNewAddressInLegacyDfu?: boolean; numberOfRetries?: number; connectionTimeout?: number; dataObjectPreparationDelay?: number; alternativeAdvertisingNameEnabled?: boolean; disableResume?: boolean; } // ─── Callback Types ────────────────────────────────────────────────────────── export type DfuStateCallback = (state: DfuState) => void; export type DfuProgressCallback = ( part: number, totalParts: number, progress: number, currentSpeed: number, avgSpeed: number, ) => void; export type DfuErrorCallback = (error: DfuError, message: string) => void; // ─── HybridObject Spec ────────────────────────────────────────────────────── export interface NativeDfuNitro extends HybridObject<{ ios: 'swift'; android: 'kotlin'; }> { startDfu( options: DfuOptions, stateCallback: DfuStateCallback, progressCallback: DfuProgressCallback, errorCallback: DfuErrorCallback ): void; pauseDfu(): void; resumeDfu(): void; abortDfu(): void; }