Add RuffyCommands.readPumpState, cleanup, fix.
This commit is contained in:
parent
e4901f292f
commit
ab4f46471b
10 changed files with 53 additions and 28 deletions
|
@ -16,9 +16,8 @@ import com.squareup.otto.Subscribe;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
import de.jotomo.ruffy.spi.PumpState;
|
|
||||||
import de.jotomo.ruffy.spi.CommandResult;
|
import de.jotomo.ruffy.spi.CommandResult;
|
||||||
|
import de.jotomo.ruffy.spi.PumpState;
|
||||||
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;
|
||||||
|
@ -111,7 +110,8 @@ public class ComboFragment extends Fragment implements View.OnClickListener {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ComboPlugin plugin = ComboPlugin.getPlugin();
|
ComboPlugin plugin = ComboPlugin.getPlugin();
|
||||||
statusText.setText(plugin.getPump().state.getStateSummary());
|
if (plugin.getPump().lastCmdResult != null)
|
||||||
|
statusText.setText(plugin.getPump().state.getStateSummary());
|
||||||
if (plugin.isInitialized()) {
|
if (plugin.isInitialized()) {
|
||||||
PumpState ps = plugin.getPump().state;
|
PumpState ps = plugin.getPump().state;
|
||||||
if (ps != null) {
|
if (ps != null) {
|
||||||
|
|
|
@ -274,8 +274,7 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
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 {
|
||||||
// TODO
|
ruffyScripter.readPumpState();
|
||||||
// runCommand(new GetPumpStateCommand());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,7 @@
|
||||||
android:gravity="start"
|
android:gravity="start"
|
||||||
android:paddingLeft="5dp"
|
android:paddingLeft="5dp"
|
||||||
android:textColor="@android:color/white"
|
android:textColor="@android:color/white"
|
||||||
|
android:text="Initializing"
|
||||||
android:textSize="14sp" />
|
android:textSize="14sp" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@ -460,7 +461,7 @@
|
||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
android:paddingLeft="5dp"
|
android:paddingLeft="5dp"
|
||||||
android:gravity="start"
|
android:gravity="start"
|
||||||
android:text=" - " />
|
android:text="" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,7 @@ package de.jotomo.ruffy.spi;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/** State displayed on the main screen of the pump. */
|
||||||
* State representing the state of the MAIN_MENU, plus reservoir level (if requested).
|
|
||||||
*/
|
|
||||||
public class PumpState {
|
public class PumpState {
|
||||||
public Date timestamp = new Date();
|
public Date timestamp = new Date();
|
||||||
public boolean tbrActive = false;
|
public boolean tbrActive = false;
|
||||||
|
|
|
@ -17,6 +17,8 @@ public interface RuffyCommands {
|
||||||
|
|
||||||
boolean isPumpBusy();
|
boolean isPumpBusy();
|
||||||
|
|
||||||
|
CommandResult readPumpState();
|
||||||
|
|
||||||
CommandResult readHistory(PumpHistoryRequest request);
|
CommandResult readHistory(PumpHistoryRequest request);
|
||||||
|
|
||||||
CommandResult readBasalProfile(int number);
|
CommandResult readBasalProfile(int number);
|
||||||
|
|
|
@ -52,6 +52,11 @@ public class RuffyCommandsV1Impl implements RuffyCommands {
|
||||||
return delegate.isPumpBusy();
|
return delegate.isPumpBusy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandResult readPumpState() {
|
||||||
|
return delegate.readPumpState();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult readHistory(PumpHistoryRequest request) {
|
public CommandResult readHistory(PumpHistoryRequest request) {
|
||||||
return delegate.readHistory(request);
|
return delegate.readHistory(request);
|
||||||
|
|
|
@ -30,6 +30,7 @@ import de.jotomo.ruffyscripter.commands.Command;
|
||||||
import de.jotomo.ruffyscripter.commands.CommandException;
|
import de.jotomo.ruffyscripter.commands.CommandException;
|
||||||
import de.jotomo.ruffyscripter.commands.GetPumpStateCommand;
|
import de.jotomo.ruffyscripter.commands.GetPumpStateCommand;
|
||||||
import de.jotomo.ruffyscripter.commands.ReadBasalProfileCommand;
|
import de.jotomo.ruffyscripter.commands.ReadBasalProfileCommand;
|
||||||
|
import de.jotomo.ruffyscripter.commands.ReadPumpStateCommand;
|
||||||
import de.jotomo.ruffyscripter.commands.SetBasalProfileCommand;
|
import de.jotomo.ruffyscripter.commands.SetBasalProfileCommand;
|
||||||
import de.jotomo.ruffyscripter.commands.SetTbrCommand;
|
import de.jotomo.ruffyscripter.commands.SetTbrCommand;
|
||||||
import de.jotomo.ruffy.spi.BasalProfile;
|
import de.jotomo.ruffy.spi.BasalProfile;
|
||||||
|
@ -109,6 +110,8 @@ public class RuffyScripter implements RuffyCommands {
|
||||||
|
|
||||||
if (!boundSucceeded) {
|
if (!boundSucceeded) {
|
||||||
log.error("No connection to ruffy. Pump control unavailable.");
|
log.error("No connection to ruffy. Pump control unavailable.");
|
||||||
|
} else {
|
||||||
|
started = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,16 +226,9 @@ public class RuffyScripter implements RuffyCommands {
|
||||||
return activeCmd != null;
|
return activeCmd != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unbind() {
|
@Override
|
||||||
/*
|
public CommandResult readPumpState() {
|
||||||
if (ruffyService != null)
|
return runCommand(new ReadPumpStateCommand());
|
||||||
try {
|
|
||||||
ruffyService.removeHandler(mHandler);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
this.ruffyService = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void returnToMainMenu() {
|
public void returnToMainMenu() {
|
||||||
|
@ -260,16 +256,17 @@ public class RuffyScripter implements RuffyCommands {
|
||||||
* Always returns a CommandResult, never throws
|
* Always returns a CommandResult, never throws
|
||||||
*/
|
*/
|
||||||
public CommandResult runCommand(final Command cmd) {
|
public CommandResult runCommand(final Command cmd) {
|
||||||
|
log.debug("Attempting to run cmd: " + cmd);
|
||||||
if (unrecoverableError != null) {
|
if (unrecoverableError != null) {
|
||||||
return new CommandResult().success(false).enacted(false).message(unrecoverableError);
|
return new CommandResult().success(false).enacted(false).message(unrecoverableError);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> violations = cmd.validateArguments();
|
List<String> violations = cmd.validateArguments();
|
||||||
if (!violations.isEmpty()) {
|
if (!violations.isEmpty()) {
|
||||||
return new CommandResult().message(Joiner.on("\n").join(violations)).state(readPumpState());
|
return new CommandResult().message(Joiner.on("\n").join(violations)).state(readPumpStateInternal());
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (RuffyScripter.class) {
|
// synchronized (RuffyScripter.class) {
|
||||||
try {
|
try {
|
||||||
activeCmd = cmd;
|
activeCmd = cmd;
|
||||||
long connectStart = System.currentTimeMillis();
|
long connectStart = System.currentTimeMillis();
|
||||||
|
@ -317,7 +314,7 @@ public class RuffyScripter implements RuffyCommands {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log.debug("Connection ready to execute cmd " + cmd);
|
log.debug("Connection ready to execute cmd " + cmd);
|
||||||
PumpState pumpState = readPumpState();
|
PumpState pumpState = readPumpStateInternal();
|
||||||
log.debug("Pump state before running command: " + pumpState);
|
log.debug("Pump state before running command: " + pumpState);
|
||||||
long cmdStartTime = System.currentTimeMillis();
|
long cmdStartTime = System.currentTimeMillis();
|
||||||
cmd.setScripter(scripter);
|
cmd.setScripter(scripter);
|
||||||
|
@ -368,7 +365,7 @@ public class RuffyScripter implements RuffyCommands {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (returnable.cmdResult.state == null) {
|
if (returnable.cmdResult.state == null) {
|
||||||
returnable.cmdResult.state = readPumpState();
|
returnable.cmdResult.state = readPumpStateInternal();
|
||||||
}
|
}
|
||||||
long connectDurationSec = (executionStart - connectStart) / 1000;
|
long connectDurationSec = (executionStart - connectStart) / 1000;
|
||||||
long executionDurationSec = (System.currentTimeMillis() - executionStart) / 1000;
|
long executionDurationSec = (System.currentTimeMillis() - executionStart) / 1000;
|
||||||
|
@ -384,7 +381,7 @@ public class RuffyScripter implements RuffyCommands {
|
||||||
} finally {
|
} finally {
|
||||||
activeCmd = null;
|
activeCmd = null;
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -436,7 +433,7 @@ public class RuffyScripter implements RuffyCommands {
|
||||||
|
|
||||||
/** This reads the state of the, which is whatever is currently displayed on the display,
|
/** This reads the state of the, which is whatever is currently displayed on the display,
|
||||||
* no actions are performed. */
|
* no actions are performed. */
|
||||||
public PumpState readPumpState() {
|
public PumpState readPumpStateInternal() {
|
||||||
PumpState state = new PumpState();
|
PumpState state = new PumpState();
|
||||||
Menu menu = currentMenu;
|
Menu menu = currentMenu;
|
||||||
if (menu == null) {
|
if (menu == null) {
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class CancelTbrCommand extends BaseCommand {
|
||||||
public CommandResult execute() {
|
public CommandResult execute() {
|
||||||
try {
|
try {
|
||||||
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU);
|
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU);
|
||||||
PumpState pumpState = scripter.readPumpState();
|
PumpState pumpState = scripter.readPumpStateInternal();
|
||||||
if (!pumpState.tbrActive) {
|
if (!pumpState.tbrActive) {
|
||||||
// log.debug("active temp basal 90s ago: " +
|
// log.debug("active temp basal 90s ago: " +
|
||||||
// MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis() - 90 * 1000));
|
// MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis() - 90 * 1000));
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package de.jotomo.ruffyscripter.commands;
|
package de.jotomo.ruffyscripter.commands;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.jotomo.ruffyscripter.RuffyScripter;
|
import de.jotomo.ruffyscripter.RuffyScripter;
|
||||||
|
@ -14,12 +15,12 @@ public class ReadBasalProfileCommand implements Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute() {
|
public CommandResult execute() {
|
||||||
return null;
|
return new CommandResult().success(false).enacted(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> validateArguments() {
|
public List<String> validateArguments() {
|
||||||
return null;
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package de.jotomo.ruffyscripter.commands;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import de.jotomo.ruffy.spi.CommandResult;
|
||||||
|
import de.jotomo.ruffyscripter.RuffyScripter;
|
||||||
|
|
||||||
|
public class ReadPumpStateCommand implements Command {
|
||||||
|
@Override
|
||||||
|
public CommandResult execute() {
|
||||||
|
return new CommandResult().success(true).enacted(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> validateArguments() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setScripter(RuffyScripter scripter) {}
|
||||||
|
}
|
Loading…
Reference in a new issue