Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backfill overlap avoidance #3872

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/src/main/java/com/eveningoutpost/dexdrip/Home.java
Original file line number Diff line number Diff line change
Expand Up @@ -2624,9 +2624,11 @@ private void updateCurrentBgInfoCommon(DexCollectionType collector, TextView not
boolean isSensorActive = Sensor.isActive();

// automagically start an xDrip sensor session if G5 transmitter already has active sensor
if (!isSensorActive && Ob1G5CollectionService.isG5SensorStarted() && !Sensor.stoppedRecently()) {
if (!isSensorActive && Ob1G5CollectionService.isG5SensorStarted() && (!Sensor.stoppedRecently() || shortTxId())) {
JoH.static_toast_long(getString(R.string.auto_starting_sensor));
Sensor.create(tsl() - HOUR_IN_MS * 3);
Sensor.create(tsl() - Ob1G5StateMachine.getLatestReadingsTime()); // Create an internal session after last existing readings
UserError.Log.ueh(TAG, "Started internal session (native session in progress H)");
Treatments.sensorStartIfNeeded();
isSensorActive = Sensor.isActive();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ 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;
private static long noOverlapBackfillRelTime = HOUR_IN_MS * 3;
private static boolean IGNORE_SENSOR = true;

public static long maxBackfillPeriod_MS = 0;

Expand Down Expand Up @@ -1555,17 +1556,23 @@ private static void checkAndActivateSensor() {
// 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));
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() - getLatestReadingsTime()); // Create an internal session after last existing readings
UserError.Log.ueh(TAG, "Started internal session (native session in progress OB)");
Treatments.sensorStartIfNeeded();
}
}

public static long getLatestReadingsTime() { // This is the backfill period, or how long ago we have had our latest readings if more recent than the backfill period.
if (shortTxId()) noOverlapBackfillRelTime = HOUR_IN_MS * 24; // If we are using a G7
final List<BgReading> last = BgReading.latest(1, IGNORE_SENSOR); // Last reading
if ((last != null) && (last.size() > 0)) { // If we have had a reading
final long now = JoH.tsl();
final long since = now - last.get(0).timestamp; // Time since last reading
if (since < noOverlapBackfillRelTime) { // 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
noOverlapBackfillRelTime = since; // We will start the new session starting from the last reading.
}
Sensor.create(tsl() - relAutoSessionStartTime);
}
return noOverlapBackfillRelTime;
}

private static void processGlucoseRxMessage(Ob1G5CollectionService parent, final BaseGlucoseRxMessage glucose) {
Expand Down
Loading