Search in sources :

Example 11 with LibreBlock

use of com.eveningoutpost.dexdrip.Models.LibreBlock in project xDrip-plus by jamorham.

the class LibreWifiReader method timeForNextRead.

static Long timeForNextRead() {
    // Allow some packets from the future.
    LibreBlock libreBlock = LibreBlock.getLatestForTrend(0L, JoH.tsl() + 5 * 60000);
    if (libreBlock == null) {
        // We did not receive a packet, well someone hopefully is looking at data, return relatively fast
        Log.e(TAG, "libreBlock == null returning 60000");
        return 60 * 1000L;
    }
    Long gapTime = new Date().getTime() - libreBlock.timestamp;
    Log.d(TAG, "gapTime = " + gapTime);
    if (gapTime < 0) {
        // There is some confusion here (clock was readjusted?)
        Log.e(TAG, "gapTime <= 0 returning 60000");
        return 60 * 1000L;
    }
    long sensor_period = isLibre2() ? LIBRE_2_PERIOD : LIBRE_1_PERIOD;
    if (gapTime < sensor_period) {
        // 300000 - gaptime is when we expect to have the next packet.
        return (sensor_period - gapTime) + 2000;
    }
    gapTime = gapTime % sensor_period;
    Log.d(TAG, "modulus gapTime = " + gapTime);
    if (gapTime < 10000) {
        // A new packet should arrive any second now
        return 10000L;
    }
    if (gapTime < 60000) {
        // A new packet should arrive but chance is we have missed it...
        return 30000L;
    }
    return (sensor_period - gapTime) + 2000;
}
Also used : LibreBlock(com.eveningoutpost.dexdrip.Models.LibreBlock) Date(java.util.Date)

Example 12 with LibreBlock

use of com.eveningoutpost.dexdrip.Models.LibreBlock in project xDrip-plus by jamorham.

the class LibreAlarmReceiver method processReadingDataTransferObject.

public static void processReadingDataTransferObject(ReadingData readingData, long CaptureDateTime, String tagid, boolean allowUpload, byte[] patchUid, byte[] patchInfo) {
    Log.d(TAG, "Data that was recieved from librealarm is " + HexDump.dumpHexString(readingData.raw_data));
    // Save raw block record (we start from block 0)
    LibreBlock libreBlock = LibreBlock.createAndSave(tagid, CaptureDateTime, readingData.raw_data, 0, allowUpload, patchUid, patchInfo);
    if (Pref.getBooleanDefaultFalse("external_blukon_algorithm")) {
        if (readingData.raw_data == null) {
            Log.e(TAG, "Please update LibreAlarm to use OOP algorithm");
            JoH.static_toast_long(gs(R.string.please_update_librealarm_to_use_oop_algorithm));
            return;
        }
        LibreOOPAlgorithm.sendData(readingData.raw_data, CaptureDateTime, tagid);
        return;
    }
    LibreTrendUtil libreTrendUtil = LibreTrendUtil.getInstance();
    // Get the data for the last 24 hours, as this affects the cache.
    List<LibreTrendPoint> libreTrendPoints = libreTrendUtil.getData(JoH.tsl() - Constants.DAY_IN_MS, JoH.tsl(), true);
    readingData.ClearErrors(libreTrendPoints);
    boolean use_smoothed_data = Pref.getBooleanDefaultFalse("libre_use_smoothed_data");
    if (use_smoothed_data) {
        readingData.calculateSmoothDataImproved(libreTrendPoints);
    }
    CalculateFromDataTransferObject(readingData, use_smoothed_data, true);
}
Also used : LibreTrendUtil(com.eveningoutpost.dexdrip.utils.LibreTrendUtil) LibreBlock(com.eveningoutpost.dexdrip.Models.LibreBlock) LibreTrendPoint(com.eveningoutpost.dexdrip.utils.LibreTrendPoint)

Example 13 with LibreBlock

use of com.eveningoutpost.dexdrip.Models.LibreBlock in project xDrip-plus by jamorham.

the class GcmListenerSvc method HandleLibreBlock.

private void HandleLibreBlock(String payload) {
    LibreBlock lb = LibreBlock.createFromExtendedJson(payload);
    if (lb == null) {
        return;
    }
    if (LibreBlock.getForTimestamp(lb.timestamp) != null) {
        // We already seen this one.
        return;
    }
    LibreBlock.Save(lb);
    PersistentStore.setString("LibreSN", lb.reference);
    if (Home.get_master()) {
        if (SensorSanity.checkLibreSensorChangeIfEnabled(lb.reference)) {
            Log.e(TAG, "Problem with Libre Serial Number - not processing");
        }
        NFCReaderX.HandleGoodReading(lb.reference, lb.blockbytes, lb.timestamp, false, lb.patchUid, lb.patchInfo);
    }
}
Also used : LibreBlock(com.eveningoutpost.dexdrip.Models.LibreBlock)

