Java Code Examples for com.eveningoutpost.dexdrip.Home#get_engineering_mode()

The following examples show how to use com.eveningoutpost.dexdrip.Home#get_engineering_mode() . 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: RollCall.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public static List<StatusItem> megaStatus() {
    if (indexed == null) loadIndex();
    GcmActivity.requestRollCall();
    // TODO sort data
    final boolean engineering = Home.get_engineering_mode();
    final boolean desert_sync = DesertSync.isEnabled();
    final String our_wifi_ssid = desert_sync ? wifiString() : "";
    final List<StatusItem> lf = new ArrayList<>();
    for (Map.Entry entry : indexed.entrySet()) {
        final RollCall rc = (RollCall) entry.getValue();
        // TODO refactor with stringbuilder
        lf.add(new StatusItem(rc.role + (desert_sync ? rc.getRemoteWifiIndicate(our_wifi_ssid) : "") + (engineering ? ("\n" + JoH.niceTimeSince(rc.last_seen) + " ago") : ""), rc.bestName() + (desert_sync ? rc.getRemoteIpStatus() : "") + (engineering && rc.batteryValid() ? ("\n" + rc.battery + "%") : "") + (engineering && rc.bridgeBatteryValid() ? (" " + rc.bridge_battery+"%") : "")));
    }

    Collections.sort(lf, new Comparator<StatusItem>() {
        public int compare(StatusItem left, StatusItem right) {
            int val = right.name.replaceFirst("\n.*$", "").compareTo(left.name.replaceFirst("\n.*$", "")); // descending sort ignore second line
            if (val == 0) val = left.value.compareTo(right.value); // ascending sort
            return val;
        }
    });
    // TODO could scan for duplicates and append serial to bestName

    return new ArrayList<>(lf);
}
 
Example 2
Source File: RollCall.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static List<StatusItem> megaStatus() {
    if (indexed == null) loadIndex();
    GcmActivity.requestRollCall();
    // TODO sort data
    final boolean engineering = Home.get_engineering_mode();
    final boolean desert_sync = DesertSync.isEnabled();
    final String our_wifi_ssid = desert_sync ? wifiString() : "";
    final List<StatusItem> lf = new ArrayList<>();
    for (Map.Entry entry : indexed.entrySet()) {
        final RollCall rc = (RollCall) entry.getValue();
        // TODO refactor with stringbuilder
        lf.add(new StatusItem(rc.role + (desert_sync ? rc.getRemoteWifiIndicate(our_wifi_ssid) : "") + (engineering ? ("\n" + JoH.niceTimeSince(rc.last_seen) + " ago") : ""), rc.bestName() + (desert_sync ? rc.getRemoteIpStatus() : "") + (engineering && rc.batteryValid() ? ("\n" + rc.battery + "%") : "") + (engineering && rc.bridgeBatteryValid() ? (" " + rc.bridge_battery+"%") : "")));
    }

    Collections.sort(lf, new Comparator<StatusItem>() {
        public int compare(StatusItem left, StatusItem right) {
            int val = right.name.replaceFirst("\n.*$", "").compareTo(left.name.replaceFirst("\n.*$", "")); // descending sort ignore second line
            if (val == 0) val = left.value.compareTo(right.value); // ascending sort
            return val;
        }
    });
    // TODO could scan for duplicates and append serial to bestName

    return new ArrayList<>(lf);
}
 
Example 3
Source File: DesertComms.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public static List<StatusItem> megaStatus() {
    final List<StatusItem> l = new ArrayList<>();
    if (Home.get_follower()) {
        if (emptyString(getOasisIP())) {
            l.add(new StatusItem("Desert Master", "Not known yet - needs QR code scan?"));
        } else {
            l.add(new StatusItem("Desert Master", getOasisIP(), RouteTools.reachable(getOasisIP()) ? StatusItem.Highlight.NORMAL : StatusItem.Highlight.BAD));
        }
        if (Home.get_engineering_mode()) {
            l.add(new StatusItem("Desert Backup", getOasisBackupIP()));
            l.add(new StatusItem("Our IP", RouteTools.getBestInterfaceAddress()));
        }
    }

    return l;
}
 
Example 4
Source File: Ob1G5StateMachine.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void evaluateG6Settings() {
    if (haveFirmwareDetails()) {
        if (FirmwareCapability.isTransmitterG6(getTransmitterID())) {
            if (!usingG6()) {
                Ob1G5CollectionService.setG6Defaults();
                JoH.showNotification("Enabled G6", "G6 Features and default settings automatically enabled", null, Constants.G6_DEFAULTS_MESSAGE, false, true, false);
            } else if (!onlyUsingNativeMode() && !Home.get_engineering_mode()) {
                // TODO revisit this now that there is scaling
                Ob1G5CollectionService.setG6Defaults();
                JoH.showNotification("Enabled G6", "G6 Native mode enabled", null, Constants.G6_DEFAULTS_MESSAGE, false, true, false);
            }
        }
    }
}
 
Example 5
Source File: BlueJayService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public void schedulePeriodicEvents() {
    final BlueJayInfo info = getInfo();
    if (info.status1Due()) {
        getStatus1();
        if (Home.get_engineering_mode()) {
            getStatus3();
        }
    }
    if (BlueJay.isCollector() && info.status2Due()) {
        getStatus2();
    }
    if (info.isTimeSetDue()) {
        setTime();
    }
    if (info.isDisplayUpdatedue()) {
        if (shouldSendReadings()) {
            Inevitable.task("bj-periodic-display-update", 3000, BlueJay::showLatestBG);
        }
    }


    if (BlueJay.isCollector() && (JoH.msSince(lastUsableGlucoseTimestamp) < MINUTE_IN_MS * 20)) {
        val bf_status = getBackFillStatus();
        if (bf_status.first > 0 && backFillOkayToAsk(bf_status.first)) {
            int records = (int) ((JoH.msSince(bf_status.first) / DEXCOM_PERIOD) + 2);
            UserError.Log.d(TAG, "Earliest backfill time: " + JoH.dateTimeText(bf_status.first) + " Would like " + records + " backfill records");
            final int max_backfill_hours = getMaxBackFillHours();
            getBackFill(Math.min(records, max_backfill_hours * recordsPerHour()));
        }
    } else {
        UserError.Log.d(TAG, "Not checking for backfill data as bluejay is not set as collector");
    }
    UserError.Log.d(TAG, "schedule periodic events done");
    changeNextState();
}
 
Example 6
Source File: Ob1G5StateMachine.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void evaluateG6Settings() {
    if (haveFirmwareDetails()) {
        if (FirmwareCapability.isTransmitterG6(getTransmitterID())) {
            if (!usingG6()) {
                Ob1G5CollectionService.setG6Defaults();
                JoH.showNotification("Enabled G6", "G6 Features and default settings automatically enabled", null, Constants.G6_DEFAULTS_MESSAGE, false, true, false);
            } else if (!onlyUsingNativeMode() && !Home.get_engineering_mode()) {
                // TODO revisit this now that there is scaling
                Ob1G5CollectionService.setG6Defaults();
                JoH.showNotification("Enabled G6", "G6 Native mode enabled", null, Constants.G6_DEFAULTS_MESSAGE, false, true, false);
            }
        }
    }
}
 
Example 7
Source File: BlueJayService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public void schedulePeriodicEvents() {
    final BlueJayInfo info = getInfo();
    if (info.status1Due()) {
        getStatus1();
        if (Home.get_engineering_mode()) {
            getStatus3();
        }
    }
    if (BlueJay.isCollector() && info.status2Due()) {
        getStatus2();
    }
    if (info.isTimeSetDue()) {
        setTime();
    }
    if (info.isDisplayUpdatedue()) {
        if (shouldSendReadings()) {
            Inevitable.task("bj-periodic-display-update", 3000, BlueJay::showLatestBG);
        }
    }


    if (BlueJay.isCollector() && (JoH.msSince(lastUsableGlucoseTimestamp) < MINUTE_IN_MS * 20)) {
        val bf_status = getBackFillStatus();
        if (bf_status.first > 0 && backFillOkayToAsk(bf_status.first)) {
            int records = (int) ((JoH.msSince(bf_status.first) / DEXCOM_PERIOD) + 2);
            UserError.Log.d(TAG, "Earliest backfill time: " + JoH.dateTimeText(bf_status.first) + " Would like " + records + " backfill records");
            final int max_backfill_hours = getMaxBackFillHours();
            getBackFill(Math.min(records, max_backfill_hours * recordsPerHour()));
        }
    } else {
        UserError.Log.d(TAG, "Not checking for backfill data as bluejay is not set as collector");
    }
    UserError.Log.d(TAG, "schedule periodic events done");
    changeNextState();
}
 
