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

The following examples show how to use com.eveningoutpost.dexdrip.Models.UserError.Log#e() . 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: ActiveBgAlert.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public String toString() {

        try {
            String alert_uuid = "alert_uuid: " + this.alert_uuid;
            String is_snoozed = "is_snoozed: " + this.is_snoozed;
            String last_alerted_at = "last_alerted_at: " + DateFormat.getDateTimeInstance(
                    DateFormat.LONG, DateFormat.LONG).format(new Date(this.last_alerted_at));
            String next_alert_at = "next_alert_at: " + DateFormat.getDateTimeInstance(
                    DateFormat.LONG, DateFormat.LONG).format(new Date(this.next_alert_at));

            String alert_started_at = "alert_started_at: " + DateFormat.getDateTimeInstance(
                    DateFormat.LONG, DateFormat.LONG).format(new Date(this.alert_started_at));

            return alert_uuid + " " + is_snoozed + " " + last_alerted_at + " " + next_alert_at + " " + alert_started_at;

        } catch (NullPointerException e) {
            Log.e(TAG, "Got Nullpointer exception in toString()! " + e);
            return "Nullpointer exception in toString!";
        }
    }
 
Example 2
Source File: EditAlertActivity.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
public String getPath(Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    if(cursor!=null)
    {
        //HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL
        //THIS CAN BE, IF YOU USED OI FILE MANAGER FOR PICKING THE MEDIA
        int column_index;
        try {
            column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        } catch ( IllegalArgumentException e) {
            Log.e(TAG, "cursor.getColumnIndexOrThrow failed", e);
            return null;
        }
        cursor.moveToFirst();
        return cursor.getString(column_index);
    }   else {
        return null;
    }
}
 
Example 3
Source File: DexCollectionService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private void watchdog() {
    if (last_time_seen == 0) return;
    if (prefs.getBoolean("bluetooth_watchdog", false)) {

        int MAX_BT_WDG = 20;
        int bt_wdg_timer = JoH.parseIntWithDefault(Pref.getString("bluetooth_watchdog_timer", Integer.toString(MAX_BT_WDG)), 10, MAX_BT_WDG);

        if ((bt_wdg_timer <= 5) || (bt_wdg_timer > MAX_BT_WDG)) {
            bt_wdg_timer = MAX_BT_WDG;
        }

        if ((JoH.msSince(last_time_seen)) > bt_wdg_timer * Constants.MINUTE_IN_MS) {
            Log.d(TAG, "Use BT Watchdog timer=" + bt_wdg_timer);
            if (!JoH.isOngoingCall()) {
                Log.e(TAG, "Watchdog triggered, attempting to reset bluetooth");
                status("Watchdog triggered");
                JoH.restartBluetooth(getApplicationContext());
                last_time_seen = JoH.tsl();
                watchdog_count++;
                if (watchdog_count > 5) last_time_seen = 0;
            } else {
                Log.e(TAG, "Delaying watchdog reset as phone call is ongoing.");
            }
        }
    }
}
 
Example 4
Source File: G5CollectionService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
// Characteristic notification
public void onCharacteristicChanged(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) {
    Log.e(TAG, "OnCharacteristic CHANGED started: " + getUUIDName(characteristic.getUuid()));
    if (enforceMainThread()) {
        Handler iHandler = new Handler(Looper.getMainLooper());
        iHandler.post(new Runnable() {
            @Override
            public void run() {
                processRxCharacteristic(gatt, characteristic);
            }
        });
    } else {
        processRxCharacteristic(gatt, characteristic);
    }
}
 
Example 5
Source File: G5CollectionService.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
private void processNewTransmitterData(int raw_data , int filtered_data,int sensor_battery_level, long captureTime) {

        TransmitterData transmitterData = TransmitterData.create(raw_data, sensor_battery_level, captureTime);
        if (transmitterData == null) {
            Log.e(TAG, "TransmitterData.create failed: Duplicate packet");
            return;
        } else {
            timeInMillisecondsOfLastSuccessfulSensorRead = captureTime;
        }
        Sensor sensor = Sensor.currentSensor();
        if (sensor == null) {
            Log.e(TAG, "setSerialDataToTransmitterRawData: No Active Sensor, Data only stored in Transmitter Data");
            return;
        }

        //TODO : LOG if unfiltered or filtered values are zero

        Sensor.updateBatteryLevel(sensor, transmitterData.sensor_battery_level);
        android.util.Log.i("timestamp create", Long.toString(transmitterData.timestamp));

        BgReading.create(transmitterData.raw_data, filtered_data, this, transmitterData.timestamp);
    }
 
