commit
7f73706a67
|
@ -88,7 +88,7 @@
|
|||
<action android:name="it.ct.glicemia.ACTION_GLUCOSE_MEASURED" />
|
||||
<!-- Receiver from DexcomG5 -->
|
||||
<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" />
|
||||
<!-- Receiver from Poctech -->
|
||||
<action android:name="com.china.poctech.data" />
|
||||
|
|
|
@ -3,12 +3,19 @@ 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.Constants;
|
||||
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 +24,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 +84,90 @@ 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]);
|
||||
data.put("units", Constants.MGDL);
|
||||
NSUpload.uploadCareportalEntryToNS(data);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue