BGSOURCE refactor & logging
This commit is contained in:
parent
bfccda21cb
commit
6a058f5036
13 changed files with 364 additions and 339 deletions
|
@ -33,9 +33,10 @@ public class Config {
|
|||
public static final boolean logNSUpload = true;
|
||||
public static final boolean logPumpActions = true;
|
||||
public static final boolean logCongigBuilderActions = true;
|
||||
public static final boolean logQueue = true;
|
||||
public static final boolean logAutosensData = false;
|
||||
public static final boolean logEvents = false;
|
||||
public static final boolean logQueue = true;
|
||||
public static final boolean logBgSource = true;
|
||||
|
||||
// DanaR specific
|
||||
public static final boolean logDanaBTComm = true;
|
||||
|
|
|
@ -72,4 +72,5 @@ public class Constants {
|
|||
public static final String AUTOSENS = "AUTOSENS";
|
||||
public static final String EVENTS = "EVENTS";
|
||||
public static final String QUEUE = "QUEUE";
|
||||
public static final String BGSOURCE = "BGSOURCE";
|
||||
}
|
||||
|
|
|
@ -13,11 +13,8 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.ProfileStore;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.CareportalEvent;
|
||||
import info.nightscout.androidaps.events.EventNsFood;
|
||||
import info.nightscout.androidaps.events.EventNsTreatment;
|
||||
|
@ -26,15 +23,13 @@ import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin
|
|||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSMbg;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
|
||||
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
||||
import info.nightscout.androidaps.plugins.ProfileNS.events.EventNSProfileUpdateGUI;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRNSHistorySync;
|
||||
import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS;
|
||||
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin;
|
||||
import info.nightscout.androidaps.plugins.Source.SourceDexcomG5Plugin;
|
||||
import info.nightscout.androidaps.plugins.Source.SourceGlimpPlugin;
|
||||
import info.nightscout.androidaps.plugins.Source.SourceMM640gPlugin;
|
||||
|
@ -44,20 +39,12 @@ import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin;
|
|||
import info.nightscout.androidaps.receivers.DataReceiver;
|
||||
import info.nightscout.utils.BundleLogger;
|
||||
import info.nightscout.utils.JsonHelper;
|
||||
import info.nightscout.utils.NSUpload;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
|
||||
public class DataService extends IntentService {
|
||||
private static Logger log = LoggerFactory.getLogger(DataService.class);
|
||||
|
||||
boolean xDripEnabled = false;
|
||||
boolean nsClientEnabled = true;
|
||||
boolean mm640gEnabled = false;
|
||||
boolean glimpEnabled = false;
|
||||
boolean dexcomG5Enabled = false;
|
||||
boolean poctechEnabled = false;
|
||||
|
||||
public DataService() {
|
||||
super("DataService");
|
||||
registerBus();
|
||||
|
@ -67,58 +54,6 @@ public class DataService extends IntentService {
|
|||
protected void onHandleIntent(final Intent intent) {
|
||||
if (Config.logFunctionCalls)
|
||||
log.debug("onHandleIntent " + BundleLogger.log(intent.getExtras()));
|
||||
if (ConfigBuilderPlugin.getPlugin().getActiveBgSource() == null) {
|
||||
xDripEnabled = true;
|
||||
nsClientEnabled = false;
|
||||
mm640gEnabled = false;
|
||||
glimpEnabled = false;
|
||||
dexcomG5Enabled = false;
|
||||
poctechEnabled = false;
|
||||
} else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceXdripPlugin.class)) {
|
||||
xDripEnabled = true;
|
||||
nsClientEnabled = false;
|
||||
mm640gEnabled = false;
|
||||
glimpEnabled = false;
|
||||
dexcomG5Enabled = false;
|
||||
poctechEnabled = false;
|
||||
} else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceNSClientPlugin.class)) {
|
||||
xDripEnabled = false;
|
||||
nsClientEnabled = true;
|
||||
mm640gEnabled = false;
|
||||
glimpEnabled = false;
|
||||
dexcomG5Enabled = false;
|
||||
poctechEnabled = false;
|
||||
} else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceMM640gPlugin.class)) {
|
||||
xDripEnabled = false;
|
||||
nsClientEnabled = false;
|
||||
mm640gEnabled = true;
|
||||
glimpEnabled = false;
|
||||
dexcomG5Enabled = false;
|
||||
poctechEnabled = false;
|
||||
} else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceGlimpPlugin.class)) {
|
||||
xDripEnabled = false;
|
||||
nsClientEnabled = false;
|
||||
mm640gEnabled = false;
|
||||
glimpEnabled = true;
|
||||
dexcomG5Enabled = false;
|
||||
poctechEnabled = false;
|
||||
} else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceDexcomG5Plugin.class)) {
|
||||
xDripEnabled = false;
|
||||
nsClientEnabled = false;
|
||||
mm640gEnabled = false;
|
||||
glimpEnabled = false;
|
||||
dexcomG5Enabled = true;
|
||||
poctechEnabled = false;
|
||||
} else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourcePoctechPlugin.class)) {
|
||||
xDripEnabled = false;
|
||||
nsClientEnabled = false;
|
||||
mm640gEnabled = false;
|
||||
glimpEnabled = false;
|
||||
dexcomG5Enabled = false;
|
||||
poctechEnabled = true;
|
||||
}
|
||||
|
||||
boolean isNSProfile = MainApp.getConfigBuilder().getActiveProfileInterface() != null && MainApp.getConfigBuilder().getActiveProfileInterface().getClass().equals(NSProfilePlugin.class);
|
||||
|
||||
boolean acceptNSData = !SP.getBoolean(R.string.key_ns_upload_only, false);
|
||||
Bundle bundles = intent.getExtras();
|
||||
|
@ -127,71 +62,44 @@ public class DataService extends IntentService {
|
|||
}
|
||||
|
||||
|
||||
if (intent != null) {
|
||||
final String action = intent.getAction();
|
||||
if (Intents.ACTION_NEW_BG_ESTIMATE.equals(action)) {
|
||||
if (xDripEnabled) {
|
||||
handleNewDataFromXDrip(intent);
|
||||
}
|
||||
} else if (Intents.NS_EMULATOR.equals(action)) {
|
||||
if (mm640gEnabled) {
|
||||
handleNewDataFromMM640g(intent);
|
||||
}
|
||||
} else if (Intents.GLIMP_BG.equals(action)) {
|
||||
if (glimpEnabled) {
|
||||
handleNewDataFromGlimp(intent);
|
||||
}
|
||||
} else if (Intents.DEXCOMG5_BG.equals(action)) {
|
||||
if (dexcomG5Enabled) {
|
||||
handleNewDataFromDexcomG5(intent);
|
||||
}
|
||||
} else if (Intents.POCTECH_BG.equals(action)) {
|
||||
if (poctechEnabled) {
|
||||
handleNewDataFromPoctech(intent);
|
||||
}
|
||||
} else if (Intents.ACTION_NEW_SGV.equals(action)) {
|
||||
if (nsClientEnabled || SP.getBoolean(R.string.key_ns_autobackfill, true))
|
||||
handleNewDataFromNSClient(intent);
|
||||
// Objectives 0
|
||||
ObjectivesPlugin.bgIsAvailableInNS = true;
|
||||
ObjectivesPlugin.saveProgress();
|
||||
} else if (isNSProfile && Intents.ACTION_NEW_PROFILE.equals(action) || Intents.ACTION_NEW_DEVICESTATUS.equals(action)) {
|
||||
// always handle Profile if NSProfile is enabled without looking at nsUploadOnly
|
||||
handleNewDataFromNSClient(intent);
|
||||
} else if (acceptNSData &&
|
||||
(Intents.ACTION_NEW_TREATMENT.equals(action) ||
|
||||
Intents.ACTION_CHANGED_TREATMENT.equals(action) ||
|
||||
Intents.ACTION_REMOVED_TREATMENT.equals(action) ||
|
||||
Intents.ACTION_NEW_STATUS.equals(action) ||
|
||||
Intents.ACTION_NEW_DEVICESTATUS.equals(action) ||
|
||||
Intents.ACTION_NEW_FOOD.equals(action) ||
|
||||
Intents.ACTION_CHANGED_FOOD.equals(action) ||
|
||||
Intents.ACTION_REMOVED_FOOD.equals(action) ||
|
||||
Intents.ACTION_NEW_CAL.equals(action) ||
|
||||
Intents.ACTION_NEW_MBG.equals(action))
|
||||
) {
|
||||
handleNewDataFromNSClient(intent);
|
||||
} else if (Telephony.Sms.Intents.SMS_RECEIVED_ACTION.equals(action)) {
|
||||
handleNewSMS(intent);
|
||||
}
|
||||
final String action = intent.getAction();
|
||||
if (Intents.ACTION_NEW_BG_ESTIMATE.equals(action)) {
|
||||
SourceXdripPlugin.getPlugin().handleNewData(intent);
|
||||
} else if (Intents.NS_EMULATOR.equals(action)) {
|
||||
SourceMM640gPlugin.getPlugin().handleNewData(intent);
|
||||
} else if (Intents.GLIMP_BG.equals(action)) {
|
||||
SourceGlimpPlugin.getPlugin().handleNewData(intent);
|
||||
} else if (Intents.DEXCOMG5_BG.equals(action)) {
|
||||
SourceDexcomG5Plugin.getPlugin().handleNewData(intent);
|
||||
} else if (Intents.POCTECH_BG.equals(action)) {
|
||||
SourcePoctechPlugin.getPlugin().handleNewData(intent);
|
||||
} else if (Intents.ACTION_NEW_SGV.equals(action)) {
|
||||
SourceNSClientPlugin.getPlugin().handleNewData(intent);
|
||||
} else if (Intents.ACTION_NEW_PROFILE.equals(action)) {
|
||||
// always handle Profile if NSProfile is enabled without looking at nsUploadOnly
|
||||
NSProfilePlugin.getPlugin().handleNewData(intent);
|
||||
} else if (acceptNSData &&
|
||||
(Intents.ACTION_NEW_TREATMENT.equals(action) ||
|
||||
Intents.ACTION_CHANGED_TREATMENT.equals(action) ||
|
||||
Intents.ACTION_REMOVED_TREATMENT.equals(action) ||
|
||||
Intents.ACTION_NEW_STATUS.equals(action) ||
|
||||
Intents.ACTION_NEW_DEVICESTATUS.equals(action) ||
|
||||
Intents.ACTION_NEW_FOOD.equals(action) ||
|
||||
Intents.ACTION_CHANGED_FOOD.equals(action) ||
|
||||
Intents.ACTION_REMOVED_FOOD.equals(action) ||
|
||||
Intents.ACTION_NEW_CAL.equals(action) ||
|
||||
Intents.ACTION_NEW_MBG.equals(action))
|
||||
) {
|
||||
handleNewDataFromNSClient(intent);
|
||||
} else if (Telephony.Sms.Intents.SMS_RECEIVED_ACTION.equals(action)) {
|
||||
SmsCommunicatorPlugin.getPlugin().handleNewData(intent);
|
||||
}
|
||||
|
||||
if (Config.logFunctionCalls)
|
||||
log.debug("onHandleIntent exit " + intent);
|
||||
DataReceiver.completeWakefulIntent(intent);
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
super.onStartCommand(intent, flags, startId);
|
||||
|
||||
if (Config.logFunctionCalls)
|
||||
log.debug("onStartCommand");
|
||||
|
||||
return START_STICKY;
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
@ -207,142 +115,6 @@ public class DataService extends IntentService {
|
|||
MainApp.bus().register(this);
|
||||
}
|
||||
|
||||
private void handleNewDataFromXDrip(Intent intent) {
|
||||
Bundle bundle = intent.getExtras();
|
||||
if (bundle == null) return;
|
||||
|
||||
BgReading bgReading = new BgReading();
|
||||
|
||||
bgReading.value = bundle.getDouble(Intents.EXTRA_BG_ESTIMATE);
|
||||
bgReading.direction = bundle.getString(Intents.EXTRA_BG_SLOPE_NAME);
|
||||
bgReading.date = bundle.getLong(Intents.EXTRA_TIMESTAMP);
|
||||
bgReading.raw = bundle.getDouble(Intents.EXTRA_RAW);
|
||||
String source = bundle.getString(Intents.XDRIP_DATA_SOURCE_DESCRIPTION, "no Source specified");
|
||||
SourceXdripPlugin.getPlugin().setSource(source);
|
||||
MainApp.getDbHelper().createIfNotExists(bgReading, "XDRIP");
|
||||
}
|
||||
|
||||
private void handleNewDataFromGlimp(Intent intent) {
|
||||
Bundle bundle = intent.getExtras();
|
||||
if (bundle == null) return;
|
||||
|
||||
BgReading bgReading = new BgReading();
|
||||
|
||||
bgReading.value = bundle.getDouble("mySGV");
|
||||
bgReading.direction = bundle.getString("myTrend");
|
||||
bgReading.date = bundle.getLong("myTimestamp");
|
||||
bgReading.raw = 0;
|
||||
|
||||
MainApp.getDbHelper().createIfNotExists(bgReading, "GLIMP");
|
||||
}
|
||||
|
||||
private void handleNewDataFromDexcomG5(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;
|
||||
|
||||
BgReading bgReading = new BgReading();
|
||||
|
||||
String data = bundle.getString("data");
|
||||
log.debug("Received Dexcom Data", data);
|
||||
|
||||
try {
|
||||
JSONArray jsonArray = new JSONArray(data);
|
||||
log.debug("Received Dexcom Data size:" + jsonArray.length());
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
JSONObject json = jsonArray.getJSONObject(i);
|
||||
bgReading.value = json.getInt("m_value");
|
||||
bgReading.direction = json.getString("m_trend");
|
||||
bgReading.date = json.getLong("m_time") * 1000L;
|
||||
bgReading.raw = 0;
|
||||
boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5");
|
||||
if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
|
||||
NSUpload.uploadBg(bgReading);
|
||||
}
|
||||
if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) {
|
||||
NSUpload.sendToXdrip(bgReading);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void handleNewDataFromPoctech(Intent intent) {
|
||||
|
||||
Bundle bundle = intent.getExtras();
|
||||
if (bundle == null) return;
|
||||
|
||||
BgReading bgReading = new BgReading();
|
||||
|
||||
String data = bundle.getString("data");
|
||||
log.debug("Received Poctech Data", data);
|
||||
|
||||
try {
|
||||
JSONArray jsonArray = new JSONArray(data);
|
||||
log.debug("Received Poctech Data size:" + jsonArray.length());
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
JSONObject json = jsonArray.getJSONObject(i);
|
||||
bgReading.value = json.getDouble("current");
|
||||
bgReading.direction = json.getString("direction");
|
||||
bgReading.date = json.getLong("date");
|
||||
bgReading.raw = json.getDouble("raw");
|
||||
if (JsonHelper.safeGetString(json, "units", Constants.MGDL).equals("mmol/L"))
|
||||
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);
|
||||
}
|
||||
if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) {
|
||||
NSUpload.sendToXdrip(bgReading);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void handleNewDataFromMM640g(Intent intent) {
|
||||
Bundle bundle = intent.getExtras();
|
||||
if (bundle == null) return;
|
||||
|
||||
final String collection = bundle.getString("collection");
|
||||
if (collection == null) return;
|
||||
|
||||
if (collection.equals("entries")) {
|
||||
final String data = bundle.getString("data");
|
||||
|
||||
if ((data != null) && (data.length() > 0)) {
|
||||
try {
|
||||
final JSONArray json_array = new JSONArray(data);
|
||||
for (int i = 0; i < json_array.length(); i++) {
|
||||
final JSONObject json_object = json_array.getJSONObject(i);
|
||||
final String type = json_object.getString("type");
|
||||
switch (type) {
|
||||
case "sgv":
|
||||
BgReading bgReading = new BgReading();
|
||||
|
||||
bgReading.value = json_object.getDouble("sgv");
|
||||
bgReading.direction = json_object.getString("direction");
|
||||
bgReading.date = json_object.getLong("date");
|
||||
bgReading.raw = json_object.getDouble("sgv");
|
||||
|
||||
MainApp.getDbHelper().createIfNotExists(bgReading, "MM640g");
|
||||
break;
|
||||
default:
|
||||
log.debug("Unknown entries type: " + type);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
log.error("Got JSON exception: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleNewDataFromNSClient(Intent intent) {
|
||||
Bundle bundles = intent.getExtras();
|
||||
if (bundles == null) return;
|
||||
|
@ -422,20 +194,6 @@ public class DataService extends IntentService {
|
|||
log.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
// Handle profile
|
||||
if (intent.getAction().equals(Intents.ACTION_NEW_PROFILE)) {
|
||||
try {
|
||||
String activeProfile = bundles.getString("activeprofile");
|
||||
String profile = bundles.getString("profile");
|
||||
ProfileStore profileStore = new ProfileStore(new JSONObject(profile));
|
||||
NSProfilePlugin.getPlugin().storeNewProfile(profileStore);
|
||||
MainApp.bus().post(new EventNSProfileUpdateGUI());
|
||||
if (Config.logIncommingData)
|
||||
log.debug("Received profileStore: " + activeProfile + " " + profile);
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (intent.getAction().equals(Intents.ACTION_NEW_TREATMENT) || intent.getAction().equals(Intents.ACTION_CHANGED_TREATMENT)) {
|
||||
try {
|
||||
|
@ -477,27 +235,6 @@ public class DataService extends IntentService {
|
|||
}
|
||||
}
|
||||
|
||||
if (intent.getAction().equals(Intents.ACTION_NEW_SGV)) {
|
||||
try {
|
||||
if (bundles.containsKey("sgv")) {
|
||||
String sgvstring = bundles.getString("sgv");
|
||||
JSONObject sgvJson = new JSONObject(sgvstring);
|
||||
storeSgv(sgvJson);
|
||||
}
|
||||
|
||||
if (bundles.containsKey("sgvs")) {
|
||||
String sgvstring = bundles.getString("sgvs");
|
||||
JSONArray jsonArray = new JSONArray(sgvstring);
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
JSONObject sgvJson = jsonArray.getJSONObject(i);
|
||||
storeSgv(sgvJson);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (intent.getAction().equals(Intents.ACTION_NEW_MBG)) {
|
||||
try {
|
||||
if (bundles.containsKey("mbg")) {
|
||||
|
@ -580,7 +317,7 @@ public class DataService extends IntentService {
|
|||
}
|
||||
|
||||
if (eventType.equals(CareportalEvent.ANNOUNCEMENT)) {
|
||||
long date = JsonHelper.safeGetLong(json,"mills");
|
||||
long date = JsonHelper.safeGetLong(json, "mills");
|
||||
long now = System.currentTimeMillis();
|
||||
String enteredBy = JsonHelper.safeGetString(json, "enteredBy", "");
|
||||
String notes = JsonHelper.safeGetString(json, "notes", "");
|
||||
|
@ -600,17 +337,4 @@ public class DataService extends IntentService {
|
|||
log.debug("Adding/Updating new MBG: " + careportalEvent.log());
|
||||
}
|
||||
|
||||
private void storeSgv(JSONObject sgvJson) {
|
||||
NSSgv nsSgv = new NSSgv(sgvJson);
|
||||
BgReading bgReading = new BgReading(nsSgv);
|
||||
MainApp.getDbHelper().createIfNotExists(bgReading, "NS");
|
||||
SourceNSClientPlugin.getPlugin().detectSource(JsonHelper.safeGetString(sgvJson, "device"), JsonHelper.safeGetLong(sgvJson, "mills"));
|
||||
}
|
||||
|
||||
private void handleNewSMS(Intent intent) {
|
||||
Bundle bundle = intent.getExtras();
|
||||
if (bundle == null) return;
|
||||
MainApp.bus().post(new EventNewSMS(bundle));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
package info.nightscout.androidaps.interfaces;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
/**
|
||||
* Created by mike on 20.06.2016.
|
||||
*/
|
||||
public interface BgSourceInterface {
|
||||
boolean advancedFilteringSupported();
|
||||
|
||||
void handleNewData(Intent intent);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package info.nightscout.androidaps.plugins.ProfileNS;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -65,12 +64,24 @@ public class NSProfilePlugin extends PluginBase implements ProfileInterface {
|
|||
MainApp.bus().unregister(this);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void storeNewProfile(ProfileStore newProfile) {
|
||||
profile = new ProfileStore(newProfile.getData());
|
||||
storeNSProfile();
|
||||
MainApp.bus().post(new EventNSProfileUpdateGUI());
|
||||
MainApp.bus().post(new EventProfileStoreChanged());
|
||||
public void handleNewData(Intent intent) {
|
||||
try {
|
||||
Bundle bundles = intent.getExtras();
|
||||
if (bundles == null) return;
|
||||
|
||||
String activeProfile = bundles.getString("activeprofile");
|
||||
String profileString = bundles.getString("profile");
|
||||
profile = new ProfileStore(new JSONObject(profileString));
|
||||
storeNSProfile();
|
||||
if (isEnabled(PluginType.PROFILE)) {
|
||||
MainApp.bus().post(new EventProfileStoreChanged());
|
||||
MainApp.bus().post(new EventNSProfileUpdateGUI());
|
||||
}
|
||||
if (Config.logIncommingData)
|
||||
log.debug("Received profileStore: " + activeProfile + " " + profile);
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void storeNSProfile() {
|
||||
|
|
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.SmsCommunicator;
|
|||
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.telephony.SmsManager;
|
||||
import android.telephony.SmsMessage;
|
||||
|
@ -39,7 +40,6 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
|||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||
import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS;
|
||||
import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventSmsCommunicatorUpdateGui;
|
||||
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
||||
import info.nightscout.androidaps.queue.Callback;
|
||||
|
@ -165,10 +165,11 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventNewSMS ev) {
|
||||
public void handleNewData(Intent intent) {
|
||||
Bundle bundle = intent.getExtras();
|
||||
if (bundle == null) return;
|
||||
|
||||
Object[] pdus = (Object[]) ev.bundle.get("pdus");
|
||||
Object[] pdus = (Object[]) bundle.get("pdus");
|
||||
if (pdus != null) {
|
||||
// For every SMS message received
|
||||
for (Object pdu : pdus) {
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.SmsCommunicator.events;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import info.nightscout.androidaps.events.Event;
|
||||
|
||||
/**
|
||||
* Created by mike on 13.07.2016.
|
||||
*/
|
||||
public class EventNewSMS extends Event {
|
||||
public Bundle bundle;
|
||||
public EventNewSMS(Bundle bundle) {
|
||||
this.bundle = bundle;
|
||||
}
|
||||
}
|
|
@ -1,17 +1,32 @@
|
|||
package info.nightscout.androidaps.plugins.Source;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
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.interfaces.BgSourceInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.utils.NSUpload;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
/**
|
||||
* Created by mike on 28.11.2017.
|
||||
*/
|
||||
|
||||
public class SourceDexcomG5Plugin extends PluginBase implements BgSourceInterface {
|
||||
private static Logger log = LoggerFactory.getLogger(Constants.BGSOURCE);
|
||||
|
||||
private static SourceDexcomG5Plugin plugin = null;
|
||||
|
||||
|
@ -37,4 +52,43 @@ public class SourceDexcomG5Plugin extends PluginBase implements BgSourceInterfac
|
|||
public boolean advancedFilteringSupported() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleNewData(Intent intent) {
|
||||
// onHandleIntent Bundle{ data => [{"m_time":1511939180,"m_trend":"NotComputable","m_value":335}]; android.support.content.wakelockid => 95; }Bundle
|
||||
|
||||
if (!isEnabled(PluginType.BGSOURCE)) return;
|
||||
|
||||
Bundle bundle = intent.getExtras();
|
||||
if (bundle == null) return;
|
||||
|
||||
BgReading bgReading = new BgReading();
|
||||
|
||||
String data = bundle.getString("data");
|
||||
if (Config.logBgSource)
|
||||
log.debug("Received Dexcom Data", data);
|
||||
|
||||
try {
|
||||
JSONArray jsonArray = new JSONArray(data);
|
||||
if (Config.logBgSource)
|
||||
log.debug("Received Dexcom Data size:" + jsonArray.length());
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
JSONObject json = jsonArray.getJSONObject(i);
|
||||
bgReading.value = json.getInt("m_value");
|
||||
bgReading.direction = json.getString("m_trend");
|
||||
bgReading.date = json.getLong("m_time") * 1000L;
|
||||
bgReading.raw = 0;
|
||||
boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5");
|
||||
if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
|
||||
NSUpload.uploadBg(bgReading);
|
||||
}
|
||||
if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) {
|
||||
NSUpload.sendToXdrip(bgReading);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
log.error("Exception: ", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,27 @@
|
|||
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.Config;
|
||||
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.interfaces.BgSourceInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.utils.BundleLogger;
|
||||
|
||||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
public class SourceGlimpPlugin extends PluginBase implements BgSourceInterface {
|
||||
private static Logger log = LoggerFactory.getLogger(Constants.BGSOURCE);
|
||||
|
||||
private static SourceGlimpPlugin plugin = null;
|
||||
|
||||
|
@ -32,4 +44,25 @@ public class SourceGlimpPlugin extends PluginBase implements BgSourceInterface {
|
|||
public boolean advancedFilteringSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleNewData(Intent intent) {
|
||||
|
||||
if (!isEnabled(PluginType.BGSOURCE)) return;
|
||||
|
||||
Bundle bundle = intent.getExtras();
|
||||
if (bundle == null) return;
|
||||
|
||||
if (Config.logBgSource)
|
||||
log.debug("Received Glimp Data: " + BundleLogger.log(bundle));
|
||||
|
||||
BgReading bgReading = new BgReading();
|
||||
|
||||
bgReading.value = bundle.getDouble("mySGV");
|
||||
bgReading.direction = bundle.getString("myTrend");
|
||||
bgReading.date = bundle.getLong("myTimestamp");
|
||||
bgReading.raw = 0;
|
||||
|
||||
MainApp.getDbHelper().createIfNotExists(bgReading, "GLIMP");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,19 @@
|
|||
package info.nightscout.androidaps.plugins.Source;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
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.interfaces.BgSourceInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||
|
@ -10,6 +23,8 @@ import info.nightscout.androidaps.interfaces.PluginType;
|
|||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
public class SourceMM640gPlugin extends PluginBase implements BgSourceInterface {
|
||||
private static Logger log = LoggerFactory.getLogger(Constants.BGSOURCE);
|
||||
|
||||
private static SourceMM640gPlugin plugin = null;
|
||||
|
||||
public static SourceMM640gPlugin getPlugin() {
|
||||
|
@ -31,4 +46,49 @@ public class SourceMM640gPlugin extends PluginBase implements BgSourceInterface
|
|||
public boolean advancedFilteringSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleNewData(Intent intent) {
|
||||
|
||||
if (!isEnabled(PluginType.BGSOURCE)) return;
|
||||
|
||||
Bundle bundle = intent.getExtras();
|
||||
if (bundle == null) return;
|
||||
|
||||
final String collection = bundle.getString("collection");
|
||||
if (collection == null) return;
|
||||
|
||||
if (collection.equals("entries")) {
|
||||
final String data = bundle.getString("data");
|
||||
if (Config.logBgSource)
|
||||
log.debug("Received MM640g Data: ", data);
|
||||
|
||||
if ((data != null) && (data.length() > 0)) {
|
||||
try {
|
||||
final JSONArray json_array = new JSONArray(data);
|
||||
for (int i = 0; i < json_array.length(); i++) {
|
||||
final JSONObject json_object = json_array.getJSONObject(i);
|
||||
final String type = json_object.getString("type");
|
||||
switch (type) {
|
||||
case "sgv":
|
||||
BgReading bgReading = new BgReading();
|
||||
|
||||
bgReading.value = json_object.getDouble("sgv");
|
||||
bgReading.direction = json_object.getString("direction");
|
||||
bgReading.date = json_object.getLong("date");
|
||||
bgReading.raw = json_object.getDouble("sgv");
|
||||
|
||||
MainApp.getDbHelper().createIfNotExists(bgReading, "MM640g");
|
||||
break;
|
||||
default:
|
||||
if (Config.logBgSource)
|
||||
log.debug("Unknown entries type: " + type);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
log.error("Exception: ", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,32 @@
|
|||
package info.nightscout.androidaps.plugins.Source;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
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.interfaces.BgSourceInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
|
||||
import info.nightscout.utils.JsonHelper;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
public class SourceNSClientPlugin extends PluginBase implements BgSourceInterface {
|
||||
private static Logger log = LoggerFactory.getLogger(Constants.BGSOURCE);
|
||||
|
||||
private static SourceNSClientPlugin plugin = null;
|
||||
|
||||
|
@ -39,6 +55,50 @@ public class SourceNSClientPlugin extends PluginBase implements BgSourceInterfac
|
|||
return isAdvancedFilteringEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleNewData(Intent intent) {
|
||||
|
||||
if (!isEnabled(PluginType.BGSOURCE) && !SP.getBoolean(R.string.key_ns_autobackfill, true))
|
||||
return;
|
||||
|
||||
Bundle bundles = intent.getExtras();
|
||||
|
||||
try {
|
||||
if (bundles.containsKey("sgv")) {
|
||||
String sgvstring = bundles.getString("sgv");
|
||||
if (Config.logBgSource)
|
||||
log.debug("Received NS Data: " + sgvstring);
|
||||
|
||||
JSONObject sgvJson = new JSONObject(sgvstring);
|
||||
storeSgv(sgvJson);
|
||||
}
|
||||
|
||||
if (bundles.containsKey("sgvs")) {
|
||||
String sgvstring = bundles.getString("sgvs");
|
||||
if (Config.logBgSource)
|
||||
log.debug("Received NS Data: " + sgvstring);
|
||||
JSONArray jsonArray = new JSONArray(sgvstring);
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
JSONObject sgvJson = jsonArray.getJSONObject(i);
|
||||
storeSgv(sgvJson);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
|
||||
// Objectives 0
|
||||
ObjectivesPlugin.bgIsAvailableInNS = true;
|
||||
ObjectivesPlugin.saveProgress();
|
||||
}
|
||||
|
||||
private void storeSgv(JSONObject sgvJson) {
|
||||
NSSgv nsSgv = new NSSgv(sgvJson);
|
||||
BgReading bgReading = new BgReading(nsSgv);
|
||||
MainApp.getDbHelper().createIfNotExists(bgReading, "NS");
|
||||
SourceNSClientPlugin.getPlugin().detectSource(JsonHelper.safeGetString(sgvJson, "device"), JsonHelper.safeGetLong(sgvJson, "mills"));
|
||||
}
|
||||
|
||||
public void detectSource(String source, long timeStamp) {
|
||||
if (timeStamp > lastBGTimeStamp) {
|
||||
if (source.contains("G5 Native") || source.contains("AndroidAPS-DexcomG5"))
|
||||
|
|
|
@ -1,16 +1,32 @@
|
|||
package info.nightscout.androidaps.plugins.Source;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
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.interfaces.BgSourceInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.utils.JsonHelper;
|
||||
import info.nightscout.utils.NSUpload;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
public class SourcePoctechPlugin extends PluginBase implements BgSourceInterface {
|
||||
private static Logger log = LoggerFactory.getLogger(Constants.BGSOURCE);
|
||||
|
||||
private static SourcePoctechPlugin plugin = null;
|
||||
|
||||
|
@ -36,4 +52,44 @@ public class SourcePoctechPlugin extends PluginBase implements BgSourceInterface
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleNewData(Intent intent) {
|
||||
|
||||
if (!isEnabled(PluginType.BGSOURCE)) return;
|
||||
|
||||
Bundle bundle = intent.getExtras();
|
||||
if (bundle == null) return;
|
||||
|
||||
BgReading bgReading = new BgReading();
|
||||
|
||||
String data = bundle.getString("data");
|
||||
if (Config.logBgSource)
|
||||
log.debug("Received Poctech Data", data);
|
||||
|
||||
try {
|
||||
JSONArray jsonArray = new JSONArray(data);
|
||||
if (Config.logBgSource)
|
||||
log.debug("Received Poctech Data size:" + jsonArray.length());
|
||||
for (int i = 0; i < jsonArray.length(); i++) {
|
||||
JSONObject json = jsonArray.getJSONObject(i);
|
||||
bgReading.value = json.getDouble("current");
|
||||
bgReading.direction = json.getString("direction");
|
||||
bgReading.date = json.getLong("date");
|
||||
bgReading.raw = json.getDouble("raw");
|
||||
if (JsonHelper.safeGetString(json, "units", Constants.MGDL).equals("mmol/L"))
|
||||
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);
|
||||
}
|
||||
if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) {
|
||||
NSUpload.sendToXdrip(bgReading);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
log.error("Exception: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +1,31 @@
|
|||
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.Config;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.Services.Intents;
|
||||
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.utils.BundleLogger;
|
||||
|
||||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
public class SourceXdripPlugin extends PluginBase implements BgSourceInterface {
|
||||
private static Logger log = LoggerFactory.getLogger(Constants.BGSOURCE);
|
||||
|
||||
private static SourceXdripPlugin plugin = null;
|
||||
|
||||
|
||||
boolean advancedFiltering;
|
||||
|
||||
public static SourceXdripPlugin getPlugin() {
|
||||
|
@ -35,6 +48,28 @@ public class SourceXdripPlugin extends PluginBase implements BgSourceInterface {
|
|||
return advancedFiltering;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleNewData(Intent intent) {
|
||||
|
||||
if (!isEnabled(PluginType.BGSOURCE)) return;
|
||||
|
||||
Bundle bundle = intent.getExtras();
|
||||
if (bundle == null) return;
|
||||
|
||||
if (Config.logBgSource)
|
||||
log.debug("Received xDrip data: " + BundleLogger.log(intent.getExtras()));
|
||||
|
||||
BgReading bgReading = new BgReading();
|
||||
|
||||
bgReading.value = bundle.getDouble(Intents.EXTRA_BG_ESTIMATE);
|
||||
bgReading.direction = bundle.getString(Intents.EXTRA_BG_SLOPE_NAME);
|
||||
bgReading.date = bundle.getLong(Intents.EXTRA_TIMESTAMP);
|
||||
bgReading.raw = bundle.getDouble(Intents.EXTRA_RAW);
|
||||
String source = bundle.getString(Intents.XDRIP_DATA_SOURCE_DESCRIPTION, "no Source specified");
|
||||
SourceXdripPlugin.getPlugin().setSource(source);
|
||||
MainApp.getDbHelper().createIfNotExists(bgReading, "XDRIP");
|
||||
}
|
||||
|
||||
public void setSource(String source) {
|
||||
this.advancedFiltering = source.contains("G5 Native");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue