WIP on always retrying 0x07 and 0x03 messages together
This commit is contained in:
parent
b515fbae92
commit
b482f0690f
5 changed files with 44 additions and 14 deletions
|
@ -7,6 +7,7 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@ -81,19 +82,18 @@ public class OmnipodManager {
|
||||||
this(communicationService, podState, null);
|
this(communicationService, podState, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized Single<SetupActionResult> pairAndPrime() {
|
public synchronized Single<SetupActionResult> pairAndPrime(int address) {
|
||||||
logStartingCommandExecution("pairAndPrime");
|
logStartingCommandExecution("pairAndPrime");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (podState == null) {
|
if (podState == null || podState.getSetupProgress().isBefore(SetupProgress.POD_CONFIGURED)) {
|
||||||
|
// Always send both 0x07 and 0x03 on retries
|
||||||
podState = communicationService.executeAction(
|
podState = communicationService.executeAction(
|
||||||
new AssignAddressAction(podStateChangedHandler));
|
new AssignAddressAction(podStateChangedHandler, address));
|
||||||
} else if (SetupProgress.PRIMING.isBefore(podState.getSetupProgress())) {
|
|
||||||
throw new IllegalSetupProgressException(SetupProgress.ADDRESS_ASSIGNED, podState.getSetupProgress());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SetupProgress.ADDRESS_ASSIGNED.equals(podState.getSetupProgress())) {
|
|
||||||
communicationService.executeAction(new SetupPodAction(podState));
|
communicationService.executeAction(new SetupPodAction(podState));
|
||||||
|
} else if (SetupProgress.PRIMING.isBefore(podState.getSetupProgress())) {
|
||||||
|
throw new IllegalSetupProgressException(SetupProgress.POD_CONFIGURED, podState.getSetupProgress());
|
||||||
}
|
}
|
||||||
|
|
||||||
communicationService.executeAction(new PrimeAction(new PrimeService(), podState));
|
communicationService.executeAction(new PrimeAction(new PrimeService(), podState));
|
||||||
|
@ -592,6 +592,11 @@ public class OmnipodManager {
|
||||||
return ex instanceof OmnipodException && ((OmnipodException) ex).isCertainFailure();
|
return ex instanceof OmnipodException && ((OmnipodException) ex).isCertainFailure();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int generateRandomAddress() {
|
||||||
|
// Create random address with 20 bits to match PDM, could easily use 24 bits instead
|
||||||
|
return 0x1f000000 | (new Random().nextInt() & 0x000fffff);
|
||||||
|
}
|
||||||
|
|
||||||
public static class BolusCommandResult {
|
public static class BolusCommandResult {
|
||||||
private final CommandDeliveryStatus commandDeliveryStatus;
|
private final CommandDeliveryStatus commandDeliveryStatus;
|
||||||
private final SingleSubject<BolusDeliveryResult> deliveryResultSubject;
|
private final SingleSubject<BolusDeliveryResult> deliveryResultSubject;
|
||||||
|
|
|
@ -6,6 +6,8 @@ import java.util.Collections;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationService;
|
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationService;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalMessageAddressException;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalVersionResponseTypeException;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.OmnipodMessage;
|
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.OmnipodMessage;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.AssignAddressCommand;
|
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.AssignAddressCommand;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.VersionResponse;
|
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.VersionResponse;
|
||||||
|
@ -18,15 +20,11 @@ public class AssignAddressAction implements OmnipodAction<PodSessionState> {
|
||||||
private final int address;
|
private final int address;
|
||||||
private final PodStateChangedHandler podStateChangedHandler;
|
private final PodStateChangedHandler podStateChangedHandler;
|
||||||
|
|
||||||
public AssignAddressAction(PodStateChangedHandler podStateChangedHandler) {
|
public AssignAddressAction(PodStateChangedHandler podStateChangedHandler, int address) {
|
||||||
this.address = generateRandomAddress();
|
this.address = address;
|
||||||
this.podStateChangedHandler = podStateChangedHandler;
|
this.podStateChangedHandler = podStateChangedHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int generateRandomAddress() {
|
|
||||||
return 0x1f000000 | (new Random().nextInt() & 0x000fffff);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PodSessionState execute(OmnipodCommunicationService communicationService) {
|
public PodSessionState execute(OmnipodCommunicationService communicationService) {
|
||||||
PodSetupState setupState = new PodSetupState(address, 0x00, 0x00);
|
PodSetupState setupState = new PodSetupState(address, 0x00, 0x00);
|
||||||
|
@ -38,6 +36,13 @@ public class AssignAddressAction implements OmnipodAction<PodSessionState> {
|
||||||
VersionResponse assignAddressResponse = communicationService.exchangeMessages(VersionResponse.class, setupState, assignAddressMessage,
|
VersionResponse assignAddressResponse = communicationService.exchangeMessages(VersionResponse.class, setupState, assignAddressMessage,
|
||||||
OmnipodConst.DEFAULT_ADDRESS, setupState.getAddress());
|
OmnipodConst.DEFAULT_ADDRESS, setupState.getAddress());
|
||||||
|
|
||||||
|
if(!assignAddressResponse.isAssignAddressVersionResponse()) {
|
||||||
|
throw new IllegalVersionResponseTypeException("assignAddress", "setupPod");
|
||||||
|
}
|
||||||
|
if(assignAddressResponse.getAddress() != address) {
|
||||||
|
throw new IllegalMessageAddressException(address, assignAddressResponse.getAddress());
|
||||||
|
}
|
||||||
|
|
||||||
DateTimeZone timeZone = DateTimeZone.getDefault();
|
DateTimeZone timeZone = DateTimeZone.getDefault();
|
||||||
|
|
||||||
PodSessionState podState = new PodSessionState(timeZone, address, assignAddressResponse.getPiVersion(),
|
PodSessionState podState = new PodSessionState(timeZone, address, assignAddressResponse.getPiVersion(),
|
||||||
|
|
|
@ -5,6 +5,8 @@ import org.joda.time.DateTime;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationService;
|
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationService;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalMessageAddressException;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalVersionResponseTypeException;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.OmnipodMessage;
|
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.OmnipodMessage;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.SetupPodCommand;
|
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.SetupPodCommand;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.VersionResponse;
|
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.VersionResponse;
|
||||||
|
@ -48,6 +50,12 @@ public class SetupPodAction implements OmnipodAction<VersionResponse> {
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!setupPodResponse.isSetupPodVersionResponse()) {
|
||||||
|
throw new IllegalVersionResponseTypeException("setupPod", "assignAddress");
|
||||||
|
}
|
||||||
|
if(setupPodResponse.getAddress() != podState.getAddress()) {
|
||||||
|
throw new IllegalMessageAddressException(podState.getAddress(), setupPodResponse.getAddress());
|
||||||
|
}
|
||||||
if (setupPodResponse.getPodProgressStatus() != PodProgressStatus.PAIRING_SUCCESS) {
|
if (setupPodResponse.getPodProgressStatus() != PodProgressStatus.PAIRING_SUCCESS) {
|
||||||
throw new IllegalPodProgressException(PodProgressStatus.PAIRING_SUCCESS, setupPodResponse.getPodProgressStatus());
|
throw new IllegalPodProgressException(PodProgressStatus.PAIRING_SUCCESS, setupPodResponse.getPodProgressStatus());
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.omnipod.comm.exception;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException;
|
||||||
|
|
||||||
|
public class IllegalVersionResponseTypeException extends OmnipodException {
|
||||||
|
public IllegalVersionResponseTypeException(String expected, String actual) {
|
||||||
|
super("Invalid Version Response type. Expected="+ expected +", actual="+ actual, false);
|
||||||
|
}
|
||||||
|
}
|
|
@ -170,7 +170,10 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
if (PodInitActionType.PairAndPrimeWizardStep.equals(podInitActionType)) {
|
if (PodInitActionType.PairAndPrimeWizardStep.equals(podInitActionType)) {
|
||||||
try {
|
try {
|
||||||
Disposable disposable = delegate.pairAndPrime().subscribe(res -> //
|
// BS FIXME use static address for retries
|
||||||
|
int address = OmnipodManager.generateRandomAddress();
|
||||||
|
|
||||||
|
Disposable disposable = delegate.pairAndPrime(address).subscribe(res -> //
|
||||||
handleSetupActionResult(podInitActionType, podInitReceiver, res, time, null));
|
handleSetupActionResult(podInitActionType, podInitReceiver, res, time, null));
|
||||||
return new PumpEnactResult().success(true).enacted(true);
|
return new PumpEnactResult().success(true).enacted(true);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|
Loading…
Reference in a new issue