Skip to content

Commit

Permalink
Merge pull request #3557 from Navid200/Navid_2024_06_29
Browse files Browse the repository at this point in the history
G7 backfill overlap fix
  • Loading branch information
jamorham authored Jul 17, 2024
2 parents 4464060 + 93b2f81 commit db95b03
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
import static com.eveningoutpost.dexdrip.utilitymodels.Constants.HOUR_IN_MS;
import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MINUTE_IN_MS;
import static com.eveningoutpost.dexdrip.utilitymodels.Constants.SECOND_IN_MS;
import static com.eveningoutpost.dexdrip.utils.DexCollectionType.getBestCollectorHardwareName;
import static com.eveningoutpost.dexdrip.utils.bt.Helper.getStatusName;


Expand Down Expand Up @@ -133,6 +134,7 @@ public class Ob1G5StateMachine {
private static volatile AuthRequestTxMessage lastAuthPacket;
private static volatile boolean backup_loaded = false;
private static final int OLDEST_RAW = 300 * 24 * 60 * 60; // 300 days
private static long relAutoSessionStartTime = HOUR_IN_MS * 3;

public static long maxBackfillPeriod_MS = 0;

Expand Down Expand Up @@ -1550,14 +1552,19 @@ private static void processQueueCommand(Ob1G5CollectionService parent, RxBleConn
}

private static void checkAndActivateSensor() {
// automagically start an xDrip sensor session if transmitter already has active sensor
// automagically start an xDrip sensor session if transmitter already has active sensor
if (!Sensor.isActive() && Ob1G5CollectionService.isG5SensorStarted() && (!Sensor.stoppedRecently() || shortTxId())) {
JoH.static_toast_long(xdrip.gs(R.string.auto_starting_sensor));
// TODO possibly here we want to look at last sensor stop time and not backtrack before that
Sensor.create(tsl() - HOUR_IN_MS * 3);
if (shortTxId()) { // If we are using G7
Sensor.create(tsl() - HOUR_IN_MS * 24);
if (shortTxId()) relAutoSessionStartTime = HOUR_IN_MS * 24; // If we are using a G7
final List<BgReading> last = BgReading.latest(1); // Last reading
if ((last != null) && (last.size() > 0)) { // Have we had a reading?
final long now = JoH.tsl();
final long since = now - last.get(0).timestamp; // Time since last reading
if (since < relAutoSessionStartTime) { // If the last reading was less than 3 hours ago, or if we are using G7 and the last reading was less than 24 hours ago
relAutoSessionStartTime = since; // We will start the new session starting from the last reading.
}
}
Sensor.create(tsl() - relAutoSessionStartTime);
}
}

Expand Down

0 comments on commit db95b03

Please sign in to comment.