simplify RL code
This commit is contained in:
parent
66c567f0e7
commit
9c472e4e05
3 changed files with 18 additions and 21 deletions
|
@ -59,23 +59,23 @@ public abstract class RileyLinkCommunicationManager {
|
|||
|
||||
|
||||
// All pump communications go through this function.
|
||||
protected <E extends RLMessage> E sendAndListen(RLMessage msg, int timeout_ms, Class<E> clazz)
|
||||
protected RLMessage sendAndListen(RLMessage msg, int timeout_ms)
|
||||
throws RileyLinkCommunicationException {
|
||||
return sendAndListen(msg, timeout_ms, null, clazz);
|
||||
return sendAndListen(msg, timeout_ms, null);
|
||||
}
|
||||
|
||||
private <E extends RLMessage> E sendAndListen(RLMessage msg, int timeout_ms, Integer extendPreamble_ms, Class<E> clazz)
|
||||
private RLMessage sendAndListen(RLMessage msg, int timeout_ms, Integer extendPreamble_ms)
|
||||
throws RileyLinkCommunicationException {
|
||||
return sendAndListen(msg, timeout_ms, 0, extendPreamble_ms, clazz);
|
||||
return sendAndListen(msg, timeout_ms, 0, extendPreamble_ms);
|
||||
}
|
||||
|
||||
// For backward compatibility
|
||||
private <E extends RLMessage> E sendAndListen(RLMessage msg, int timeout_ms, int repeatCount, Integer extendPreamble_ms, Class<E> clazz)
|
||||
private RLMessage sendAndListen(RLMessage msg, int timeout_ms, int repeatCount, Integer extendPreamble_ms)
|
||||
throws RileyLinkCommunicationException {
|
||||
return sendAndListen(msg, timeout_ms, repeatCount, 0, extendPreamble_ms, clazz);
|
||||
return sendAndListen(msg, timeout_ms, repeatCount, 0, extendPreamble_ms);
|
||||
}
|
||||
|
||||
protected <E extends RLMessage> E sendAndListen(RLMessage msg, int timeout_ms, int repeatCount, int retryCount, Integer extendPreamble_ms, Class<E> clazz)
|
||||
protected RLMessage sendAndListen(RLMessage msg, int timeout_ms, int repeatCount, int retryCount, Integer extendPreamble_ms)
|
||||
throws RileyLinkCommunicationException {
|
||||
|
||||
// internal flag
|
||||
|
@ -88,7 +88,7 @@ public abstract class RileyLinkCommunicationManager {
|
|||
(byte) 0, (byte) repeatCount, (byte) 0, (byte) 0, timeout_ms, (byte) retryCount, extendPreamble_ms);
|
||||
|
||||
RadioResponse radioResponse = rfSpyResponse.getRadioResponse(injector);
|
||||
E response = createResponseMessage(radioResponse.getPayload(), clazz);
|
||||
RLMessage response = createResponseMessage(radioResponse.getPayload());
|
||||
|
||||
if (response.isValid()) {
|
||||
// Mark this as the last time we heard from the pump.
|
||||
|
@ -124,7 +124,7 @@ public abstract class RileyLinkCommunicationManager {
|
|||
}
|
||||
|
||||
|
||||
public abstract <E extends RLMessage> E createResponseMessage(byte[] payload, Class<E> clazz);
|
||||
public abstract RLMessage createResponseMessage(byte[] payload);
|
||||
|
||||
|
||||
public abstract void setPumpDeviceState(PumpDeviceState pumpDeviceState);
|
||||
|
|
|
@ -87,9 +87,9 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
}
|
||||
|
||||
@Override
|
||||
public <E extends RLMessage> E createResponseMessage(byte[] payload, Class<E> clazz) {
|
||||
public RLMessage createResponseMessage(byte[] payload) {
|
||||
PumpMessage pumpMessage = new PumpMessage(aapsLogger, payload);
|
||||
return (E) pumpMessage;
|
||||
return pumpMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -170,7 +170,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
|
||||
if (radioResponse.isValid()) {
|
||||
|
||||
PumpMessage pumpResponse = createResponseMessage(radioResponse.getPayload(), PumpMessage.class);
|
||||
PumpMessage pumpResponse = (PumpMessage) createResponseMessage(radioResponse.getPayload());
|
||||
|
||||
if (!pumpResponse.isValid()) {
|
||||
aapsLogger.warn(LTag.PUMPCOMM, "Response is invalid ! [interrupted={}, timeout={}]", rfSpyResponse.wasInterrupted(),
|
||||
|
@ -551,8 +551,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
|
||||
|
||||
// All pump communications go through this function.
|
||||
private PumpMessage sendAndListen(RLMessage msg, int timeout_ms) throws RileyLinkCommunicationException {
|
||||
return sendAndListen(msg, timeout_ms, PumpMessage.class);
|
||||
protected PumpMessage sendAndListen(RLMessage msg, int timeout_ms) throws RileyLinkCommunicationException {
|
||||
return sendAndListen(msg, timeout_ms);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,11 +16,8 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLink
|
|||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RLMessage;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RLMessageType;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkBLEError;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor;
|
||||
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.OmnipodAction;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.CommunicationException;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalMessageAddressException;
|
||||
|
@ -94,8 +91,8 @@ public class OmnipodCommunicationManager extends RileyLinkCommunicationManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <E extends RLMessage> E createResponseMessage(byte[] payload, Class<E> clazz) {
|
||||
return (E) new OmnipodPacket(payload);
|
||||
public RLMessage createResponseMessage(byte[] payload) {
|
||||
return new OmnipodPacket(payload);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -301,7 +298,7 @@ public class OmnipodCommunicationManager extends RileyLinkCommunicationManager {
|
|||
OmnipodPacket ack = createAckPacket(podState, packetAddress, messageAddress);
|
||||
boolean quiet = false;
|
||||
while (!quiet) try {
|
||||
sendAndListen(ack, 300, 1, 0, 40, OmnipodPacket.class);
|
||||
sendAndListen(ack, 300, 1, 0, 40);
|
||||
} catch (RileyLinkCommunicationException ex) {
|
||||
if (RileyLinkBLEError.Timeout.equals(ex.getErrorCode())) {
|
||||
quiet = true;
|
||||
|
@ -333,7 +330,7 @@ public class OmnipodCommunicationManager extends RileyLinkCommunicationManager {
|
|||
while (System.currentTimeMillis() < timeoutTime) {
|
||||
OmnipodPacket response = null;
|
||||
try {
|
||||
response = sendAndListen(packet, responseTimeoutMilliseconds, repeatCount, 9, preambleExtensionMilliseconds, OmnipodPacket.class);
|
||||
response = (OmnipodPacket) sendAndListen(packet, responseTimeoutMilliseconds, repeatCount, 9, preambleExtensionMilliseconds);
|
||||
} catch (RileyLinkCommunicationException | OmnipodException ex) {
|
||||
aapsLogger.debug(LTag.PUMPBTCOMM, "Ignoring exception in exchangePackets: " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
|
||||
continue;
|
||||
|
|
Loading…
Reference in a new issue