G5 2018 app version support
This commit is contained in:
parent
7f73706a67
commit
8610dcc21d
5 changed files with 162 additions and 11 deletions
|
@ -9,16 +9,21 @@ import org.json.JSONObject;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
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;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
|
||||
import info.nightscout.androidaps.services.Intents;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
/**
|
||||
|
@ -58,6 +63,16 @@ public class SourceDexcomG5Plugin extends PluginBase implements BgSourceInterfac
|
|||
|
||||
if (!isEnabled(PluginType.BGSOURCE)) return;
|
||||
|
||||
if (intent.getAction().equals(Intents.DEXCOMG5_BG))
|
||||
handleNewDataOld(intent);
|
||||
|
||||
if (intent.getAction().equals(Intents.DEXCOMG5_BG_NEW))
|
||||
handleNewDataNew(intent);
|
||||
}
|
||||
|
||||
public void handleNewDataOld(Intent intent) {
|
||||
// onHandleIntent Bundle{ data => [{"m_time":1511939180,"m_trend":"NotComputable","m_value":335}]; android.support.content.wakelockid => 95; }Bundle
|
||||
|
||||
Bundle bundle = intent.getExtras();
|
||||
if (bundle == null) return;
|
||||
|
||||
|
@ -92,4 +107,126 @@ public class SourceDexcomG5Plugin extends PluginBase implements BgSourceInterfac
|
|||
log.error("Exception: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void handleNewDataNew(Intent intent) {
|
||||
|
||||
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")));
|
||||
if (bundle.containsKey("transmitterRemainingTime"))
|
||||
log.debug("transmitterRemainingTime: " + DateUtil.dateAndTimeFullString(bundle.getLong("transmitterRemainingTime")));
|
||||
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")) {
|
||||
long sensorInsertionTime = bundle.getLong("sensorInsertionTime");
|
||||
if (L.isEnabled(L.BGSOURCE))
|
||||
log.debug("sensorInsertionTime: " + DateUtil.dateAndTimeFullString(sensorInsertionTime));
|
||||
if (SP.getBoolean(R.string.key_dexcom_lognssensorchange, false)) {
|
||||
try {
|
||||
if (MainApp.getDbHelper().getCareportalEventFromTimestamp(sensorInsertionTime) == null) {
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("enteredBy", "AndroidAPS-DexcomG5");
|
||||
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("glucoseValues")) {
|
||||
int[] glucoseValues = bundle.getIntArray("glucoseValues");
|
||||
int[] glucoseRecordIDs = bundle.getIntArray("glucoseRecordIDs");
|
||||
long[] glucoseRecordedTimestamps = bundle.getLongArray("glucoseRecordedTimestamps");
|
||||
long[] glucoseSessionStartTimes = bundle.getLongArray("glucoseSessionStartTimes");
|
||||
long[] glucoseSystemTimestamps = bundle.getLongArray("glucoseSystemTimestamps");
|
||||
String[] glucoseTransmitterIDS = bundle.getStringArray("glucoseTransmitterIDS");
|
||||
long[] glucoseTransmitterTimestamps = bundle.getLongArray("glucoseTransmitterTimestamps");
|
||||
String[] glucoseTrendsArrows = bundle.getStringArray("glucoseTrendsArrows");
|
||||
boolean[] glucoseWasBackfilled = bundle.getBooleanArray("glucoseWasBackfilled");
|
||||
|
||||
if (L.isEnabled(L.BGSOURCE)) {
|
||||
log.debug("glucoseValues", Arrays.toString(glucoseValues));
|
||||
log.debug("glucoseRecordIDs", Arrays.toString(glucoseRecordIDs));
|
||||
log.debug("glucoseRecordedTimestamps", Arrays.toString(glucoseRecordedTimestamps));
|
||||
log.debug("glucoseSessionStartTimes", Arrays.toString(glucoseSessionStartTimes));
|
||||
log.debug("glucoseSystemTimestamps", Arrays.toString(glucoseSystemTimestamps));
|
||||
log.debug("glucoseTransmitterIDS", Arrays.toString(glucoseTransmitterIDS));
|
||||
log.debug("glucoseTransmitterTimestamps", Arrays.toString(glucoseTransmitterTimestamps));
|
||||
log.debug("glucoseTrendsArrows", Arrays.toString(glucoseTrendsArrows));
|
||||
log.debug("glucoseWasBackfilled", Arrays.toString(glucoseWasBackfilled));
|
||||
}
|
||||
|
||||
for (int i = 0; i < glucoseValues.length; i++) {
|
||||
BgReading bgReading = new BgReading();
|
||||
bgReading.value = glucoseValues[i];
|
||||
bgReading.direction = glucoseTrendsArrows[i];
|
||||
bgReading.date = glucoseTransmitterTimestamps[i];
|
||||
bgReading.raw = 0;
|
||||
boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5");
|
||||
if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
|
||||
NSUpload.uploadBg(bgReading, "AndroidAPS-DexcomG5");
|
||||
}
|
||||
if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) {
|
||||
NSUpload.sendToXdrip(bgReading);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bundle.containsKey("meterValues")) {
|
||||
String[] meterEntryTypes = bundle.getStringArray("meterEntryTypes");
|
||||
long[] meterTimestamps = bundle.getLongArray("meterTimestamps");
|
||||
int[] meterValues = bundle.getIntArray("meterValues");
|
||||
long[] meterRecordedTimestamps = bundle.getLongArray("meterRecordedTimestamps");
|
||||
int[] meterTransmitterIDs = bundle.getIntArray("meterTransmitterIDs");
|
||||
long[] meterTransmitterTimestamps = bundle.getLongArray("meterTransmitterTimestamps");
|
||||
|
||||
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("meterTransmitterIDs", Arrays.toString(meterTransmitterIDs));
|
||||
}
|
||||
|
||||
for (int i = 0; i < meterValues.length; i++) {
|
||||
try {
|
||||
if (MainApp.getDbHelper().getCareportalEventFromTimestamp(meterTimestamps[i]) == null) {
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("enteredBy", "AndroidAPS-DexcomG5");
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,17 +90,20 @@ public class SourceDexcomG6Plugin extends PluginBase implements BgSourceInterfac
|
|||
|
||||
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);
|
||||
if (L.isEnabled(L.BGSOURCE))
|
||||
log.debug("sensorInsertionTime: " + DateUtil.dateAndTimeFullString(sensorInsertionTime));
|
||||
if (SP.getBoolean(R.string.key_dexcom_lognssensorchange, false)) {
|
||||
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);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,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.DEXCOMG5_BG_NEW.equals(action)) {
|
||||
SourceDexcomG5Plugin.getPlugin().handleNewData(intent);
|
||||
} else if (Intents.DEXCOMG6_BG.equals(action)) {
|
||||
SourceDexcomG6Plugin.getPlugin().handleNewData(intent);
|
||||
} else if (Intents.POCTECH_BG.equals(action)) {
|
||||
|
|
|
@ -1221,6 +1221,9 @@
|
|||
<string name="profile_ins_units_per_hout">U/h</string>
|
||||
<string name="profile_carbs_per_unit">g/U</string>
|
||||
<string name="profile_per_unit">/U</string>
|
||||
<string name="key_dexcom_lognssensorchange">dexcom_lognssensorchange</string>
|
||||
<string name="dexcom_lognssensorchange_title">Log sensor change to NS</string>
|
||||
<string name="dexcom_lognssensorchange_summary">Create event \"Sensor Change\" in NS automaticaly on sensor start</string>
|
||||
|
||||
<plurals name="objective_days">
|
||||
<item quantity="one">%1$d day</item>
|
||||
|
|
|
@ -14,6 +14,12 @@
|
|||
android:summary="@string/dexcomg5_xdripupload_summary"
|
||||
android:title="@string/dexcomg5_xdripupload_title" />
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="@string/key_dexcom_lognssensorchange"
|
||||
android:summary="@string/dexcom_lognssensorchange_summary"
|
||||
android:title="@string/dexcom_lognssensorchange_title" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
Loading…
Reference in a new issue