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

The following examples show how to use com.eveningoutpost.dexdrip.Models.UserError.Log#d() . 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: DexShareCollectionService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public void assignCharacteristics() {
    if(!share2) {
        Log.d(TAG, "Setting #1 characteristics");
        mSendDataCharacteristic = mShareService.getCharacteristic(DexShareAttributes.ShareMessageReceiver);
        mReceiveDataCharacteristic = mShareService.getCharacteristic(DexShareAttributes.ShareMessageResponse);
        mCommandCharacteristic = mShareService.getCharacteristic(DexShareAttributes.Command);
        mResponseCharacteristic = mShareService.getCharacteristic(DexShareAttributes.Response);
        mHeartBeatCharacteristic = mShareService.getCharacteristic(DexShareAttributes.HeartBeat);
    } else {
        Log.d(TAG, "Setting #1 characteristics");
        mSendDataCharacteristic = mShareService.getCharacteristic(DexShareAttributes.ShareMessageReceiver2);
        mReceiveDataCharacteristic = mShareService.getCharacteristic(DexShareAttributes.ShareMessageResponse2);
        mCommandCharacteristic = mShareService.getCharacteristic(DexShareAttributes.Command2);
        mResponseCharacteristic = mShareService.getCharacteristic(DexShareAttributes.Response2);
        mHeartBeatCharacteristic = mShareService.getCharacteristic(DexShareAttributes.HeartBeat2);
    }
}
 
Example 2
Source File: DexShareCollectionService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    UUID charUuid = characteristic.getUuid();
    Log.d(TAG, "Characteristic Update Received: " + charUuid);
    if (charUuid.compareTo(mReceiveDataCharacteristic.getUuid()) == 0) {
        Log.d(TAG, "mCharReceiveData Update");
        byte[] value = characteristic.getValue();
        if (value != null) {
            Observable.just(characteristic.getValue()).subscribe(mDataResponseListener);
        }
    } else if (charUuid.compareTo(mHeartBeatCharacteristic.getUuid()) == 0) {
        long heartbeat = System.currentTimeMillis();
        Log.d(TAG, "Heartbeat delta: " + (heartbeat - lastHeartbeat));
        if ((heartbeat-lastHeartbeat < 59000) || heartbeatCount > 5) {
            Log.d(TAG, "Early heartbeat.  Fetching data.");
            AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
            alarm.cancel(pendingIntent);
            heartbeatCount = 0;
            attemptConnection();
        }
        heartbeatCount += 1;
        lastHeartbeat = heartbeat;
    }
}
 
Example 3
Source File: DexCollectionService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private synchronized void processNewTransmitterData(TransmitterData transmitterData, long timestamp) {
    if (transmitterData == null) {
        return;
    }

    final Sensor sensor = Sensor.currentSensor();
    if (sensor == null) {
        Log.i(TAG, "setSerialDataToTransmitterRawData: No Active Sensor, Data only stored in Transmitter Data");
        return;
    }

    if (use_transmiter_pl_bluetooth && (transmitterData.raw_data == 100000)) {
        Log.wtf(TAG, "Ignoring probably erroneous Transmiter_PL data: " + transmitterData.raw_data);
        return;
    }


    //sensor.latest_battery_level = (sensor.latest_battery_level != 0) ? Math.min(sensor.latest_battery_level, transmitterData.sensor_battery_level) : transmitterData.sensor_battery_level;
    sensor.latest_battery_level = transmitterData.sensor_battery_level; // allow level to go up and down
    sensor.save();

    last_transmitter_Data = transmitterData;
    Log.d(TAG, "BgReading.create: new BG reading at " + timestamp + " with a timestamp of " + transmitterData.timestamp);
    BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, this, transmitterData.timestamp);
}
 
