public static int secondsSinceReferenceTime(long serial, long time) { final long stored_time = getTime(serial); if (stored_time == 0) return -1; return (int) ((time - stored_time) / 1000); }
private static long getTime(long serial) { return PersistentStore.getLong(getPrefTag(serial)); }
public boolean processForTimeKeeper(long serial) { if (referenceMs > 0) { final long time = JoH.tsl() - referenceMs; UserError.Log.d(TAG, "ReferenceMS equates to: " + JoH.dateTimeText(time)); TimeKeeper.setTime(serial, time); return true; } else { UserError.Log.d(TAG, "ReferenceMS invalid at: " + referenceMs); } return false; }
public CalibrateTx(long serial, long time, int mgdl) throws InvalidAlgorithmParameterException { final int seconds_since = TimeKeeper.secondsSinceReferenceTime(serial, time); if (seconds_since <= 0) { throw new InvalidAlgorithmParameterException("sensor time unknown"); } init(opcode, length, true); data.putShort((short) mgdl); data.putInt(seconds_since); // time since sensor start in seconds - need lag time? data.put((byte) 0x00); // 0 = finger-stick, 1 = other?? } }
private boolean backFillIfNeeded(final AnnexARx annex, int offset) { if (annex == null) return false; if (!annex.isStateOkForBackFill()) return false; final Pair<Long, Long> backfillTimes = BackfillAssessor.check(); if (backfillTimes != null) { int startTick = TimeKeeper.tickCounterFromTimeStamp(serial, backfillTimes.first); int endTick = TimeKeeper.tickCounterFromTimeStamp(serial, backfillTimes.second); if (endTick >= annex.sensorAge) endTick = annex.sensorAge - 1; if (startTick < 62) startTick = 62; // after warmup only if (endTick < 1) endTick = 1; startTick += offset; if ((startTick != endTick) && (endTick > startTick)) { if (endTick - startTick > MAX_BACKFILL_ENTRIES) { endTick = startTick + MAX_BACKFILL_ENTRIES; // only ask this many at once } UserError.Log.d(TAG, "Ask backfill: start: " + startTick + " end: " + endTick); requestedBackfillSize = endTick - startTick; sendTx(new BackFillTx(startTick, endTick)); return true; } else { UserError.Log.d(TAG, "Not backfilling with start and end tick at: " + startTick + " " + endTick); } } return false; }
if (backsies != null) { for (int index = 0; index < backsies.size(); index++) { final long timestamp = timeStampFromTickCounter(serial, backFillRx.sequenceStart + index); UserError.Log.d(TAG, "Backsie: id:" + (backFillRx.sequenceStart + index) + " raw:" + backsies.get(index) + " @ " + JoH.dateTimeText(timestamp)); final long since = msSince(timestamp);
private static long getTime(long serial) { return PersistentStore.getLong(getPrefTag(serial)); }
public boolean processForTimeKeeper(long serial) { if (referenceMs > 0) { final long time = JoH.tsl() - referenceMs; UserError.Log.d(TAG, "ReferenceMS equates to: " + JoH.dateTimeText(time)); TimeKeeper.setTime(serial, time); return true; } else { UserError.Log.d(TAG, "ReferenceMS invalid at: " + referenceMs); } return false; }
public CalibrateTx(long serial, long time, int mgdl) throws InvalidAlgorithmParameterException { final int seconds_since = TimeKeeper.secondsSinceReferenceTime(serial, time); if (seconds_since <= 0) { throw new InvalidAlgorithmParameterException("sensor time unknown"); } init(opcode, length, true); data.putShort((short) mgdl); data.putInt(seconds_since); // time since sensor start in seconds - need lag time? data.put((byte) 0x00); // 0 = finger-stick, 1 = other?? } }
private boolean backFillIfNeeded(final AnnexARx annex, int offset) { if (annex == null) return false; if (!annex.isStateOkForBackFill()) return false; final Pair<Long, Long> backfillTimes = BackfillAssessor.check(); if (backfillTimes != null) { int startTick = TimeKeeper.tickCounterFromTimeStamp(serial, backfillTimes.first); int endTick = TimeKeeper.tickCounterFromTimeStamp(serial, backfillTimes.second); if (endTick >= annex.sensorAge) endTick = annex.sensorAge - 1; if (startTick < 62) startTick = 62; // after warmup only if (endTick < 1) endTick = 1; startTick += offset; if ((startTick != endTick) && (endTick > startTick)) { if (endTick - startTick > MAX_BACKFILL_ENTRIES) { endTick = startTick + MAX_BACKFILL_ENTRIES; // only ask this many at once } UserError.Log.d(TAG, "Ask backfill: start: " + startTick + " end: " + endTick); requestedBackfillSize = endTick - startTick; sendTx(new BackFillTx(startTick, endTick)); return true; } else { UserError.Log.d(TAG, "Not backfilling with start and end tick at: " + startTick + " " + endTick); } } return false; }
if (backsies != null) { for (int index = 0; index < backsies.size(); index++) { final long timestamp = timeStampFromTickCounter(serial, backFillRx.sequenceStart + index); UserError.Log.d(TAG, "Backsie: id:" + (backFillRx.sequenceStart + index) + " raw:" + backsies.get(index) + " @ " + JoH.dateTimeText(timestamp)); final long since = msSince(timestamp);
public static long timeStampFromTickCounter(long serial, int tick) { final long stored_time = getTime(serial); if (stored_time == 0) return -1; return stored_time + (tick * MINUTE_IN_MS * 2); }
public static void setTime(long serial, long time) { if (serial != 0) { if (time >= 1530198145000L) { PersistentStore.setLong(getPrefTag(serial), time); UserError.Log.d(TAG, "Reference Time updated: " + JoH.dateTimeText(time)); } else { UserError.Log.e(TAG, "Time is too far in past: " + JoH.dateText(time)); } } else { UserError.Log.e(TAG, "Serial is not set"); } }
public static int tickCounterFromTimeStamp(long serial, long timestmap) { final long stored_time = getTime(serial); if (stored_time == 0) return -1; return (int) ((timestmap - stored_time) / (MINUTE_IN_MS * 2)); }
public static void setTime(long serial, long time) { if (serial != 0) { if (time >= 1530198145000L) { PersistentStore.setLong(getPrefTag(serial), time); UserError.Log.d(TAG, "Reference Time updated: " + JoH.dateTimeText(time)); } else { UserError.Log.e(TAG, "Time is too far in past: " + JoH.dateText(time)); } } else { UserError.Log.e(TAG, "Serial is not set"); } }
public static long timeStampFromTickCounter(long serial, int tick) { final long stored_time = getTime(serial); if (stored_time == 0) return -1; return stored_time + (tick * MINUTE_IN_MS * 2); }
public static int tickCounterFromTimeStamp(long serial, long timestmap) { final long stored_time = getTime(serial); if (stored_time == 0) return -1; return (int) ((timestmap - stored_time) / (MINUTE_IN_MS * 2)); }
public static int secondsSinceReferenceTime(long serial, long time) { final long stored_time = getTime(serial); if (stored_time == 0) return -1; return (int) ((time - stored_time) / 1000); }