From cd337ecdc8afa442ebc126cea8d5ac2782147a55 Mon Sep 17 00:00:00 2001 From: PoweRGbg Date: Wed, 13 Jun 2018 10:51:06 +0300 Subject: [PATCH] update to latest changes from Milos --- .../plugins/PumpDanaR/DanaRPump.java | 2 +- .../activities/DanaRUserOptionsActivity.java | 30 +---- .../PumpDanaR/comm/MsgSetUserOptions.java | 127 ++++++++++++++---- .../PumpDanaR/comm/MsgSettingUserOptions.java | 2 + .../AbstractDanaRExecutionService.java | 1 + .../services/DanaRExecutionService.java | 37 ++--- .../services/DanaRKoreanExecutionService.java | 5 + .../plugins/PumpDanaRv2/DanaRv2Plugin.java | 11 +- .../services/DanaRv2ExecutionService.java | 39 +----- .../androidaps/queue/CommandQueue.java | 2 +- 10 files changed, 129 insertions(+), 127 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java index 1e346695e3..d9bc947b84 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java @@ -161,7 +161,7 @@ public class DanaRPump { public int lowReservoirRate; public int cannulaVolume; public int refillAmount; - + public byte[] userOptionsFrompump; public double initialBolusAmount; // Bolus settings public int bolusCalculationOption; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRUserOptionsActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRUserOptionsActivity.java index b7b7a793f4..4a670a7e81 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRUserOptionsActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRUserOptionsActivity.java @@ -1,7 +1,6 @@ package info.nightscout.androidaps.plugins.PumpDanaR.activities; import android.app.Activity; -import android.content.Intent; import android.os.Bundle; import android.widget.Button; import android.widget.RadioButton; @@ -20,13 +19,10 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin; import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; -import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.NumberPicker; /** @@ -83,9 +79,6 @@ public class DanaRUserOptionsActivity extends Activity { saveToPumpButton.setOnClickListener(v -> onSaveClick()); - boolean isv2 = MainApp.getSpecificPlugin(DanaRv2Plugin.class) != null && MainApp.getSpecificPlugin(DanaRv2Plugin.class).isEnabled(PluginType.PUMP); - - DanaRPump pump = DanaRPump.getInstance(); //used for debugging log.debug("UserOptionsLoaded:" + (System.currentTimeMillis() - pump.lastConnection) / 1000 + " s ago" @@ -96,20 +89,6 @@ public class DanaRUserOptionsActivity extends Activity { + "\nbacklight:" + pump.backlightOnTimeSec + "\npumpUnits:" + pump.units + "\nlowReservoir:" + pump.lowReservoirRate); - log.debug("isV2:"+isv2); - if(isv2 && pump.lowReservoirRate < 10){ - log.debug("No user settings loaded forcing reload!"); - DanaRv2Plugin.getPlugin().getUserOptions(); - log.debug("UserOptionsLoaded:" + (System.currentTimeMillis() - pump.lastConnection) / 1000 + " s ago" - + "\ntimeDisplayType:" + pump.timeDisplayType - + "\nbuttonScroll:" + pump.buttonScrollOnOff - + "\ntimeDisplayType:" + pump.timeDisplayType - + "\nlcdOnTimeSec:" + pump.lcdOnTimeSec - + "\nbacklight:" + pump.backlightOnTimeSec - + "\npumpUnits:" + pump.units - + "\nlowReservoir:" + pump.lowReservoirRate); - - } screenTimeout.setParams((double) pump.lcdOnTimeSec, 5d, 240d, 5d, new DecimalFormat("1"), false); backlightTimeout.setParams((double) pump.backlightOnTimeSec, 1d, 60d, 1d, new DecimalFormat("1"), false); @@ -164,9 +143,6 @@ public class DanaRUserOptionsActivity extends Activity { //exit if pump is not DanaRS, Dana!, or DanaR with upgraded firmware return; } - if (isDanaRv2) { - DanaRv2Plugin.getPlugin().getUserOptions(); - } DanaRPump pump = DanaRPump.getInstance(); if (timeFormat.isChecked()) @@ -205,11 +181,7 @@ public class DanaRUserOptionsActivity extends Activity { } else pump.lowReservoirRate = 10; - if (isDanaRv2) { - DanaRv2Plugin.getPlugin().setUserOptions(); - } - - MainApp.getConfigBuilder().getCommandQueue().setUserSettings(null); + MainApp.getConfigBuilder().getCommandQueue().setUserOptions(null); finish(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetUserOptions.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetUserOptions.java index 5cdf2d75fa..1f2552ef03 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetUserOptions.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetUserOptions.java @@ -2,49 +2,77 @@ package info.nightscout.androidaps.plugins.PumpDanaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import android.support.v4.internal.view.SupportMenu; import info.nightscout.androidaps.Config; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; /** * Created by mike on 05.07.2016. */ public class MsgSetUserOptions extends MessageBase { + private static Logger log = LoggerFactory.getLogger(MsgSetUserOptions.class); + + private int backlightOnTimeSec; + private int beepAndAlarm; + private int buttonScrollOnOff; + private int cannulaVolume; + private int error; + private int glucoseUnit; + private int lcdOnTimeSec; + private int lowReservoirRate; + private int refillRate; + private int selectedLanguage; + private int shutdownHour; + private int timeDisplayType; + byte[] newOptions; public boolean done; + public MsgSetUserOptions(int timeDisplayType, int buttonScrollOnOff, int beepAndAlarm, int lcdOnTimeSec, int backlightOnTimeSec, int selectedLanguage, int glucoseUnit, int shutdownHour, int lowReservoirRate, int cannulaVolume, int refillRate) { + this(); + log.debug(" initializing MsgSetUserOptions"); + log.debug("timeDisplayType: " + (byte) timeDisplayType); + log.debug("Button scroll: " + (byte) buttonScrollOnOff); + log.debug("BeepAndAlarm: " + (byte) beepAndAlarm); + log.debug("screen timeout: " + (byte) lcdOnTimeSec); + log.debug("Backlight: " + (byte) backlightOnTimeSec); + log.debug("Selected language: " + (byte) selectedLanguage); + log.debug("Units: " + (byte) glucoseUnit); + log.debug("Shutdown: " + (byte) shutdownHour); + log.debug("Low reservoir: " + (byte) lowReservoirRate); + this.timeDisplayType = timeDisplayType; + this.buttonScrollOnOff = buttonScrollOnOff; + this.beepAndAlarm = beepAndAlarm; + this.lcdOnTimeSec = lcdOnTimeSec; + this.backlightOnTimeSec = backlightOnTimeSec; + this.selectedLanguage = selectedLanguage; + this.glucoseUnit = glucoseUnit; + this.shutdownHour = shutdownHour; + this.lowReservoirRate = lowReservoirRate; + this.cannulaVolume = cannulaVolume; + this.refillRate = refillRate; + newOptions[0] = (byte) (timeDisplayType == 1 ? 0 : 1); + newOptions[1] = (byte) buttonScrollOnOff; + newOptions[2] = (byte) beepAndAlarm; + newOptions[3] = (byte) lcdOnTimeSec; + newOptions[4] = (byte) backlightOnTimeSec; + newOptions[5] = (byte) selectedLanguage; + newOptions[8] = (byte) glucoseUnit; + newOptions[9] = (byte) shutdownHour; + newOptions[27] = (byte) lowReservoirRate; + // need to organize here + // glucoseunit is at pos 8 and lowReservoirRate is at pos 27 + // 6 extended bolus on/off + // 10 missed bolus + } + public MsgSetUserOptions() { SetCommand(0x330B); - - DanaRPump pump = DanaRPump.getInstance(); - - log.debug(" initializing MsgSetUserOptions"); - log.debug("timeDisplayType: " + (byte) pump.timeDisplayType); - log.debug("Button scroll: " + (byte) pump.buttonScrollOnOff); - log.debug("BeepAndAlarm: " + (byte) pump.beepAndAlarm); - log.debug("screen timeout: " + (byte) pump.lcdOnTimeSec); - log.debug("Backlight: " + (byte) pump.backlightOnTimeSec); - log.debug("Selected language: " + (byte) pump.selectedLanguage); - log.debug("Units: " + (byte) pump.units); - log.debug("Shutdown: " + (byte) pump.shutdownHour); - log.debug("Low reservoir: " + (byte) pump.lowReservoirRate); - // need to organize here - // glucoseunit is at pos 8 and lowReservoirRate is at pos 27 - AddParamByte((byte) pump.timeDisplayType); - AddParamByte((byte) pump.buttonScrollOnOff); - AddParamByte((byte) pump.beepAndAlarm); - AddParamByte((byte) pump.lcdOnTimeSec); - AddParamByte((byte) pump.backlightOnTimeSec); - AddParamByte((byte) pump.selectedLanguage); - AddParamByte((byte) pump.units); - AddParamByte((byte) pump.shutdownHour); - AddParamByte((byte) pump.lowReservoirRate); } - private static Logger log = LoggerFactory.getLogger(MsgSetUserOptions.class); - public void handleMessage(byte[] bytes) { log.debug("Entering handleMessage "); + newOptions = new byte[]{bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7], bytes[8], bytes[9], bytes[15], bytes[16], bytes[17], bytes[18], bytes[19], bytes[20], bytes[21], bytes[22], bytes[23], bytes[24], bytes[25], bytes[26], bytes[27], bytes[28], bytes[29], bytes[30], bytes[31], bytes[32]}; int result = intFromBuff(bytes, 0, 1); if (result != 1) { failed = true; @@ -55,4 +83,49 @@ public class MsgSetUserOptions extends MessageBase { } } + public byte[] getCommByte(int cmd, byte[] data) { + int len = (data == null ? 0 : data.length) + 3; + byte[] btSendData = new byte[(len + 7)]; + byte[] csr = new byte[2]; + byte[] crcData = new byte[len]; + try { + Thread.sleep(200); + } catch (InterruptedException e) { + e.printStackTrace(); + } + btSendData[0] = (byte) 126; + btSendData[1] = (byte) 126; + btSendData[2] = (byte) len; + btSendData[3] = (byte) 241; + btSendData[4] = (byte) ((cmd >> 8) & 255); + btSendData[5] = (byte) (cmd & 255); + if (len > 3) { + System.arraycopy(data, 0, btSendData, 6, len - 3); + } + System.arraycopy(btSendData, 3, crcData, 0, len); + int crc_result = GenerateCrc(crcData, len) & SupportMenu.USER_MASK; + csr[0] = (byte) (crc_result & 255); + csr[1] = (byte) ((crc_result >> 8) & 255); + btSendData[len + 3] = csr[1]; + btSendData[len + 4] = csr[0]; + btSendData[len + 5] = (byte) 46; + btSendData[len + 6] = (byte) 46; + return btSendData; + } + + public static int GenerateCrc(byte[] send_buf, int len) { + int crc = 0; + for (int i = 0; i < len; i++) { + crc = Crc16(send_buf[i], crc); + } + return crc; + } + + static int Crc16(byte byte1, int crc) { + int li_crc = ((((crc >> 8) | (crc << 8)) & SupportMenu.USER_MASK) ^ (byte1 & 255)) & SupportMenu.USER_MASK; + li_crc = (li_crc ^ ((li_crc & 255) >> 4)) & SupportMenu.USER_MASK; + li_crc = (li_crc ^ ((li_crc << 8) << 4)) & SupportMenu.USER_MASK; + return (li_crc ^ (((li_crc & 255) << 4) << 1)) & SupportMenu.USER_MASK; + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingUserOptions.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingUserOptions.java index 2d4dc09c4b..bdd6ea9367 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingUserOptions.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingUserOptions.java @@ -20,6 +20,8 @@ public class MsgSettingUserOptions extends MessageBase { public void handleMessage(byte[] packet) { DanaRPump pump = DanaRPump.getInstance(); byte[] bytes = getDataBytes(packet, 0, packet.length - 10); + // saving pumpDataBytes to use it in MsgSetUserOptions + pump.userOptionsFrompump = bytes; for(int pos=0; pos < bytes.length; pos++) { log.debug("[" + pos + "]" + bytes[pos]); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractDanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractDanaRExecutionService.java index 17db916dae..e4c2933d43 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractDanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractDanaRExecutionService.java @@ -92,6 +92,7 @@ public abstract class AbstractDanaRExecutionService extends Service { public abstract boolean extendedBolusStop(); + public abstract PumpEnactResult setUserOptions(); protected BroadcastReceiver receiver = new BroadcastReceiver() { @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java index de7eeb1591..7976430b77 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java @@ -18,8 +18,8 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgGetUserOptions; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingUserOptions; +import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetUserOptions; import info.nightscout.androidaps.plugins.Treatments.Treatment; import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventInitializationChanged; @@ -64,7 +64,6 @@ import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus; import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.NSUpload; import info.nightscout.utils.SP; -import info.nightscout.utils.ToastUtils; public class DanaRExecutionService extends AbstractDanaRExecutionService{ @@ -179,6 +178,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService{ mSerialIOThread.sendMessage(new MsgSettingActiveProfile()); mSerialIOThread.sendMessage(new MsgSettingProfileRatios()); mSerialIOThread.sendMessage(new MsgSettingProfileRatiosAll()); + mSerialIOThread.sendMessage(new MsgSettingUserOptions()); MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime))); mSerialIOThread.sendMessage(new MsgSettingPumpTime()); long timeDiff = (mDanaRPump.pumpTime.getTime() - System.currentTimeMillis()) / 1000L; @@ -384,30 +384,6 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService{ return true; } - public PumpEnactResult getUserOptions() { - if (!isConnected()) - return new PumpEnactResult().success(false); - DanaRPump pump = DanaRPump.getInstance(); - MsgGetUserOptions msg = new MsgGetUserOptions(); - mDanaRPump.lastConnection = System.currentTimeMillis(); - return new PumpEnactResult().success(true); - } - - public PumpEnactResult updateUserOptions() { - if (!isConnected()) - return new PumpEnactResult().success(false); - DanaRPump pump = DanaRPump.getInstance(); - MsgSettingUserOptions msg = new MsgSettingUserOptions(pump.timeDisplayType, pump.buttonScrollOnOff, pump.beepAndAlarm, pump.lcdOnTimeSec, pump.backlightOnTimeSec, pump.selectedLanguage, pump.units, pump.shutdownHour, pump.lowReservoirRate, 0, 0); - - mSerialIOThread.sendMessage(msg); - while (!msg.done && mRfcommSocket.isConnected()) { - SystemClock.sleep(100); - } - SystemClock.sleep(200); - mDanaRPump.lastConnection = System.currentTimeMillis(); - return new PumpEnactResult().success(true); - } - @Subscribe public void onStatusEvent(EventAppExit event) { if (Config.logFunctionCalls) @@ -423,4 +399,13 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService{ log.debug("EventAppExit finished"); } + public PumpEnactResult setUserOptions() { + if (!isConnected()) + return new PumpEnactResult().success(false); + SystemClock.sleep(300); + MsgSetUserOptions msg = new MsgSetUserOptions(); + mSerialIOThread.sendMessage(msg); + SystemClock.sleep(200); + return new PumpEnactResult().success(!msg.failed); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java index e46e3d6caf..7854426b5d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java @@ -327,4 +327,9 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { return true; } + @Override + public PumpEnactResult setUserOptions() { + return null; + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java index 83d6b24a6b..b4004fecb3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java @@ -391,15 +391,6 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { @Override public PumpEnactResult setUserOptions() { - DanaRv2ExecutionService service = new DanaRv2ExecutionService(); - log.debug("MsgSetUserOptions executed!"); - return service.setUserOptions(); + return sExecutionService.setUserOptions(); } - - public PumpEnactResult getUserOptions() { - DanaRv2ExecutionService service = new DanaRv2ExecutionService(); - log.debug("MsgGetUserOptions executed!"); - return service.getUserOptions(); - } - } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java index 0b646fde48..1ada4c629d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java @@ -18,8 +18,8 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgGetUserOptions; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingUserOptions; +import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetUserOptions; import info.nightscout.androidaps.plugins.Treatments.Treatment; import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventInitializationChanged; @@ -70,7 +70,6 @@ import info.nightscout.utils.DateUtil; import info.nightscout.utils.NSUpload; import info.nightscout.utils.SP; import info.nightscout.utils.T; -import info.nightscout.utils.ToastUtils; public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { @@ -201,8 +200,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { mSerialIOThread.sendMessage(new MsgSettingGlucose()); mSerialIOThread.sendMessage(new MsgSettingActiveProfile()); mSerialIOThread.sendMessage(new MsgSettingProfileRatios()); - //added by Roumen for testing - mSerialIOThread.sendMessage(new MsgGetUserOptions()); + mSerialIOThread.sendMessage(new MsgSettingUserOptions()); mSerialIOThread.sendMessage(new MsgSettingProfileRatiosAll()); MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime))); mSerialIOThread.sendMessage(new MsgSettingPumpTime()); @@ -477,38 +475,13 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { } public PumpEnactResult setUserOptions() { - if (!isConnected()) { - log.debug("MsgSetUserOptions - service is not connected"); -// return new PumpEnactResult().success(false); - connect(); - } + if (!isConnected()) + return new PumpEnactResult().success(false); SystemClock.sleep(300); - DanaRPump pump = DanaRPump.getInstance(); - MsgSettingUserOptions msg = new MsgSettingUserOptions(pump.timeDisplayType, pump.buttonScrollOnOff, pump.beepAndAlarm, pump.lcdOnTimeSec, pump.backlightOnTimeSec, pump.selectedLanguage, pump.units, pump.shutdownHour, pump.lowReservoirRate, 0, 0); - if (mSerialIOThread != null) { - mSerialIOThread.disconnect("MsgSetUserOptions - Recreate SerialIOThread"); - } - mSerialIOThread = new SerialIOThread(mRfcommSocket); - MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED, 0)); + MsgSetUserOptions msg = new MsgSetUserOptions(); mSerialIOThread.sendMessage(msg); - while (!msg.done && mRfcommSocket.isConnected()) { - SystemClock.sleep(100); - } SystemClock.sleep(200); - mDanaRPump.lastConnection = System.currentTimeMillis(); - return new PumpEnactResult().success(true); + return new PumpEnactResult().success(!msg.failed); } - public PumpEnactResult getUserOptions() { - if (!isConnected()) { - log.debug("MsgGetUserOptions fails - disconnected!"); - connect(); -// return new PumpEnactResult().success(false); - } - MsgGetUserOptions msg = new MsgGetUserOptions(); -// mSerialIOThread.sendMessage(msg); // == null - mDanaRPump.lastConnection = System.currentTimeMillis(); - log.debug("MsgGetUserOptions executed!"); - return new PumpEnactResult().success(true); - } } diff --git a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java index f76e6044aa..9f2fdf7eee 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java @@ -405,7 +405,7 @@ public class CommandQueue { } // returns true if command is queued - public boolean setUserSettings(Callback callback) { + public boolean setUserOptions(Callback callback) { if (isRunning(Command.CommandType.SETUSERSETTINGS)) { if (callback != null) callback.result(executingNowError()).run();