Example 4
Source File: DexShareCollectionService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
    Log.d(TAG, "services discovered " + status);
   if (status == BluetoothGatt.GATT_SUCCESS && mBluetoothGatt != null) {
       mShareService = mBluetoothGatt.getService(DexShareAttributes.CradleService);
       if(mShareService == null) {
           mShareService = mBluetoothGatt.getService(DexShareAttributes.CradleService2);
           share2 = true;
       } else {
           share2 = false;
       }
        assignCharacteristics();
        authenticateConnection();
        gattSetupStep();
    } else {
        Log.w(TAG, "No Services Discovered!");
    }
}
 
Example 5
Source File: Blukon.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private static synchronized void processNewTransmitterData(TransmitterData transmitterData) {
    if (transmitterData == null) {
        Log.e(TAG, "Got duplicated data! Last BG at " + JoH.dateTimeText(m_timeLastBg));
        return;
    }

    final Sensor sensor = Sensor.currentSensor();
    if (sensor == null) {
        Log.i(TAG, "processNewTransmitterData: No Active Sensor, Data only stored in Transmitter Data");
        return;
    }

    DexCollectionService.last_transmitter_Data = transmitterData;
    Log.d(TAG, "BgReading.create: new BG reading at " + transmitterData.timestamp);
    BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, xdrip.getAppContext(), transmitterData.timestamp);
}
 
Example 6
Source File: CollectionServiceStarter.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static void startBtService(Context context) {
    Log.d(TAG, "startBtService: " + DexCollectionType.getDexCollectionType());
    //stopBtService(context);
    CollectionServiceStarter collectionServiceStarter = new CollectionServiceStarter(context);
    collectionServiceStarter.stopBtShareService();
    collectionServiceStarter.stopBtWixelService();
    collectionServiceStarter.stopG5ShareService();
    switch (DexCollectionType.getDexCollectionType()) {
        case DexcomShare:
            collectionServiceStarter.startBtShareService();
            break;
        case DexcomG5:
            collectionServiceStarter.startBtG5Service();
            break;
        default:
            collectionServiceStarter.startBtWixelService();
            break;
    }
}
 
Example 7
Source File: DexShareCollectionService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    final BluetoothDevice bondDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

    if (mBluetoothGatt != null && mBluetoothGatt.getDevice() != null && bondDevice != null) {
        if (!bondDevice.getAddress().equals(mBluetoothGatt.getDevice().getAddress())) {
            Log.d(TAG, "Bond state wrong device");
            return; // That wasnt a device we care about!!
        }
    }

    if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)) {
        final int state = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.ERROR);
        if (state == BluetoothDevice.BOND_BONDED) {
            authenticateConnection();
        }
    }
}
 
