Improve alerter.

This commit is contained in:
Johannes Mockenhaupt 2017-07-16 19:16:40 +02:00
parent c131280e91
commit ecf3866b43
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -108,7 +108,6 @@ public class ComboPlugin implements PluginBase, PumpInterface {
@Override @Override
public void run() { public void run() {
log.debug("Querying pump for initial state"); log.debug("Querying pump for initial state");
runCommand(new ReadPumpStateCommand());
} }
}).start(); }).start();
} }
@ -134,27 +133,30 @@ public class ComboPlugin implements PluginBase, PumpInterface {
while (true) { while (true) {
String errorMsg = pumpState.errorMsg; String errorMsg = pumpState.errorMsg;
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
long sixMinutesSinceLastAlarm = lastAlarmTime + 6 * 60 * 1000; long sixMinutesSinceLastAlarm = lastAlarmTime + (5 * 60 * 1000) + (15 * 1000);
if (errorMsg != null && now > sixMinutesSinceLastAlarm) { if (errorMsg != null)
log.warn("Pump is in error state, raising alert: " + errorMsg); if (now > sixMinutesSinceLastAlarm) {
long[] vibratePattern = new long[]{1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000}; log.warn("Pump is in error state, raising alert: " + errorMsg);
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); long[] vibratePattern = new long[]{1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000};
NotificationCompat.Builder notificationBuilder = Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
new NotificationCompat.Builder(context) NotificationCompat.Builder notificationBuilder =
.setSmallIcon(R.drawable.notif_icon) new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.icon_bolus) .setSmallIcon(R.drawable.notif_icon)
.setContentTitle("Combo communication error") .setSmallIcon(R.drawable.icon_bolus)
.setContentText(errorMsg) .setContentTitle("Combo communication error")
.setPriority(NotificationCompat.PRIORITY_MAX) .setContentText(errorMsg)
.setLights(Color.BLUE, 1000, 0) .setPriority(NotificationCompat.PRIORITY_MAX)
.setSound(uri) .setLights(Color.BLUE, 1000, 0)
.setVibrate(vibratePattern); .setSound(uri)
mgr.notify(id, notificationBuilder.build()); .setVibrate(vibratePattern);
lastAlarmTime = now; mgr.notify(id, notificationBuilder.build());
lastAlarmTime = now;
} else {
log.warn("Pump still in error state, but alarm raised recently, so not triggering again: " + errorMsg);
} else { } else {
log.debug("Pump state normal"); log.debug("Pump state normal");
} }
SystemClock.sleep(15_000); SystemClock.sleep(60 * 1000);
} }
} }
}, "combo-alerter").start(); }, "combo-alerter").start();
@ -288,8 +290,7 @@ public class ComboPlugin implements PluginBase, PumpInterface {
// this is called regulary from keepalive // this is called regulary from keepalive
// TODO how often is this called? use this to run checks regularly, e.g. runCommand(new ReadPumpStateCommand());
// recheck active TBR, basal rate to ensure nothing broke?
} }
// TODO uses profile values for the time being // TODO uses profile values for the time being
@ -347,12 +348,6 @@ public class ComboPlugin implements PluginBase, PumpInterface {
} }
} }
// TODO if there was some clue as to what refreshDataFromPump would do with the data ...
// that method calls NSUpload.uploadDeviceStatus(); in VirtualPump ...
void fetchPumpState() {
runCommand(new ReadPumpStateCommand());
}
private CommandResult runCommand(Command command) { private CommandResult runCommand(Command command) {
statusSummary = "Busy running command: " + command; statusSummary = "Busy running command: " + command;
MainApp.bus().post(new EventComboPumpUpdateGUI()); MainApp.bus().post(new EventComboPumpUpdateGUI());
@ -369,6 +364,9 @@ public class ComboPlugin implements PluginBase, PumpInterface {
pumpState.errorMsg = commandResult.message != null pumpState.errorMsg = commandResult.message != null
? commandResult.message ? commandResult.message
: "Unknown error"; : "Unknown error";
if (commandResult.exception != null) {
log.error("Exception received from pump", commandResult.exception);
}
} }
MainApp.bus().post(new EventComboPumpUpdateGUI()); MainApp.bus().post(new EventComboPumpUpdateGUI());
return commandResult; return commandResult;