From 946b2bfd124c3996843c9fae8394d026146d6cf5 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 1 Dec 2018 00:16:15 +0100 Subject: [PATCH] Initial G6 support --- .../plugins/NSClientInternal/NSUpload.java | 4 +- .../plugins/Source/SourceDexcomG5Plugin.java | 2 +- .../plugins/Source/SourceDexcomG6Plugin.java | 126 ++++++++++++++++++ .../plugins/Source/SourceNSClientPlugin.java | 2 +- .../plugins/Source/SourcePoctechPlugin.java | 2 +- .../androidaps/services/DataService.java | 3 + .../androidaps/services/Intents.java | 1 + app/src/main/res/values/strings.xml | 3 + 8 files changed, 138 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG6Plugin.java diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSUpload.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSUpload.java index 8f3f31f6e7..9ae8f3b0ec 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSUpload.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSUpload.java @@ -470,14 +470,14 @@ public class NSUpload { DbLogger.dbAdd(intent, data.toString()); } - public static void uploadBg(BgReading reading) { + public static void uploadBg(BgReading reading, String source) { Context context = MainApp.instance().getApplicationContext(); Bundle bundle = new Bundle(); bundle.putString("action", "dbAdd"); bundle.putString("collection", "entries"); JSONObject data = new JSONObject(); try { - data.put("device", "AndroidAPS-DexcomG5"); + data.put("device", source); data.put("date", reading.date); data.put("dateString", DateUtil.toISOString(reading.date)); data.put("sgv", reading.value); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java index 460e550b8e..77f12f4e02 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java @@ -81,7 +81,7 @@ public class SourceDexcomG5Plugin extends PluginBase implements BgSourceInterfac bgReading.raw = 0; boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5"); if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) { - NSUpload.uploadBg(bgReading); + NSUpload.uploadBg(bgReading, "AndroidAPS-DexcomG5"); } if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { NSUpload.sendToXdrip(bgReading); 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 new file mode 100644 index 0000000000..a460b75e69 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG6Plugin.java @@ -0,0 +1,126 @@ +package info.nightscout.androidaps.plugins.Source; + +import android.content.Intent; +import android.os.Bundle; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.db.BgReading; +import info.nightscout.androidaps.interfaces.BgSourceInterface; +import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PluginDescription; +import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; +import info.nightscout.utils.DateUtil; +import info.nightscout.utils.SP; + +/** + * Created by mike on 30.11.2018. + */ + +public class SourceDexcomG6Plugin extends PluginBase implements BgSourceInterface { + private static Logger log = LoggerFactory.getLogger(L.BGSOURCE); + + private static SourceDexcomG6Plugin plugin = null; + + public static SourceDexcomG6Plugin getPlugin() { + if (plugin == null) + plugin = new SourceDexcomG6Plugin(); + return plugin; + } + + private SourceDexcomG6Plugin() { + super(new PluginDescription() + .mainType(PluginType.BGSOURCE) + .fragmentClass(BGSourceFragment.class.getName()) + .pluginName(R.string.DexcomG6) + .shortName(R.string.dexcomG6_shortname) + .preferencesId(R.xml.pref_dexcomg5) + .description(R.string.description_source_dexcom_g6) + ); + } + + @Override + public boolean advancedFilteringSupported() { + return true; + } + + @Override + public void handleNewData(Intent intent) { + if (!isEnabled(PluginType.BGSOURCE)) return; + + Bundle bundle = intent.getExtras(); + if (bundle == null) return; + + if (L.isEnabled(L.BGSOURCE)) { + if (bundle.containsKey("transmitterSystemTime")) + log.debug("transmitterSystemTime: " + DateUtil.dateAndTimeFullString(bundle.getLong("transmitterSystemTime"))); + log.debug("transmitterId: " + bundle.getString("transmitterId")); + if (bundle.containsKey("transmitterActivatedOn")) + log.debug("transmitterActivatedOn: " + DateUtil.dateAndTimeFullString(bundle.getLong("transmitterActivatedOn"))); + log.debug("transmitterVersion: " + bundle.getString("transmitterVersion")); + log.debug("transmitterSoftwareNumber: " + bundle.getString("transmitterSoftwareNumber")); + log.debug("transmitterStorageTimeDays: " + bundle.getInt("transmitterStorageTimeDays")); + log.debug("transmitterApiVersion: " + bundle.getInt("transmitterApiVersion")); + log.debug("transmitterMaxRuntimeDays: " + bundle.getInt("transmitterMaxRuntimeDays")); + log.debug("transmitterMaxStorageTimeDays: " + bundle.getInt("transmitterMaxStorageTimeDays")); + log.debug("transmitterCGMProcessorFirmwareVersion: " + bundle.getString("transmitterCGMProcessorFirmwareVersion")); + log.debug("transmitterBleRadioFirmwareVersion: " + bundle.getString("transmitterBleRadioFirmwareVersion")); + log.debug("transmitterHardwareVersion: " + bundle.getInt("transmitterHardwareVersion")); + log.debug("transmitterBleSoftDeviceVersion: " + bundle.getString("transmitterBleSoftDeviceVersion")); + log.debug("transmitterNordicAsicHwID: " + bundle.getInt("transmitterNordicAsicHwID")); + 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("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]); + } + } + } + + } + } +} 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 de110edd4e..f70c443d6e 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 @@ -99,7 +99,7 @@ public class SourceNSClientPlugin extends PluginBase implements BgSourceInterfac public void detectSource(String source, long timeStamp) { if (timeStamp > lastBGTimeStamp) { - if (source.contains("G5 Native") || source.contains("G6 Native") || source.contains("AndroidAPS-DexcomG5")) + if (source.contains("G5 Native") || source.contains("G6 Native") || source.contains("AndroidAPS-DexcomG5") || source.contains("AndroidAPS-DexcomG6")) isAdvancedFilteringEnabled = true; else isAdvancedFilteringEnabled = false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourcePoctechPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourcePoctechPlugin.java index df390522d3..6a63922426 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourcePoctechPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourcePoctechPlugin.java @@ -80,7 +80,7 @@ public class SourcePoctechPlugin extends PluginBase implements BgSourceInterface bgReading.value = bgReading.value * Constants.MMOLL_TO_MGDL; boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "Poctech"); if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) { - NSUpload.uploadBg(bgReading); + NSUpload.uploadBg(bgReading, "AndroidAPS-Poctech"); } if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { NSUpload.sendToXdrip(bgReading); 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 cfc564770d..dfed3ce443 100644 --- a/app/src/main/java/info/nightscout/androidaps/services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/services/DataService.java @@ -26,6 +26,7 @@ import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin; import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRNSHistorySync; import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin; import info.nightscout.androidaps.plugins.Source.SourceDexcomG5Plugin; +import info.nightscout.androidaps.plugins.Source.SourceDexcomG6Plugin; import info.nightscout.androidaps.plugins.Source.SourceGlimpPlugin; import info.nightscout.androidaps.plugins.Source.SourceMM640gPlugin; import info.nightscout.androidaps.plugins.Source.SourceNSClientPlugin; @@ -68,6 +69,8 @@ public class DataService extends IntentService { SourceGlimpPlugin.getPlugin().handleNewData(intent); } else if (Intents.DEXCOMG5_BG.equals(action)) { SourceDexcomG5Plugin.getPlugin().handleNewData(intent); + } else if (Intents.DEXCOMG6_BG.equals(action)) { + SourceDexcomG6Plugin.getPlugin().handleNewData(intent); } else if (Intents.POCTECH_BG.equals(action)) { SourcePoctechPlugin.getPlugin().handleNewData(intent); } else if (Intents.ACTION_NEW_SGV.equals(action)) { 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 6d3daf1ea9..0ef4e16590 100644 --- a/app/src/main/java/info/nightscout/androidaps/services/Intents.java +++ b/app/src/main/java/info/nightscout/androidaps/services/Intents.java @@ -49,6 +49,7 @@ 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 POCTECH_BG = "com.china.poctech.data"; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 96fd0c32b0..eab98346e9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -44,6 +44,7 @@ Sensitivity is calculated from 8h data in the past and carbs (if not absorbed) are cut after time specified in preferences. Plugin also calculates UAM. Sensitivity is calculated as a weighted average from deviations. Newer deviations have higher weight. Minimal carb absorption is calculated from max carb absorption time from preferences. This algorithm is the fastest in following sensitivity changes. Receive BG values from the patched Dexcom G5 app. + Receive BG values from the patched Dexcom G6 app. Receive BG values from Glimp. Receive BG values from the 600SeriesAndroidUploader. Downloads BG data from Nightscout @@ -799,6 +800,7 @@ BT Watchdog Switches off the phone\'s bluetooth for one second if no connection to the pump is possible. This may help on some phones where the bluetooth stack freezes. DexcomG5 App (patched) + DexcomG6 App (patched) Upload BG data to NS dexcomg5_nsupload G5 upload settings @@ -960,6 +962,7 @@ Create announcements from errors Create Nightscout announcement for error dialogs and local alerts (also viewable in Careportal under Treatments) G5 + G6 Show the predictions on the watchface. Predictions Data Choices