Example 8
Source File: Ob1G5StateMachine.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void evaluateG6Settings() {
    if (haveFirmwareDetails()) {
        if (FirmwareCapability.isTransmitterG6(getTransmitterID())) {
            if (!usingG6()) {
                Ob1G5CollectionService.setG6Defaults();
                JoH.showNotification("Enabled G6", "G6 Features and default settings automatically enabled", null, Constants.G6_DEFAULTS_MESSAGE, false, true, false);
            } else if (!onlyUsingNativeMode() && !Home.get_engineering_mode()) {
                // TODO revisit this now that there is scaling
                Ob1G5CollectionService.setG6Defaults();
                JoH.showNotification("Enabled G6", "G6 Native mode enabled", null, Constants.G6_DEFAULTS_MESSAGE, false, true, false);
            }
        }
    }
}
 
Example 9
Source File: Ob1G5StateMachine.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
public static boolean useExtendedTimeTravel() {
    return Pref.getBooleanDefaultFalse("ob1_g5_preemptive_restart_extended_time_travel")
                && (FirmwareCapability.isTransmitterTimeTravelCapable(getTransmitterID())
                || (Pref.getBooleanDefaultFalse("ob1_g5_defer_preemptive_restart_all_firmwares") && Home.get_engineering_mode()));
}
 
Example 10
Source File: LibreWifiReader.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private void readData() {
    // Start very simply by getting only one object and using it.
    Log.e(TAG, "readData called");
    Long LastReportedTime = 0L;
    
    // TODO change that to work based on readings as well ???
    LibreBlock libreBlock = LibreBlock.getLatestForTrend(0L, JoH.tsl() + 5 * 60000); // Allow some packets from the future.
    if (libreBlock != null) {
        LastReportedTime = libreBlock.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", "");
        }
    }
    String recieversIpAddresses;

    // This is the same ip location as for the wixelreader.
    if (!WixelReader.IsConfigured()) {
        Log.e(TAG, "LibreWifiReader not configured");
        return;
    }

    if ((DexCollectionType.getDexCollectionType() == DexCollectionType.Mock) && Home.get_engineering_mode()) {
        recieversIpAddresses = "fake://FAKE_DATA";
    } else {
        recieversIpAddresses = Pref.getString("wifi_recievers_addresses", "");
    }
    int packetsToRead = 1;
    Log.d(TAG, "reading " + packetsToRead + " packets");
    LibreWifiData[] LibreWifiDataArr = Read(recieversIpAddresses, packetsToRead);
    
    Log.d(TAG, "After reading ..." + LibreWifiDataArr);

    if (LibreWifiDataArr == null || LibreWifiDataArr.length == 0) {
        return;
    }
    Log.d(TAG, "After verification ..." + LibreWifiDataArr);
    // Last in the array is the most updated reading we have.
    for (LibreWifiData LastReading : LibreWifiDataArr) {
        // 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 + 4 * 60000) &&
                LastReading.CaptureDateTime < new Date().getTime() + 120000) {
            // We have a real new reading...
            Log.d(TAG, "calling HandleGoodReading from " +  JoH.dateTimeText(LastReading.CaptureDateTime ));

            byte data[] = Base64.decode(LastReading.BlockBytes, Base64.DEFAULT);

            byte patchUid[] = null;
            if (LastReading.patchUid != null && (!LastReading.patchUid.isEmpty())) {
                patchUid = Base64.decode(LastReading.patchUid, Base64.DEFAULT);
            }
            byte patchInfo[] = null;
            if (LastReading.patchInfo != null && (!LastReading.patchInfo.isEmpty())) {        
                patchInfo = Base64.decode(LastReading.patchInfo, Base64.DEFAULT);
            }
            boolean checksum_ok = NFCReaderX.HandleGoodReading(LastReading.SensorId, data, LastReading.CaptureDateTime, false, patchUid, patchInfo);
            if (checksum_ok) {
                // TODO use battery, and other interesting data.
                LastReportedTime = LastReading.CaptureDateTime;
                
                PersistentStore.setString("Tomatobattery", Integer.toString(LastReading.TomatoBatteryLife));
                Pref.setInt("bridge_battery", LastReading.TomatoBatteryLife);
                PersistentStore.setString("TomatoHArdware", LastReading.HwVersion);
                PersistentStore.setString("TomatoFirmware",LastReading.FwVersion);
                Log.i(TAG, "LastReading.SensorId " + LastReading.SensorId);
                PersistentStore.setString("LibreSN", LastReading.SensorId);
                
                
            } else {
                Log.e(TAG, "Recieved a pacjet with bad checksum");
            }
        }
    }
}
 
