Java Code Examples for com.eveningoutpost.dexdrip.Models.UserError.Log#wtf()

The following examples show how to use com.eveningoutpost.dexdrip.Models.UserError.Log#wtf() . 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: DexCollectionService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private void closeCycle(boolean should_close) {
    if (mBluetoothGatt != null) {
        try {
            if (JoH.ratelimit("refresh-gatt", 60)) {
                Log.d(TAG, "Refresh result close: " + JoH.refreshDeviceCache(TAG, mBluetoothGatt));
            }
            if (should_close) {
                Log.i(TAG, "connect: mBluetoothGatt isn't null, Closing.");
                mBluetoothGatt.close();
            } else {
                Log.i(TAG, "preserving existing connection");
            }
        } catch (NullPointerException e) {
            Log.wtf(TAG, "Concurrency related null pointer in connect");
        } finally {
            if (should_close) mBluetoothGatt = null;
        }
    }
}
 
Example 2
Source File: ActiveBgAlert.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public static AlertType alertTypegetOnly() {
    ActiveBgAlert aba = getOnly();

    if (aba == null) {
        Log.v(TAG, "ActiveBgAlert: alertTypegetOnly returning null");
        return null;
    }

    AlertType alert = AlertType.get_alert(aba.alert_uuid);
    if(alert == null) {
        Log.d(TAG, "alertTypegetOnly did not find the active alert as part of existing alerts. returning null");
        // removing the alert to be in a better state.
        ClearData();
        return null;
    }
    if(!alert.uuid.equals(aba.alert_uuid)) {
        Log.wtf(TAG, "AlertType.get_alert did not return the correct alert");
    }
    return alert;
}
 
Example 3
Source File: AlertType.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public static AlertType HigherAlert(AlertType a1, AlertType a2) {
    if (a1.above && !a2.above) {
        return a2;
    }
    if (!a1.above && a2.above) {
        return a1;
    }
    if (a1.above && a2.above) {
        // both are high, the higher the better
        if (a1.threshold > a2.threshold) {
            return a1;
        } else {
            return a2;
        }
    }
    if (a1.above || a2.above) {
        Log.wtf(TAG, "a1.above and a2.above must be false");
    }
    // both are low, the lower the better
    if (a1.threshold < a2.threshold) {
        return a1;
    } else {
        return a2;
    }
}
 
Example 4
Source File: ActiveBgAlert.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static AlertType alertTypegetOnly(final ActiveBgAlert aba) {

        if (aba == null) {
            Log.v(TAG, "ActiveBgAlert: alertTypegetOnly returning null");
            return null;
        }

        AlertType alert = AlertType.get_alert(aba.alert_uuid);
        if(alert == null) {
            Log.d(TAG, "alertTypegetOnly did not find the active alert as part of existing alerts. returning null");
            // removing the alert to be in a better state.
            ClearData();
            return null;
        }
        if(!alert.uuid.equals(aba.alert_uuid)) {
            Log.wtf(TAG, "AlertType.get_alert did not return the correct alert");
        }
        return alert;
    }
 
Example 5
Source File: AlertType.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static AlertType HigherAlert(AlertType a1, AlertType a2) {
    if (a1.above && !a2.above) {
        return a2;
    }
    if (!a1.above && a2.above) {
        return a1;
    }
    if (a1.above && a2.above) {
        // both are high, the higher the better
        if (a1.threshold > a2.threshold) {
            return a1;
        } else {
            return a2;
        }
    }
    if (a1.above || a2.above) {
        Log.wtf(TAG, "a1.above and a2.above must be false");
    }
    // both are low, the lower the better
    if (a1.threshold < a2.threshold) {
        return a1;
    } else {
        return a2;
    }
}
 
Example 6
Source File: DexCollectionService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private void closeCycle(boolean should_close) {
    if (mBluetoothGatt != null) {
        try {
            if (JoH.ratelimit("refresh-gatt", 60)) {
                Log.d(TAG, "Refresh result close: " + JoH.refreshDeviceCache(TAG, mBluetoothGatt));
            }
            if (should_close) {
                Log.i(TAG, "connect: mBluetoothGatt isn't null, Closing.");
                mBluetoothGatt.close();
            } else {
                Log.i(TAG, "preserving existing connection");
            }
        } catch (NullPointerException e) {
            Log.wtf(TAG, "Concurrency related null pointer in connect");
        } finally {
            if (should_close) mBluetoothGatt = null;
        }
    }
}
 
Example 7
Source File: G5CollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static VersionRequestRxMessage getFirmwareDetails(String tx_id) {
    try {
        byte[] stored = getStoredFirmwareBytes(tx_id);
        if ((stored != null) && (stored.length > 9)) {
            return new VersionRequestRxMessage(stored);
        }
    } catch (Exception e) {
        Log.wtf(TAG, "Exception in getFirmwareDetails: " + e);
        return null;
    }
    return null;
}
 
