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 java.util.EnumSet;
|
||||
import java.util.Random;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -81,19 +82,18 @@ public class OmnipodManager {
|
|||
this(communicationService, podState, null);
|
||||
}
|
||||
|
||||
public synchronized Single<SetupActionResult> pairAndPrime() {
|
||||
public synchronized Single<SetupActionResult> pairAndPrime(int address) {
|
||||
logStartingCommandExecution("pairAndPrime");
|
||||
|
||||
try {
|
||||
if (podState == null) {
|
||||
if (podState == null || podState.getSetupProgress().isBefore(SetupProgress.POD_CONFIGURED)) {
|
||||
// Always send both 0x07 and 0x03 on retries
|
||||
podState = communicationService.executeAction(
|
||||
new AssignAddressAction(podStateChangedHandler));
|
||||
} else if (SetupProgress.PRIMING.isBefore(podState.getSetupProgress())) {
|
||||
throw new IllegalSetupProgressException(SetupProgress.ADDRESS_ASSIGNED, podState.getSetupProgress());
|
||||
}
|
||||
new AssignAddressAction(podStateChangedHandler, address));
|
||||
|
||||
if (SetupProgress.ADDRESS_ASSIGNED.equals(podState.getSetupProgress())) {
|
||||
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));
|
||||
|
@ -592,6 +592,11 @@ public class OmnipodManager {
|
|||
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 {
|
||||
private final CommandDeliveryStatus commandDeliveryStatus;
|
||||
private final SingleSubject<BolusDeliveryResult> deliveryResultSubject;
|
||||
|
|
|
@ -6,6 +6,8 @@ import java.util.Collections;
|
|||
import java.util.Random;
|
||||
|
||||
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.command.AssignAddressCommand;
|
||||
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 PodStateChangedHandler podStateChangedHandler;
|
||||
|
||||
public AssignAddressAction(PodStateChangedHandler podStateChangedHandler) {
|
||||
this.address = generateRandomAddress();
|
||||
public AssignAddressAction(PodStateChangedHandler podStateChangedHandler, int address) {
|
||||
this.address = address;
|
||||
this.podStateChangedHandler = podStateChangedHandler;
|
||||
}
|
||||
|
||||
private static int generateRandomAddress() {
|
||||
return 0x1f000000 | (new Random().nextInt() & 0x000fffff);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PodSessionState execute(OmnipodCommunicationService communicationService) {
|
||||
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,
|
||||
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();
|
||||
|
||||
PodSessionState podState = new PodSessionState(timeZone, address, assignAddressResponse.getPiVersion(),
|
||||
|
|
|
@ -5,6 +5,8 @@ import org.joda.time.DateTime;
|
|||
import java.util.Collections;
|
||||
|
||||
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.command.SetupPodCommand;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.VersionResponse;
|
||||
|
@ -48,6 +50,12 @@ public class SetupPodAction implements OmnipodAction<VersionResponse> {
|
|||
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) {
|
||||
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();
|
||||
if (PodInitActionType.PairAndPrimeWizardStep.equals(podInitActionType)) {
|
||||
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));
|
||||
return new PumpEnactResult().success(true).enacted(true);
|
||||
} catch (Exception ex) {
|
||||
|
|
Loading…
Reference in a new issue