Java Code Examples for com.eveningoutpost.dexdrip.Home#get_master()
The following examples show how to use
com.eveningoutpost.dexdrip.Home#get_master() .
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: NanoStatus.java From xDrip with GNU General Public License v3.0 | 6 votes |
public static void keepFollowerUpdated() { try { if (Home.get_master()) { gsonInstance(); final String serialized = muhGson.toJson(nanoStatusColor("collector")); if (PersistentStore.updateStringIfDifferent(LAST_COLLECTOR_STATUS_STORE, serialized)) { Inevitable.task("update-follower-to-nanostatus", 500, new Runnable() { @Override public void run() { GcmActivity.sendNanoStatusUpdate(PersistentStore.getString(LAST_COLLECTOR_STATUS_STORE)); } }); } } } catch (Exception e) { UserError.Log.wtf(TAG, "Got exception serializing: " + e); } }
Example 2
Source File: Sensor.java From xDrip with GNU General Public License v3.0 | 6 votes |
public static void updateBatteryLevel(Sensor sensor, int sensorBatteryLevel, boolean from_sync) { if (sensorBatteryLevel < 120) { // This must be a wrong battery level. Some transmitter send those every couple of readings // even if the battery is ok. return; } int startBatteryLevel = sensor.latest_battery_level; // if(sensor.latest_battery_level == 0) { // allow sensor battery level to go up and down sensor.latest_battery_level = sensorBatteryLevel; // } else { // sensor.latest_battery_level = Math.min(sensor.latest_battery_level, sensorBatteryLevel); // } if (startBatteryLevel == sensor.latest_battery_level) { // no need to update anything if nothing has changed. return; } sensor.save(); SensorSendQueue.addToQueue(sensor); if ((!from_sync) && (Home.get_master())) { GcmActivity.sendSensorBattery(sensor.latest_battery_level); } }
Example 3
Source File: NanoStatus.java From xDrip with GNU General Public License v3.0 | 6 votes |
public static void keepFollowerUpdated(final String prefix, final int rateLimit) { try { if (Home.get_master()) { UserError.Log.d(TAG, "keepfollower updated called: " + prefix + " " + rateLimit); if (rateLimit == 0 || JoH.pratelimit("keep-follower-updated" + prefix, rateLimit)) { final String serialized = SpannableSerializer.serializeSpannableString(nanoStatusColor(prefix.equals("") ? "collector" : prefix)); if (PersistentStore.updateStringIfDifferent(LAST_COLLECTOR_STATUS_STORE + prefix, serialized)) { Inevitable.task("update-follower-to-nanostatus" + prefix, 500, () -> GcmActivity.sendNanoStatusUpdate(prefix, PersistentStore.getString(LAST_COLLECTOR_STATUS_STORE + prefix))); } } else { UserError.Log.d(TAG, "Ratelimiting keepFollowerUpdated check on " + prefix + " @ " + rateLimit); } } } catch (Exception e) { UserError.Log.wtf(TAG, "Got exception serializing: " + e); } }
Example 4
Source File: NanoStatus.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
public static void keepFollowerUpdated() { try { if (Home.get_master()) { gsonInstance(); final String serialized = muhGson.toJson(nanoStatusColor("collector")); if (PersistentStore.updateStringIfDifferent(LAST_COLLECTOR_STATUS_STORE, serialized)) { Inevitable.task("update-follower-to-nanostatus", 500, new Runnable() { @Override public void run() { GcmActivity.sendNanoStatusUpdate(PersistentStore.getString(LAST_COLLECTOR_STATUS_STORE)); } }); } } } catch (Exception e) { UserError.Log.wtf(TAG, "Got exception serializing: " + e); } }
Example 5
Source File: Sensor.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
public static void updateBatteryLevel(Sensor sensor, int sensorBatteryLevel, boolean from_sync) { if (sensorBatteryLevel < 120) { // This must be a wrong battery level. Some transmitter send those every couple of readings // even if the battery is ok. return; } int startBatteryLevel = sensor.latest_battery_level; // if(sensor.latest_battery_level == 0) { // allow sensor battery level to go up and down sensor.latest_battery_level = sensorBatteryLevel; // } else { // sensor.latest_battery_level = Math.min(sensor.latest_battery_level, sensorBatteryLevel); // } if (startBatteryLevel == sensor.latest_battery_level) { // no need to update anything if nothing has changed. return; } sensor.save(); SensorSendQueue.addToQueue(sensor); if ((!from_sync) && (Home.get_master())) { GcmActivity.sendSensorBattery(sensor.latest_battery_level); } }
Example 6
Source File: NanoStatus.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
public static void keepFollowerUpdated(final String prefix, final int rateLimit) { try { if (Home.get_master()) { UserError.Log.d(TAG, "keepfollower updated called: " + prefix + " " + rateLimit); if (rateLimit == 0 || JoH.pratelimit("keep-follower-updated" + prefix, rateLimit)) { final String serialized = SpannableSerializer.serializeSpannableString(nanoStatusColor(prefix.equals("") ? "collector" : prefix)); if (PersistentStore.updateStringIfDifferent(LAST_COLLECTOR_STATUS_STORE + prefix, serialized)) { Inevitable.task("update-follower-to-nanostatus" + prefix, 500, () -> GcmActivity.sendNanoStatusUpdate(prefix, PersistentStore.getString(LAST_COLLECTOR_STATUS_STORE + prefix))); } } else { UserError.Log.d(TAG, "Ratelimiting keepFollowerUpdated check on " + prefix + " @ " + rateLimit); } } } catch (Exception e) { UserError.Log.wtf(TAG, "Got exception serializing: " + e); } }
Example 7
Source File: DoNothingService.java From xDrip with GNU General Public License v3.0 | 5 votes |
public static List<StatusItem> megaStatus() { final List<StatusItem> l = new ArrayList<>(); if (GcmActivity.cease_all_activity) { l.add(new StatusItem("SYNC DISABLED", Pref.getBooleanDefaultFalse("disable_all_sync") ? "By preference option" : (InstalledApps.isGooglePlayInstalled(xdrip.getAppContext()) ? "Not by preference option" : "By missing Google Play services"), StatusItem.Highlight.CRITICAL)); } if (Home.get_master()) { l.add(new StatusItem("Service State", "We are the Master")); } else { l.add(new StatusItem("Service State", lastState)); updateLastBg(); if (last_bg != null) { l.add(new StatusItem("Glucose Data", JoH.niceTimeSince(last_bg.timestamp) + " ago")); } if (wakeUpErrors > 0) { l.add(new StatusItem("Slow Wake up", JoH.niceTimeScalar(wake_time_difference))); l.add(new StatusItem("Wake Up Errors", wakeUpErrors)); } if (max_wake_time_difference > 0) { l.add(new StatusItem("Slowest Wake up", JoH.niceTimeScalar(max_wake_time_difference))); } if (JoH.buggy_samsung) { l.add(new StatusItem("Buggy Samsung", "Using workaround", max_wake_time_difference < TOLERABLE_JITTER ? StatusItem.Highlight.GOOD : BAD)); } if (nextWakeUpTime != -1) { l.add(new StatusItem("Next Wake up: ", JoH.niceTimeTill(nextWakeUpTime))); } } return l; }
Example 8
Source File: DesertComms.java From xDrip with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("NonAtomicOperationOnVolatileField") private static void checkCommsFailures(boolean failed) { if (failed) { comms_failures++; UserError.Log.d(TAG, "Comms failures increased to: " + comms_failures); if (!Home.get_master()) { if (comms_failures > COMM_FAILURE_NOTIFICATION_THRESHOLD) { if (pratelimit("desert-check-comms", 1800)) { if (!RouteTools.reachable(getOasisIP())) { UserError.Log.e(TAG, "Oasis master IP appears unreachable: " + getOasisIP()); showNotification("Desert Sync Failure", "Master unreachable: " + getOasisIP() + " changed?", null, DESERT_MASTER_UNREACHABLE, false, true, false); } } } } } else { if (!Home.get_master()) { if (comms_failures > 0) { UserError.Log.d(TAG, "Comms restored after " + comms_failures + " failures"); if (comms_failures > COMM_FAILURE_NOTIFICATION_THRESHOLD) { cancelNotification(DESERT_MASTER_UNREACHABLE); } } } comms_failures = 0; // reset counter } }
Example 9
Source File: PumpStatus.java From xDrip with GNU General Public License v3.0 | 5 votes |
public static synchronized void syncUpdate() { if (Home.get_master()) { final String current_json = toJson(); if (current_json.equals(last_json)) { Log.d(TAG, "No sync as data is identical"); } else { Log.d(TAG, "Sending update: " + current_json); GcmActivity.sendPumpStatus(current_json); last_json = current_json; } } }
Example 10
Source File: DoNothingService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public static List<StatusItem> megaStatus() { final List<StatusItem> l = new ArrayList<>(); if (GcmActivity.cease_all_activity) { l.add(new StatusItem("SYNC DISABLED", Pref.getBooleanDefaultFalse("disable_all_sync") ? "By preference option" : (InstalledApps.isGooglePlayInstalled(xdrip.getAppContext()) ? "Not by preference option" : "By missing Google Play services"), StatusItem.Highlight.CRITICAL)); } if (Home.get_master()) { l.add(new StatusItem("Service State", "We are the Master")); } else { l.add(new StatusItem("Service State", lastState)); updateLastBg(); if (last_bg != null) { l.add(new StatusItem("Glucose Data", JoH.niceTimeSince(last_bg.timestamp) + " ago")); } if (wakeUpErrors > 0) { l.add(new StatusItem("Slow Wake up", JoH.niceTimeScalar(wake_time_difference))); l.add(new StatusItem("Wake Up Errors", wakeUpErrors)); } if (max_wake_time_difference > 0) { l.add(new StatusItem("Slowest Wake up", JoH.niceTimeScalar(max_wake_time_difference))); } if (JoH.buggy_samsung) { l.add(new StatusItem("Buggy Samsung", "Using workaround", max_wake_time_difference < TOLERABLE_JITTER ? StatusItem.Highlight.GOOD : BAD)); } if (nextWakeUpTime != -1) { l.add(new StatusItem("Next Wake up: ", JoH.niceTimeTill(nextWakeUpTime))); } } return l; }
Example 11
Source File: DesertComms.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("NonAtomicOperationOnVolatileField") private static void checkCommsFailures(boolean failed) { if (failed) { comms_failures++; UserError.Log.d(TAG, "Comms failures increased to: " + comms_failures); if (!Home.get_master()) { if (comms_failures > COMM_FAILURE_NOTIFICATION_THRESHOLD) { if (pratelimit("desert-check-comms", 1800)) { if (!RouteTools.reachable(getOasisIP())) { UserError.Log.e(TAG, "Oasis master IP appears unreachable: " + getOasisIP()); showNotification("Desert Sync Failure", "Master unreachable: " + getOasisIP() + " changed?", null, DESERT_MASTER_UNREACHABLE, false, true, false); } } } } } else { if (!Home.get_master()) { if (comms_failures > 0) { UserError.Log.d(TAG, "Comms restored after " + comms_failures + " failures"); if (comms_failures > COMM_FAILURE_NOTIFICATION_THRESHOLD) { cancelNotification(DESERT_MASTER_UNREACHABLE); } } } comms_failures = 0; // reset counter } }
Example 12
Source File: PumpStatus.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public static synchronized void syncUpdate() { if (Home.get_master()) { final String current_json = toJson(); if (current_json.equals(last_json)) { Log.d(TAG, "No sync as data is identical"); } else { Log.d(TAG, "Sending update: " + current_json); GcmActivity.sendPumpStatus(current_json); last_json = current_json; } } }
Example 13
Source File: WixelReader.java From xDrip with GNU General Public License v3.0 | 4 votes |
private void readData() { Long LastReportedTime = 0L; TransmitterData lastTransmitterData = TransmitterData.last(); if (lastTransmitterData != null) { LastReportedTime = lastTransmitterData.timestamp; // jamorham fix to avoid going twice to network when we just got a packet if ((new Date().getTime() - LastReportedTime) < DEXCOM_PERIOD - 2000) { Log.d(TAG, "Already have a recent packet - returning"); if (JoH.ratelimit("deferred-msg", 60)) { statusLog(" Deferred", "Already have recent reading"); } return; } else { statusLog(" Deferred", ""); } } Long startReadTime = LastReportedTime; TransmitterRawData LastReportedReading = null; Log.d(TAG, "Starting... LastReportedReading " + LastReportedReading); // try to read one object... TransmitterRawData[] LastReadingArr = null; String recieversIpAddresses; if (!WixelReader.IsConfigured()) { return; } if ((DexCollectionType.getDexCollectionType() == DexCollectionType.Mock) && Home.get_engineering_mode()) { recieversIpAddresses = "fake://FAKE_DATA"; } else { recieversIpAddresses = Pref.getString("wifi_recievers_addresses", ""); } // How many packets should we read? we look at the maximum time between last calibration and last reading time // and calculate how much are needed. final Calibration lastCalibration = Calibration.lastValid(); if (lastCalibration != null) { startReadTime = Math.max(startReadTime, lastCalibration.timestamp); } Long gapTime = new Date().getTime() - startReadTime + 120000; int packetsToRead = (int) (gapTime / (5 * 60000)); packetsToRead = Math.min(packetsToRead, 200); // don't read too much, but always read 1. packetsToRead = Math.max(packetsToRead, 1); Log.d(TAG, "reading " + packetsToRead + " packets"); LastReadingArr = Read(recieversIpAddresses, packetsToRead); if (LastReadingArr == null || LastReadingArr.length == 0) { return; } for (TransmitterRawData LastReading : LastReadingArr) { // Last in the array is the most updated reading we have. //TransmitterRawData LastReading = LastReadingArr[LastReadingArr.length -1]; //if (LastReading.CaptureDateTime > LastReportedReading + 5000) { // Make sure we do not report packets from the far future... if ((LastReading.CaptureDateTime > LastReportedTime + 120000) && (!almostEquals(LastReading, LastReportedReading)) && LastReading.CaptureDateTime < new Date().getTime() + 120000) { // We have a real new reading... Log.d(TAG, "calling setSerialDataToTransmitterRawData " + LastReading.RawValue + " LastReading.CaptureDateTime " + LastReading.CaptureDateTime + " " + LastReading.TransmissionId); setSerialDataToTransmitterRawData(LastReading.RawValue, LastReading.FilteredValue, LastReading.BatteryLife, LastReading.CaptureDateTime); LastReportedReading = LastReading; LastReportedTime = LastReading.CaptureDateTime; if (LastReading.UploaderBatteryLife > 0) { Pref.setInt("parakeet_battery", LastReading.UploaderBatteryLife); CheckBridgeBattery.checkParakeetBattery(); if (Home.get_master()) { GcmActivity.sendParakeetBattery(LastReading.UploaderBatteryLife); } } } } }
Example 14
Source File: SensorSendQueue.java From xDrip with GNU General Public License v3.0 | 4 votes |
public static void SendToFollower(Sensor sensor) { // SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(xdrip.getAppContext()); if(Home.get_master()) { GcmActivity.syncSensor(sensor, true); } }
Example 15
Source File: WixelReader.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
private void readData() { Long LastReportedTime = 0L; TransmitterData lastTransmitterData = TransmitterData.last(); if (lastTransmitterData != null) { LastReportedTime = lastTransmitterData.timestamp; // jamorham fix to avoid going twice to network when we just got a packet if ((new Date().getTime() - LastReportedTime) < DEXCOM_PERIOD - 2000) { Log.d(TAG, "Already have a recent packet - returning"); if (JoH.ratelimit("deferred-msg", 60)) { statusLog(" Deferred", "Already have recent reading"); } return; } else { statusLog(" Deferred", ""); } } Long startReadTime = LastReportedTime; TransmitterRawData LastReportedReading = null; Log.d(TAG, "Starting... LastReportedReading " + LastReportedReading); // try to read one object... TransmitterRawData[] LastReadingArr = null; String recieversIpAddresses; if (!WixelReader.IsConfigured()) { return; } if ((DexCollectionType.getDexCollectionType() == DexCollectionType.Mock) && Home.get_engineering_mode()) { recieversIpAddresses = "fake://FAKE_DATA"; } else { recieversIpAddresses = Pref.getString("wifi_recievers_addresses", ""); } // How many packets should we read? we look at the maximum time between last calibration and last reading time // and calculate how much are needed. final Calibration lastCalibration = Calibration.lastValid(); if (lastCalibration != null) { startReadTime = Math.max(startReadTime, lastCalibration.timestamp); } Long gapTime = new Date().getTime() - startReadTime + 120000; int packetsToRead = (int) (gapTime / (5 * 60000)); packetsToRead = Math.min(packetsToRead, 200); // don't read too much, but always read 1. packetsToRead = Math.max(packetsToRead, 1); Log.d(TAG, "reading " + packetsToRead + " packets"); LastReadingArr = Read(recieversIpAddresses, packetsToRead); if (LastReadingArr == null || LastReadingArr.length == 0) { return; } for (TransmitterRawData LastReading : LastReadingArr) { // Last in the array is the most updated reading we have. //TransmitterRawData LastReading = LastReadingArr[LastReadingArr.length -1]; //if (LastReading.CaptureDateTime > LastReportedReading + 5000) { // Make sure we do not report packets from the far future... if ((LastReading.CaptureDateTime > LastReportedTime + 120000) && (!almostEquals(LastReading, LastReportedReading)) && LastReading.CaptureDateTime < new Date().getTime() + 120000) { // We have a real new reading... Log.d(TAG, "calling setSerialDataToTransmitterRawData " + LastReading.RawValue + " LastReading.CaptureDateTime " + LastReading.CaptureDateTime + " " + LastReading.TransmissionId); setSerialDataToTransmitterRawData(LastReading.RawValue, LastReading.FilteredValue, LastReading.BatteryLife, LastReading.CaptureDateTime); LastReportedReading = LastReading; LastReportedTime = LastReading.CaptureDateTime; if (LastReading.UploaderBatteryLife > 0) { Pref.setInt("parakeet_battery", LastReading.UploaderBatteryLife); CheckBridgeBattery.checkParakeetBattery(); if (Home.get_master()) { GcmActivity.sendParakeetBattery(LastReading.UploaderBatteryLife); } } } } }
Example 16
Source File: SensorSendQueue.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
public static void SendToFollower(Sensor sensor) { // SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(xdrip.getAppContext()); if(Home.get_master()) { GcmActivity.syncSensor(sensor, true); } }