Example 8
Source File: GcmActivity.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private static void fmSend(Bundle data) {
    final FirebaseMessaging fm = FirebaseMessaging.getInstance();
    if (senderid != null) {
        fm.send(new RemoteMessage.Builder(senderid + "@gcm.googleapis.com")
                .setMessageId(Integer.toString(msgId.incrementAndGet()))
                .setData(JoH.bundleToMap(data))
                .build());
    } else {
        Log.wtf(TAG, "senderid is null");
    }
}
 
Example 9
Source File: ActiveBgAlert.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static boolean alertSnoozeOver() {
    ActiveBgAlert activeBgAlert = getOnly();
    if (activeBgAlert == null) {
        // no alert exists, so snoozing is over... (this should not happen)
        Log.wtf(TAG, "ActiveBgAlert getOnly returning null (we have just checked it)");
        return true;
    }
    return activeBgAlert.ready_to_alarm();
}
 
Example 10
Source File: ActiveBgAlert.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
public static boolean alertSnoozeOver() {
    ActiveBgAlert activeBgAlert = getOnly();
    if (activeBgAlert == null) {
        // no alert exists, so snoozing is over... (this should not happen)
        Log.wtf(TAG, "ActiveBgAlert getOnly returning null (we have just checked it)");
        return true;
    }
    return activeBgAlert.ready_to_alarm();
}
 
Example 11
Source File: AlertPlayer.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public synchronized void PreSnooze(Context ctx, String uuid, int repeatTime) {
    Log.i(TAG, "PreSnooze called repeatTime = "+ repeatTime);
    stopAlert(ctx, true, false);
    ActiveBgAlert.Create(uuid, true, new Date().getTime() + repeatTime * 60000);
    ActiveBgAlert activeBgAlert = ActiveBgAlert.getOnly();
    if (activeBgAlert  == null) {
        Log.wtf(TAG, "Just created the alert, where did it go...");
        return;
    }
    activeBgAlert.snooze(repeatTime);
}
 
Example 12
Source File: Preferences.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onSearchResultClicked(@NonNull SearchPreferenceResult searchPreferenceResult) {
    try {
        searchPreferenceResult.closeSearchPage(this);
        searchPreferenceResult.highlight(this.preferenceFragment, Color.YELLOW);
    } catch (RuntimeException e) {
        Log.wtf(TAG, "Got error trying to highlight search results: " + e);
        JoH.static_toast_long("" + e);
    }
}
 
Example 13
Source File: G5CollectionService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static BatteryInfoRxMessage getBatteryDetails(final String tx_id) {
    try {
        final byte[] batteryStoredBytes = PersistentStore.getBytes(G5_BATTERY_MARKER + tx_id);
        return batteryStoredBytes.length > 0 ? new BatteryInfoRxMessage(batteryStoredBytes) : null;
    } catch (Exception e) {
        Log.wtf(TAG, "Exception in getFirmwareDetails: " + e);
        return null;
    }
}
 