Example 8
Source File: DexShareCollectionService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public void setFailoverTimer() { //Sometimes it gets stuck in limbo on 4.4, this should make it try again
    if (CollectionServiceStarter.isBTShare(getApplicationContext())) {
        long retry_in = (1000 * 60 * 5);
        Log.d(TAG, "Fallover Restarting in: " + (retry_in / (60 * 1000)) + " minutes");
        Calendar calendar = Calendar.getInstance();
        AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
        if (pendingIntent != null)
            alarm.cancel(pendingIntent);
        long wakeTime = calendar.getTimeInMillis() + retry_in;
        pendingIntent = PendingIntent.getService(this, 0, new Intent(this, this.getClass()), 0);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            alarm.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            alarm.setExact(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
        } else
            alarm.set(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
    } else {
        stopSelf();
    }
}
 
Example 9
Source File: G5CollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public synchronized void keepAlive(int wake_in_ms) {
    Log.d(TAG,"keepAlive keep_running=" + keep_running);
    if (!keep_running) return;
    if (JoH.ratelimit("G5-keepalive", 5)) {
        long wakeTime;
        if (wake_in_ms==0) {
            wakeTime = getNextAdvertiseTime() - 60 * 1000;
        } else {
            wakeTime = Calendar.getInstance().getTimeInMillis() + wake_in_ms;
        }
        nextWakeUpTime = wakeTime;//Benchmark test

        //Log.e(TAG, "Delay Time: " + minuteDelay);
        Log.e(TAG, "Scheduling Wake Time: in " +  JoH.qs((wakeTime-JoH.tsl())/1000,0)+ " secs "+ JoH.dateTimeText(wakeTime));
        AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
        if (pendingIntent != null)
            alarm.cancel(pendingIntent);
        pendingIntent = PendingIntent.getService(this, 0, new Intent(this, this.getClass()), 0);
        // TODO use wakeIntent feature
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            alarm.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            alarm.setExact(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
        } else
            alarm.set(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
    } else {
        Log.e(TAG, "Ignoring keepalive call due to ratelimit");
    }
}
 
Example 10
Source File: PacketBuilder.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public byte[] compose() {
    packet = new ArrayList<Byte>();
    packet.add(OFFSET_SOF, SOF);
    packet.add(OFFSET_LENGTH, getLength());
    packet.add(OFFSET_NULL, NULL);
    packet.add(OFFSET_CMD, (byte) command);
    if (this.payload != null) { this.packet.addAll(OFFSET_PAYLOAD, this.payload); }
    byte[] crc16 = CRC16.calculate(toBytes(), 0, this.packet.size());
    this.packet.add(crc16[0]);
    this.packet.add(crc16[1]);
    Log.d("ShareTest", "About to start adding to Byte, size: " + this.packet.size());
    return this.toBytes();
}
 
Example 11
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
DataRequester(Context context, String thispath, byte[] thispayload) {
    path = thispath;
    payload = thispayload;
    if (JoH.quietratelimit("db-init",10)) {
        Sensor.InitDb(context);//ensure database has already been initialized
    }
    Log.d(TAG, "DataRequester DataRequester: " + thispath + " lastRequest:" + JoH.dateTimeText(lastRequest));
}
 
Example 12
Source File: PacketBuilder.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public byte[] compose() {
    packet = new ArrayList<Byte>();
    packet.add(OFFSET_SOF, SOF);
    packet.add(OFFSET_LENGTH, getLength());
    packet.add(OFFSET_NULL, NULL);
    packet.add(OFFSET_CMD, (byte) command);
    if (this.payload != null) { this.packet.addAll(OFFSET_PAYLOAD, this.payload); }
    byte[] crc16 = CRC16.calculate(toBytes(), 0, this.packet.size());
    this.packet.add(crc16[0]);
    this.packet.add(crc16[1]);
    Log.d("ShareTest", "About to start adding to Byte, size: " + this.packet.size());
    return this.toBytes();
}
 
Example 13
Source File: BgReading.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void deleteALL() {
    try {
        SQLiteUtils.execSql("delete from BgSendQueue");
        SQLiteUtils.execSql("delete from BgReadings");
        Log.d(TAG, "Deleting all BGReadings");
    } catch (Exception e) {
        Log.e(TAG, "Got exception running deleteALL " + e.toString());
    }
}
 
Example 14
Source File: PebbleDisplayTrendOld.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void startDeviceCommand() {
    if (JoH.ratelimitmilli("pebble-trend", 250)) {
        transactionFailed = false;
        transactionOk = false;
        sendStep = 5;
        messageInTransit = false;
        done = true;
        sendingData = false;
        sendData();
    } else {
        Log.d(TAG, "SendData ratelimited!");
    }
}
 
Example 15
Source File: WixelReader.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
public void setSerialDataToTransmitterRawData(int raw_data, int filtered_data ,int sensor_battery_leve, Long CaptureTime) {

        TransmitterData transmitterData = TransmitterData.create(raw_data, sensor_battery_leve, CaptureTime);
        if (transmitterData != null) {
            Sensor sensor = Sensor.currentSensor();
            if (sensor != null) {
                Sensor.updateBatteryLevel(sensor, transmitterData.sensor_battery_level);
                BgReading bgReading = BgReading.create(transmitterData.raw_data, filtered_data, mContext, CaptureTime);
            } else {
                Log.d(TAG, "No Active Sensor, Data only stored in Transmitter Data");
            }
        }
    }
 
Example 16
Source File: BgReading.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private static boolean checkForDropRiseAllert(float MaxSpeed, boolean drop) {
    Log.d(TAG_ALERT, "checkForDropRiseAllert called drop=" + drop);
    List<BgReading> latest = getXRecentPoints(4);
    if(latest == null) {
        Log.d(TAG_ALERT, "checkForDropRiseAllert we don't have enough points from the last 15 minutes, returning false");
        return false;
    }
    float time3 = (latest.get(0).timestamp - latest.get(3).timestamp) / 60000;
    double bg_diff3 = latest.get(3).calculated_value - latest.get(0).calculated_value;
    if (!drop) {
        bg_diff3 *= (-1);
    }
    Log.i(TAG_ALERT, "bg_diff3=" + bg_diff3 + " time3 = " + time3);
    if(bg_diff3 < time3 * MaxSpeed) {
        Log.d(TAG_ALERT, "checkForDropRiseAllert for latest 4 points not fast enough, returning false");
        return false;
    }
    // we should alert here, but if the last measurement was less than MaxSpeed / 2, I won't.


    float time1 = (latest.get(0).timestamp - latest.get(1).timestamp) / 60000;
    double bg_diff1 = latest.get(1).calculated_value - latest.get(0).calculated_value;
    if (!drop) {
        bg_diff1 *= (-1);
    }

    if(time1 > 7.0) {
        Log.d(TAG_ALERT, "checkForDropRiseAllert the two points are not close enough, returning true");
        return true;
    }
    if(bg_diff1 < time1 * MaxSpeed /2) {
        Log.d(TAG_ALERT, "checkForDropRiseAllert for latest 2 points not fast enough, returning false");
        return false;
    }
    Log.d(TAG_ALERT, "checkForDropRiseAllert returning true speed is " + (bg_diff3 / time3));
    return true;
}
 
Example 17
Source File: Tomato.java    From xDrip 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);

    
}
 
