Merge pull request #1099 from PoweRGbg/dev

getting userOptions from v2 works
This commit is contained in:
Milos Kozak 2018-06-12 18:29:14 +02:00 committed by GitHub
commit b5eff7baab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 165 additions and 37 deletions

View file

@ -9,5 +9,5 @@ import info.nightscout.androidaps.data.PumpEnactResult;
public interface DanaRInterface {
PumpEnactResult loadHistory(byte type); // for history browser
PumpEnactResult loadEvents(); // events history to build treatments from
PumpEnactResult setUserSettings(); // like AnyDana does
PumpEnactResult setUserOptions(); // like AnyDana does
}

View file

@ -381,7 +381,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
}
@Override
public PumpEnactResult setUserSettings() {
public PumpEnactResult setUserOptions() {
return null;
}
}

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,13 +96,42 @@ 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);
shutdown.setParams((double) pump.shutdownHour, 0d, 24d, 1d, new DecimalFormat("1"), true);
lowReservoir.setParams((double) pump.lowReservoirRate, 10d, 60d, 10d, new DecimalFormat("10"), false);
switch (pump.beepAndAlarm) {
case 1: pumpAlarmSound.setChecked(true);
break;
case 2: pumpAlarmVibrate.setChecked(true);
break;
case 3: pumpAlarmBoth.setChecked(true);
break;
case 5: pumpAlarmSound.setChecked(true);
beep.setChecked(true);
break;
case 6: pumpAlarmVibrate.setChecked(true);
beep.setChecked(true);
break;
case 7: pumpAlarmBoth.setChecked(true);
beep.setChecked(true);
break;
}
if (pump.lastSettingsRead == 0)
log.debug("No settings loaded from pump!");
else
@ -111,9 +141,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 > 4);
screenTimeout.setValue((double) pump.lcdOnTimeSec);
backlightTimeout.setValue((double) pump.backlightOnTimeSec);
pumpUnits.setChecked(pump.getUnits() != null && pump.getUnits().equals(Constants.MMOL));
@ -128,10 +158,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 +178,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,18 +193,22 @@ 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
pump.lowReservoirRate = 10;
if (isDanaRv2) {
DanaRv2Plugin.getPlugin().setUserOptions();
}
MainApp.getConfigBuilder().getCommandQueue().setUserSettings(null);
finish();
}

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,20 @@ 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);
for(int pos=0; pos < bytes.length; pos++) {
log.debug("[" + pos + "]" + bytes[pos]);
}
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 +56,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 +67,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

@ -4,11 +4,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
/**
* Created by mike on 05.07.2016.
@ -32,6 +27,16 @@ public class MsgSettingUserOptions extends MessageBase {
public MsgSettingUserOptions(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;
@ -43,7 +48,8 @@ public class MsgSettingUserOptions extends MessageBase {
this.lowReservoirRate = lowReservoirRate;
this.cannulaVolume = cannulaVolume;
this.refillRate = refillRate;
// need to organize here
// glucoseunit is at pos 8 and lowReservoirRate is at pos 27
AddParamByte((byte) timeDisplayType);
AddParamByte((byte) buttonScrollOnOff);
AddParamByte((byte) beepAndAlarm);
@ -62,6 +68,7 @@ public class MsgSettingUserOptions extends MessageBase {
}
public void handleMessage(byte[] bytes) {
log.debug("Entering handleMessage ");
int result = intFromBuff(bytes, 0, 1);
if (result != 1) {
failed = true;

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

@ -382,7 +382,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
}
@Override
public PumpEnactResult setUserSettings() {
public PumpEnactResult setUserOptions() {
return null;
}
}

View file

@ -224,7 +224,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
}
@Override
public PumpEnactResult setUserSettings() {
public PumpEnactResult setUserOptions() {
return danaRSService.setUserSettings();
}

View file

@ -390,8 +390,16 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
}
@Override
public PumpEnactResult setUserSettings() {
return null;
public PumpEnactResult setUserOptions() {
DanaRv2ExecutionService service = new DanaRv2ExecutionService();
log.debug("MsgSetUserOptions executed!");
return service.setUserOptions();
}
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());
@ -473,12 +476,20 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
}
}
public PumpEnactResult updateUserSettings() {
if (!isConnected())
return new PumpEnactResult().success(false);
public PumpEnactResult setUserOptions() {
if (!isConnected()) {
log.debug("MsgSetUserOptions - service is not connected");
// return new PumpEnactResult().success(false);
connect();
}
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);
if (mSerialIOThread != null) {
mSerialIOThread.disconnect("MsgSetUserOptions - Recreate SerialIOThread");
}
mSerialIOThread = new SerialIOThread(mRfcommSocket);
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED, 0));
mSerialIOThread.sendMessage(msg);
while (!msg.done && mRfcommSocket.isConnected()) {
SystemClock.sleep(100);
@ -487,4 +498,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,15 @@
package info.nightscout.androidaps.queue.commands;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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;
/**
@ -11,7 +17,7 @@ import info.nightscout.androidaps.queue.Callback;
*/
public class CommandSetUserSettings extends Command {
private static Logger log = LoggerFactory.getLogger(CommandSetUserSettings.class);
public CommandSetUserSettings(Callback callback) {
commandType = CommandType.SETUSERSETTINGS;
this.callback = callback;
@ -22,7 +28,11 @@ public class CommandSetUserSettings extends Command {
PumpInterface pump = ConfigBuilderPlugin.getActivePump();
if (pump instanceof DanaRInterface) {
DanaRInterface danaPump = (DanaRInterface) pump;
PumpEnactResult r = danaPump.setUserSettings();
boolean isDanaRv2 = MainApp.getSpecificPlugin(DanaRv2Plugin.class) != null && MainApp.getSpecificPlugin(DanaRv2Plugin.class).isEnabled(PluginType.PUMP);
if(isDanaRv2){
log.debug("MsgSetUserOptions detected for DanaRv2");
}
PumpEnactResult r = danaPump.setUserOptions();
if (callback != null)
callback.result(r).run();
}