G5 upload to xdrip
This commit is contained in:
parent
9602bde6a1
commit
5f60e7cf2b
7 changed files with 64 additions and 202 deletions
|
@ -1,7 +1,6 @@
|
|||
package info.nightscout.androidaps;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Resources;
|
||||
import android.os.SystemClock;
|
||||
|
@ -25,7 +24,6 @@ import info.nightscout.androidaps.Services.Intents;
|
|||
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.Actions.ActionsFragment;
|
||||
import info.nightscout.androidaps.plugins.Careportal.CareportalPlugin;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
|
||||
|
@ -51,13 +49,9 @@ import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfileFragment;
|
|||
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
||||
import info.nightscout.androidaps.plugins.ProfileSimple.SimpleProfilePlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRS.services.DanaRSService;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService;
|
||||
import info.nightscout.androidaps.plugins.PumpMDI.MDIPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
|
||||
import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin;
|
||||
|
@ -71,7 +65,6 @@ import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin;
|
|||
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin;
|
||||
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
||||
import info.nightscout.androidaps.plugins.Wear.WearPlugin;
|
||||
import info.nightscout.androidaps.plugins.XDripFakeEsel.XDripFakeEselPlugin;
|
||||
import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin;
|
||||
import info.nightscout.androidaps.receivers.DataReceiver;
|
||||
import info.nightscout.androidaps.receivers.KeepAliveReceiver;
|
||||
|
@ -161,7 +154,6 @@ public class MainApp extends Application {
|
|||
|
||||
pluginsList.add(WearPlugin.initPlugin(this));
|
||||
pluginsList.add(StatuslinePlugin.initPlugin(this));
|
||||
pluginsList.add(XDripFakeEselPlugin.initPlugin(this));
|
||||
pluginsList.add(new PersistentNotificationPlugin(this));
|
||||
pluginsList.add(NSClientInternalPlugin.getPlugin());
|
||||
|
||||
|
@ -175,7 +167,7 @@ public class MainApp extends Application {
|
|||
else
|
||||
Answers.getInstance().logCustom(new CustomEvent("AppStart"));
|
||||
|
||||
new Thread(new Runnable() {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SystemClock.sleep(5000);
|
||||
|
|
|
@ -228,6 +228,9 @@ public class DataService extends IntentService {
|
|||
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) {
|
||||
|
|
|
@ -159,12 +159,16 @@ public class Profile {
|
|||
LongSparseArray<Double> sparse = new LongSparseArray<>();
|
||||
for (Integer index = 0; index < array.length(); index++) {
|
||||
try {
|
||||
JSONObject o = array.getJSONObject(index);
|
||||
final JSONObject o = array.getJSONObject(index);
|
||||
long tas = getShitfTimeSecs((int) o.getLong("timeAsSeconds"));
|
||||
Double value = o.getDouble("value") * multiplier;
|
||||
sparse.put(tas, value);
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
try {
|
||||
log.error(array.getJSONObject(index).toString());
|
||||
} catch (JSONException e1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,190 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.XDripFakeEsel;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||
import info.nightscout.androidaps.events.EventNewBG;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
|
||||
/**
|
||||
* Created by adrian on 13/12/17.
|
||||
*/
|
||||
|
||||
public class XDripFakeEselPlugin implements PluginBase {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(XDripFakeEselPlugin.class);
|
||||
|
||||
public static final String XDRIP_PLUS_NS_EMULATOR = "com.eveningoutpost.dexdrip.NS_EMULATOR";
|
||||
private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US);
|
||||
|
||||
private boolean fragmentEnabled = false;
|
||||
|
||||
private final Context ctx;
|
||||
|
||||
private static XDripFakeEselPlugin thisPlugin;
|
||||
|
||||
public static XDripFakeEselPlugin getPlugin() {
|
||||
return thisPlugin;
|
||||
}
|
||||
|
||||
public static XDripFakeEselPlugin initPlugin(Context ctx) {
|
||||
|
||||
if (thisPlugin == null) {
|
||||
thisPlugin = new XDripFakeEselPlugin(ctx);
|
||||
}
|
||||
|
||||
return thisPlugin;
|
||||
}
|
||||
|
||||
private XDripFakeEselPlugin(Context ctx) {
|
||||
this.ctx = ctx;
|
||||
MainApp.bus().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return PluginBase.GENERAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFragmentClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Fake ESEL for xDrip";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameShort() {
|
||||
String name = "FakeESEL";
|
||||
if (!name.trim().isEmpty()) {
|
||||
//only if translation exists
|
||||
return name;
|
||||
}
|
||||
// use long name as fallback
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(int type) {
|
||||
return type == GENERAL && fragmentEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisibleInTabs(int type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeHidden(int type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFragment() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showInList(int type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
|
||||
if (type == GENERAL) {
|
||||
this.fragmentEnabled = fragmentEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFragmentVisible(int type, boolean fragmentVisible) {
|
||||
// do nothing, no gui
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPreferencesId() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
private void sendBG() {
|
||||
if (!fragmentEnabled) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
||||
final JSONArray entriesBody = new JSONArray();
|
||||
addLastSgvEntry(entriesBody);
|
||||
|
||||
sendBundle("add", "entries", entriesBody, XDRIP_PLUS_NS_EMULATOR);
|
||||
} catch (Exception e) {
|
||||
log.debug(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventNewBG ev) {
|
||||
sendBG();
|
||||
}
|
||||
|
||||
private static void sendBundle(String action, String collection, Object json, String intentIdAction) {
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putString("action", action);
|
||||
bundle.putString("collection", collection);
|
||||
bundle.putString("data", json.toString());
|
||||
final Intent intent = new Intent(intentIdAction);
|
||||
intent.putExtras(bundle).addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||
MainApp.instance().sendBroadcast(intent);
|
||||
List<ResolveInfo> receivers = MainApp.instance().getPackageManager().queryBroadcastReceivers(intent, 0);
|
||||
if (receivers.size() < 1) {
|
||||
log.debug("No xDrip receivers found. ");
|
||||
} else {
|
||||
log.debug(receivers.size() + " xDrip receivers");
|
||||
}
|
||||
}
|
||||
|
||||
private static void addLastSgvEntry(JSONArray entriesArray) throws Exception {
|
||||
JSONObject json = new JSONObject();
|
||||
BgReading bgReading = DatabaseHelper.lastBg();
|
||||
if(bgReading==null){
|
||||
log.debug("bgReading==null");
|
||||
}
|
||||
|
||||
json.put("sgv", bgReading.value);
|
||||
if (bgReading.direction == null){
|
||||
json.put("direction", "NONE");
|
||||
} else {
|
||||
json.put("direction", bgReading.direction);
|
||||
}
|
||||
json.put("device", "ESEL");
|
||||
json.put("type", "sgv");
|
||||
json.put("date", bgReading.date);
|
||||
json.put("dateString", format.format(bgReading.date));
|
||||
|
||||
entriesArray.put(json);
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return fragmentEnabled;
|
||||
}
|
||||
|
||||
}
|
|
@ -3,33 +3,37 @@ package info.nightscout.utils;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.Services.Intents;
|
||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.CareportalEvent;
|
||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||
import info.nightscout.androidaps.db.ProfileSwitch;
|
||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||
import info.nightscout.androidaps.plugins.Loop.DeviceStatus;
|
||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.DbLogger;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.plugins.OpenAPSAMA.DetermineBasalResultAMA;
|
||||
import info.nightscout.androidaps.plugins.OpenAPSMA.DetermineBasalResultMA;
|
||||
|
||||
|
@ -449,4 +453,44 @@ public class NSUpload {
|
|||
|
||||
}
|
||||
|
||||
public static void sendToXdrip(BgReading bgReading) {
|
||||
final String XDRIP_PLUS_NS_EMULATOR = "com.eveningoutpost.dexdrip.NS_EMULATOR";
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US);
|
||||
|
||||
try {
|
||||
final JSONArray entriesBody = new JSONArray();
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("sgv", bgReading.value);
|
||||
if (bgReading.direction == null) {
|
||||
json.put("direction", "NONE");
|
||||
} else {
|
||||
json.put("direction", bgReading.direction);
|
||||
}
|
||||
json.put("device", "G5");
|
||||
json.put("type", "sgv");
|
||||
json.put("date", bgReading.date);
|
||||
json.put("dateString", format.format(bgReading.date));
|
||||
entriesBody.put(json);
|
||||
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putString("action", "add");
|
||||
bundle.putString("collection", "entries");
|
||||
bundle.putString("data", entriesBody.toString());
|
||||
final Intent intent = new Intent(XDRIP_PLUS_NS_EMULATOR);
|
||||
intent.putExtras(bundle).addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||
MainApp.instance().sendBroadcast(intent);
|
||||
List<ResolveInfo> receivers = MainApp.instance().getPackageManager().queryBroadcastReceivers(intent, 0);
|
||||
if (receivers.size() < 1) {
|
||||
log.debug("No xDrip receivers found. ");
|
||||
} else {
|
||||
log.debug(receivers.size() + " xDrip receivers");
|
||||
}
|
||||
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -785,5 +785,8 @@
|
|||
<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="unsupportedfirmware">Unsupported pump firmware</string>
|
||||
<string name="dexcomg5_xdripupload_title">Send BG data to xDrip+</string>
|
||||
<string name="key_dexcomg5_xdripupload" translatable="false">dexcomg5_xdripupload</string>
|
||||
<string name="dexcomg5_xdripupload_summary">In xDrip+ select 640g/Eversense data source</string>
|
||||
</resources>
|
||||
|
||||
|
|
|
@ -9,6 +9,12 @@
|
|||
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>
|
Loading…
Reference in a new issue