Example 18
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 19
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);

    
}
 
Example 20
Source File: BgReading.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public static void create(Context context, double raw_data, double age_adjusted_raw_value, double filtered_data, Long timestamp,
                          double calculated_bg, double calculated_current_slope, boolean hide_slope) {

    BgReading bgReading = new BgReading();
    Sensor sensor = Sensor.currentSensor();
    if (sensor == null) {
        Log.w(TAG, "No sensor, ignoring this bg reading");
        return;
    }

    Calibration calibration = Calibration.lastValid();
    if (calibration == null) {
        Log.d(TAG, "create: No calibration yet");
        bgReading.sensor = sensor;
        bgReading.sensor_uuid = sensor.uuid;
        bgReading.raw_data = (raw_data / 1000);
        bgReading.age_adjusted_raw_value = age_adjusted_raw_value;
        bgReading.filtered_data = (filtered_data / 1000);
        bgReading.timestamp = timestamp;
        bgReading.uuid = UUID.randomUUID().toString();
        bgReading.calculated_value = calculated_bg;
        bgReading.calculated_value_slope = calculated_current_slope;
        bgReading.hide_slope = hide_slope;

        bgReading.save();
        bgReading.perform_calculations();
    } else {
        Log.d(TAG, "Calibrations, so doing everything bgReading = " + bgReading);
        bgReading.sensor = sensor;
        bgReading.sensor_uuid = sensor.uuid;
        bgReading.calibration = calibration;
        bgReading.calibration_uuid = calibration.uuid;
        bgReading.raw_data = (raw_data / 1000);
        bgReading.age_adjusted_raw_value = age_adjusted_raw_value;
        bgReading.filtered_data = (filtered_data / 1000);
        bgReading.timestamp = timestamp;
        bgReading.uuid = UUID.randomUUID().toString();
        bgReading.calculated_value = calculated_bg;
        bgReading.calculated_value_slope = calculated_current_slope;
        bgReading.hide_slope = hide_slope;

        bgReading.save();
    }
    BgSendQueue.handleNewBgReading(bgReading, "create", context);

    Log.i("BG GSON: ", bgReading.toS());
}