Merge pull request #1574 from TebbeUbben/G6

Complete G6 plugin
This commit is contained in:
Milos Kozak 2018-12-01 20:42:52 +01:00 committed by GitHub
commit 7f73706a67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 86 additions and 38 deletions

View file

@ -88,7 +88,7 @@
<action android:name="it.ct.glicemia.ACTION_GLUCOSE_MEASURED" /> <action android:name="it.ct.glicemia.ACTION_GLUCOSE_MEASURED" />
<!-- Receiver from DexcomG5 --> <!-- Receiver from DexcomG5 -->
<action android:name="com.dexcom.cgm.DATA" /> <action android:name="com.dexcom.cgm.DATA" />
<action android:name="com.dexcom.cgm.AndroidAPSEVGCallback.Broadcast" /> <action android:name="com.dexcom.cgm.AndroidAPSEVGCallback.BROADCAST" />
<action android:name="com.dexcom.cgm.g5.AndroidAPSEVGCallback.BROADCAST" /> <action android:name="com.dexcom.cgm.g5.AndroidAPSEVGCallback.BROADCAST" />
<!-- Receiver from Poctech --> <!-- Receiver from Poctech -->
<action android:name="com.china.poctech.data" /> <action android:name="com.china.poctech.data" />

View file

@ -3,12 +3,19 @@ package info.nightscout.androidaps.plugins.Source;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Arrays;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.interfaces.BgSourceInterface; import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginDescription;
@ -17,6 +24,7 @@ import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
import info.nightscout.utils.SafeParse;
/** /**
* Created by mike on 30.11.2018. * Created by mike on 30.11.2018.
@ -76,11 +84,25 @@ public class SourceDexcomG6Plugin extends PluginBase implements BgSourceInterfac
log.debug("transmitterSessionTimeDays: " + bundle.getInt("transmitterSessionTimeDays")); log.debug("transmitterSessionTimeDays: " + bundle.getInt("transmitterSessionTimeDays"));
log.debug("transmitterFeatureFlags: " + bundle.getInt("transmitterFeatureFlags")); log.debug("transmitterFeatureFlags: " + bundle.getInt("transmitterFeatureFlags"));
if (bundle.containsKey("sensorInsertionTime"))
log.debug("sensorInsertionTime: " + DateUtil.dateAndTimeFullString(bundle.getLong("sensorInsertionTime")));
if (bundle.containsKey("sensorCode")) if (bundle.containsKey("sensorCode"))
log.debug("sensorCode: " + bundle.getString("sensorCode")); log.debug("sensorCode: " + bundle.getString("sensorCode"));
}
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")) { if (bundle.containsKey("evgTimestamps")) {
long[] timestamps = bundle.getLongArray("evgTimestamps"); long[] timestamps = bundle.getLongArray("evgTimestamps");
@ -89,6 +111,14 @@ public class SourceDexcomG6Plugin extends PluginBase implements BgSourceInterfac
int[] predictiveEVGs = bundle.getIntArray("predictiveEVGs"); int[] predictiveEVGs = bundle.getIntArray("predictiveEVGs");
String[] trendArrows = bundle.getStringArray("trendArrows"); 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));
}
for (int i = 0; i < transmitterTimes.length; i++) { for (int i = 0; i < transmitterTimes.length; i++) {
BgReading bgReading = new BgReading(); BgReading bgReading = new BgReading();
bgReading.value = evgs[i]; bgReading.value = evgs[i];
@ -113,14 +143,31 @@ public class SourceDexcomG6Plugin extends PluginBase implements BgSourceInterfac
long[] meterRecordedTimestamps = bundle.getLongArray("meterRecordedTimestamps"); long[] meterRecordedTimestamps = bundle.getLongArray("meterRecordedTimestamps");
int[] meterRecordIDs = bundle.getIntArray("meterRecordIDs"); int[] meterRecordIDs = bundle.getIntArray("meterRecordIDs");
for (int i = 0; i < meterValues.length; i++) {
if (L.isEnabled(L.BGSOURCE)) { if (L.isEnabled(L.BGSOURCE)) {
log.debug("meterValues: " + meterValues[i] + " meterEntryTypes: " + meterEntryTypes[i] + " meterTimestamps: " + meterTimestamps[i] + " meterTransmitterTimestamps: " + log.debug("meterValues", Arrays.toString(meterValues));
meterTransmitterTimestamps[i] + " meterRecordedTimestamps: " + meterRecordedTimestamps[i] + " meterRecordIDs: " + meterRecordIDs[i]); 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]);
data.put("units", Constants.MGDL);
NSUpload.uploadCareportalEntryToNS(data);
}
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
}
} }
} }
} }

View file

@ -49,7 +49,8 @@ public interface Intents {
String GLIMP_BG = "it.ct.glicemia.ACTION_GLUCOSE_MEASURED"; String GLIMP_BG = "it.ct.glicemia.ACTION_GLUCOSE_MEASURED";
String DEXCOMG5_BG = "com.dexcom.cgm.DATA"; 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"; String POCTECH_BG = "com.china.poctech.data";
} }