First steps to syncing full pump state with AAPS.
This commit is contained in:
parent
491caadd71
commit
1aa2ce48a1
1 changed files with 66 additions and 9 deletions
|
@ -136,7 +136,7 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
if (now > fiveMinutesSinceLastAlarm && loopEnabled) {
|
if (now > fiveMinutesSinceLastAlarm && loopEnabled) {
|
||||||
log.error("Command result: " + localLastCmdResult);
|
log.error("Command result: " + localLastCmdResult);
|
||||||
PumpState localPumpState = pump.state;
|
PumpState localPumpState = pump.state;
|
||||||
if (localPumpState != null && localPumpState.errorMsg != null) {
|
if (localPumpState.errorMsg != null) {
|
||||||
log.warn("Pump is in error state, displaying; " + localPumpState.errorMsg);
|
log.warn("Pump is in error state, displaying; " + localPumpState.errorMsg);
|
||||||
}
|
}
|
||||||
long[] vibratePattern = new long[]{1000, 2000, 1000, 2000, 1000};
|
long[] vibratePattern = new long[]{1000, 2000, 1000, 2000, 1000};
|
||||||
|
@ -254,12 +254,36 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Date lastDataTime() {
|
public Date lastDataTime() {
|
||||||
CommandResult lastCmdResult = pump.lastCmdResult;
|
CommandResult lastCmdResult = pump.lastCmdResult;
|
||||||
return lastCmdResult != null ? new Date(lastCmdResult.completionTime) : new Date(0);
|
return lastCmdResult != null ? new Date(lastCmdResult.completionTime) : new Date(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize() {
|
||||||
|
runCommand("Syncing pump state", new CommandExecution() {
|
||||||
|
@Override
|
||||||
|
public CommandResult execute() {
|
||||||
|
return ruffyScripter.readHistory(
|
||||||
|
new PumpHistoryRequest()
|
||||||
|
.reservoirLevel(true)
|
||||||
|
.bolusHistory(PumpHistoryRequest.LAST)
|
||||||
|
.tbrHistory(PumpHistoryRequest.LAST)
|
||||||
|
.errorHistory(PumpHistoryRequest.LAST)
|
||||||
|
.tddHistory(PumpHistoryRequest.LAST));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
// detectStateMismatch(): expensive sync, checking everything (detectTbrMisMatch us called for every command)
|
||||||
|
// check 'lasts' of pump against treatment db, request full sync if needed
|
||||||
|
// and also remove treatments the pump doesn't have.
|
||||||
|
// warn about this with a notification? show what was removed on combo tab?
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// this method is regularly called from info.nightscout.androidaps.receivers.KeepAliveReceiver
|
// this method is regularly called from info.nightscout.androidaps.receivers.KeepAliveReceiver
|
||||||
// TODO check this is eithor called regularly even with other commansd being fired; if not,
|
// TODO check this is eithor called regularly even with other commansd being fired; if not,
|
||||||
// request this periodically
|
// request this periodically
|
||||||
|
@ -269,24 +293,24 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
|
|
||||||
// if Android is sluggish this might get called before ruffy is bound
|
// if Android is sluggish this might get called before ruffy is bound
|
||||||
if (!ruffyScripter.isPumpAvailable()) {
|
if (!ruffyScripter.isPumpAvailable()) {
|
||||||
log.warn("Rejecting call to RefreshDataFromPump: scripter not ready yet.");
|
log.error("Rejecting call to RefreshDataFromPump: scripter not ready yet.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
boolean notAUserRequest = !reason.toLowerCase().contains("user");
|
// boolean notAUserRequest = !reason.toLowerCase().contains("user");
|
||||||
boolean wasRunAtLeastOnce = pump.lastCmdResult != null;
|
// boolean wasRunAtLeastOnce = pump.lastCmdResult != null;
|
||||||
boolean ranWithinTheLastMinute = wasRunAtLeastOnce && System.currentTimeMillis() < pump.lastCmdResult.completionTime + 60 * 1000;
|
// boolean ranWithinTheLastMinute = wasRunAtLeastOnce && System.currentTimeMillis() < pump.lastCmdResult.completionTime + 60 * 1000;
|
||||||
if (notAUserRequest && wasRunAtLeastOnce && ranWithinTheLastMinute) {
|
// if (notAUserRequest && wasRunAtLeastOnce && ranWithinTheLastMinute) {
|
||||||
log.debug("Not fetching state from pump, since we did already within the last 60 seconds");
|
// log.debug("Not fetching state from pump, since we did already within the last 60 seconds");
|
||||||
} else {
|
// } else {
|
||||||
runCommand("Refreshing", new CommandExecution() {
|
runCommand("Refreshing", new CommandExecution() {
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute() {
|
public CommandResult execute() {
|
||||||
return ruffyScripter.readHistory(new PumpHistoryRequest().reservoirLevel(true).bolusHistory(PumpHistoryRequest.LAST));
|
return ruffyScripter.readHistory(new PumpHistoryRequest().reservoirLevel(true).bolusHistory(PumpHistoryRequest.LAST));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO uses profile values for the time being
|
// TODO uses profile values for the time being
|
||||||
|
@ -576,6 +600,39 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
|
|
||||||
pump.lastCmdResult = commandResult;
|
pump.lastCmdResult = commandResult;
|
||||||
pump.state = commandResult.state;
|
pump.state = commandResult.state;
|
||||||
|
|
||||||
|
// detectTbrMismatch(): 'quick' check with not overhead on the pump side
|
||||||
|
// TODO check if this works with pump suspend, esp. around pump suspend there'll be syncing to do;
|
||||||
|
TemporaryBasal aapsTbr = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
||||||
|
if (aapsTbr == null && pump.state.tbrActive) {
|
||||||
|
// pump runs TBR AAPS is unaware off
|
||||||
|
// => fetch full history so the full TBR is added to treatments
|
||||||
|
} else if (aapsTbr != null && !pump.state.tbrActive) {
|
||||||
|
// AAPS has a TBR but the pump isn't running a TBR
|
||||||
|
// => remove the TBR from treatments
|
||||||
|
// => fetch full history, so that if the TBR was cancelled but ran some time we get the IOB from that partial TBR
|
||||||
|
} else if (aapsTbr != null && pump.state.tbrActive) {
|
||||||
|
// both AAPS and pump have a TBR ...
|
||||||
|
if (aapsTbr.percentRate != pump.state.tbrPercent) {
|
||||||
|
// ... but they have different percentages
|
||||||
|
// => remove TBR from treatments
|
||||||
|
// => full history sync so we get up to date on actual IOB
|
||||||
|
}
|
||||||
|
int durationDiff = Math.abs(aapsTbr.getPlannedRemainingMinutes() - pump.state.tbrRemainingDuration);
|
||||||
|
if (durationDiff > 2) {
|
||||||
|
// ... but they have different runtimes
|
||||||
|
// ^ same as above, merge branches
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO not propely set all the time ...
|
||||||
|
if (pump.lastCmdResult == null) {
|
||||||
|
log.error("JOE: no!");
|
||||||
|
} else {
|
||||||
|
// still crashable ...
|
||||||
|
pump.lastCmdResult.completionTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
// TOOD
|
// TOOD
|
||||||
if (commandResult.history != null) {
|
if (commandResult.history != null) {
|
||||||
if (commandResult.history.reservoirLevel != -1) {
|
if (commandResult.history.reservoirLevel != -1) {
|
||||||
|
|
Loading…
Reference in a new issue