Example 14
Source File: blueReader.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
public static byte[] decodeblueReaderPacket(byte[] buffer, int len) {
    int cmdFound = 0;
    long timestamp = new Date().getTime();
    String bufferstring;
    //Log.w(TAG, "Packet: " + bufferstring);
    if (buffer == null) {
        Log.e(TAG, "null buffer passed to decodeblueReaderPacket");
        return null;
    } else {
        bufferstring=new String(buffer);
    }
    if (bufferstring.startsWith("not ready for") ) { //delete the trans_failed, because its normal only if the bluereader could not read the sensor.
        counterHibernated++;
        Log.e(TAG, "Found blueReader in a ugly State (" + counterHibernated + "/3), send hibernate to reset! If this does not help in the next 5 Minutes, then turn the bluereader manually off and on!");
        if (counterHibernated > 2) {
            Log.wtf(TAG, "Ugly state not resolveable. Bluereader will be shut down! Please restart it!");
            Home.toaststatic("BlueReader ugly state not resolveable, bluereader will be shut down. Please restart it!");
            if (!Pref.getBooleanDefaultFalse("blueReader_suppressuglystatemsg")) {
                Notifications.RiseDropAlert(xdrip.getAppContext(),true,"BlueReader Alarm", xdrip.getAppContext().getString(R.string.bluereaderuglystate),1);
            }
            return shutdown;
        } else {
            Home.toaststatic("Found blueReader in a ugly State, send hibernate to reset!");
            return goHybernate; //send hard hibernate, because blueReader is in a ugly state
        }
    } else if (bufferstring.startsWith("IDR")){
        Log.i(TAG, bufferstring);
        PersistentStore.setString("blueReaderFirmware", bufferstring );
        tempVers=Pattern.compile(".*\\|blue(.*)-.*").matcher(bufferstring);
        tempVers.find();
        PersistentStore.setDouble("blueReaderFirmwareValue",Double.parseDouble(tempVers.group(1)));
        Log.i(TAG, "bluereader-Firmware-Version: " + tempVers);
        if (BgReading.last() == null || BgReading.last().timestamp + (4 * 60 * 1000) < System.currentTimeMillis()) {
            return requestValue;
        } else {
            return null;
        }
    } else if (bufferstring.startsWith("WAKE")) {
        Log.d (TAG, "blueReader was set to wakeup-mode manually...");
        return null;
    } else if (bufferstring.startsWith("ECHO")) {
        Log.d (TAG, "blueReader was set to Echo-Mode manually...");
        return null;
    } else if (bufferstring.startsWith("NFC READY")) {
        Log.d (TAG, "blueReader notice that NFC is active...");
        return null;
    } else if (bufferstring.startsWith("NFC_DISABLED")) {
        Log.d (TAG, "blueReader notice that NFC is now hibernated...");
        return null;
    } else if (bufferstring.startsWith("HYBERNATE SUCCESS")) {
        Log.i (TAG, "blueReader notice that NFC is now really hibernated...");
        if (counterHibernated > 0) {
            Log.w (TAG,"Found hibernation after wrong read. Resend read-command...");
            return requestValue;
        } else {
            return null;
        }
    } else if (bufferstring.startsWith("-r 0:")) {
        Log.d (TAG, "blueReader sends an unknown reaction: '" + bufferstring + "'");
        return null;
    } else if (bufferstring.startsWith("TRANS_FAILED")) {
        Log.w (TAG, "Attention: check position of blueReader on the sensor, as it was not able to read!");
        Home.toaststatic(xdrip.getAppContext().getString(R.string.bluereader_position));
        return null;
    } else if (bufferstring.startsWith("battery: ")) {
        if (BgReading.last() == null || BgReading.last().timestamp + (4 * 60 * 1000) < System.currentTimeMillis()) {
            return requestValue;
        }
    } else {
        counterHibernated = 0;
        processNewTransmitterData(TransmitterData.create(buffer, len, timestamp), timestamp);
        // check for shutdown blueReader if Battery is too low
        if (Pref.getBooleanDefaultFalse("blueReader_turn_off")) {
            if (Pref.getInt("blueReader_turn_off_value",5) > Pref.getInt("bridge_battery",100)) {
                Log.w (TAG, "blueReader will be turn off, as the battery is lower then " + Pref.getInt("blueReader_turn_off_value",5) +"%");
                Home.toaststatic(xdrip.getAppContext().getString(R.string.bluereaderoff) + Pref.getInt("blueReader_turn_off_value",5) +"%");
                return shutdown;
            }
        }
    }

    return null;
}
 
