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

refactoring

parent 880fe887
No related branches found
No related tags found
No related merge requests found
...@@ -187,13 +187,13 @@ public class MedtronicCnlReader implements ContourNextLinkMessageHandler { ...@@ -187,13 +187,13 @@ public class MedtronicCnlReader implements ContourNextLinkMessageHandler {
do { do {
doRetry = false; doRetry = false;
try { try {
new ContourNextLinkCommandMessage(ASCII.NAK.value) new ContourNextLinkCommandMessage(ContourNextLinkCommandMessage.ASCII.NAK)
.send(mDevice).checkControlMessage(ASCII.EOT.value); .send(mDevice).checkControlMessage(ContourNextLinkCommandMessage.ASCII.EOT);
new ContourNextLinkCommandMessage(ASCII.ENQ.value) new ContourNextLinkCommandMessage(ContourNextLinkCommandMessage.ASCII.ENQ)
.send(mDevice).checkControlMessage(ASCII.ACK.value); .send(mDevice).checkControlMessage(ContourNextLinkCommandMessage.ASCII.ACK);
} catch (UnexpectedMessageException e2) { } catch (UnexpectedMessageException e2) {
try { try {
new ContourNextLinkCommandMessage(ASCII.EOT.value).send(this); new ContourNextLinkCommandMessage(ContourNextLinkCommandMessage.ASCII.EOT).send(this);
} catch (IOException e) {} } catch (IOException e) {}
finally { finally {
doRetry = true; doRetry = true;
...@@ -205,11 +205,11 @@ public class MedtronicCnlReader implements ContourNextLinkMessageHandler { ...@@ -205,11 +205,11 @@ public class MedtronicCnlReader implements ContourNextLinkMessageHandler {
public void enterPassthroughMode() throws IOException, TimeoutException, UnexpectedMessageException, ChecksumException, EncryptionException { public void enterPassthroughMode() throws IOException, TimeoutException, UnexpectedMessageException, ChecksumException, EncryptionException {
Log.d(TAG, "Begin enterPasshtroughMode"); Log.d(TAG, "Begin enterPasshtroughMode");
new ContourNextLinkCommandMessage("W|") new ContourNextLinkCommandMessage("W|")
.send(mDevice).checkControlMessage(ASCII.ACK.value); .send(mDevice).checkControlMessage(ContourNextLinkCommandMessage.ASCII.ACK);
new ContourNextLinkCommandMessage("Q|") new ContourNextLinkCommandMessage("Q|")
.send(mDevice).checkControlMessage(ASCII.ACK.value); .send(mDevice).checkControlMessage(ContourNextLinkCommandMessage.ASCII.ACK);
new ContourNextLinkCommandMessage("1|") new ContourNextLinkCommandMessage("1|")
.send(mDevice).checkControlMessage(ASCII.ACK.value); .send(mDevice).checkControlMessage(ContourNextLinkCommandMessage.ASCII.ACK);
Log.d(TAG, "Finished enterPasshtroughMode"); Log.d(TAG, "Finished enterPasshtroughMode");
} }
...@@ -466,35 +466,21 @@ public class MedtronicCnlReader implements ContourNextLinkMessageHandler { ...@@ -466,35 +466,21 @@ public class MedtronicCnlReader implements ContourNextLinkMessageHandler {
Log.d(TAG, "Finished closeConnection"); Log.d(TAG, "Finished closeConnection");
} }
public void endPassthroughMode() throws IOException, TimeoutException, UnexpectedMessageException { public void endPassthroughMode() throws IOException, TimeoutException, UnexpectedMessageException, ChecksumException, EncryptionException {
Log.d(TAG, "Begin endPassthroughMode"); Log.d(TAG, "Begin endPassthroughMode");
new ContourNextLinkCommandMessage("W|").send(this); new ContourNextLinkCommandMessage("W|")
checkControlMessage(readMessage(), ASCII.ACK.value); .send(mDevice).checkControlMessage(ContourNextLinkCommandMessage.ASCII.ACK);
new ContourNextLinkCommandMessage("Q|").send(this); new ContourNextLinkCommandMessage("Q|")
checkControlMessage(readMessage(), ASCII.ACK.value); .send(mDevice).checkControlMessage(ContourNextLinkCommandMessage.ASCII.ACK);
new ContourNextLinkCommandMessage("0|").send(this); new ContourNextLinkCommandMessage("0|")
checkControlMessage(readMessage(), ASCII.ACK.value); .send(mDevice).checkControlMessage(ContourNextLinkCommandMessage.ASCII.ACK);
Log.d(TAG, "Finished endPassthroughMode"); Log.d(TAG, "Finished endPassthroughMode");
} }
public void endControlMode() throws IOException, TimeoutException, UnexpectedMessageException { public void endControlMode() throws IOException, TimeoutException, UnexpectedMessageException, ChecksumException, EncryptionException {
Log.d(TAG, "Begin endControlMode"); Log.d(TAG, "Begin endControlMode");
new ContourNextLinkCommandMessage(ASCII.EOT.value).send(this); new ContourNextLinkCommandMessage(ContourNextLinkCommandMessage.ASCII.EOT)
checkControlMessage(readMessage(), ASCII.ENQ.value); .send(mDevice).checkControlMessage(ContourNextLinkCommandMessage.ASCII.ENQ);
Log.d(TAG, "Finished endControlMode"); Log.d(TAG, "Finished endControlMode");
} }
public enum ASCII {
STX(0x02),
EOT(0x04),
ENQ(0x05),
ACK(0x06),
NAK(0x15);
private byte value;
ASCII(int code) {
this.value = (byte) code;
}
}
} }
...@@ -64,7 +64,7 @@ public class ContourNextLinkBinaryMessage extends ContourNextLinkMessage { ...@@ -64,7 +64,7 @@ public class ContourNextLinkBinaryMessage extends ContourNextLinkMessage {
} }
public void checkControlMessage(byte controlCharacter) throws IOException, TimeoutException, UnexpectedMessageException { public void checkControlMessage(ASCII controlCharacter) throws IOException, TimeoutException, UnexpectedMessageException {
checkControlMessage(mPayload.array(), controlCharacter); checkControlMessage(mPayload.array(), controlCharacter);
} }
...@@ -119,10 +119,10 @@ public class ContourNextLinkBinaryMessage extends ContourNextLinkMessage { ...@@ -119,10 +119,10 @@ public class ContourNextLinkBinaryMessage extends ContourNextLinkMessage {
} }
} }
protected void checkControlMessage(byte[] msg, byte controlCharacter) throws IOException, TimeoutException, UnexpectedMessageException { protected void checkControlMessage(byte[] msg, ASCII controlCharacter) throws IOException, TimeoutException, UnexpectedMessageException {
if (msg.length != 1 || msg[0] != controlCharacter) { if (msg.length != 1 || msg[0] != controlCharacter.value) {
throw new UnexpectedMessageException(String.format(Locale.getDefault(), "Expected to get control character '%d' Got '%d'.", throw new UnexpectedMessageException(String.format(Locale.getDefault(), "Expected to get control character '%d' Got '%d'.",
(int) controlCharacter, (int) msg[0])); (int) controlCharacter.value, (int) msg[0]));
} }
} }
......
...@@ -9,6 +9,10 @@ import info.nightscout.android.USB.UsbHidDriver; ...@@ -9,6 +9,10 @@ import info.nightscout.android.USB.UsbHidDriver;
* Created by lgoedhart on 26/03/2016. * Created by lgoedhart on 26/03/2016.
*/ */
public class ContourNextLinkCommandMessage extends ContourNextLinkMessage { public class ContourNextLinkCommandMessage extends ContourNextLinkMessage {
public ContourNextLinkCommandMessage(ASCII command) {
super(new byte[]{command.value});
}
public ContourNextLinkCommandMessage(byte command) { public ContourNextLinkCommandMessage(byte command) {
super(new byte[]{command}); super(new byte[]{command});
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment