Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jamorham committed Nov 29, 2023
2 parents c74c1dc + bda62e3 commit 5a5681d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
4 changes: 3 additions & 1 deletion app/src/main/java/com/eveningoutpost/dexdrip/BGHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class BGHistory extends ActivityWithMenu {
private int noDays = 1;
private SharedPreferences prefs;
private TextView statisticsTextView;
private static final int SAMPLE_PERIOD = 1; // In minutes - The time between two consecutive readings - The lowest period we currently support: 1 minute
private static final int GRACE_READINGS_PER_DAY = 2; // When switching from one source to another, there may be a misalignment in sample timing resulting in more readings per day

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -148,7 +150,7 @@ private void setupCharts() {

Calendar endDate = (GregorianCalendar) date1.clone();
endDate.add(Calendar.DATE, noDays);
int numValues = noDays * (60 / 2) * 24; // LimiTTer sample rate 1 per 2 minutes
int numValues = noDays * (24 * (60 / SAMPLE_PERIOD) + GRACE_READINGS_PER_DAY); // The highest sample rate we currently support
BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(this, date1.getTimeInMillis(), endDate.getTimeInMillis(), numValues, false);

chart = (LineChartView) findViewById(R.id.chart);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class BackFillStream extends BaseMessage {
private volatile boolean locked = false;

public BackFillStream() {
data = ByteBuffer.allocate(1000);
data = ByteBuffer.allocate(2800);
data.order(ByteOrder.LITTLE_ENDIAN);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public class Ob1G5StateMachine {
private static int LOW_BATTERY_WARNING_LEVEL = Pref.getStringToInt("g5-battery-warning-level", 300); // voltage a < this value raises warnings;
private static final long BATTERY_READ_PERIOD_MS = HOUR_IN_MS * 12; // how often to poll battery data (12 hours)
private static final long MAX_BACKFILL_PERIOD_MS = HOUR_IN_MS * 3; // how far back to request backfill data
private static final long MAX_BACKFILL_PERIOD_MS2 = HOUR_IN_MS * 24; // A larger backfill option
private static final int BACKFILL_CHECK_SMALL = 3;
private static final int BACKFILL_CHECK_LARGE = (int) (MAX_BACKFILL_PERIOD_MS / DEXCOM_PERIOD);

private static final boolean getVersionDetails = true; // try to load firmware version details
private static final boolean getBatteryDetails = true; // try to load battery info details
Expand All @@ -132,6 +132,18 @@ public class Ob1G5StateMachine {
private static volatile boolean backup_loaded = false;
private static final int OLDEST_RAW = 300 * 24 * 60 * 60; // 300 days

public static long maxBackfillPeriod_MS = 0;
public static long maxBackfillPeriod_MS() {
maxBackfillPeriod_MS = MAX_BACKFILL_PERIOD_MS;
if (shortTxId()) { // If using G7
maxBackfillPeriod_MS = MAX_BACKFILL_PERIOD_MS2;
}
return maxBackfillPeriod_MS;
}
public static int backfillCheckLarge() {
return (int) (maxBackfillPeriod_MS() / DEXCOM_PERIOD);
}

// Auth Check + Request
@SuppressLint("CheckResult")
public static boolean doCheckAuth(final Ob1G5CollectionService parent, final RxBleConnection connection) {
Expand Down Expand Up @@ -713,7 +725,7 @@ public static boolean doGetData(Ob1G5CollectionService parent, RxBleConnection c
if (!setStoredFirmwareBytes(getTransmitterID(), 1, bytes, true)) {
UserError.Log.e(TAG, "Could not save out firmware version!");
}
nextBackFillCheckSize = BACKFILL_CHECK_LARGE;
nextBackFillCheckSize = backfillCheckLarge();
if (JoH.ratelimit("g6-evaluate", 600)) {
Inevitable.task("evaluteG6Settings", 10000, () -> evaluateG6Settings());
}
Expand All @@ -723,7 +735,7 @@ public static boolean doGetData(Ob1G5CollectionService parent, RxBleConnection c
if (!setStoredFirmwareBytes(getTransmitterID(), 0, bytes, true)) {
UserError.Log.e(TAG, "Could not save out firmware version!");
}
nextBackFillCheckSize = BACKFILL_CHECK_LARGE;
nextBackFillCheckSize = backfillCheckLarge();
if (JoH.ratelimit("g6-evaluate", 600)) {
Inevitable.task("evaluteG6Settings", 10000, () -> evaluateG6Settings());
}
Expand All @@ -735,7 +747,7 @@ public static boolean doGetData(Ob1G5CollectionService parent, RxBleConnection c
UserError.Log.e(TAG, "Could not save out firmware version!");
}
SensorDays.clearCache();
nextBackFillCheckSize = BACKFILL_CHECK_LARGE;
nextBackFillCheckSize = backfillCheckLarge();
if (JoH.ratelimit("g6-evaluate", 600)) {
Inevitable.task("evaluteG6Settings", 10000, () -> evaluateG6Settings());
}
Expand All @@ -749,7 +761,7 @@ public static boolean doGetData(Ob1G5CollectionService parent, RxBleConnection c
PersistentStore.setBoolean(G5_BATTERY_WEARABLE_SEND, true);
}
}
nextBackFillCheckSize = BACKFILL_CHECK_LARGE;
nextBackFillCheckSize = backfillCheckLarge();
break;

case SessionStartRxMessage:
Expand Down Expand Up @@ -1056,7 +1068,7 @@ private static void backFillIfNeeded(Ob1G5CollectionService parent, RxBleConnect
UserError.Log.d(TAG, "Checking " + check_readings + " for backfill requirement");
final List<BgReading> lastReadings = BgReading.latest_by_size(check_readings);
boolean ask_for_backfill = false;
long earliest_timestamp = tsl() - MAX_BACKFILL_PERIOD_MS;
long earliest_timestamp = tsl() - maxBackfillPeriod_MS();
long latest_timestamp = tsl();
if ((lastReadings == null) || (lastReadings.size() != check_readings)) {
ask_for_backfill = true;
Expand All @@ -1065,7 +1077,7 @@ private static void backFillIfNeeded(Ob1G5CollectionService parent, RxBleConnect
final BgReading reading = lastReadings.get(i);
if ((reading == null) || (msSince(reading.timestamp) > ((DEXCOM_PERIOD * i) + Constants.MINUTE_IN_MS * 7))) {
ask_for_backfill = true;
if ((reading != null) && (msSince(reading.timestamp) <= MAX_BACKFILL_PERIOD_MS)) {
if ((reading != null) && (msSince(reading.timestamp) <= maxBackfillPeriod_MS())) {
earliest_timestamp = reading.timestamp;
}
if (reading != null) {
Expand All @@ -1082,7 +1094,7 @@ private static void backFillIfNeeded(Ob1G5CollectionService parent, RxBleConnect
}

if (ask_for_backfill) {
nextBackFillCheckSize = BACKFILL_CHECK_LARGE;
nextBackFillCheckSize = backfillCheckLarge();
monitorBackFill(parent, connection);
final long startTime = Math.max(earliest_timestamp - (Constants.MINUTE_IN_MS * 5), sensor.started_at);
final long endTime = latest_timestamp + (Constants.MINUTE_IN_MS * 5);
Expand Down Expand Up @@ -1536,6 +1548,9 @@ private static void checkAndActivateSensor() {
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);
}
}
}

Expand Down Expand Up @@ -1868,7 +1883,7 @@ private static void updateStreamedTillTimeForBackfill() {
if (JoH.areWeRunningOnAndroidWear()) {
final String pref_last_send_previous = "last_send_previous";
final long last_send_previous = PersistentStore.getLong(pref_last_send_previous);
PersistentStore.setLong(pref_last_send_previous, Math.min(last_send_previous, tsl() - MAX_BACKFILL_PERIOD_MS));
PersistentStore.setLong(pref_last_send_previous, Math.min(last_send_previous, tsl() - maxBackfillPeriod_MS()));
}
}

Expand All @@ -1878,7 +1893,7 @@ private static void processBacksies(List<BackFillStream.Backsie> backsies) {
final long time = DexTimeKeeper.fromDexTime(getTransmitterID(), backsie.getDextime());

final long since = JoH.msSince(time);
if ((since > HOUR_IN_MS * 6) || (since < 0)) {
if ((!shortTxId() && since > HOUR_IN_MS * 6) || (since > HOUR_IN_MS * 25) || (since < 0)) {
UserError.Log.wtf(TAG, "Backfill timestamp unrealistic: " + JoH.dateTimeText(time) + " (ignored)");
} else {
if (BgReading.getForPreciseTimestamp(time, Constants.MINUTE_IN_MS * 4) == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.eveningoutpost.dexdrip.models.Sensor;
import com.eveningoutpost.dexdrip.R;
import com.eveningoutpost.dexdrip.models.UserError;
import com.eveningoutpost.dexdrip.utilitymodels.Constants;
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
import com.eveningoutpost.dexdrip.utilitymodels.StatusItem.Highlight;
Expand Down Expand Up @@ -102,6 +103,11 @@ public static SensorDays get(DexCollectionType type, final String tx_id) {
ths.warmupMs = 2 * HOUR_IN_MS;
}

if (FirmwareCapability.isDeviceG7(getTransmitterID())) { // If using a G7
ths.period = DAY_IN_MS * 10 + HOUR_IN_MS * 12; // The device lasts 10.5 days.
ths.warmupMs = 30 * MINUTE_IN_MS; // The warmup time is 30 minutes.
}

} else {
// unknown type
}
Expand Down

0 comments on commit 5a5681d

Please sign in to comment.