Example 15
Source File: BgReading.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
public static BgReading createFromRawNoSave(Sensor sensor, Calibration calibration, double raw_data, double filtered_data, long timestamp) {
    final BgReading bgReading = new BgReading();
    if (sensor == null) {
        sensor = Sensor.currentSensor();
        if (sensor == null) {
            return bgReading;
        }
    }
    if (calibration == null) {
        calibration = Calibration.lastValid();
        if (calibration == null) {
            return bgReading;
        }
    }

    bgReading.sensor = sensor;
    bgReading.sensor_uuid = sensor.uuid;
    bgReading.calibration = calibration;
    bgReading.calibration_uuid = calibration.uuid;
    bgReading.raw_data = (raw_data / 1000);
    bgReading.filtered_data = (filtered_data / 1000);
    bgReading.timestamp = timestamp;
    bgReading.uuid = UUID.randomUUID().toString();
    bgReading.time_since_sensor_started = bgReading.timestamp - sensor.started_at;

    bgReading.calculateAgeAdjustedRawValue();

    if (calibration.check_in) {
        double firstAdjSlope = calibration.first_slope + (calibration.first_decay * (Math.ceil(new Date().getTime() - calibration.timestamp) / (1000 * 60 * 10)));
        double calSlope = (calibration.first_scale / firstAdjSlope) * 1000;
        double calIntercept = ((calibration.first_scale * calibration.first_intercept) / firstAdjSlope) * -1;
        bgReading.calculated_value = (((calSlope * bgReading.raw_data) + calIntercept) - 5);
        bgReading.filtered_calculated_value = (((calSlope * bgReading.ageAdjustedFiltered()) + calIntercept) - 5);

    } else {
        BgReading lastBgReading = BgReading.last();
        if (lastBgReading != null && lastBgReading.calibration != null) {
            Log.d(TAG, "Create calibration.uuid=" + calibration.uuid + " bgReading.uuid: " + bgReading.uuid + " lastBgReading.calibration_uuid: " + lastBgReading.calibration_uuid + " lastBgReading.calibration.uuid: " + lastBgReading.calibration.uuid);
            Log.d(TAG, "Create lastBgReading.calibration_flag=" + lastBgReading.calibration_flag + " bgReading.timestamp: " + bgReading.timestamp + " lastBgReading.timestamp: " + lastBgReading.timestamp + " lastBgReading.calibration.timestamp: " + lastBgReading.calibration.timestamp);
            Log.d(TAG, "Create lastBgReading.calibration_flag=" + lastBgReading.calibration_flag + " bgReading.timestamp: " + JoH.dateTimeText(bgReading.timestamp) + " lastBgReading.timestamp: " + JoH.dateTimeText(lastBgReading.timestamp) + " lastBgReading.calibration.timestamp: " + JoH.dateTimeText(lastBgReading.calibration.timestamp));
            if (lastBgReading.calibration_flag == true && ((lastBgReading.timestamp + (60000 * 20)) > bgReading.timestamp) && ((lastBgReading.calibration.timestamp + (60000 * 20)) > bgReading.timestamp)) {
                lastBgReading.calibration.rawValueOverride(BgReading.weightedAverageRaw(lastBgReading.timestamp, bgReading.timestamp, lastBgReading.calibration.timestamp, lastBgReading.age_adjusted_raw_value, bgReading.age_adjusted_raw_value), xdrip.getAppContext());
                newCloseSensorData();
            }
        }

        if ((bgReading.raw_data != 0) && (bgReading.raw_data * 2 == bgReading.filtered_data)) {
            Log.wtf(TAG, "Filtered data is exactly double raw - this is completely wrong - dead transmitter? - blocking glucose calculation");
            bgReading.calculated_value = 0;
            bgReading.filtered_calculated_value = 0;
            bgReading.hide_slope = true;
        } else if (!SensorSanity.isRawValueSane(bgReading.raw_data)) {
            Log.wtf(TAG, "Raw data fails sanity check! " + bgReading.raw_data);
            bgReading.calculated_value = 0;
            bgReading.filtered_calculated_value = 0;
            bgReading.hide_slope = true;
        } else {

            // calculate glucose number from raw
            final CalibrationAbstract.CalibrationData pcalibration;
            final CalibrationAbstract plugin = getCalibrationPluginFromPreferences(); // make sure do this only once

            if ((plugin != null) && ((pcalibration = plugin.getCalibrationData()) != null) && (Pref.getBoolean("use_pluggable_alg_as_primary", false))) {
                Log.d(TAG, "USING CALIBRATION PLUGIN AS PRIMARY!!!");
                if (plugin.isCalibrationSane(pcalibration)) {
                    bgReading.calculated_value = (pcalibration.slope * bgReading.age_adjusted_raw_value) + pcalibration.intercept;
                    bgReading.filtered_calculated_value = (pcalibration.slope * bgReading.ageAdjustedFiltered()) + calibration.intercept;
                } else {
                    UserError.Log.wtf(TAG, "Calibration plugin failed intercept sanity check: " + pcalibration.toS());
                    Home.toaststaticnext("Calibration plugin failed intercept sanity check");
                }
            } else {
                bgReading.calculated_value = ((calibration.slope * bgReading.age_adjusted_raw_value) + calibration.intercept);
                bgReading.filtered_calculated_value = ((calibration.slope * bgReading.ageAdjustedFiltered()) + calibration.intercept);
            }

            updateCalculatedValueToWithinMinMax(bgReading);
        }
    }

    // LimiTTer can send 12 to indicate problem with NFC reading.
    if ((!calibration.check_in) && (raw_data == 12) && (filtered_data == 12)) {
        // store the raw value for sending special codes, note updateCalculatedValue would try to nix it
        bgReading.calculated_value = raw_data;
        bgReading.filtered_calculated_value = filtered_data;
    }
    return  bgReading;
}
 
