Have Bgsource.processNewData return added BGs.
This commit is contained in:
parent
922f9ff83d
commit
aab171932c
8 changed files with 142 additions and 88 deletions
|
@ -71,6 +71,8 @@ public class DataService extends IntentService {
|
||||||
protected void onHandleIntent(final Intent intent) {
|
protected void onHandleIntent(final Intent intent) {
|
||||||
if (intent == null)
|
if (intent == null)
|
||||||
return;
|
return;
|
||||||
|
if (Config.logIncommingData)
|
||||||
|
log.debug("Got intent: " + intent.getAction());
|
||||||
if (Config.logFunctionCalls)
|
if (Config.logFunctionCalls)
|
||||||
log.debug("onHandleIntent " + BundleLogger.log(intent.getExtras()));
|
log.debug("onHandleIntent " + BundleLogger.log(intent.getExtras()));
|
||||||
if (ConfigBuilderPlugin.getActiveBgSource() == null) {
|
if (ConfigBuilderPlugin.getActiveBgSource() == null) {
|
||||||
|
@ -203,25 +205,21 @@ public class DataService extends IntentService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processNewBgIntent(BgSourceInterface bgSource, Intent intent) {
|
private void processNewBgIntent(BgSourceInterface bgSource, Intent intent) {
|
||||||
if (Config.logIncommingData)
|
|
||||||
log.debug("Got intent: " + intent.getAction());
|
|
||||||
Bundle bundle = intent.getExtras();
|
Bundle bundle = intent.getExtras();
|
||||||
if (bundle == null) return;
|
if (bundle == null) return;
|
||||||
bgSource.processNewData(bundle);
|
bgSource.processNewData(bundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleNewDataFromNSClient(Intent intent) {
|
private void handleNewDataFromNSClient(Intent intent) {
|
||||||
Bundle bundles = intent.getExtras();
|
Bundle bundle = intent.getExtras();
|
||||||
if (bundles == null) return;
|
if (bundle == null) return;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (intent.getAction().equals(Intents.ACTION_NEW_STATUS)) {
|
if (intent.getAction().equals(Intents.ACTION_NEW_STATUS)) {
|
||||||
if (bundles.containsKey("nsclientversioncode")) {
|
if (bundle.containsKey("nsclientversioncode")) {
|
||||||
ConfigBuilderPlugin.nightscoutVersionCode = bundles.getInt("nightscoutversioncode"); // for ver 1.2.3 contains 10203
|
ConfigBuilderPlugin.nightscoutVersionCode = bundle.getInt("nightscoutversioncode"); // for ver 1.2.3 contains 10203
|
||||||
ConfigBuilderPlugin.nightscoutVersionName = bundles.getString("nightscoutversionname");
|
ConfigBuilderPlugin.nightscoutVersionName = bundle.getString("nightscoutversionname");
|
||||||
ConfigBuilderPlugin.nsClientVersionCode = bundles.getInt("nsclientversioncode"); // for ver 1.17 contains 117
|
ConfigBuilderPlugin.nsClientVersionCode = bundle.getInt("nsclientversioncode"); // for ver 1.17 contains 117
|
||||||
ConfigBuilderPlugin.nsClientVersionName = bundles.getString("nsclientversionname");
|
ConfigBuilderPlugin.nsClientVersionName = bundle.getString("nsclientversionname");
|
||||||
log.debug("Got versions: NSClient: " + ConfigBuilderPlugin.nsClientVersionName + " Nightscout: " + ConfigBuilderPlugin.nightscoutVersionName);
|
log.debug("Got versions: NSClient: " + ConfigBuilderPlugin.nsClientVersionName + " Nightscout: " + ConfigBuilderPlugin.nightscoutVersionName);
|
||||||
try {
|
try {
|
||||||
if (ConfigBuilderPlugin.nsClientVersionCode < MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionCode) {
|
if (ConfigBuilderPlugin.nsClientVersionCode < MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionCode) {
|
||||||
|
@ -243,9 +241,9 @@ public class DataService extends IntentService {
|
||||||
Notification notification = new Notification(Notification.OLD_NSCLIENT, MainApp.gs(R.string.unsupportedclientver), Notification.URGENT);
|
Notification notification = new Notification(Notification.OLD_NSCLIENT, MainApp.gs(R.string.unsupportedclientver), Notification.URGENT);
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
}
|
}
|
||||||
if (bundles.containsKey("status")) {
|
if (bundle.containsKey("status")) {
|
||||||
try {
|
try {
|
||||||
JSONObject statusJson = new JSONObject(bundles.getString("status"));
|
JSONObject statusJson = new JSONObject(bundle.getString("status"));
|
||||||
NSSettingsStatus.getInstance().setData(statusJson);
|
NSSettingsStatus.getInstance().setData(statusJson);
|
||||||
if (Config.logIncommingData)
|
if (Config.logIncommingData)
|
||||||
log.debug("Received status: " + statusJson.toString());
|
log.debug("Received status: " + statusJson.toString());
|
||||||
|
@ -262,8 +260,8 @@ public class DataService extends IntentService {
|
||||||
}
|
}
|
||||||
if (intent.getAction().equals(Intents.ACTION_NEW_DEVICESTATUS)) {
|
if (intent.getAction().equals(Intents.ACTION_NEW_DEVICESTATUS)) {
|
||||||
try {
|
try {
|
||||||
if (bundles.containsKey("devicestatus")) {
|
if (bundle.containsKey("devicestatus")) {
|
||||||
JSONObject devicestatusJson = new JSONObject(bundles.getString("devicestatus"));
|
JSONObject devicestatusJson = new JSONObject(bundle.getString("devicestatus"));
|
||||||
NSDeviceStatus.getInstance().setData(devicestatusJson);
|
NSDeviceStatus.getInstance().setData(devicestatusJson);
|
||||||
if (devicestatusJson.has("pump")) {
|
if (devicestatusJson.has("pump")) {
|
||||||
// Objectives 0
|
// Objectives 0
|
||||||
|
@ -271,8 +269,8 @@ public class DataService extends IntentService {
|
||||||
ObjectivesPlugin.saveProgress();
|
ObjectivesPlugin.saveProgress();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bundles.containsKey("devicestatuses")) {
|
if (bundle.containsKey("devicestatuses")) {
|
||||||
String devicestatusesstring = bundles.getString("devicestatuses");
|
String devicestatusesstring = bundle.getString("devicestatuses");
|
||||||
JSONArray jsonArray = new JSONArray(devicestatusesstring);
|
JSONArray jsonArray = new JSONArray(devicestatusesstring);
|
||||||
for (int i = 0; i < jsonArray.length(); i++) {
|
for (int i = 0; i < jsonArray.length(); i++) {
|
||||||
JSONObject devicestatusJson = jsonArray.getJSONObject(i);
|
JSONObject devicestatusJson = jsonArray.getJSONObject(i);
|
||||||
|
@ -291,8 +289,8 @@ public class DataService extends IntentService {
|
||||||
// Handle profile
|
// Handle profile
|
||||||
if (intent.getAction().equals(Intents.ACTION_NEW_PROFILE)) {
|
if (intent.getAction().equals(Intents.ACTION_NEW_PROFILE)) {
|
||||||
try {
|
try {
|
||||||
String activeProfile = bundles.getString("activeprofile");
|
String activeProfile = bundle.getString("activeprofile");
|
||||||
String profile = bundles.getString("profile");
|
String profile = bundle.getString("profile");
|
||||||
ProfileStore profileStore = new ProfileStore(new JSONObject(profile));
|
ProfileStore profileStore = new ProfileStore(new JSONObject(profile));
|
||||||
NSProfilePlugin.getPlugin().storeNewProfile(profileStore);
|
NSProfilePlugin.getPlugin().storeNewProfile(profileStore);
|
||||||
MainApp.bus().post(new EventNSProfileUpdateGUI());
|
MainApp.bus().post(new EventNSProfileUpdateGUI());
|
||||||
|
@ -305,12 +303,12 @@ public class DataService extends IntentService {
|
||||||
|
|
||||||
if (intent.getAction().equals(Intents.ACTION_NEW_TREATMENT) || intent.getAction().equals(Intents.ACTION_CHANGED_TREATMENT)) {
|
if (intent.getAction().equals(Intents.ACTION_NEW_TREATMENT) || intent.getAction().equals(Intents.ACTION_CHANGED_TREATMENT)) {
|
||||||
try {
|
try {
|
||||||
if (bundles.containsKey("treatment")) {
|
if (bundle.containsKey("treatment")) {
|
||||||
JSONObject json = new JSONObject(bundles.getString("treatment"));
|
JSONObject json = new JSONObject(bundle.getString("treatment"));
|
||||||
handleTreatmentFromNS(json, intent);
|
handleTreatmentFromNS(json, intent);
|
||||||
}
|
}
|
||||||
if (bundles.containsKey("treatments")) {
|
if (bundle.containsKey("treatments")) {
|
||||||
String trstring = bundles.getString("treatments");
|
String trstring = bundle.getString("treatments");
|
||||||
JSONArray jsonArray = new JSONArray(trstring);
|
JSONArray jsonArray = new JSONArray(trstring);
|
||||||
for (int i = 0; i < jsonArray.length(); i++) {
|
for (int i = 0; i < jsonArray.length(); i++) {
|
||||||
JSONObject json = jsonArray.getJSONObject(i);
|
JSONObject json = jsonArray.getJSONObject(i);
|
||||||
|
@ -324,14 +322,14 @@ public class DataService extends IntentService {
|
||||||
|
|
||||||
if (intent.getAction().equals(Intents.ACTION_REMOVED_TREATMENT)) {
|
if (intent.getAction().equals(Intents.ACTION_REMOVED_TREATMENT)) {
|
||||||
try {
|
try {
|
||||||
if (bundles.containsKey("treatment")) {
|
if (bundle.containsKey("treatment")) {
|
||||||
String trstring = bundles.getString("treatment");
|
String trstring = bundle.getString("treatment");
|
||||||
JSONObject json = new JSONObject(trstring);
|
JSONObject json = new JSONObject(trstring);
|
||||||
handleTreatmentFromNS(json);
|
handleTreatmentFromNS(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bundles.containsKey("treatments")) {
|
if (bundle.containsKey("treatments")) {
|
||||||
String trstring = bundles.getString("treatments");
|
String trstring = bundle.getString("treatments");
|
||||||
JSONArray jsonArray = new JSONArray(trstring);
|
JSONArray jsonArray = new JSONArray(trstring);
|
||||||
for (int i = 0; i < jsonArray.length(); i++) {
|
for (int i = 0; i < jsonArray.length(); i++) {
|
||||||
JSONObject json = jsonArray.getJSONObject(i);
|
JSONObject json = jsonArray.getJSONObject(i);
|
||||||
|
@ -344,36 +342,19 @@ public class DataService extends IntentService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (intent.getAction().equals(Intents.ACTION_NEW_SGV)) {
|
if (intent.getAction().equals(Intents.ACTION_NEW_SGV)) {
|
||||||
try {
|
SourceNSClientPlugin.getPlugin().processNewData(bundle);
|
||||||
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)) {
|
if (intent.getAction().equals(Intents.ACTION_NEW_MBG)) {
|
||||||
try {
|
try {
|
||||||
if (bundles.containsKey("mbg")) {
|
if (bundle.containsKey("mbg")) {
|
||||||
String mbgstring = bundles.getString("mbg");
|
String mbgstring = bundle.getString("mbg");
|
||||||
JSONObject mbgJson = new JSONObject(mbgstring);
|
JSONObject mbgJson = new JSONObject(mbgstring);
|
||||||
storeMbg(mbgJson);
|
storeMbg(mbgJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bundles.containsKey("mbgs")) {
|
if (bundle.containsKey("mbgs")) {
|
||||||
String sgvstring = bundles.getString("mbgs");
|
String sgvstring = bundle.getString("mbgs");
|
||||||
JSONArray jsonArray = new JSONArray(sgvstring);
|
JSONArray jsonArray = new JSONArray(sgvstring);
|
||||||
for (int i = 0; i < jsonArray.length(); i++) {
|
for (int i = 0; i < jsonArray.length(); i++) {
|
||||||
JSONObject mbgJson = jsonArray.getJSONObject(i);
|
JSONObject mbgJson = jsonArray.getJSONObject(i);
|
||||||
|
@ -388,12 +369,12 @@ public class DataService extends IntentService {
|
||||||
if (intent.getAction().equals(Intents.ACTION_NEW_FOOD)
|
if (intent.getAction().equals(Intents.ACTION_NEW_FOOD)
|
||||||
|| intent.getAction().equals(Intents.ACTION_CHANGED_FOOD)) {
|
|| intent.getAction().equals(Intents.ACTION_CHANGED_FOOD)) {
|
||||||
int mode = Intents.ACTION_NEW_FOOD.equals(intent.getAction()) ? EventNsFood.ADD : EventNsFood.UPDATE;
|
int mode = Intents.ACTION_NEW_FOOD.equals(intent.getAction()) ? EventNsFood.ADD : EventNsFood.UPDATE;
|
||||||
EventNsFood evt = new EventNsFood(mode, bundles);
|
EventNsFood evt = new EventNsFood(mode, bundle);
|
||||||
MainApp.bus().post(evt);
|
MainApp.bus().post(evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (intent.getAction().equals(Intents.ACTION_REMOVED_FOOD)) {
|
if (intent.getAction().equals(Intents.ACTION_REMOVED_FOOD)) {
|
||||||
EventNsFood evt = new EventNsFood(EventNsFood.REMOVE, bundles);
|
EventNsFood evt = new EventNsFood(EventNsFood.REMOVE, bundle);
|
||||||
MainApp.bus().post(evt);
|
MainApp.bus().post(evt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -466,13 +447,6 @@ public class DataService extends IntentService {
|
||||||
log.debug("Adding/Updating new MBG: " + careportalEvent.log());
|
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) {
|
private void handleNewSMS(Intent intent) {
|
||||||
Bundle bundle = intent.getExtras();
|
Bundle bundle = intent.getExtras();
|
||||||
if (bundle == null) return;
|
if (bundle == null) return;
|
||||||
|
|
|
@ -2,9 +2,13 @@ package info.nightscout.androidaps.interfaces;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 20.06.2016.
|
* Created by mike on 20.06.2016.
|
||||||
*/
|
*/
|
||||||
public interface BgSourceInterface {
|
public interface BgSourceInterface {
|
||||||
void processNewData(Bundle bundle);
|
List<BgReading> processNewData(Bundle bundle);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,18 @@ package info.nightscout.androidaps.plugins.Source;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
@ -47,8 +53,8 @@ public class SourceDexcomG5Plugin extends PluginBase implements BgSourceInterfac
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processNewData(Bundle bundle) {
|
public List<BgReading> processNewData(Bundle bundle) {
|
||||||
BgReading bgReading = new BgReading();
|
List<BgReading> bgReadings = new ArrayList<>();
|
||||||
|
|
||||||
String data = bundle.getString("data");
|
String data = bundle.getString("data");
|
||||||
// onHandleIntent Bundle{ data => [{"m_time":1511939180,"m_trend":"NotComputable","m_value":335}]; android.support.content.wakelockid => 95; }Bundle
|
// onHandleIntent Bundle{ data => [{"m_time":1511939180,"m_trend":"NotComputable","m_value":335}]; android.support.content.wakelockid => 95; }Bundle
|
||||||
|
@ -59,22 +65,27 @@ public class SourceDexcomG5Plugin extends PluginBase implements BgSourceInterfac
|
||||||
log.debug("Received Dexcom Data size:" + jsonArray.length());
|
log.debug("Received Dexcom Data size:" + jsonArray.length());
|
||||||
for (int i = 0; i < jsonArray.length(); i++) {
|
for (int i = 0; i < jsonArray.length(); i++) {
|
||||||
JSONObject json = jsonArray.getJSONObject(i);
|
JSONObject json = jsonArray.getJSONObject(i);
|
||||||
|
BgReading bgReading = new BgReading();
|
||||||
bgReading.value = json.getInt("m_value");
|
bgReading.value = json.getInt("m_value");
|
||||||
bgReading.direction = json.getString("m_trend");
|
bgReading.direction = json.getString("m_trend");
|
||||||
bgReading.date = json.getLong("m_time") * 1000L;
|
bgReading.date = json.getLong("m_time") * 1000L;
|
||||||
bgReading.raw = 0;
|
bgReading.raw = 0;
|
||||||
bgReading.filtered = true;
|
bgReading.filtered = true;
|
||||||
bgReading.sourcePlugin = SourceDexcomG5Plugin.getPlugin().getName();
|
bgReading.sourcePlugin = SourceDexcomG5Plugin.getPlugin().getName();
|
||||||
boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5");
|
boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, getName());
|
||||||
if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
|
if (isNew) {
|
||||||
NSUpload.uploadBg(bgReading);
|
bgReadings.add(bgReading);
|
||||||
}
|
if (SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
|
||||||
if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) {
|
NSUpload.uploadBg(bgReading);
|
||||||
NSUpload.sendToXdrip(bgReading);
|
}
|
||||||
|
if (SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) {
|
||||||
|
NSUpload.sendToXdrip(bgReading);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
|
return bgReadings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,11 @@ package info.nightscout.androidaps.plugins.Source;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -33,7 +38,7 @@ public class SourceGlimpPlugin extends PluginBase implements BgSourceInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processNewData(Bundle bundle) {
|
public List<BgReading> processNewData(Bundle bundle) {
|
||||||
BgReading bgReading = new BgReading();
|
BgReading bgReading = new BgReading();
|
||||||
|
|
||||||
bgReading.value = bundle.getDouble("mySGV");
|
bgReading.value = bundle.getDouble("mySGV");
|
||||||
|
@ -43,6 +48,7 @@ public class SourceGlimpPlugin extends PluginBase implements BgSourceInterface {
|
||||||
bgReading.filtered = false;
|
bgReading.filtered = false;
|
||||||
bgReading.sourcePlugin = SourceGlimpPlugin.getPlugin().getName();
|
bgReading.sourcePlugin = SourceGlimpPlugin.getPlugin().getName();
|
||||||
|
|
||||||
MainApp.getDbHelper().createIfNotExists(bgReading, getName());
|
boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, getName());
|
||||||
|
return isNew ? Lists.newArrayList(bgReading) : Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,10 @@ import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -40,11 +44,10 @@ public class SourceMM640gPlugin extends PluginBase implements BgSourceInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processNewData(Bundle bundle) {
|
public List<BgReading> processNewData(Bundle bundle) {
|
||||||
final String collection = bundle.getString("collection");
|
List<BgReading> bgReadings = new ArrayList<>();
|
||||||
if (collection == null) return;
|
|
||||||
|
|
||||||
if (collection.equals("entries")) {
|
if (Objects.equals(bundle.getString("collection"), "entries")) {
|
||||||
final String data = bundle.getString("data");
|
final String data = bundle.getString("data");
|
||||||
|
|
||||||
if ((data != null) && (data.length() > 0)) {
|
if ((data != null) && (data.length() > 0)) {
|
||||||
|
@ -64,7 +67,10 @@ public class SourceMM640gPlugin extends PluginBase implements BgSourceInterface
|
||||||
bgReading.filtered = true;
|
bgReading.filtered = true;
|
||||||
bgReading.sourcePlugin = SourceMM640gPlugin.getPlugin().getName();
|
bgReading.sourcePlugin = SourceMM640gPlugin.getPlugin().getName();
|
||||||
|
|
||||||
MainApp.getDbHelper().createIfNotExists(bgReading, "MM640g");
|
boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, getName());
|
||||||
|
if (isNew) {
|
||||||
|
bgReadings.add(bgReading);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
log.debug("Unknown entries type: " + type);
|
log.debug("Unknown entries type: " + type);
|
||||||
|
@ -75,5 +81,7 @@ public class SourceMM640gPlugin extends PluginBase implements BgSourceInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return bgReadings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,17 +2,29 @@ package info.nightscout.androidaps.plugins.Source;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
|
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.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;
|
||||||
import info.nightscout.androidaps.interfaces.PluginType;
|
import info.nightscout.androidaps.interfaces.PluginType;
|
||||||
|
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 05.08.2016.
|
* Created by mike on 05.08.2016.
|
||||||
*/
|
*/
|
||||||
public class SourceNSClientPlugin extends PluginBase implements BgSourceInterface {
|
public class SourceNSClientPlugin extends PluginBase implements BgSourceInterface {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(SourceNSClientPlugin.class);
|
||||||
|
|
||||||
private static SourceNSClientPlugin plugin = null;
|
private static SourceNSClientPlugin plugin = null;
|
||||||
|
|
||||||
|
@ -34,8 +46,35 @@ public class SourceNSClientPlugin extends PluginBase implements BgSourceInterfac
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processNewData(Bundle bundle) {
|
public List<BgReading> processNewData(Bundle bundle) {
|
||||||
// TODO
|
List<BgReading> sgvs = new ArrayList<>();
|
||||||
throw new IllegalStateException("Nope");
|
try {
|
||||||
|
if (bundle.containsKey("sgv")) {
|
||||||
|
String sgvstring = bundle.getString("sgv");
|
||||||
|
JSONObject sgvJson = new JSONObject(sgvstring);
|
||||||
|
BgReading bgReading = new BgReading(new NSSgv(sgvJson));
|
||||||
|
boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, getName());
|
||||||
|
if (isNew) {
|
||||||
|
sgvs.add(bgReading);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bundle.containsKey("sgvs")) {
|
||||||
|
String sgvstring = bundle.getString("sgvs");
|
||||||
|
JSONArray jsonArray = new JSONArray(sgvstring);
|
||||||
|
for (int i = 0; i < jsonArray.length(); i++) {
|
||||||
|
JSONObject sgvJson = jsonArray.getJSONObject(i);
|
||||||
|
BgReading bgReading = new BgReading(new NSSgv(sgvJson));
|
||||||
|
boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "NS");
|
||||||
|
if (isNew) {
|
||||||
|
sgvs.add(bgReading);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Unhandled exception", e);
|
||||||
|
}
|
||||||
|
return sgvs;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,9 @@ import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
@ -47,8 +50,8 @@ public class SourcePoctechPlugin extends PluginBase implements BgSourceInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processNewData(Bundle bundle) {
|
public List<BgReading> processNewData(Bundle bundle) {
|
||||||
BgReading bgReading = new BgReading();
|
List<BgReading> bgReadings = new ArrayList<>();
|
||||||
|
|
||||||
String data = bundle.getString("data");
|
String data = bundle.getString("data");
|
||||||
log.debug("Received Poctech Data", data);
|
log.debug("Received Poctech Data", data);
|
||||||
|
@ -58,23 +61,27 @@ public class SourcePoctechPlugin extends PluginBase implements BgSourceInterface
|
||||||
log.debug("Received Poctech Data size:" + jsonArray.length());
|
log.debug("Received Poctech Data size:" + jsonArray.length());
|
||||||
for (int i = 0; i < jsonArray.length(); i++) {
|
for (int i = 0; i < jsonArray.length(); i++) {
|
||||||
JSONObject json = jsonArray.getJSONObject(i);
|
JSONObject json = jsonArray.getJSONObject(i);
|
||||||
|
BgReading bgReading = new BgReading();
|
||||||
bgReading.value = json.getDouble("current");
|
bgReading.value = json.getDouble("current");
|
||||||
bgReading.direction = json.getString("direction");
|
bgReading.direction = json.getString("direction");
|
||||||
bgReading.date = json.getLong("date");
|
bgReading.date = json.getLong("date");
|
||||||
bgReading.raw = json.getDouble("raw");
|
bgReading.raw = json.getDouble("raw");
|
||||||
if (JsonHelper.safeGetString(json, "utils", Constants.MGDL).equals("mmol/L"))
|
if (JsonHelper.safeGetString(json, "utils", Constants.MGDL).equals("mmol/L"))
|
||||||
bgReading.value = bgReading.value * Constants.MMOLL_TO_MGDL;
|
bgReading.value = bgReading.value * Constants.MMOLL_TO_MGDL;
|
||||||
boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "Poctech");
|
boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, getName());
|
||||||
if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
|
if (isNew) {
|
||||||
NSUpload.uploadBg(bgReading);
|
bgReadings.add(bgReading);
|
||||||
}
|
if (SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
|
||||||
if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) {
|
NSUpload.uploadBg(bgReading);
|
||||||
NSUpload.sendToXdrip(bgReading);
|
}
|
||||||
|
if (SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) {
|
||||||
|
NSUpload.sendToXdrip(bgReading);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
|
return bgReadings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,10 @@ package info.nightscout.androidaps.plugins.Source;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
@ -36,7 +40,7 @@ public class SourceXdripPlugin extends PluginBase implements BgSourceInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processNewData(Bundle bundle) {
|
public List<BgReading> processNewData(Bundle bundle) {
|
||||||
BgReading bgReading = new BgReading();
|
BgReading bgReading = new BgReading();
|
||||||
|
|
||||||
bgReading.value = bundle.getDouble(Intents.EXTRA_BG_ESTIMATE);
|
bgReading.value = bundle.getDouble(Intents.EXTRA_BG_ESTIMATE);
|
||||||
|
@ -46,6 +50,7 @@ public class SourceXdripPlugin extends PluginBase implements BgSourceInterface {
|
||||||
bgReading.sourcePlugin = SourceXdripPlugin.getPlugin().getName();
|
bgReading.sourcePlugin = SourceXdripPlugin.getPlugin().getName();
|
||||||
bgReading.filtered = Objects.equals(bundle.getString(Intents.XDRIP_DATA_SOURCE_DESCRIPTION), "G5 Native");
|
bgReading.filtered = Objects.equals(bundle.getString(Intents.XDRIP_DATA_SOURCE_DESCRIPTION), "G5 Native");
|
||||||
|
|
||||||
MainApp.getDbHelper().createIfNotExists(bgReading, "XDRIP");
|
boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, getName());
|
||||||
|
return isNew ? Lists.newArrayList(bgReading) : Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue