Skip to content

Commit

Permalink
Merge pull request #1414 from NightscoutFoundation/libresanity-fix
Browse files Browse the repository at this point in the history
Fix the case that sensor was stopped, and started by the user and then new readings started.
  • Loading branch information
jamorham authored Sep 4, 2020
2 parents 5d4ba4b + a5985bc commit edd2c2a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public static boolean checkLibreSensorChangeIfEnabled(final String sn) {

// returns true in the case of an error (had to stop the sensor)
public synchronized static boolean checkLibreSensorChange(final String currentSerial) {
Log.i(TAG, "checkLibreSensorChange called currentSerial = " + currentSerial);
if ((currentSerial == null) || currentSerial.length() < 4) return false;
final Sensor this_sensor = Sensor.currentSensor();
if(this_sensor == null || this_sensor.uuid == null|| this_sensor.uuid.length() < 4) {
Expand All @@ -125,6 +126,7 @@ public synchronized static boolean checkLibreSensorChange(final String currentSe
}
final String lastSn = PersistentStore.getString(PREF_LIBRE_SN);
final String last_uuid = PersistentStore.getString(PREF_LIBRE_SENSOR_UUID);
Log.i(TAG, "checkLibreSensorChange Initial values: lastSn = " + lastSn + " last_uuid = " + last_uuid);
if(lastSn.length() < 4 || last_uuid.length() < 4) {
Log.i(TAG, "lastSn or last_uuid not valid, writing current values.");
PersistentStore.setString(PREF_LIBRE_SENSOR_UUID, this_sensor.uuid);
Expand All @@ -135,6 +137,7 @@ public synchronized static boolean checkLibreSensorChange(final String currentSe
if(lastSn.equals(currentSerial)) {
if(this_sensor.uuid.equals(last_uuid)) {
// all well
Log.i(TAG, "checkLibreSensorChange returning false 1");
return false;
} else {
// This is the case that the user had a sensor, but he stopped it and started a new one in xDrip.
Expand All @@ -158,9 +161,10 @@ public synchronized static boolean checkLibreSensorChange(final String currentSe
return true;

} else {
// This is the first time we see this sensor, update our uuid.
// This is the first time we see this sensor, update our uuid and current serial.
Log.i(TAG, "This is the first time we see this sensor uuid = " + this_sensor.uuid);
PersistentStore.setString(PREF_LIBRE_SENSOR_UUID, this_sensor.uuid);
PersistentStore.setString(PREF_LIBRE_SN, currentSerial);
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,14 @@ public void checkLibreSensorChangeTestRepeatStarting() {
SensorSanity.checkLibreSensorChange("SN333");
this_sensor = Sensor.currentSensor();
assertWithMessage("Expecting this_sensor not to be null without serial change").that(this_sensor).isNotNull();

// A clasic sensor replacement:
// Stop the sensor. Start a new one. call checkLibreSensorChange with the new sensor_sn twice. Sensor should be alive.
Sensor.stopSensor();
Sensor.create(JoH.tsl());
SensorSanity.checkLibreSensorChange("SN444");
SensorSanity.checkLibreSensorChange("SN444");
this_sensor = Sensor.currentSensor();
assertWithMessage("Expecting this_sensor not to be null without serial change").that(this_sensor).isNotNull();
}
}

0 comments on commit edd2c2a

Please sign in to comment.