Skip to content
Snippets Groups Projects
Commit c5f91833 authored by Volker Richert's avatar Volker Richert
Browse files

add logging for decrypted messages & payload

parent 9c35bd9f
Branches
Tags
No related merge requests found
package info.nightscout.android.medtronic.message; package info.nightscout.android.medtronic.message;
import android.util.Log;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import javax.crypto.Cipher; import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import info.nightscout.android.BuildConfig;
import info.nightscout.android.medtronic.MedtronicCnlSession; import info.nightscout.android.medtronic.MedtronicCnlSession;
import info.nightscout.android.medtronic.exception.ChecksumException; import info.nightscout.android.medtronic.exception.ChecksumException;
import info.nightscout.android.medtronic.exception.EncryptionException; import info.nightscout.android.medtronic.exception.EncryptionException;
import info.nightscout.android.utils.HexDump;
/** /**
* Created by lgoedhart on 26/03/2016. * Created by lgoedhart on 26/03/2016.
*/ */
public class MedtronicResponseMessage extends ContourNextLinkResponseMessage { public class MedtronicResponseMessage extends ContourNextLinkResponseMessage {
private static final String TAG = MedtronicResponseMessage.class.getSimpleName();
static int ENVELOPE_SIZE = 22; static int ENVELOPE_SIZE = 22;
static int ENCRYPTED_ENVELOPE_SIZE = 3; static int ENCRYPTED_ENVELOPE_SIZE = 3;
static int CRC_SIZE = 2; static int CRC_SIZE = 2;
...@@ -43,6 +49,11 @@ public class MedtronicResponseMessage extends ContourNextLinkResponseMessage { ...@@ -43,6 +49,11 @@ public class MedtronicResponseMessage extends ContourNextLinkResponseMessage {
// Should be fine provided we check the CCITT first... // Should be fine provided we check the CCITT first...
this.mPayload.position(57); this.mPayload.position(57);
this.mPayload.put(decryptedPayload); this.mPayload.put(decryptedPayload);
if (BuildConfig.DEBUG) {
String outputString = HexDump.dumpHexString(this.mPayload.array());
Log.d(TAG, "DECRYPTED: " + outputString);
}
} }
} }
......
...@@ -8,11 +8,13 @@ import java.nio.ByteOrder; ...@@ -8,11 +8,13 @@ import java.nio.ByteOrder;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import info.nightscout.android.BuildConfig;
import info.nightscout.android.medtronic.MedtronicCnlSession; import info.nightscout.android.medtronic.MedtronicCnlSession;
import info.nightscout.android.medtronic.exception.ChecksumException; import info.nightscout.android.medtronic.exception.ChecksumException;
import info.nightscout.android.medtronic.exception.EncryptionException; import info.nightscout.android.medtronic.exception.EncryptionException;
import info.nightscout.android.medtronic.exception.UnexpectedMessageException; import info.nightscout.android.medtronic.exception.UnexpectedMessageException;
import info.nightscout.android.model.medtronicNg.PumpStatusEvent; import info.nightscout.android.model.medtronicNg.PumpStatusEvent;
import info.nightscout.android.utils.HexDump;
/** /**
* Created by lgoedhart on 27/03/2016. * Created by lgoedhart on 27/03/2016.
...@@ -61,6 +63,10 @@ public class PumpStatusResponseMessage extends MedtronicSendMessageResponseMessa ...@@ -61,6 +63,10 @@ public class PumpStatusResponseMessage extends MedtronicSendMessageResponseMessa
statusBuffer.order(ByteOrder.BIG_ENDIAN); statusBuffer.order(ByteOrder.BIG_ENDIAN);
statusBuffer.put(this.encode(), 0x39, 96); statusBuffer.put(this.encode(), 0x39, 96);
if (BuildConfig.DEBUG) {
String outputString = HexDump.dumpHexString(statusBuffer.array());
Log.d(TAG, "PAYLOAD: " + outputString);
}
// Status Flags // Status Flags
suspended = ((statusBuffer.get(0x03) & 0x01) != 0x00); suspended = ((statusBuffer.get(0x03) & 0x01) != 0x00);
bolusing = ((statusBuffer.get(0x03) & 0x02) != 0x00); bolusing = ((statusBuffer.get(0x03) & 0x02) != 0x00);
...@@ -108,9 +114,6 @@ public class PumpStatusResponseMessage extends MedtronicSendMessageResponseMessa ...@@ -108,9 +114,6 @@ public class PumpStatusResponseMessage extends MedtronicSendMessageResponseMessa
// CGM SGV // CGM SGV
sgv = (statusBuffer.getShort(0x35) & 0x0000ffff); // In mg/DL. 0 means no CGM reading sgv = (statusBuffer.getShort(0x35) & 0x0000ffff); // In mg/DL. 0 means no CGM reading
// SGV Date
if ((sgv & 0x200) == 0x200) { if ((sgv & 0x200) == 0x200) {
// Sensor error. Let's reset. FIXME - solve this more elegantly later // Sensor error. Let's reset. FIXME - solve this more elegantly later
sgv = 0; sgv = 0;
...@@ -123,6 +126,7 @@ public class PumpStatusResponseMessage extends MedtronicSendMessageResponseMessa ...@@ -123,6 +126,7 @@ public class PumpStatusResponseMessage extends MedtronicSendMessageResponseMessa
cgmTrend = (PumpStatusEvent.CGM_TREND.fromMessageByte(statusBuffer.get(0x40))); cgmTrend = (PumpStatusEvent.CGM_TREND.fromMessageByte(statusBuffer.get(0x40)));
} }
// SGV Date
// TODO - this should go in the sgvDate, and eventDate should be the time of this poll. // TODO - this should go in the sgvDate, and eventDate should be the time of this poll.
sgvDate = MessageUtils.decodeDateTime(rtc, offset); sgvDate = MessageUtils.decodeDateTime(rtc, offset);
Log.d(TAG, "original sgv date: " + sgvDate); Log.d(TAG, "original sgv date: " + sgvDate);
......
...@@ -6,9 +6,11 @@ import java.nio.ByteBuffer; ...@@ -6,9 +6,11 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.util.Date; import java.util.Date;
import info.nightscout.android.BuildConfig;
import info.nightscout.android.medtronic.MedtronicCnlSession; import info.nightscout.android.medtronic.MedtronicCnlSession;
import info.nightscout.android.medtronic.exception.ChecksumException; import info.nightscout.android.medtronic.exception.ChecksumException;
import info.nightscout.android.medtronic.exception.EncryptionException; import info.nightscout.android.medtronic.exception.EncryptionException;
import info.nightscout.android.utils.HexDump;
/** /**
* Created by lgoedhart on 27/03/2016. * Created by lgoedhart on 27/03/2016.
...@@ -30,6 +32,12 @@ public class PumpTimeResponseMessage extends MedtronicSendMessageResponseMessage ...@@ -30,6 +32,12 @@ public class PumpTimeResponseMessage extends MedtronicSendMessageResponseMessage
ByteBuffer dateBuffer = ByteBuffer.allocate(8); ByteBuffer dateBuffer = ByteBuffer.allocate(8);
dateBuffer.order(ByteOrder.BIG_ENDIAN); dateBuffer.order(ByteOrder.BIG_ENDIAN);
dateBuffer.put(this.encode(), 0x3d, 8); dateBuffer.put(this.encode(), 0x3d, 8);
if (BuildConfig.DEBUG) {
String outputString = HexDump.dumpHexString(dateBuffer.array());
Log.d(TAG, "PAYLOAD: " + outputString);
}
long rtc = dateBuffer.getInt(0) & 0x00000000ffffffffL; long rtc = dateBuffer.getInt(0) & 0x00000000ffffffffL;
long offset = dateBuffer.getInt(4); long offset = dateBuffer.getInt(4);
pumpTime = MessageUtils.decodeDateTime(rtc, offset); pumpTime = MessageUtils.decodeDateTime(rtc, offset);
......
...@@ -5,6 +5,7 @@ import android.util.Log; ...@@ -5,6 +5,7 @@ import android.util.Log;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import info.nightscout.android.BuildConfig;
import info.nightscout.android.medtronic.MedtronicCnlSession; import info.nightscout.android.medtronic.MedtronicCnlSession;
import info.nightscout.android.medtronic.exception.ChecksumException; import info.nightscout.android.medtronic.exception.ChecksumException;
import info.nightscout.android.medtronic.exception.EncryptionException; import info.nightscout.android.medtronic.exception.EncryptionException;
...@@ -32,6 +33,10 @@ public class ReadHistoryInfoResponseMessage extends MedtronicSendMessageResponse ...@@ -32,6 +33,10 @@ public class ReadHistoryInfoResponseMessage extends MedtronicSendMessageResponse
basalRatesBuffer.order(ByteOrder.BIG_ENDIAN); basalRatesBuffer.order(ByteOrder.BIG_ENDIAN);
basalRatesBuffer.put(this.encode()); basalRatesBuffer.put(this.encode());
if (BuildConfig.DEBUG) {
String outputString = HexDump.dumpHexString(basalRatesBuffer.array());
Log.d(TAG, "PAYLOAD: " + outputString);
}
String responseString = HexDump.dumpHexString(basalRatesBuffer.array()); String responseString = HexDump.dumpHexString(basalRatesBuffer.array());
Log.d(TAG, "ReadHistoryInfo: " + responseString); Log.d(TAG, "ReadHistoryInfo: " + responseString);
Log.d(TAG, "ReadHistoryInfo-length: " + basalRatesBuffer.getLong(28)); Log.d(TAG, "ReadHistoryInfo-length: " + basalRatesBuffer.getLong(28));
......
...@@ -35,7 +35,12 @@ public class HexDump { ...@@ -35,7 +35,12 @@ public class HexDump {
byte[] line = new byte[16]; byte[] line = new byte[16];
int lineIndex = 0; int lineIndex = 0;
result.append("\n ");
for (int i = 0; i < Math.min(16, array.length); i++) {
result.append(" ?" + HEX_DIGITS[i]);
}
result.append("\n0x"); result.append("\n0x");
result.append(toHexString(offset)); result.append(toHexString(offset));
for (int i = offset; i < offset + length; i++) { for (int i = offset; i < offset + length; i++) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment