Skip to content

Commit

Permalink
Add back mtu and retries capabilities for android
Browse files Browse the repository at this point in the history
  • Loading branch information
manualexSP committed Jun 28, 2023
1 parent a7df6b2 commit bbcbadd
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions android/src/main/java/com/pilloxa/dfu/RNNordicDfuModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,37 @@ public RNNordicDfuModule(ReactApplicationContext reactContext) {
}

@ReactMethod
public void startDFU(String address, String name, String filePath, int packetReceiptNotificationParameter, Promise promise) {
public void startDFU(String address, String name, String filePath, int packetReceiptNotificationParameter, ReadableMap options, Promise promise) {
mPromise = promise;
final DfuServiceInitiator starter = new DfuServiceInitiator(address)
.setKeepBond(false);

if (options.hasKey("retries")) {
int retries = options.getInt("retries");
starter.setNumberOfRetries(retries);
}

if (options.hasKey("maxMtu")) {
int mtu = options.getInt("maxMtu");
starter.setMtu(mtu);
}
if (name != null) {
starter.setDeviceName(name);
}
starter.setPacketsReceiptNotificationsValue(1);
// 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.setPacketsReceiptNotificationsValue(1);
starter.setPacketsReceiptNotificationsEnabled(false);
}
starter.setUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(true);
if (filePath.endsWith(".bin") || filePath.endsWith(".hex")) {
starter.setBinOrHex(DfuBaseService.TYPE_APPLICATION, filePath).setInitFile(null, null);
} else {
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

0 comments on commit bbcbadd

Please sign in to comment.