use of com.eveningoutpost.dexdrip.cgm.medtrum.messages.BackFillRx in project xDrip by NightscoutFoundation.
the class MedtrumCollectionService method processBackFillPacket.
private void processBackFillPacket(final byte[] packet) {
final BackFillRx backFillRx = new BackFillRx(packet);
UserError.Log.d(TAG, backFillRx.toS());
if (backFillRx.isOk()) {
boolean changed = false;
final List<Integer> backsies = backFillRx.getRawList();
if (backsies != null) {
for (int index = 0; index < backsies.size(); index++) {
final long timestamp = timeStampFromTickCounter(serial, backFillRx.sequenceStart + index);
UserError.Log.d(TAG, "Backsie: id:" + (backFillRx.sequenceStart + index) + " raw:" + backsies.get(index) + " @ " + JoH.dateTimeText(timestamp));
final long since = msSince(timestamp);
if ((since > HOUR_IN_MS * 6) || (since < 0)) {
UserError.Log.wtf(TAG, "Backfill timestamp unrealistic: " + JoH.dateTimeText(timestamp) + " (ignored)");
} else {
final double glucose = backFillRx.getGlucose(backsies.get(index));
final int scaled_raw_data = backFillRx.getSensorRawEmulateDex(backsies.get(index));
if (BgReading.getForPreciseTimestamp(timestamp, (long) (Constants.MINUTE_IN_MS * 2.5)) == null) {
if (isNative()) {
// Native version
if (glucose > 0) {
BgReading.bgReadingInsertMedtrum(glucose, timestamp, "Backfill", scaled_raw_data);
UserError.Log.d(TAG, "Adding native backfilled reading: " + JoH.dateTimeText(timestamp) + " " + BgGraphBuilder.unitized_string_static(glucose));
}
final BgReading bgReadingTemp = BgReading.createFromRawNoSave(null, null, scaled_raw_data, scaled_raw_data, timestamp);
if (bgReadingTemp.calculated_value > 0) {
Prediction.create(bgReadingTemp.timestamp, (int) bgReadingTemp.calculated_value, "Medtrum2nd").save();
}
} else {
if (glucose > 0) {
Prediction.create(timestamp, (int) glucose, "Medtrum2nd").save();
}
// xDrip as primary
final BgReading bgreading = BgReading.create(scaled_raw_data, scaled_raw_data, xdrip.getAppContext(), timestamp);
if (bgreading != null) {
UserError.Log.d(TAG, "Backfilled BgReading created: " + bgreading.uuid + " " + JoH.dateTimeText(bgreading.timestamp));
} else {
UserError.Log.d(TAG, "BgReading null!");
}
}
Inevitable.task("backfill-ui-update", 3000, Home::staticRefreshBGChartsOnIdle);
changed = true;
}
}
}
if (!changed && backsies.size() < requestedBackfillSize) {
if (JoH.ratelimit("mt-backfill-repeat", 60)) {
UserError.Log.d(TAG, "Requesting additional backfill with offset: " + backsies.size());
backFillIfNeeded(lastAnnex, backsies.size());
}
}
}
} else {
UserError.Log.e(TAG, "Backfill data reports not ok");
}
}
use of com.eveningoutpost.dexdrip.cgm.medtrum.messages.BackFillRx in project xDrip-plus by jamorham.
the class MedtrumCollectionService method processBackFillPacket.
private void processBackFillPacket(final byte[] packet) {
final BackFillRx backFillRx = new BackFillRx(packet);
UserError.Log.d(TAG, backFillRx.toS());
if (backFillRx.isOk()) {
boolean changed = false;
final List<Integer> backsies = backFillRx.getRawList();
if (backsies != null) {
for (int index = 0; index < backsies.size(); index++) {
final long timestamp = timeStampFromTickCounter(serial, backFillRx.sequenceStart + index);
UserError.Log.d(TAG, "Backsie: id:" + (backFillRx.sequenceStart + index) + " raw:" + backsies.get(index) + " @ " + JoH.dateTimeText(timestamp));
final long since = msSince(timestamp);
if ((since > HOUR_IN_MS * 6) || (since < 0)) {
UserError.Log.wtf(TAG, "Backfill timestamp unrealistic: " + JoH.dateTimeText(timestamp) + " (ignored)");
} else {
final double glucose = backFillRx.getGlucose(backsies.get(index));
final int scaled_raw_data = backFillRx.getSensorRawEmulateDex(backsies.get(index));
if (BgReading.getForPreciseTimestamp(timestamp, (long) (Constants.MINUTE_IN_MS * 2.5)) == null) {
if (isNative()) {
// Native version
if (glucose > 0) {
BgReading.bgReadingInsertMedtrum(glucose, timestamp, "Backfill", scaled_raw_data);
UserError.Log.d(TAG, "Adding native backfilled reading: " + JoH.dateTimeText(timestamp) + " " + BgGraphBuilder.unitized_string_static(glucose));
}
final BgReading bgReadingTemp = BgReading.createFromRawNoSave(null, null, scaled_raw_data, scaled_raw_data, timestamp);
if (bgReadingTemp.calculated_value > 0) {
Prediction.create(bgReadingTemp.timestamp, (int) bgReadingTemp.calculated_value, "Medtrum2nd").save();
}
} else {
if (glucose > 0) {
Prediction.create(timestamp, (int) glucose, "Medtrum2nd").save();
}
// xDrip as primary
final BgReading bgreading = BgReading.create(scaled_raw_data, scaled_raw_data, xdrip.getAppContext(), timestamp);
if (bgreading != null) {
UserError.Log.d(TAG, "Backfilled BgReading created: " + bgreading.uuid + " " + JoH.dateTimeText(bgreading.timestamp));
} else {
UserError.Log.d(TAG, "BgReading null!");
}
}
Inevitable.task("backfill-ui-update", 3000, Home::staticRefreshBGChartsOnIdle);
changed = true;
}
}
}
if (!changed && backsies.size() < requestedBackfillSize) {
if (JoH.ratelimit("mt-backfill-repeat", 60)) {
UserError.Log.d(TAG, "Requesting additional backfill with offset: " + backsies.size());
backFillIfNeeded(lastAnnex, backsies.size());
}
}
}
} else {
UserError.Log.e(TAG, "Backfill data reports not ok");
}
}
Aggregations