Example 11
Source File: Ob1G5StateMachine.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
public static boolean useExtendedTimeTravel() {
    return Pref.getBooleanDefaultFalse("ob1_g5_preemptive_restart_extended_time_travel")
                && (FirmwareCapability.isTransmitterTimeTravelCapable(getTransmitterID())
                || (Pref.getBooleanDefaultFalse("ob1_g5_defer_preemptive_restart_all_firmwares") && Home.get_engineering_mode()));
}
 
Example 12
Source File: MedtrumCollectionService.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public static List<StatusItem> megaStatus() {

        if (lastAnnex == null) {
            lastAnnex = com.eveningoutpost.dexdrip.cgm.medtrum.Medtrum.getLastAdvertAnnex();
            // add some advert only marker
        }

        final List<StatusItem> l = new ArrayList<>();

        l.add(new StatusItem("Phone Service State", lastState));
        if (!JoH.emptyString(lastErrorState)) {
            l.add(new StatusItem("Error", lastErrorState, BAD));
        }
        if (lastAnnex != null) {
            l.add(new StatusItem("Battery", lastAnnex.getBatteryPercent() + "%"));
            if (lastAnnex.charging) {
                l.add(new StatusItem("Charging", lastAnnex.charged ? "Charged" : "On charge"));
            }
            l.add(new StatusItem("Sensor State", lastAnnex.getState().getDescription(), lastAnnex.getState() == Ok ? GOOD : NORMAL));

            if (lastAnnex.getState() == SensorState.WarmingUp1) {
                l.add(new StatusItem("Warm up", "Initial warm up", StatusItem.Highlight.NOTICE));
            } else if (lastAnnex.getState() == SensorState.WarmingUp2) {
                final long warmupMinsLeft = ((2 * HOUR_IN_MS) - lastAnnex.getSensorAgeInMs()) / Constants.MINUTE_IN_MS;
                if (warmupMinsLeft > -1 && warmupMinsLeft < 121) {
                    l.add(new StatusItem("Warmup left", warmupMinsLeft + " mins", StatusItem.Highlight.NOTICE));
                }
            }

            if (lastAnnex.getSensorAgeInMs() > 0) {
                l.add(new StatusItem("Sensor Age", lastAnnex.getNiceSensorAge()));
            }

            if (lastAnnex.sensorGood) {
                l.add(new StatusItem("Sensor", "Good", GOOD));
                // } else {
                // if (lastAnnex.getState() == Ok) {
                //     l.add(new StatusItem("Sensor", "Ok", StatusItem.Highlight.NORMAL));
                // }
            }

            if (lastAnnex.sensorError) {
                l.add(new StatusItem("Sensor Error", "Error", BAD));
            }

            if (lastAnnex.sensorFail) {
                l.add(new StatusItem("Sensor Fail", "FAILED", CRITICAL));
            }

            if (lastAnnex.calibrationErrorA) {
                l.add(new StatusItem("Calibration Error", "Error A", BAD));
            }
            if (lastAnnex.calibrationErrorB) {
                l.add(new StatusItem("Calibration Error", "Error B", BAD));
            }

            final Pair<Long, Integer> calibration = Medtrum.getCalibration();
            if (calibration != null) {
                l.add(new StatusItem("Blood test", BgGraphBuilder.unitized_string_with_units_static(calibration.second) + " @ " + JoH.hourMinuteString(calibration.first), StatusItem.Highlight.NOTICE));
            }

            if (serial != 0) {
                final int version = Medtrum.getVersion(serial);
                l.add(new StatusItem("Serial", "" + serial));
                if (version > 0) {
                    final String versionString = "v" + (JoH.qs(version / 100d, 2));
                    l.add(new StatusItem("Firmware", versionString));
                }
            }

            if (lastAnnex.getState() == Ok || lastAnnex.getState() == SensorState.NotCalibrated) {
                l.add(new StatusItem("Slope", JoH.qs(lastAnnex.calibrationSlope / 1000d, 3) + " (" + JoH.qs(1d / (lastAnnex.calibrationSlope / 1000d), 2) + ")"));
                l.add(new StatusItem("Intercept", lastAnnex.calibrationIntercept));
                l.add(new StatusItem("Raw Data", lastAnnex.sensorRaw));
            }

            if (lastAnnex.getState() == Ok) {
                l.add(new StatusItem("Last Glucose", BgGraphBuilder.unitized_string_with_units_static(lastAnnex.calculatedGlucose()) + (lastAnnex.recent() ? "" : " @ " + JoH.niceTimeScalarShort(JoH.msSince(lastAnnex.created))), lastAnnex.recent() ? NORMAL : StatusItem.Highlight.NOTICE));
            }

            if (retry_time != 0) {
                l.add(new StatusItem("Wake up in", JoH.niceTimeScalar(msTill(retry_time))));
            }
            if (failover_time != 0) {
                l.add(new StatusItem("System check in", JoH.niceTimeScalar(msTill(failover_time))));
            }

            if (Home.get_engineering_mode()) {
                l.add(new StatusItem("Brain State", state.getString()));
                l.add(new StatusItem("Last Interaction", JoH.niceTimeScalar(msSince(lastInteractionTime))));
                l.add(new StatusItem("Last Wake Up", JoH.niceTimeScalar(msSince(last_wake_up_time))));
            }

        } else {
            l.add(new StatusItem("Status Information", "Nothing Yet", StatusItem.Highlight.NOTICE));
        }
        return l;
    }
 
