Poctech BG source

This commit is contained in:
Milos Kozak 2018-06-11 17:26:31 +02:00
parent ec5b0cc3f7
commit e7eec8fe69
8 changed files with 123 additions and 1 deletions

View file

@ -82,6 +82,8 @@
<action android:name="it.ct.glicemia.ACTION_GLUCOSE_MEASURED" />
<!-- Receiver from DexcomG5 -->
<action android:name="com.dexcom.cgm.DATA" />
<!-- Receiver from Poctech -->
<action android:name="com.china.poctech.data" />
</intent-filter>
</receiver>
<!-- Receiver keepalive, scheduled every 30 min -->

View file

@ -69,6 +69,7 @@ import info.nightscout.androidaps.plugins.Source.SourceDexcomG5Plugin;
import info.nightscout.androidaps.plugins.Source.SourceGlimpPlugin;
import info.nightscout.androidaps.plugins.Source.SourceMM640gPlugin;
import info.nightscout.androidaps.plugins.Source.SourceNSClientPlugin;
import info.nightscout.androidaps.plugins.Source.SourcePoctechPlugin;
import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.androidaps.plugins.Wear.WearPlugin;
@ -178,6 +179,8 @@ public class MainApp extends Application {
pluginsList.add(SourceGlimpPlugin.getPlugin());
if (!Config.NSCLIENT)
pluginsList.add(SourceDexcomG5Plugin.getPlugin());
if (!Config.NSCLIENT)
pluginsList.add(SourcePoctechPlugin.getPlugin());
if (Config.SMSCOMMUNICATORENABLED) pluginsList.add(SmsCommunicatorPlugin.getPlugin());
pluginsList.add(FoodPlugin.getPlugin());

View file

@ -13,6 +13,7 @@ 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;
@ -38,6 +39,7 @@ import info.nightscout.androidaps.plugins.Source.SourceDexcomG5Plugin;
import info.nightscout.androidaps.plugins.Source.SourceGlimpPlugin;
import info.nightscout.androidaps.plugins.Source.SourceMM640gPlugin;
import info.nightscout.androidaps.plugins.Source.SourceNSClientPlugin;
import info.nightscout.androidaps.plugins.Source.SourcePoctechPlugin;
import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin;
import info.nightscout.androidaps.receivers.DataReceiver;
import info.nightscout.utils.BundleLogger;
@ -54,6 +56,7 @@ public class DataService extends IntentService {
boolean mm640gEnabled = false;
boolean glimpEnabled = false;
boolean dexcomG5Enabled = false;
boolean poctechEnabled = false;
public DataService() {
super("DataService");
@ -70,36 +73,49 @@ public class DataService extends IntentService {
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);
@ -129,6 +145,10 @@ public class DataService extends IntentService {
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);
@ -250,6 +270,41 @@ public class DataService extends IntentService {
}
}
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, "utils", Constants.MGDL).equals(Constants.MMOL))
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;

View file

@ -49,4 +49,6 @@ public interface Intents {
String GLIMP_BG = "it.ct.glicemia.ACTION_GLUCOSE_MEASURED";
String DEXCOMG5_BG = "com.dexcom.cgm.DATA";
String POCTECH_BG = "com.china.poctech.data";
}

View file

@ -0,0 +1,39 @@
package info.nightscout.androidaps.plugins.Source;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
/**
* Created by mike on 05.08.2016.
*/
public class SourcePoctechPlugin extends PluginBase implements BgSourceInterface {
private static SourcePoctechPlugin plugin = null;
public static SourcePoctechPlugin getPlugin() {
if (plugin == null)
plugin = new SourcePoctechPlugin();
return plugin;
}
private SourcePoctechPlugin() {
super(new PluginDescription()
.mainType(PluginType.BGSOURCE)
.fragmentClass(BGSourceFragment.class.getName())
.pluginName(R.string.poctech)
.showInList(!Config.NSCLIENT)
.preferencesId(R.xml.pref_poctech)
.description(R.string.description_source_poctech)
);
}
@Override
public boolean advancedFilteringSupported() {
return false;
}
}

View file

@ -803,6 +803,7 @@
<string name="dexcomg5_nsupload_title">Upload BG data to NS</string>
<string name="key_dexcomg5_nsupload" translatable="false">dexcomg5_nsupload</string>
<string name="dexcomg5_upload">G5 upload settings</string>
<string name="poctech_upload">Poctech upload settings</string>
<string name="wear_detailed_delta_title">Show detailed delta</string>
<string name="wear_detailed_delta_summary">Show delta with one more decimal place</string>
<string name="smbmaxminutes" translatable="false">45 60 75 90 105 120</string>
@ -1139,4 +1140,6 @@
<string name="open_navigation">Open navigation</string>
<string name="close_navigation">Close navigation</string>
<string name="nav_plugin_preferences">Plugin preferences</string>
<string name="poctech">Poctech</string>
<string name="description_source_poctech">Receive BG values from Poctech app</string>
</resources>

View file

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:key="danar"
android:title="@string/dexcomg5_upload">
<SwitchPreference

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="@string/poctech_upload">
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_dexcomg5_nsupload"
android:title="@string/dexcomg5_nsupload_title" />
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_dexcomg5_xdripupload"
android:summary="@string/dexcomg5_xdripupload_summary"
android:title="@string/dexcomg5_xdripupload_title" />
</PreferenceCategory>
</PreferenceScreen>