internal nsclient

This commit is contained in:
Milos Kozak 2017-02-17 13:18:36 +01:00
parent 1a3d3eb97c
commit 71112a90e2
89 changed files with 2404 additions and 114 deletions

View file

@ -157,5 +157,11 @@ dependencies {
androidTestCompile "com.google.dexmaker:dexmaker:1.2"
androidTestCompile "com.google.dexmaker:dexmaker-mockito:1.2"
compile(name:'android-edittext-validator-v1.3.4-mod', ext:'aar')
compile ('io.socket:socket.io-client:0.8.3') {
// excluding org.json which is provided by Android
exclude group: 'org.json', module: 'json'
}
compile 'com.google.code.gson:gson:2.4'
compile 'com.google.guava:guava:18.0'
}

View file

@ -29,11 +29,14 @@
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".PreferencesActivity" />
<activity android:name=".plugins.Overview.Dialogs.BolusProgressHelperActivity" android:theme="@style/Theme.AppCompat.Translucent" />
<activity
android:name=".plugins.Overview.Dialogs.BolusProgressHelperActivity"
android:theme="@style/Theme.AppCompat.Translucent" />
<activity android:name=".AgreementActivity" />
<activity android:name=".plugins.DanaR.History.DanaRHistoryActivity" />
<activity android:name=".plugins.DanaRKorean.History.DanaRHistoryActivity" />
@ -42,6 +45,7 @@
<activity android:name=".plugins.Overview.activities.QuickWizardListActivity">
<intent-filter>
<action android:name="info.nightscout.androidaps.plugins.Overview.activities.QuickWizardListActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
@ -68,20 +72,44 @@
<action android:name="com.eveningoutpost.dexdrip.BgEstimate" />
<!-- Receiver from 640g uploader -->
<action android:name="com.eveningoutpost.dexdrip.NS_EMULATOR" />
<!-- Auto start -->
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<!-- Receiver keepalive, scheduled every 30 min -->
<receiver android:name=".receivers.KeepAliveReceiver" />
<!-- Auto start -->
<receiver
android:name=".plugins.NSClientInternal.receivers.AutoStartReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<!-- NSClient -->
<receiver
android:name=".plugins.NSClientInternal.receivers.RestartReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="info.nightscout.client.RESTART" />
</intent-filter>
</receiver>
<receiver
android:name=".plugins.NSClientInternal.receivers.DBAccessReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="info.nightscout.client.DBACCESS" />
</intent-filter>
</receiver>
<!-- Service processing incomming data -->
<service
android:name=".Services.DataService"
android:exported="false" />
<!-- Service showing alert on screen -->
<service
android:name=".plugins.DanaR.Services.ExecutionService"
android:enabled="true"
@ -90,15 +118,23 @@
android:name=".plugins.DanaRKorean.Services.ExecutionService"
android:enabled="true"
android:exported="false" />
<service android:name=".plugins.Wear.wearintegration.WatchUpdaterService" android:exported="true" >
<intent-filter> <action android:name="com.google.android.gms.wearable.BIND_LISTENER" /> </intent-filter>
<service
android:name=".plugins.Wear.wearintegration.WatchUpdaterService"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
</intent-filter>
</service>
<meta-data
android:name="io.fabric.ApiKey"
android:value="59d462666c664c57b29e1d79ea123e01f8057cfa" />
<service
android:name=".plugins.NSClientInternal.services.NSClientService"
android:enabled="true"
android:exported="true" />
</application>
</manifest>
</manifest>

View file

@ -52,4 +52,7 @@ public class Constants {
//DanaR
public static final double dailyLimitWarning = 0.95d;
//NSClientInternal
public static final int MAX_LOG_LINES = 100;
}

View file

