From 6e30088d1addfdc2c602b22ba5b477915ff40108 Mon Sep 17 00:00:00 2001 From: Artiom Kenibasov Date: Thu, 17 Dec 2020 20:46:36 +0100 Subject: [PATCH] Now AAPS recognizes firmwares different than 2.0 and 2.2 Also, the exact version string is shown in the RL Status window --- .../pump/common/hw/rileylink/ble/RFSpy.java | 36 ++++++++++++------- .../hw/rileylink/ble/data/RadioResponse.java | 2 +- .../ble/defs/RileyLinkFirmwareVersion.java | 21 +++++------ .../RileyLinkStatusGeneralFragment.java | 6 ++-- .../service/RileyLinkBroadcastReceiver.java | 2 +- .../service/RileyLinkServiceData.java | 5 +-- 6 files changed, 41 insertions(+), 31 deletions(-) diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java index 5bec93fb4c..1aaa9e5008 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java @@ -99,6 +99,8 @@ public class RFSpy { public void initializeRileyLink() { bleVersion = getVersion(); rileyLinkServiceData.firmwareVersion = getFirmwareVersion(); + rileyLinkServiceData.versionCC110 = getCC1110Version(); + } @@ -129,9 +131,7 @@ public class RFSpy { return (firmwareVersion != RileyLinkFirmwareVersion.UnknownVersion); } - - private RileyLinkFirmwareVersion getFirmwareVersion() { - + private String getCC1110Version() { aapsLogger.debug(LTag.PUMPBTCOMM, "Firmware Version. Get Version - Start"); for (int i = 0; i < 5; i++) { @@ -146,19 +146,30 @@ public class RFSpy { if (response != null) { // && response[0] == (byte) 0xDD) { String versionString = StringUtil.fromBytes(response); - - RileyLinkFirmwareVersion version = RileyLinkFirmwareVersion.getByVersionString(StringUtil - .fromBytes(response)); - - aapsLogger.debug(LTag.PUMPBTCOMM, "Firmware Version string: {}, resolved to {}.", versionString, version); - - if (version != RileyLinkFirmwareVersion.UnknownVersion) - return version; - + if (versionString.length() > 3) { + if (versionString.indexOf('s') >= 0) { + versionString = versionString.substring(versionString.indexOf('s')); + } + return versionString; + } SystemClock.sleep(1000); } } + return null; + } + + private RileyLinkFirmwareVersion getFirmwareVersion() { + String versionString = getCC1110Version(); + if (versionString != null) { + RileyLinkFirmwareVersion version = RileyLinkFirmwareVersion.getByVersionString(versionString); + aapsLogger.debug(LTag.PUMPBTCOMM, "Firmware Version string: {}, resolved to {}.", versionString, version); + + if (version != RileyLinkFirmwareVersion.UnknownVersion) { + return version; + } + } + aapsLogger.error(LTag.PUMPBTCOMM, "Firmware Version can't be determined. Checking with BLE Version [{}].", bleVersion); if (bleVersion.contains(" 2.")) { @@ -168,7 +179,6 @@ public class RFSpy { return RileyLinkFirmwareVersion.UnknownVersion; } - private byte[] writeToDataRaw(byte[] bytes, int responseTimeout_ms) { SystemClock.sleep(100); // FIXME drain read queue? diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/data/RadioResponse.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/data/RadioResponse.java index dccf3a5c15..d2033aa429 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/data/RadioResponse.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/data/RadioResponse.java @@ -74,7 +74,7 @@ public class RadioResponse { } byte[] encodedPayload; - if (RileyLinkFirmwareVersion.isSameVersion(rileyLinkServiceData.versionCC110, + if (RileyLinkFirmwareVersion.isSameVersion(rileyLinkServiceData.firmwareVersion, RileyLinkFirmwareVersion.Version2AndHigher)) { encodedPayload = ByteUtil.substring(rxData, 3, rxData.length - 3); rssi = rxData[1]; diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/defs/RileyLinkFirmwareVersion.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/defs/RileyLinkFirmwareVersion.java index 1a6b42c443..47e61e9bf6 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/defs/RileyLinkFirmwareVersion.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/defs/RileyLinkFirmwareVersion.java @@ -12,12 +12,13 @@ public enum RileyLinkFirmwareVersion { Version_1_0(1, 0, "1.0"), // Version_2_0(2, 0, "2.0"), // Version_2_2(2, 2, "2.2"), // - Version_3_x(3, 0, "3.x"), // - Version_4_x(4, 0, "4.x"), // - UnknownVersion(0, 0, "???"), // + Version_2_x(2, null, "2.x"), // + Version_3_x(3, null, "3.x"), // + Version_4_x(4, null, "4.x"), // + UnknownVersion(null, null, "???"), // Version1(Version_0_0, Version_0_9, Version_1_0), // - Version2(Version_2_0, Version_2_2), // - Version2AndHigher(Version_2_0, Version_2_2, Version_3_x, Version_4_x), // + Version2(Version_2_0, Version_2_2, Version_2_x), // + Version2AndHigher(Version2, Version_3_x, Version_4_x), // ; private static final String FIRMWARE_IDENTIFICATION_PREFIX = "subg_rfspy "; @@ -35,12 +36,12 @@ public enum RileyLinkFirmwareVersion { } protected RileyLinkFirmwareVersion[] familyMembers; - private int major; - private int minor; + private Integer major; + private Integer minor; private String versionKey = ""; - RileyLinkFirmwareVersion(int major, int minor, String versionKey) { + RileyLinkFirmwareVersion(Integer major, Integer minor, String versionKey) { this.major = major; this.minor = minor; this.versionKey = versionKey; @@ -86,8 +87,8 @@ public enum RileyLinkFirmwareVersion { private static RileyLinkFirmwareVersion defaultToLowestMajorVersion(int major) { - if (mapByVersion.containsKey(major + ".0")) { - return mapByVersion.get(major + ".0"); + if (mapByVersion.containsKey(major + ".x")) { + return mapByVersion.get(major + ".x"); } return UnknownVersion; } diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java index 6f4462a470..85cf96a350 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java @@ -108,13 +108,11 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re "-" : resourceHelper.gs(rileyLinkServiceData.rileyLinkError.getResourceId(targetDevice))); - RileyLinkFirmwareVersion firmwareVersion = rileyLinkServiceData.versionCC110; - if (firmwareVersion == null) { this.firmwareVersion.setText("BLE113: -\nCC110: -"); } else { - this.firmwareVersion.setText("BLE113: " + rileyLinkServiceData.versionBLE113 + // - "\nCC110: " + firmwareVersion.toString()); + this.firmwareVersion.setText("BLE113: " + rileyLinkServiceData.versionBLE113 + + "\nCC110: " + rileyLinkServiceData.versionCC110); } } diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java index 337f8b5527..b240f8bc0b 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java @@ -159,7 +159,7 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver { // if (isLoggingEnabled()) aapsLogger.debug(LTag.PUMPBTCOMM, "RfSpy Radio version (CC110): " + rlVersion.name()); - this.rileyLinkServiceData.versionCC110 = rlVersion; + this.rileyLinkServiceData.firmwareVersion = rlVersion; ServiceTask task = new InitializePumpManagerTask(injector, context); serviceTaskExecutor.startTask(task); diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java index 02b27846bc..f1050b4656 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java @@ -32,7 +32,7 @@ public class RileyLinkServiceData { public RileyLinkError rileyLinkError; public RileyLinkServiceState rileyLinkServiceState = RileyLinkServiceState.NotStarted; private long lastServiceStateChange = 0L; - public RileyLinkFirmwareVersion firmwareVersion; + public RileyLinkFirmwareVersion firmwareVersion; // here we have "compatibility level" version public RileyLinkTargetFrequency rileyLinkTargetFrequency; public String rileylinkAddress; long lastTuneUpTime = 0L; @@ -41,7 +41,8 @@ public class RileyLinkServiceData { // bt version public String versionBLE113; // radio version - public RileyLinkFirmwareVersion versionCC110; + public String versionCC110; + public RileyLinkTargetDevice targetDevice;