Example 16
Source File: blueReader.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public static byte[] decodeblueReaderPacket(byte[] buffer, int len) {
    int cmdFound = 0;
    long timestamp = new Date().getTime();
    String bufferstring;
    //Log.w(TAG, "Packet: " + bufferstring);
    if (buffer == null) {
        Log.e(TAG, "null buffer passed to decodeblueReaderPacket");
        return null;
    } else {
        bufferstring=new String(buffer);
    }
    if (bufferstring.startsWith("not ready for") ) { //delete the trans_failed, because its normal only if the bluereader could not read the sensor.
        counterHibernated++;
        Log.e(TAG, "Found blueReader in a ugly State (" + counterHibernated + "/3), send hibernate to reset! If this does not help in the next 5 Minutes, then turn the bluereader manually off and on!");
        if (counterHibernated > 2) {
            Log.wtf(TAG, "Ugly state not resolveable. Bluereader will be shut down! Please restart it!");
            Home.toaststatic("BlueReader ugly state not resolveable, bluereader will be shut down. Please restart it!");
            if (!Pref.getBooleanDefaultFalse("blueReader_suppressuglystatemsg")) {
                Notifications.RiseDropAlert(xdrip.getAppContext(),true,"BlueReader Alarm", xdrip.getAppContext().getString(R.string.bluereaderuglystate),1);
            }
            return shutdown;
        } else {
            Home.toaststatic("Found blueReader in a ugly State, send hibernate to reset!");
            return goHybernate; //send hard hibernate, because blueReader is in a ugly state
        }
    } else if (bufferstring.startsWith("IDR")){
        Log.i(TAG, bufferstring);
        PersistentStore.setString("blueReaderFirmware", bufferstring );
        tempVers=Pattern.compile(".*\\|blue(.*)-.*").matcher(bufferstring);
        tempVers.find();
        PersistentStore.setDouble("blueReaderFirmwareValue",Double.parseDouble(tempVers.group(1)));
        Log.i(TAG, "bluereader-Firmware-Version: " + tempVers);
        if (BgReading.last() == null || BgReading.last().timestamp + (4 * 60 * 1000) < System.currentTimeMillis()) {
            return requestValue;
        } else {
            return null;
        }
    } else if (bufferstring.startsWith("WAKE")) {
        Log.d (TAG, "blueReader was set to wakeup-mode manually...");
        return null;
    } else if (bufferstring.startsWith("ECHO")) {
        Log.d (TAG, "blueReader was set to Echo-Mode manually...");
        return null;
    } else if (bufferstring.startsWith("NFC READY")) {
        Log.d (TAG, "blueReader notice that NFC is active...");
        return null;
    } else if (bufferstring.startsWith("NFC_DISABLED")) {
        Log.d (TAG, "blueReader notice that NFC is now hibernated...");
        return null;
    } else if (bufferstring.startsWith("HYBERNATE SUCCESS")) {
        Log.i (TAG, "blueReader notice that NFC is now really hibernated...");
        if (counterHibernated > 0) {
            Log.w (TAG,"Found hibernation after wrong read. Resend read-command...");
            return requestValue;
        } else {
            return null;
        }
    } else if (bufferstring.startsWith("-r 0:")) {
        Log.d (TAG, "blueReader sends an unknown reaction: '" + bufferstring + "'");
        return null;
    } else if (bufferstring.startsWith("TRANS_FAILED")) {
        Log.w (TAG, "Attention: check position of blueReader on the sensor, as it was not able to read!");
        Home.toaststatic(xdrip.getAppContext().getString(R.string.bluereader_position));
        return null;
    } else if (bufferstring.startsWith("battery: ")) {
        if (BgReading.last() == null || BgReading.last().timestamp + (4 * 60 * 1000) < System.currentTimeMillis()) {
            return requestValue;
        }
    } else {
        counterHibernated = 0;
        processNewTransmitterData(TransmitterData.create(buffer, len, timestamp), timestamp);
        // check for shutdown blueReader if Battery is too low
        if (Pref.getBooleanDefaultFalse("blueReader_turn_off")) {
            if (Pref.getInt("blueReader_turn_off_value",5) > Pref.getInt("bridge_battery",100)) {
                Log.w (TAG, "blueReader will be turn off, as the battery is lower then " + Pref.getInt("blueReader_turn_off_value",5) +"%");
                Home.toaststatic(xdrip.getAppContext().getString(R.string.bluereaderoff) + Pref.getInt("blueReader_turn_off_value",5) +"%");
                return shutdown;
            }
        }
    }

    return null;
}
 
