medtronic-0.11.6-SNAPSHOT

- fixed problem with GettingBasal
- fixed problem with writing data into logs
This commit is contained in:
Andy Rozman 2019-06-26 23:02:35 +01:00
parent 570e93273c
commit f0b8aefc14
16 changed files with 109 additions and 80 deletions

View file

@ -105,7 +105,7 @@ android {
multiDexEnabled true
versionCode 1500
// dev_version: 2.3.1-dev
version "medtronic-0.11.5-SNAPSHOT"
version "medtronic-0.11.6-SNAPSHOT"
buildConfigField "String", "VERSION", '"' + version + '"'
buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"'
buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"'

View file

@ -156,7 +156,7 @@ public class MainApp extends Application {
File engineeringModeSemaphore = new File(extFilesDir, "engineering_mode");
engineeringMode = engineeringModeSemaphore.exists() && engineeringModeSemaphore.isFile();
devBranch = BuildConfig.VERSION.contains("dev") || BuildConfig.DEV_VERSION.contains("dev");
devBranch = BuildConfig.VERSION.contains("dev");
sBus = L.isEnabled(L.EVENTS) && devBranch ? new LoggingBus(ThreadEnforcer.ANY) : new Bus(ThreadEnforcer.ANY);

View file

@ -129,7 +129,7 @@ public class RFSpy {
byte[] response = writeToDataRaw(getVersionRaw, 5000);
if (isLogEnabled())
LOG.debug("Firmware Version. GetVersion [response={}]", ByteUtil.getHex(response));
LOG.debug("Firmware Version. GetVersion [response={}]", ByteUtil.shortHexString(response));
if (response != null) { // && response[0] == (byte) 0xDD) {
@ -172,7 +172,7 @@ public class RFSpy {
// prepend length, and send it.
byte[] prepended = ByteUtil.concat(new byte[]{(byte) (bytes.length)}, bytes);
LOG.debug("writeToData (raw={})", ByteUtil.getHex(prepended));
LOG.debug("writeToData (raw={})", ByteUtil.shortHexString(prepended));
BLECommOperationResult writeCheck = rileyLinkBle.writeCharacteristic_blocking(radioServiceUUID, radioDataUUID,
prepended);

View file

@ -71,7 +71,7 @@ public class RileyLinkBLE {
+ GattAttributes.lookup(characteristic.getUuid()) + " "
+ ByteUtil.getHex(characteristic.getValue()));
if (characteristic.getUuid().equals(UUID.fromString(GattAttributes.CHARA_RADIO_RESPONSE_COUNT))) {
LOG.debug("Response Count is " + ByteUtil.getHex(characteristic.getValue()));
LOG.debug("Response Count is " + ByteUtil.shortHexString(characteristic.getValue()));
}
}
if (radioResponseCountNotified != null) {
@ -103,7 +103,7 @@ public class RileyLinkBLE {
final String uuidString = GattAttributes.lookup(characteristic.getUuid());
if (gattDebugEnabled && isLogEnabled()) {
LOG.trace(ThreadUtil.sig() + "onCharacteristicWrite " + getGattStatusMessage(status) + " "
+ uuidString + " " + ByteUtil.getHex(characteristic.getValue()));
+ uuidString + " " + ByteUtil.shortHexString(characteristic.getValue()));
}
mCurrentOperation.gattOperationCompletionCallback(characteristic.getUuid(), characteristic.getValue());
}

View file

@ -1,11 +1,11 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.encoding;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkCommunicationException;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkBLEError;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
@ -40,7 +40,7 @@ public class Encoding4b6bGeoff extends Encoding4b6bAbstract {
bitcount += 6;
while (bitcount >= 8) {
byte outByte = (byte)(acc >> (bitcount - 8) & 0xff);
byte outByte = (byte) (acc >> (bitcount - 8) & 0xff);
outData.add(outByte);
bitcount -= 8;
acc &= (0xffff >> (16 - bitcount));
@ -51,13 +51,13 @@ public class Encoding4b6bGeoff extends Encoding4b6bAbstract {
acc |= 0x14; // marks uneven packet boundary.
bitcount += 6;
if (bitcount >= 8) {
byte outByte = (byte)((acc >> (bitcount - 8)) & 0xff);
byte outByte = (byte) ((acc >> (bitcount - 8)) & 0xff);
outData.add(outByte);
bitcount -= 8;
// acc &= (0xffff >> (16 - bitcount));
}
while (bitcount >= 8) {
outData.add((byte)0);
outData.add((byte) 0);
bitcount -= 8;
}
}
@ -81,13 +81,13 @@ public class Encoding4b6bGeoff extends Encoding4b6bAbstract {
StringBuilder errorMessageBuilder = new StringBuilder();
errorMessageBuilder.append("Input data: " + ByteUtil.getHex(raw) + "\n");
errorMessageBuilder.append("Input data: " + ByteUtil.shortHexString(raw) + "\n");
if ((raw.length % 2) != 0) {
errorMessageBuilder.append("Warn: odd number of bytes.\n");
}
byte[] rval = new byte[] {};
byte[] rval = new byte[]{};
int availableBits = 0;
int codingErrors = 0;
int x = 0;
@ -103,13 +103,13 @@ public class Encoding4b6bGeoff extends Encoding4b6bAbstract {
if (availableBits >= 12) {
// take top six
int highcode = (x >> (availableBits - 6)) & 0x3F;
int highIndex = encode4b6bListIndex((byte)(highcode));
int highIndex = encode4b6bListIndex((byte) (highcode));
// take bottom six
int lowcode = (x >> (availableBits - 12)) & 0x3F;
int lowIndex = encode4b6bListIndex((byte)(lowcode));
int lowIndex = encode4b6bListIndex((byte) (lowcode));
// special case at end of transmission on uneven boundaries:
if ((highIndex >= 0) && (lowIndex >= 0)) {
byte decoded = (byte)((highIndex << 4) + lowIndex);
byte decoded = (byte) ((highIndex << 4) + lowIndex);
rval = ByteUtil.concat(rval, decoded);
/*
* LOG.debug(String.format(
@ -122,8 +122,8 @@ public class Encoding4b6bGeoff extends Encoding4b6bAbstract {
} else {
// LOG.debug(String.format("i=%d,x=%08X, coding error: highcode=0x%02X, lowcode=0x%02X, %d bits remaining",i,x,highcode,lowcode,availableBits));
errorMessageBuilder.append(String.format(
"decode4b6b: i=%d,x=%08X, coding error: highcode=0x%02X, lowcode=0x%02X, %d bits remaining.\n",
i, x, highcode, lowcode, availableBits));
"decode4b6b: i=%d,x=%08X, coding error: highcode=0x%02X, lowcode=0x%02X, %d bits remaining.\n",
i, x, highcode, lowcode, availableBits));
codingErrors++;
}
@ -139,7 +139,7 @@ public class Encoding4b6bGeoff extends Encoding4b6bAbstract {
// LOG.error("decode4b6b: failed clean decode -- extra bits available (not marker)(" + availableBits +
// ")");
errorMessageBuilder.append("decode4b6b: failed clean decode -- extra bits available (not marker)("
+ availableBits + ")\n");
+ availableBits + ")\n");
codingErrors++;
}
} else {

View file

@ -107,6 +107,17 @@ public class ByteUtil {
return rval;
}
public static String shortHexString(List<Byte> list) {
byte[] abyte0 = getByteArrayFromList(list);
return shortHexString(abyte0);
}
public static String shortHexString(byte val) {
return getHexCompact(val);
}
public static String showPrintable(byte[] ra) {
String s = new String();
@ -323,7 +334,7 @@ public class ByteUtil {
if (abyte0 != null) {
i = Math.min(i, abyte0.length);
for (int j = 0; j < i; j++) {
stringbuffer.append(getHex(abyte0[j]));
stringbuffer.append(shortHexString(abyte0[j]));
if (j < i - 1) {
stringbuffer.append(" ");
}

View file

@ -644,7 +644,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
if (contents != null) {
if (contents.length >= expectedLength) {
LOG.trace("{}: Content: {}", method, ByteUtil.getHex(contents));
LOG.trace("{}: Content: {}", method, ByteUtil.shortHexString(contents));
return null;
} else {
@ -722,7 +722,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
if (check == null) {
data = response.getRawContent();
data = response.getRawContentOfFrame();
PumpMessage ackMsg = makePumpMessage(MedtronicCommandType.CommandACK, new PumpAckMessageBody());
@ -740,7 +740,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
if (check2 == null) {
data = ByteUtil.concat(data, ByteUtil.substring(response2.getMessageBody().getTxData(), 1));
data = ByteUtil.concat(data, response2.getRawContentOfFrame());
} else {
this.errorMessage = check2;
@ -755,13 +755,15 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
BasalProfile basalProfile = (BasalProfile) medtronicConverter.convertResponse(commandType, data);
if (isLogEnabled())
LOG.debug("Converted response for {} is {}.", commandType.name(), basalProfile);
if (basalProfile != null) {
if (isLogEnabled())
LOG.debug("Converted response for {} is {}.", commandType.name(), basalProfile);
MedtronicUtil.setCurrentCommand(null);
MedtronicUtil.setPumpDeviceState(PumpDeviceState.Sleeping);
MedtronicUtil.setCurrentCommand(null);
MedtronicUtil.setPumpDeviceState(PumpDeviceState.Sleeping);
return basalProfile;
return basalProfile;
}
} catch (RileyLinkCommunicationException e) {
LOG.error("Error getting response from RileyLink (error={}, retry={})", e.getMessage(), retries + 1);
@ -953,7 +955,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
LOG.warn("Error getting response from RileyLink (error={}, retry={})", e.getMessage(), retries + 1);
}
LOG.warn("Set Basal Profile: Invalid response: commandType={},rawData={}", responseMessage.commandType, ByteUtil.getHex(responseMessage.getRawContent()));
LOG.warn("Set Basal Profile: Invalid response: commandType={},rawData={}", responseMessage.commandType, ByteUtil.shortHexString(responseMessage.getRawContent()));
}
return false;

View file

@ -41,7 +41,7 @@ public class MedtronicConverter {
}
if (isLogEnabled())
LOG.debug("Raw response before convert: " + ByteUtil.getHex(rawContent));
LOG.debug("Raw response before convert: " + ByteUtil.shortHexString(rawContent));
this.pumpModel = MedtronicUtil.getMedtronicPumpModel();

View file

@ -135,7 +135,7 @@ public abstract class MedtronicHistoryEntry implements MedtronicHistoryEntryInte
public Object getDecodedDataEntry(String key) {
return this.decodedData.get(key);
return this.decodedData != null ? this.decodedData.get(key) : null;
}
@ -197,21 +197,21 @@ public abstract class MedtronicHistoryEntry implements MedtronicHistoryEntryInte
if (head != null) {
sb.append(", head=");
sb.append(ByteUtil.getHex(this.head));
sb.append(ByteUtil.shortHexString(this.head));
}
if (datetime != null) {
sb.append(", datetime=");
sb.append(ByteUtil.getHex(this.datetime));
sb.append(ByteUtil.shortHexString(this.datetime));
}
if (body != null) {
sb.append(", body=");
sb.append(ByteUtil.getHex(this.body));
sb.append(ByteUtil.shortHexString(this.body));
}
sb.append(", rawData=");
sb.append(ByteUtil.getHex(this.rawData));
sb.append(ByteUtil.shortHexString(this.rawData));
sb.append("]");
// sb.append(" DT: ");
@ -297,7 +297,7 @@ public abstract class MedtronicHistoryEntry implements MedtronicHistoryEntryInte
if (head == null) {
return "Unidentified record. ";
} else {
return "HistoryRecord: head=[" + ByteUtil.getHex(this.head) + "]";
return "HistoryRecord: head=[" + ByteUtil.shortHexString(this.head) + "]";
}
}

View file

@ -116,7 +116,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
listRawData.add(dataClear.get(counter));
counter++;
} catch (Exception ex) {
LOG.error("OpCode: " + ByteUtil.getHex((byte) opCode) + ", Invalid package: "
LOG.error("OpCode: " + ByteUtil.shortHexString((byte) opCode) + ", Invalid package: "
+ ByteUtil.getHex(listRawData));
// throw ex;
incompletePacket = true;

View file

@ -67,9 +67,20 @@ public class PumpHistoryEntry extends MedtronicHistoryEntry {
@Override
public String getToStringStart() {
return "PumpHistoryRecord [type=" + StringUtil.getStringInLength(entryType.name(), 20) + " ["
return "PumpHistoryEntry [type=" + StringUtil.getStringInLength(entryType.name(), 20) + " ["
+ StringUtil.getStringInLength("" + getOpCode(), 3) + ", 0x"
+ ByteUtil.getHex((byte) getOpCode()) + "]";
+ ByteUtil.shortHexString((byte) getOpCode()) + "]";
}
public String toString() {
Object object = this.getDecodedDataEntry("Object");
if (object == null) {
return super.toString();
} else {
return "PumpHistoryEntry [DT: " + DT + ", Object=" + object.toString() + "]";
}
}

View file

@ -25,7 +25,7 @@ public class MessageBody {
StringBuilder sb = new StringBuilder(getClass().getSimpleName());
sb.append(" [txData=");
sb.append(ByteUtil.getHex(getTxData()));
sb.append(ByteUtil.shortHexString(getTxData()));
sb.append("]");
return sb.toString();

View file

@ -129,6 +129,11 @@ public class PumpMessage implements RLMessage {
return arrayOut;
}
public byte[] getRawContentOfFrame() {
byte[] raw = getRawContent();
return ByteUtil.substring(raw, 0, raw.length - 1);
}
public boolean isValid() {
if (packetType == null)
@ -169,7 +174,7 @@ public class PumpMessage implements RLMessage {
if (showData) {
sb.append(", rawResponse=");
sb.append(ByteUtil.getHex(getRawContent()));
sb.append(ByteUtil.shortHexString(getRawContent()));
}
sb.append("]");
@ -185,7 +190,7 @@ public class PumpMessage implements RLMessage {
sb.append(packetType == null ? "null" : packetType.name());
sb.append(", address=(");
sb.append(ByteUtil.getHex(this.address));
sb.append(ByteUtil.shortHexString(this.address));
sb.append("), commandType=");
sb.append(commandType == null ? "null" : commandType.name());

View file

@ -231,7 +231,7 @@ public class BasalProfile {
try {
entries.add(new BasalProfileEntry(r, st));
} catch (Exception ex) {
LOG.error("Error decoding basal profile from bytes: {}", ByteUtil.getHex(mRawData));
LOG.error("Error decoding basal profile from bytes: {}", ByteUtil.shortHexString(mRawData));
throw ex;
}
@ -282,7 +282,7 @@ public class BasalProfile {
} catch (Exception ex) {
LOG.error("=============================================================================");
LOG.error(" Error generating entries. Ex.: " + ex, ex);
LOG.error(" rawBasalValues: " + ByteUtil.getHex(this.getRawData()));
LOG.error(" rawBasalValues: " + ByteUtil.shortHexString(this.getRawData()));
LOG.error("=============================================================================");
//FabricUtil.createEvent("MedtronicBasalProfileGetByHourError", null);

View file

@ -1,11 +1,11 @@
package info.nightscout.androidaps.plugins.pump.medtronic.data.dto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
import com.google.gson.annotations.Expose;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.db.TDD;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
@ -100,15 +100,15 @@ public class DailyTotalsDTO {
this.entry.setDisplayableValue("Total Insulin: " + StringUtil.getFormatedValueUS(this.insulinTotal, 2));
} else {
this.entry.setDisplayableValue("Basal Insulin: " + StringUtil.getFormatedValueUS(this.insulinBasal, 2)
+ ", Total Insulin: " + StringUtil.getFormatedValueUS(this.insulinTotal, 2));
+ ", Total Insulin: " + StringUtil.getFormatedValueUS(this.insulinTotal, 2));
}
}
private void decodeEndResultsTotals(PumpHistoryEntry entry) {
double totals = ByteUtil.toInt((int)entry.getHead()[0], (int)entry.getHead()[1], (int)entry.getHead()[2],
(int)entry.getHead()[3], ByteUtil.BitConversion.BIG_ENDIAN) * 0.025d;
double totals = ByteUtil.toInt((int) entry.getHead()[0], (int) entry.getHead()[1], (int) entry.getHead()[2],
(int) entry.getHead()[3], ByteUtil.BitConversion.BIG_ENDIAN) * 0.025d;
this.insulinTotal = totals;
@ -132,11 +132,11 @@ public class DailyTotalsDTO {
int k1 = ByteUtil.toInt(body[i + 2], body[i + 1], body[i]);
System.out.println(String.format(
"index: %d, number=%d, del/40=%.3f, del/10=%.3f, singular=%d, sing_hex=%s", i, j, j / 40.0d, j / 10.0d,
body[i], ByteUtil.getHex(body[i])));
"index: %d, number=%d, del/40=%.3f, del/10=%.3f, singular=%d, sing_hex=%s", i, j, j / 40.0d, j / 10.0d,
body[i], ByteUtil.shortHexString(body[i])));
System.out.println(String.format(" number[k,j1,k1]=%d / %d /%d, del/40=%.3f, del/40=%.3f, del/40=%.3f",
k, j1, k1, k / 40.0d, j1 / 40.0d, k1 / 40.0d));
k, j1, k1, k / 40.0d, j1 / 40.0d, k1 / 40.0d));
}
}
@ -214,31 +214,31 @@ public class DailyTotalsDTO {
@Override
public String toString() {
return MoreObjects.toStringHelper(this) //
.add("bgAvg", bgAvg) //
.add("bgLow", bgLow) //
.add("bgHigh", bgHigh) //
.add("bgCount", bgCount) //
.add("sensorAvg", sensorAvg) //
.add("sensorMin", sensorMin) //
.add("sensorMax", sensorMax) //
.add("sensorCalcCount", sensorCalcCount) //
.add("sensorDataCount", sensorDataCount) //
.add("insulinTotal", insulinTotal) //
.add("insulinBasal", insulinBasal) //
.add("insulinBolus", insulinBolus) //
.add("insulinCarbs", insulinCarbs) //
.add("bolusTotal", bolusTotal) //
.add("bolusFood", bolusFood) //
.add("bolusCorrection", bolusCorrection) //
.add("bolusManual", bolusManual) //
.add("bolusCount", bolusCount) //
.add("bolusCountFoodOrCorr", bolusCountFoodOrCorr) //
.add("bolusCountFoodAndCorr", bolusCountFoodAndCorr) //
.add("bolusCountFood", bolusCountFood) //
.add("bolusCountCorr", bolusCountCorr) //
.add("bolusCountManual", bolusCountManual) //
.omitNullValues() //
.toString();
.add("bgAvg", bgAvg) //
.add("bgLow", bgLow) //
.add("bgHigh", bgHigh) //
.add("bgCount", bgCount) //
.add("sensorAvg", sensorAvg) //
.add("sensorMin", sensorMin) //
.add("sensorMax", sensorMax) //
.add("sensorCalcCount", sensorCalcCount) //
.add("sensorDataCount", sensorDataCount) //
.add("insulinTotal", insulinTotal) //
.add("insulinBasal", insulinBasal) //
.add("insulinBolus", insulinBolus) //
.add("insulinCarbs", insulinCarbs) //
.add("bolusTotal", bolusTotal) //
.add("bolusFood", bolusFood) //
.add("bolusCorrection", bolusCorrection) //
.add("bolusManual", bolusManual) //
.add("bolusCount", bolusCount) //
.add("bolusCountFoodOrCorr", bolusCountFoodOrCorr) //
.add("bolusCountFoodAndCorr", bolusCountFoodAndCorr) //
.add("bolusCountFood", bolusCountFood) //
.add("bolusCountCorr", bolusCountCorr) //
.add("bolusCountManual", bolusCountManual) //
.omitNullValues() //
.toString();
}

View file

@ -281,7 +281,7 @@ public class MedtronicUtil extends RileyLinkUtil {
byte[] payload = sendPayloadBuffer.array();
if (L.isEnabled(L.PUMPCOMM))
LOG.debug("buildCommandPayload [{}]", ByteUtil.getHex(payload));
LOG.debug("buildCommandPayload [{}]", ByteUtil.shortHexString(payload));
// int crc = computeCRC8WithPolynomial(payload, 0, payload.length - 1);