Example 6
Source File: EditAlertActivity.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public String getPath(Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    if(cursor!=null)
    {
        //HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL
        //THIS CAN BE, IF YOU USED OI FILE MANAGER FOR PICKING THE MEDIA
        int column_index;
        try {
            column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        } catch ( IllegalArgumentException e) {
            Log.e(TAG, "cursor.getColumnIndexOrThrow failed", e);
            return null;
        }
        cursor.moveToFirst();
        return cursor.getString(column_index);
    }   else {
        return null;
    }
}
 
Example 7
Source File: TransmitterData.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static void updateTransmitterBatteryFromSync(final int battery_level) {
    try {
        TransmitterData td = TransmitterData.last();
        if ((td == null) || (td.raw_data!=0))
        {
            td=TransmitterData.create(0,battery_level,(long)JoH.ts());
            Log.d(TAG,"Created new fake transmitter data record for battery sync");
            if (td==null) return;
        }
        if ((battery_level != td.sensor_battery_level) || ((JoH.ts()-td.timestamp)>(1000*60*60))) {
            td.sensor_battery_level = battery_level;
            td.timestamp = (long)JoH.ts(); // freshen timestamp on this bogus record for system status
            Log.d(TAG,"Saving synced sensor battery, new level: "+battery_level);
            td.save();
        } else {
            Log.d(TAG,"Synced sensor battery level same as existing: "+battery_level);
        }
    } catch (Exception e) {
        Log.e(TAG,"Got exception updating sensor battery from sync: "+e.toString());
    }
}
 
Example 8
Source File: G5CollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private synchronized void processNewTransmitterData(int raw_data , int filtered_data,int sensor_battery_level, long captureTime) {

        final TransmitterData transmitterData = TransmitterData.create(raw_data, filtered_data, sensor_battery_level, captureTime);
        if (transmitterData == null) {
            Log.e(TAG, "TransmitterData.create failed: Duplicate packet");
            return;
        } else {
            timeInMillisecondsOfLastSuccessfulSensorRead = captureTime;
        }
        Sensor sensor = Sensor.currentSensor();
        if (sensor == null) {
            Log.e(TAG, "setSerialDataToTransmitterRawData: No Active Sensor, Data only stored in Transmitter Data");
            return;
        }

        //TODO : LOG if unfiltered or filtered values are zero

        Sensor.updateBatteryLevel(sensor, transmitterData.sensor_battery_level);
        Log.i(TAG,"timestamp create: "+ Long.toString(transmitterData.timestamp));

        BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, this, transmitterData.timestamp);

        Log.d(TAG,"Dex raw_data "+ Double.toString(transmitterData.raw_data));//KS
        Log.d(TAG,"Dex filtered_data "+ Double.toString(transmitterData.filtered_data));//KS
        Log.d(TAG,"Dex sensor_battery_level "+ Double.toString(transmitterData.sensor_battery_level));//KS
        Log.d(TAG,"Dex timestamp "+ JoH.dateTimeText(transmitterData.timestamp));//KS

        static_last_timestamp =  transmitterData.timestamp;

    }
 
Example 9
Source File: NFCReaderX.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static boolean HandleGoodReading(final String tagId, byte[] data1, final long CaptureDateTime, final boolean allowUpload, byte []patchUid,  byte []patchInfo ) {


        if (Pref.getBooleanDefaultFalse("external_blukon_algorithm")) {
            // If oop is used, there is no need to  do the checksum It will be done by the oop.
            // (or actually we don't know how to do it, for us 14/de sensors).
            // Save raw block record (we start from block 0)
            LibreBlock.createAndSave(tagId, CaptureDateTime, data1, 0, allowUpload, patchUid, patchInfo);
            LibreOOPAlgorithm.SendData(data1, CaptureDateTime, patchUid, patchInfo);
        } else {
            final boolean checksum_ok = LibreUtils.verify(data1);
            if (!checksum_ok) {
                return false;
            }
            
            // The 4'th byte is where the sensor status is.
            if(!LibreUtils.isSensorReady(data1[4])) {
                Log.e(TAG, "Sensor is not ready, Ignoring reading!");
                return true;
            }
            
            final ReadingData mResult = parseData(0, tagId, data1, CaptureDateTime);
            new Thread() {
                @Override
                public void run() {
                    final PowerManager.WakeLock wl = JoH.getWakeLock("processTransferObject", 60000);
                    try {
                        mResult.CalculateSmothedData();
                        LibreAlarmReceiver.processReadingDataTransferObject(new ReadingData.TransferObject(1, mResult), CaptureDateTime, tagId, allowUpload, patchUid, patchInfo );
                        Home.staticRefreshBGCharts();
                    } finally {
                        JoH.releaseWakeLock(wl);
                    }
                }
            }.start();
        }
        return true; // Checksum tests have passed.
    }
 