Example 13
Source File: Ob1G5StateMachine.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public static boolean useExtendedTimeTravel() {
    return Pref.getBooleanDefaultFalse("ob1_g5_preemptive_restart_extended_time_travel")
                && (FirmwareCapability.isTransmitterTimeTravelCapable(getTransmitterID())
                || (Pref.getBooleanDefaultFalse("ob1_g5_defer_preemptive_restart_all_firmwares") && Home.get_engineering_mode()));
}
 
Example 14
Source File: G5CollectionService.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public static List<StatusItem> megaStatus() {
    final List<StatusItem> l = new ArrayList<>();

    l.add(new StatusItem("Phone Service State", lastState));
    if (static_last_timestamp > 0) {
        l.add(new StatusItem("Phone got Glucose", JoH.niceTimeSince(static_last_timestamp) + " ago"));
    } else {
        if (static_device_address != null) {
            if (Home.get_engineering_mode())
                l.add(new StatusItem("Bluetooth Device", static_device_address));
            l.add(new StatusItem("Bonded", static_is_bonded ? "Yes" : "No", static_is_bonded ? StatusItem.Highlight.GOOD : StatusItem.Highlight.NOTICE));
        } else {
            l.add(new StatusItem("Bluetooth Device", "Not yet found"));
        }
    }

    if (Pref.getBooleanDefaultFalse("wear_sync") &&
            Pref.getBooleanDefaultFalse("enable_wearG5")) {
        l.add(new StatusItem("Watch Service State", lastStateWatch));
        if (static_last_timestamp_watch > 0) {
            l.add(new StatusItem("Watch got Glucose", JoH.niceTimeSince(static_last_timestamp_watch) + " ago"));
        }
    }

    final String tx_id = Pref.getStringDefaultBlank("dex_txid");

    l.add(new StatusItem("Transmitter ID", tx_id));


    // show firmware details
    final VersionRequestRxMessage vr = getFirmwareDetails(tx_id);
    try {
        if ((vr != null) && (vr.firmware_version_string.length() > 0)) {

            l.add(new StatusItem("Firmware Version", vr.firmware_version_string));
            if (Home.get_engineering_mode()) {
                l.add(new StatusItem("Bluetooth Version", vr.bluetooth_firmware_version_string));
                l.add(new StatusItem("Other Version", vr.other_firmware_version));
                l.add(new StatusItem("Hardware Version", vr.hardwarev));
                if (vr.asic != 61440)
                    l.add(new StatusItem("ASIC", vr.asic, StatusItem.Highlight.NOTICE)); // TODO color code
            }
        }
    } catch (NullPointerException e) {
        l.add(new StatusItem("Version", "Information corrupted", StatusItem.Highlight.BAD));
    }

    final BatteryInfoRxMessage bt = getBatteryDetails(tx_id);
    long last_battery_query = PersistentStore.getLong(G5_BATTERY_FROM_MARKER + tx_id);
    if (getBatteryStatusNow) {
        l.add(new StatusItem("Battery Status Request Queued", "Will attempt to read battery status on next sensor reading", StatusItem.Highlight.NOTICE, "long-press",
                new Runnable() {
                    @Override
                    public void run() {
                        getBatteryStatusNow = false;
                    }
                }));
    }
    if ((bt != null) && (last_battery_query > 0)) {
        l.add(new StatusItem("Battery Last queried", JoH.niceTimeSince(last_battery_query) + " " + "ago", StatusItem.Highlight.NORMAL, "long-press",
                new Runnable() {
                    @Override
                    public void run() {
                        getBatteryStatusNow = true;
                    }
                }));
        l.add(new StatusItem("Transmitter Status", TransmitterStatus.getBatteryLevel(vr.status).toString()));
        l.add(new StatusItem("Transmitter Days", bt.runtime + ((last_transmitter_timestamp > 0) ? " / " + JoH.qs((double) last_transmitter_timestamp / 86400, 1) : "")));
        l.add(new StatusItem("Voltage A", bt.voltagea, bt.voltagea < LOW_BATTERY_WARNING_LEVEL ? StatusItem.Highlight.BAD : StatusItem.Highlight.NORMAL));
        l.add(new StatusItem("Voltage B", bt.voltageb, bt.voltageb < (LOW_BATTERY_WARNING_LEVEL - 10) ? StatusItem.Highlight.BAD : StatusItem.Highlight.NORMAL));
        l.add(new StatusItem("Resistance", bt.resist, bt.resist > 1400 ? StatusItem.Highlight.BAD : (bt.resist > 1000 ? StatusItem.Highlight.NOTICE : (bt.resist > 750 ? StatusItem.Highlight.NORMAL : StatusItem.Highlight.GOOD))));
        l.add(new StatusItem("Temperature", bt.temperature + " \u2103"));
    }


    return l;
}
 
