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("");
tbrRateText.setText("" + getPlugin().getBaseBasalRate() + " U/h");
}
Command lastCmd = getPlugin().lastCmd;
if (lastCmd != null) {
lastCmdText.setText("" + lastCmd);
if (getPlugin().lastCmd != null) {
lastCmdText.setText("" + getPlugin().lastCmd);
lastCmdTimeText.setText(getPlugin().lastCmdTime.toLocaleString());
CommandResult lastCmdResult = getPlugin().lastCmdResult;
if (lastCmdResult != null) {
String message = lastCmdResult.message;
if (getPlugin().lastCmdResult != null) {
String message = getPlugin().lastCmdResult.message;
if (ps.errorMsg != null) {
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 ServiceConnection mRuffyServiceConnection;
// TODO is volatile really needed here?
// package-protected only so ComboFragment can access these
@NonNull
volatile String statusSummary = "Initializing";
String statusSummary = "Initializing";
@Nullable
volatile Command lastCmd;
Command lastCmd;
@Nullable
volatile CommandResult lastCmdResult;
CommandResult lastCmdResult;
@NonNull
volatile Date lastCmdTime = new Date(0);
Date lastCmdTime = new Date(0);
@NonNull
volatile PumpState pumpState = new PumpState();
PumpState pumpState = new PumpState();
private static PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult();
@ -125,23 +125,23 @@ public class ComboPlugin implements PluginBase, PumpInterface {
int id = 1000;
long lastAlarmTime = 0;
while (true) {
PumpState ps = ComboPlugin.this.pumpState;
String errorMsg = ps.errorMsg;
if (errorMsg != null) {
if (lastCmdResult != null && !lastCmdResult.success) {
long now = System.currentTimeMillis();
long fiveMinutesSinceLastAlarm = lastAlarmTime + (5 * 60 * 1000) + (15 * 1000);
if (now > fiveMinutesSinceLastAlarm) {
log.warn("Pump is in error state, raising alert: " + errorMsg);
log.warn(" LastCmd: " + lastCmd);
log.warn(" LastCmdTime: " + lastCmdTime);
long[] vibratePattern = new long[]{1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000};
log.error("Command failed: " + lastCmd);
log.error("Command result: " + lastCmdResult);
if (pumpState.errorMsg != null) {
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);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.notif_icon)
.setSmallIcon(R.drawable.icon_bolus)
.setContentTitle("Combo communication error")
.setContentText(errorMsg)
.setContentText(lastCmdResult.message)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setLights(Color.BLUE, 1000, 0)
.setSound(uri)
@ -149,10 +149,8 @@ public class ComboPlugin implements PluginBase, PumpInterface {
mgr.notify(id, notificationBuilder.build());
lastAlarmTime = now;
} 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);
}
@ -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
// returns false and isBusy returns true; this will however not crash the alerter
// which will raise an exception. Not really ideal.
pumpState.errorMsg = "Failed to bind to ruffy service";
statusSummary = "Failed to bind to ruffy service";
}
}