Example 10
Source File: Preferences.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void updateMiBandScreen(){
    MiBand.MiBandType type = MiBand.getMibandType();
    PreferenceScreen settings = (PreferenceScreen) findPreference(MiBandEntry.PREF_MIBAND_SETTINGS);
    PreferenceScreen prefs = (PreferenceScreen) findPreference(MiBandEntry.PREF_MIBAND_PREFERENCES);
    try {
        settings.removePreference(miband2_screen);
        settings.removePreference(miband3_4_screen);
        settings.removePreference(miband_nightmode_category);
        prefs.removePreference(miband_graph_category);
        prefs.removePreference(miband_send_readings_as_notification);
        prefs.removePreference(miband_authkey);

        if (type == MiBand.MiBandType.MI_BAND4) {
            settings.addPreference(miband3_4_screen);
            settings.addPreference(miband_nightmode_category);
            prefs.addPreference(miband_graph_category);
            prefs.addPreference(miband_send_readings_as_notification);
            prefs.addPreference(miband_authkey);
        } else if (type == MiBand.MiBandType.MI_BAND2) {
            settings.addPreference(miband2_screen);
        }
        else if (type == MiBand.MiBandType.MI_BAND3 || type == MiBand.MiBandType.MI_BAND3_1){
            settings.addPreference(miband3_4_screen);
            settings.addPreference(miband_nightmode_category);
        }
    } catch (Exception e) {
        Log.e(TAG, "Cannot find preference item: " + e);
    }
}
 
Example 11
Source File: EditAlertActivity.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private Integer parseInt(String str) {
    try {
        return Integer.parseInt(str);
    }
    catch (NumberFormatException nfe) {
        Log.e(TAG, "Invalid number", nfe);
        Toast.makeText(getApplicationContext(), "Invalid number: " + str, Toast.LENGTH_LONG).show();
        return null;
    }
}
 
Example 12
Source File: LibreWifiReader.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private static List<LibreWifiData> ReadFromMongo(String dbury, int numberOfRecords) {
   
    Log.i(TAG, "Reading From " + dbury);
    // format is dburi/db/collection. We need to find the collection and strip it from the dburi.
    int indexOfSlash = dbury.lastIndexOf('/');
    if (indexOfSlash == -1) {
        // We can not find a collection name
        Log.e(TAG, "Error bad dburi. Did not find a collection name starting with / " + dbury);
        // in order for the user to understand that there is a problem, we return null
        return null;

    }
    final String collection = dbury.substring(indexOfSlash + 1);
    dbury = dbury.substring(0, indexOfSlash);

    // Make sure that we have another /, since this is used in the constructor.
    indexOfSlash = dbury.lastIndexOf('/');
    if (indexOfSlash == -1) {
        // We can not find a collection name
        Log.e(TAG, "Error bad dburi. Did not find a collection name starting with / " + dbury);
        // in order for the user to understand that there is a problem, we return null
        return null;
    }

    final MongoWrapper mt = new MongoWrapper(dbury, collection, "CaptureDateTime", "MachineNameNotUsed");
    List<LibreWifiData> rd = mt.ReadFromMongoLibre(numberOfRecords);
    if (rd != null) {
        long newest_timestamp = 0;
        for (LibreWifiData r : rd) {
            if (newest_timestamp < r.getCaptureDateTime()) {
                statusLog(dbury, JoH.hourMinuteString() + " OK data from:", r.getCaptureDateTime());
                newest_timestamp = r.getCaptureDateTime();
            }
        }
    }
    return rd;
    
}
 
