From 8e08a293c10f481ce8040ec3ffaf1e258f06c9a7 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 22 Jun 2018 22:30:03 +0200 Subject: [PATCH] detect bg source in nsclient --- .../androidaps/Services/DataService.java | 1 + .../plugins/Source/SourceNSClientPlugin.java | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java index f8a9ed5d5e..9f3873cb93 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -604,6 +604,7 @@ public class DataService extends IntentService { NSSgv nsSgv = new NSSgv(sgvJson); BgReading bgReading = new BgReading(nsSgv); MainApp.getDbHelper().createIfNotExists(bgReading, "NS"); + SourceNSClientPlugin.getPlugin().detectSource(JsonHelper.safeGetString(sgvJson, "device"), JsonHelper.safeGetLong(sgvJson, "mills")); } private void handleNewSMS(Intent intent) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java index e3c4181c05..c99fbcb9bb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java @@ -20,6 +20,9 @@ public class SourceNSClientPlugin extends PluginBase implements BgSourceInterfac return plugin; } + private long lastBGTimeStamp = 0; + private boolean isAdvancedFilteringEnabled = false; + private SourceNSClientPlugin() { super(new PluginDescription() .mainType(PluginType.BGSOURCE) @@ -33,6 +36,16 @@ public class SourceNSClientPlugin extends PluginBase implements BgSourceInterfac @Override public boolean advancedFilteringSupported() { - return false; + return isAdvancedFilteringEnabled; + } + + public void detectSource(String source, long timeStamp) { + if (timeStamp > lastBGTimeStamp) { + if (source.contains("G5 Native") || source.contains("AndroidAPS-DexcomG5")) + isAdvancedFilteringEnabled = true; + else + isAdvancedFilteringEnabled = false; + lastBGTimeStamp = timeStamp; + } } }