Java Code Examples for com.eveningoutpost.dexdrip.UtilityModels.Constants#MINUTE_IN_MS
The following examples show how to use
com.eveningoutpost.dexdrip.UtilityModels.Constants#MINUTE_IN_MS .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PebbleDisplayAbstract.java From xDrip with GNU General Public License v3.0 | 6 votes |
synchronized void pebble_watchdog(boolean online, String tag) { if (online) { last_seen_timestamp = JoH.tsl(); } else { if (last_seen_timestamp == 0) return; if ((JoH.msSince(last_seen_timestamp) > 20 * Constants.MINUTE_IN_MS)) { if (!JoH.isOngoingCall()) { last_seen_timestamp = JoH.tsl(); if (Pref.getBooleanDefaultFalse("bluetooth_watchdog")) { UserError.Log.e(tag, "Triggering pebble watchdog reset!"); JoH.restartBluetooth(xdrip.getAppContext()); } else { UserError.Log.e(tag, "Would have Triggered pebble watchdog reset but bluetooth watchdog is disabled"); } } else { UserError.Log.d(tag, "Ongoing call blocking pebble watchdog reset"); } } } }
Example 2
Source File: DexCollectionService.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
private void watchdog() { if (last_time_seen == 0) return; if (prefs.getBoolean("bluetooth_watchdog", false)) { int MAX_BT_WDG = 20; int bt_wdg_timer = JoH.parseIntWithDefault(Pref.getString("bluetooth_watchdog_timer", Integer.toString(MAX_BT_WDG)), 10, MAX_BT_WDG); if ((bt_wdg_timer <= 5) || (bt_wdg_timer > MAX_BT_WDG)) { bt_wdg_timer = MAX_BT_WDG; } if ((JoH.msSince(last_time_seen)) > bt_wdg_timer * Constants.MINUTE_IN_MS) { Log.d(TAG, "Use BT Watchdog timer=" + bt_wdg_timer); if (!JoH.isOngoingCall()) { Log.e(TAG, "Watchdog triggered, attempting to reset bluetooth"); status("Watchdog triggered"); JoH.restartBluetooth(getApplicationContext()); last_time_seen = JoH.tsl(); watchdog_count++; if (watchdog_count > 5) last_time_seen = 0; } else { Log.e(TAG, "Delaying watchdog reset as phone call is ongoing."); } } } }
Example 3
Source File: DexCollectionService.java From xDrip with GNU General Public License v3.0 | 5 votes |
private long whenToRetryNext() { final long poll_time = Math.max((Constants.SECOND_IN_MS * 10) + retry_backoff, RETRY_PERIOD - JoH.msSince(lastPacketTime)); if (retry_backoff < (Constants.MINUTE_IN_MS)) { retry_backoff += Constants.SECOND_IN_MS; } Log.d(TAG, "Scheduling next retry in: " + JoH.niceTimeScalar(poll_time) + " @ " + JoH.dateTimeText(poll_time + JoH.tsl()) + " period diff: " + (RETRY_PERIOD - JoH.msSince(lastPacketTime))); return poll_time; }
Example 4
Source File: SensorDays.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
private long getLibreStart() { try { val age_minutes = Pref.getInt("nfc_sensor_age", -50000); if (age_minutes > 0) { return tsl() - (age_minutes * Constants.MINUTE_IN_MS); } else { return Sensor.currentSensor().started_at; } } catch (Exception e) { return -1; } }
Example 5
Source File: APStatus.java From xDrip with GNU General Public License v3.0 | 5 votes |
public static List<APStatus> latestForGraph(int number, long startTime, long endTime) { try { final List<APStatus> results = new Select() .from(APStatus.class) .where("timestamp >= " + Math.max(startTime, 0)) .where("timestamp <= " + endTime) .orderBy("timestamp asc") // warn asc! .limit(number) .execute(); // extend line to now if we have current data but it is continuation of last record // so not generating a new efficient record. if (results != null && (results.size() > 0)) { final APStatus last = results.get(results.size() - 1); final long last_raw_record_timestamp = ExternalStatusService.getLastStatusLineTime(); // check are not already using the latest. if (last_raw_record_timestamp > last.timestamp) { final Integer last_recorded_tbr = ExternalStatusService.getTBRInt(); if (last_recorded_tbr != null) { if ((last.basal_percent == last_recorded_tbr) && (JoH.msSince(last.timestamp) < Constants.HOUR_IN_MS * 3) && (JoH.msSince(ExternalStatusService.getLastStatusLineTime()) < Constants.MINUTE_IN_MS * 20)) { results.add(new APStatus(JoH.tsl(), last_recorded_tbr)); UserError.Log.d(TAG, "Adding extension record"); } } } } return results; } catch (android.database.sqlite.SQLiteException e) { updateDB(); return new ArrayList<>(); } }
Example 6
Source File: BgToSpeech.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public static void speak(final double value, long timestamp, String delta_name) { // don't read out old values. if (JoH.msSince(timestamp) > 4 * Constants.MINUTE_IN_MS) { return; } // TODO As we check for this in new data observer should we only check for ongoing call here? // check if speech is enabled and extra check for ongoing call if (!(Pref.getBooleanDefaultFalse(BG_TO_SPEECH_PREF) || VehicleMode.shouldSpeak()) || JoH.isOngoingCall()) { return; } // check constraints final long change_time = getMinutesSliderValue(Pref.getInt("speak_readings_change_time", 0)) * Constants.MINUTE_IN_MS; boolean conditions_met = false; if (lastSpokenSince() < change_time) { UserError.Log.d(TAG, "Not speaking due to change time threshold: " + JoH.niceTimeScalar(change_time) + " vs " + JoH.niceTimeScalar(lastSpokenSince())); } else { UserError.Log.d(TAG, "Speaking due to change time threshold: " + JoH.niceTimeScalar(change_time) + " vs " + JoH.niceTimeScalar(lastSpokenSince())); conditions_met = true; } if (!conditions_met) { if (!thresholdExceeded(value)) { UserError.Log.d(TAG, "Not speaking due to change delta threshold: " + value); return; } } updateLastSpokenSince(); realSpeakNow(value, timestamp, delta_name); }
Example 7
Source File: DexCollectionService.java From xDrip with GNU General Public License v3.0 | 5 votes |
public synchronized void setFailoverTimer() { if (shouldServiceRun()) { final long retry_in = use_polling ? whenToPollNext() : (Constants.MINUTE_IN_MS * 6); Log.d(TAG, "setFailoverTimer: Fallover Restarting in: " + (retry_in / (Constants.MINUTE_IN_MS)) + " minutes"); //serviceFailoverIntent = PendingIntent.getService(this, Constants.DEX_COLLECTION_SERVICE_FAILOVER_ID, new Intent(this, this.getClass()), 0); serviceFailoverIntent = WakeLockTrampoline.getPendingIntent(this.getClass(), Constants.DEX_COLLECTION_SERVICE_FAILOVER_ID); failover_time = JoH.wakeUpIntent(this, retry_in, serviceFailoverIntent); retry_time = 0; // only one alarm will run } else { stopSelf(); } }
Example 8
Source File: DexCollectionService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public synchronized void setFailoverTimer() { if (shouldServiceRun()) { final long retry_in = use_polling ? whenToPollNext() : (Constants.MINUTE_IN_MS * 6); Log.d(TAG, "setFailoverTimer: Fallover Restarting in: " + (retry_in / (Constants.MINUTE_IN_MS)) + " minutes"); //serviceFailoverIntent = PendingIntent.getService(this, Constants.DEX_COLLECTION_SERVICE_FAILOVER_ID, new Intent(this, this.getClass()), 0); serviceFailoverIntent = WakeLockTrampoline.getPendingIntent(this.getClass(), Constants.DEX_COLLECTION_SERVICE_FAILOVER_ID); failover_time = JoH.wakeUpIntent(this, retry_in, serviceFailoverIntent); retry_time = 0; // only one alarm will run } else { stopSelf(); } }
Example 9
Source File: MedtrumCollectionService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
private void setFailOverTimer() { if (shouldServiceRun()) { if (quietratelimit("mt-failover-cooldown", 30)) { final long retry_in = Constants.MINUTE_IN_MS * 7; UserError.Log.d(TAG, "setFailOverTimer: Restarting in: " + (retry_in / Constants.SECOND_IN_MS) + " seconds"); // serviceFailoverIntent = PendingIntent.getService(this, MEDTRUM_SERVICE_FAILOVER_ID, // new Intent(this, this.getClass()), 0); serviceFailoverIntent = WakeLockTrampoline.getPendingIntent(this.getClass(), MEDTRUM_SERVICE_FAILOVER_ID); failover_time = JoH.wakeUpIntent(this, retry_in, serviceFailoverIntent); } } else { UserError.Log.d(TAG, "Not setting retry timer as service should not be running"); } }
Example 10
Source File: CheckBridgeBattery.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public static void checkParakeetBattery() { if (!Pref.getBooleanDefaultFalse("bridge_battery_alerts")) return; threshold = Pref.getStringToInt("bridge_battery_alert_level", 30); final int this_level = Pref.getInt(PARAKEET_PREFS_ITEM, -1); if (last_parakeet_level == -1) { last_parakeet_level = (int) PersistentStore.getLong(LAST_PARAKEET_PREFS_ITEM); } if (d) UserError.Log.e(TAG, "checkParakeetBattery threshold:" + threshold + " this_level:" + this_level + " last:" + last_parakeet_level); if ((this_level > 0) && (threshold > 0)) { if ((this_level < threshold) && (this_level < last_parakeet_level)) { if (JoH.pratelimit("parakeet-battery-warning", repeat_seconds)) { parakeet_notification_showing = true; final PendingIntent pendingIntent = android.app.PendingIntent.getActivity(xdrip.getAppContext(), 0, new Intent(xdrip.getAppContext(), Home.class), android.app.PendingIntent.FLAG_UPDATE_CURRENT); cancelNotification(PARAKEET_NOTIFICATION_ITEM); showNotification(xdrip.getAppContext().getString(R.string.low_parakeet_battery), "Parakeet battery dropped to: " + this_level + "%", pendingIntent, PARAKEET_NOTIFICATION_ITEM, NotificationChannels.LOW_BRIDGE_BATTERY_CHANNEL, true, true, null, null, null); last_parakeet_notification = JoH.tsl(); if (d) UserError.Log.e(TAG, "checkParakeetBattery RAISED ALERT threshold:" + threshold + " this_level:" + this_level + " last:" + last_parakeet_level); } } else { if ((parakeet_notification_showing) && (JoH.msSince(last_parakeet_level) > Constants.MINUTE_IN_MS * 25)) { cancelNotification(PARAKEET_NOTIFICATION_ITEM); parakeet_notification_showing = false; } } last_parakeet_level = this_level; PersistentStore.setLong(LAST_PARAKEET_PREFS_ITEM, this_level); } }
Example 11
Source File: BlueJayService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public void sendGlucose() { val last = BgReading.last(); if (last != null && msSince(last.timestamp) < Constants.HOUR_IN_MS) { val info = BlueJayInfo.getInfo(BlueJay.getMac()); if (Math.abs(info.lastReadingTime - last.timestamp) > Constants.MINUTE_IN_MS * 3) { val glucoseTx = new GlucoseTx(last); if (glucoseTx.isValid()) { val item = new QueueMe() .setBytes(glucoseTx.getBytes()) .expireInSeconds(60) .setDescription("Glucose to watch"); item.setProcessor(new AuthReplyProcessor(new ReplyProcessor(I.connection) { @Override public void process(byte[] bytes) { UserError.Log.d(TAG, "Glucose Incoming reply processor: " + HexDump.dumpHexString(bytes)); info.displayUpdated(); } }).setTag(item)); item.queue(); doQueue(); } else { UserError.Log.d(TAG, "GlucoseTX wasn't valid so not sending."); } } else { UserError.Log.d(TAG, "Watch already has recent reading"); // watch reading too close to the reading we were going to send } } }
Example 12
Source File: DexCollectionService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
private long whenToPollNext() { final long poll_time = Math.max((Constants.SECOND_IN_MS * 5) + poll_backoff, POLLING_PERIOD - JoH.msSince(lastPacketTime)); if (poll_backoff < (Constants.MINUTE_IN_MS * 6)) { poll_backoff += Constants.SECOND_IN_MS; } Log.d(TAG, "Scheduling next poll in: " + JoH.niceTimeScalar(poll_time) + " @ " + JoH.dateTimeText(poll_time + JoH.tsl()) + " period diff: " + (POLLING_PERIOD - JoH.msSince(lastPacketTime))); return poll_time; }
Example 13
Source File: BgReading.java From xDrip with GNU General Public License v3.0 | 5 votes |
public static void deleteRandomData() { Random rand = new Random(); int minutes_ago_end = rand.nextInt(120); int minutes_ago_start = minutes_ago_end + rand.nextInt(35)+5; long ts_start = JoH.tsl() - minutes_ago_start * Constants.MINUTE_IN_MS; long ts_end = JoH.tsl() - minutes_ago_end * Constants.MINUTE_IN_MS; UserError.Log.d(TAG,"Deleting random bgreadings: "+JoH.dateTimeText(ts_start)+" -> "+JoH.dateTimeText(ts_end)); testDeleteRange(ts_start, ts_end); }
Example 14
Source File: SensorDays.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
boolean cacheValid() { return msSince(created) < Constants.MINUTE_IN_MS * 10; }
Example 15
Source File: DesertComms.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
boolean okToProcess() { return msSince(lastProcessedTime) > Constants.MINUTE_IN_MS; }
Example 16
Source File: Ob1G5CollectionService.java From xDrip with GNU General Public License v3.0 | 4 votes |
public static boolean isCollecting() { return (state == CONNECT_NOW && JoH.msSince(static_last_timestamp) < Constants.MINUTE_IN_MS * 30) || JoH.msSince(static_last_timestamp) < Constants.MINUTE_IN_MS * 6; }
Example 17
Source File: Ob1G5StateMachine.java From xDrip with GNU General Public License v3.0 | 4 votes |
private static void backFillIfNeeded(Ob1G5CollectionService parent, RxBleConnection connection) { final int check_readings = nextBackFillCheckSize; 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 latest_timestamp = tsl(); if ((lastReadings == null) || (lastReadings.size() != check_readings)) { ask_for_backfill = true; } else { for (int i = 0; i < lastReadings.size(); i++) { 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)) { earliest_timestamp = reading.timestamp; } if (reading != null) { UserError.Log.d(TAG, "Flagging backfill tripped by reading: " + i + " at time: " + JoH.dateTimeText(reading.timestamp) + " creating backfill window: " + JoH.dateTimeText(earliest_timestamp)); } else { UserError.Log.d(TAG, "Flagging backfill tripped by null reading: " + i); } break; } else { // good record latest_timestamp = reading.timestamp; } } } if (ask_for_backfill) { nextBackFillCheckSize = BACKFILL_CHECK_LARGE; monitorBackFill(parent, connection); final long startTime = earliest_timestamp - (Constants.MINUTE_IN_MS * 5); final long endTime = latest_timestamp + (Constants.MINUTE_IN_MS * 5); UserError.Log.d(TAG, "Requesting backfill between: " + JoH.dateTimeText(startTime) + " " + JoH.dateTimeText(endTime)); enqueueUniqueCommand( BackFillTxMessage.get(getTransmitterID(), startTime, endTime), "Get backfill since: " + JoH.hourMinuteString(startTime)); } else { nextBackFillCheckSize = BACKFILL_CHECK_SMALL; } }
Example 18
Source File: AnticipateTestRobolectric.java From xDrip with GNU General Public License v3.0 | 4 votes |
@Test // look for the first failure for issue as they are daisy chained public void nextTest() { final long now = 1545157669000L; final long last = now - Constants.MINUTE_IN_MS; // Tuesday 18. December 2018 18:27:49 assertWithMessage("first now time").that(now).isEqualTo(1545157669000L); // Tuesday 18. December 2018 18:26:49 assertWithMessage("first last time").that(last).isEqualTo(1545157609000L); //System.out.println("Time lst: "+ dateTimeText(last)); // System.out.println("Time now: "+ dateTimeText(now)); long next = next(now, last); // recent reading assertWithMessage("next 0").that(dateTimeText(next)).isEqualTo("2018-12-18 18:31:39"); next = next(next, last); assertWithMessage("next 1").that(dateTimeText(next)).isEqualTo("2018-12-18 18:31:49"); next = next(next, last); assertWithMessage("next 2").that(dateTimeText(next)).isEqualTo("2018-12-18 18:31:59"); next = next(next, last); assertWithMessage("next 3").that(dateTimeText(next)).isEqualTo("2018-12-18 18:32:09"); next = next(next, last); // Modulus calculation assertWithMessage("next 4").that(dateTimeText(next)).isEqualTo("2018-12-18 18:36:39"); next = next(next, last); assertWithMessage("next 5").that(dateTimeText(next)).isEqualTo("2018-12-18 18:36:49"); next = next(next, last); assertWithMessage("next 6").that(dateTimeText(next)).isEqualTo("2018-12-18 18:36:59"); next = next(next, last); assertWithMessage("next 7").that(dateTimeText(next)).isEqualTo("2018-12-18 18:37:09"); next = next(next, last); assertWithMessage("next 8").that(dateTimeText(next)).isEqualTo("2018-12-18 18:41:39"); next = next(next, last); assertWithMessage("next 9").that(dateTimeText(next)).isEqualTo("2018-12-18 18:41:49"); next = next(next - Constants.SECOND_IN_MS, last); assertWithMessage("next -1").that(dateTimeText(next)).isEqualTo("2018-12-18 18:41:49"); next = next(next + Constants.SECOND_IN_MS, last); assertWithMessage("next +1").that(dateTimeText(next)).isEqualTo("2018-12-18 18:41:59"); next = next(now, 0); assertWithMessage("next from 0").that(dateTimeText(next)).isEqualTo("2018-12-18 18:29:50"); }
Example 19
Source File: BackfillAssessor.java From xDrip with GNU General Public License v3.0 | 4 votes |
public static Pair<Long, Long> check() { final int check_readings = nextBackFillCheckSize; UserError.Log.d(TAG, "Checking " + check_readings + " for backfill requirement"); final List<BgReading> lastReadings = BgReading.latest_by_size(check_readings); // newest first boolean ask_for_backfill = false; long check_timestamp = JoH.tsl(); // TODO can this be merged with latest timestamp?? long earliest_timestamp = JoH.tsl() - MAX_BACKFILL_PERIOD_MS; long latest_timestamp = JoH.tsl(); if ((lastReadings == null) || (lastReadings.size() != check_readings)) { ask_for_backfill = true; } else { // find a gap larger than specified period for (int i = 0; i < lastReadings.size(); i++) { final BgReading reading = lastReadings.get(i); // TODO this can't handle readings more frequent than dexcom period if ((reading == null) || (check_timestamp - reading.timestamp) > (DEXCOM_PERIOD + (Constants.MINUTE_IN_MS * 2))) { ask_for_backfill = true; if ((reading != null) && (msSince(reading.timestamp) <= MAX_BACKFILL_PERIOD_MS)) { earliest_timestamp = reading.timestamp; } if (reading != null) { UserError.Log.d(TAG, "Flagging backfill tripped by reading: " + i + " at time: " + JoH.dateTimeText(reading.timestamp) + " creating backfill window: " + JoH.dateTimeText(earliest_timestamp)); } else { UserError.Log.d(TAG, "Flagging backfill tripped by null reading: " + i); } break; } else { // good record latest_timestamp = reading.timestamp; check_timestamp = reading.timestamp; } } } if (ask_for_backfill) { nextBackFillCheckSize = BACKFILL_CHECK_LARGE; final long startTime = earliest_timestamp - (Constants.MINUTE_IN_MS * 5); final long endTime = latest_timestamp + (Constants.MINUTE_IN_MS * 5); UserError.Log.d(TAG, "Requesting backfill between: " + JoH.dateTimeText(startTime) + " " + JoH.dateTimeText(endTime)); return new Pair<>(startTime, endTime); } else { nextBackFillCheckSize = BACKFILL_CHECK_SMALL; return null; } }
Example 20
Source File: BlueJayInfo.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
public boolean isDisplayUpdatedue() { return msSince(displayLastUpdated) > (Constants.MINUTE_IN_MS * 10); }