Example 13
Source File: G5CollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private synchronized void cycleBT() {
    synchronized (short_lock) {
        if (JoH.ratelimit("cyclebt", 20)) {

            // TODO cycling_bt not used as never set to true - rate limit any sync used instead
            if (cycling_bt) {
                Log.e(TAG, "jamorham Already concurrent BT cycle in progress!");
                return;
            }
            encountered133 = false;
            stopScan();
            if (g5BluetoothWatchdog()) {
                Log.e(TAG, "Cycling BT-gatt - disabling BT");
                mBluetoothAdapter.disable();
                Timer single_timer = new Timer();
                single_timer.schedule(new TimerTask() {
                    @Override
                    public void run() {
                        mBluetoothAdapter.enable();
                        Log.e(TAG, "Cycling BT-gatt - enableing BT");
                        cycling_bt = false;
                    }
                }, 3000);
            } else {
                Log.e(TAG, "Wanted to cycle g5 bluetooth but is disabled in advanced bluetooth preferences!");
                waitFor(3000);
            }
        }
        keepAlive();
    }
}
 
Example 14
Source File: BgReading.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void checkForRisingAllert(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Boolean rising_alert = prefs.getBoolean("rising_alert", false);
    if(!rising_alert) {
        return;
    }
    if(prefs.getLong("alerts_disabled_until", 0) > new Date().getTime()){
        Log.i("NOTIFICATIONS", "checkForRisingAllert: Notifications are currently disabled!!");
        return;
    }

    String riseRate = prefs.getString("rising_bg_val", "2");
    float friseRate = 2;

    try
    {
        friseRate = Float.parseFloat(riseRate);
    }
    catch (NumberFormatException nfe)
    {
        Log.e(TAG_ALERT, "checkForRisingAllert reading falling_bg_val failed, continuing with 2", nfe);
    }
    Log.d(TAG_ALERT, "checkForRisingAllert will check for rate of " + friseRate);

    boolean riseAlert = checkForDropRiseAllert(friseRate, false);
    Notifications.RisingAlert(context, riseAlert);
}
 
Example 15
Source File: Preferences.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private static void setSummary_static(AllPrefsFragment allPrefsFragment, String pref_name) {
    try {
        // is there a cleaner way to bind these values when setting programatically?
        final String pref_val = allPrefsFragment.prefs.getString(pref_name, "");
        allPrefsFragment.findPreference(pref_name).setSummary(pref_val);
        EditTextPreference thispref = (EditTextPreference) allPrefsFragment.findPreference(pref_name);
        thispref.setText(pref_val);
    } catch (Exception e) {
        Log.e(TAG, "Exception during setSummary: " + e.toString());
    }
}
 
Example 16
Source File: G5CollectionService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCharacteristicRead(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, final int status) {
    Log.e(TAG, "OnCharacteristic READ started: " + getUUIDName(characteristic.getUuid()) + " status: " + status);
    if (enforceMainThread()) {
        Handler iHandler = new Handler(Looper.getMainLooper());
        iHandler.post(new Runnable() {
            @Override
            public void run() {
                processOnCharacteristicRead(gatt, characteristic, status);
            }
        });
    } else {
        processOnCharacteristicRead(gatt, characteristic, status);
    }
}
 
Example 17
Source File: G5CollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if ((device != null) && (device.getAddress() != null)) {
        Log.e(TAG,"Processing mPairingRequestReceiver");
        JoH.doPairingRequest(context, this, intent, device.getAddress());
    } else {
        Log.e(TAG,"Received pairing request but device was null");
    }
}
 
