ns alarms & getBasal fix

This commit is contained in:
Milos Kozak 2017-06-11 17:22:54 +02:00
parent bf953f1240
commit 77659e20e7
39 changed files with 669 additions and 71 deletions

View file

@ -17,6 +17,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.permission.PROVIDE_BACKGROUND" />
<uses-permission-sdk-23 android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<!-- To receive data from xdrip. -->
@ -58,7 +59,6 @@
android:enabled="true"
android:exported="true">
<intent-filter>
<!-- Receiver from NSClient -->
<action android:name="info.nightscout.client.NEW_SGV" />
<action android:name="info.nightscout.client.NEW_TREATMENT" />
@ -79,6 +79,19 @@
<action android:name="it.ct.glicemia.ACTION_GLUCOSE_MEASURED" />
</intent-filter>
</receiver>
<receiver
android:name=".receivers.NSAlarmReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<!-- Receiver from NSClient -->
<action android:name="info.nightscout.client.ANNOUNCEMENT" />
<action android:name="info.nightscout.client.ALARM" />
<action android:name="info.nightscout.client.URGENT_ALARM" />
<action android:name="info.nightscout.client.CLEAR_ALARM" />
</intent-filter>
</receiver>
<!-- Receiver keepalive, scheduled every 30 min -->
<receiver android:name=".receivers.KeepAliveReceiver" />
@ -110,6 +123,14 @@
<action android:name="info.nightscout.client.DBACCESS" />
</intent-filter>
</receiver>
<receiver
android:name=".plugins.NSClientInternal.receivers.AckAlarmReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="info.nightscout.client.ACK_ALARM" />
</intent-filter>
</receiver>
<!-- Service processing incomming data -->
<service
@ -117,7 +138,6 @@
android:exported="false" />
<service
android:name=".plugins.PumpDanaR.services.DanaRExecutionService"
android:enabled="true"
android:exported="false" />
<service
@ -135,16 +155,19 @@
<action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
</intent-filter>
</service>
<service
android:name=".plugins.NSClientInternal.services.NSClientService"
android:enabled="true"
android:exported="true" />
<service
android:name=".Services.AlarmSoundService"
android:enabled="true"
android:exported="true" />
<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>

View file

@ -34,6 +34,7 @@ import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Services.AlarmSoundService;
import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRefreshGui;
@ -79,6 +80,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
registerBus();
setUpTabs(false);
Intent alarm = new Intent(this, AlarmSoundService.class);
alarm.putExtra("soundid", R.raw.staledataalarm);
//startService(alarm);
}
@Subscribe

View file

@ -0,0 +1,71 @@
package info.nightscout.androidaps.Services;
import android.app.Service;
import android.content.Intent;
import android.content.res.AssetFileDescriptor;
import android.media.MediaPlayer;
import android.os.IBinder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
public class AlarmSoundService extends Service {
private static Logger log = LoggerFactory.getLogger(AlarmSoundService.class);
MediaPlayer player;
int resourceId = R.raw.bgalarm;
public AlarmSoundService() {
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public void onCreate() {
super.onCreate();
log.debug("onCreate");
}
public int onStartCommand(Intent intent, int flags, int startId) {
log.debug("onStartCommand");
if (intent != null && intent.hasExtra("soundid"))
resourceId = intent.getIntExtra("soundid", R.raw.bgalarm);
player = new MediaPlayer();
AssetFileDescriptor afd = MainApp.sResources.openRawResourceFd(resourceId);
if (afd == null)
return START_STICKY;
try {
player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
afd.close();
} catch (IOException e) {
e.printStackTrace();
}
player.setLooping(true); // Set looping
player.setVolume(100, 100);
try {
player.prepare();
player.start();
} catch (IOException e) {
e.printStackTrace();
}
return START_STICKY;
}
@Override
public void onDestroy() {
player.stop();
player.release();
}
}

View file

@ -504,7 +504,7 @@ public class DataService extends IntentService {
long date = trJson.getLong("mills");
long now = new Date().getTime();
if (date > now - 15 * 60 * 1000L && trJson.has("notes")) {
Notification announcement = new Notification(Notification.ANNOUNCEMENT, trJson.getString("notes"), Notification.URGENT);
Notification announcement = new Notification(Notification.NSANNOUNCEMENT, trJson.getString("notes"), Notification.ANNOUNCEMENT, 60);
MainApp.bus().post(new EventNewNotification(announcement));
}
}

View file

@ -12,12 +12,17 @@ public interface Intents {
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";
String ACTION_ANNOUNCEMENT = "info.nightscout.client.ANNOUNCEMENT";
String ACTION_ALARM = "info.nightscout.client.ALARM";
String ACTION_URGENT_ALARM = "info.nightscout.client.URGENT_ALARM";
String ACTION_CLEAR_ALARM = "info.nightscout.client.CLEAR_ALARM";
// App -> NSClient
String ACTION_DATABASE = "info.nightscout.client.DBACCESS";
String ACTION_RESTART = "info.nightscout.client.RESTART";
String ACTION_RESEND = "info.nightscout.client.RESEND";
String ACTION_ACK_ALARM = "info.nightscout.client.ACK_ALARM";
// xDrip -> App
String RECEIVER_PERMISSION = "com.eveningoutpost.dexdrip.permissions.RECEIVE_BG_ESTIMATE";

View file

@ -0,0 +1,37 @@
package info.nightscout.androidaps.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.NSAlarm;
/**
* Created by mike on 11.06.2017.
*/
public class NSClearAlarmBroadcast {
private static Logger log = LoggerFactory.getLogger(NSClearAlarmBroadcast.class);
public static void handleClearAlarm(NSAlarm originalAlarm, Context context, long silenceTimeInMsec) {
Bundle bundle = new Bundle();
bundle.putInt("level", originalAlarm.getLevel());
bundle.putString("group", originalAlarm.getGroup());
bundle.putLong("silenceTime", silenceTimeInMsec);
Intent intent = new Intent(Intents.ACTION_ACK_ALARM);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("ACKALARM " + x.size() + " receivers");
}
}

View file

@ -230,7 +230,7 @@ public class CareportalEvent implements DataPointWithLabelInterface {
@Override
public int getColor() {
if (eventType.equals(ANNOUNCEMENT))
return 0xFFFF8C00;
return MainApp.sResources.getColor(R.color.notificationAnnouncement);
if (eventType.equals(MBG))
return Color.RED;
if (eventType.equals(BGCHECK))

View file

@ -0,0 +1,33 @@
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.JSONObject;
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 BroadcastAlarm {
private static Logger log = LoggerFactory.getLogger(BroadcastAlarm.class);
public static void handleAlarm(JSONObject alarm, Context context) {
Bundle bundle = new Bundle();
bundle.putString("data", alarm.toString());
Intent intent = new Intent(Intents.ACTION_ALARM);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("ALARM " + 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.json.JSONObject;
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 BroadcastAnnouncement {
private static Logger log = LoggerFactory.getLogger(BroadcastAnnouncement.class);
public static void handleAnnouncement(JSONObject announcement, Context context) {
Bundle bundle = new Bundle();
bundle.putString("data", announcement.toString());
Intent intent = new Intent(Intents.ACTION_ANNOUNCEMENT);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("ANNOUNCEMENT " + x.size() + " receivers");
}
}

View file

@ -19,7 +19,7 @@ import info.nightscout.androidaps.Services.Intents;
public class BroadcastCals {
private static Logger log = LoggerFactory.getLogger(BroadcastCals.class);
public void handleNewCal(JSONArray cals, Context context, boolean isDelta) {
public static void handleNewCal(JSONArray cals, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("cals", cals.toString());
bundle.putBoolean("delta", isDelta);

View file

@ -0,0 +1,33 @@
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.JSONObject;
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 BroadcastClearAlarm {
private static Logger log = LoggerFactory.getLogger(BroadcastClearAlarm.class);
public static void handleClearAlarm(JSONObject clearalarm, Context context) {
Bundle bundle = new Bundle();
bundle.putString("data", clearalarm.toString());
Intent intent = new Intent(Intents.ACTION_CLEAR_ALARM);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("CLEARALARM " + x.size() + " receivers");
}
}

View file

@ -18,7 +18,7 @@ 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) {
public static void handleNewDeviceStatus(JSONObject status, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("devicestatus", status.toString());
bundle.putBoolean("delta", isDelta);
@ -30,7 +30,7 @@ public class BroadcastDeviceStatus {
log.debug("DEVICESTATUS " + x.size() + " receivers");
}
public void handleNewDeviceStatus(JSONArray statuses, Context context, boolean isDelta) {
public static void handleNewDeviceStatus(JSONArray statuses, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("devicestatuses", statuses.toString());
bundle.putBoolean("delta", isDelta);

View file

@ -19,7 +19,7 @@ import info.nightscout.androidaps.Services.Intents;
public class BroadcastMbgs {
private static Logger log = LoggerFactory.getLogger(BroadcastMbgs.class);
public void handleNewMbg(JSONArray mbgs, Context context, boolean isDelta) {
public static void handleNewMbg(JSONArray mbgs, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("mbgs", mbgs.toString());
bundle.putBoolean("delta", isDelta);

View file

@ -20,7 +20,7 @@ import info.nightscout.androidaps.data.ProfileStore;
public class BroadcastProfile {
private static Logger log = LoggerFactory.getLogger(BroadcastProfile.class);
public void handleNewTreatment(ProfileStore profile, Context context, boolean isDelta) {
public static void handleNewTreatment(ProfileStore profile, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("profile", profile.getData().toString());
bundle.putBoolean("delta", isDelta);

View file

@ -11,7 +11,7 @@ import info.nightscout.androidaps.Services.Intents;
* Created by mike on 28.02.2016.
*/
public class BroadcastQueueStatus {
public void handleNewStatus(int size, Context context) {
public static void handleNewStatus(int size, Context context) {
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"sendQueue");

View file

@ -20,7 +20,7 @@ import info.nightscout.androidaps.Services.Intents;
public class BroadcastSgvs {
private static Logger log = LoggerFactory.getLogger(BroadcastSgvs.class);
public void handleNewSgv(JSONObject sgv, Context context, boolean isDelta) {
public static void handleNewSgv(JSONObject sgv, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("sgv", sgv.toString());
bundle.putBoolean("delta", isDelta);
@ -33,7 +33,7 @@ public class BroadcastSgvs {
log.debug("SGV " + x.size() + " receivers");
}
public void handleNewSgv(JSONArray sgvs, Context context, boolean isDelta) {
public static void handleNewSgv(JSONArray sgvs, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("sgvs", sgvs.toString());
bundle.putBoolean("delta", isDelta);

View file

@ -22,7 +22,7 @@ import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientServ
public class BroadcastStatus {
private static Logger log = LoggerFactory.getLogger(BroadcastStatus.class);
public void handleNewStatus(NSStatus status, Context context, boolean isDelta) {
public static 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);

View file

@ -22,7 +22,7 @@ import info.nightscout.androidaps.plugins.NSClientInternal.data.NSTreatment;
public class BroadcastTreatment {
private static Logger log = LoggerFactory.getLogger(BroadcastTreatment.class);
public void handleNewTreatment(NSTreatment treatment, Context context, boolean isDelta) {
public static void handleNewTreatment(NSTreatment treatment, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("treatment", treatment.getData().toString());
bundle.putBoolean("delta", isDelta);
@ -35,7 +35,7 @@ public class BroadcastTreatment {
log.debug("TREAT_ADD " + treatment.getEventType() + " " + x.size() + " receivers");
}
public void handleNewTreatment(JSONArray treatments, Context context, boolean isDelta) {
public static void handleNewTreatment(JSONArray treatments, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("treatments", treatments.toString());
bundle.putBoolean("delta", isDelta);
@ -63,7 +63,7 @@ public class BroadcastTreatment {
} catch (JSONException e) {}
}
public void handleChangedTreatment(JSONArray treatments, Context context, boolean isDelta) {
public static void handleChangedTreatment(JSONArray treatments, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("treatments", treatments.toString());
bundle.putBoolean("delta", isDelta);
@ -76,7 +76,7 @@ public class BroadcastTreatment {
log.debug("TREAT_CHANGE " + treatments.length() + " " + x.size() + " receivers");
}
public void handleRemovedTreatment(JSONObject treatment, Context context, boolean isDelta) {
public static void handleRemovedTreatment(JSONObject treatment, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("treatment", treatment.toString());
bundle.putBoolean("delta", isDelta);
@ -91,7 +91,7 @@ public class BroadcastTreatment {
} catch (JSONException e) {}
}
public void handleRemovedTreatment(JSONArray treatments, Context context, boolean isDelta) {
public static void handleRemovedTreatment(JSONArray treatments, Context context, boolean isDelta) {
Bundle bundle = new Bundle();
bundle.putString("treatments", treatments.toString());
bundle.putBoolean("delta", isDelta);

View file

@ -0,0 +1,33 @@
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.JSONObject;
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 BroadcastUrgentAlarm {
private static Logger log = LoggerFactory.getLogger(BroadcastUrgentAlarm.class);
public static void handleUrgentAlarm(JSONObject urgentalarm, Context context) {
Bundle bundle = new Bundle();
bundle.putString("data", urgentalarm.toString());
Intent intent = new Intent(Intents.ACTION_URGENT_ALARM);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> x = context.getPackageManager().queryBroadcastReceivers(intent, 0);
log.debug("URGENTALARM " + x.size() + " receivers");
}
}

View file

@ -0,0 +1,11 @@
package info.nightscout.androidaps.plugins.NSClientInternal.data;
/**
* Created by mike on 11.06.2017.
*/
public class AlarmAck {
public Integer level = null;
public String group = null;
public Long silenceTime = null;
}

View file

@ -0,0 +1,64 @@
package info.nightscout.androidaps.plugins.NSClientInternal.data;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Created by mike on 11.06.2017.
*/
public class NSAlarm {
JSONObject data;
public NSAlarm(JSONObject data) {
this.data = data;
}
public int getLevel() {
int retval = 0;
if (data.has("level")) {
try {
retval = data.getInt("level");
} catch (JSONException e) {
e.printStackTrace();
}
}
return retval;
}
public String getGroup() {
String retval = "N/A";
if (data.has("group")) {
try {
retval = data.getString("group");
} catch (JSONException e) {
e.printStackTrace();
}
}
return retval;
}
public String getTile() {
String retval = "N/A";
if (data.has("title")) {
try {
retval = data.getString("title");
} catch (JSONException e) {
e.printStackTrace();
}
}
return retval;
}
public String getMessage() {
String retval = "N/A";
if (data.has("message")) {
try {
retval = data.getString("message");
} catch (JSONException e) {
e.printStackTrace();
}
}
return retval;
}
}

View file

@ -0,0 +1,64 @@
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.R;
import info.nightscout.androidaps.db.DbRequest;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
import info.nightscout.androidaps.plugins.NSClientInternal.data.AlarmAck;
import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
import info.nightscout.utils.SP;
public class AckAlarmReceiver extends BroadcastReceiver {
private static Logger log = LoggerFactory.getLogger(AckAlarmReceiver.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,
AckAlarmReceiver.class.getSimpleName());
NSClientInternalPlugin nsClientInternalPlugin = (NSClientInternalPlugin) MainApp.getSpecificPlugin(NSClientInternalPlugin.class);
if (!nsClientInternalPlugin.isEnabled(PluginBase.GENERAL)) {
return;
}
if (SP.getBoolean(R.string.key_ns_noupload, false)) {
log.debug("Upload disabled. Message dropped");
return;
}
wakeLock.acquire();
try {
Bundle bundles = intent.getExtras();
if (bundles == null) return;
if (!bundles.containsKey("level")) return;
if (!bundles.containsKey("group")) return;
if (!bundles.containsKey("silenceTime")) return;
AlarmAck ack = new AlarmAck();
ack.level = bundles.getInt("level");
ack.group = bundles.getString("group");
ack.silenceTime = bundles.getLong("silenceTime");
NSClientService nsClientService = nsClientInternalPlugin.nsClientService;
if (nsClientService != null)
nsClientService.sendAlarmAck(ack);
} finally {
wakeLock.release();
}
}
}

View file

@ -19,6 +19,8 @@ import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
import info.nightscout.androidaps.db.DbRequest;
import info.nightscout.androidaps.plugins.NSClientInternal.data.AlarmAck;
import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
import info.nightscout.utils.SP;
public class DBAccessReceiver extends BroadcastReceiver {
@ -29,7 +31,7 @@ public class DBAccessReceiver extends BroadcastReceiver {
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");
DBAccessReceiver.class.getSimpleName());
NSClientInternalPlugin nsClientInternalPlugin = (NSClientInternalPlugin) MainApp.getSpecificPlugin(NSClientInternalPlugin.class);
if (!nsClientInternalPlugin.isEnabled(PluginBase.GENERAL)) {
return;

View file

@ -38,14 +38,18 @@ 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.NSUpdateAck;
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastAlarm;
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastAnnouncement;
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastCals;
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastClearAlarm;
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.NSCal;
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastUrgentAlarm;
import info.nightscout.androidaps.plugins.NSClientInternal.data.AlarmAck;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSStatus;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSTreatment;
@ -201,6 +205,10 @@ public class NSClientService extends Service {
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "do connect"));
mSocket.connect();
mSocket.on("dataUpdate", onDataUpdate);
mSocket.on("announcement", onAnnouncement);
mSocket.on("alarm", onAlarm);
mSocket.on("urgent_alarm", onUrgentAlarm);
mSocket.on("clear_alarm", onClearAlarm);
} catch (URISyntaxException | RuntimeException e) {
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "Wrong URL syntax"));
MainApp.bus().post(new EventNSClientStatus("Wrong URL syntax"));
@ -297,6 +305,99 @@ public class NSClientService extends Service {
}
};
private Emitter.Listener onAnnouncement = new Emitter.Listener() {
/*
{
"level":0,
"title":"Announcement",
"message":"test",
"plugin":{"name":"treatmentnotify","label":"Treatment Notifications","pluginType":"notification","enabled":true},
"group":"Announcement",
"isAnnouncement":true,
"key":"9ac46ad9a1dcda79dd87dae418fce0e7955c68da"
}
*/
@Override
public void call(final Object... args) {
JSONObject data = (JSONObject) args[0];
if (Config.detailedLog)
try {
MainApp.bus().post(new EventNSClientNewLog("ANNOUNCEMENT", data.has("message") ? data.getString("message") : "received"));
} catch (JSONException e) {
e.printStackTrace();
}
BroadcastAnnouncement.handleAnnouncement(data, getApplicationContext());
log.debug(data.toString());
}
};
private Emitter.Listener onAlarm = new Emitter.Listener() {
/*
{
"level":1,
"title":"Warning HIGH",
"message":"BG Now: 5 -0.2 → mmol\/L\nRaw BG: 4.8 mmol\/L Čistý\nBG 15m: 4.8 mmol\/L\nIOB: -0.02U\nCOB: 0g",
"eventName":"high",
"plugin":{"name":"simplealarms","label":"Simple Alarms","pluginType":"notification","enabled":true},
"pushoverSound":"climb",
"debug":{"lastSGV":5,"thresholds":{"bgHigh":180,"bgTargetTop":75,"bgTargetBottom":72,"bgLow":70}},
"group":"default",
"key":"simplealarms_1"
}
*/
@Override
public void call(final Object... args) {
if (Config.detailedLog)
MainApp.bus().post(new EventNSClientNewLog("ALARM", "received"));
JSONObject data = (JSONObject) args[0];
BroadcastAlarm.handleAlarm(data, getApplicationContext());
log.debug(data.toString());
}
};
private Emitter.Listener onUrgentAlarm = new Emitter.Listener() {
/*
{
"level":2,
"title":"Urgent HIGH",
"message":"BG Now: 5.2 -0.1 → mmol\/L\nRaw BG: 5 mmol\/L Čistý\nBG 15m: 5 mmol\/L\nIOB: 0.00U\nCOB: 0g",
"eventName":"high",
"plugin":{"name":"simplealarms","label":"Simple Alarms","pluginType":"notification","enabled":true},
"pushoverSound":"persistent",
"debug":{"lastSGV":5.2,"thresholds":{"bgHigh":80,"bgTargetTop":75,"bgTargetBottom":72,"bgLow":70}},
"group":"default",
"key":"simplealarms_2"
}
*/
@Override
public void call(final Object... args) {
JSONObject data = (JSONObject) args[0];
if (Config.detailedLog)
MainApp.bus().post(new EventNSClientNewLog("URGENTALARM", "received"));
BroadcastUrgentAlarm.handleUrgentAlarm(data, getApplicationContext());
log.debug(data.toString());
}
};
private Emitter.Listener onClearAlarm = new Emitter.Listener() {
/*
{
"clear":true,
"title":"All Clear",
"message":"default - Urgent was ack'd",
"group":"default"
}
*/
@Override
public void call(final Object... args) {
if (Config.detailedLog)
MainApp.bus().post(new EventNSClientNewLog("CLEARALARM", "received"));
JSONObject data = (JSONObject) args[0];
BroadcastClearAlarm.handleClearAlarm(data, getApplicationContext());
log.debug(data.toString());
}
};
private Emitter.Listener onDataUpdate = new Emitter.Listener() {
@Override
public void call(final Object... args) {
@ -339,9 +440,7 @@ public class NSClientService extends Service {
nightscoutVersionName = status.getString("version");
nightscoutVersionCode = status.getInt("versionNum");
}
BroadcastStatus bs = new BroadcastStatus();
bs.handleNewStatus(nsStatus, MainApp.instance().getApplicationContext(), isDelta);
BroadcastStatus.handleNewStatus(nsStatus, MainApp.instance().getApplicationContext(), isDelta);
/* Other received data to 2016/02/10
{
@ -365,17 +464,15 @@ public class NSClientService extends Service {
// If new profile received or change detected broadcast it
if (broadcastProfile && profileStore != null) {
BroadcastProfile bp = new BroadcastProfile();
bp.handleNewTreatment(profileStore, MainApp.instance().getApplicationContext(), isDelta);
BroadcastProfile.handleNewTreatment(profileStore, MainApp.instance().getApplicationContext(), isDelta);
MainApp.bus().post(new EventNSClientNewLog("PROFILE", "broadcasting"));
}
if (data.has("treatments")) {
JSONArray treatments = (JSONArray) data.getJSONArray("treatments");
JSONArray treatments = 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++) {
@ -399,18 +496,17 @@ public class NSClientService extends Service {
}
}
if (removedTreatments.length() > 0) {
bt.handleRemovedTreatment(removedTreatments, MainApp.instance().getApplicationContext(), isDelta);
BroadcastTreatment.handleRemovedTreatment(removedTreatments, MainApp.instance().getApplicationContext(), isDelta);
}
if (updatedTreatments.length() > 0) {
bt.handleChangedTreatment(updatedTreatments, MainApp.instance().getApplicationContext(), isDelta);
BroadcastTreatment.handleChangedTreatment(updatedTreatments, MainApp.instance().getApplicationContext(), isDelta);
}
if (addedTreatments.length() > 0) {
bt.handleNewTreatment(addedTreatments, MainApp.instance().getApplicationContext(), isDelta);
BroadcastTreatment.handleNewTreatment(addedTreatments, MainApp.instance().getApplicationContext(), isDelta);
}
}
if (data.has("devicestatus")) {
BroadcastDeviceStatus bds = new BroadcastDeviceStatus();
JSONArray devicestatuses = (JSONArray) data.getJSONArray("devicestatus");
JSONArray devicestatuses = 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++) {
@ -419,12 +515,11 @@ public class NSClientService extends Service {
UploadQueue.removeID(jsonStatus);
}
// send only last record
bds.handleNewDeviceStatus(devicestatuses.getJSONObject(devicestatuses.length() - 1), MainApp.instance().getApplicationContext(), isDelta);
BroadcastDeviceStatus.handleNewDeviceStatus(devicestatuses.getJSONObject(devicestatuses.length() - 1), MainApp.instance().getApplicationContext(), isDelta);
}
}
if (data.has("mbgs")) {
BroadcastMbgs bmbg = new BroadcastMbgs();
JSONArray mbgs = (JSONArray) data.getJSONArray("mbgs");
JSONArray mbgs = 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++) {
@ -432,11 +527,10 @@ public class NSClientService extends Service {
// remove from upload queue if Ack is failing
UploadQueue.removeID(jsonMbg);
}
bmbg.handleNewMbg(mbgs, MainApp.instance().getApplicationContext(), isDelta);
BroadcastMbgs.handleNewMbg(mbgs, MainApp.instance().getApplicationContext(), isDelta);
}
if (data.has("cals")) {
BroadcastCals bc = new BroadcastCals();
JSONArray cals = (JSONArray) data.getJSONArray("cals");
JSONArray cals = data.getJSONArray("cals");
if (cals.length() > 0)
MainApp.bus().post(new EventNSClientNewLog("DATA", "received " + cals.length() + " cals"));
// Retreive actual calibration
@ -444,11 +538,10 @@ public class NSClientService extends Service {
// remove from upload queue if Ack is failing
UploadQueue.removeID(cals.optJSONObject(index));
}
bc.handleNewCal(cals, MainApp.instance().getApplicationContext(), isDelta);
BroadcastCals.handleNewCal(cals, MainApp.instance().getApplicationContext(), isDelta);
}
if (data.has("sgvs")) {
BroadcastSgvs bs = new BroadcastSgvs();
JSONArray sgvs = (JSONArray) data.getJSONArray("sgvs");
JSONArray sgvs = 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++) {
@ -463,7 +556,7 @@ public class NSClientService extends Service {
if (sgv.getMills() > latestDateInReceivedData)
latestDateInReceivedData = sgv.getMills();
}
bs.handleNewSgv(sgvs, MainApp.instance().getApplicationContext(), isDelta);
BroadcastSgvs.handleNewSgv(sgvs, MainApp.instance().getApplicationContext(), isDelta);
}
MainApp.bus().post(new EventNSClientNewLog("LAST", DateUtil.dateAndTimeString(latestDateInReceivedData)));
} catch (JSONException e) {
@ -543,6 +636,12 @@ public class NSClientService extends Service {
}
}
public void sendAlarmAck(AlarmAck alarmAck) {
if (!isConnected || !hasWriteAuth) return;
mSocket.emit("ack", alarmAck.level, alarmAck.group, alarmAck.silenceTime);
MainApp.bus().post(new EventNSClientNewLog("ALARMACK ", alarmAck.level + " " + alarmAck.group + " " + alarmAck.silenceTime));
}
@Subscribe
public void onStatusEvent(NSAddAck ack) {
if (ack.nsClientID != null) {

View file

@ -2,6 +2,8 @@ package info.nightscout.androidaps.plugins.Overview;
import java.util.Date;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSAlarm;
/**
* Created by mike on 03.12.2016.
*/
@ -11,6 +13,7 @@ public class Notification {
public static final int NORMAL = 1;
public static final int LOW = 2;
public static final int INFO = 3;
public static final int ANNOUNCEMENT = 4;
public static final int PROFILE_SET_FAILED = 0;
public static final int PROFILE_SET_OK = 1;
@ -29,7 +32,9 @@ public class Notification {
public static final int IC_MISSING = 14;
public static final int BASAL_MISSING = 15;
public static final int TARGET_MISSING = 16;
public static final int ANNOUNCEMENT = 17;
public static final int NSANNOUNCEMENT = 17;
public static final int NSALARM = 18;
public static final int NSURGENTALARM = 18;
public int id;
public Date date;
@ -37,6 +42,8 @@ public class Notification {
public int level;
public Date validTo = new Date(0);
public NSAlarm nsAlarm = null;
public Notification() {
}
@ -63,4 +70,28 @@ public class Notification {
this.level = level;
this.validTo = new Date(0);
}
public Notification(NSAlarm nsAlarm) {
this.date = new Date();
this.validTo = new Date(0);
this.nsAlarm = nsAlarm;
switch (nsAlarm.getLevel()) {
case 0:
this.id = NSANNOUNCEMENT;
this.level = ANNOUNCEMENT;
this.text = nsAlarm.getMessage();
this.validTo = new Date(new Date().getTime() + 60 * 60 * 1000L);
break;
case 1:
this.id = NSALARM;
this.level = NORMAL;
this.text = nsAlarm.getTile();
break;
case 2:
this.id = NSURGENTALARM;
this.level = URGENT;
this.text = nsAlarm.getTile();
break;
}
}
}

View file

@ -64,6 +64,7 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.broadcasts.NSClearAlarmBroadcast;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.GlucoseStatus;
import info.nightscout.androidaps.data.IobTotal;
@ -1631,6 +1632,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
holder.cv.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.notificationLow));
else if (notification.level == Notification.INFO)
holder.cv.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.notificationInfo));
else if (notification.level == Notification.ANNOUNCEMENT)
holder.cv.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.notificationAnnouncement));
}
@Override
@ -1664,6 +1667,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
switch (v.getId()) {
case R.id.notification_dismiss:
MainApp.bus().post(new EventDismissNotification(notification.id));
if (notification.nsAlarm != null) {
NSClearAlarmBroadcast.handleClearAlarm(notification.nsAlarm, MainApp.instance().getApplicationContext(), 60 * 60 * 1000L);
}
break;
}
}

View file

@ -265,7 +265,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
int basalIncrement = pump.basal48Enable ? 30 * 60 : 60 * 60;
for (int h = 0; h < basalValues; h++) {
Double pumpValue = pump.pumpProfiles[pump.activeProfile][h];
Double profileValue = profile.getBasal(h * basalIncrement);
Double profileValue = profile.getBasal((Integer) (h * basalIncrement));
if (profileValue == null) return true;
if (Math.abs(pumpValue - profileValue) > getPumpDescription().basalStep) {
log.debug("Diff found. Hour: " + h + " Pump: " + pumpValue + " Profile: " + profileValue);

View file

@ -74,7 +74,7 @@ public class DanaRNSHistorySync {
nsrec.put("eventType", "Meal Bolus");
nsrec.put("insulin", record.recordValue);
nsrec.put("created_at", DateUtil.toISOString(record.recordDate));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
nsrec.put("enteredBy", "openaps://" + MainApp.sResources.getString(R.string.app_name));
NSUpload.uploadCareportalEntryToNS(nsrec);
uploaded++;
ev.message += MainApp.sResources.getString(R.string.danar_sbolus);
@ -92,7 +92,7 @@ public class DanaRNSHistorySync {
cal.setTimeInMillis(record.recordDate);
cal.add(Calendar.MINUTE, -1 * record.recordDuration);
nsrec.put("created_at", DateUtil.toISOString(cal.getTime()));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
nsrec.put("enteredBy", "openaps://" + MainApp.sResources.getString(R.string.app_name));
NSUpload.uploadCareportalEntryToNS(nsrec);
uploaded++;
ev.message += MainApp.sResources.getString(R.string.danar_ebolus);
@ -108,7 +108,7 @@ public class DanaRNSHistorySync {
nsrec.put("splitNow", 100);
nsrec.put("splitExt", 0);
nsrec.put("created_at", DateUtil.toISOString(record.recordDate));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
nsrec.put("enteredBy", "openaps://" + MainApp.sResources.getString(R.string.app_name));
NSUpload.uploadCareportalEntryToNS(nsrec);
uploaded++;
ev.message += MainApp.sResources.getString(R.string.danar_dsbolus);
@ -124,7 +124,7 @@ public class DanaRNSHistorySync {
cal.setTimeInMillis(record.recordDate);
cal.add(Calendar.MINUTE, -1 * record.recordDuration);
nsrec.put("created_at", DateUtil.toISOString(cal.getTime()));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
nsrec.put("enteredBy", "openaps://" + MainApp.sResources.getString(R.string.app_name));
NSUpload.uploadCareportalEntryToNS(nsrec);
uploaded++;
ev.message += MainApp.sResources.getString(R.string.danar_debolus);
@ -141,7 +141,7 @@ public class DanaRNSHistorySync {
nsrec.put("eventType", "Note");
nsrec.put("notes", "Error");
nsrec.put("created_at", DateUtil.toISOString(record.recordDate));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
nsrec.put("enteredBy", "openaps://" + MainApp.sResources.getString(R.string.app_name));
NSUpload.uploadCareportalEntryToNS(nsrec);
uploaded++;
ev.message += MainApp.sResources.getString(R.string.danar_error);
@ -153,7 +153,7 @@ public class DanaRNSHistorySync {
nsrec.put("eventType", "Insulin Change");
nsrec.put("notes", "Refill " + record.recordValue + "U");
nsrec.put("created_at", DateUtil.toISOString(record.recordDate));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
nsrec.put("enteredBy", "openaps://" + MainApp.sResources.getString(R.string.app_name));
NSUpload.uploadCareportalEntryToNS(nsrec);
uploaded++;
ev.message += MainApp.sResources.getString(R.string.danar_refill);
@ -166,7 +166,7 @@ public class DanaRNSHistorySync {
nsrec.put("absolute", record.recordValue);
nsrec.put("duration", 60);
nsrec.put("created_at", DateUtil.toISOString(record.recordDate));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
nsrec.put("enteredBy", "openaps://" + MainApp.sResources.getString(R.string.app_name));
NSUpload.uploadCareportalEntryToNS(nsrec);
uploaded++;
ev.message += MainApp.sResources.getString(R.string.danar_basalhour);
@ -182,7 +182,7 @@ public class DanaRNSHistorySync {
nsrec.put("glucose", Profile.fromMgdlToUnits(record.recordValue, profile.getUnits()));
nsrec.put("glucoseType", "Finger");
nsrec.put("created_at", DateUtil.toISOString(record.recordDate));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
nsrec.put("enteredBy", "openaps://" + MainApp.sResources.getString(R.string.app_name));
NSUpload.uploadCareportalEntryToNS(nsrec);
uploaded++;
ev.message += MainApp.sResources.getString(R.string.danar_glucose);
@ -194,7 +194,7 @@ public class DanaRNSHistorySync {
nsrec.put("eventType", "Meal Bolus");
nsrec.put("carbs", record.recordValue);
nsrec.put("created_at", DateUtil.toISOString(record.recordDate));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
nsrec.put("enteredBy", "openaps://" + MainApp.sResources.getString(R.string.app_name));
NSUpload.uploadCareportalEntryToNS(nsrec);
uploaded++;
ev.message += MainApp.sResources.getString(R.string.danar_carbohydrate);
@ -206,7 +206,7 @@ public class DanaRNSHistorySync {
nsrec.put("eventType", "Note");
nsrec.put("notes", "Alarm: " + record.recordAlarm);
nsrec.put("created_at", DateUtil.toISOString(record.recordDate));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
nsrec.put("enteredBy", "openaps://" + MainApp.sResources.getString(R.string.app_name));
NSUpload.uploadCareportalEntryToNS(nsrec);
uploaded++;
ev.message += MainApp.sResources.getString(R.string.danar_alarm);

View file

@ -531,7 +531,7 @@ public class DanaRExecutionService extends Service {
for (Integer hour = 0; hour < 24; hour++) {
//Some values get truncated to the next lower one.
// -> round them to two decimals and make sure we are a small delta larger (that will get truncated)
double value = Math.round(100d * nsProfile.getBasal(hour * 60 * 60))/100d + 0.00001;
double value = Math.round(100d * nsProfile.getBasal((Integer) (hour * 60 * 60)))/100d + 0.00001;
if (Config.logDanaMessageDetail)
log.debug("NS basal value for " + hour + ":00 is " + value);
record[hour] = value;

View file

@ -268,7 +268,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
int basalIncrement = pump.basal48Enable ? 30 * 60 : 60 * 60;
for (int h = 0; h < basalValues; h++) {
Double pumpValue = pump.pumpProfiles[pump.activeProfile][h];
Double profileValue = profile.getBasal(h * basalIncrement);
Double profileValue = profile.getBasal((Integer) (h * basalIncrement));
if (profileValue == null) return true;
if (Math.abs(pumpValue - profileValue) > getPumpDescription().basalStep) {
log.debug("Diff found. Hour: " + h + " Pump: " + pumpValue + " Profile: " + profileValue);

View file

@ -504,7 +504,7 @@ public class DanaRKoreanExecutionService extends Service {
private double[] buildDanaRProfileRecord(Profile nsProfile) {
double[] record = new double[24];
for (Integer hour = 0; hour < 24; hour++) {
double value = Math.round(100d * nsProfile.getBasal(hour * 60 * 60))/100d + 0.00001;
double value = Math.round(100d * nsProfile.getBasal((Integer) (hour * 60 * 60)))/100d + 0.00001;
if (Config.logDanaMessageDetail)
log.debug("NS basal value for " + hour + ":00 is " + value);
record[hour] = value;

View file

@ -253,7 +253,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
int basalIncrement = pump.basal48Enable ? 30 * 60 : 60 * 60;
for (int h = 0; h < basalValues; h++) {
Double pumpValue = pump.pumpProfiles[pump.activeProfile][h];
Double profileValue = profile.getBasal(h * basalIncrement);
Double profileValue = profile.getBasal((Integer) (h * basalIncrement));
if (profileValue == null) return true;
if (Math.abs(pumpValue - profileValue) > getPumpDescription().basalStep) {
log.debug("Diff found. Hour: " + h + " Pump: " + pumpValue + " Profile: " + profileValue);

View file

@ -537,7 +537,7 @@ public class DanaRv2ExecutionService extends Service {
private double[] buildDanaRProfileRecord(Profile nsProfile) {
double[] record = new double[24];
for (Integer hour = 0; hour < 24; hour++) {
double value = Math.round(100d * nsProfile.getBasal(hour * 60 * 60))/100d + 0.00001;
double value = Math.round(100d * nsProfile.getBasal((Integer) (hour * 60 * 60)))/100d + 0.00001;
if (Config.logDanaMessageDetail)
log.debug("NS basal value for " + hour + ":00 is " + value);
record[hour] = value;

View file

@ -0,0 +1,47 @@
package info.nightscout.androidaps.receivers;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import org.json.JSONException;
import org.json.JSONObject;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSAlarm;
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
public class NSAlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent == null)
return;
Bundle bundle = intent.getExtras();
String data = bundle.getString("data");
JSONObject json = null;
try {
json = new JSONObject(data);
} catch (JSONException e) {
e.printStackTrace();
return;
}
NSAlarm nsAlarm = new NSAlarm(json);
switch (intent.getAction()) {
case Intents.ACTION_ANNOUNCEMENT:
case Intents.ACTION_ALARM:
case Intents.ACTION_URGENT_ALARM:
Notification notification = new Notification(nsAlarm);
MainApp.bus().post(new EventNewNotification(notification));
break;
case Intents.ACTION_CLEAR_ALARM:
MainApp.bus().post(new EventDismissNotification(Notification.NSALARM));
MainApp.bus().post(new EventDismissNotification(Notification.NSURGENTALARM));
break;
}
}
}

View file

@ -99,7 +99,7 @@ public class BolusWizard {
insulinFromSuperBolus = specificProfile.getBasal();
long timeAfter1h = new Date().getTime();
timeAfter1h += 60L * 60 * 1000;
insulinFromSuperBolus += specificProfile.getBasal(Profile.secondsFromMidnight(new Date(timeAfter1h)));
insulinFromSuperBolus += specificProfile.getBasal(timeAfter1h);
}
// Total

View file

@ -47,7 +47,7 @@ public class NSUpload {
if (temporaryBasal.pumpId != 0)
data.put("pumpId", temporaryBasal.pumpId);
data.put("created_at", DateUtil.toISOString(temporaryBasal.date));
data.put("enteredBy", MainApp.instance().getString(R.string.app_name));
data.put("enteredBy", "openaps://" + MainApp.instance().getString(R.string.app_name));
data.put("notes", MainApp.sResources.getString(R.string.androidaps_tempbasalstartnote) + " " + temporaryBasal.absoluteRate + "u/h " + temporaryBasal.durationInMinutes + " min"); // ECOR
if (originalExtendedAmount != null)
data.put("originalExtendedAmount", originalExtendedAmount); // for back synchronization
@ -86,7 +86,7 @@ public class NSUpload {
if (temporaryBasal.pumpId != 0)
data.put("pumpId", temporaryBasal.pumpId);
data.put("created_at", DateUtil.toISOString(temporaryBasal.date));
data.put("enteredBy", MainApp.instance().getString(R.string.app_name));
data.put("enteredBy", "openaps://" + MainApp.instance().getString(R.string.app_name));
data.put("notes", MainApp.sResources.getString(R.string.androidaps_tempbasalstartnote) + " " + temporaryBasal.percentRate + "% " + temporaryBasal.durationInMinutes + " min"); // ECOR
Bundle bundle = new Bundle();
bundle.putString("action", "dbAdd");
@ -109,7 +109,7 @@ public class NSUpload {
JSONObject data = new JSONObject();
data.put("eventType", CareportalEvent.TEMPBASAL);
data.put("created_at", DateUtil.toISOString(time));
data.put("enteredBy", MainApp.instance().getString(R.string.app_name));
data.put("enteredBy", "openaps://" + MainApp.instance().getString(R.string.app_name));
data.put("notes", MainApp.sResources.getString(R.string.androidaps_tempbasalendnote)); // ECOR
if (isFakedTempBasal)
data.put("isFakedTempBasal", isFakedTempBasal);
@ -142,7 +142,7 @@ public class NSUpload {
if (extendedBolus.pumpId != 0)
data.put("pumpId", extendedBolus.pumpId);
data.put("created_at", DateUtil.toISOString(extendedBolus.date));
data.put("enteredBy", MainApp.instance().getString(R.string.app_name));
data.put("enteredBy", "openaps://" + MainApp.instance().getString(R.string.app_name));
Bundle bundle = new Bundle();
bundle.putString("action", "dbAdd");
bundle.putString("collection", "treatments");
@ -168,7 +168,7 @@ public class NSUpload {
data.put("enteredinsulin", 0);
data.put("relative", 0);
data.put("created_at", DateUtil.toISOString(time));
data.put("enteredBy", MainApp.instance().getString(R.string.app_name));
data.put("enteredBy", "openaps://" + MainApp.instance().getString(R.string.app_name));
if (pumpId != 0)
data.put("pumpId", pumpId);
Bundle bundle = new Bundle();
@ -346,7 +346,7 @@ public class NSUpload {
data.put("eventType", "OpenAPS Offline");
data.put("duration", durationInMinutes);
data.put("created_at", DateUtil.toISOString(new Date()));
data.put("enteredBy", MainApp.instance().getString(R.string.app_name));
data.put("enteredBy", "openaps://" + MainApp.instance().getString(R.string.app_name));
Bundle bundle = new Bundle();
bundle.putString("action", "dbAdd");
bundle.putString("collection", "treatments");

Binary file not shown.

Binary file not shown.

View file

@ -55,6 +55,7 @@
<color name="loopdisabled">#FFDD7792</color>
<color name="looppumpsuspended">#ff0400</color>
<color name="notificationAnnouncement">#FF8C00</color>
<color name="notificationUrgent">#ff0400</color>
<color name="notificationNormal">#ff5e55</color>
<color name="notificationLow">#ff827c</color>