Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add packetReceiptNotificationParameter to startDFU #138

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion android/src/main/java/com/pilloxa/dfu/RNNordicDfuModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down
4 changes: 3 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
}

Expand Down
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,7 +43,8 @@ function startDFU({
deviceAddress,
deviceName = null,
filePath,
alternativeAdvertisingNameEnabled = true
alternativeAdvertisingNameEnabled = true,
packetReceiptNotificationParameter = 12,
}) {
if (deviceAddress == undefined) {
return rejectPromise("No deviceAddress defined");
Expand All @@ -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);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions ios/RNNordicDfu.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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];
Expand Down