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

G7 backfill overlap fix #3557

Merged
merged 2 commits into from
Jul 17, 2024
Merged
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
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
Loading