getting userOptions from v2

This commit is contained in:
Roumen Georgiev 2018-06-12 10:29:47 +03:00
parent 2441214bb8
commit 01012d817c
8 changed files with 113 additions and 27 deletions

View file

@ -21,9 +21,11 @@ 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;
@ -81,8 +83,7 @@ public class DanaRUserOptionsActivity extends Activity {
saveToPumpButton.setOnClickListener(v -> onSaveClick());
boolean isKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class) != null && MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginType.PUMP);
boolean isRS = MainApp.getSpecificPlugin(DanaRSPlugin.class) != null && MainApp.getSpecificPlugin(DanaRSPlugin.class).isEnabled(PluginType.PUMP);
boolean isv2 = MainApp.getSpecificPlugin(DanaRv2Plugin.class) != null && MainApp.getSpecificPlugin(DanaRv2Plugin.class).isEnabled(PluginType.PUMP);
DanaRPump pump = DanaRPump.getInstance();
@ -95,7 +96,20 @@ 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);
@ -111,9 +125,9 @@ public class DanaRUserOptionsActivity extends Activity {
public void setData() {
DanaRPump pump = DanaRPump.getInstance();
timeFormat.setChecked(pump.timeDisplayType == 0);
timeFormat.setChecked(pump.timeDisplayType != 0);
buttonScroll.setChecked(pump.buttonScrollOnOff != 0);
beep.setChecked(pump.beepAndAlarm != 0);
beep.setChecked(pump.beepAndAlarm < 5);
screenTimeout.setValue((double) pump.lcdOnTimeSec);
backlightTimeout.setValue((double) pump.backlightOnTimeSec);
pumpUnits.setChecked(pump.getUnits() != null && pump.getUnits().equals(Constants.MMOL));
@ -128,10 +142,15 @@ public class DanaRUserOptionsActivity extends Activity {
public void onSaveClick() {
boolean isRS = MainApp.getSpecificPlugin(DanaRSPlugin.class) != null && MainApp.getSpecificPlugin(DanaRSPlugin.class).isEnabled(PluginType.PUMP);
if (!isRS) {
//exit if pump is not DanaRS
boolean isDanaR = MainApp.getSpecificPlugin(DanaRPlugin.class) != null && MainApp.getSpecificPlugin(DanaRPlugin.class).isEnabled(PluginType.PUMP);
boolean isDanaRv2 = MainApp.getSpecificPlugin(DanaRv2Plugin.class) != null && MainApp.getSpecificPlugin(DanaRv2Plugin.class).isEnabled(PluginType.PUMP);
if (!isRS && !isDanaR && !isDanaRv2) {
//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())
@ -143,13 +162,13 @@ public class DanaRUserOptionsActivity extends Activity {
else
pump.buttonScrollOnOff = 0;
// step is 5 seconds
int screenTimeoutValue = (Integer.parseInt(screenTimeout.getText().toString()) / 5) * 5;
int screenTimeoutValue = !screenTimeout.getText().isEmpty() ? (Integer.parseInt(screenTimeout.getText().toString()) / 5) * 5: 5;
if (screenTimeoutValue > 4 && screenTimeoutValue < 241) {
pump.lcdOnTimeSec = screenTimeoutValue;
} else {
pump.lcdOnTimeSec = 5;
}
int backlightTimeoutValue = Integer.parseInt(backlightTimeout.getText().toString());
int backlightTimeoutValue = !backlightTimeout.getText().isEmpty() ? Integer.parseInt(backlightTimeout.getText().toString()): 1;
if (backlightTimeoutValue > 0 && backlightTimeoutValue < 61) {
pump.backlightOnTimeSec = backlightTimeoutValue;
}
@ -158,13 +177,13 @@ public class DanaRUserOptionsActivity extends Activity {
} else {
pump.units = 0;
}
int shutDownValue = Integer.parseInt(shutdown.getText().toString());
int shutDownValue = !shutdown.getText().isEmpty() ? Integer.parseInt(shutdown.getText().toString()) : 0;
if (shutDownValue > -1 && shutDownValue < 25) {
pump.shutdownHour = shutDownValue;
} else {
pump.shutdownHour = 0;
}
int lowReservoirValue = (Integer.parseInt(lowReservoir.getText().toString()) * 10) / 10;
int lowReservoirValue = !lowReservoir.getText().isEmpty() ? (Integer.parseInt(lowReservoir.getText().toString()) * 10) / 10 : 10;
if (lowReservoirValue > 9 && lowReservoirValue < 51) {
pump.lowReservoirRate = lowReservoirValue;
} else

View file

@ -56,6 +56,7 @@ public class MessageHashTable {
put(new MsgSettingGlucose()); // 0x3209 CMD_SETTING_V_GLUCOSEandEASY
put(new MsgSettingPumpTime()); // 0x320A CMD_SETTING_V_TIME_I
put(new MsgSettingUserOptions()); // 0x320B CMD_SETTING_V_USER_OPTIONS
put(new MsgGetUserOptions()); // 0x320B CMD_SETTING_V_USER_OPTIONS - trying to get uptions
put(new MsgSettingActiveProfile()); // 0x320C CMD_SETTING_V_PROFILE_NUMBER
put(new MsgSettingProfileRatiosAll()); // 0x320D CMD_SETTING_V_CIR_CF_VALUE
put(new MsgSetSingleBasalProfile()); // 0x3302 CMD_SETTING_BASAL_INS_S

View file

@ -34,16 +34,17 @@ public class MsgGetUserOptions extends MessageBase {
SetCommand(0x320B);
}
public void handleMessage(byte[] bytes) {
public void handleMessage(byte[] packet) {
DanaRPump pump = DanaRPump.getInstance();
pump.timeDisplayType = bytes[0] == (byte) 1 ? 0 : 1;
pump.buttonScrollOnOff = bytes[1];
pump.beepAndAlarm = bytes[2];
byte[] bytes = getDataBytes(packet, 0, packet.length - 10);
pump.timeDisplayType = bytes[0] == (byte) 1 ? 0 : 1; // 1 -> 24h 0 -> 12h
pump.buttonScrollOnOff = bytes[1] == (byte) 1 ? 1 : 0; // 1 -> ON, 0-> OFF
pump.beepAndAlarm = bytes[2]; // 1 -> Sound on alarm 2-> Vibrate on alarm 3-> Both on alarm 5-> Sound + beep 6-> vibrate + beep 7-> both + beep Beep adds 4
pump.lcdOnTimeSec = bytes[3] & 255;
pump.backlightOnTimeSec = bytes[4] & 255;
pump.selectedLanguage = bytes[5];
pump.selectedLanguage = bytes[5]; // on DanaRv2 is that needed ?
pump.units = bytes[8];
pump.shutdownHour = bytes[9] & 255;
pump.shutdownHour = bytes[9];
pump.lowReservoirRate = bytes[32] & 255;
/* int selectableLanguage1 = bytes[10];
int selectableLanguage2 = bytes[11];
@ -52,7 +53,8 @@ public class MsgGetUserOptions extends MessageBase {
int selectableLanguage5 = bytes[14];
*/
if (Config.logDanaMessageDetail) {
// if (Config.logDanaMessageDetail) {
log.debug("timeDisplayType: " + pump.timeDisplayType);
log.debug("Button scroll: " + pump.buttonScrollOnOff);
log.debug("BeepAndAlarm: " + pump.beepAndAlarm);
@ -62,6 +64,14 @@ public class MsgGetUserOptions extends MessageBase {
log.debug("Units: " + pump.getUnits());
log.debug("Shutdown: " + pump.shutdownHour);
log.debug("Low reservoir: " + pump.lowReservoirRate);
// }
}
public static byte[] getDataBytes(byte[] bytes, int start, int len) {
if (bytes == null) {
return null;
}
byte[] ret = new byte[len];
System.arraycopy(bytes, start + 6, ret, 0, len);
return ret;
}
}

View file

@ -44,15 +44,15 @@ public class MsgSettingUserOptions extends MessageBase {
this.cannulaVolume = cannulaVolume;
this.refillRate = refillRate;
AddParamByte((byte) timeDisplayType);
AddParamByte((byte) buttonScrollOnOff);
AddParamByte((byte) beepAndAlarm);
AddParamByte((byte) lcdOnTimeSec);
AddParamByte((byte) backlightOnTimeSec);
AddParamByte((byte) selectedLanguage);
AddParamByte((byte) glucoseUnit);
AddParamByte((byte) shutdownHour);
AddParamByte((byte) lowReservoirRate);
AddParamInt(timeDisplayType);
AddParamInt(buttonScrollOnOff);
AddParamInt(beepAndAlarm);
AddParamInt(lcdOnTimeSec);
AddParamInt(backlightOnTimeSec);
AddParamInt(selectedLanguage);
AddParamInt(glucoseUnit);
AddParamInt(shutdownHour);
AddParamInt(lowReservoirRate);
}
private static Logger log = LoggerFactory.getLogger(MsgSettingUserOptions.class);

View file

@ -18,6 +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.Treatments.Treatment;
import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventInitializationChanged;
@ -382,6 +384,30 @@ 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)

View file

@ -394,4 +394,10 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
return null;
}
public PumpEnactResult getUserOptions() {
DanaRv2ExecutionService service = new DanaRv2ExecutionService();
log.debug("MsgGetUserOptions executed!");
return service.getUserOptions();
}
}

View file

@ -18,6 +18,7 @@ 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.Treatments.Treatment;
import info.nightscout.androidaps.events.EventAppExit;
@ -200,6 +201,8 @@ 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 MsgSettingProfileRatiosAll());
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime)));
mSerialIOThread.sendMessage(new MsgSettingPumpTime());
@ -477,7 +480,8 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
if (!isConnected())
return new PumpEnactResult().success(false);
SystemClock.sleep(300);
MsgSettingUserOptions msg;
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()) {
@ -487,4 +491,17 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
mDanaRPump.lastConnection = System.currentTimeMillis();
return new PumpEnactResult().success(true);
}
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);
}
}

View file

@ -1,9 +1,12 @@
package info.nightscout.androidaps.queue.commands;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.interfaces.DanaRInterface;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
import info.nightscout.androidaps.queue.Callback;
/**
@ -22,6 +25,10 @@ public class CommandSetUserSettings extends Command {
PumpInterface pump = ConfigBuilderPlugin.getActivePump();
if (pump instanceof DanaRInterface) {
DanaRInterface danaPump = (DanaRInterface) pump;
boolean isDanaRv2 = MainApp.getSpecificPlugin(DanaRv2Plugin.class) != null && MainApp.getSpecificPlugin(DanaRv2Plugin.class).isEnabled(PluginType.PUMP);
if(isDanaRv2){
pump.getPumpStatus();
}
PumpEnactResult r = danaPump.setUserSettings();
if (callback != null)
callback.result(r).run();