Show last command and pump state better in the Combo tab.

Gets rid of unhelpful "Unknown error" messaegs.
This commit is contained in:
Johannes Mockenhaupt 2017-07-19 01:33:19 +02:00
parent 5aacf8410d
commit 485b99e260
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
3 changed files with 68 additions and 46 deletions

View file

@ -11,6 +11,12 @@ public class PumpState {
public int tbrPercent = -1; public int tbrPercent = -1;
public double tbrRate = -1; public double tbrRate = -1;
public int tbrRemainingDuration = -1; public int tbrRemainingDuration = -1;
/** This is the error message (if any) displayed by the pump if there is an alarm,
e.g. if a "TBR cancelled alarm" is active, the value will be "TBR CANCELLED".
Generally, an error code is also displayed, but it flashes and it might take
longer to read that and the pump connection gets interrupted if we're not
reacting quickly.
*/
public String errorMsg; public String errorMsg;
public boolean suspended; public boolean suspended;

View file

@ -17,6 +17,8 @@ import org.slf4j.LoggerFactory;
import de.jotomo.ruffyscripter.PumpState; import de.jotomo.ruffyscripter.PumpState;
import de.jotomo.ruffyscripter.commands.Command;
import de.jotomo.ruffyscripter.commands.CommandResult;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI; import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI;
@ -31,13 +33,13 @@ public class ComboFragment extends Fragment implements View.OnClickListener {
} }
private Button refresh; private Button refresh;
private TextView status; private TextView statusText;
private TextView tbrPercentage; private TextView tbrPercentageText;
private TextView tbrDuration; private TextView tbrDurationText;
private TextView tbrRate; private TextView tbrRateText;
private TextView lastCmd; private TextView lastCmdText;
private TextView lastCmdTime; private TextView lastCmdTimeText;
private TextView lastCmdResult; private TextView lastCmdResultText;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
@ -45,13 +47,13 @@ public class ComboFragment extends Fragment implements View.OnClickListener {
View view = inflater.inflate(R.layout.combopump_fragment, container, false); View view = inflater.inflate(R.layout.combopump_fragment, container, false);
refresh = (Button) view.findViewById(R.id.combo_refresh); refresh = (Button) view.findViewById(R.id.combo_refresh);
status = (TextView) view.findViewById(R.id.combo_status); statusText = (TextView) view.findViewById(R.id.combo_status);
tbrPercentage = (TextView) view.findViewById(R.id.combo_tbr_percentage); tbrPercentageText = (TextView) view.findViewById(R.id.combo_tbr_percentage);
tbrDuration = (TextView) view.findViewById(R.id.combo_tbr_duration); tbrDurationText = (TextView) view.findViewById(R.id.combo_tbr_duration);
tbrRate = (TextView) view.findViewById(R.id.combo_tbr_rate); tbrRateText = (TextView) view.findViewById(R.id.combo_tbr_rate);
lastCmd = (TextView) view.findViewById(R.id.combo_last_command); lastCmdText = (TextView) view.findViewById(R.id.combo_last_command);
lastCmdTime = (TextView) view.findViewById(R.id.combo_last_command_time); lastCmdTimeText = (TextView) view.findViewById(R.id.combo_last_command_time);
lastCmdResult = (TextView) view.findViewById(R.id.combo_last_command_result); lastCmdResultText = (TextView) view.findViewById(R.id.combo_last_command_result);
refresh.setOnClickListener(this); refresh.setOnClickListener(this);
@ -98,27 +100,37 @@ public class ComboFragment extends Fragment implements View.OnClickListener {
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
status.setText(getPlugin().statusSummary); statusText.setText(getPlugin().statusSummary);
if (getPlugin().isInitialized()) { if (getPlugin().isInitialized()) {
PumpState ps = getPlugin().pumpState; PumpState ps = getPlugin().pumpState;
boolean tbrActive = ps.tbrPercent != -1 && ps.tbrPercent != 100; boolean tbrActive = ps.tbrPercent != -1 && ps.tbrPercent != 100;
if (tbrActive) { if (tbrActive) {
tbrPercentage.setText("" + ps.tbrPercent + "%"); tbrPercentageText.setText("" + ps.tbrPercent + "%");
tbrDuration.setText("" + ps.tbrRemainingDuration + " min"); tbrDurationText.setText("" + ps.tbrRemainingDuration + " min");
tbrRate.setText("" + ps.tbrRate + " U/h"); tbrRateText.setText("" + ps.tbrRate + " U/h");
} else { } else {
tbrPercentage.setText("Default basal rate running"); tbrPercentageText.setText("Default basal rate running");
tbrDuration.setText(""); tbrDurationText.setText("");
tbrRate.setText("" + getPlugin().getBaseBasalRate() + " U/h"); tbrRateText.setText("" + getPlugin().getBaseBasalRate() + " U/h");
} }
if (getPlugin().lastCmd != null) { Command lastCmd = getPlugin().lastCmd;
lastCmd.setText("" + getPlugin().lastCmd); if (lastCmd != null) {
lastCmdTime.setText(ps.timestamp.toLocaleString()); lastCmdText.setText("" + lastCmd);
lastCmdResult.setText(ps.errorMsg == null ? "Success" : ps.errorMsg); lastCmdTimeText.setText(getPlugin().lastCmdTime.toLocaleString());
CommandResult lastCmdResult = getPlugin().lastCmdResult;
if (lastCmdResult != null) {
String message = lastCmdResult.message;
if (ps.errorMsg != null) {
message = message + "\nPump is in error state:\n" + ps.errorMsg;
}
lastCmdResultText.setText(message);
} else {
lastCmdResultText.setText("");
}
} else { } else {
lastCmd.setText(""); ComboFragment.this.lastCmdText.setText("");
lastCmdTime.setText(""); lastCmdTimeText.setText("");
lastCmdResult.setText(""); lastCmdResultText.setText("");
} }
} }
} }

