more debugging output

This commit is contained in:
Roumen Georgiev 2018-06-13 09:00:04 +03:00
parent 1adf8718ae
commit f1f8bae2d1
4 changed files with 70 additions and 39 deletions

View file

@ -11,25 +11,9 @@ import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
*/
public class MsgGetUserOptions extends MessageBase {
private int backlightOnTimeSec;
private int beepAndAlarm;
private int buttonScrollOnOff;
private int cannulaVolume;
private int glucoseUnit;
private int lcdOnTimeSec;
private int lowReservoirRate;
private int refillRate;
private int selectableLanguage1;
private int selectableLanguage2;
private int selectableLanguage3;
private int selectableLanguage4;
private int selectableLanguage5;
private int selectedLanguage;
private int shutdownHour;
private int timeDisplayType;
private static Logger log = LoggerFactory.getLogger(MsgGetUserOptions.class);
private byte[] optionsInPump;
public MsgGetUserOptions() {
SetCommand(0x320B);
}
@ -37,8 +21,9 @@ public class MsgGetUserOptions extends MessageBase {
public void handleMessage(byte[] packet) {
DanaRPump pump = DanaRPump.getInstance();
byte[] bytes = getDataBytes(packet, 0, packet.length - 10);
for(int pos=0; pos < bytes.length; pos++) {
log.debug("[" + pos + "]" + bytes[pos]);
this.optionsInPump = getDataBytes(packet, 0, packet.length - 10);
for(int pos=0; pos < packet.length; pos++) {
log.debug("[" + pos + "]" + packet[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
@ -69,6 +54,7 @@ public class MsgGetUserOptions extends MessageBase {
log.debug("Low reservoir: " + pump.lowReservoirRate);
// }
}
public static byte[] getDataBytes(byte[] bytes, int start, int len) {
if (bytes == null) {
return null;
@ -77,4 +63,6 @@ public class MsgGetUserOptions extends MessageBase {
System.arraycopy(bytes, start + 6, ret, 0, len);
return ret;
}
}

View file

@ -2,6 +2,7 @@ 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;
@ -22,7 +23,7 @@ public class MsgSettingUserOptions extends MessageBase {
private int selectedLanguage;
private int shutdownHour;
private int timeDisplayType;
byte[] newOptions;
public boolean done;
public MsgSettingUserOptions(int timeDisplayType, int buttonScrollOnOff, int beepAndAlarm, int lcdOnTimeSec, int backlightOnTimeSec, int selectedLanguage, int glucoseUnit, int shutdownHour, int lowReservoirRate, int cannulaVolume, int refillRate) {
@ -48,17 +49,19 @@ public class MsgSettingUserOptions extends MessageBase {
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
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);
// 6 extended bolus on/off
// 10 missed bolus
}
private static Logger log = LoggerFactory.getLogger(MsgSettingUserOptions.class);
@ -69,6 +72,7 @@ public class MsgSettingUserOptions extends MessageBase {
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;
@ -79,4 +83,49 @@ public class MsgSettingUserOptions 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;
}
}

View file

@ -392,7 +392,6 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
@Override
public PumpEnactResult setUserOptions() {
DanaRv2ExecutionService service = new DanaRv2ExecutionService();
log.debug("MsgSetUserOptions executed!");
return service.setUserOptions();
}

View file

@ -201,7 +201,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
mSerialIOThread.sendMessage(new MsgSettingGlucose());
mSerialIOThread.sendMessage(new MsgSettingActiveProfile());
mSerialIOThread.sendMessage(new MsgSettingProfileRatios());
//added by Roumen for testing
//added by Roumen for testing and
mSerialIOThread.sendMessage(new MsgGetUserOptions());
mSerialIOThread.sendMessage(new MsgSettingProfileRatiosAll());
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime)));
@ -478,9 +478,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
public PumpEnactResult setUserOptions() {
if (!isConnected()) {
log.debug("MsgSetUserOptions - service is not connected");
// return new PumpEnactResult().success(false);
connect();
return new PumpEnactResult().success(false);
}
SystemClock.sleep(300);
DanaRPump pump = DanaRPump.getInstance();
@ -501,14 +499,11 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
public PumpEnactResult getUserOptions() {
if (!isConnected()) {
log.debug("MsgGetUserOptions fails - disconnected!");
connect();
// return new PumpEnactResult().success(false);
return new PumpEnactResult().success(false);
}
MsgGetUserOptions msg = new MsgGetUserOptions();
// mSerialIOThread.sendMessage(msg); // == null
mSerialIOThread.sendMessage(msg);
mDanaRPump.lastConnection = System.currentTimeMillis();
log.debug("MsgGetUserOptions executed!");
return new PumpEnactResult().success(true);
}
}