Log pump status on connect.

This commit is contained in:
Johannes Mockenhaupt 2017-07-15 11:34:59 +02:00
parent 347890496b
commit a2b3c26b33
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -6,7 +6,9 @@ import android.os.SystemClock;
import org.monkey.d.ruffy.ruffy.driver.IRTHandler; import org.monkey.d.ruffy.ruffy.driver.IRTHandler;
import org.monkey.d.ruffy.ruffy.driver.IRuffyService; import org.monkey.d.ruffy.ruffy.driver.IRuffyService;
import org.monkey.d.ruffy.ruffy.driver.display.Menu; import org.monkey.d.ruffy.ruffy.driver.display.Menu;
import org.monkey.d.ruffy.ruffy.driver.display.MenuAttribute;
import org.monkey.d.ruffy.ruffy.driver.display.MenuType; import org.monkey.d.ruffy.ruffy.driver.display.MenuType;
import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuTime;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -124,6 +126,7 @@ public class RuffyScripter {
// TODO hackish, to say the least ... // TODO hackish, to say the least ...
// wait till pump is ready for input // wait till pump is ready for input
waitForMenuUpdate(); waitForMenuUpdate();
logPumpStatus();
log.debug("Cmd execution: connection ready, executing cmd " + cmd); log.debug("Cmd execution: connection ready, executing cmd " + cmd);
cmdThread = new Thread(new Runnable() { cmdThread = new Thread(new Runnable() {
@Override @Override
@ -166,6 +169,28 @@ public class RuffyScripter {
} }
} }
private void logPumpStatus() {
log.debug("Pump status:");
MenuType currentMenuType = currentMenu.getType();
if (currentMenuType == MenuType.MAIN_MENU) {
Double tbrPercentage = (Double) currentMenu.getAttribute(MenuAttribute.TBR);
if (tbrPercentage != 100) {
MenuTime durationMenuTime = ((MenuTime) currentMenu.getAttribute(MenuAttribute.RUNTIME));
long durationRemainging = durationMenuTime.getHour() * 60 + durationMenuTime.getMinute();
log.debug(" TBR active: " + tbrPercentage + "%/" + durationRemainging + "m remaining");
} else {
log.debug(" TBR active: no");
}
} else {
log.warn(" !!! Pump is on unexpected screen " + currentMenuType + " !!!");
log.warn(" Dumping all displayed attributes:");
for (MenuAttribute menuAttribute : currentMenu.attributes()) {
log.warn(" " + menuAttribute + ": " + currentMenu.getAttribute(menuAttribute));
}
}
}
public void ensureConnected() { public void ensureConnected() {
// did we get a menu update from the pump in the last 5s? Then we're connected // did we get a menu update from the pump in the last 5s? Then we're connected
if (currentMenu != null && menuLastUpdated + 5000 > System.currentTimeMillis()) { if (currentMenu != null && menuLastUpdated + 5000 > System.currentTimeMillis()) {