@ -27,6 +27,7 @@ import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanFragment;
import info.nightscout.androidaps.plugins.LocalProfile.LocalProfileFragment;
import info.nightscout.androidaps.plugins.Loop.LoopFragment;
import info.nightscout.androidaps.plugins.MDI.MDIFragment;
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalFragment;
import info.nightscout.androidaps.plugins.NSProfile.NSProfileFragment;
import info.nightscout.androidaps.plugins.Objectives.ObjectivesFragment;
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAFragment;
@ -103,6 +104,7 @@ public class MainApp extends Application {
if (Config.WEAR) pluginsList.add(WearFragment.getPlugin(this));
pluginsList.add(new PersistentNotificationPlugin(this));
pluginsList.add(NSClientInternalFragment.getPlugin());
pluginsList.add(sConfigBuilder = ConfigBuilderFragment.getPlugin());

View file

@ -18,6 +18,7 @@ import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.DanaR.BluetoothDevicePreference;
import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin;
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
import info.nightscout.androidaps.plugins.VirtualPump.VirtualPumpPlugin;
import info.nightscout.utils.LocaleHelper;
@ -110,6 +111,10 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
if (virtualPumpPlugin != null && virtualPumpPlugin.isEnabled(PluginBase.PUMP)) {
addPreferencesFromResource(R.xml.pref_virtualpump);
}
NSClientInternalPlugin nsClientInternalPlugin = (NSClientInternalPlugin) MainApp.getSpecificPlugin(NSClientInternalPlugin.class);
if (nsClientInternalPlugin != null && nsClientInternalPlugin.isEnabled(PluginBase.GENERAL)) {
addPreferencesFromResource(R.xml.pref_nsclientinternal);
}
if (Config.SMSCOMMUNICATORENABLED)
addPreferencesFromResource(R.xml.pref_smscommunicator);
addPreferencesFromResource(R.xml.pref_others);

View file

@ -49,8 +49,8 @@ import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin;
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin;
import info.nightscout.androidaps.plugins.TempTargetRange.events.EventTempTargetRangeChange;
import info.nightscout.androidaps.receivers.DataReceiver;
import info.nightscout.client.data.NSProfile;
import info.nightscout.client.data.NSSgv;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
public class DataService extends IntentService {

View file

@ -11,11 +11,13 @@ public interface Intents {
String ACTION_NEW_MBG = "info.nightscout.client.NEW_MBG";
String ACTION_NEW_CAL = "info.nightscout.client.NEW_CAL";
String ACTION_NEW_STATUS = "info.nightscout.client.NEW_STATUS";
String ACTION_QUEUE_STATUS = "info.nightscout.client.QUEUE_STATUS";
// App -> NSClient
String ACTION_DATABASE = "info.nightscout.client.DBACCESS";
String ACTION_RESTART = "info.nightscout.client.RESTART";
String ACTION_RESEND = "info.nightscout.client.RESEND";
// xDrip -> App
String RECEIVER_PERMISSION = "com.eveningoutpost.dexdrip.permissions.RECEIVE_BG_ESTIMATE";

View file

@ -6,9 +6,8 @@ import org.json.JSONObject;
import java.util.Date;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.Round;

View file

@ -10,7 +10,7 @@ import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.OpenAPSAMA.Autosens;
import info.nightscout.androidaps.plugins.OpenAPSAMA.AutosensResult;
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
/**
* Created by mike on 04.01.2017.

View file

@ -1,7 +1,5 @@
package info.nightscout.androidaps.data;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.Html;
import android.text.Spanned;
@ -10,7 +8,7 @@ import org.json.JSONObject;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.Round;

View file

@ -10,7 +10,7 @@ import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.Constants;
import info.nightscout.client.data.NSSgv;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
import info.nightscout.utils.DecimalFormatter;
@DatabaseTable(tableName = DatabaseHelper.DATABASE_BGREADINGS)

View file

@ -11,7 +11,7 @@ import java.util.Date;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;

View file

@ -15,7 +15,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;

View file

@ -1,6 +1,6 @@
package info.nightscout.androidaps.events;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
/**
* Created by mike on 04.06.2016.

View file

@ -2,7 +2,7 @@ package info.nightscout.androidaps.interfaces;
import android.support.annotation.Nullable;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
/**
* Created by mike on 14.06.2016.

View file

@ -8,8 +8,7 @@ import java.util.Date;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.plugins.Loop.APSResult;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
/**
* Created by mike on 04.06.2016.

View file

@ -23,7 +23,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.PlusMinusEditText;
import info.nightscout.utils.SafeParse;

View file

@ -54,7 +54,7 @@ import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
import info.nightscout.androidaps.plugins.CircadianPercentageProfile.CircadianPercentageProfilePlugin;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.TempTargetRange.events.EventTempTargetRangeChange;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.PlusMinusEditText;
import info.nightscout.utils.SafeParse;

View file

@ -15,7 +15,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.SafeParse;
import info.nightscout.utils.ToastUtils;

View file

@ -54,8 +54,8 @@ import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressHelperAc
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.client.data.DbLogger;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.DbLogger;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
/**

View file

@ -40,7 +40,7 @@ import info.nightscout.androidaps.plugins.NSProfile.NSProfilePlugin;
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.Round;

View file

@ -12,7 +12,7 @@ import java.util.Date;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.SafeParse;
/**

View file

@ -15,12 +15,10 @@ import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.DanaR.DanaRFragment;
import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DecimalFormatter;
/**

View file

@ -32,7 +32,6 @@ import org.slf4j.LoggerFactory;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import info.nightscout.androidaps.Constants;
@ -44,7 +43,7 @@ import info.nightscout.androidaps.plugins.DanaR.Services.ExecutionService;
import info.nightscout.androidaps.plugins.DanaR.comm.RecordTypes;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRSyncStatus;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.ToastUtils;

View file

@ -14,7 +14,7 @@ import info.nightscout.androidaps.db.DanaRHistoryRecord;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.DanaR.comm.RecordTypes;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRSyncStatus;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.ToastUtils;

View file

@ -34,7 +34,6 @@ import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.DanaR.DanaRPump;
import info.nightscout.androidaps.plugins.DanaR.SerialIOThread;
@ -82,7 +81,7 @@ import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatu
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRNewStatus;
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.SafeParse;
import info.nightscout.utils.ToastUtils;

View file

@ -40,7 +40,7 @@ import info.nightscout.androidaps.plugins.NSProfile.NSProfilePlugin;
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.Round;

View file

@ -12,7 +12,7 @@ import java.util.Date;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.SafeParse;
/**

View file

@ -32,7 +32,6 @@ import org.slf4j.LoggerFactory;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import info.nightscout.androidaps.Constants;
@ -45,7 +44,7 @@ import info.nightscout.androidaps.plugins.DanaR.comm.RecordTypes;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRSyncStatus;
import info.nightscout.androidaps.plugins.DanaRKorean.Services.ExecutionService;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.ToastUtils;

View file

@ -77,7 +77,7 @@ import info.nightscout.androidaps.plugins.DanaRKorean.comm.MsgStatusBolusExtende
import info.nightscout.androidaps.plugins.DanaRKorean.comm.MsgStatusTempBasal;
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.SafeParse;
import info.nightscout.utils.ToastUtils;

View file

@ -15,8 +15,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.plugins.SimpleProfile.SimpleProfileFragment;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.SafeParse;
/**

View file

@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.Loop;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import org.json.JSONException;
@ -10,12 +9,9 @@ import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.client.data.DbLogger;
import info.nightscout.androidaps.plugins.NSClientInternal.data.DbLogger;
/*
{

View file

@ -7,7 +7,6 @@ import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.SQLException;
import java.util.Date;
import info.nightscout.androidaps.BuildConfig;
@ -19,10 +18,7 @@ import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.VirtualPump.VirtualPumpFragment;
import info.nightscout.androidaps.plugins.VirtualPump.events.EventVirtualPumpUpdateGui;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
/**

View file

@ -0,0 +1,163 @@
package info.nightscout.androidaps.plugins.NSClientInternal;
import android.app.Activity;
import android.content.SharedPreferences;
import android.graphics.Paint;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ScrollView;
import android.widget.TextView;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.FragmentBase;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientUpdateGUI;
public class NSClientInternalFragment extends Fragment implements FragmentBase, View.OnClickListener, CompoundButton.OnCheckedChangeListener {
private static Logger log = LoggerFactory.getLogger(NSClientInternalFragment.class);
static NSClientInternalPlugin nsClientInternalPlugin;
static public NSClientInternalPlugin getPlugin() {
if (nsClientInternalPlugin == null) {
nsClientInternalPlugin = new NSClientInternalPlugin();
}
return nsClientInternalPlugin;
}
private TextView logTextView;
private TextView queueTextView;
private TextView urlTextView;
private TextView statusTextView;
private TextView restart;
private TextView delivernow;
private TextView clearqueue;
private TextView showqueue;
private ScrollView logScrollview;
private CheckBox autoscrollCheckbox;
private CheckBox pausedCheckbox;
String status = "";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.nsclientinternal_fragment, container, false);
logScrollview = (ScrollView) view.findViewById(R.id.nsclientinternal_logscrollview);
autoscrollCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_autoscroll);
autoscrollCheckbox.setOnCheckedChangeListener(this);
pausedCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_paused);
pausedCheckbox.setOnCheckedChangeListener(this);
logTextView = (TextView) view.findViewById(R.id.nsclientinternal_log);
queueTextView = (TextView) view.findViewById(R.id.nsclientinternal_queue);
urlTextView = (TextView) view.findViewById(R.id.nsclientinternal_url);
statusTextView = (TextView) view.findViewById(R.id.nsclientinternal_status);
restart = (TextView) view.findViewById(R.id.nsclientinternal_restart);
restart.setOnClickListener(this);
restart.setPaintFlags(restart.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
delivernow = (TextView) view.findViewById(R.id.nsclientinternal_delivernow);
delivernow.setOnClickListener(this);
delivernow.setPaintFlags(delivernow.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
clearqueue = (TextView) view.findViewById(R.id.nsclientinternal_clearqueue);
clearqueue.setOnClickListener(this);
clearqueue.setPaintFlags(clearqueue.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
showqueue = (TextView) view.findViewById(R.id.nsclientinternal_showqueue);
showqueue.setOnClickListener(this);
showqueue.setPaintFlags(showqueue.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
updateGUI();
return view;
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.nsclientinternal_restart:
MainApp.bus().post(new EventNSClientRestart());
break;
case R.id.nsclientinternal_delivernow:
getPlugin().resend("GUI");
break;
case R.id.nsclientinternal_clearqueue:
getPlugin().clearLog();
break;
case R.id.nsclientinternal_showqueue:
MainApp.bus().post(new EventNSClientNewLog("QUEUE", getPlugin().queue().textList()));
break;
}
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
SharedPreferences.Editor editor = SP.edit();
switch (buttonView.getId()) {
case R.id.nsclientinternal_paused:
editor.putBoolean("nsclientinternal_paused", isChecked);
editor.apply();
getPlugin().paused = isChecked;
// TODO
updateGUI();
break;
case R.id.nsclientinternal_autoscroll:
editor.putBoolean("nsclientinternal_autoscroll", isChecked);
editor.apply();
updateGUI();
break;
}
}
@Override
public void onPause() {
super.onPause();
MainApp.bus().unregister(this);
}
@Override
public void onResume() {
super.onResume();
MainApp.bus().register(this);
updateGUI();
}
@Subscribe
public void onStatusEvent(final EventNSClientUpdateGUI ev) {
updateGUI();
}
private void updateGUI() {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
logTextView.setText(getPlugin().textLog);
if (getPlugin().autoscroll) {
logScrollview.fullScroll(ScrollView.FOCUS_DOWN);
}
urlTextView.setText(getPlugin().url);
queueTextView.setText(((Integer)getPlugin().queue().size()).toString());
statusTextView.setText(getPlugin().status);
}
});
}
}

View file

@ -0,0 +1,215 @@
package info.nightscout.androidaps.plugins.NSClientInternal;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.plugins.DanaR.Services.ExecutionService;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientUpdateGUI;
import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
public class NSClientInternalPlugin implements PluginBase {
private static Logger log = LoggerFactory.getLogger(NSClientInternalPlugin.class);
boolean fragmentEnabled = true;
boolean fragmentVisible = true;
static public Handler handler;
static private HandlerThread handlerThread;
public List<EventNSClientNewLog> listLog = new ArrayList<EventNSClientNewLog>();
public Spanned textLog = Html.fromHtml("");
public boolean paused = false;
public boolean autoscroll = true;
public String url = "";
public String status = "";
public NSClientService nsClientService = null;
public NSClientInternalPlugin() {
MainApp.bus().register(this);
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
paused = SP.getBoolean("nsclientinternal_paused", false);
autoscroll = SP.getBoolean("nsclientinternal_autoscroll", true);
url = SP.getString("nsclientinternal_url", "");
if (handler == null) {
handlerThread = new HandlerThread(NSClientInternalPlugin.class.getSimpleName() + "Handler");
handlerThread.start();
handler = new Handler(handlerThread.getLooper());
}
Context context = MainApp.instance().getApplicationContext();
Intent intent = new Intent(context, NSClientService.class);
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}
@Override
public int getType() {
return PluginBase.GENERAL;
}
@Override
public String getFragmentClass() {
return NSClientInternalFragment.class.getName();
}
@Override
public String getName() {
return MainApp.sResources.getString(R.string.nsclientinternal);
}
@Override
public String getNameShort() {
String name = MainApp.sResources.getString(R.string.nsclientinternal_shortname);
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 type == GENERAL && fragmentVisible;
}
@Override
public boolean canBeHidden(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) {
if (type == GENERAL) this.fragmentVisible = fragmentVisible;
}
ServiceConnection mConnection = new ServiceConnection() {
public void onServiceDisconnected(ComponentName name) {
log.debug("Service is disconnected");
nsClientService = null;
}
public void onServiceConnected(ComponentName name, IBinder service) {
log.debug("Service is connected");
NSClientService.LocalBinder mLocalBinder = (NSClientService.LocalBinder) service;
nsClientService = mLocalBinder.getServiceInstance();
}
};
@SuppressWarnings("UnusedParameters")
@Subscribe
public void onStatusEvent(final EventAppExit e) {
if (nsClientService != null)
MainApp.instance().getApplicationContext().unbindService(mConnection);
}
@Subscribe
public void onStatusEvent(final EventPreferenceChange s) {
//TODO
}
@Subscribe
public void onStatusEvent(final EventNSClientNewLog ev) {
addToLog(ev);
log.debug(ev.action + " " + ev.logText);
}
@Subscribe
public void onStatusEvent(final EventNSClientRestart ev) {
if (nsClientService != null)
nsClientService.restart();
}
@Subscribe
public void onStatusEvent(final EventNSClientStatus ev) {
status = ev.status;
MainApp.bus().post(new EventNSClientUpdateGUI());
}
public void clearLog() {
handler.post(new Runnable() {
@Override
public void run() {
listLog = new ArrayList<EventNSClientNewLog>();
updateLog();
}
});
}
private void addToLog(final EventNSClientNewLog ev) {
handler.post(new Runnable() {
@Override
public void run() {
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
listLog.add(ev);
// remove the first line if log is too large
if (listLog.size() >= Constants.MAX_LOG_LINES) {
listLog.remove(0);
}
updateLog();
}
});
}
private void updateLog() {
Spanned newTextLog = Html.fromHtml("");
for (EventNSClientNewLog log : listLog) {
newTextLog = (Spanned) TextUtils.concat(newTextLog, log.toHtml());
}
textLog = newTextLog;
MainApp.bus().post(new EventNSClientUpdateGUI());
}
public void resend(String reason) {
if (nsClientService != null)
nsClientService.resend(reason);
}
public UploadQueue queue() {
return NSClientService.uploadQueue;
}
}

View file

@ -0,0 +1,151 @@
package info.nightscout.androidaps.plugins.NSClientInternal;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.plugins.NSClientInternal.acks.NSAddAck;
import info.nightscout.androidaps.plugins.NSClientInternal.acks.NSUpdateAck;
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastQueueStatus;
import info.nightscout.androidaps.plugins.NSClientInternal.data.DbRequest;
import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
/**
* Created by mike on 21.02.2016.
*/
public class UploadQueue {
private static Logger log = LoggerFactory.getLogger(UploadQueue.class);
public static HashMap<String, DbRequest> queue = null;
public UploadQueue() {
loadMap();
}
public static String status() {
return "QUEUE: " + queue.size();
}
public static int size() {
return queue.size();
}
public static void add(final DbRequest dbr) {
NSClientService.handler.post(new Runnable() {
@Override
public void run() {
log.debug("QUEUE adding: " + dbr.data.toString());
queue.put(dbr.hash(), dbr);
}
});
}
public static void put(final String hash, final DbRequest dbr) {
NSClientService.handler.post(new Runnable() {
@Override
public void run() {
queue.put(hash, dbr);
BroadcastQueueStatus bs = new BroadcastQueueStatus();
bs.handleNewStatus(queue.size(), MainApp.instance().getApplicationContext());
}
});
}
public static void reset() {
NSClientService.handler.post(new Runnable() {
@Override
public void run() {
log.debug("QUEUE Reset");
queue.clear();
log.debug(status());
}
});
}
public static void removeID(final JSONObject record) {
NSClientService.handler.post(new Runnable() {
@Override
public void run() {
try {
long id = -1L;
if (record.has("NSCLIENT_ID")) {
id = record.getLong("NSCLIENT_ID");
} else {
return;
}
Iterator<Map.Entry<String, DbRequest>> iter = queue.entrySet().iterator();
while (iter.hasNext()) {
DbRequest dbr = iter.next().getValue();
JSONObject data = dbr.data;
long nsclientId = -1;
if (data.has("NSCLIENT_ID")) {
nsclientId = data.getLong("NSCLIENT_ID");
if (nsclientId == id) {
log.debug("Removing item from UploadQueue");
iter.remove();
log.debug(UploadQueue.status());
return;
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
final String KEY = "UploadQueue";
private void saveMap() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
JSONObject jsonObject = new JSONObject(queue);
String jsonString = jsonObject.toString();
SharedPreferences.Editor editor = sp.edit();
editor.remove(KEY).commit();
editor.putString(KEY, jsonString);
editor.commit();
}
private void loadMap() {
queue = new HashMap<String, DbRequest>();
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
try {
String jsonString = sp.getString(KEY, (new JSONObject()).toString());
JSONObject jsonObject = new JSONObject(jsonString);
Iterator<String> keysItr = jsonObject.keys();
while (keysItr.hasNext()) {
String key = keysItr.next();
DbRequest value = (DbRequest) jsonObject.get(key);
queue.put(key, value);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public String textList() {
Iterator<Map.Entry<String, DbRequest>> iter = queue.entrySet().iterator();
String result = "";
while (iter.hasNext()) {
DbRequest dbr = iter.next().getValue();
result += dbr.action.toUpperCase() + " ";
result += dbr.collection + ": ";
result += dbr.data.toString();
}
return result;
}
}

View file

@ -0,0 +1,54 @@
package info.nightscout.androidaps.plugins.NSClientInternal.acks;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
import io.socket.client.Ack;
/**
* Created by mike on 29.12.2015.
*/
public class NSAddAck implements Ack {
private static Logger log = LoggerFactory.getLogger(NSAddAck.class);
public String _id = null;
public void call(Object...args) {
// Regular response
try {
JSONArray responsearray = (JSONArray) (args[0]);
JSONObject response = null;
if (responsearray.length()>0) {
response = responsearray.getJSONObject(0);
_id = response.getString("_id");
}
synchronized(this) {
this.notify();
}
return;
} catch (Exception e) {
}
// Check for not authorized
try {
JSONObject response = (JSONObject) (args[0]);
if (response.has("result")) {
_id = null;
if (response.getString("result").equals("Not authorized")) {
synchronized(this) {
this.notify();
}
NSClientService.forcerestart = true;
return;
}
log.debug("DBACCESS " + response.getString("result"));
}
synchronized(this) {
this.notify();
}
return;
} catch (Exception e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,24 @@
package info.nightscout.androidaps.plugins.NSClientInternal.acks;
import org.json.JSONObject;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog;
import io.socket.client.Ack;
/**
* Created by mike on 02.01.2016.
*/
public class NSAuthAck implements Ack{
public boolean read = false;
public boolean write = false;
public boolean write_treatment = false;
public void call(Object...args) {
JSONObject response = (JSONObject)args[0];
read = response.optBoolean("read");
write = response.optBoolean("write");
write_treatment = response.optBoolean("write_treatment");
MainApp.bus().post(this);
}
}

View file

@ -0,0 +1,38 @@
package info.nightscout.androidaps.plugins.NSClientInternal.acks;
import org.json.JSONException;
import org.json.JSONObject;
import io.socket.client.Ack;
/**
* Created by mike on 29.12.2015.
*/
public class NSPingAck implements Ack {
public long mills = 0;
public boolean received = false;
public boolean auth_received = false;
public boolean read = false;
public boolean write = false;
public boolean write_treatment = false;
public void call(Object...args) {
JSONObject response = (JSONObject)args[0];
mills = response.optLong("mills");
if (response.has("authorization")) {
auth_received = true;
try {
JSONObject authorization = response.getJSONObject("authorization");
read = authorization.optBoolean("read");
write = authorization.optBoolean("write");
write_treatment = authorization.optBoolean("write_treatment");
} catch (JSONException e) {
e.printStackTrace();
}
}
received = true;
synchronized(this) {
this.notify();
}
}
}

View file

@ -0,0 +1,32 @@
package info.nightscout.androidaps.plugins.NSClientInternal.acks;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.socket.client.Ack;
/**
* Created by mike on 21.02.2016.
*/
public class NSUpdateAck implements Ack {
private static Logger log = LoggerFactory.getLogger(NSUpdateAck.class);
public boolean result = false;
public void call(Object...args) {
JSONObject response = (JSONObject)args[0];
if (response.has("result"))
try {
if (response.getString("result").equals("success"))
result = true;
else if (response.getString("result").equals("Missing _id")) {
result = true;
log.debug("Internal error: Missing _id returned on dbUpdate ack");
}
} catch (JSONException e) {
}
synchronized(this) {
this.notify();
}
}
}

View file

@ -0,0 +1,34 @@
package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import org.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import info.nightscout.androidaps.Services.Intents;
/**
* Created by mike on 26.06.2016.
*/
public class BroadcastCals {
private static Logger log = LoggerFactory.getLogger(BroadcastCals.class);
public void handleNewCal(JSONArray cals, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("cals", cals.toString());
bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_NEW_CAL);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("CAL " + x.size() + " receivers");
}
}

View file

@ -0,0 +1,45 @@
package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import info.nightscout.androidaps.Services.Intents;
public class BroadcastDeviceStatus {
private static Logger log = LoggerFactory.getLogger(BroadcastDeviceStatus.class);
public void handleNewDeviceStatus(JSONObject status, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("devicestatus", status.toString());
bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_NEW_DEVICESTATUS);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("DEVICESTATUS " + x.size() + " receivers");
}
public void handleNewDeviceStatus(JSONArray statuses, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("devicestatuses", statuses.toString());
bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_NEW_DEVICESTATUS);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("DEVICESTATUS " + x.size() + " receivers");
}
}

View file

@ -0,0 +1,34 @@
package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import org.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import info.nightscout.androidaps.Services.Intents;
/**
* Created by mike on 26.06.2016.
*/
public class BroadcastMbgs {
private static Logger log = LoggerFactory.getLogger(BroadcastMbgs.class);
public void handleNewMbg(JSONArray mbgs, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("mbgs", mbgs.toString());
bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_NEW_MBG);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("MBG " + x.size() + " receivers");
}
}

View file

@ -0,0 +1,37 @@
package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
/**
* Created by mike on 20.02.2016.
*/
public class BroadcastProfile {
private static Logger log = LoggerFactory.getLogger(BroadcastProfile.class);
public void handleNewTreatment(NSProfile profile, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("profile", profile.getData().toString());
bundle.putString("activeprofile", profile.getActiveProfile());
bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_NEW_PROFILE);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("PROFILE " + x.size() + " receivers");
}
}

View file

@ -0,0 +1,30 @@
package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.PowerManager;
import info.nightscout.androidaps.Services.Intents;
/**
* Created by mike on 28.02.2016.
*/
public class BroadcastQueueStatus {
public void handleNewStatus(int size, Context context) {
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"sendQueue");
wakeLock.acquire();
try {
Bundle bundle = new Bundle();
bundle.putInt("size", size);
Intent intent = new Intent(Intents.ACTION_QUEUE_STATUS);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
} finally {
wakeLock.release();
}
}
}

View file

@ -0,0 +1,49 @@
package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import info.nightscout.androidaps.Services.Intents;
/**
* Created by mike on 22.02.2016.
*/
public class BroadcastSgvs {
private static Logger log = LoggerFactory.getLogger(BroadcastSgvs.class);
public void handleNewSgv(JSONObject sgv, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("sgv", sgv.toString());
bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_NEW_SGV);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("SGV " + x.size() + " receivers");
}
public void handleNewSgv(JSONArray sgvs, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("sgvs", sgvs.toString());
bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_NEW_SGV);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("SGV " + x.size() + " receivers");
}
}

View file

@ -0,0 +1,45 @@
package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSStatus;
import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
/**
* Created by mike on 24.02.2016.
*/
public class BroadcastStatus {
private static Logger log = LoggerFactory.getLogger(BroadcastStatus.class);
public void handleNewStatus(NSStatus status, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
try {
bundle.putString("nsclientversionname", MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionName);
bundle.putInt("nsclientversioncode", MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionCode);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
};
bundle.putString("nightscoutversionname", NSClientService.nightscoutVersionName);
bundle.putInt("nightscoutversioncode", NSClientService.nightscoutVersionCode);
bundle.putString("status", status.getData().toString());
bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_NEW_STATUS);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("STATUS: " + x.size() + " receivers");
}
}

View file

@ -0,0 +1,107 @@
package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
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 java.util.List;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSTreatment;
/**
* Created by mike on 20.02.2016.
*/
public class BroadcastTreatment {
private static Logger log = LoggerFactory.getLogger(BroadcastTreatment.class);
public void handleNewTreatment(NSTreatment treatment, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("treatment", treatment.getData().toString());
bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("TREAT_ADD " + treatment.getEventType() + " " + x.size() + " receivers");
}
public void handleNewTreatment(JSONArray treatments, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("treatments", treatments.toString());
bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("TREAT_ADD " + treatments.length() + " " + x.size() + " receivers");
}
public void handleChangedTreatment(JSONObject treatment, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("treatment", treatment.toString());
bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_CHANGED_TREATMENT);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
try {
log.debug("TREAT_CHANGE " + treatment.getString("_id") + " " + x.size() + " receivers");
} catch (JSONException e) {}
}
public void handleChangedTreatment(JSONArray treatments, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("treatments", treatments.toString());
bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_CHANGED_TREATMENT);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("TREAT_CHANGE " + treatments.length() + " " + x.size() + " receivers");
}
public void handleRemovedTreatment(JSONObject treatment, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("treatment", treatment.toString());
bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_REMOVED_TREATMENT);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
try {
log.debug("TREAT_REMOVE " + treatment.getString("_id") + " " + x.size() + " receivers");
} catch (JSONException e) {}
}
public void handleRemovedTreatment(JSONArray treatments, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("treatments", treatments.toString());
bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_REMOVED_TREATMENT);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("TREAT_REMOVE " + treatments.length() + " treatments " + x.size() + " receivers");
}
}

View file

@ -1,4 +1,4 @@
package info.nightscout.client.data;
package info.nightscout.androidaps.plugins.NSClientInternal.data;
import android.content.Intent;
import android.content.pm.ResolveInfo;

View file

@ -0,0 +1,46 @@
package info.nightscout.androidaps.plugins.NSClientInternal.data;
import com.google.common.base.Charsets;
import com.google.common.hash.Hashing;
import org.json.JSONObject;
/**
* Created by mike on 27.02.2016.
*
* Allowed actions "dbAdd" || "dbUpdate" || "dbUpdateUnset" || "dbRemove"
*/
public class DbRequest {
public String action = null;
public String collection = null;
public JSONObject data = null;
public String _id = null;
// dbAdd
public DbRequest(String action, String collection, JSONObject data) {
this.action = action;
this.collection = collection;
this.data = data;
this._id = "";
}
// dbUpdate, dbUpdateUnset
public DbRequest(String action, String collection, String _id, JSONObject data) {
this.action = action;
this.collection = collection;
this.data = data;
this._id = _id;
}
// dbRemove
public DbRequest(String action, String collection, String _id) {
this.action = action;
this.collection = collection;
this.data = new JSONObject();
this._id = _id;
}
public String hash() {
return Hashing.sha1().hashString(action + collection + _id + data.toString(), Charsets.UTF_8).toString();
}
}

View file

@ -1,9 +1,12 @@
package info.nightscout.client.data;
package info.nightscout.androidaps.plugins.NSClientInternal.data;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class NSCal {
private static Logger log = LoggerFactory.getLogger(NSCal.class);
public long date;
public double slope;
public double intercept;
@ -17,6 +20,7 @@ public class NSCal {
scale = json.getDouble("scale");
} catch (JSONException e) {
e.printStackTrace();
log.debug("Data: " + json.toString());
}
}
}

View file

@ -1,4 +1,4 @@
package info.nightscout.client.data;
package info.nightscout.androidaps.plugins.NSClientInternal.data;
import com.crashlytics.android.Crashlytics;

View file

@ -1,4 +1,4 @@
package info.nightscout.client.data;
package info.nightscout.androidaps.plugins.NSClientInternal.data;
import org.json.JSONException;
import org.json.JSONObject;

View file

@ -1,4 +1,4 @@
package info.nightscout.client.data;
package info.nightscout.androidaps.plugins.NSClientInternal.data;
import org.json.JSONException;
import org.json.JSONObject;

View file

@ -1,4 +1,4 @@
package info.nightscout.client.data;
package info.nightscout.androidaps.plugins.NSClientInternal.data;
import org.json.JSONException;
import org.json.JSONObject;

View file

@ -0,0 +1,30 @@
package info.nightscout.androidaps.plugins.NSClientInternal.events;
import android.text.Html;
import android.text.Spanned;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Created by mike on 15.02.2017.
*/
public class EventNSClientNewLog {
public Date date = new Date();
public String action;
public String logText;
public EventNSClientNewLog(String action, String logText) {
this.action = action;
this.logText = logText;
}
public Spanned toHtml() {
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
Spanned line = Html.fromHtml(timeFormat.format(date) + " <b>" + action + "</b> " + logText + "<br>");
return line;
}
}

View file

@ -0,0 +1,8 @@
package info.nightscout.androidaps.plugins.NSClientInternal.events;
/**
* Created by mike on 15.02.2017.
*/
public class EventNSClientRestart {
}

View file

@ -0,0 +1,16 @@
package info.nightscout.androidaps.plugins.NSClientInternal.events;
/**
* Created by mike on 02.01.2016.
*/
public class EventNSClientStatus {
public String status = "";
public EventNSClientStatus(String status) {
this.status = status;
}
public EventNSClientStatus() {
}
}

View file

@ -0,0 +1,8 @@
package info.nightscout.androidaps.plugins.NSClientInternal.events;
/**
* Created by mike on 17.02.2017.
*/
public class EventNSClientUpdateGUI {
}

View file

@ -0,0 +1,17 @@
package info.nightscout.androidaps.plugins.NSClientInternal.receivers;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
public class AutoStartReceiver extends BroadcastReceiver {
public AutoStartReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
context.startService(new Intent(context, NSClientService.class));
}
}

View file

@ -0,0 +1,87 @@
package info.nightscout.androidaps.plugins.NSClientInternal.receivers;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.PowerManager;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
import info.nightscout.androidaps.plugins.NSClientInternal.data.DbRequest;
public class DBAccessReceiver extends BroadcastReceiver {
private static Logger log = LoggerFactory.getLogger(DBAccessReceiver.class);
@Override
public void onReceive(Context context, Intent intent) {
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"sendQueue");
wakeLock.acquire();
try {
Bundle bundles = intent.getExtras();
if (bundles == null) return;
if (!bundles.containsKey("action")) return;
String collection = null;
String _id = null;
JSONObject data = null;
String action = bundles.getString("action");
try { collection = bundles.getString("collection"); } catch (Exception e) {}
try { _id = bundles.getString("_id"); } catch (Exception e) {}
try { data = new JSONObject(bundles.getString("data")); } catch (Exception e) {}
if (data == null && !action.equals("dbRemove") || _id == null && action.equals("dbRemove")) {
log.debug("DBACCESS no data inside record");
return;
}
// mark by id
if (action.equals("dbRemove")) {
data = new JSONObject();
}
try {
data.put("NSCLIENT_ID", (new Date()).getTime());
} catch (JSONException e) {
e.printStackTrace();
}
if (!isAllowedCollection(collection)) {
log.debug("DBACCESS wrong collection specified");
return;
}
if (action.equals("dbRemove")) {
DbRequest dbr = new DbRequest(action, collection, _id);
UploadQueue.add(dbr);
} else {
DbRequest dbr = new DbRequest(action, collection, data);
UploadQueue.add(dbr);
}
} finally {
wakeLock.release();
}
}
private boolean isAllowedCollection(String collection) {
// "treatments" || "entries" || "devicestatus" || "profile" || "food"
if (collection.equals("treatments")) return true;
if (collection.equals("entries")) return true;
if (collection.equals("devicestatus")) return true;
if (collection.equals("profile")) return true;
if (collection.equals("food")) return true;
return false;
}
}

View file

@ -0,0 +1,25 @@
package info.nightscout.androidaps.plugins.NSClientInternal.receivers;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart;
import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
public class RestartReceiver extends WakefulBroadcastReceiver {
public RestartReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
startWakefulService(context, new Intent(context, NSClientService.class)
.setAction(intent.getAction())
.putExtras(intent));
MainApp.bus().post(new EventNSClientRestart());
completeWakefulIntent(intent);
}
}

View file

@ -0,0 +1,760 @@
package info.nightscout.androidaps.plugins.NSClientInternal.services;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Binder;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.widget.Toast;
import com.google.common.base.Charsets;
import com.google.common.hash.Hashing;
import com.squareup.otto.Subscribe;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.URISyntaxException;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.DanaR.Services.ExecutionService;
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
import info.nightscout.androidaps.plugins.NSClientInternal.acks.NSAddAck;
import info.nightscout.androidaps.plugins.NSClientInternal.acks.NSAuthAck;
import info.nightscout.androidaps.plugins.NSClientInternal.acks.NSPingAck;
import info.nightscout.androidaps.plugins.NSClientInternal.acks.NSUpdateAck;
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastCals;
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastDeviceStatus;
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastMbgs;
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastSgvs;
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastStatus;
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastTreatment;
import info.nightscout.androidaps.plugins.NSClientInternal.data.DbRequest;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSCal;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSStatus;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSTreatment;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus;
import info.nightscout.utils.SafeParse;
import io.socket.client.IO;
import io.socket.client.Socket;
import io.socket.emitter.Emitter;
public class NSClientService extends Service {
private static Logger log = LoggerFactory.getLogger(ExecutionService.class);
static public PowerManager.WakeLock mWakeLock;
public static boolean forcerestart = false;
private IBinder mBinder = new NSClientService.LocalBinder();
static NSProfile nsProfile;
static public Handler handler;
static private HandlerThread handlerThread;
public static Socket mSocket;
public static boolean isConnected = false;
private static Integer dataCounter = 0;
public static String nightscoutVersionName = "";
public static Integer nightscoutVersionCode = 0;
private boolean nsEnabled = false;
private String nsURL = "";
private String nsAPISecret = "";
private String nsDevice = "";
private Integer nsHours = 3;
private final Integer timeToWaitForResponseInMs = 30000;
private boolean uploading = false;
public Date lastReception = new Date();
private String nsAPIhashCode = "";
public static UploadQueue uploadQueue = new UploadQueue();
public NSClientService() {
registerBus();
if (handler == null) {
handlerThread = new HandlerThread(NSClientService.class.getSimpleName() + "Handler");
handlerThread.start();
handler = new Handler(handlerThread.getLooper());
}
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "NSClientService");
initialize();
}
public class LocalBinder extends Binder {
public NSClientService getServiceInstance() {
return NSClientService.this;
}
}
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
private void registerBus() {
try {
MainApp.bus().unregister(this);
} catch (RuntimeException x) {
// Ignore
}
MainApp.bus().register(this);
}
@Subscribe
public void onStatusEvent(EventAppExit event) {
if (Config.logFunctionCalls)
log.debug("EventAppExit received");
destroy();
stopSelf();
if (Config.logFunctionCalls)
log.debug("EventAppExit finished");
}
public static void setNsProfile(NSProfile profile) {
nsProfile = profile;
}
public static NSProfile getNsProfile() {
return nsProfile;
}
public void initialize() {
dataCounter = 0;
NSClientService.mWakeLock.acquire();
readPreferences();
if (!nsAPISecret.equals(""))
nsAPIhashCode = Hashing.sha1().hashString(nsAPISecret, Charsets.UTF_8).toString();
MainApp.bus().post(new EventNSClientStatus("Initializing"));
if (!nsEnabled) {
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "disabled"));
MainApp.bus().post(new EventNSClientStatus("Disabled"));
} else if (!nsURL.equals("")) {
try {
MainApp.bus().post(new EventNSClientStatus("Connecting ..."));
IO.Options opt = new IO.Options();
opt.forceNew = true;
opt.reconnection = true;
mSocket = IO.socket(nsURL, opt);
mSocket.on(Socket.EVENT_CONNECT, onConnect);
mSocket.on(Socket.EVENT_DISCONNECT, onDisconnect);
mSocket.on(Socket.EVENT_PING, onPing);
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "do connect"));
mSocket.connect();
mSocket.on("dataUpdate", onDataUpdate);
} catch (URISyntaxException | RuntimeException e) {
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "Wrong URL syntax"));
MainApp.bus().post(new EventNSClientStatus("Wrong URL syntax"));
}
} else {
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "No NS URL specified"));
MainApp.bus().post(new EventNSClientStatus("Not configured"));
}
NSClientService.mWakeLock.release();
}
private Emitter.Listener onConnect = new Emitter.Listener() {
@Override
public void call(Object... args) {
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "connect event. ID: " + mSocket.id()));
sendAuthMessage(new NSAuthAck());
}
};
private Emitter.Listener onDisconnect = new Emitter.Listener() {
@Override
public void call(Object... args) {
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "disconnect event"));
}
};
public void destroy() {
if (mSocket != null) {
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "destroy"));
isConnected = false;
mSocket.disconnect();
mSocket = null;
}
}
public void sendAuthMessage(NSAuthAck ack) {
JSONObject authMessage = new JSONObject();
try {
authMessage.put("client", "Android_" + nsDevice);
authMessage.put("history", nsHours);
authMessage.put("status", true); // receive status
authMessage.put("pingme", true); // send mi pings to keep alive
authMessage.put("secret", nsAPIhashCode);
} catch (JSONException e) {
e.printStackTrace();
return;
}
MainApp.bus().post(new EventNSClientNewLog("AUTH", "requesting auth"));
mSocket.emit("authorize", authMessage, ack);
}
@Subscribe
public void onStatusEvent(NSAuthAck ack) {
String connectionStatus = "Authenticated (";
if (ack.read) connectionStatus += "R";
if (ack.write) connectionStatus += "W";
if (ack.write_treatment) connectionStatus += "T";
connectionStatus += ')';
isConnected = true;
MainApp.bus().post(new EventNSClientStatus(connectionStatus));
MainApp.bus().post(new EventNSClientNewLog("AUTH", connectionStatus));
if (!ack.write) {
MainApp.bus().post(new EventNSClientNewLog("ERROR", "Write permission not granted !!!!"));
}
if (!ack.write_treatment) {
MainApp.bus().post(new EventNSClientNewLog("ERROR", "Write treatment permission not granted !!!!"));
}
lastReception = new Date();
}
public void readPreferences() {
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
nsEnabled = MainApp.getSpecificPlugin(NSClientInternalPlugin.class).isEnabled(PluginBase.GENERAL);
nsURL = SP.getString("nsclientinternal_url", "");
nsAPISecret = SP.getString("nsclientinternal_api_secret", "");
nsHours = SafeParse.stringToInt(SP.getString("nsclientinternal_hours", "3"));
nsDevice = SP.getString("nsclientinternal_devicename", "");
}
private Emitter.Listener onPing = new Emitter.Listener() {
@Override
public void call(final Object... args) {
if (Config.detailedLog)
MainApp.bus().post(new EventNSClientNewLog("PING", "received"));
// send data if there is something waiting
resend("Ping received");
}
};
private Emitter.Listener onDataUpdate = new Emitter.Listener() {
@Override
public void call(final Object... args) {
lastReception = new Date();
NSClientService.handler.post(new Runnable() {
@Override
public void run() {
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"onDataUpdate");
wakeLock.acquire();
try {
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
JSONObject data = (JSONObject) args[0];
NSCal actualCal = new NSCal();
boolean broadcastProfile = false;
try {
// delta means only increment/changes are comming
boolean isDelta = data.has("delta");
boolean isFull = !isDelta;
MainApp.bus().post(new EventNSClientNewLog("DATA", "Data packet #" + dataCounter++ + (isDelta ? " delta" : " full")));
if (data.has("profiles")) {
JSONArray profiles = (JSONArray) data.getJSONArray("profiles");
if (profiles.length() > 0) {
JSONObject profile = (JSONObject) profiles.get(profiles.length() - 1);
String activeProfile = NSClientService.getNsProfile() == null ? null : NSClientService.getNsProfile().getActiveProfile();
NSProfile nsProfile = new NSProfile(profile, activeProfile);
NSClientService.setNsProfile(nsProfile);
broadcastProfile = true;
MainApp.bus().post(new EventNSClientNewLog("PROFILE", "profile received"));
}
}
if (data.has("status")) {
JSONObject status = data.getJSONObject("status");
NSStatus nsStatus = new NSStatus(status);
if (!status.has("versionNum")) {
if (status.getInt("versionNum") < 900) {
MainApp.bus().post(new EventNSClientNewLog("ERROR", "Unsupported Nightscout version !!!!"));
}
} else {
nightscoutVersionName = status.getString("version");
nightscoutVersionCode = status.getInt("versionNum");
}
BroadcastStatus bs = new BroadcastStatus();
bs.handleNewStatus(nsStatus, MainApp.instance().getApplicationContext(), isDelta);
if (NSClientService.getNsProfile() != null) {
String oldActiveProfile = NSClientService.getNsProfile().getActiveProfile();
String receivedActiveProfile = nsStatus.getActiveProfile();
NSClientService.getNsProfile().setActiveProfile(receivedActiveProfile);
if (receivedActiveProfile != null) {
MainApp.bus().post(new EventNSClientNewLog("PROFILE", "status activeProfile received: " + receivedActiveProfile));
}
// Change possible nulls to ""
String oldP = oldActiveProfile == null ? "" : oldActiveProfile;
String newP = receivedActiveProfile == null ? "" : receivedActiveProfile;
if (!newP.equals(oldP)) {
broadcastProfile = true;
}
}
/* Other received data to 2016/02/10
{
status: 'ok'
, name: env.name
, version: env.version
, versionNum: versionNum (for ver 1.2.3 contains 10203)
, serverTime: new Date().toISOString()
, apiEnabled: apiEnabled
, careportalEnabled: apiEnabled && env.settings.enable.indexOf('careportal') > -1
, boluscalcEnabled: apiEnabled && env.settings.enable.indexOf('boluscalc') > -1
, head: env.head
, settings: env.settings
, extendedSettings: ctx.plugins && ctx.plugins.extendedClientSettings ? ctx.plugins.extendedClientSettings(env.extendedSettings) : {}
, activeProfile ..... calculated from treatments or missing
}
*/
} else if (!isDelta) {
MainApp.bus().post(new EventNSClientNewLog("ERROR", "Unsupported Nightscout version !!!!"));
}
// If new profile received or change detected broadcast it
if (broadcastProfile && nsProfile != null) {
BroadcastProfile bp = new BroadcastProfile();
bp.handleNewTreatment(nsProfile, MainApp.instance().getApplicationContext(), isDelta);
MainApp.bus().post(new EventNSClientNewLog("PROFILE", "broadcasting"));
}
if (data.has("treatments")) {
JSONArray treatments = (JSONArray) data.getJSONArray("treatments");
JSONArray removedTreatments = new JSONArray();
JSONArray updatedTreatments = new JSONArray();
JSONArray addedTreatments = new JSONArray();
BroadcastTreatment bt = new BroadcastTreatment();
if (treatments.length() > 0)
MainApp.bus().post(new EventNSClientNewLog("DATA", "received " + treatments.length() + " treatments"));
for (Integer index = 0; index < treatments.length(); index++) {
JSONObject jsonTreatment = treatments.getJSONObject(index);
NSTreatment treatment = new NSTreatment(jsonTreatment);
// remove from upload queue if Ack is failing
UploadQueue.removeID(jsonTreatment);
if (treatment.getAction() == null) {
if (!isCurrent(treatment)) continue;
addedTreatments.put(jsonTreatment);
} else if (treatment.getAction().equals("update")) {
if (!isCurrent(treatment)) continue;
updatedTreatments.put(jsonTreatment);
} else if (treatment.getAction().equals("remove")) {
removedTreatments.put(jsonTreatment);
}
}
if (removedTreatments.length() > 0) {
bt.handleRemovedTreatment(removedTreatments, MainApp.instance().getApplicationContext(), isDelta);
}
if (updatedTreatments.length() > 0) {
bt.handleChangedTreatment(updatedTreatments, MainApp.instance().getApplicationContext(), isDelta);
}
if (addedTreatments.length() > 0) {
bt.handleNewTreatment(addedTreatments, MainApp.instance().getApplicationContext(), isDelta);
}
}
if (data.has("devicestatus")) {
BroadcastDeviceStatus bds = new BroadcastDeviceStatus();
JSONArray devicestatuses = (JSONArray) data.getJSONArray("devicestatus");
if (devicestatuses.length() > 0) {
MainApp.bus().post(new EventNSClientNewLog("DATA", "received " + devicestatuses.length() + " devicestatuses"));
for (Integer index = 0; index < devicestatuses.length(); index++) {
JSONObject jsonStatus = devicestatuses.getJSONObject(index);
// remove from upload queue if Ack is failing
UploadQueue.removeID(jsonStatus);
}
// send only last record
bds.handleNewDeviceStatus(devicestatuses.getJSONObject(devicestatuses.length() - 1), MainApp.instance().getApplicationContext(), isDelta);
}
}
if (data.has("mbgs")) {
BroadcastMbgs bmbg = new BroadcastMbgs();
JSONArray mbgs = (JSONArray) data.getJSONArray("mbgs");
if (mbgs.length() > 0)
MainApp.bus().post(new EventNSClientNewLog("DATA", "received " + mbgs.length() + " mbgs"));
for (Integer index = 0; index < mbgs.length(); index++) {
JSONObject jsonMbg = mbgs.getJSONObject(index);
// remove from upload queue if Ack is failing
UploadQueue.removeID(jsonMbg);
}
bmbg.handleNewMbg(mbgs, MainApp.instance().getApplicationContext(), isDelta);
}
if (data.has("cals")) {
BroadcastCals bc = new BroadcastCals();
JSONArray cals = (JSONArray) data.getJSONArray("cals");
if (cals.length() > 0)
MainApp.bus().post(new EventNSClientNewLog("DATA", "received " + cals.length() + " cals"));
// Retreive actual calibration
for (Integer index = 0; index < cals.length(); index++) {
if (index == 0) {
actualCal.set(cals.optJSONObject(index));
}
// remove from upload queue if Ack is failing
UploadQueue.removeID(cals.optJSONObject(index));
}
bc.handleNewCal(cals, MainApp.instance().getApplicationContext(), isDelta);
}
if (data.has("sgvs")) {
BroadcastSgvs bs = new BroadcastSgvs();
String units = nsProfile != null ? nsProfile.getUnits() : "mg/dl";
JSONArray sgvs = (JSONArray) data.getJSONArray("sgvs");
if (sgvs.length() > 0)
MainApp.bus().post(new EventNSClientNewLog("DATA", "received " + sgvs.length() + " sgvs"));
for (Integer index = 0; index < sgvs.length(); index++) {
JSONObject jsonSgv = sgvs.getJSONObject(index);
// MainApp.bus().post(new EventNSClientNewLog("DATA", "svg " + sgvs.getJSONObject(index).toString());
NSSgv sgv = new NSSgv(jsonSgv);
// Handle new sgv here
// remove from upload queue if Ack is failing
UploadQueue.removeID(jsonSgv);
}
bs.handleNewSgv(sgvs, MainApp.instance().getApplicationContext(), isDelta);
}
} catch (JSONException e) {
e.printStackTrace();
}
//MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "onDataUpdate end");
} finally {
wakeLock.release();
}
}
});
}
};
public void dbUpdate(DbRequest dbr, NSUpdateAck ack) {
try {
if (!isConnected) return;
if (uploading) {
MainApp.bus().post(new EventNSClientNewLog("DBUPDATE", "Busy, adding to queue"));
return;
}
uploading = true;
JSONObject message = new JSONObject();
message.put("collection", dbr.collection);
message.put("_id", dbr._id);
message.put("data", dbr.data);
mSocket.emit("dbUpdate", message, ack);
synchronized (ack) {
try {
ack.wait(timeToWaitForResponseInMs);
} catch (InterruptedException e) {
}
}
} catch (JSONException e) {
e.printStackTrace();
return;
}
uploading = false;
}
public void dbUpdate(DbRequest dbr) {
try {
if (!isConnected) return;
if (uploading) {
MainApp.bus().post(new EventNSClientNewLog("DBUPDATE", "Busy, adding to queue"));
return;
}
uploading = true;
JSONObject message = new JSONObject();
message.put("collection", dbr.collection);
message.put("_id", dbr._id);
message.put("data", dbr.data);
mSocket.emit("dbUpdate", message);
} catch (JSONException e) {
e.printStackTrace();
return;
}
uploading = false;
}
public void dbUpdateUnset(DbRequest dbr, NSUpdateAck ack) {
try {
if (!isConnected) return;
if (uploading) {
MainApp.bus().post(new EventNSClientNewLog("DBUPUNSET", "Busy, adding to queue"));
return;
}
uploading = true;
JSONObject message = new JSONObject();
message.put("collection", dbr.collection);
message.put("_id", dbr._id);
message.put("data", dbr.data);
mSocket.emit("dbUpdateUnset", message, ack);
synchronized (ack) {
try {
ack.wait(timeToWaitForResponseInMs);
} catch (InterruptedException e) {
}
}
} catch (JSONException e) {
e.printStackTrace();
return;
}
uploading = false;
}
public void dbUpdateUnset(DbRequest dbr) {
try {
if (!isConnected) return;
if (uploading) {
MainApp.bus().post(new EventNSClientNewLog("DBUPUNSET", "Busy, adding to queue"));
return;
}
uploading = true;
JSONObject message = new JSONObject();
message.put("collection", dbr.collection);
message.put("_id", dbr._id);
message.put("data", dbr.data);
mSocket.emit("dbUpdateUnset", message);
} catch (JSONException e) {
e.printStackTrace();
return;
}
uploading = false;
}
public void dbRemove(DbRequest dbr, NSUpdateAck ack) {
try {
if (!isConnected) return;
if (uploading) {
MainApp.bus().post(new EventNSClientNewLog("DBREMOVE", "Busy, adding to queue"));
return;
}
uploading = true;
JSONObject message = new JSONObject();
message.put("collection", dbr.collection);
message.put("_id", dbr._id);
mSocket.emit("dbRemove", message, ack);
synchronized (ack) {
try {
ack.wait(timeToWaitForResponseInMs);
} catch (InterruptedException e) {
}
}
} catch (JSONException e) {
e.printStackTrace();
return;
}
uploading = false;
}
public void dbRemove(DbRequest dbr) {
try {
if (!isConnected) return;
if (uploading) {
MainApp.bus().post(new EventNSClientNewLog("DBREMOVE", "Busy, adding to queue"));
return;
}
uploading = true;
JSONObject message = new JSONObject();
message.put("collection", dbr.collection);
message.put("_id", dbr._id);
mSocket.emit("dbRemove", message);
} catch (JSONException e) {
e.printStackTrace();
return;
}
uploading = false;
}
public void dbAdd(DbRequest dbr, NSAddAck ack) {
try {
if (!isConnected) return;
if (uploading) {
MainApp.bus().post(new EventNSClientNewLog("DBADD", "Busy, adding to queue"));
return;
}
uploading = true;
JSONObject message = new JSONObject();
message.put("collection", dbr.collection);
message.put("data", dbr.data);
mSocket.emit("dbAdd", message, ack);
synchronized (ack) {
try {
ack.wait(timeToWaitForResponseInMs);
} catch (InterruptedException e) {
}
}
} catch (JSONException e) {
e.printStackTrace();
return;
}
uploading = false;
}
public void dbAdd(DbRequest dbr) {
try {
if (!isConnected) return;
if (uploading) {
MainApp.bus().post(new EventNSClientNewLog("DBADD", "Busy, adding to queue"));
return;
}
uploading = true;
JSONObject message = new JSONObject();
message.put("collection", dbr.collection);
message.put("data", dbr.data);
mSocket.emit("dbAdd", message);
} catch (JSONException e) {
e.printStackTrace();
return;
}
uploading = false;
}
public void doPing() {
if (!isConnected) return;
MainApp.bus().post(new EventNSClientNewLog("PING", "Sending"));
uploading = true;
JSONObject message = new JSONObject();
try {
message.put("mills", new Date().getTime());
} catch (JSONException e) {
e.printStackTrace();
}
NSPingAck ack = new NSPingAck();
mSocket.emit("nsping", message, ack);
synchronized (ack) {
try {
ack.wait(timeToWaitForResponseInMs);
} catch (InterruptedException e) {
}
}
if (ack.received) {
String connectionStatus = "Pong received";
if (ack.auth_received) {
connectionStatus += ": ";
if (ack.read) connectionStatus += "R";
if (ack.write) connectionStatus += "W";
if (ack.write_treatment) connectionStatus += "T";
}
if (!ack.read) sendAuthMessage(new NSAuthAck());
MainApp.bus().post(new EventNSClientNewLog("AUTH ", connectionStatus));
} else {
MainApp.bus().post(new EventNSClientNewLog("PING", "Ping lost"));
}
uploading = false;
}
private boolean isCurrent(NSTreatment treatment) {
long now = (new Date()).getTime();
long minPast = now - nsHours * 60L * 60 * 1000;
if (treatment.getMills() == null) {
log.debug("treatment.getMills() == null " + treatment.getData().toString());
return false;
}
if (treatment.getMills() > minPast) return true;
return false;
}
public void resend(final String reason) {
if (UploadQueue.queue.size() == 0)
return;
if (!isConnected) return;
MainApp.bus().post(new EventNSClientNewLog("QUEUE", "Resend started: " + reason));
handler.post(new Runnable() {
@Override
public void run() {
Logger log = LoggerFactory.getLogger(UploadQueue.class);
Iterator<Map.Entry<String, DbRequest>> iter = UploadQueue.queue.entrySet().iterator();
if (mSocket == null || !mSocket.connected()) return;
while (iter.hasNext()) {
DbRequest dbr = iter.next().getValue();
if (dbr.action.equals("dbAdd")) {
NSAddAck addAck = new NSAddAck();
dbAdd(dbr, addAck);
if (addAck._id == null) {
MainApp.bus().post(new EventNSClientNewLog("QUEUE", "No response on dbAdd"));
return;
}
if (Config.detailedLog)
MainApp.bus().post(new EventNSClientNewLog("QUEUE", "dbAdd processed: " + dbr.data.toString()));
else
MainApp.bus().post(new EventNSClientNewLog("QUEUE", "dbAdd processed"));
iter.remove();
} else if (dbr.action.equals("dbRemove")) {
NSUpdateAck removeAck = new NSUpdateAck();
dbRemove(dbr, removeAck);
if (!removeAck.result) {
MainApp.bus().post(new EventNSClientNewLog("QUEUE", "No response on dbRemove"));
return;
}
MainApp.bus().post(new EventNSClientNewLog("QUEUE", "dbRemove processed: " + dbr._id));
iter.remove();
} else if (dbr.action.equals("dbUpdate")) {
NSUpdateAck updateAck = new NSUpdateAck();
dbUpdate(dbr, updateAck);
if (!updateAck.result) {
MainApp.bus().post(new EventNSClientNewLog("QUEUE", "No response on dbUpdate"));
return;
}
MainApp.bus().post(new EventNSClientNewLog("QUEUE", "dbUpdate processed: " + dbr._id));
iter.remove();
} else if (dbr.action.equals("dbUpdateUnset")) {
NSUpdateAck updateUnsetAck = new NSUpdateAck();
dbUpdateUnset(dbr, updateUnsetAck);
if (!updateUnsetAck.result) {
MainApp.bus().post(new EventNSClientNewLog("QUEUE", "No response on dbUpdateUnset"));
return;
}
MainApp.bus().post(new EventNSClientNewLog("QUEUE", "dbUpdateUnset processed: " + dbr._id));
iter.remove();
}
}
MainApp.bus().post(new EventNSClientNewLog("QUEUE", "Resend ended: " + reason));
}
});
}
public void restart() {
destroy();
initialize();
}
}