Example 15
Source File: WixelReader.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
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: WixelReader.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public static TransmitterRawData[] Read(String hostsNames, int numberOfRecords) {
    String[] hosts = hostsNames.split(",");
    if (hosts.length == 0) {
        Log.e(TAG, "Error no hosts were found " + hostsNames);
        return null;
    }
    List<List<TransmitterRawData>> allTransmitterRawData = new LinkedList<List<TransmitterRawData>>();

    // go over all hosts and read data from them
    for (String host : hosts) {
        host = host.trim();
        List<TransmitterRawData> tmpList;
        if (host.startsWith("mongodb://")) {
            tmpList = ReadFromMongo(host, numberOfRecords);
        } else if ((host.startsWith("http://") || host.startsWith("https://"))
                && host.contains("/json.get")) {
            tmpList = readHttpJson(host, numberOfRecords);
        } else if ((host.startsWith("fake://")
                && (Home.get_engineering_mode())
                && (DexCollectionType.getDexCollectionType() == DexCollectionType.Mock))) {
            tmpList = readFake();
        } else {
            tmpList = ReadHost(host, numberOfRecords);
        }
        if (tmpList != null && tmpList.size() > 0) {
            allTransmitterRawData.add(tmpList);
        }
    }
    // merge the information
    if (allTransmitterRawData.size() == 0) {
        //System.out.println("Could not read anything from " + hostsNames);
        Log.e(TAG, "Could not read anything from " + hostsNames);
        return null;

    }
    final List<TransmitterRawData> mergedData = MergeLists(allTransmitterRawData);

    int retSize = Math.min(numberOfRecords, mergedData.size());
    TransmitterRawData[] trd_array = new TransmitterRawData[retSize];
    mergedData.subList(mergedData.size() - retSize, mergedData.size()).toArray(trd_array);

    //      System.out.println("Final Results========================================================================");
    //       for (int i= 0; i < trd_array.length; i++) {
    //           System.out.println( trd_array[i].toTableString());
    //      }
    return trd_array;

}
 
