diff --git a/app/src/main/java/info/nightscout/androidaps/Services/Intents.java b/app/src/main/java/info/nightscout/androidaps/Services/Intents.java index 25485fb34d..1c2753b847 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/Intents.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/Intents.java @@ -38,6 +38,7 @@ public interface Intents { String EXTRA_TIMESTAMP = "com.eveningoutpost.dexdrip.Extras.Time"; String EXTRA_RAW = "com.eveningoutpost.dexdrip.Extras.Raw"; String XDRIP_DATA_SOURCE_DESCRIPTION = "com.eveningoutpost.dexdrip.Extras.SourceDesc"; + String EXTRA_NOISE = "com.eveningoutpost.dexdrip.Extras.Noise"; String ACTION_NEW_BG_ESTIMATE_NO_DATA = "com.eveningoutpost.dexdrip.BgEstimateNoData"; diff --git a/app/src/main/java/info/nightscout/androidaps/db/BgReading.java b/app/src/main/java/info/nightscout/androidaps/db/BgReading.java index 79b5236162..322f46100d 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/BgReading.java +++ b/app/src/main/java/info/nightscout/androidaps/db/BgReading.java @@ -1,7 +1,5 @@ package info.nightscout.androidaps.db; -import android.content.res.Resources; - import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.table.DatabaseTable; @@ -39,6 +37,8 @@ public class BgReading implements DataPointWithLabelInterface { @DatabaseField public double raw; @DatabaseField + public double noise = -999; // xDrip sends -999 to indicate lack of a noise reading (due to missed readings or calibration) + @DatabaseField public boolean filtered; @DatabaseField public String sourcePlugin; @@ -154,6 +154,7 @@ public class BgReading implements DataPointWithLabelInterface { raw = other.raw; direction = other.direction; _id = other._id; + noise = other.noise; sourcePlugin = other.sourcePlugin; filtered = other.filtered; } diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 19fbc7b10d..8dba0a7919 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -123,6 +123,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { "filtered", "integer"); createRowIfNotExists(getDaoBgReadings(), DatabaseHelper.DATABASE_BGREADINGS, "sourcePlugin", "text"); + createRowIfNotExists(getDaoBgReadings(), DatabaseHelper.DATABASE_BGREADINGS, + "noise", "real"); } catch (SQLException e) { log.error("Can't create database", e); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java index 07dda4ca6e..647e5cf877 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java @@ -4,6 +4,9 @@ import android.os.Bundle; import com.google.common.collect.Lists; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.util.Collections; import java.util.List; @@ -20,6 +23,7 @@ import info.nightscout.androidaps.interfaces.PluginType; * Created by mike on 05.08.2016. */ public class SourceXdripPlugin extends PluginBase implements BgSourceInterface { + private static final Logger log = LoggerFactory.getLogger(SourceXdripPlugin.class); private static SourceXdripPlugin plugin = null; @@ -46,8 +50,13 @@ public class SourceXdripPlugin extends PluginBase implements BgSourceInterface { bgReading.direction = bundle.getString(Intents.EXTRA_BG_SLOPE_NAME); bgReading.date = bundle.getLong(Intents.EXTRA_TIMESTAMP); bgReading.raw = bundle.getDouble(Intents.EXTRA_RAW); + bgReading.noise = bundle.getDouble(Intents.EXTRA_NOISE, -999); String sourceDescription = bundle.getString(Intents.XDRIP_DATA_SOURCE_DESCRIPTION, ""); bgReading.filtered = sourceDescription.equals("G5 Native"); + if (MainApp.engineeringMode && !bgReading.filtered && bgReading.noise >= 0 && bgReading.noise <= 4) { + log.debug("Setting filtered=true, since noise is provided and passed check: " + bgReading.noise); + bgReading.filtered = true; + } bgReading.sourcePlugin = getName(); boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, getName());