View file

@ -20,7 +20,7 @@ import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.plugins.NSProfile.events.EventNSProfileUpdateGUI;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
/**
* Created by mike on 05.08.2016.

View file

@ -11,11 +11,10 @@ import java.util.Arrays;
import java.util.Date;
import java.util.List;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.Round;
import info.nightscout.utils.SafeParse;

View file

@ -16,17 +16,14 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.GlucoseStatus;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.SafeParse;
public class DetermineBasalAdapterAMAJS {

View file

@ -22,14 +22,13 @@ import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
import info.nightscout.androidaps.plugins.Loop.APSResult;
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui;
import info.nightscout.androidaps.plugins.TempTargetRange.TempTargetRangePlugin;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.Profiler;
import info.nightscout.utils.Round;

View file

@ -18,7 +18,7 @@ import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
public class DetermineBasalAdapterMAJS {
private static Logger log = LoggerFactory.getLogger(DetermineBasalAdapterMAJS.class);

View file

@ -28,12 +28,11 @@ import info.nightscout.androidaps.plugins.Loop.ScriptReader;
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui;
import info.nightscout.androidaps.plugins.TempTargetRange.TempTargetRangePlugin;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.Profiler;
import info.nightscout.utils.Round;
import info.nightscout.utils.SafeParse;
import info.nightscout.utils.ToastUtils;
import static info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin.checkOnlyHardLimits;
import static info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin.verifyHardLimits;

View file

@ -21,7 +21,7 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.GlucoseStatus;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.PlusMinusEditText;
import info.nightscout.utils.XdripCalibrations;

View file

@ -43,7 +43,7 @@ import info.nightscout.androidaps.interfaces.TempBasalsInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.BolusWizard;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;

View file

@ -87,7 +87,7 @@ import info.nightscout.androidaps.plugins.Overview.graphExtensions.TimeAsXAxisLa
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin;
import info.nightscout.androidaps.plugins.TempTargetRange.TempTargetRangePlugin;
import info.nightscout.androidaps.plugins.TempTargetRange.events.EventTempTargetRangeChange;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.BolusWizard;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;

View file

@ -7,12 +7,10 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import info.nightscout.androidaps.MainApp;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
/**

View file

@ -13,7 +13,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.Round;
import info.nightscout.utils.SafeParse;

View file

@ -15,7 +15,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.SafeParse;
/**

View file

@ -35,7 +35,7 @@ import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS;
import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventSmsCommunicatorUpdateGui;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.SafeParse;
import info.nightscout.utils.XdripCalibrations;

View file

@ -34,7 +34,7 @@ import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.interfaces.FragmentBase;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.TempTargetRange.events.EventTempTargetRangeChange;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.ToastUtils;

View file

@ -36,7 +36,7 @@ import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.FragmentBase;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.ToastUtils;

View file

@ -3,21 +3,14 @@ package info.nightscout.androidaps.plugins.Treatments;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.PreparedQuery;
import com.j256.ormlite.stmt.QueryBuilder;
import com.j256.ormlite.stmt.Where;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Iob;
@ -28,7 +21,7 @@ import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.SafeParse;
/**

View file

@ -23,7 +23,7 @@ import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.VirtualPump.events.EventVirtualPumpUpdateGui;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
/**

View file

@ -1,21 +1,13 @@
package info.nightscout.androidaps.plugins.Wear;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Handler;
import android.os.HandlerThread;
import android.preference.PreferenceManager;
import android.support.annotation.BoolRes;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.view.View;
import com.j256.ormlite.dao.Dao;
import org.json.JSONException;
import org.json.JSONObject;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.Date;
@ -32,12 +24,10 @@ import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.Overview.QuickWizard;
import info.nightscout.androidaps.plugins.TempTargetRange.TempTargetRangePlugin;
import info.nightscout.androidaps.plugins.TempTargetRange.events.EventTempTargetRangeChange;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.BolusWizard;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;

View file

@ -33,7 +33,7 @@ import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
import info.nightscout.androidaps.plugins.Wear.ActionStringHandler;
import info.nightscout.androidaps.plugins.Wear.WearPlugin;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.SafeParse;
import info.nightscout.utils.ToastUtils;

View file

@ -28,7 +28,7 @@ import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DecimalFormatter;
/**

View file

@ -18,14 +18,10 @@ import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanPlugin;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
public class KeepAliveReceiver extends BroadcastReceiver {
private static Logger log = LoggerFactory.getLogger(KeepAliveReceiver.class);

View file

@ -6,7 +6,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
/**
* Created by mike on 11.10.2016.

View file

@ -17,7 +17,7 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.client.data.NSProfile;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
/**
* Created by mike on 10.02.2017.

View file

@ -0,0 +1,156 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/nsclientinternal_url"
android:textSize="16dp" />
<TextView
android:id="@+id/nsclientinternal_url"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:autoLink="web"
android:gravity="center_vertical|end"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:orientation="horizontal">
<CheckBox
android:id="@+id/nsclientinternal_paused"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/paused" />
<CheckBox
android:id="@+id/nsclientinternal_autoscroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:text="@string/nsclientinternal_autoscroll" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:text="@string/queue" />
<TextView
android:id="@+id/nsclientinternal_queue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:text="@string/status" />
<TextView
android:id="@+id/nsclientinternal_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:orientation="horizontal">
<TextView
android:id="@+id/nsclientinternal_restart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/restart"
android:textAlignment="center"
android:textColor="@android:color/holo_orange_light" />
<TextView
android:id="@+id/nsclientinternal_delivernow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/deliver_now"
android:textAlignment="center"
android:textColor="@android:color/holo_orange_light" />
<TextView
android:id="@+id/nsclientinternal_clearqueue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/clear_queue"
android:textAlignment="center"
android:textColor="@android:color/holo_orange_light" />
<TextView
android:id="@+id/nsclientinternal_showqueue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/show_queue"
android:textAlignment="center"
android:textColor="@android:color/holo_orange_light" />
</LinearLayout>
<ScrollView
android:id="@+id/nsclientinternal_logscrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp">
<TextView
android:id="@+id/nsclientinternal_log"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="" />
</ScrollView>
</LinearLayout>
</FrameLayout>

View file

@ -507,4 +507,26 @@
<string name="settings_password">Password for settings</string>
<string name="unlock_settings">Unlock settings</string>
<string name="approachingdailylimit">Approaching insulin daily limit</string>
<string name="nsclientinternal">NSClient internal</string>
<string name="nsclientinternal_shortname">NSCI</string>
<string name="nsclientinternal_url">URL:</string>
<string name="nsclientinternal_autoscroll">Autoscroll</string>
<string name="restart">Restart</string>
<string name="nsclientinternal_title">Internal NSClient</string>
<string name="nsclientinternal_url_title">Nightscout URL</string>
<string name="nsclientinternal_url_dialogmessage">Enter Nightscout URL</string>
<string name="nsclientinternal_hours">Hours to fetch</string>
<string name="nsclientinternal_hours_message">Enter hours to fetch from NS (max 48)</string>
<string name="nsclientinternal_secret_title">NS API secret</string>
<string name="nsclientinternal_secret_dialogtitle">NS API secret</string>
<string name="nsclientinternal_secret_dialogmessage">Enter NS API secret (min 12 chars)</string>
<string name="nsclientinternal_devicename_title">Device name</string>
<string name="nsclientinternal_devicename_dialogtitle">Enter device name</string>
<string name="nsclientinternal_devicename_dialogmessage">It will be used for enteredBy field</string>
<string name="deliver_now">Deliver now</string>
<string name="clear_queue">Clear queue</string>
<string name="show_queue">Show queue</string>
<string name="queue">Queue:</string>
<string name="status">Status:</string>
<string name="paused">Paused</string>
</resources>

View file

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:validate="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
android:key="ns_api"
android:title="@string/nsclientinternal_title">
<com.andreabaccega.widget.ValidatingEditTextPreference
validate:testType="webUrl"
android:defaultValue="https://{YOUR-SITE}.azurewebsites.net/"
android:selectAllOnFocus="true"
android:inputType="textUri"
android:title="@string/nsclientinternal_url_title"
android:dialogMessage="@string/nsclientinternal_url_dialogmessage"
android:key="nsclientinternal_url" />
<EditTextPreference
android:title="@string/nsclientinternal_secret_title"
android:key="nsclientinternal_api_secret"
android:dialogTitle="@string/nsclientinternal_secret_dialogtitle"
android:dialogMessage="@string/nsclientinternal_secret_dialogmessage"
android:defaultValue=""
android:inputType="textPassword">
</EditTextPreference>
<EditTextPreference
android:title="@string/nsclientinternal_devicename_title"
android:key="nsclientinternal_devicename"
android:dialogTitle="@string/nsclientinternal_devicename_dialogtitle"
android:dialogMessage="@string/nsclientinternal_devicename_dialogmessage"
android:defaultValue=""
android:inputType="text">
</EditTextPreference>
<com.andreabaccega.widget.ValidatingEditTextPreference
validate:testType="numericRange"
validate:minNumber="1"
validate:maxNumber="48"
android:digits="0123456789"
android:defaultValue="24"
android:selectAllOnFocus="true"
android:inputType="number"
android:maxLines="20"
android:title="@string/nsclientinternal_hours"
android:dialogMessage="@string/nsclientinternal_hours_message"
android:key="nsclientinternal_hours" />
</PreferenceCategory>
</PreferenceScreen>