diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index f6e693e611..d49ee22092 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -63,6 +63,8 @@
+
+
diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java
index e2e7eabd89..9e609a3b15 100644
--- a/app/src/main/java/info/nightscout/androidaps/MainApp.java
+++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java
@@ -33,6 +33,7 @@ import info.nightscout.androidaps.plugins.Overview.OverviewFragment;
import info.nightscout.androidaps.plugins.SafetyFragment.SafetyFragment;
import info.nightscout.androidaps.plugins.SimpleProfile.SimpleProfileFragment;
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorFragment;
+import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gFragment;
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientFragment;
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripFragment;
import info.nightscout.androidaps.plugins.TempBasals.TempBasalsFragment;
@@ -89,6 +90,7 @@ public class MainApp extends Application {
if (Config.APS) pluginsList.add(ObjectivesFragment.getPlugin());
pluginsList.add(SourceXdripFragment.getPlugin());
pluginsList.add(SourceNSClientFragment.getPlugin());
+ pluginsList.add(SourceMM640gFragment.getPlugin());
if (Config.SMSCOMMUNICATORENABLED)
pluginsList.add(SmsCommunicatorFragment.getPlugin());
diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java
index 95a6b81b68..734e3defaf 100644
--- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java
+++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java
@@ -42,6 +42,7 @@ import info.nightscout.androidaps.plugins.Objectives.ObjectivesPlugin;
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin;
import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS;
+import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gPlugin;
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin;
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin;
import info.nightscout.androidaps.receivers.DataReceiver;
@@ -55,6 +56,7 @@ public class DataService extends IntentService {
boolean xDripEnabled = false;
boolean nsClientEnabled = true;
+ boolean mm640gEnabled = false;
public DataService() {
super("DataService");
@@ -69,9 +71,15 @@ public class DataService extends IntentService {
if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceXdripPlugin.class)) {
xDripEnabled = true;
nsClientEnabled = false;
+ mm640gEnabled = false;
} else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceNSClientPlugin.class)) {
xDripEnabled = false;
nsClientEnabled = true;
+ mm640gEnabled = false;
+ } else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceMM640gPlugin.class)) {
+ xDripEnabled = false;
+ nsClientEnabled = false;
+ mm640gEnabled = true;
}
boolean isNSProfile = ConfigBuilderPlugin.getActiveProfile().getClass().equals(NSProfilePlugin.class);
@@ -85,6 +93,10 @@ public class DataService extends IntentService {
if (xDripEnabled) {
handleNewDataFromXDrip(intent);
}
+ } else if (Intents.NS_EMULATOR.equals(action)) {
+ if (mm640gEnabled) {
+ handleNewDataFromMM640g(intent);
+ }
} else if (Intents.ACTION_NEW_SGV.equals(action)) {
// always handle SGV if NS-Client is the source
if (nsClientEnabled) {
@@ -171,6 +183,58 @@ public class DataService extends IntentService {
MainApp.bus().post(new EventNewBG());
}
+ 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.timeIndex = json_object.getLong("date");
+ bgReading.raw = json_object.getDouble("sgv");
+
+ if (bgReading.timeIndex < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) {
+ if (Config.logIncommingBG)
+ log.debug("Ignoring old MM640g BG " + bgReading.toString());
+ return;
+ }
+
+ if (Config.logIncommingBG)
+ log.debug("MM640g BG " + bgReading.toString());
+
+ try {
+ MainApp.getDbHelper().getDaoBgReadings().createIfNotExists(bgReading);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ break;
+ default:
+ log.debug("Unknown entries type: " + type);
+ }
+ }
+ } catch (JSONException e) {
+ log.error("Got JSON exception: " + e);
+ }
+ }
+ }
+ MainApp.bus().post(new EventNewBG());
+ }
+
private void handleNewDataFromNSClient(Intent intent) {
Bundle bundles = intent.getExtras();
if (bundles == null) return;
diff --git a/app/src/main/java/info/nightscout/androidaps/Services/Intents.java b/app/src/main/java/info/nightscout/androidaps/Services/Intents.java
index 63ef83e298..e46071e7ff 100644
--- a/app/src/main/java/info/nightscout/androidaps/Services/Intents.java
+++ b/app/src/main/java/info/nightscout/androidaps/Services/Intents.java
@@ -29,4 +29,6 @@ public interface Intents {
String EXTRA_RAW = "com.eveningoutpost.dexdrip.Extras.Raw";
String ACTION_NEW_BG_ESTIMATE_NO_DATA = "com.eveningoutpost.dexdrip.BgEstimateNoData";
+
+ String NS_EMULATOR = "com.eveningoutpost.dexdrip.NS_EMULATOR";
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gFragment.java
new file mode 100644
index 0000000000..f43dc6ada7
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gFragment.java
@@ -0,0 +1,16 @@
+package info.nightscout.androidaps.plugins.SourceMM640g;
+
+
+import android.support.v4.app.Fragment;
+
+import info.nightscout.androidaps.interfaces.FragmentBase;
+
+public class SourceMM640gFragment extends Fragment implements FragmentBase {
+
+ private static SourceMM640gPlugin sourceMM640gPlugin = new SourceMM640gPlugin();
+
+ public static SourceMM640gPlugin getPlugin() {
+ return sourceMM640gPlugin;
+ }
+
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gPlugin.java
new file mode 100644
index 0000000000..f7f0de23fb
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gPlugin.java
@@ -0,0 +1,56 @@
+package info.nightscout.androidaps.plugins.SourceMM640g;
+
+import info.nightscout.androidaps.MainApp;
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.interfaces.BgSourceInterface;
+import info.nightscout.androidaps.interfaces.PluginBase;
+import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientFragment;
+
+/**
+ * Created by mike on 05.08.2016.
+ */
+public class SourceMM640gPlugin implements PluginBase, BgSourceInterface {
+ boolean fragmentEnabled = true;
+
+ @Override
+ public String getFragmentClass() {
+ return SourceMM640gFragment.class.getName();
+ }
+
+ @Override
+ public int getType() {
+ return PluginBase.BGSOURCE;
+ }
+
+ @Override
+ public String getName() {
+ return MainApp.instance().getString(R.string.MM640g);
+ }
+
+ @Override
+ public boolean isEnabled(int type) {
+ return type == BGSOURCE && fragmentEnabled;
+ }
+
+ @Override
+ public boolean isVisibleInTabs(int type) {
+ return false;
+ }
+
+ @Override
+ public boolean canBeHidden(int type) {
+ return true;
+ }
+
+ @Override
+ public void setFragmentEnabled(int type, boolean fragmentEnabled) {
+ if (type == BGSOURCE) this.fragmentEnabled = fragmentEnabled;
+ }
+
+ @Override
+ public void setFragmentVisible(int type, boolean fragmentVisible) {
+
+ }
+
+
+}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 87b200db28..586bc7176b 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -387,4 +387,5 @@
BG:
Last BG:
MDI
+ MM640g