Clean up statusSumary, command result and pump status.

This commit is contained in:
Johannes Mockenhaupt 2017-07-19 01:51:20 +02:00
parent 485b99e260
commit 7b16716b65
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
2 changed files with 20 additions and 24 deletions

View file

@ -113,13 +113,11 @@ public class ComboFragment extends Fragment implements View.OnClickListener {
tbrDurationText.setText(""); tbrDurationText.setText("");
tbrRateText.setText("" + getPlugin().getBaseBasalRate() + " U/h"); tbrRateText.setText("" + getPlugin().getBaseBasalRate() + " U/h");
} }
Command lastCmd = getPlugin().lastCmd; if (getPlugin().lastCmd != null) {
if (lastCmd != null) { lastCmdText.setText("" + getPlugin().lastCmd);
lastCmdText.setText("" + lastCmd);
lastCmdTimeText.setText(getPlugin().lastCmdTime.toLocaleString()); lastCmdTimeText.setText(getPlugin().lastCmdTime.toLocaleString());
CommandResult lastCmdResult = getPlugin().lastCmdResult; if (getPlugin().lastCmdResult != null) {
if (lastCmdResult != null) { String message = getPlugin().lastCmdResult.message;
String message = lastCmdResult.message;
if (ps.errorMsg != null) { if (ps.errorMsg != null) {
message = message + "\nPump is in error state:\n" + ps.errorMsg; message = message + "\nPump is in error state:\n" + ps.errorMsg;
} }

View file

@ -63,17 +63,17 @@ public class ComboPlugin implements PluginBase, PumpInterface {
private RuffyScripter ruffyScripter; private RuffyScripter ruffyScripter;
private ServiceConnection mRuffyServiceConnection; private ServiceConnection mRuffyServiceConnection;
// TODO is volatile really needed here? // package-protected only so ComboFragment can access these
@NonNull @NonNull
volatile String statusSummary = "Initializing"; String statusSummary = "Initializing";
@Nullable @Nullable
volatile Command lastCmd; Command lastCmd;
@Nullable @Nullable
volatile CommandResult lastCmdResult; CommandResult lastCmdResult;
@NonNull @NonNull
volatile Date lastCmdTime = new Date(0); Date lastCmdTime = new Date(0);
@NonNull @NonNull
volatile PumpState pumpState = new PumpState(); PumpState pumpState = new PumpState();
private static PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult(); private static PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult();
@ -125,23 +125,23 @@ public class ComboPlugin implements PluginBase, PumpInterface {
int id = 1000; int id = 1000;
long lastAlarmTime = 0; long lastAlarmTime = 0;
while (true) { while (true) {
PumpState ps = ComboPlugin.this.pumpState; if (lastCmdResult != null && !lastCmdResult.success) {
String errorMsg = ps.errorMsg;
if (errorMsg != null) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
long fiveMinutesSinceLastAlarm = lastAlarmTime + (5 * 60 * 1000) + (15 * 1000); long fiveMinutesSinceLastAlarm = lastAlarmTime + (5 * 60 * 1000) + (15 * 1000);
if (now > fiveMinutesSinceLastAlarm) { if (now > fiveMinutesSinceLastAlarm) {
log.warn("Pump is in error state, raising alert: " + errorMsg); log.error("Command failed: " + lastCmd);
log.warn(" LastCmd: " + lastCmd); log.error("Command result: " + lastCmdResult);
log.warn(" LastCmdTime: " + lastCmdTime); if (pumpState.errorMsg != null) {
long[] vibratePattern = new long[]{1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000}; log.warn("Pump is in error state, displayng; " + pumpState.errorMsg);
}
long[] vibratePattern = new long[]{1000, 1000, 1000, 1000, 1000};
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
NotificationCompat.Builder notificationBuilder = NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(context) new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.notif_icon) .setSmallIcon(R.drawable.notif_icon)
.setSmallIcon(R.drawable.icon_bolus) .setSmallIcon(R.drawable.icon_bolus)
.setContentTitle("Combo communication error") .setContentTitle("Combo communication error")
.setContentText(errorMsg) .setContentText(lastCmdResult.message)
.setPriority(NotificationCompat.PRIORITY_MAX) .setPriority(NotificationCompat.PRIORITY_MAX)
.setLights(Color.BLUE, 1000, 0) .setLights(Color.BLUE, 1000, 0)
.setSound(uri) .setSound(uri)
@ -149,10 +149,8 @@ public class ComboPlugin implements PluginBase, PumpInterface {
mgr.notify(id, notificationBuilder.build()); mgr.notify(id, notificationBuilder.build());
lastAlarmTime = now; lastAlarmTime = now;
} else { } else {
log.warn("Pump still in error state, but alarm raised recently, so not triggering again: " + errorMsg); log.warn("Pump still in error state, but alarm raised recently, so not triggering again: " + lastCmdResult.message);
} }
} else {
log.trace("Pump state: " + (ps.suspended ? "suspended" : "normal"));
} }
SystemClock.sleep(5 * 1000); SystemClock.sleep(5 * 1000);
} }
@ -195,7 +193,7 @@ public class ComboPlugin implements PluginBase, PumpInterface {
// AAPS will still crash since it continues trying to access the pump, even when isInitalized // AAPS will still crash since it continues trying to access the pump, even when isInitalized
// returns false and isBusy returns true; this will however not crash the alerter // returns false and isBusy returns true; this will however not crash the alerter
// which will raise an exception. Not really ideal. // which will raise an exception. Not really ideal.
pumpState.errorMsg = "Failed to bind to ruffy service"; statusSummary = "Failed to bind to ruffy service";
} }
} }