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

fixing handling of waits after communicating to CNL

parent 77b2d97e
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,7 @@ import info.nightscout.android.medtronic.exception.EncryptionException; ...@@ -11,7 +11,7 @@ import info.nightscout.android.medtronic.exception.EncryptionException;
/** /**
* Created by lgoedhart on 26/03/2016. * Created by lgoedhart on 26/03/2016.
*/ */
public class BeginEHSMMessage extends MedtronicSendMessageRequestMessage<ContourNextLinkResponseMessage> { public class BeginEHSMMessage extends EHSMMessage {
public BeginEHSMMessage(MedtronicCnlSession pumpSession) throws EncryptionException, ChecksumException { public BeginEHSMMessage(MedtronicCnlSession pumpSession) throws EncryptionException, ChecksumException {
super(SendMessageType.BEGIN_EHSM_SESSION, pumpSession, buildPayload()); super(SendMessageType.BEGIN_EHSM_SESSION, pumpSession, buildPayload());
} }
...@@ -20,12 +20,4 @@ public class BeginEHSMMessage extends MedtronicSendMessageRequestMessage<Contour ...@@ -20,12 +20,4 @@ public class BeginEHSMMessage extends MedtronicSendMessageRequestMessage<Contour
// Not sure what the payload of a null byte means, but it's the same every time. // Not sure what the payload of a null byte means, but it's the same every time.
return new byte[] { 0x00 }; return new byte[] { 0x00 };
} }
public ContourNextLinkResponseMessage send(UsbHidDriver mDevice) throws IOException, TimeoutException {
sendMessage(mDevice);
// The Begin EHSM Session only has an 0x81 response
readMessage(mDevice);
return null;
}
} }
...@@ -19,22 +19,21 @@ public abstract class ContourNextLinkRequestMessage<T> extends ContourNextLinkMe ...@@ -19,22 +19,21 @@ public abstract class ContourNextLinkRequestMessage<T> extends ContourNextLinkMe
} }
public T send(UsbHidDriver mDevice) throws IOException, TimeoutException, EncryptionException, ChecksumException, UnexpectedMessageException { public T send(UsbHidDriver mDevice) throws IOException, TimeoutException, EncryptionException, ChecksumException, UnexpectedMessageException {
sendMessage(mDevice); return send(mDevice, 0);
T response = this.getResponse(readMessage(mDevice)); //new ContourNextLinkCommandResponse();
// FIXME - We need to care what the response message is - wrong MAC and all that
return response;
} }
public T send(UsbHidDriver mDevice, int millis) throws UnexpectedMessageException, EncryptionException, TimeoutException, ChecksumException, IOException { public T send(UsbHidDriver mDevice, int millis) throws UnexpectedMessageException, EncryptionException, TimeoutException, ChecksumException, IOException {
T response = send(mDevice); sendMessage(mDevice);
if (millis > 0) {
try { try {
Thread.sleep(millis); Thread.sleep(millis);
} catch (InterruptedException e) { } catch (InterruptedException e) {
}
} }
T response = this.getResponse(readMessage(mDevice)); //new ContourNextLinkCommandResponse();
// FIXME - We need to care what the response message is - wrong MAC and all that
return response; return response;
} }
......
...@@ -18,10 +18,22 @@ public class DeviceInfoRequestCommandMessage extends ContourNextLinkRequestMessa ...@@ -18,10 +18,22 @@ public class DeviceInfoRequestCommandMessage extends ContourNextLinkRequestMessa
} }
@Override @Override
public DeviceInfoResponseCommandMessage send(UsbHidDriver mDevice) throws IOException, TimeoutException, EncryptionException, ChecksumException, UnexpectedMessageException { public DeviceInfoResponseCommandMessage send(UsbHidDriver mDevice, int millis) throws IOException, TimeoutException, EncryptionException, ChecksumException, UnexpectedMessageException {
sendMessage(mDevice); sendMessage(mDevice);
if (millis > 0) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
}
}
byte[] response1 = readMessage(mDevice); byte[] response1 = readMessage(mDevice);
if (millis > 0) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
}
}
byte[] response2 = readMessage(mDevice); byte[] response2 = readMessage(mDevice);
boolean doRetry = false; boolean doRetry = false;
......
package info.nightscout.android.medtronic.message;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
import info.nightscout.android.USB.UsbHidDriver;
import info.nightscout.android.medtronic.MedtronicCnlSession;
import info.nightscout.android.medtronic.exception.ChecksumException;
import info.nightscout.android.medtronic.exception.EncryptionException;
/**
* Created by volker on 22.12.2016.
*/
public class EHSMMessage extends MedtronicSendMessageRequestMessage<ContourNextLinkResponseMessage>{
protected EHSMMessage(SendMessageType sendMessageType, MedtronicCnlSession pumpSession, byte[] payload) throws EncryptionException, ChecksumException {
super(sendMessageType, pumpSession, payload);
}
@Override
public ContourNextLinkResponseMessage send(UsbHidDriver mDevice, int millis) throws IOException, TimeoutException {
sendMessage(mDevice);
if (millis > 0) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
}
}
// The End EHSM Session only has an 0x81 response
readMessage(mDevice);
return null;
}
}
...@@ -12,7 +12,7 @@ import info.nightscout.android.medtronic.exception.UnexpectedMessageException; ...@@ -12,7 +12,7 @@ import info.nightscout.android.medtronic.exception.UnexpectedMessageException;
/** /**
* Created by lgoedhart on 26/03/2016. * Created by lgoedhart on 26/03/2016.
*/ */
public class EndEHSMMessage extends MedtronicSendMessageRequestMessage<ContourNextLinkResponseMessage> { public class EndEHSMMessage extends EHSMMessage {
public EndEHSMMessage(MedtronicCnlSession pumpSession) throws EncryptionException, ChecksumException { public EndEHSMMessage(MedtronicCnlSession pumpSession) throws EncryptionException, ChecksumException {
super(SendMessageType.END_EHSM_SESSION, pumpSession, buildPayload()); super(SendMessageType.END_EHSM_SESSION, pumpSession, buildPayload());
} }
...@@ -22,13 +22,4 @@ public class EndEHSMMessage extends MedtronicSendMessageRequestMessage<ContourNe ...@@ -22,13 +22,4 @@ public class EndEHSMMessage extends MedtronicSendMessageRequestMessage<ContourNe
return new byte[] { 0x01 }; return new byte[] { 0x01 };
} }
@Override
public ContourNextLinkResponseMessage send(UsbHidDriver mDevice) throws IOException, TimeoutException {
sendMessage(mDevice);
// The End EHSM Session only has an 0x81 response
readMessage(mDevice);
return null;
}
} }
...@@ -17,12 +17,22 @@ public class PumpStatusRequestMessage extends MedtronicSendMessageRequestMessage ...@@ -17,12 +17,22 @@ public class PumpStatusRequestMessage extends MedtronicSendMessageRequestMessage
super(SendMessageType.READ_PUMP_STATUS_REQUEST, pumpSession, null); super(SendMessageType.READ_PUMP_STATUS_REQUEST, pumpSession, null);
} }
public PumpStatusResponseMessage send(UsbHidDriver mDevice) throws IOException, TimeoutException, ChecksumException, EncryptionException, UnexpectedMessageException { public PumpStatusResponseMessage send(UsbHidDriver mDevice, int millis) throws IOException, TimeoutException, ChecksumException, EncryptionException, UnexpectedMessageException {
sendMessage(mDevice); sendMessage(mDevice);
if (millis > 0) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
}
}
// Read the 0x81 // Read the 0x81
readMessage(mDevice); readMessage(mDevice);
if (millis > 0) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
}
}
PumpStatusResponseMessage response = this.getResponse(readMessage(mDevice)); PumpStatusResponseMessage response = this.getResponse(readMessage(mDevice));
return response; return response;
......
...@@ -18,12 +18,22 @@ public class PumpTimeRequestMessage extends MedtronicSendMessageRequestMessage<P ...@@ -18,12 +18,22 @@ public class PumpTimeRequestMessage extends MedtronicSendMessageRequestMessage<P
} }
@Override @Override
public PumpTimeResponseMessage send(UsbHidDriver mDevice) throws IOException, TimeoutException, ChecksumException, EncryptionException, UnexpectedMessageException { public PumpTimeResponseMessage send(UsbHidDriver mDevice, int millis) throws IOException, TimeoutException, ChecksumException, EncryptionException, UnexpectedMessageException {
sendMessage(mDevice); sendMessage(mDevice);
if (millis > 0) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
}
}
// Read the 0x81 // Read the 0x81
readMessage(mDevice); readMessage(mDevice);
if (millis > 0) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
}
}
// Read the 0x80 // Read the 0x80
PumpTimeResponseMessage response = this.getResponse(readMessage(mDevice)); PumpTimeResponseMessage response = this.getResponse(readMessage(mDevice));
......
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