Example 17
Source File: G5CollectionService.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
public static List<StatusItem> megaStatus() {
    final List<StatusItem> l = new ArrayList<>();

    l.add(new StatusItem("Phone Service State", lastState));
    if (static_last_timestamp > 0) {
        l.add(new StatusItem("Phone got Glucose", JoH.niceTimeSince(static_last_timestamp) + " ago"));
    } else {
        if (static_device_address != null) {
            if (Home.get_engineering_mode())
                l.add(new StatusItem("Bluetooth Device", static_device_address));
            l.add(new StatusItem("Bonded", static_is_bonded ? "Yes" : "No", static_is_bonded ? StatusItem.Highlight.GOOD : StatusItem.Highlight.NOTICE));
        } else {
            l.add(new StatusItem("Bluetooth Device", "Not yet found"));
        }
    }

    if (Pref.getBooleanDefaultFalse("wear_sync") &&
            Pref.getBooleanDefaultFalse("enable_wearG5")) {
        l.add(new StatusItem("Watch Service State", lastStateWatch));
        if (static_last_timestamp_watch > 0) {
            l.add(new StatusItem("Watch got Glucose", JoH.niceTimeSince(static_last_timestamp_watch) + " ago"));
        }
    }

    final String tx_id = Pref.getStringDefaultBlank("dex_txid");

    l.add(new StatusItem("Transmitter ID", tx_id));


    // show firmware details
    final VersionRequestRxMessage vr = getFirmwareDetails(tx_id);
    try {
        if ((vr != null) && (vr.firmware_version_string.length() > 0)) {

            l.add(new StatusItem("Firmware Version", vr.firmware_version_string));
            if (Home.get_engineering_mode()) {
                l.add(new StatusItem("Bluetooth Version", vr.bluetooth_firmware_version_string));
                l.add(new StatusItem("Other Version", vr.other_firmware_version));
                l.add(new StatusItem("Hardware Version", vr.hardwarev));
                if (vr.asic != 61440)
                    l.add(new StatusItem("ASIC", vr.asic, StatusItem.Highlight.NOTICE)); // TODO color code
            }
        }
    } catch (NullPointerException e) {
        l.add(new StatusItem("Version", "Information corrupted", StatusItem.Highlight.BAD));
    }

    final BatteryInfoRxMessage bt = getBatteryDetails(tx_id);
    long last_battery_query = PersistentStore.getLong(G5_BATTERY_FROM_MARKER + tx_id);
    if (getBatteryStatusNow) {
        l.add(new StatusItem("Battery Status Request Queued", "Will attempt to read battery status on next sensor reading", StatusItem.Highlight.NOTICE, "long-press",
                new Runnable() {
                    @Override
                    public void run() {
                        getBatteryStatusNow = false;
                    }
                }));
    }
    if ((bt != null) && (last_battery_query > 0)) {
        l.add(new StatusItem("Battery Last queried", JoH.niceTimeSince(last_battery_query) + " " + "ago", StatusItem.Highlight.NORMAL, "long-press",
                new Runnable() {
                    @Override
                    public void run() {
                        getBatteryStatusNow = true;
                    }
                }));
        l.add(new StatusItem("Transmitter Status", TransmitterStatus.getBatteryLevel(vr.status).toString()));
        l.add(new StatusItem("Transmitter Days", bt.runtime + ((last_transmitter_timestamp > 0) ? " / " + JoH.qs((double) last_transmitter_timestamp / 86400, 1) : "")));
        l.add(new StatusItem("Voltage A", bt.voltagea, bt.voltagea < LOW_BATTERY_WARNING_LEVEL ? StatusItem.Highlight.BAD : StatusItem.Highlight.NORMAL));
        l.add(new StatusItem("Voltage B", bt.voltageb, bt.voltageb < (LOW_BATTERY_WARNING_LEVEL - 10) ? StatusItem.Highlight.BAD : StatusItem.Highlight.NORMAL));
        l.add(new StatusItem("Resistance", bt.resist, bt.resist > 1400 ? StatusItem.Highlight.BAD : (bt.resist > 1000 ? StatusItem.Highlight.NOTICE : (bt.resist > 750 ? StatusItem.Highlight.NORMAL : StatusItem.Highlight.GOOD))));
        l.add(new StatusItem("Temperature", bt.temperature + " \u2103"));
    }


    return l;
}
 
