From dfe1e032beb3bad528dff87c5a4752818b7155ae Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sat, 1 Dec 2018 16:51:12 +0100 Subject: [PATCH 1/2] Complete G6 plugin --- app/src/main/AndroidManifest.xml | 2 +- .../plugins/Source/SourceDexcomG6Plugin.java | 117 ++++++++++++------ .../androidaps/services/Intents.java | 3 +- 3 files changed, 84 insertions(+), 38 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 59bdf15251..3fc0f27e2a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -88,7 +88,7 @@ - + diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG6Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG6Plugin.java index a460b75e69..69d1253289 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG6Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG6Plugin.java @@ -3,12 +3,18 @@ package info.nightscout.androidaps.plugins.Source; import android.content.Intent; import android.os.Bundle; +import org.json.JSONException; +import org.json.JSONObject; +import org.mozilla.javascript.tools.jsc.Main; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Arrays; + import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.BgReading; +import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.interfaces.BgSourceInterface; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; @@ -17,6 +23,7 @@ import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; import info.nightscout.utils.DateUtil; import info.nightscout.utils.SP; +import info.nightscout.utils.SafeParse; /** * Created by mike on 30.11.2018. @@ -76,51 +83,89 @@ public class SourceDexcomG6Plugin extends PluginBase implements BgSourceInterfac log.debug("transmitterSessionTimeDays: " + bundle.getInt("transmitterSessionTimeDays")); log.debug("transmitterFeatureFlags: " + bundle.getInt("transmitterFeatureFlags")); - if (bundle.containsKey("sensorInsertionTime")) - log.debug("sensorInsertionTime: " + DateUtil.dateAndTimeFullString(bundle.getLong("sensorInsertionTime"))); - if (bundle.containsKey("sensorCode")) log.debug("sensorCode: " + bundle.getString("sensorCode")); + } - if (bundle.containsKey("evgTimestamps")) { - long[] timestamps = bundle.getLongArray("evgTimestamps"); - long[] transmitterTimes = bundle.getLongArray("transmitterTimes"); - int[] evgs = bundle.getIntArray("evgs"); - int[] predictiveEVGs = bundle.getIntArray("predictiveEVGs"); - String[] trendArrows = bundle.getStringArray("trendArrows"); - - for (int i = 0; i < transmitterTimes.length; i++) { - BgReading bgReading = new BgReading(); - bgReading.value = evgs[i]; - bgReading.direction = trendArrows[i]; - bgReading.date = timestamps[i]; - bgReading.raw = 0; - boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG6"); - if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) { - NSUpload.uploadBg(bgReading, "AndroidAPS-DexcomG6"); - } - if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { - NSUpload.sendToXdrip(bgReading); - } + if (bundle.containsKey("sensorInsertionTime")) { + long sensorInsertionTime = bundle.getLong("sensorInsertionTime"); + if (L.isEnabled(L.BGSOURCE)) log.debug("sensorInsertionTime: " + DateUtil.dateAndTimeFullString(sensorInsertionTime)); + try { + if (MainApp.getDbHelper().getCareportalEventFromTimestamp(sensorInsertionTime) == null) { + JSONObject data = new JSONObject(); + data.put("enteredBy", "AndroidAPS-DexcomG6"); + data.put("created_at", DateUtil.toISOString(sensorInsertionTime)); + data.put("eventType", CareportalEvent.SENSORCHANGE); + NSUpload.uploadCareportalEntryToNS(data); } + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + } + + if (bundle.containsKey("evgTimestamps")) { + long[] timestamps = bundle.getLongArray("evgTimestamps"); + long[] transmitterTimes = bundle.getLongArray("transmitterTimes"); + int[] evgs = bundle.getIntArray("evgs"); + int[] predictiveEVGs = bundle.getIntArray("predictiveEVGs"); + String[] trendArrows = bundle.getStringArray("trendArrows"); + + if (L.isEnabled(L.BGSOURCE)) { + log.debug("timestamps", Arrays.toString(timestamps)); + log.debug("transmitterTimes", Arrays.toString(transmitterTimes)); + log.debug("evgs", Arrays.toString(evgs)); + log.debug("predictiveEVGs", Arrays.toString(predictiveEVGs)); + log.debug("trendArrows", Arrays.toString(trendArrows)); } - if (bundle.containsKey("meterValues")) { - int[] meterValues = bundle.getIntArray("meterValues"); - String[] meterEntryTypes = bundle.getStringArray("meterEntryTypes"); - long[] meterTimestamps = bundle.getLongArray("meterTimestamps"); - long[] meterTransmitterTimestamps = bundle.getLongArray("meterTransmitterTimestamps"); - long[] meterRecordedTimestamps = bundle.getLongArray("meterRecordedTimestamps"); - int[] meterRecordIDs = bundle.getIntArray("meterRecordIDs"); - - for (int i = 0; i < meterValues.length; i++) { - if (L.isEnabled(L.BGSOURCE)) { - log.debug("meterValues: " + meterValues[i] + " meterEntryTypes: " + meterEntryTypes[i] + " meterTimestamps: " + meterTimestamps[i] + " meterTransmitterTimestamps: " + - meterTransmitterTimestamps[i] + " meterRecordedTimestamps: " + meterRecordedTimestamps[i] + " meterRecordIDs: " + meterRecordIDs[i]); - } + for (int i = 0; i < transmitterTimes.length; i++) { + BgReading bgReading = new BgReading(); + bgReading.value = evgs[i]; + bgReading.direction = trendArrows[i]; + bgReading.date = timestamps[i]; + bgReading.raw = 0; + boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG6"); + if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) { + NSUpload.uploadBg(bgReading, "AndroidAPS-DexcomG6"); + } + if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { + NSUpload.sendToXdrip(bgReading); } } + } + if (bundle.containsKey("meterValues")) { + int[] meterValues = bundle.getIntArray("meterValues"); + String[] meterEntryTypes = bundle.getStringArray("meterEntryTypes"); + long[] meterTimestamps = bundle.getLongArray("meterTimestamps"); + long[] meterTransmitterTimestamps = bundle.getLongArray("meterTransmitterTimestamps"); + long[] meterRecordedTimestamps = bundle.getLongArray("meterRecordedTimestamps"); + int[] meterRecordIDs = bundle.getIntArray("meterRecordIDs"); + + if (L.isEnabled(L.BGSOURCE)) { + log.debug("meterValues", Arrays.toString(meterValues)); + log.debug("meterEntryTypes", Arrays.toString(meterEntryTypes)); + log.debug("meterTimestamps", Arrays.toString(meterTimestamps)); + log.debug("meterTransmitterTimestamps", Arrays.toString(meterTransmitterTimestamps)); + log.debug("meterRecordedTimestamps", Arrays.toString(meterRecordedTimestamps)); + log.debug("meterRecordIDs", Arrays.toString(meterRecordIDs)); + } + + for (int i = 0; i < meterValues.length; i++) { + try { + if (MainApp.getDbHelper().getCareportalEventFromTimestamp(meterTimestamps[i]) == null) { + JSONObject data = new JSONObject(); + data.put("enteredBy", "AndroidAPS-DexcomG6"); + data.put("created_at", DateUtil.toISOString(meterTimestamps[i])); + data.put("eventType", CareportalEvent.BGCHECK); + data.put("glucoseType", "Finger"); + data.put("glucose", meterValues[i]); + NSUpload.uploadCareportalEntryToNS(data); + } + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + } } } } 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 0ef4e16590..f9442470ee 100644 --- a/app/src/main/java/info/nightscout/androidaps/services/Intents.java +++ b/app/src/main/java/info/nightscout/androidaps/services/Intents.java @@ -49,7 +49,8 @@ public interface Intents { String GLIMP_BG = "it.ct.glicemia.ACTION_GLUCOSE_MEASURED"; String DEXCOMG5_BG = "com.dexcom.cgm.DATA"; - String DEXCOMG6_BG = "com.dexcom.cgm.AndroidAPSEVGCallback.Broadcast"; + String DEXCOMG5_BG_NEW = "com.dexcom.cgm.g5.AndroidAPSEVGCallback.BROADCAST"; + String DEXCOMG6_BG = "com.dexcom.cgm.AndroidAPSEVGCallback.BROADCAST"; String POCTECH_BG = "com.china.poctech.data"; } From e075a73c876538b23af9f2da9605848d1aa0ba78 Mon Sep 17 00:00:00 2001 From: TebbeUbben Date: Sat, 1 Dec 2018 16:52:46 +0100 Subject: [PATCH 2/2] Add unit to Careportal bgcheck entries --- .../androidaps/plugins/Source/SourceDexcomG6Plugin.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG6Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG6Plugin.java index 69d1253289..a8a50f85be 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG6Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG6Plugin.java @@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory; import java.util.Arrays; +import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.BgReading; @@ -160,6 +161,7 @@ public class SourceDexcomG6Plugin extends PluginBase implements BgSourceInterfac data.put("eventType", CareportalEvent.BGCHECK); data.put("glucoseType", "Finger"); data.put("glucose", meterValues[i]); + data.put("units", Constants.MGDL); NSUpload.uploadCareportalEntryToNS(data); } } catch (JSONException e) {