Example 14 with LibreBlock

use of com.eveningoutpost.dexdrip.Models.LibreBlock in project xDrip by NightscoutFoundation.

the class NFCReaderX method SendLibrereading.

public static void SendLibrereading(final String tagId, byte[] data1, final long CaptureDateTime, byte[] patchUid, byte[] patchInfo) {
    if (!Home.get_master()) {
        return;
    }
    LibreBlock libreBlock = LibreBlock.getForTimestamp(CaptureDateTime);
    if (libreBlock != null) {
        // We already have this one, so we have already sent it, so let's not crate storms.
        return;
    }
    // Create the object to send
    libreBlock = LibreBlock.create(tagId, CaptureDateTime, data1, 0, patchUid, patchInfo);
    if (libreBlock == null) {
        Log.e(TAG, "Error could not create libreBlock for libre-allhouse");
        return;
    }
    final String json = libreBlock.toExtendedJson();
    GcmActivity.pushLibreBlock(json);
}
Also used : LibreBlock(com.eveningoutpost.dexdrip.Models.LibreBlock)

Example 15 with LibreBlock

use of com.eveningoutpost.dexdrip.Models.LibreBlock in project xDrip by NightscoutFoundation.

the class LibreAlarmReceiver method processReadingDataTransferObject.

public static void processReadingDataTransferObject(ReadingData readingData, long CaptureDateTime, String tagid, boolean allowUpload, byte[] patchUid, byte[] patchInfo) {
    Log.d(TAG, "Data that was recieved from librealarm is " + HexDump.dumpHexString(readingData.raw_data));
    // Save raw block record (we start from block 0)
    LibreBlock libreBlock = LibreBlock.createAndSave(tagid, CaptureDateTime, readingData.raw_data, 0, allowUpload, patchUid, patchInfo);
    if (Pref.getBooleanDefaultFalse("external_blukon_algorithm")) {
        if (readingData.raw_data == null) {
            Log.e(TAG, "Please update LibreAlarm to use OOP algorithm");
            JoH.static_toast_long(gs(R.string.please_update_librealarm_to_use_oop_algorithm));
            return;
        }
        LibreOOPAlgorithm.sendData(readingData.raw_data, CaptureDateTime, tagid);
        return;
    }
    LibreTrendUtil libreTrendUtil = LibreTrendUtil.getInstance();
    // Get the data for the last 24 hours, as this affects the cache.
    List<LibreTrendPoint> libreTrendPoints = libreTrendUtil.getData(JoH.tsl() - Constants.DAY_IN_MS, JoH.tsl(), true);
    readingData.ClearErrors(libreTrendPoints);
    boolean use_smoothed_data = Pref.getBooleanDefaultFalse("libre_use_smoothed_data");
    if (use_smoothed_data) {
        readingData.calculateSmoothDataImproved(libreTrendPoints);
    }
    CalculateFromDataTransferObject(readingData, use_smoothed_data, true);
}
Also used : LibreTrendUtil(com.eveningoutpost.dexdrip.utils.LibreTrendUtil) LibreBlock(com.eveningoutpost.dexdrip.Models.LibreBlock) LibreTrendPoint(com.eveningoutpost.dexdrip.utils.LibreTrendPoint)

Aggregations

LibreBlock (com.eveningoutpost.dexdrip.Models.LibreBlock)20 Date (java.util.Date)10 BgReading (com.eveningoutpost.dexdrip.Models.BgReading)4 Calibration (com.eveningoutpost.dexdrip.Models.Calibration)4 Treatments (com.eveningoutpost.dexdrip.Models.Treatments)4 LibreTrendPoint (com.eveningoutpost.dexdrip.utils.LibreTrendPoint)4 ArrayList (java.util.ArrayList)4 TextView (android.widget.TextView)2 InfluxDBUploader (com.eveningoutpost.dexdrip.InfluxDB.InfluxDBUploader)2 BloodTest (com.eveningoutpost.dexdrip.Models.BloodTest)2 GlucoseData (com.eveningoutpost.dexdrip.Models.GlucoseData)2 TransmitterData (com.eveningoutpost.dexdrip.Models.TransmitterData)2 LibreTrendUtil (com.eveningoutpost.dexdrip.utils.LibreTrendUtil)2 BasicDBObject (com.mongodb.BasicDBObject)2 DB (com.mongodb.DB)2 DBCollection (com.mongodb.DBCollection)2 MongoClient (com.mongodb.MongoClient)2 MongoClientURI (com.mongodb.MongoClientURI)2 WriteResult (com.mongodb.WriteResult)2 IOException (java.io.IOException)2