Example 18
Source File: WixelReader.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
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 19
Source File: LibreWifiReader.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public static LibreWifiData[] Read(String hostsNames, int numberOfRecords) {
    String[] hosts = hostsNames.split(",");
    if (hosts.length == 0) {
        Log.e(TAG, "Error no hosts were found " + hostsNames);
        return null;
    }
    List<List<LibreWifiData>> allTransmitterRawData = new LinkedList<List<LibreWifiData>>();

    // go over all hosts and read data from them
    for (String host : hosts) {
        host = host.trim();
        List<LibreWifiData> tmpList;
        if (host.startsWith("mongodb://")) {
            tmpList = ReadFromMongo(host, numberOfRecords);
        }  else if ((host.startsWith("fake://")
                && (Home.get_engineering_mode())
                && (DexCollectionType.getDexCollectionType() == DexCollectionType.Mock))) {
            tmpList = readFake();
        } else {
            tmpList = ReadHost(host, numberOfRecords);
        }
        if (tmpList != null && tmpList.size() > 0) {
            allTransmitterRawData.add(tmpList);
        }
    }
    // merge the information
    if (allTransmitterRawData.size() == 0) {
        //System.out.println("Could not read anything from " + hostsNames);
        Log.e(TAG, "Could not read anything from " + hostsNames);
        return null;

    }
    final List<LibreWifiData> mergedData = MergeLists(allTransmitterRawData);

    int retSize = Math.min(numberOfRecords, mergedData.size());
    LibreWifiData[] trd_array = new LibreWifiData[retSize];
    mergedData.subList(mergedData.size() - retSize, mergedData.size()).toArray(trd_array);

    //      System.out.println("Final Results========================================================================");
    //       for (int i= 0; i < trd_array.length; i++) {
    //           System.out.println( trd_array[i].toTableString());
    //      }
    return trd_array;

}
 
Example 20
Source File: WixelReader.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
public static TransmitterRawData[] Read(String hostsNames, int numberOfRecords) {
    String[] hosts = hostsNames.split(",");
    if (hosts.length == 0) {
        Log.e(TAG, "Error no hosts were found " + hostsNames);
        return null;
    }
    List<List<TransmitterRawData>> allTransmitterRawData = new LinkedList<List<TransmitterRawData>>();

    // go over all hosts and read data from them
    for (String host : hosts) {
        host = host.trim();
        List<TransmitterRawData> tmpList;
        if (host.startsWith("mongodb://")) {
            tmpList = ReadFromMongo(host, numberOfRecords);
        } else if ((host.startsWith("http://") || host.startsWith("https://"))
                && host.contains("/json.get")) {
            tmpList = readHttpJson(host, numberOfRecords);
        } else if ((host.startsWith("fake://")
                && (Home.get_engineering_mode())
                && (DexCollectionType.getDexCollectionType() == DexCollectionType.Mock))) {
            tmpList = readFake();
        } else {
            tmpList = ReadHost(host, numberOfRecords);
        }
        if (tmpList != null && tmpList.size() > 0) {
            allTransmitterRawData.add(tmpList);
        }
    }
    // merge the information
    if (allTransmitterRawData.size() == 0) {
        //System.out.println("Could not read anything from " + hostsNames);
        Log.e(TAG, "Could not read anything from " + hostsNames);
        return null;

    }
    final List<TransmitterRawData> mergedData = MergeLists(allTransmitterRawData);

    int retSize = Math.min(numberOfRecords, mergedData.size());
    TransmitterRawData[] trd_array = new TransmitterRawData[retSize];
    mergedData.subList(mergedData.size() - retSize, mergedData.size()).toArray(trd_array);

    //      System.out.println("Final Results========================================================================");
    //       for (int i= 0; i < trd_array.length; i++) {
    //           System.out.println( trd_array[i].toTableString());
    //      }
    return trd_array;

}