Example 17
Source File: G5CollectionService.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private synchronized void processRxCharacteristic(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {

            Log.i(TAG, "onCharacteristicChanged On Main Thread? " + isOnMainThread());
            Log.e(TAG, "CharBytes-nfy" + Arrays.toString(characteristic.getValue()));
            Log.i(TAG, "CharHex-nfy" + Extensions.bytesToHex(characteristic.getValue()));


            byte[] buffer = characteristic.getValue();
            byte firstByte = buffer[0];
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && gatt != null) {
                gatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
            }
            Log.d(TAG, "Received opcode reply: " + JoH.bytesToHex(new byte[] { firstByte }));
            if (firstByte == 0x2f) {
                SensorRxMessage sensorRx = new SensorRxMessage(characteristic.getValue());

                ByteBuffer sensorData = ByteBuffer.allocate(buffer.length);
                sensorData.order(ByteOrder.LITTLE_ENDIAN);
                sensorData.put(buffer, 0, buffer.length);

                int sensor_battery_level = 0;
                if (sensorRx.status == TransmitterStatus.BRICKED) {
                    //TODO Handle this in UI/Notification
                    sensor_battery_level = 206; //will give message "EMPTY"
                } else if (sensorRx.status == TransmitterStatus.LOW) {
                    sensor_battery_level = 209; //will give message "LOW"
                } else {
                    sensor_battery_level = 216; //no message, just system status "OK"
                }

                //Log.e(TAG, "filtered: " + sensorRx.filtered);
                disconnected133 = 0; // reset as we got a reading
                disconnected59 = 0;
                lastState = "Got data OK: " + JoH.hourMinuteString();
                successes++;
                failures=0;
                Log.e(TAG, "SUCCESS!! unfiltered: " + sensorRx.unfiltered + " timestamp: " + sensorRx.timestamp + " " + JoH.qs((double)sensorRx.timestamp / 86400, 1) + " days");
                if (sensorRx.unfiltered == 0) {
                    lastState = "Transmitter sent raw sensor value of 0 !! This isn't good. " + JoH.hourMinuteString();
                }
                last_transmitter_timestamp = sensorRx.timestamp;
                if ((getVersionDetails) && (!haveFirmwareDetails())) {
                    doVersionRequestMessage(gatt, characteristic);
                } else if ((getBatteryDetails) && (getBatteryStatusNow || !haveCurrentBatteryStatus())) {
                    doBatteryInfoRequestMessage(gatt, characteristic);
                } else {
                    doDisconnectMessage(gatt, characteristic);
                }

                // TODO beware that wear G5CollectionService is now getting rather out of sync with app version
                final boolean g6 = usingG6();
                processNewTransmitterData(g6 ? sensorRx.unfiltered * G6_SCALING : sensorRx.unfiltered, g6 ? sensorRx.filtered * G6_SCALING : sensorRx.filtered, sensor_battery_level, new Date().getTime());

                // was this the first success after we force enabled always_authenticate?
                if (force_always_authenticate && (successes == 1)) {
                    Log.wtf(TAG, "We apparently only got a reading after forcing the Always Authenticate option");
                    Home.toaststaticnext("Please Enable G5 Always Authenticate debug option!");
                    // TODO should we actually change the settings here?
                }
            } else if (firstByte == GlucoseRxMessage.opcode) {
                disconnected133 = 0; // reset as we got a reading
                disconnected59 = 0;
                GlucoseRxMessage glucoseRx = new GlucoseRxMessage(characteristic.getValue());
                Log.e(TAG, "SUCCESS!! glucose unfiltered: " + glucoseRx.unfiltered);
                successes++;
                failures=0;
                doDisconnectMessage(gatt, characteristic);
                processNewTransmitterData(glucoseRx.unfiltered, glucoseRx.filtered, 216, new Date().getTime());
            } else if (firstByte == VersionRequestRxMessage.opcode) {
                if (!setStoredFirmwareBytes(defaultTransmitter.transmitterId, characteristic.getValue(), true)) {
                    Log.wtf(TAG, "Could not save out firmware version!");
                }
                doDisconnectMessage(gatt, characteristic);
            } else if (firstByte == BatteryInfoRxMessage.opcode) {
                if (!setStoredBatteryBytes(defaultTransmitter.transmitterId, characteristic.getValue())) {
                    Log.wtf(TAG, "Could not save out battery data!");
                }
                getBatteryStatusNow = false;
                doDisconnectMessage(gatt, characteristic);
            } else {
                Log.e(TAG, "onCharacteristic CHANGED unexpected opcode: " + firstByte + " (have not disconnected!)");
            }
            Log.e(TAG, "OnCharacteristic CHANGED finished: ");
        }
 
Example 18
Source File: GcmActivity.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
static void coolDown() {
    cool_down_till = JoH.tsl() + Constants.MINUTE_IN_MS * 20;
    Log.wtf(TAG, "Too many messages, activating cool down till: " + JoH.dateTimeText(cool_down_till));
}
 