View file

@ -63,15 +63,17 @@ public class ComboPlugin implements PluginBase, PumpInterface {
private RuffyScripter ruffyScripter; private RuffyScripter ruffyScripter;
private ServiceConnection mRuffyServiceConnection; private ServiceConnection mRuffyServiceConnection;
@Nullable // TODO is volatile really needed here?
volatile Command lastCmd;
@NonNull
private Date lastCmdTime = new Date(0);
@NonNull
volatile PumpState pumpState = new PumpState();
@NonNull @NonNull
volatile String statusSummary = "Initializing"; volatile String statusSummary = "Initializing";
@Nullable
volatile Command lastCmd;
@Nullable
volatile CommandResult lastCmdResult;
@NonNull
volatile Date lastCmdTime = new Date(0);
@NonNull
volatile PumpState pumpState = new PumpState();
private static PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult(); private static PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult();
@ -260,7 +262,8 @@ public class ComboPlugin implements PluginBase, PumpInterface {
@Override @Override
public boolean isInitialized() { public boolean isInitialized() {
// consider initialized when the pump's state was initially fetched // consider initialized when the pump's state was initially fetched,
// after that lastCmd* variables will have values
return lastCmdTime.getTime() > 0; return lastCmdTime.getTime() > 0;
} }
@ -372,22 +375,23 @@ public class ComboPlugin implements PluginBase, PumpInterface {
CommandResult commandResult = ruffyScripter.runCommand(command); CommandResult commandResult = ruffyScripter.runCommand(command);
log.debug("RuffyScripter returned from command invocation, result: " + commandResult); log.debug("RuffyScripter returned from command invocation, result: " + commandResult);
if (commandResult.exception != null) {
log.error("Exception received from pump", commandResult.exception);
}
lastCmd = command; lastCmd = command;
lastCmdTime = new Date(); lastCmdTime = new Date();
if (commandResult.success) { lastCmdResult = commandResult;
statusSummary = commandResult.state.suspended ? "Suspended" : "Idle"; pumpState = commandResult.state;
pumpState = commandResult.state;
if (commandResult.success && commandResult.state.suspended) {
statusSummary = "Suspended";
} else if (commandResult.success) {
statusSummary = "Idle";
} else { } else {
statusSummary = "Error"; statusSummary = "Error";
pumpState = new PumpState();
pumpState.errorMsg = commandResult.message != null
? commandResult.message
: "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;
} }