ComboPlugin.runCommand: wait if pump is busy with a command.

This commit is contained in:
Johannes Mockenhaupt 2017-07-15 15:00:27 +02:00
parent d8011aeaa4
commit 77711b2174
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -319,10 +319,17 @@ public class ComboPlugin implements PluginBase, PumpInterface {
private CommandResult runCommand(Command command, boolean keepConnectionOpen) { private CommandResult runCommand(Command command, boolean keepConnectionOpen) {
// TODO use this to dispatch methods to a service thread, like DanaRs executionService // TODO use this to dispatch methods to a service thread, like DanaRs executionService
try { try {
long timeout = System.currentTimeMillis() + 10 * 1000;
while (ruffyScripter.isPumpBusy()) {
if (System.currentTimeMillis() < timeout) {
return new CommandResult().success(false).enacted(false).message("Timeout waiting for the pump to be ready");
}
SystemClock.sleep(200);
}
return ruffyScripter.runCommand(command); return ruffyScripter.runCommand(command);
} finally { } finally {
lastCmdTime = new Date(); lastCmdTime = new Date();
if(!keepConnectionOpen) { if (!keepConnectionOpen) {
ruffyScripter.disconnect(); ruffyScripter.disconnect();
} }
} }
@ -340,7 +347,7 @@ public class ComboPlugin implements PluginBase, PumpInterface {
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) { public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) {
log.debug("setTempBasalAbsolute called with a rate of " + absoluteRate + " for " + durationInMinutes + " min."); log.debug("setTempBasalAbsolute called with a rate of " + absoluteRate + " for " + durationInMinutes + " min.");
int unroundedPercentage = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue(); int unroundedPercentage = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue();
int roundedPercentage = (int) (Math.round(absoluteRate/ getBaseBasalRate() * 10) * 10); int roundedPercentage = (int) (Math.round(absoluteRate / getBaseBasalRate() * 10) * 10);
if (unroundedPercentage != roundedPercentage) { if (unroundedPercentage != roundedPercentage) {
log.debug("Rounded requested rate " + unroundedPercentage + "% -> " + roundedPercentage + "%"); log.debug("Rounded requested rate " + unroundedPercentage + "% -> " + roundedPercentage + "%");
} }