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;
}
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);
}
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);
}
}
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);
}
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);
}
Aggregations