Skip to content

Commit bbcbadd

Browse files
committed
Add back mtu and retries capabilities for android
1 parent a7df6b2 commit bbcbadd

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

android/src/main/java/com/pilloxa/dfu/RNNordicDfuModule.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,37 @@ public RNNordicDfuModule(ReactApplicationContext reactContext) {
3131
}
3232

3333
@ReactMethod
34-
public void startDFU(String address, String name, String filePath, int packetReceiptNotificationParameter, Promise promise) {
34+
public void startDFU(String address, String name, String filePath, int packetReceiptNotificationParameter, ReadableMap options, Promise promise) {
3535
mPromise = promise;
3636
final DfuServiceInitiator starter = new DfuServiceInitiator(address)
3737
.setKeepBond(false);
38+
39+
if (options.hasKey("retries")) {
40+
int retries = options.getInt("retries");
41+
starter.setNumberOfRetries(retries);
42+
}
43+
44+
if (options.hasKey("maxMtu")) {
45+
int mtu = options.getInt("maxMtu");
46+
starter.setMtu(mtu);
47+
}
3848
if (name != null) {
3949
starter.setDeviceName(name);
4050
}
41-
starter.setPacketsReceiptNotificationsValue(1);
51+
// 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
52+
if (packetReceiptNotificationParameter > 0) {
53+
starter.setPacketsReceiptNotificationsValue(packetReceiptNotificationParameter);
54+
} else {
55+
starter.setPacketsReceiptNotificationsValue(1);
56+
starter.setPacketsReceiptNotificationsEnabled(false);
57+
}
4258
starter.setUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(true);
4359
if (filePath.endsWith(".bin") || filePath.endsWith(".hex")) {
4460
starter.setBinOrHex(DfuBaseService.TYPE_APPLICATION, filePath).setInitFile(null, null);
4561
} else {
4662
starter.setZip(filePath);
4763
}
48-
// 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
49-
if (packetReceiptNotificationParameter > 0) {
50-
starter.setPacketsReceiptNotificationsValue(packetReceiptNotificationParameter);
51-
} else {
52-
starter.setPacketsReceiptNotificationsEnabled(false);
53-
}
64+
5465
final DfuServiceController controller = starter.start(this.reactContext, DfuService.class);
5566
}
5667

0 commit comments

Comments
 (0)