ComboPlugin.runCommand: wait if pump is busy with a command.
This commit is contained in:
parent
d8011aeaa4
commit
77711b2174
1 changed files with 9 additions and 2 deletions
|
@ -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 + "%");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue