Use static Pod address in between pairing retries and remove unused methods from OmnipodUtil
This commit is contained in:
parent
a0b4e0c7ce
commit
79d64dff64
5 changed files with 45 additions and 62 deletions
|
@ -597,6 +597,10 @@ public class OmnipodManager {
|
||||||
return 0x1f000000 | (new Random().nextInt() & 0x000fffff);
|
return 0x1f000000 | (new Random().nextInt() & 0x000fffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isValidAddress(int address) {
|
||||||
|
return (0x1f000000 | (address & 0x000fffff)) == address;
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
|
@ -144,7 +144,7 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
|
||||||
val isPodSessionActive = (OmnipodUtil.getPodSessionState() != null)
|
val isPodSessionActive = (OmnipodUtil.getPodSessionState() != null)
|
||||||
|
|
||||||
initpod_remove_pod.isEnabled = isPodSessionActive
|
initpod_remove_pod.isEnabled = isPodSessionActive
|
||||||
initpod_reset_pod.isEnabled = isPodSessionActive
|
initpod_reset_pod.isEnabled = isPodSessionActive || OmnipodUtil.hasNextPodAddress()
|
||||||
|
|
||||||
if (OmnipodUtil.getDriverState() == OmnipodDriverState.NotInitalized) {
|
if (OmnipodUtil.getDriverState() == OmnipodDriverState.NotInitalized) {
|
||||||
// if rileylink is not running we disable all operations
|
// if rileylink is not running we disable all operations
|
||||||
|
|
|
@ -84,6 +84,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
||||||
|
|
||||||
private static AapsOmnipodManager instance;
|
private static AapsOmnipodManager instance;
|
||||||
private OmnipodPumpStatus pumpStatus;
|
private OmnipodPumpStatus pumpStatus;
|
||||||
|
private Integer nextPodAddress;
|
||||||
|
|
||||||
private Date lastBolusTime;
|
private Date lastBolusTime;
|
||||||
private Double lastBolusUnits;
|
private Double lastBolusUnits;
|
||||||
|
@ -98,6 +99,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
||||||
OmnipodUtil.setPodSessionState(podSessionState);
|
OmnipodUtil.setPodSessionState(podSessionState);
|
||||||
updatePumpStatus(podSessionState);
|
updatePumpStatus(podSessionState);
|
||||||
});
|
});
|
||||||
|
this.nextPodAddress = OmnipodUtil.getNextPodAddress();
|
||||||
this.pumpStatus = _pumpStatus;
|
this.pumpStatus = _pumpStatus;
|
||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
@ -171,8 +173,7 @@ 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 {
|
||||||
// BS FIXME use static address for retries
|
int address = obtainNextPodAddress();
|
||||||
int address = OmnipodManager.generateRandomAddress();
|
|
||||||
|
|
||||||
Disposable disposable = delegate.pairAndPrime(address).subscribe(res -> //
|
Disposable disposable = delegate.pairAndPrime(address).subscribe(res -> //
|
||||||
handleSetupActionResult(podInitActionType, podInitReceiver, res, time, null));
|
handleSetupActionResult(podInitActionType, podInitReceiver, res, time, null));
|
||||||
|
@ -279,6 +280,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
||||||
reportImplicitlyCanceledTbr();
|
reportImplicitlyCanceledTbr();
|
||||||
|
|
||||||
OmnipodUtil.setPodSessionState(null);
|
OmnipodUtil.setPodSessionState(null);
|
||||||
|
OmnipodUtil.removeNextPodAddress();
|
||||||
|
|
||||||
addSuccessToHistory(System.currentTimeMillis(), PodHistoryEntryType.ResetPodState, null);
|
addSuccessToHistory(System.currentTimeMillis(), PodHistoryEntryType.ResetPodState, null);
|
||||||
|
|
||||||
|
@ -544,18 +546,15 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long addSuccessToHistory(long requestTime, PodHistoryEntryType entryType, Object data) {
|
||||||
public long addSuccessToHistory(long requestTime, PodHistoryEntryType entryType, Object data) {
|
|
||||||
return addToHistory(requestTime, entryType, data, true);
|
return addToHistory(requestTime, entryType, data, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long addFailureToHistory(long requestTime, PodHistoryEntryType entryType, Object data) {
|
private long addFailureToHistory(long requestTime, PodHistoryEntryType entryType, Object data) {
|
||||||
return addToHistory(requestTime, entryType, data, false);
|
return addToHistory(requestTime, entryType, data, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long addToHistory(long requestTime, PodHistoryEntryType entryType, Object data, boolean success) {
|
||||||
public long addToHistory(long requestTime, PodHistoryEntryType entryType, Object data, boolean success) {
|
|
||||||
|
|
||||||
PodHistory podHistory = new PodHistory(requestTime, entryType);
|
PodHistory podHistory = new PodHistory(requestTime, entryType);
|
||||||
|
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
|
@ -572,7 +571,15 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
|
||||||
MainApp.getDbHelper().createOrUpdate(podHistory);
|
MainApp.getDbHelper().createOrUpdate(podHistory);
|
||||||
|
|
||||||
return podHistory.getPumpId();
|
return podHistory.getPumpId();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int obtainNextPodAddress() {
|
||||||
|
if(nextPodAddress == null) {
|
||||||
|
nextPodAddress = OmnipodManager.generateRandomAddress();
|
||||||
|
OmnipodUtil.setNextPodAddress(nextPodAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
return nextPodAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleSetupActionResult(PodInitActionType podInitActionType, PodInitReceiver podInitReceiver, SetupActionResult res, long time, Profile profile) {
|
private void handleSetupActionResult(PodInitActionType podInitActionType, PodInitReceiver podInitReceiver, SetupActionResult res, long time, Profile profile) {
|
||||||
|
|
|
@ -14,6 +14,7 @@ public class OmnipodConst {
|
||||||
|
|
||||||
public class Prefs {
|
public class Prefs {
|
||||||
public static final String PodState = Prefix + "pod_state";
|
public static final String PodState = Prefix + "pod_state";
|
||||||
|
public static final String NextPodAddress = Prefix + "next_pod_address";
|
||||||
public static final int BeepBasalEnabled = R.string.key_omnipod_beep_basal_enabled;
|
public static final int BeepBasalEnabled = R.string.key_omnipod_beep_basal_enabled;
|
||||||
public static final int BeepBolusEnabled = R.string.key_omnipod_beep_bolus_enabled;
|
public static final int BeepBolusEnabled = R.string.key_omnipod_beep_bolus_enabled;
|
||||||
public static final int BeepSMBEnabled = R.string.key_omnipod_beep_smb_enabled;
|
public static final int BeepSMBEnabled = R.string.key_omnipod_beep_smb_enabled;
|
||||||
|
|
|
@ -26,6 +26,7 @@ import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin;
|
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodManager;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType;
|
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface;
|
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodPodType;
|
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodPodType;
|
||||||
|
@ -38,6 +39,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodDevice
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.service.RileyLinkOmnipodService;
|
import info.nightscout.androidaps.plugins.pump.omnipod.service.RileyLinkOmnipodService;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod_dash.OmnipodDashPumpPlugin;
|
import info.nightscout.androidaps.plugins.pump.omnipod_dash.OmnipodDashPumpPlugin;
|
||||||
import info.nightscout.androidaps.utils.OKDialog;
|
import info.nightscout.androidaps.utils.OKDialog;
|
||||||
|
import info.nightscout.androidaps.utils.SP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by andy on 4/8/19.
|
* Created by andy on 4/8/19.
|
||||||
|
@ -47,7 +49,6 @@ public class OmnipodUtil extends RileyLinkUtil {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(L.PUMPCOMM);
|
private static final Logger LOG = LoggerFactory.getLogger(L.PUMPCOMM);
|
||||||
|
|
||||||
private static boolean lowLevelDebug = true;
|
|
||||||
private static RileyLinkOmnipodService omnipodService;
|
private static RileyLinkOmnipodService omnipodService;
|
||||||
private static OmnipodPumpStatus omnipodPumpStatus;
|
private static OmnipodPumpStatus omnipodPumpStatus;
|
||||||
private static OmnipodCommandType currentCommand;
|
private static OmnipodCommandType currentCommand;
|
||||||
|
@ -63,61 +64,14 @@ public class OmnipodUtil extends RileyLinkUtil {
|
||||||
return gsonInstance;
|
return gsonInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int makeUnsignedShort(int b2, int b1) {
|
|
||||||
int k = (b2 & 0xff) << 8 | b1 & 0xff;
|
|
||||||
return k;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] getByteArrayFromUnsignedShort(int shortValue, boolean returnFixedSize) {
|
|
||||||
byte highByte = (byte) (shortValue >> 8 & 0xFF);
|
|
||||||
byte lowByte = (byte) (shortValue & 0xFF);
|
|
||||||
|
|
||||||
if (highByte > 0) {
|
|
||||||
return createByteArray(highByte, lowByte);
|
|
||||||
} else {
|
|
||||||
return returnFixedSize ? createByteArray(highByte, lowByte) : createByteArray(lowByte);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static byte[] createByteArray(byte... data) {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static byte[] createByteArray(List<Byte> data) {
|
|
||||||
|
|
||||||
byte[] array = new byte[data.size()];
|
|
||||||
|
|
||||||
for (int i = 0; i < data.size(); i++) {
|
|
||||||
array[i] = data.get(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean isLowLevelDebug() {
|
|
||||||
return lowLevelDebug;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void setLowLevelDebug(boolean lowLevelDebug) {
|
|
||||||
OmnipodUtil.lowLevelDebug = lowLevelDebug;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static OmnipodCommunicationManagerInterface getOmnipodCommunicationManager() {
|
public static OmnipodCommunicationManagerInterface getOmnipodCommunicationManager() {
|
||||||
return (OmnipodCommunicationManagerInterface) RileyLinkUtil.rileyLinkCommunicationManager;
|
return (OmnipodCommunicationManagerInterface) RileyLinkUtil.rileyLinkCommunicationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static RileyLinkOmnipodService getOmnipodService() {
|
public static RileyLinkOmnipodService getOmnipodService() {
|
||||||
return OmnipodUtil.omnipodService;
|
return OmnipodUtil.omnipodService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void setOmnipodService(RileyLinkOmnipodService medtronicService) {
|
public static void setOmnipodService(RileyLinkOmnipodService medtronicService) {
|
||||||
OmnipodUtil.omnipodService = medtronicService;
|
OmnipodUtil.omnipodService = medtronicService;
|
||||||
}
|
}
|
||||||
|
@ -126,24 +80,20 @@ public class OmnipodUtil extends RileyLinkUtil {
|
||||||
return OmnipodUtil.currentCommand;
|
return OmnipodUtil.currentCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// FIXME
|
// FIXME
|
||||||
public static void setCurrentCommand(OmnipodCommandType currentCommand) {
|
public static void setCurrentCommand(OmnipodCommandType currentCommand) {
|
||||||
OmnipodUtil.currentCommand = currentCommand;
|
OmnipodUtil.currentCommand = currentCommand;
|
||||||
|
|
||||||
if (currentCommand != null)
|
if (currentCommand != null)
|
||||||
historyRileyLink.add(new RLHistoryItem(currentCommand));
|
historyRileyLink.add(new RLHistoryItem(currentCommand));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static boolean isSame(Double d1, Double d2) {
|
public static boolean isSame(Double d1, Double d2) {
|
||||||
double diff = d1 - d2;
|
double diff = d1 - d2;
|
||||||
|
|
||||||
return (Math.abs(diff) <= 0.000001);
|
return (Math.abs(diff) <= 0.000001);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void displayNotConfiguredDialog(Context context) {
|
public static void displayNotConfiguredDialog(Context context) {
|
||||||
OKDialog.show(context, MainApp.gs(R.string.combo_warning),
|
OKDialog.show(context, MainApp.gs(R.string.combo_warning),
|
||||||
MainApp.gs(R.string.omnipod_error_operation_not_possible_no_configuration), null);
|
MainApp.gs(R.string.omnipod_error_operation_not_possible_no_configuration), null);
|
||||||
|
@ -239,7 +189,6 @@ public class OmnipodUtil extends RileyLinkUtil {
|
||||||
return OmnipodDashPumpPlugin.getPlugin().isEnabled(PluginType.PUMP);
|
return OmnipodDashPumpPlugin.getPlugin().isEnabled(PluginType.PUMP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void setPumpType(PumpType pumpType) {
|
public static void setPumpType(PumpType pumpType) {
|
||||||
OmnipodUtil.pumpType = pumpType;
|
OmnipodUtil.pumpType = pumpType;
|
||||||
}
|
}
|
||||||
|
@ -247,4 +196,26 @@ public class OmnipodUtil extends RileyLinkUtil {
|
||||||
public static PumpType getPumpType() {
|
public static PumpType getPumpType() {
|
||||||
return pumpType;
|
return pumpType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Integer getNextPodAddress() {
|
||||||
|
if(SP.contains(OmnipodConst.Prefs.NextPodAddress)) {
|
||||||
|
int nextPodAddress = SP.getInt(OmnipodConst.Prefs.NextPodAddress, 0);
|
||||||
|
if (OmnipodManager.isValidAddress(nextPodAddress)) {
|
||||||
|
return nextPodAddress;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasNextPodAddress() {
|
||||||
|
return getNextPodAddress() != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setNextPodAddress(int address) {
|
||||||
|
SP.putInt(OmnipodConst.Prefs.NextPodAddress, address);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeNextPodAddress() {
|
||||||
|
SP.remove(OmnipodConst.Prefs.NextPodAddress);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue