From 2eee64dc0dce6a39d40910b5e7f81193cbc9fa2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Both=C3=A9n?= Date: Mon, 28 Feb 2022 08:44:25 +0100 Subject: [PATCH] Add support for binary and hex files In some cases it is more convinient to use a binary or hex file directly instead of using a zip file. We can check the extention and do the appropriate action. --- .../main/java/com/pilloxa/dfu/RNNordicDfuModule.java | 8 +++++++- ios/RNNordicDfu.m | 11 +++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/pilloxa/dfu/RNNordicDfuModule.java b/android/src/main/java/com/pilloxa/dfu/RNNordicDfuModule.java index 6520122..e6216ca 100644 --- a/android/src/main/java/com/pilloxa/dfu/RNNordicDfuModule.java +++ b/android/src/main/java/com/pilloxa/dfu/RNNordicDfuModule.java @@ -38,7 +38,13 @@ public void startDFU(String address, String name, String filePath, Promise promi starter.setDeviceName(name); } starter.setUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(true); - starter.setZip(filePath); + + if (filePath.endsWith(".bin") || filePath.endsWith(".hex")) { + starter.setBinOrHex(DfuBaseService.TYPE_APPLICATION, filePath).setInitFile(null, null); + } else { + starter.setZip(filePath); + } + final DfuServiceController controller = starter.start(this.reactContext, DfuService.class); } diff --git a/ios/RNNordicDfu.m b/ios/RNNordicDfu.m index ed58530..ebfda9e 100644 --- a/ios/RNNordicDfu.m +++ b/ios/RNNordicDfu.m @@ -213,10 +213,17 @@ - (void)logWith:(enum LogLevel)level message:(NSString * _Nonnull)message reject(@"unable_to_find_device", @"Could not find device with deviceAddress", nil); } else { CBPeripheral * peripheral = [peripherals objectAtIndex:0]; + DFUFirmware * firmware; NSURL * url = [NSURL URLWithString:filePath]; - - DFUFirmware * firmware = [[DFUFirmware alloc] initWithUrlToZipFile:url]; + NSString * extension = [url pathExtension]; + + if (([extension caseInsensitiveCompare:@"bin"] == NSOrderedSame) || + ([extension caseInsensitiveCompare:@"hex"] == NSOrderedSame)) { + firmware = [[DFUFirmware alloc] initWithUrlToBinOrHexFile:url urlToDatFile:nil type:4]; + } else { + firmware = [[DFUFirmware alloc] initWithUrlToZipFile:url]; + } DFUServiceInitiator * initiator = [[[DFUServiceInitiator alloc] initWithCentralManager:centralManager