Refactor RFSpy.getFirmWareVersion() for testability
This commit is contained in:
parent
6e30088d1a
commit
9e51f35c41
3 changed files with 10 additions and 20 deletions
|
@ -98,9 +98,9 @@ public class RFSpy {
|
||||||
// firmware version
|
// firmware version
|
||||||
public void initializeRileyLink() {
|
public void initializeRileyLink() {
|
||||||
bleVersion = getVersion();
|
bleVersion = getVersion();
|
||||||
rileyLinkServiceData.firmwareVersion = getFirmwareVersion();
|
String cc1110Version = getCC1110Version();
|
||||||
rileyLinkServiceData.versionCC110 = getCC1110Version();
|
rileyLinkServiceData.versionCC110 = cc1110Version;
|
||||||
|
rileyLinkServiceData.firmwareVersion = getFirmwareVersion(aapsLogger, bleVersion, cc1110Version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -125,12 +125,6 @@ public class RFSpy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRileyLinkStillAvailable() {
|
|
||||||
RileyLinkFirmwareVersion firmwareVersion = getFirmwareVersion();
|
|
||||||
|
|
||||||
return (firmwareVersion != RileyLinkFirmwareVersion.UnknownVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getCC1110Version() {
|
private String getCC1110Version() {
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "Firmware Version. Get Version - Start");
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Firmware Version. Get Version - Start");
|
||||||
|
|
||||||
|
@ -159,11 +153,10 @@ public class RFSpy {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private RileyLinkFirmwareVersion getFirmwareVersion() {
|
static RileyLinkFirmwareVersion getFirmwareVersion(AAPSLogger aapsLogger, String bleVersion, String cc1110Version) {
|
||||||
String versionString = getCC1110Version();
|
if (cc1110Version != null) {
|
||||||
if (versionString != null) {
|
RileyLinkFirmwareVersion version = RileyLinkFirmwareVersion.getByVersionString(cc1110Version);
|
||||||
RileyLinkFirmwareVersion version = RileyLinkFirmwareVersion.getByVersionString(versionString);
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Firmware Version string: {}, resolved to {}.", cc1110Version, version);
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "Firmware Version string: {}, resolved to {}.", versionString, version);
|
|
||||||
|
|
||||||
if (version != RileyLinkFirmwareVersion.UnknownVersion) {
|
if (version != RileyLinkFirmwareVersion.UnknownVersion) {
|
||||||
return version;
|
return version;
|
||||||
|
|
|
@ -18,12 +18,11 @@ public enum RileyLinkFirmwareVersion {
|
||||||
UnknownVersion(null, null, "???"), //
|
UnknownVersion(null, null, "???"), //
|
||||||
Version1(Version_0_0, Version_0_9, Version_1_0), //
|
Version1(Version_0_0, Version_0_9, Version_1_0), //
|
||||||
Version2(Version_2_0, Version_2_2, Version_2_x), //
|
Version2(Version_2_0, Version_2_2, Version_2_x), //
|
||||||
Version2AndHigher(Version2, Version_3_x, Version_4_x), //
|
Version2AndHigher(Version2, Version_3_x, Version_4_x);
|
||||||
;
|
|
||||||
|
|
||||||
private static final String FIRMWARE_IDENTIFICATION_PREFIX = "subg_rfspy ";
|
private static final String FIRMWARE_IDENTIFICATION_PREFIX = "subg_rfspy ";
|
||||||
private static final Pattern _version_pattern = Pattern.compile(FIRMWARE_IDENTIFICATION_PREFIX
|
private static final Pattern _version_pattern = Pattern.compile(FIRMWARE_IDENTIFICATION_PREFIX
|
||||||
+ "([0-9]+)\\.([0-9]+)");
|
+ "([0-9]+)\\.([0-9]+)");
|
||||||
static Map<String, RileyLinkFirmwareVersion> mapByVersion;
|
static Map<String, RileyLinkFirmwareVersion> mapByVersion;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
@ -77,7 +76,7 @@ public enum RileyLinkFirmwareVersion {
|
||||||
return mapByVersion.get(versionKey);
|
return mapByVersion.get(versionKey);
|
||||||
} else {
|
} else {
|
||||||
return defaultToLowestMajorVersion(major); // just in case there is new release that we don't cover
|
return defaultToLowestMajorVersion(major); // just in case there is new release that we don't cover
|
||||||
// example: 2.3 etc
|
// example: 2.3 etc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,6 @@ public class RileyLinkServiceData {
|
||||||
private synchronized RileyLinkServiceState workWithServiceState(RileyLinkServiceState newState, RileyLinkError errorCode, boolean set) {
|
private synchronized RileyLinkServiceState workWithServiceState(RileyLinkServiceState newState, RileyLinkError errorCode, boolean set) {
|
||||||
|
|
||||||
if (set) {
|
if (set) {
|
||||||
|
|
||||||
rileyLinkServiceState = newState;
|
rileyLinkServiceState = newState;
|
||||||
lastServiceStateChange = System.currentTimeMillis();
|
lastServiceStateChange = System.currentTimeMillis();
|
||||||
this.rileyLinkError = errorCode;
|
this.rileyLinkError = errorCode;
|
||||||
|
@ -88,7 +87,6 @@ public class RileyLinkServiceData {
|
||||||
rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItem(rileyLinkServiceState, errorCode, targetDevice));
|
rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItem(rileyLinkServiceState, errorCode, targetDevice));
|
||||||
rxBus.send(new EventRileyLinkDeviceStatusChange(targetDevice, newState, errorCode));
|
rxBus.send(new EventRileyLinkDeviceStatusChange(targetDevice, newState, errorCode));
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return rileyLinkServiceState;
|
return rileyLinkServiceState;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue