Improve alerter.
This commit is contained in:
parent
c131280e91
commit
ecf3866b43
1 changed files with 25 additions and 27 deletions
|
@ -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,8 +133,9 @@ 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)
|
||||||
|
if (now > sixMinutesSinceLastAlarm) {
|
||||||
log.warn("Pump is in error state, raising alert: " + errorMsg);
|
log.warn("Pump is in error state, raising alert: " + errorMsg);
|
||||||
long[] vibratePattern = new long[]{1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000};
|
long[] vibratePattern = new long[]{1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000};
|
||||||
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
|
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
|
||||||
|
@ -151,10 +151,12 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
.setVibrate(vibratePattern);
|
.setVibrate(vibratePattern);
|
||||||
mgr.notify(id, notificationBuilder.build());
|
mgr.notify(id, notificationBuilder.build());
|
||||||
lastAlarmTime = now;
|
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;
|
||||||
|
|
Loading…
Reference in a new issue