Example 18
Source File: ReadData.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private ReadPacket read(int numOfBytes) {
        byte[] readData = new byte[numOfBytes];
        int len = 0;
        try {
//            UsbInterface mDataInterface = mDevice.getInterface(1);
//            UsbEndpoint mReadEndpoint = mDataInterface.getEndpoint(1);
//            byte[] mReadBuffer;
//            mReadBuffer = new byte[16 * 1024];
//
//            int readAmt = Math.min(readData.length, mReadBuffer.length);
//            synchronized (mReadBufferLock) {
//
//
//                Log.d(TAG, "Read about to call bulk transfer.");
//                if (len < 0) {
//                    // This sucks: we get -1 on timeout, not 0 as preferred.
//                    // We *should* use UsbRequest, except it has a bug/api oversight
//                    // where there is no way to determine the number of bytes read
//                    // in response :\ -- http://b.android.com/28023
//                    if (IO_TIMEOUT == Integer.MAX_VALUE) {
//                        // Hack: Special case "~infinite timeout" as an error.
//                        len = -1;
//                    }
//                    len = 0;
//                }
//
////              System.arraycopy(mReadBuffer, 0, readData, 0, readAmt);
//            }
//            len = mConnection.bulkTransfer(mReadEndpoint, readData, readAmt, IO_TIMEOUT);

            len = mSerialDevice.getPorts().get(0).read(readData, IO_TIMEOUT);

            Log.d(TAG, "Read " + len + " byte(s) complete.");

            // Add a 100ms delay for when multiple write/reads are occurring in series
            Thread.sleep(100);

            // TODO: this debug code to print data of the read, should be removed after
            // finding the source of the reading issue
            String bytes = "";
            int readAmount = len;
            for (int i = 0; i < readAmount; i++) bytes += String.format("%02x", readData[i]) + " ";
            Log.d(TAG, "Read data: " + bytes);
            ////////////////////////////////////////////////////////////////////////////////////////

        } catch (Exception e) {
            Log.e(TAG, "Unable to read from serial device.", e);
        }
        byte[] data = Arrays.copyOfRange(readData, 0, len);
        return new ReadPacket(data);
    }
 
Example 19
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: ");
        }
 
Example 20
Source File: Tomato.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
static void AreWeDone() {
    // Give both versions a chance to work.
    final int extended_length = 344 + TOMATO_HEADER_LENGTH + 1 + TOMATO_PATCH_INFO;
    if(s_recviedEnoughData && (s_acumulatedSize != extended_length))  {
        // This reading already ended
        Log.e(TAG,"Getting out, as s_recviedEnoughData and we have too much data already s_acumulatedSize = " + s_acumulatedSize);
        return;
    }

    if(s_acumulatedSize < 344 + TOMATO_HEADER_LENGTH + 1 ) {
        //Log.e(TAG,"Getting out, since not enough data s_acumulatedSize = " + s_acumulatedSize);
        return;   
    }
    byte[] data = Arrays.copyOfRange(s_full_data, TOMATO_HEADER_LENGTH, TOMATO_HEADER_LENGTH+344);
    s_recviedEnoughData = true;
    
    long now = JoH.tsl();
    // Important note, the actual serial number is 8 bytes long and starts at addresses 5.
    final String SensorSn = LibreUtils.decodeSerialNumberKey(Arrays.copyOfRange(s_full_data, 5, 13));
    byte []patchUid = null;
    byte []patchInfo = null;
    if(s_acumulatedSize >= extended_length) {
        patchUid = Arrays.copyOfRange(s_full_data, 5, 13);
        patchInfo = Arrays.copyOfRange(s_full_data, TOMATO_HEADER_LENGTH+ 344 + 1 , TOMATO_HEADER_LENGTH + 344 + 1+ TOMATO_PATCH_INFO);
    }
    Log.d(TAG, "patchUid = " + HexDump.dumpHexString(patchUid));
    Log.d(TAG, "patchInfo = " + HexDump.dumpHexString(patchInfo));
    boolean checksum_ok = NFCReaderX.HandleGoodReading(SensorSn, data, now, true, patchUid, patchInfo);
    Log.e(TAG, "We have all the data that we need " + s_acumulatedSize + " checksum_ok = " + checksum_ok + HexDump.dumpHexString(data));

    if(!checksum_ok) {
        throw new RuntimeException(CHECKSUM_FAILED);
    }

    if (SensorSanity.checkLibreSensorChangeIfEnabled(SensorSn)) {
        Log.e(TAG,"Problem with Libre Serial Number - not processing");
        throw new RuntimeException(SERIAL_FAILED);
    }

    PersistentStore.setString("Tomatobattery", Integer.toString(s_full_data[13]));
    Pref.setInt("bridge_battery", s_full_data[13]);
    PersistentStore.setString("TomatoHArdware",HexDump.toHexString(s_full_data,16,2));
    PersistentStore.setString("TomatoFirmware",HexDump.toHexString(s_full_data,14,2));
    PersistentStore.setString("LibreSN", SensorSn);

    
}