Example 19
Source File: BgReading.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public static BgReading createFromRawNoSave(Sensor sensor, Calibration calibration, double raw_data, double filtered_data, long timestamp) {
    final BgReading bgReading = new BgReading();
    if (sensor == null) {
        sensor = Sensor.currentSensor();
        if (sensor == null) {
            return bgReading;
        }
    }
    if (calibration == null) {
        calibration = Calibration.lastValid();
        if (calibration == null) {
            return bgReading;
        }
    }

    bgReading.sensor = sensor;
    bgReading.sensor_uuid = sensor.uuid;
    bgReading.calibration = calibration;
    bgReading.calibration_uuid = calibration.uuid;
    bgReading.raw_data = (raw_data / 1000);
    bgReading.filtered_data = (filtered_data / 1000);
    bgReading.timestamp = timestamp;
    bgReading.uuid = UUID.randomUUID().toString();
    bgReading.time_since_sensor_started = bgReading.timestamp - sensor.started_at;

    bgReading.calculateAgeAdjustedRawValue();

    if (calibration.check_in) {
        double firstAdjSlope = calibration.first_slope + (calibration.first_decay * (Math.ceil(new Date().getTime() - calibration.timestamp) / (1000 * 60 * 10)));
        double calSlope = (calibration.first_scale / firstAdjSlope) * 1000;
        double calIntercept = ((calibration.first_scale * calibration.first_intercept) / firstAdjSlope) * -1;
        bgReading.calculated_value = (((calSlope * bgReading.raw_data) + calIntercept) - 5);
        bgReading.filtered_calculated_value = (((calSlope * bgReading.ageAdjustedFiltered()) + calIntercept) - 5);

    } else {
        BgReading lastBgReading = BgReading.last();
        if (lastBgReading != null && lastBgReading.calibration != null) {
            Log.d(TAG, "Create calibration.uuid=" + calibration.uuid + " bgReading.uuid: " + bgReading.uuid + " lastBgReading.calibration_uuid: " + lastBgReading.calibration_uuid + " lastBgReading.calibration.uuid: " + lastBgReading.calibration.uuid);
            Log.d(TAG, "Create lastBgReading.calibration_flag=" + lastBgReading.calibration_flag + " bgReading.timestamp: " + bgReading.timestamp + " lastBgReading.timestamp: " + lastBgReading.timestamp + " lastBgReading.calibration.timestamp: " + lastBgReading.calibration.timestamp);
            Log.d(TAG, "Create lastBgReading.calibration_flag=" + lastBgReading.calibration_flag + " bgReading.timestamp: " + JoH.dateTimeText(bgReading.timestamp) + " lastBgReading.timestamp: " + JoH.dateTimeText(lastBgReading.timestamp) + " lastBgReading.calibration.timestamp: " + JoH.dateTimeText(lastBgReading.calibration.timestamp));
            if (lastBgReading.calibration_flag == true && ((lastBgReading.timestamp + (60000 * 20)) > bgReading.timestamp) && ((lastBgReading.calibration.timestamp + (60000 * 20)) > bgReading.timestamp)) {
                lastBgReading.calibration.rawValueOverride(BgReading.weightedAverageRaw(lastBgReading.timestamp, bgReading.timestamp, lastBgReading.calibration.timestamp, lastBgReading.age_adjusted_raw_value, bgReading.age_adjusted_raw_value), xdrip.getAppContext());
                newCloseSensorData();
            }
        }

        if ((bgReading.raw_data != 0) && (bgReading.raw_data * 2 == bgReading.filtered_data)) {
            Log.wtf(TAG, "Filtered data is exactly double raw - this is completely wrong - dead transmitter? - blocking glucose calculation");
            bgReading.calculated_value = 0;
            bgReading.filtered_calculated_value = 0;
            bgReading.hide_slope = true;
        } else if (!SensorSanity.isRawValueSane(bgReading.raw_data)) {
            Log.wtf(TAG, "Raw data fails sanity check! " + bgReading.raw_data);
            bgReading.calculated_value = 0;
            bgReading.filtered_calculated_value = 0;
            bgReading.hide_slope = true;
        } else {

            // calculate glucose number from raw
            final CalibrationAbstract.CalibrationData pcalibration;
            final CalibrationAbstract plugin = getCalibrationPluginFromPreferences(); // make sure do this only once

            if ((plugin != null) && ((pcalibration = plugin.getCalibrationData()) != null) && (Pref.getBoolean("use_pluggable_alg_as_primary", false))) {
                Log.d(TAG, "USING CALIBRATION PLUGIN AS PRIMARY!!!");
                if (plugin.isCalibrationSane(pcalibration)) {
                    bgReading.calculated_value = (pcalibration.slope * bgReading.age_adjusted_raw_value) + pcalibration.intercept;
                    bgReading.filtered_calculated_value = (pcalibration.slope * bgReading.ageAdjustedFiltered()) + calibration.intercept;
                } else {
                    UserError.Log.wtf(TAG, "Calibration plugin failed intercept sanity check: " + pcalibration.toS());
                    Home.toaststaticnext("Calibration plugin failed intercept sanity check");
                }
            } else {
                bgReading.calculated_value = ((calibration.slope * bgReading.age_adjusted_raw_value) + calibration.intercept);
                bgReading.filtered_calculated_value = ((calibration.slope * bgReading.ageAdjustedFiltered()) + calibration.intercept);
            }

            updateCalculatedValueToWithinMinMax(bgReading);
        }
    }

    // LimiTTer can send 12 to indicate problem with NFC reading.
    if ((!calibration.check_in) && (raw_data == 12) && (filtered_data == 12)) {
        // store the raw value for sending special codes, note updateCalculatedValue would try to nix it
        bgReading.calculated_value = raw_data;
        bgReading.filtered_calculated_value = filtered_data;
    }
    return  bgReading;
}
 
