diff --git a/README.md b/README.md index cd405df..693ad8c 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,7 @@ done in React Native. - `obj.deviceAddress` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The `identifier`\* of the device that should be updated - `obj.deviceName` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the device in the update notification (optional, default `null`) - `obj.filePath` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The file system path to the zip-file used for updating + - `obj.packetReceiptNotificationParameter` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** set number of packets of firmware data to be received by the DFU target before sending a new Packet Receipt Notification - defaults to `12` - `obj.alternativeAdvertisingNameEnabled` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Send unique name to device before it is switched into bootloader mode (iOS only) - defaults to `true` \* `identifier` — MAC address (Android) / UUID (iOS) diff --git a/android/src/main/java/com/pilloxa/dfu/RNNordicDfuModule.java b/android/src/main/java/com/pilloxa/dfu/RNNordicDfuModule.java index 4df3737..5938f0e 100644 --- a/android/src/main/java/com/pilloxa/dfu/RNNordicDfuModule.java +++ b/android/src/main/java/com/pilloxa/dfu/RNNordicDfuModule.java @@ -30,7 +30,7 @@ public RNNordicDfuModule(ReactApplicationContext reactContext) { } @ReactMethod - public void startDFU(String address, String name, String filePath, Promise promise) { + public void startDFU(String address, String name, String filePath, int packetReceiptNotificationParameter, Promise promise) { mPromise = promise; final DfuServiceInitiator starter = new DfuServiceInitiator(address) .setKeepBond(false); @@ -39,6 +39,12 @@ public void startDFU(String address, String name, String filePath, Promise promi } starter.setUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(true); starter.setZip(filePath); + // mimic behavior of iOSDFULibrary when packetReceiptNotificationParameter is set to `0` - see: https://github.com/NordicSemiconductor/IOS-Pods-DFU-Library/blob/master/iOSDFULibrary/Classes/Implementation/DFUServiceInitiator.swift#L115 + if (packetReceiptNotificationParameter > 0) { + starter.setPacketsReceiptNotificationsValue(packetReceiptNotificationParameter); + } else { + starter.setPacketsReceiptNotificationsEnabled(false); + } final DfuServiceController controller = starter.start(this.reactContext, DfuService.class); } diff --git a/index.d.ts b/index.d.ts index 8e0ae01..757620e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -4,12 +4,14 @@ declare module 'react-native-nordic-dfu' { deviceAddress, deviceName, filePath, - alternativeAdvertisingNameEnabled + alternativeAdvertisingNameEnabled, + packetReceiptNotificationParameter }: { deviceAddress: string; deviceName?: string; filePath: string | null; alternativeAdvertisingNameEnabled?: boolean; + packetReceiptNotificationParameter?: number; }): Promise; } diff --git a/index.js b/index.js index ac19207..c606e6e 100644 --- a/index.js +++ b/index.js @@ -25,6 +25,7 @@ function rejectPromise(message) { * @param {string} [obj.deviceName = null] The name of the device in the update notification * @param {string} obj.filePath The file system path to the zip-file used for updating * @param {Boolean} obj.alternativeAdvertisingNameEnabled Send unique name to device before it is switched into bootloader mode (iOS only) + * @param {number} obj.packetReceiptNotificationParameter set number of packets of firmware data to be received by the DFU target before sending a new Packet Receipt Notification * @returns {Promise} A promise that resolves or rejects with the `deviceAddress` in the return value * * @example @@ -42,7 +43,8 @@ function startDFU({ deviceAddress, deviceName = null, filePath, - alternativeAdvertisingNameEnabled = true + alternativeAdvertisingNameEnabled = true, + packetReceiptNotificationParameter = 12, }) { if (deviceAddress == undefined) { return rejectPromise("No deviceAddress defined"); @@ -52,9 +54,9 @@ function startDFU({ } const upperDeviceAddress = deviceAddress.toUpperCase(); if (Platform.OS === 'ios') { - return RNNordicDfu.startDFU(upperDeviceAddress, deviceName, filePath, alternativeAdvertisingNameEnabled); + return RNNordicDfu.startDFU(upperDeviceAddress, deviceName, filePath, packetReceiptNotificationParameter, alternativeAdvertisingNameEnabled); } - return RNNordicDfu.startDFU(upperDeviceAddress, deviceName, filePath); + return RNNordicDfu.startDFU(upperDeviceAddress, deviceName, filePath, packetReceiptNotificationParameter); } /** diff --git a/ios/RNNordicDfu.m b/ios/RNNordicDfu.m index ed58530..0c6d5fe 100644 --- a/ios/RNNordicDfu.m +++ b/ios/RNNordicDfu.m @@ -185,6 +185,7 @@ - (void)logWith:(enum LogLevel)level message:(NSString * _Nonnull)message RCT_EXPORT_METHOD(startDFU:(NSString *)deviceAddress deviceName:(NSString *)deviceName filePath:(NSString *)filePath + packetReceiptNotificationParameter:(NSInteger *)packetReceiptNotificationParameter alternativeAdvertisingNameEnabled:(BOOL *)alternativeAdvertisingNameEnabled resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) @@ -226,6 +227,7 @@ - (void)logWith:(enum LogLevel)level message:(NSString * _Nonnull)message initiator.logger = self; initiator.delegate = self; initiator.progressDelegate = self; + initiator.packetReceiptNotificationParameter = packetReceiptNotificationParameter; initiator.alternativeAdvertisingNameEnabled = alternativeAdvertisingNameEnabled; DFUServiceController * controller = [initiator start];