Example 20
Source File: G5CollectionService.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private synchronized void processRxCharacteristic(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {

            Log.i(TAG, "onCharacteristicChanged On Main Thread? " + isOnMainThread());
            Log.e(TAG, "CharBytes-nfy" + Arrays.toString(characteristic.getValue()));
            Log.i(TAG, "CharHex-nfy" + Extensions.bytesToHex(characteristic.getValue()));


            byte[] buffer = characteristic.getValue();
            byte firstByte = buffer[0];
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && gatt != null) {
                gatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
            }
            Log.d(TAG, "Received opcode reply: " + JoH.bytesToHex(new byte[] { firstByte }));
            if (firstByte == 0x2f) {
                SensorRxMessage sensorRx = new SensorRxMessage(characteristic.getValue());

                ByteBuffer sensorData = ByteBuffer.allocate(buffer.length);
                sensorData.order(ByteOrder.LITTLE_ENDIAN);
                sensorData.put(buffer, 0, buffer.length);

                int sensor_battery_level = 0;
                if (sensorRx.status == TransmitterStatus.BRICKED) {
                    //TODO Handle this in UI/Notification
                    sensor_battery_level = 206; //will give message "EMPTY"
                } else if (sensorRx.status == TransmitterStatus.LOW) {
                    sensor_battery_level = 209; //will give message "LOW"
                } else {
                    sensor_battery_level = 216; //no message, just system status "OK"
                }

                //Log.e(TAG, "filtered: " + sensorRx.filtered);
                disconnected133 = 0; // reset as we got a reading
                disconnected59 = 0;
                lastState = "Got data OK: " + JoH.hourMinuteString();
                successes++;
                failures=0;
                Log.e(TAG, "SUCCESS!! unfiltered: " + sensorRx.unfiltered + " timestamp: " + sensorRx.timestamp + " " + JoH.qs((double)sensorRx.timestamp / 86400, 1) + " days");
                if (sensorRx.unfiltered == 0) {
                    lastState = "Transmitter sent raw sensor value of 0 !! This isn't good. " + JoH.hourMinuteString();
                }
                last_transmitter_timestamp = sensorRx.timestamp;
                if ((getVersionDetails) && (!haveFirmwareDetails())) {
                    doVersionRequestMessage(gatt, characteristic);
                } else if ((getBatteryDetails) && (getBatteryStatusNow || !haveCurrentBatteryStatus())) {
                    doBatteryInfoRequestMessage(gatt, characteristic);
                } else {
                    doDisconnectMessage(gatt, characteristic);
                }

                final boolean g6 = usingG6();
                processNewTransmitterData(g6 ? sensorRx.unfiltered * G6_SCALING : sensorRx.unfiltered, g6 ? sensorRx.filtered * G6_SCALING : sensorRx.filtered, sensor_battery_level, new Date().getTime());
                // was this the first success after we force enabled always_authenticate?
                if (force_always_authenticate && (successes == 1)) {
                    Log.wtf(TAG, "We apparently only got a reading after forcing the Always Authenticate option");
                    Home.toaststaticnext("Please Enable G5 Always Authenticate debug option!");
                    // TODO should we actually change the settings here?
                }
            } else if (firstByte == GlucoseRxMessage.opcode) {
                // TODO doesn't support firmware version reading in GlucoseRX
                disconnected133 = 0; // reset as we got a reading
                disconnected59 = 0;
                GlucoseRxMessage glucoseRx = new GlucoseRxMessage(characteristic.getValue());
                Log.e(TAG, "SUCCESS!! glucose unfiltered: " + glucoseRx.unfiltered);
                successes++;
                failures=0;
                doDisconnectMessage(gatt, characteristic);
                processNewTransmitterData(glucoseRx.unfiltered, glucoseRx.filtered, 216, new Date().getTime());
            } else if (firstByte == VersionRequestRxMessage.opcode) {
                if (!setStoredFirmwareBytes(defaultTransmitter.transmitterId, characteristic.getValue(), true)) {
                    Log.wtf(TAG, "Could not save out firmware version!");
                }
                doDisconnectMessage(gatt, characteristic);
            } else if (firstByte == BatteryInfoRxMessage.opcode) {
                if (!setStoredBatteryBytes(defaultTransmitter.transmitterId, characteristic.getValue())) {
                    Log.wtf(TAG, "Could not save out battery data!");
                }
                getBatteryStatusNow = false;
                doDisconnectMessage(gatt, characteristic);
            } else {
                Log.e(TAG, "onCharacteristic CHANGED unexpected opcode: " + firstByte + " (have not disconnected!)");
            }
            Log.e(TAG, "OnCharacteristic CHANGED finished: ");
        }