- fully daggerized omnipod

This commit is contained in:
Andy Rozman 2020-05-01 10:55:48 +01:00
parent 4d39cbba95
commit 48572d64fc
25 changed files with 381 additions and 737 deletions

View file

@ -21,7 +21,6 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.WakeAndTuneTask; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.WakeAndTuneTask;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState; import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
import info.nightscout.androidaps.utils.Round; import info.nightscout.androidaps.utils.Round;
import info.nightscout.androidaps.utils.sharedPreferences.SP; import info.nightscout.androidaps.utils.sharedPreferences.SP;
@ -34,16 +33,14 @@ public abstract class RileyLinkCommunicationManager {
@Inject protected AAPSLogger aapsLogger; @Inject protected AAPSLogger aapsLogger;
@Inject protected SP sp; @Inject protected SP sp;
@Inject protected RileyLinkServiceData rileyLinkServiceData;
//@Inject MedtronicPumpStatus medtronicPumpStatus; @Inject protected ServiceTaskExecutor serviceTaskExecutor;
@Inject RileyLinkServiceData rileyLinkServiceData;
@Inject ServiceTaskExecutor serviceTaskExecutor;
private final int SCAN_TIMEOUT = 1500; private final int SCAN_TIMEOUT = 1500;
private final int ALLOWED_PUMP_UNREACHABLE = 10 * 60 * 1000; // 10 minutes private final int ALLOWED_PUMP_UNREACHABLE = 10 * 60 * 1000; // 10 minutes
protected final HasAndroidInjector injector; public final HasAndroidInjector injector;
protected final RFSpy rfspy; protected final RFSpy rfspy;
protected int receiverDeviceAwakeForMinutes = 1; // override this in constructor of specific implementation protected int receiverDeviceAwakeForMinutes = 1; // override this in constructor of specific implementation
protected String receiverDeviceID; // String representation of receiver device (ex. Pump (xxxxxx) or Pod (yyyyyy)) protected String receiverDeviceID; // String representation of receiver device (ex. Pump (xxxxxx) or Pod (yyyyyy))

View file

@ -14,12 +14,9 @@ import info.nightscout.androidaps.events.EventPreferenceChange
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType 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.defs.RileyLinkError
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusActivity import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusActivity
@ -35,9 +32,14 @@ import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodRefres
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil
import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.utils.* import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.Round
import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.WarnColors
import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable import io.reactivex.disposables.Disposable
@ -57,25 +59,18 @@ class OmnipodFragment : DaggerFragment() {
@Inject lateinit var omnipodPumpPlugin: OmnipodPumpPlugin @Inject lateinit var omnipodPumpPlugin: OmnipodPumpPlugin
@Inject lateinit var warnColors: WarnColors @Inject lateinit var warnColors: WarnColors
@Inject lateinit var omnipodPumpStatus: OmnipodPumpStatus @Inject lateinit var omnipodPumpStatus: OmnipodPumpStatus
@Inject lateinit var sp: SP
@Inject lateinit var omnipodUtil: OmnipodUtil
private var disposable: CompositeDisposable = CompositeDisposable() private var disposable: CompositeDisposable = CompositeDisposable()
private val loopHandler = Handler() private val loopHandler = Handler()
private lateinit var refreshLoop: Runnable private lateinit var refreshLoop: Runnable
//private val LOG = LoggerFactory.getLogger(L.PUMP)
//private var disposable: CompositeDisposable = CompositeDisposable()
//private var podAvailable = false
operator fun CompositeDisposable.plusAssign(disposable: Disposable) { operator fun CompositeDisposable.plusAssign(disposable: Disposable) {
add(disposable) add(disposable)
} }
init { init {
refreshLoop = Runnable { refreshLoop = Runnable {
activity?.runOnUiThread { updateGUI() } activity?.runOnUiThread { updateGUI() }
@ -139,12 +134,6 @@ class OmnipodFragment : DaggerFragment() {
if (omnipodPumpPlugin.rileyLinkService?.verifyConfiguration() != true) { if (omnipodPumpPlugin.rileyLinkService?.verifyConfiguration() != true) {
displayNotConfiguredDialog() displayNotConfiguredDialog()
} else { } else {
// val readPulseLog = AapsOmnipodManager.getInstance().readPulseLog()
//
// OKDialog.show(MainApp.instance().applicationContext, resourceHelper.gs(R.string.action),
// "Pulse Log:\n" + readPulseLog.toString(), null)
//
omnipod_pod_debug.isEnabled = false omnipod_pod_debug.isEnabled = false
omnipodPumpPlugin.addPodStatusRequest(OmnipodStatusRequest.GetPodPulseLog); omnipodPumpPlugin.addPodStatusRequest(OmnipodStatusRequest.GetPodPulseLog);
commandQueue.readStatus("Clicked Refresh", object : Callback() { commandQueue.readStatus("Clicked Refresh", object : Callback() {
@ -152,7 +141,6 @@ class OmnipodFragment : DaggerFragment() {
activity?.runOnUiThread { omnipod_pod_debug.isEnabled = true } activity?.runOnUiThread { omnipod_pod_debug.isEnabled = true }
} }
}) })
} }
} }
@ -174,7 +162,6 @@ class OmnipodFragment : DaggerFragment() {
.toObservable(EventOmnipodDeviceStatusChange::class.java) .toObservable(EventOmnipodDeviceStatusChange::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ .subscribe({
if (L.isEnabled(L.PUMP))
aapsLogger.info(LTag.PUMP, "onStatusEvent(EventOmnipodDeviceStatusChange): {}", it) aapsLogger.info(LTag.PUMP, "onStatusEvent(EventOmnipodDeviceStatusChange): {}", it)
setDeviceStatus() setDeviceStatus()
}, { fabricPrivacy.logException(it) }) }, { fabricPrivacy.logException(it) })
@ -192,12 +179,10 @@ class OmnipodFragment : DaggerFragment() {
.subscribe({ event -> .subscribe({ event ->
setVisibilityOfPodDebugButton() setVisibilityOfPodDebugButton()
}, { fabricPrivacy.logException(it) }) }, { fabricPrivacy.logException(it) })
} }
fun setVisibilityOfPodDebugButton() { fun setVisibilityOfPodDebugButton() {
val isEnabled = SP.getBoolean(OmnipodConst.Prefs.PodDebuggingOptionsEnabled, false) val isEnabled = sp.getBoolean(OmnipodConst.Prefs.PodDebuggingOptionsEnabled, false)
if (isEnabled) if (isEnabled)
omnipod_pod_debug.visibility = View.VISIBLE omnipod_pod_debug.visibility = View.VISIBLE
@ -205,7 +190,6 @@ class OmnipodFragment : DaggerFragment() {
omnipod_pod_debug.visibility = View.GONE omnipod_pod_debug.visibility = View.GONE
} }
private fun displayNotConfiguredDialog() { private fun displayNotConfiguredDialog() {
context?.let { context?.let {
OKDialog.show(it, resourceHelper.gs(R.string.combo_warning), OKDialog.show(it, resourceHelper.gs(R.string.combo_warning),
@ -219,15 +203,12 @@ class OmnipodFragment : DaggerFragment() {
loopHandler.removeCallbacks(refreshLoop) loopHandler.removeCallbacks(refreshLoop)
} }
@Synchronized @Synchronized
private fun setDeviceStatus() { private fun setDeviceStatus() {
//val omnipodPumpStatus: OmnipodPumpStatus = OmnipodUtil.getPumpStatus() //val omnipodPumpStatus: OmnipodPumpStatus = OmnipodUtil.getPumpStatus()
// omnipodPumpStatus.rileyLinkServiceState = checkStatusSet(omnipodPumpStatus.rileyLinkServiceState, // omnipodPumpStatus.rileyLinkServiceState = checkStatusSet(omnipodPumpStatus.rileyLinkServiceState,
// RileyLinkUtil.getServiceState()) as RileyLinkServiceState? // RileyLinkUtil.getServiceState()) as RileyLinkServiceState?
aapsLogger.info(LTag.PUMP, "setDeviceStatus: [pumpStatus={}]", omnipodPumpStatus) aapsLogger.info(LTag.PUMP, "setDeviceStatus: [pumpStatus={}]", omnipodPumpStatus)
val resourceId = omnipodPumpStatus.rileyLinkServiceState.getResourceId(RileyLinkTargetDevice.Omnipod) val resourceId = omnipodPumpStatus.rileyLinkServiceState.getResourceId(RileyLinkTargetDevice.Omnipod)
@ -251,7 +232,7 @@ class OmnipodFragment : DaggerFragment() {
resourceHelper.gs(it.getResourceId(RileyLinkTargetDevice.Omnipod)) resourceHelper.gs(it.getResourceId(RileyLinkTargetDevice.Omnipod))
} ?: "-" } ?: "-"
val driverState = OmnipodUtil.getDriverState(); val driverState = omnipodUtil.getDriverState();
aapsLogger.info(LTag.PUMP, "getDriverState: [driverState={}]", driverState) aapsLogger.info(LTag.PUMP, "getDriverState: [driverState={}]", driverState)
@ -294,6 +275,7 @@ class OmnipodFragment : DaggerFragment() {
PodDeviceState.ErrorWhenCommunicating, PodDeviceState.ErrorWhenCommunicating,
PodDeviceState.TimeoutWhenCommunicating, PodDeviceState.TimeoutWhenCommunicating,
PodDeviceState.InvalidConfiguration -> omnipod_pod_status.text = " " + resourceHelper.gs(podDeviceState.resourceId) PodDeviceState.InvalidConfiguration -> omnipod_pod_status.text = " " + resourceHelper.gs(podDeviceState.resourceId)
PodDeviceState.Active -> { PodDeviceState.Active -> {
omnipod_pod_status.text = "Active"; omnipod_pod_status.text = "Active";
@ -314,13 +296,12 @@ class OmnipodFragment : DaggerFragment() {
// } // }
// } // }
} }
else -> aapsLogger.warn(LTag.PUMP, "Unknown pump state: " + omnipodPumpStatus.podDeviceState) else -> aapsLogger.warn(LTag.PUMP, "Unknown pump state: " + omnipodPumpStatus.podDeviceState)
} }
} }
// pumpStatus.pumpDeviceState = checkStatusSet(pumpStatus.pumpDeviceState, // pumpStatus.pumpDeviceState = checkStatusSet(pumpStatus.pumpDeviceState,
// OmnipodUtil.getPumpDeviceState()) as PumpDeviceState? // OmnipodUtil.getPumpDeviceState()) as PumpDeviceState?
// //
@ -363,7 +344,6 @@ class OmnipodFragment : DaggerFragment() {
} }
} }
private fun checkStatusSet(object1: Any?, object2: Any?): Any? { private fun checkStatusSet(object1: Any?, object2: Any?): Any? {
return if (object1 == null) { return if (object1 == null) {
object2 object2
@ -470,11 +450,9 @@ class OmnipodFragment : DaggerFragment() {
} }
private fun updateAcknowledgeAlerts() { private fun updateAcknowledgeAlerts() {
omnipod_pod_active_alerts_ack.isEnabled = omnipodPumpStatus.ackAlertsAvailable omnipod_pod_active_alerts_ack.isEnabled = omnipodPumpStatus.ackAlertsAvailable
omnipod_pod_active_alerts.text = omnipodPumpStatus.ackAlertsText omnipod_pod_active_alerts.text = omnipodPumpStatus.ackAlertsText
} }
} }

View file

@ -9,8 +9,8 @@ import android.os.SystemClock;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import org.slf4j.Logger; import org.apache.commons.lang3.StringUtils;
import org.slf4j.LoggerFactory; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -39,7 +39,6 @@ import info.nightscout.androidaps.interfaces.CommandQueueProvider;
import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
@ -54,7 +53,6 @@ import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkPumpDevice; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkPumpDevice;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkService;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ResetRileyLinkConfigurationTask; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ResetRileyLinkConfigurationTask;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor;
@ -76,7 +74,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.service.RileyLinkOmnipodS
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.Round;
import info.nightscout.androidaps.utils.TimeChangeType; import info.nightscout.androidaps.utils.TimeChangeType;
import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP; import info.nightscout.androidaps.utils.sharedPreferences.SP;
@ -91,8 +89,7 @@ import io.reactivex.schedulers.Schedulers;
@Singleton @Singleton
public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPumpPluginInterface, RileyLinkPumpDevice { public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPumpPluginInterface, RileyLinkPumpDevice {
private static final Logger LOG = LoggerFactory.getLogger(L.PUMP); // TODO Dagger (maybe done)
private static OmnipodPumpPlugin plugin = null; private static OmnipodPumpPlugin plugin = null;
private RileyLinkServiceData rileyLinkServiceData; private RileyLinkServiceData rileyLinkServiceData;
private ServiceTaskExecutor serviceTaskExecutor; private ServiceTaskExecutor serviceTaskExecutor;
@ -100,6 +97,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
private OmnipodUtil omnipodUtil; private OmnipodUtil omnipodUtil;
protected OmnipodPumpStatus omnipodPumpStatus = null; protected OmnipodPumpStatus omnipodPumpStatus = null;
protected OmnipodUIComm omnipodUIComm; protected OmnipodUIComm omnipodUIComm;
private CompositeDisposable disposable = new CompositeDisposable(); private CompositeDisposable disposable = new CompositeDisposable();
@ -170,7 +168,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
// // TODO ccc // // TODO ccc
serviceConnection = new ServiceConnection() { serviceConnection = new ServiceConnection() {
@Override @Override
@ -199,7 +196,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
} }
// if (OmnipodPumpPlugin.this.omnipodPumpStatus != null) { // if (OmnipodPumpPlugin.this.omnipodPumpStatus != null) {
// //
// aapsLogger.debug(LTag.PUMP, "Starting OmniPod-RileyLink service"); // aapsLogger.debug(LTag.PUMP, "Starting OmniPod-RileyLink service");
@ -346,9 +342,8 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
} }
private void doPodCheck() { private void doPodCheck() {
if (System.currentTimeMillis() > this.nextPodCheck) { if (System.currentTimeMillis() > this.nextPodCheck) {
if (OmnipodUtil.getDriverState() == OmnipodDriverState.Initalized_NoPod) { if (omnipodUtil.getDriverState() == OmnipodDriverState.Initalized_NoPod) {
Notification notification = new Notification(Notification.OMNIPOD_POD_NOT_ATTACHED, resourceHelper.gs(R.string.omnipod_error_pod_not_attached), Notification.NORMAL); Notification notification = new Notification(Notification.OMNIPOD_POD_NOT_ATTACHED, resourceHelper.gs(R.string.omnipod_error_pod_not_attached), Notification.NORMAL);
rxBus.send(new EventNewNotification(notification)); rxBus.send(new EventNewNotification(notification));
} else { } else {
@ -522,7 +517,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class); Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
i.putExtra("soundid", 0); i.putExtra("soundid", 0);
i.putExtra("status", "Pulse Log (copied to clipboard):\n" + result.toString()); i.putExtra("status", "Pulse Log (copied to clipboard):\n" + result.toString());
i.putExtra("title", MainApp.gs(R.string.combo_warning)); i.putExtra("title", resourceHelper.gs(R.string.combo_warning));
i.putExtra("clipboardContent", result.toString()); i.putExtra("clipboardContent", result.toString());
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MainApp.instance().startActivity(i); MainApp.instance().startActivity(i);
@ -573,9 +568,11 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
// TODO read pod status // TODO read pod status
aapsLogger.error(LTag.PUMP, "getPodPumpStatus() NOT IMPLEMENTED"); aapsLogger.error(LTag.PUMP, "getPodPumpStatus() NOT IMPLEMENTED");
//addPodStatusRequest(OmnipodStatusRequest.GetPodState);
//getPodPumpStatusObject().driverState = OmnipodDriverState.Initalized_PodAvailable; //getPodPumpStatusObject().driverState = OmnipodDriverState.Initalized_PodAvailable;
//driverState = OmnipodDriverState.Initalized_PodAvailable; //driverState = OmnipodDriverState.Initalized_PodAvailable;
OmnipodUtil.setDriverState(OmnipodDriverState.Initalized_PodAttached); omnipodUtil.setDriverState(OmnipodDriverState.Initalized_PodAttached);
// we would probably need to read Basal Profile here too // we would probably need to read Basal Profile here too
} }
@ -627,7 +624,8 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
aapsLogger.info(LTag.PUMP, "PodSessionState-SP: loaded from SharedPreferences: " + podState); aapsLogger.info(LTag.PUMP, "PodSessionState-SP: loaded from SharedPreferences: " + podState);
if (podState != null) { if (podState != null) {
podSessionState = OmnipodUtil.getGsonInstance().fromJson(podState, PodSessionState.class); podSessionState = omnipodUtil.getGsonInstance().fromJson(podState, PodSessionState.class);
podSessionState.injectDaggerClass(injector);
omnipodUtil.setPodSessionState(podSessionState); omnipodUtil.setPodSessionState(podSessionState);
} }
} }
@ -645,8 +643,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
} else { } else {
aapsLogger.debug(LTag.PUMP, "No PodSessionState found. Pod probably not running."); aapsLogger.debug(LTag.PUMP, "No PodSessionState found. Pod probably not running.");
//podPumpStatus.driverState = OmnipodDriverState.Initalized_NoPod; omnipodUtil.setDriverState(OmnipodDriverState.Initalized_NoPod);
OmnipodUtil.setDriverState(OmnipodDriverState.Initalized_NoPod);
} }
finishAction("Omnipod Pump"); finishAction("Omnipod Pump");
@ -681,8 +678,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
@Override @Override
public long lastDataTime() { public long lastDataTime() {
getPodPumpStatusObject();
if (omnipodPumpStatus.lastConnection != 0) { if (omnipodPumpStatus.lastConnection != 0) {
return omnipodPumpStatus.lastConnection; return omnipodPumpStatus.lastConnection;
} }
@ -705,7 +700,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
@Override @Override
public double getReservoirLevel() { public double getReservoirLevel() {
return getPodPumpStatusObject().reservoirRemainingUnits; return omnipodPumpStatus.reservoirRemainingUnits;
} }
@ -715,21 +710,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
} }
protected OmnipodPumpStatus getPodPumpStatusObject() {
if (omnipodPumpStatus == null) {
// FIXME I don't know why this happens
aapsLogger.warn(LTag.PUMP, "!!!! Reset Pump Status Local");
// pumpStatusLocal = OmnipodUtil.getPumpStatus();
// if (omnipodCommunicationManager != null) {
// omnipodCommunicationManager.setPumpStatus(pumpStatusLocal);
// }
}
return omnipodPumpStatus;
}
@Override @Override
protected void triggerUIChange() { protected void triggerUIChange() {
rxBus.send(new EventOmnipodPumpValuesChanged()); rxBus.send(new EventOmnipodPumpValuesChanged());
@ -810,25 +790,20 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile,
boolean enforceNew) { boolean enforceNew) {
getPodPumpStatusObject();
setRefreshButtonEnabled(false); setRefreshButtonEnabled(false);
aapsLogger.info(LTag.PUMP, getLogPrefix() + "setTempBasalAbsolute: rate: {}, duration={}", absoluteRate, durationInMinutes); aapsLogger.info(LTag.PUMP, getLogPrefix() + "setTempBasalAbsolute: rate: {}, duration={}", absoluteRate, durationInMinutes);
// read current TBR // read current TBR
TempBasalPair tbrCurrent = readTBR(); TempBasalPair tbrCurrent = readTBR();
if (tbrCurrent != null) { if (tbrCurrent != null) {
aapsLogger.info(LTag.PUMP, getLogPrefix() + "setTempBasalAbsolute: Current Basal: duration: {} min, rate={}", aapsLogger.info(LTag.PUMP, getLogPrefix() + "setTempBasalAbsolute: Current Basal: duration: {} min, rate={}",
tbrCurrent.getDurationMinutes(), tbrCurrent.getInsulinRate()); tbrCurrent.getDurationMinutes(), tbrCurrent.getInsulinRate());
} }
if (tbrCurrent != null && !enforceNew) { if (tbrCurrent != null && !enforceNew) {
if (OmnipodUtil.isSame(tbrCurrent.getInsulinRate(), absoluteRate)) { if (Round.isSame(tbrCurrent.getInsulinRate(), absoluteRate)) {
aapsLogger.info(LTag.PUMP, getLogPrefix() + "setTempBasalAbsolute - No enforceNew and same rate. Exiting."); aapsLogger.info(LTag.PUMP, getLogPrefix() + "setTempBasalAbsolute - No enforceNew and same rate. Exiting.");
finishAction("TBR"); finishAction("TBR");
return new PumpEnactResult(getInjector()).success(true).enacted(false); return new PumpEnactResult(getInjector()).success(true).enacted(false);
@ -864,7 +839,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
PumpEnactResult result = responseTask.getResult(); PumpEnactResult result = responseTask.getResult();
aapsLogger.info(LTag.PUMP, getLogPrefix() + "setTempBasalAbsolute - setTBR. Response: " + result.success); aapsLogger.info(LTag.PUMP, getLogPrefix() + "setTempBasalAbsolute - setTBR. Response: " + result.success);
if (result.success) { if (result.success) {
@ -920,7 +894,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
finishAction("TBR"); finishAction("TBR");
if (result.success) { if (result.success) {
aapsLogger.info(LTag.PUMP, getLogPrefix() + "cancelTempBasal - Cancel TBR successful."); aapsLogger.info(LTag.PUMP, getLogPrefix() + "cancelTempBasal - Cancel TBR successful.");
TemporaryBasal tempBasal = new TemporaryBasal() // TemporaryBasal tempBasal = new TemporaryBasal() //
@ -930,21 +903,22 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
activePlugin.getActiveTreatments().addToHistoryTempBasal(tempBasal); activePlugin.getActiveTreatments().addToHistoryTempBasal(tempBasal);
} else { } else {
aapsLogger.info(LTag.PUMP, getLogPrefix() + "cancelTempBasal - Cancel TBR failed."); aapsLogger.info(LTag.PUMP, getLogPrefix() + "cancelTempBasal - Cancel TBR failed.");
} }
return result; return result;
} }
@NotNull
@Override @Override
public String serialNumber() { public String serialNumber() {
return getPodPumpStatusObject().podNumber; return StringUtils.isNotBlank(omnipodPumpStatus.podNumber) ?
omnipodPumpStatus.podNumber : "None";
} }
@NotNull
@Override @Override
public PumpEnactResult setNewBasalProfile(Profile profile) { public PumpEnactResult setNewBasalProfile(Profile profile) {
aapsLogger.info(LTag.PUMP, getLogPrefix() + "setNewBasalProfile"); aapsLogger.info(LTag.PUMP, getLogPrefix() + "setNewBasalProfile");
// this shouldn't be needed, but let's do check if profile setting we are setting is same as current one // this shouldn't be needed, but let's do check if profile setting we are setting is same as current one
@ -952,7 +926,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
return new PumpEnactResult(getInjector()) // return new PumpEnactResult(getInjector()) //
.success(true) // .success(true) //
.enacted(false) // .enacted(false) //
.comment(MainApp.gs(R.string.medtronic_cmd_basal_profile_not_set_is_same)); .comment(resourceHelper.gs(R.string.medtronic_cmd_basal_profile_not_set_is_same));
} }
setRefreshButtonEnabled(false); setRefreshButtonEnabled(false);
@ -962,16 +936,19 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
PumpEnactResult result = responseTask.getResult(); PumpEnactResult result = responseTask.getResult();
aapsLogger.info(LTag.PUMP, getLogPrefix() + "Basal Profile was set: " + result.success); aapsLogger.info(LTag.PUMP, getLogPrefix() + "Basal Profile was set: " + result.success);
if (result.success) { if (result.success) {
this.currentProfile = profile; this.currentProfile = profile;
Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.gs(R.string.profile_set_ok), Notification.INFO, 60); Notification notification = new Notification(Notification.PROFILE_SET_OK,
resourceHelper.gs(R.string.profile_set_ok),
Notification.INFO, 60);
rxBus.send(new EventNewNotification(notification)); rxBus.send(new EventNewNotification(notification));
} else { } else {
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.gs(R.string.failedupdatebasalprofile), Notification.URGENT); Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE,
resourceHelper.gs(R.string.failedupdatebasalprofile),
Notification.URGENT);
rxBus.send(new EventNewNotification(notification)); rxBus.send(new EventNewNotification(notification));
} }
@ -997,13 +974,11 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
} }
return this.customActions; return this.customActions;
} }
@Override @Override
public void executeCustomAction(CustomActionType customActionType) { public void executeCustomAction(CustomActionType customActionType) {
OmnipodCustomActionType mcat = (OmnipodCustomActionType) customActionType; OmnipodCustomActionType mcat = (OmnipodCustomActionType) customActionType;
switch (mcat) { switch (mcat) {
@ -1016,15 +991,13 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
default: default:
break; break;
} }
} }
@Override @Override
public void timezoneOrDSTChanged(TimeChangeType timeChangeType) { public void timezoneOrDSTChanged(TimeChangeType timeChangeType) {
aapsLogger.warn(LTag.PUMP, getLogPrefix() + "Time, Date and/or TimeZone changed. [changeType=" + timeChangeType.name() + ", eventHandlingEnabled=" + omnipodPumpStatus.timeChangeEventEnabled + "]"); aapsLogger.warn(LTag.PUMP, getLogPrefix() + "Time, Date and/or TimeZone changed. [changeType=" + timeChangeType.name() + ", eventHandlingEnabled=" + omnipodPumpStatus.timeChangeEventEnabled + "]");
if (OmnipodUtil.getDriverState() == OmnipodDriverState.Initalized_PodAttached) { if (omnipodUtil.getDriverState() == OmnipodDriverState.Initalized_PodAttached) {
if (omnipodPumpStatus.timeChangeEventEnabled) { if (omnipodPumpStatus.timeChangeEventEnabled) {
aapsLogger.info(LTag.PUMP, getLogPrefix() + "Time,and/or TimeZone changed event received and will be consumed by driver."); aapsLogger.info(LTag.PUMP, getLogPrefix() + "Time,and/or TimeZone changed event received and will be consumed by driver.");
this.hasTimeDateOrTimeZoneChanged = true; this.hasTimeDateOrTimeZoneChanged = true;
@ -1034,8 +1007,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
@Override @Override
public boolean isUnreachableAlertTimeoutExceeded(long unreachableTimeoutMilliseconds) { public boolean isUnreachableAlertTimeoutExceeded(long unreachableTimeoutMilliseconds) {
getPodPumpStatusObject();
if (omnipodPumpStatus.lastConnection != 0 || omnipodPumpStatus.lastErrorConnection != 0) { if (omnipodPumpStatus.lastConnection != 0 || omnipodPumpStatus.lastErrorConnection != 0) {
if (omnipodPumpStatus.lastConnection + unreachableTimeoutMilliseconds < System.currentTimeMillis()) { if (omnipodPumpStatus.lastConnection + unreachableTimeoutMilliseconds < System.currentTimeMillis()) {
if (omnipodPumpStatus.lastErrorConnection > omnipodPumpStatus.lastConnection) { if (omnipodPumpStatus.lastErrorConnection > omnipodPumpStatus.lastConnection) {
@ -1048,7 +1019,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
// This happens when we simply didn't need to send any commands to the pump // This happens when we simply didn't need to send any commands to the pump
return false; return false;
} }
} }
return false; return false;

View file

@ -1,8 +1,5 @@
package info.nightscout.androidaps.plugins.pump.omnipod.comm; package info.nightscout.androidaps.plugins.pump.omnipod.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -10,7 +7,6 @@ import javax.inject.Inject;
import dagger.android.HasAndroidInjector; import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus; import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager;
@ -23,14 +19,17 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.Rile
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData; 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.hw.rileylink.service.tasks.ServiceTaskExecutor;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicConverter;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.MedtronicPumpHistoryDecoder;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState; import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin; 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.action.OmnipodAction;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.CommunicationException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalPacketTypeException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalResponseException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.NonceOutOfSyncException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.NonceResyncException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.NotEnoughDataException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.PodFaultException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.PodReturnedErrorResponseException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.MessageBlock; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.MessageBlock;
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.OmnipodPacket; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.OmnipodPacket;
@ -44,30 +43,20 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.MessageBlockType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PacketType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PacketType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodState; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodState;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.CommunicationException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalPacketTypeException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalResponseException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.NonceOutOfSyncException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.NonceResyncException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.NotEnoughDataException;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException; import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.PodFaultException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.PodReturnedErrorResponseException;
/** /**
* Created by andy on 6/29/18. * Created by andy on 6/29/18.
*/ */
public class OmnipodCommunicationManager extends RileyLinkCommunicationManager { public class OmnipodCommunicationManager extends RileyLinkCommunicationManager {
@Inject AAPSLogger aapsLogger; @Inject public AAPSLogger aapsLogger;
@Inject OmnipodPumpStatus omnipodPumpStatus; @Inject OmnipodPumpStatus omnipodPumpStatus;
@Inject OmnipodPumpPlugin omnipodPumpPlugin; @Inject OmnipodPumpPlugin omnipodPumpPlugin;
@Inject RileyLinkServiceData rileyLinkServiceData; @Inject RileyLinkServiceData rileyLinkServiceData;
@Inject ServiceTaskExecutor serviceTaskExecutor; @Inject ServiceTaskExecutor serviceTaskExecutor;
//private static final Logger LOG = LoggerFactory.getLogger(L.PUMPCOMM);
public OmnipodCommunicationManager(HasAndroidInjector injector, RFSpy rfspy) { public OmnipodCommunicationManager(HasAndroidInjector injector, RFSpy rfspy) {
super(injector, rfspy); super(injector, rfspy);
omnipodPumpStatus.previousConnection = sp.getLong( omnipodPumpStatus.previousConnection = sp.getLong(
@ -143,7 +132,6 @@ public class OmnipodCommunicationManager extends RileyLinkCommunicationManager {
aapsLogger.debug(LTag.PUMPCOMM, "Exchanging OmnipodMessage [responseClass={}, podState={}, message={}, addressOverride={}, ackAddressOverride={}, automaticallyResyncNonce={}]: {}", // aapsLogger.debug(LTag.PUMPCOMM, "Exchanging OmnipodMessage [responseClass={}, podState={}, message={}, addressOverride={}, ackAddressOverride={}, automaticallyResyncNonce={}]: {}", //
responseClass.getSimpleName(), podState, message, addressOverride, ackAddressOverride, automaticallyResyncNonce, message); responseClass.getSimpleName(), podState, message, addressOverride, ackAddressOverride, automaticallyResyncNonce, message);
for (int i = 0; 2 > i; i++) { for (int i = 0; 2 > i; i++) {
if (podState.hasNonceState() && message.isNonceResyncable()) { if (podState.hasNonceState() && message.isNonceResyncable()) {
@ -235,7 +223,6 @@ public class OmnipodCommunicationManager extends RileyLinkCommunicationManager {
// so it's impossible for the pod to have received the message // so it's impossible for the pod to have received the message
newException.setCertainFailure(!lastPacket); newException.setCertainFailure(!lastPacket);
aapsLogger.debug(LTag.PUMPCOMM, "Caught exception in transportMessages. Set certainFailure to {} because encodedMessage.length={}", newException.isCertainFailure(), encodedMessage.length); aapsLogger.debug(LTag.PUMPCOMM, "Caught exception in transportMessages. Set certainFailure to {} because encodedMessage.length={}", newException.isCertainFailure(), encodedMessage.length);
throw newException; throw newException;
@ -281,7 +268,7 @@ public class OmnipodCommunicationManager extends RileyLinkCommunicationManager {
throw new NotEnoughDataException(receivedMessageData); throw new NotEnoughDataException(receivedMessageData);
} else if (messageBlocks.size() > 1) { } else if (messageBlocks.size() > 1) {
// BS: don't expect this to happen // BS: don't expect this to happen
aapsLogger.error(LTag.PUMPCOMM,"Received more than one message block: {}", messageBlocks.toString()); aapsLogger.error(LTag.PUMPBTCOMM, "Received more than one message block: {}", messageBlocks.toString());
} }
return messageBlocks.get(0); return messageBlocks.get(0);
@ -308,10 +295,10 @@ public class OmnipodCommunicationManager extends RileyLinkCommunicationManager {
if (RileyLinkBLEError.Timeout.equals(ex.getErrorCode())) { if (RileyLinkBLEError.Timeout.equals(ex.getErrorCode())) {
quiet = true; quiet = true;
} else { } else {
aapsLogger.debug(LTag.PUMPCOMM,"Ignoring exception in ackUntilQuiet", ex); aapsLogger.debug(LTag.PUMPBTCOMM, "Ignoring exception in ackUntilQuiet", ex);
} }
} catch (OmnipodException ex) { } catch (OmnipodException ex) {
aapsLogger.debug(LTag.PUMPCOMM,"Ignoring exception in ackUntilQuiet", ex); aapsLogger.debug(LTag.PUMPBTCOMM, "Ignoring exception in ackUntilQuiet", ex);
} catch (Exception ex) { } catch (Exception ex) {
throw new CommunicationException(CommunicationException.Type.UNEXPECTED_EXCEPTION, ex); throw new CommunicationException(CommunicationException.Type.UNEXPECTED_EXCEPTION, ex);
} }
@ -335,7 +322,7 @@ public class OmnipodCommunicationManager extends RileyLinkCommunicationManager {
try { try {
response = sendAndListen(packet, responseTimeoutMilliseconds, repeatCount, 9, preambleExtensionMilliseconds, OmnipodPacket.class); response = sendAndListen(packet, responseTimeoutMilliseconds, repeatCount, 9, preambleExtensionMilliseconds, OmnipodPacket.class);
} catch (RileyLinkCommunicationException | OmnipodException ex) { } catch (RileyLinkCommunicationException | OmnipodException ex) {
aapsLogger.debug(LTag.PUMPCOMM,"Ignoring exception in exchangePackets", ex); aapsLogger.debug(LTag.PUMPBTCOMM, "Ignoring exception in exchangePackets", ex);
} catch (Exception ex) { } catch (Exception ex) {
throw new CommunicationException(CommunicationException.Type.UNEXPECTED_EXCEPTION, ex); throw new CommunicationException(CommunicationException.Type.UNEXPECTED_EXCEPTION, ex);
} }

View file

@ -3,18 +3,12 @@ package info.nightscout.androidaps.plugins.pump.omnipod.comm;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.DateTimeZone; import org.joda.time.DateTimeZone;
import org.joda.time.Duration; import org.joda.time.Duration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.AcknowledgeAlertsAction; import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.AcknowledgeAlertsAction;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.AssignAddressAction; import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.AssignAddressAction;
@ -30,6 +24,11 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.SetBasalSched
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.SetTempBasalAction; import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.SetTempBasalAction;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.InsertCannulaService; import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.InsertCannulaService;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.PrimeService; import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.PrimeService;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.CommunicationException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalDeliveryStatusException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalSetupProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.NonceOutOfSyncException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.PodFaultException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.CancelDeliveryCommand; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.CancelDeliveryCommand;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoRecentPulseLog; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoRecentPulseLog;
@ -42,14 +41,8 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedule; import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedule;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateChangedHandler; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateChangedHandler;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.CommunicationException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalDeliveryStatusException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalSetupProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.NonceOutOfSyncException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException; import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.PodFaultException;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
import info.nightscout.androidaps.utils.sharedPreferences.SP; import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.Completable; import io.reactivex.Completable;
import io.reactivex.Flowable; import io.reactivex.Flowable;
@ -61,8 +54,6 @@ import io.reactivex.subjects.SingleSubject;
public class OmnipodManager { public class OmnipodManager {
private static final int ACTION_VERIFICATION_TRIES = 3; private static final int ACTION_VERIFICATION_TRIES = 3;
//private static final Logger LOG = LoggerFactory.getLogger(L.PUMP);
protected final OmnipodCommunicationManager communicationService; protected final OmnipodCommunicationManager communicationService;
private final PodStateChangedHandler podStateChangedHandler; private final PodStateChangedHandler podStateChangedHandler;
protected PodSessionState podState; protected PodSessionState podState;
@ -70,19 +61,23 @@ public class OmnipodManager {
private ActiveBolusData activeBolusData; private ActiveBolusData activeBolusData;
private final Object bolusDataMutex = new Object(); private final Object bolusDataMutex = new Object();
private HasAndroidInjector injector; //private HasAndroidInjector injector;
@Inject AAPSLogger aapsLogger; AAPSLogger aapsLogger;
@Inject SP sp; SP sp;
public OmnipodManager(HasAndroidInjector injector, public OmnipodManager(//HasAndroidInjector injector,
AAPSLogger aapsLogger,
SP sp,
OmnipodCommunicationManager communicationService, OmnipodCommunicationManager communicationService,
PodSessionState podState, PodSessionState podState,
PodStateChangedHandler podStateChangedHandler) { PodStateChangedHandler podStateChangedHandler) {
this.injector = injector; // this.injector = injector;
this.injector.androidInjector().inject(this); // this.injector.androidInjector().inject(this);
if (communicationService == null) { if (communicationService == null) {
throw new IllegalArgumentException("Communication service cannot be null"); throw new IllegalArgumentException("Communication service cannot be null");
} }
this.aapsLogger = aapsLogger;
this.sp = sp;
this.communicationService = communicationService; this.communicationService = communicationService;
if (podState != null) { if (podState != null) {
podState.setStateChangedHandler(podStateChangedHandler); podState.setStateChangedHandler(podStateChangedHandler);
@ -91,11 +86,11 @@ public class OmnipodManager {
this.podStateChangedHandler = podStateChangedHandler; this.podStateChangedHandler = podStateChangedHandler;
} }
public OmnipodManager(HasAndroidInjector injector, // public OmnipodManager(HasAndroidInjector injector,
OmnipodCommunicationManager communicationService, // OmnipodCommunicationManager communicationService,
PodSessionState podState) { // PodSessionState podState) {
this(injector, communicationService, podState, null); // this(injector, communicationService, podState, null);
} // }
public synchronized Single<SetupActionResult> pairAndPrime() { public synchronized Single<SetupActionResult> pairAndPrime() {
logStartingCommandExecution("pairAndPrime"); logStartingCommandExecution("pairAndPrime");
@ -121,7 +116,7 @@ public class OmnipodManager {
return Single.timer(delayInSeconds, TimeUnit.SECONDS) // return Single.timer(delayInSeconds, TimeUnit.SECONDS) //
.map(o -> verifySetupAction(statusResponse -> .map(o -> verifySetupAction(statusResponse ->
PrimeAction.updatePrimingStatus(podState, statusResponse), SetupProgress.PRIMING_FINISHED)) // PrimeAction.updatePrimingStatus(podState, statusResponse, aapsLogger), SetupProgress.PRIMING_FINISHED)) //
.observeOn(Schedulers.io()); .observeOn(Schedulers.io());
} }
@ -144,7 +139,7 @@ public class OmnipodManager {
return Single.timer(delayInSeconds, TimeUnit.SECONDS) // return Single.timer(delayInSeconds, TimeUnit.SECONDS) //
.map(o -> verifySetupAction(statusResponse -> .map(o -> verifySetupAction(statusResponse ->
InsertCannulaAction.updateCannulaInsertionStatus(podState, statusResponse), SetupProgress.COMPLETED)) // InsertCannulaAction.updateCannulaInsertionStatus(podState, statusResponse, aapsLogger), SetupProgress.COMPLETED)) //
.observeOn(Schedulers.io()); .observeOn(Schedulers.io());
} }
@ -254,9 +249,7 @@ public class OmnipodManager {
try { try {
return executeAndVerify(() -> { return executeAndVerify(() -> {
StatusResponse statusResponse = communicationService.executeAction(new CancelDeliveryAction(podState, deliveryTypes, acknowledgementBeep)); StatusResponse statusResponse = communicationService.executeAction(new CancelDeliveryAction(podState, deliveryTypes, acknowledgementBeep));
if (isLoggingEnabled()) { aapsLogger.info(LTag.PUMPBTCOMM, "Status response after cancel delivery[types={}]: {}", deliveryTypes.toString(), statusResponse.toString());
aapsLogger.info(LTag.PUMPCOMM,"Status response after cancel delivery[types={}]: {}", deliveryTypes.toString(), statusResponse.toString());
}
return statusResponse; return statusResponse;
}); });
} finally { } finally {
@ -282,9 +275,7 @@ public class OmnipodManager {
} }
// Catch uncertain exceptions as we still want to report bolus progress indication // Catch uncertain exceptions as we still want to report bolus progress indication
if (isLoggingEnabled()) { aapsLogger.error(LTag.PUMPBTCOMM, "Caught exception[certainFailure=false] in bolus", ex);
aapsLogger.error(LTag.PUMPCOMM,"Caught exception[certainFailure=false] in bolus", ex);
}
commandDeliveryStatus = CommandDeliveryStatus.UNCERTAIN_FAILURE; commandDeliveryStatus = CommandDeliveryStatus.UNCERTAIN_FAILURE;
} finally { } finally {
logCommandExecutionFinished("bolus"); logCommandExecutionFinished("bolus");
@ -335,14 +326,10 @@ public class OmnipodManager {
// Substract units not delivered in case of a Pod failure // Substract units not delivered in case of a Pod failure
unitsNotDelivered = ex.getFaultEvent().getInsulinNotDelivered(); unitsNotDelivered = ex.getFaultEvent().getInsulinNotDelivered();
if (isLoggingEnabled()) { aapsLogger.debug(LTag.PUMPBTCOMM, "Caught PodFaultException in bolus completion verification", ex);
aapsLogger.debug(LTag.PUMPCOMM,"Caught PodFaultException in bolus completion verification", ex);
}
break; break;
} catch (Exception ex) { } catch (Exception ex) {
if (isLoggingEnabled()) { aapsLogger.debug(LTag.PUMPBTCOMM, "Ignoring exception in bolus completion verification", ex);
aapsLogger.debug(LTag.PUMPCOMM,"Ignoring exception in bolus completion verification", ex);
}
} }
} }
@ -446,23 +433,19 @@ public class OmnipodManager {
// Try to get pulse log for diagnostics // Try to get pulse log for diagnostics
// FIXME replace by storing to file // FIXME replace by storing to file
if (isLoggingEnabled()) {
try { try {
PodInfoResponse podInfoResponse = communicationService.executeAction(new GetPodInfoAction(podState, PodInfoType.RECENT_PULSE_LOG)); PodInfoResponse podInfoResponse = communicationService.executeAction(new GetPodInfoAction(podState, PodInfoType.RECENT_PULSE_LOG));
PodInfoRecentPulseLog pulseLogInfo = podInfoResponse.getPodInfo(); PodInfoRecentPulseLog pulseLogInfo = podInfoResponse.getPodInfo();
aapsLogger.info(LTag.PUMPCOMM,"Retrieved pulse log from the pod: {}", pulseLogInfo.toString()); aapsLogger.info(LTag.PUMPBTCOMM, "Retrieved pulse log from the pod: {}", pulseLogInfo.toString());
} catch (Exception ex) { } catch (Exception ex) {
aapsLogger.warn(LTag.PUMPCOMM,"Failed to retrieve pulse log from the pod", ex); aapsLogger.warn(LTag.PUMPBTCOMM, "Failed to retrieve pulse log from the pod", ex);
}
} }
try { try {
// Always send acknowledgement beeps here. Matches the PDM's behavior // Always send acknowledgement beeps here. Matches the PDM's behavior
communicationService.executeAction(new DeactivatePodAction(podState, true)); communicationService.executeAction(new DeactivatePodAction(podState, true));
} catch (PodFaultException ex) { } catch (PodFaultException ex) {
if (isLoggingEnabled()) { aapsLogger.info(LTag.PUMPBTCOMM, "Ignoring PodFaultException in deactivatePod", ex);
aapsLogger.info(LTag.PUMPCOMM,"Ignoring PodFaultException in deactivatePod", ex);
}
} finally { } finally {
logCommandExecutionFinished("deactivatePod"); logCommandExecutionFinished("deactivatePod");
} }
@ -471,9 +454,7 @@ public class OmnipodManager {
} }
public void resetPodState(boolean forcedByUser) { public void resetPodState(boolean forcedByUser) {
if (isLoggingEnabled()) { aapsLogger.warn(LTag.PUMPBTCOMM, "resetPodState has been called. forcedByUser={}", forcedByUser);
aapsLogger.warn(LTag.PUMPCOMM,"resetPodState has been called. forcedByUser={}", forcedByUser);
}
podState = null; podState = null;
sp.remove(OmnipodConst.Prefs.PodState); sp.remove(OmnipodConst.Prefs.PodState);
} }
@ -514,23 +495,18 @@ public class OmnipodManager {
if (isCertainFailure(originalException)) { if (isCertainFailure(originalException)) {
throw originalException; throw originalException;
} else { } else {
if (isLoggingEnabled()) { aapsLogger.warn(LTag.PUMPBTCOMM, "Caught exception in executeAndVerify. Verifying command by using cancel none command to verify nonce", originalException);
aapsLogger.warn(LTag.PUMPCOMM,"Caught exception in executeAndVerify. Verifying command by using cancel none command to verify nonce", originalException);
}
try { try {
logStartingCommandExecution("verifyCommand"); logStartingCommandExecution("verifyCommand");
StatusResponse statusResponse = communicationService.sendCommand(StatusResponse.class, podState, StatusResponse statusResponse = communicationService.sendCommand(StatusResponse.class, podState,
new CancelDeliveryCommand(podState.getCurrentNonce(), BeepType.NO_BEEP, DeliveryType.NONE), false); new CancelDeliveryCommand(podState.getCurrentNonce(), BeepType.NO_BEEP, DeliveryType.NONE), false);
if (isLoggingEnabled()) { aapsLogger.info(LTag.PUMPBTCOMM, "Command status resolved to SUCCESS. Status response after cancelDelivery[types=DeliveryType.NONE]: {}", statusResponse);
aapsLogger.info(LTag.PUMPCOMM,"Command status resolved to SUCCESS. Status response after cancelDelivery[types=DeliveryType.NONE]: {}", statusResponse);
}
return statusResponse; return statusResponse;
} catch (NonceOutOfSyncException verificationException) { } catch (NonceOutOfSyncException verificationException) {
if (isLoggingEnabled()) { aapsLogger.error(LTag.PUMPBTCOMM, "Command resolved to FAILURE (CERTAIN_FAILURE)", verificationException);
aapsLogger.error(LTag.PUMPCOMM,"Command resolved to FAILURE (CERTAIN_FAILURE)", verificationException);
}
if (originalException instanceof OmnipodException) { if (originalException instanceof OmnipodException) {
((OmnipodException) originalException).setCertainFailure(true); ((OmnipodException) originalException).setCertainFailure(true);
throw originalException; throw originalException;
@ -540,9 +516,7 @@ public class OmnipodManager {
throw newException; throw newException;
} }
} catch (Exception verificationException) { } catch (Exception verificationException) {
if (isLoggingEnabled()) { aapsLogger.error(LTag.PUMPBTCOMM, "Command unresolved (UNCERTAIN_FAILURE)", verificationException);
aapsLogger.error(LTag.PUMPCOMM,"Command unresolved (UNCERTAIN_FAILURE)", verificationException);
}
throw originalException; throw originalException;
} finally { } finally {
logCommandExecutionFinished("verifyCommand"); logCommandExecutionFinished("verifyCommand");
@ -581,20 +555,11 @@ public class OmnipodManager {
} }
private void logStartingCommandExecution(String action) { private void logStartingCommandExecution(String action) {
if (isLoggingEnabled()) { aapsLogger.debug(LTag.PUMPBTCOMM, "Starting command execution for action: " + action);
aapsLogger.debug(LTag.PUMPCOMM,"Starting command execution for action: " + action);
}
} }
private void logCommandExecutionFinished(String action) { private void logCommandExecutionFinished(String action) {
if (isLoggingEnabled()) { aapsLogger.debug(LTag.PUMPBTCOMM, "Command execution finished for action: " + action);
aapsLogger.debug(LTag.PUMPCOMM,"Command execution finished for action: " + action);
}
}
// TODO remove this
private boolean isLoggingEnabled() {
return true;
} }
private static Duration calculateBolusDuration(double units, double deliveryRate) { private static Duration calculateBolusDuration(double units, double deliveryRate) {

View file

@ -42,7 +42,7 @@ public class AssignAddressAction implements OmnipodAction<PodSessionState> {
PodSessionState podState = new PodSessionState(timeZone, address, assignAddressResponse.getPiVersion(), PodSessionState podState = new PodSessionState(timeZone, address, assignAddressResponse.getPiVersion(),
assignAddressResponse.getPmVersion(), assignAddressResponse.getLot(), assignAddressResponse.getTid(), assignAddressResponse.getPmVersion(), assignAddressResponse.getLot(), assignAddressResponse.getTid(),
setupState.getPacketNumber(), 0x00); // At this point, for an unknown reason, the pod starts counting messages from 0 again setupState.getPacketNumber(), 0x00, communicationService.injector); // At this point, for an unknown reason, the pod starts counting messages from 0 again
podState.setStateChangedHandler(podStateChangedHandler); podState.setStateChangedHandler(podStateChangedHandler);
return podState; return podState;

View file

@ -1,19 +1,17 @@
package info.nightscout.androidaps.plugins.pump.omnipod.comm.action; package info.nightscout.androidaps.plugins.pump.omnipod.comm.action;
import org.slf4j.Logger; import info.nightscout.androidaps.logging.AAPSLogger;
import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager; import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.InsertCannulaService; import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.InsertCannulaService;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.ActionInitializationException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalSetupProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress; import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedule; import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedule;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.ActionInitializationException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalSetupProgressException;
public class InsertCannulaAction implements OmnipodAction<StatusResponse> { public class InsertCannulaAction implements OmnipodAction<StatusResponse> {
private static final Logger LOG = LoggerFactory.getLogger(InsertCannulaAction.class);
private final PodSessionState podState; private final PodSessionState podState;
private final InsertCannulaService service; private final InsertCannulaService service;
@ -34,12 +32,10 @@ public class InsertCannulaAction implements OmnipodAction<StatusResponse> {
this.initialBasalSchedule = initialBasalSchedule; this.initialBasalSchedule = initialBasalSchedule;
} }
public static void updateCannulaInsertionStatus(PodSessionState podState, StatusResponse statusResponse) { public static void updateCannulaInsertionStatus(PodSessionState podState, StatusResponse statusResponse, AAPSLogger aapsLogger) {
if (podState.getSetupProgress().equals(SetupProgress.CANNULA_INSERTING) && if (podState.getSetupProgress().equals(SetupProgress.CANNULA_INSERTING) &&
statusResponse.getPodProgressStatus().isReadyForDelivery()) { statusResponse.getPodProgressStatus().isReadyForDelivery()) {
if (LOG.isDebugEnabled()) { aapsLogger.debug(LTag.PUMPBTCOMM, "Updating SetupProgress from CANNULA_INSERTING to COMPLETED");
LOG.debug("Updating SetupProgress from CANNULA_INSERTING to COMPLETED");
}
podState.setSetupProgress(SetupProgress.COMPLETED); podState.setSetupProgress(SetupProgress.COMPLETED);
} }
} }
@ -66,7 +62,7 @@ public class InsertCannulaAction implements OmnipodAction<StatusResponse> {
} else if (podState.getSetupProgress().equals(SetupProgress.CANNULA_INSERTING)) { } else if (podState.getSetupProgress().equals(SetupProgress.CANNULA_INSERTING)) {
// Check status // Check status
StatusResponse statusResponse = communicationService.executeAction(new GetStatusAction(podState)); StatusResponse statusResponse = communicationService.executeAction(new GetStatusAction(podState));
updateCannulaInsertionStatus(podState, statusResponse); updateCannulaInsertionStatus(podState, statusResponse, communicationService.aapsLogger);
return statusResponse; return statusResponse;
} else { } else {
throw new IllegalSetupProgressException(null, podState.getSetupProgress()); throw new IllegalSetupProgressException(null, podState.getSetupProgress());

View file

@ -1,19 +1,17 @@
package info.nightscout.androidaps.plugins.pump.omnipod.comm.action; package info.nightscout.androidaps.plugins.pump.omnipod.comm.action;
import org.slf4j.Logger; import info.nightscout.androidaps.logging.AAPSLogger;
import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager; import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.PrimeService; import info.nightscout.androidaps.plugins.pump.omnipod.comm.action.service.PrimeService;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.ActionInitializationException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalSetupProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress; import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.ActionInitializationException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalSetupProgressException;
public class PrimeAction implements OmnipodAction<StatusResponse> { public class PrimeAction implements OmnipodAction<StatusResponse> {
private static final Logger LOG = LoggerFactory.getLogger(PrimeAction.class);
private final PrimeService service; private final PrimeService service;
private final PodSessionState podState; private final PodSessionState podState;
@ -29,11 +27,9 @@ public class PrimeAction implements OmnipodAction<StatusResponse> {
this.podState = podState; this.podState = podState;
} }
public static void updatePrimingStatus(PodSessionState podState, StatusResponse statusResponse) { public static void updatePrimingStatus(PodSessionState podState, StatusResponse statusResponse, AAPSLogger aapsLogger) {
if (podState.getSetupProgress().equals(SetupProgress.PRIMING) && statusResponse.getPodProgressStatus().equals(PodProgressStatus.READY_FOR_BASAL_SCHEDULE)) { if (podState.getSetupProgress().equals(SetupProgress.PRIMING) && statusResponse.getPodProgressStatus().equals(PodProgressStatus.READY_FOR_BASAL_SCHEDULE)) {
if (LOG.isDebugEnabled()) { aapsLogger.debug(LTag.PUMPBTCOMM, "Updating SetupProgress from PRIMING to PRIMING_FINISHED");
LOG.debug("Updating SetupProgress from PRIMING to PRIMING_FINISHED");
}
podState.setSetupProgress(SetupProgress.PRIMING_FINISHED); podState.setSetupProgress(SetupProgress.PRIMING_FINISHED);
} }
} }
@ -56,7 +52,7 @@ public class PrimeAction implements OmnipodAction<StatusResponse> {
} else if (podState.getSetupProgress().equals(SetupProgress.PRIMING)) { } else if (podState.getSetupProgress().equals(SetupProgress.PRIMING)) {
// Check status // Check status
StatusResponse statusResponse = communicationService.executeAction(new GetStatusAction(podState)); StatusResponse statusResponse = communicationService.executeAction(new GetStatusAction(podState));
updatePrimingStatus(podState, statusResponse); updatePrimingStatus(podState, statusResponse, communicationService.aapsLogger);
return statusResponse; return statusResponse;
} else { } else {
throw new IllegalSetupProgressException(null, podState.getSetupProgress()); throw new IllegalSetupProgressException(null, podState.getSetupProgress());

View file

@ -5,13 +5,15 @@ import com.google.gson.Gson;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.DateTimeZone; import org.joda.time.DateTimeZone;
import org.joda.time.Duration; import org.joda.time.Duration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import info.nightscout.androidaps.logging.L; import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoFaultEvent; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoFaultEvent;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertSet; import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertSet;
@ -26,10 +28,14 @@ import info.nightscout.androidaps.plugins.pump.omnipod.util.OmniCRC;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.sharedPreferences.SP;
public class PodSessionState extends PodState { public class PodSessionState extends PodState {
private static final Logger LOG = LoggerFactory.getLogger(L.PUMPCOMM);
@Inject AAPSLogger aapsLogger;
@Inject SP sp;
@Inject OmnipodUtil omnipodUtil;
private final Map<AlertSlot, AlertType> configuredAlerts; private final Map<AlertSlot, AlertType> configuredAlerts;
private transient PodStateChangedHandler stateChangedHandler; private transient PodStateChangedHandler stateChangedHandler;
@ -50,8 +56,9 @@ public class PodSessionState extends PodState {
private DeliveryStatus lastDeliveryStatus; private DeliveryStatus lastDeliveryStatus;
public PodSessionState(DateTimeZone timeZone, int address, FirmwareVersion piVersion, public PodSessionState(DateTimeZone timeZone, int address, FirmwareVersion piVersion,
FirmwareVersion pmVersion, int lot, int tid, int packetNumber, int messageNumber) { FirmwareVersion pmVersion, int lot, int tid, int packetNumber, int messageNumber, HasAndroidInjector injector) {
super(address, messageNumber, packetNumber); super(address, messageNumber, packetNumber);
injectDaggerClass(injector);
if (timeZone == null) { if (timeZone == null) {
throw new IllegalArgumentException("Time zone can not be null"); throw new IllegalArgumentException("Time zone can not be null");
} }
@ -70,6 +77,10 @@ public class PodSessionState extends PodState {
handleUpdates(); handleUpdates();
} }
public void injectDaggerClass(HasAndroidInjector injector) {
injector.androidInjector().inject(this);
}
public void setStateChangedHandler(PodStateChangedHandler handler) { public void setStateChangedHandler(PodStateChangedHandler handler) {
// FIXME this is an ugly workaround for not being able to serialize the PodStateChangedHandler // FIXME this is an ugly workaround for not being able to serialize the PodStateChangedHandler
if (stateChangedHandler != null) { if (stateChangedHandler != null) {
@ -241,7 +252,7 @@ public class PodSessionState extends PodState {
boolean newSuspendedState = statusResponse.getDeliveryStatus() == DeliveryStatus.SUSPENDED; boolean newSuspendedState = statusResponse.getDeliveryStatus() == DeliveryStatus.SUSPENDED;
if (suspended != newSuspendedState) { if (suspended != newSuspendedState) {
LOG.info("Updating pod suspended state in updateFromStatusResponse. newSuspendedState={}, statusResponse={}", newSuspendedState, statusResponse.toString()); aapsLogger.info(LTag.PUMPCOMM, "Updating pod suspended state in updateFromStatusResponse. newSuspendedState={}, statusResponse={}", newSuspendedState, statusResponse.toString());
suspended = newSuspendedState; suspended = newSuspendedState;
} }
activeAlerts = statusResponse.getAlerts(); activeAlerts = statusResponse.getAlerts();
@ -251,10 +262,10 @@ public class PodSessionState extends PodState {
} }
private void handleUpdates() { private void handleUpdates() {
Gson gson = OmnipodUtil.getGsonInstance(); Gson gson = omnipodUtil.getGsonInstance();
String gsonValue = gson.toJson(this); String gsonValue = gson.toJson(this);
LOG.info("PodSessionState-SP: Saved Session State to SharedPreferences: " + gsonValue); aapsLogger.info(LTag.PUMPCOMM, "PodSessionState-SP: Saved Session State to SharedPreferences: " + gsonValue);
SP.putString(OmnipodConst.Prefs.PodState, gsonValue); sp.putString(OmnipodConst.Prefs.PodState, gsonValue);
if (stateChangedHandler != null) { if (stateChangedHandler != null) {
stateChangedHandler.handle(this); stateChangedHandler.handle(this);
} }

View file

@ -13,8 +13,7 @@ import android.widget.TextView;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import org.slf4j.Logger; import org.jetbrains.annotations.NotNull;
import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
@ -22,26 +21,32 @@ import java.util.Collections;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.List; import java.util.List;
import javax.inject.Inject;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity; import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair; import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpHistoryEntryGroup; import info.nightscout.androidaps.plugins.pump.common.defs.PumpHistoryEntryGroup;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.utils.ProfileUtil; import info.nightscout.androidaps.plugins.pump.common.utils.ProfileUtil;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.db.PodHistory; import info.nightscout.androidaps.plugins.pump.omnipod.driver.db.PodHistory;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
public class PodHistoryActivity extends NoSplashAppCompatActivity { public class PodHistoryActivity extends NoSplashAppCompatActivity {
private static Logger LOG = LoggerFactory.getLogger(L.PUMP); @Inject AAPSLogger aapsLogger;
@Inject OmnipodUtil omnipodUtil;
@Inject ResourceHelper resourceHelper;
Spinner historyTypeSpinner; private Spinner historyTypeSpinner;
TextView statusView; private TextView statusView;
RecyclerView recyclerView; private RecyclerView recyclerView;
LinearLayoutManager llm; private LinearLayoutManager linearLayoutManager;
static TypeList showingType = null; static TypeList showingType = null;
static PumpHistoryEntryGroup selectedGroup = PumpHistoryEntryGroup.All; static PumpHistoryEntryGroup selectedGroup = PumpHistoryEntryGroup.All;
@ -73,7 +78,7 @@ public class PodHistoryActivity extends NoSplashAppCompatActivity {
this.filteredHistoryList.clear(); this.filteredHistoryList.clear();
LOG.debug("Items on full list: {}", fullHistoryList.size()); aapsLogger.debug(LTag.PUMP, "Items on full list: {}", fullHistoryList.size());
if (group == PumpHistoryEntryGroup.All) { if (group == PumpHistoryEntryGroup.All) {
this.filteredHistoryList.addAll(fullHistoryList); this.filteredHistoryList.addAll(fullHistoryList);
@ -90,7 +95,7 @@ public class PodHistoryActivity extends NoSplashAppCompatActivity {
this.recyclerViewAdapter.notifyDataSetChanged(); this.recyclerViewAdapter.notifyDataSetChanged();
} }
LOG.debug("Items on filtered list: {}", filteredHistoryList.size()); aapsLogger.debug(LTag.PUMP, "Items on filtered list: {}", filteredHistoryList.size());
} }
@ -128,13 +133,13 @@ public class PodHistoryActivity extends NoSplashAppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.omnipod_pod_history_activity); setContentView(R.layout.omnipod_pod_history_activity);
historyTypeSpinner = (Spinner) findViewById(R.id.omnipod_historytype); historyTypeSpinner = findViewById(R.id.omnipod_historytype);
statusView = (TextView) findViewById(R.id.omnipod_historystatus); statusView = findViewById(R.id.omnipod_historystatus);
recyclerView = (RecyclerView) findViewById(R.id.omnipod_history_recyclerview); recyclerView = findViewById(R.id.omnipod_history_recyclerview);
recyclerView.setHasFixedSize(true); recyclerView.setHasFixedSize(true);
llm = new LinearLayoutManager(this);
recyclerView.setLayoutManager(llm); linearLayoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(linearLayoutManager);
prepareData(); prepareData();
@ -188,41 +193,34 @@ public class PodHistoryActivity extends NoSplashAppCompatActivity {
PumpHistoryEntryGroup entryGroup; PumpHistoryEntryGroup entryGroup;
String name; String name;
TypeList(PumpHistoryEntryGroup entryGroup) { TypeList(PumpHistoryEntryGroup entryGroup) {
this.entryGroup = entryGroup; this.entryGroup = entryGroup;
this.name = entryGroup.getTranslated(); this.name = entryGroup.getTranslated();
} }
@NotNull
@Override @Override
public String toString() { public String toString() {
return name; return name;
} }
} }
public static class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.HistoryViewHolder> { public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.HistoryViewHolder> {
List<PodHistory> historyList; List<PodHistory> historyList;
RecyclerViewAdapter(List<PodHistory> historyList) { RecyclerViewAdapter(List<PodHistory> historyList) {
this.historyList = historyList; this.historyList = historyList;
} }
public void setHistoryList(List<PodHistory> historyList) { public void setHistoryList(List<PodHistory> historyList) {
// this.historyList.clear();
// this.historyList.addAll(historyList);
this.historyList = historyList; this.historyList = historyList;
Collections.sort(this.historyList); Collections.sort(this.historyList);
// this.notifyDataSetChanged();
} }
@NotNull
@Override @Override
public HistoryViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { public HistoryViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.omnipod_pod_history_item, // View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.omnipod_pod_history_item, //
@ -232,7 +230,7 @@ public class PodHistoryActivity extends NoSplashAppCompatActivity {
@Override @Override
public void onBindViewHolder(HistoryViewHolder holder, int position) { public void onBindViewHolder(@NotNull HistoryViewHolder holder, int position) {
PodHistory record = historyList.get(position); PodHistory record = historyList.get(position);
if (record != null) { if (record != null) {
@ -250,8 +248,8 @@ public class PodHistoryActivity extends NoSplashAppCompatActivity {
switch (historyEntry.getPodDbEntryType()) { switch (historyEntry.getPodDbEntryType()) {
case SetTemporaryBasal: { case SetTemporaryBasal: {
TempBasalPair tempBasalPair = OmnipodUtil.getGsonInstance().fromJson(historyEntry.getData(), TempBasalPair.class); TempBasalPair tempBasalPair = omnipodUtil.getGsonInstance().fromJson(historyEntry.getData(), TempBasalPair.class);
valueView.setText(MainApp.gs(R.string.omnipod_cmd_tbr_value, tempBasalPair.getInsulinRate(), tempBasalPair.getDurationMinutes())); valueView.setText(resourceHelper.gs(R.string.omnipod_cmd_tbr_value, tempBasalPair.getInsulinRate(), tempBasalPair.getDurationMinutes()));
} }
break; break;
@ -266,9 +264,9 @@ public class PodHistoryActivity extends NoSplashAppCompatActivity {
case SetBolus: { case SetBolus: {
if (historyEntry.getData().contains(";")) { if (historyEntry.getData().contains(";")) {
String[] splitVal = historyEntry.getData().split(";"); String[] splitVal = historyEntry.getData().split(";");
valueView.setText(MainApp.gs(R.string.omnipod_cmd_bolus_value_with_carbs, Double.valueOf(splitVal[0]), Double.valueOf(splitVal[1]))); valueView.setText(resourceHelper.gs(R.string.omnipod_cmd_bolus_value_with_carbs, Double.valueOf(splitVal[0]), Double.valueOf(splitVal[1])));
} else { } else {
valueView.setText(MainApp.gs(R.string.omnipod_cmd_bolus_value, Double.valueOf(historyEntry.getData()))); valueView.setText(resourceHelper.gs(R.string.omnipod_cmd_bolus_value, Double.valueOf(historyEntry.getData())));
} }
} }
break; break;
@ -299,19 +297,15 @@ public class PodHistoryActivity extends NoSplashAppCompatActivity {
} }
private void setProfileValue(String data, TextView valueView) { private void setProfileValue(String data, TextView valueView) {
LOG.debug("Profile json:\n" + data); aapsLogger.debug(LTag.PUMP, "Profile json:\n" + data);
try { try {
Profile.ProfileValue[] profileValuesArray = OmnipodUtil.getGsonInstance().fromJson(data, Profile.ProfileValue[].class); Profile.ProfileValue[] profileValuesArray = omnipodUtil.getGsonInstance().fromJson(data, Profile.ProfileValue[].class);
//profile = new Profile(new JSONObject(data), Constants.MGDL);
valueView.setText(ProfileUtil.getBasalProfilesDisplayable(profileValuesArray, PumpType.Insulet_Omnipod)); valueView.setText(ProfileUtil.getBasalProfilesDisplayable(profileValuesArray, PumpType.Insulet_Omnipod));
} catch (Exception e) { } catch (Exception e) {
LOG.error("Problem parsing Profile json. Ex: {}, Data:\n{}", e.getMessage(), data); aapsLogger.error(LTag.PUMP, "Problem parsing Profile json. Ex: {}, Data:\n{}", e.getMessage(), data);
valueView.setText(""); valueView.setText("");
} }
//Profile profile = OmnipodUtil.getGsonInstance().fromJson(data, Profile.class);
} }
@ -327,7 +321,7 @@ public class PodHistoryActivity extends NoSplashAppCompatActivity {
} }
static class HistoryViewHolder extends RecyclerView.ViewHolder { class HistoryViewHolder extends RecyclerView.ViewHolder {
TextView timeView; TextView timeView;
TextView typeView; TextView typeView;

View file

@ -6,17 +6,14 @@ import com.atech.android.library.wizardpager.WizardPagerActivity
import com.atech.android.library.wizardpager.WizardPagerContext import com.atech.android.library.wizardpager.WizardPagerContext
import com.atech.android.library.wizardpager.data.WizardPagerSettings import com.atech.android.library.wizardpager.data.WizardPagerSettings
import com.atech.android.library.wizardpager.defs.WizardStepsWayType import com.atech.android.library.wizardpager.defs.WizardStepsWayType
import info.nightscout.androidaps.MainApp import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
import info.nightscout.androidaps.events.EventRefreshOverview import info.nightscout.androidaps.events.EventRefreshOverview
import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin
import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin
import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.defs.PodActionType import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.defs.PodActionType
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.model.FullInitPodWizardModel import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.model.FullInitPodWizardModel
@ -45,6 +42,7 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
@Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var fabricPrivacy: FabricPrivacy
@Inject lateinit var commandQueue: CommandQueueProvider @Inject lateinit var commandQueue: CommandQueueProvider
@Inject lateinit var omnipodUtil: OmnipodUtil @Inject lateinit var omnipodUtil: OmnipodUtil
@Inject lateinit var injector: HasAndroidInjector
private var initPodChanged = false private var initPodChanged = false
private var podSessionFullyInitalized = false private var podSessionFullyInitalized = false
@ -68,13 +66,11 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
initPodChanged = true initPodChanged = true
} }
initpod_pod_history.setOnClickListener { initpod_pod_history.setOnClickListener {
showPodHistory() showPodHistory()
} }
refreshButtons(); refreshButtons();
} }
override fun onDestroy() { override fun onDestroy() {
@ -89,7 +85,7 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
fun initPodAction() { fun initPodAction() {
val pagerSettings = WizardPagerSettings() val pagerSettings = WizardPagerSettings()
var refreshAction = InitPodRefreshAction(this, PodActionType.InitPod) var refreshAction = InitPodRefreshAction(injector, this, PodActionType.InitPod)
pagerSettings.setWizardStepsWayType(WizardStepsWayType.CancelNext) pagerSettings.setWizardStepsWayType(WizardStepsWayType.CancelNext)
pagerSettings.setFinishStringResourceId(R.string.close) pagerSettings.setFinishStringResourceId(R.string.close)
@ -117,7 +113,7 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
fun removePodAction() { fun removePodAction() {
val pagerSettings = WizardPagerSettings() val pagerSettings = WizardPagerSettings()
var refreshAction = InitPodRefreshAction(this, PodActionType.RemovePod) var refreshAction = InitPodRefreshAction(injector, this, PodActionType.RemovePod)
pagerSettings.setWizardStepsWayType(WizardStepsWayType.CancelNext) pagerSettings.setWizardStepsWayType(WizardStepsWayType.CancelNext)
pagerSettings.setFinishStringResourceId(R.string.close) pagerSettings.setFinishStringResourceId(R.string.close)
@ -142,7 +138,7 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
OKDialog.showConfirmation(this, OKDialog.showConfirmation(this,
resourceHelper.gs(R.string.omnipod_cmd_reset_pod_desc), Thread { resourceHelper.gs(R.string.omnipod_cmd_reset_pod_desc), Thread {
AapsOmnipodManager.getInstance().resetPodStatus() AapsOmnipodManager.getInstance().resetPodStatus()
OmnipodUtil.setDriverState(OmnipodDriverState.Initalized_NoPod) omnipodUtil.setDriverState(OmnipodDriverState.Initalized_NoPod)
refreshButtons() refreshButtons()
}) })
} }
@ -163,7 +159,7 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
initpod_remove_pod.isEnabled = isPodSessionActive initpod_remove_pod.isEnabled = isPodSessionActive
initpod_reset_pod.isEnabled = isPodSessionActive initpod_reset_pod.isEnabled = isPodSessionActive
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
initpod_init_pod.isEnabled = false initpod_init_pod.isEnabled = false
initpod_remove_pod.isEnabled = false initpod_remove_pod.isEnabled = false

View file

@ -5,13 +5,15 @@ import com.atech.android.library.wizardpager.defs.action.FinishActionInterface;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress; import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress;
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.PodManagementActivity; import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.PodManagementActivity;
@ -19,20 +21,23 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.defs.PodAc
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodDriverState; import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodDriverState;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.sharedPreferences.SP;
/** /**
* Created by andy on 12/11/2019 * Created by andy on 12/11/2019
*/ */
public class InitPodRefreshAction extends AbstractCancelAction implements FinishActionInterface { public class InitPodRefreshAction extends AbstractCancelAction implements FinishActionInterface {
private static final Logger LOG = LoggerFactory.getLogger(L.PUMP);
private PodManagementActivity podManagementActivity; private PodManagementActivity podManagementActivity;
private PodActionType actionType; private PodActionType actionType;
OmnipodUtil omnipodUtil; @Inject OmnipodUtil omnipodUtil;
@Inject AAPSLogger aapsLogger;
@Inject SP sp;
public InitPodRefreshAction(PodManagementActivity podManagementActivity, PodActionType actionType) { public InitPodRefreshAction(HasAndroidInjector injector, PodManagementActivity podManagementActivity, PodActionType actionType) {
injector.androidInjector().inject(this);
this.podManagementActivity = podManagementActivity; this.podManagementActivity = podManagementActivity;
this.actionType = actionType; this.actionType = actionType;
} }
@ -71,7 +76,7 @@ public class InitPodRefreshAction extends AbstractCancelAction implements Finish
return; return;
try { try {
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
String enteredBy = SP.getString("careportal_enteredby", ""); String enteredBy = sp.getString("careportal_enteredby", "");
if (!enteredBy.equals("")) data.put("enteredBy", enteredBy); if (!enteredBy.equals("")) data.put("enteredBy", enteredBy);
data.put("created_at", DateUtil.toISOString(date)); data.put("created_at", DateUtil.toISOString(date));
data.put("eventType", event); data.put("eventType", event);
@ -83,7 +88,7 @@ public class InitPodRefreshAction extends AbstractCancelAction implements Finish
MainApp.getDbHelper().createOrUpdate(careportalEvent); MainApp.getDbHelper().createOrUpdate(careportalEvent);
NSUpload.uploadCareportalEntryToNS(data); NSUpload.uploadCareportalEntryToNS(data);
} catch (JSONException e) { } catch (JSONException e) {
LOG.error("Unhandled exception when uploading SiteChange event.", e); aapsLogger.error(LTag.PUMPCOMM, "Unhandled exception when uploading SiteChange event.", e);
} }
} }

View file

@ -3,37 +3,22 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.pages;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.ListFragment;
import com.tech.freak.wizardpager.model.ModelCallbacks;
import com.tech.freak.wizardpager.model.Page;
import com.tech.freak.wizardpager.model.ReviewItem; import com.tech.freak.wizardpager.model.ReviewItem;
import com.tech.freak.wizardpager.ui.PageFragmentCallbacks; import com.tech.freak.wizardpager.ui.PageFragmentCallbacks;
import com.tech.freak.wizardpager.ui.ReviewFragment;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import dagger.android.support.DaggerFragment; import dagger.android.support.DaggerFragment;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.FirmwareVersion;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
@ -152,10 +137,10 @@ public class PodInfoFragment extends DaggerFragment {
private ArrayList<ReviewItem> dataSet; private ArrayList<ReviewItem> dataSet;
Context mContext; Context mContext;
private int lastPosition = -1;
// View lookup cache // View lookup cache
public PodInfoAdapter(ArrayList<ReviewItem> data, Context context) { public PodInfoAdapter(ArrayList<ReviewItem> data, Context context) {
super(context, com.tech.freak.wizardpager.R.layout.list_item_review, data); super(context, com.tech.freak.wizardpager.R.layout.list_item_review, data);
this.dataSet = data; this.dataSet = data;
@ -163,9 +148,6 @@ public class PodInfoFragment extends DaggerFragment {
} }
private int lastPosition = -1;
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
// Get the data item for this position // Get the data item for this position
@ -183,7 +165,6 @@ public class PodInfoFragment extends DaggerFragment {
viewHolder.txtName = (TextView) convertView.findViewById(android.R.id.text1); viewHolder.txtName = (TextView) convertView.findViewById(android.R.id.text1);
viewHolder.txtType = (TextView) convertView.findViewById(android.R.id.text2); viewHolder.txtType = (TextView) convertView.findViewById(android.R.id.text2);
result = convertView; result = convertView;
convertView.setTag(viewHolder); convertView.setTag(viewHolder);
@ -192,16 +173,12 @@ public class PodInfoFragment extends DaggerFragment {
result = convertView; result = convertView;
} }
viewHolder.txtName.setText(dataModel.getTitle()); viewHolder.txtName.setText(dataModel.getTitle());
viewHolder.txtType.setText(dataModel.getDisplayValue()); viewHolder.txtType.setText(dataModel.getDisplayValue());
// Return the completed view to render on screen // Return the completed view to render on screen
return convertView; return convertView;
} }
} }
private static class ViewHolder { private static class ViewHolder {
@ -209,6 +186,4 @@ public class PodInfoFragment extends DaggerFragment {
TextView txtType; TextView txtType;
} }
} }

View file

@ -1,23 +1,14 @@
package info.nightscout.androidaps.plugins.pump.omnipod.driver; package info.nightscout.androidaps.plugins.pump.omnipod.driver;
import org.joda.time.LocalDateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays; import java.util.Arrays;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus; import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair; import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
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.common.hw.rileylink.defs.RileyLinkError; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
@ -28,9 +19,8 @@ import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicDe
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
/** /**
* Created by andy on 4.8.2019 * Created by andy on 4.8.2019
@ -38,9 +28,8 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper;
@Singleton @Singleton
public class OmnipodPumpStatus extends PumpStatus { public class OmnipodPumpStatus extends PumpStatus {
//private static Logger LOG = LoggerFactory.getLogger(L.PUMP);
private final ResourceHelper resourceHelper; private final ResourceHelper resourceHelper;
private final info.nightscout.androidaps.utils.sharedPreferences.SP sp; private final SP sp;
private final RileyLinkUtil rileyLinkUtil; private final RileyLinkUtil rileyLinkUtil;
private final RxBusWrapper rxBus; private final RxBusWrapper rxBus;
@ -60,9 +49,7 @@ public class OmnipodPumpStatus extends PumpStatus {
public PodSessionState podSessionState; public PodSessionState podSessionState;
public PumpType pumpType; public PumpType pumpType;
private boolean rileyLinkAddressChanged = false; public String regexMac = "([\\da-fA-F]{1,2}(?:\\:|$)){6}";
private String regexMac = "([\\da-fA-F]{1,2}(?:\\:|$)){6}";
public String podNumber; public String podNumber;
public PodDeviceState podDeviceState = PodDeviceState.NeverContacted; public PodDeviceState podDeviceState = PodDeviceState.NeverContacted;
@ -108,8 +95,6 @@ public class OmnipodPumpStatus extends PumpStatus {
} }
public String getErrorInfo() { public String getErrorInfo() {
//verifyConfiguration(); //verifyConfiguration();
@ -117,7 +102,6 @@ public class OmnipodPumpStatus extends PumpStatus {
} }
// public boolean setNotInPreInit() { // public boolean setNotInPreInit() {
// this.inPreInit = false; // this.inPreInit = false;
// //
@ -133,10 +117,6 @@ public class OmnipodPumpStatus extends PumpStatus {
} }
private boolean isLogEnabled() {
return L.isEnabled(L.PUMP);
}
public TempBasalPair getTemporaryBasal() { public TempBasalPair getTemporaryBasal() {
TempBasalPair tbr = new TempBasalPair(); TempBasalPair tbr = new TempBasalPair();
@ -162,7 +142,6 @@ public class OmnipodPumpStatus extends PumpStatus {
", tempBasalAmount=" + tempBasalAmount + ", tempBasalAmount=" + tempBasalAmount +
", tempBasalLength=" + tempBasalLength + ", tempBasalLength=" + tempBasalLength +
", podSessionState=" + podSessionState + ", podSessionState=" + podSessionState +
", rileyLinkAddressChanged=" + rileyLinkAddressChanged +
", regexMac='" + regexMac + '\'' + ", regexMac='" + regexMac + '\'' +
", podNumber='" + podNumber + '\'' + ", podNumber='" + podNumber + '\'' +
", podDeviceState=" + podDeviceState + ", podDeviceState=" + podDeviceState +

View file

@ -26,7 +26,6 @@ import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.interfaces.ActivePluginProvider;
import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
@ -40,6 +39,21 @@ import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager; import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodManager; import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.SetupActionResult; import info.nightscout.androidaps.plugins.pump.omnipod.comm.SetupActionResult;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.ActionInitializationException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.CommandInitializationException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.CommunicationException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.CrcMismatchException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalDeliveryStatusException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalPacketTypeException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalPodProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalResponseException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalSetupProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.MessageDecodingException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.NonceOutOfSyncException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.NonceResyncException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.NotEnoughDataException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.PodFaultException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.PodReturnedErrorResponseException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoRecentPulseLog; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoRecentPulseLog;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoResponse; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoResponse;
@ -58,40 +72,25 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.db.PodHistory;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.db.PodHistoryEntryType; import info.nightscout.androidaps.plugins.pump.omnipod.driver.db.PodHistoryEntryType;
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodAcknowledgeAlertsChanged; import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodAcknowledgeAlertsChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged; import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.ActionInitializationException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.CommandInitializationException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.CommunicationException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.CrcMismatchException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalDeliveryStatusException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalPacketTypeException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalPodProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalResponseException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalSetupProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.MessageDecodingException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.NonceOutOfSyncException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.NonceResyncException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.NotEnoughDataException;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException; import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.PodFaultException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.PodReturnedErrorResponseException;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface { public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface {
private OmnipodUtil omnipodUtil; private OmnipodUtil omnipodUtil;
AAPSLogger aapsLogger; private AAPSLogger aapsLogger;
RxBusWrapper rxBus; private RxBusWrapper rxBus;
ResourceHelper resourceHelper; private ResourceHelper resourceHelper;
HasAndroidInjector injector; private HasAndroidInjector injector;
ActivePluginProvider activePlugin; private ActivePluginProvider activePlugin;
private OmnipodPumpStatus pumpStatus;
//private static final Logger LOG = LoggerFactory.getLogger(L.PUMP);
private final OmnipodManager delegate; private final OmnipodManager delegate;
private static AapsOmnipodManager instance; private static AapsOmnipodManager instance;
private OmnipodPumpStatus pumpStatus;
private Date lastBolusTime; private Date lastBolusTime;
private Double lastBolusUnits; private Double lastBolusUnits;
@ -106,6 +105,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
OmnipodUtil omnipodUtil, OmnipodUtil omnipodUtil,
AAPSLogger aapsLogger, AAPSLogger aapsLogger,
RxBusWrapper rxBus, RxBusWrapper rxBus,
SP sp,
ResourceHelper resourceHelper, ResourceHelper resourceHelper,
HasAndroidInjector injector, HasAndroidInjector injector,
ActivePluginProvider activePlugin) { ActivePluginProvider activePlugin) {
@ -117,7 +117,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
this.activePlugin = activePlugin; this.activePlugin = activePlugin;
this.pumpStatus = _pumpStatus; this.pumpStatus = _pumpStatus;
delegate = new OmnipodManager(communicationService, podState, podSessionState -> { delegate = new OmnipodManager(aapsLogger, sp, communicationService, podState, podSessionState -> {
// Handle pod state changes // Handle pod state changes
omnipodUtil.setPodSessionState(podSessionState); omnipodUtil.setPodSessionState(podSessionState);
updatePumpStatus(podSessionState); updatePumpStatus(podSessionState);
@ -454,7 +454,6 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
@Override @Override
public void setPumpStatus(OmnipodPumpStatus pumpStatus) { public void setPumpStatus(OmnipodPumpStatus pumpStatus) {
this.pumpStatus = pumpStatus; this.pumpStatus = pumpStatus;
//this.getCommunicationService().setPumpStatus(pumpStatus);
updatePumpStatus(delegate.getPodState()); updatePumpStatus(delegate.getPodState());
} }
@ -547,9 +546,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
//TreatmentsPlugin plugin = TreatmentsPlugin.getPlugin(); //TreatmentsPlugin plugin = TreatmentsPlugin.getPlugin();
TreatmentsInterface plugin = activePlugin.getActiveTreatments(); TreatmentsInterface plugin = activePlugin.getActiveTreatments();
if (plugin.isTempBasalInProgress()) { if (plugin.isTempBasalInProgress()) {
if (isLoggingEnabled()) {
aapsLogger.debug(LTag.PUMP, "Reporting implicitly cancelled TBR to Treatments plugin"); aapsLogger.debug(LTag.PUMP, "Reporting implicitly cancelled TBR to Treatments plugin");
}
long time = System.currentTimeMillis() - 1000; long time = System.currentTimeMillis() - 1000;
@ -583,7 +580,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
if (data instanceof String) { if (data instanceof String) {
podHistory.setData((String) data); podHistory.setData((String) data);
} else { } else {
podHistory.setData(OmnipodUtil.getGsonInstance().toJson(data)); podHistory.setData(omnipodUtil.getGsonInstance().toJson(data));
} }
} }
@ -599,17 +596,15 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
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) {
String comment = null; String comment = null;
switch (res.getResultType()) { switch (res.getResultType()) {
case FAILURE: case FAILURE: {
if (isLoggingEnabled()) {
aapsLogger.error(LTag.PUMP, "Setup action failed: illegal setup progress: {}", res.getSetupProgress()); aapsLogger.error(LTag.PUMP, "Setup action failed: illegal setup progress: {}", res.getSetupProgress());
}
comment = getStringResource(R.string.omnipod_driver_error_invalid_progress_state, res.getSetupProgress()); comment = getStringResource(R.string.omnipod_driver_error_invalid_progress_state, res.getSetupProgress());
break;
case VERIFICATION_FAILURE:
if (isLoggingEnabled()) {
aapsLogger.error(LTag.PUMP,"Setup action verification failed: caught exception", res.getException());
} }
break;
case VERIFICATION_FAILURE: {
aapsLogger.error(LTag.PUMP, "Setup action verification failed: caught exception", res.getException());
comment = getStringResource(R.string.omnipod_driver_error_setup_action_verification_failed); comment = getStringResource(R.string.omnipod_driver_error_setup_action_verification_failed);
}
break; break;
} }
@ -657,15 +652,11 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
// Shouldn't be reachable // Shouldn't be reachable
comment = getStringResource(R.string.omnipod_driver_error_unexpected_exception_type, ex.getClass().getName()); comment = getStringResource(R.string.omnipod_driver_error_unexpected_exception_type, ex.getClass().getName());
} }
if (isLoggingEnabled()) {
aapsLogger.error(LTag.PUMP, String.format("Caught OmnipodException[certainFailure=%s] from OmnipodManager (user-friendly error message: %s)", ((OmnipodException) ex).isCertainFailure(), comment), ex); aapsLogger.error(LTag.PUMP, String.format("Caught OmnipodException[certainFailure=%s] from OmnipodManager (user-friendly error message: %s)", ((OmnipodException) ex).isCertainFailure(), comment), ex);
}
} else { } else {
comment = getStringResource(R.string.omnipod_driver_error_unexpected_exception_type, ex.getClass().getName()); comment = getStringResource(R.string.omnipod_driver_error_unexpected_exception_type, ex.getClass().getName());
if (isLoggingEnabled()) {
aapsLogger.error(LTag.PUMP, String.format("Caught unexpected exception type[certainFailure=false] from OmnipodManager (user-friendly error message: %s)", comment), ex); aapsLogger.error(LTag.PUMP, String.format("Caught unexpected exception type[certainFailure=false] from OmnipodManager (user-friendly error message: %s)", comment), ex);
} }
}
return comment; return comment;
} }
@ -744,11 +735,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
} }
private String getStringResource(int id, Object... args) { private String getStringResource(int id, Object... args) {
return MainApp.gs(id, args); return resourceHelper.gs(id, args);
}
private boolean isLoggingEnabled() {
return L.isEnabled(L.PUMP);
} }
static BasalSchedule mapProfileToBasalSchedule(Profile profile) { static BasalSchedule mapProfileToBasalSchedule(Profile profile) {

View file

@ -3,12 +3,8 @@ package info.nightscout.androidaps.plugins.pump.omnipod.driver.db;
import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable; import com.j256.ormlite.table.DatabaseTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.db.DbObjectBase; import info.nightscout.androidaps.db.DbObjectBase;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil; import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
/** /**
@ -17,8 +13,6 @@ import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
@DatabaseTable(tableName = DatabaseHelper.DATABASE_POD_HISTORY) @DatabaseTable(tableName = DatabaseHelper.DATABASE_POD_HISTORY)
public class PodHistory implements DbObjectBase, Comparable<PodHistory> { public class PodHistory implements DbObjectBase, Comparable<PodHistory> {
private static Logger log = LoggerFactory.getLogger(L.DATABASE);
@DatabaseField(id = true) @DatabaseField(id = true)
public long date; public long date;

View file

@ -1,20 +1,10 @@
package info.nightscout.androidaps.plugins.pump.omnipod.driver.ui; package info.nightscout.androidaps.plugins.pump.omnipod.driver.ui;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import dagger.android.HasAndroidInjector; import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUIPostprocessor;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface;
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.OmnipodPumpPluginInterface; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
/** /**
@ -22,8 +12,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
*/ */
public class OmnipodUIComm { public class OmnipodUIComm {
private static final Logger LOG = LoggerFactory.getLogger(L.PUMP);
private final HasAndroidInjector injector; private final HasAndroidInjector injector;
private final AAPSLogger aapsLogger; private final AAPSLogger aapsLogger;
private final OmnipodUtil omnipodUtil; private final OmnipodUtil omnipodUtil;
@ -31,10 +19,6 @@ public class OmnipodUIComm {
private final OmnipodUIPostprocessor omnipodUIPostprocessor; private final OmnipodUIPostprocessor omnipodUIPostprocessor;
//OmnipodCommunicationManagerInterface ocmInstance = null;
//OmnipodUIPostprocessor uiPostprocessor; // = new OmnipodUIPostprocessor();
public OmnipodUIComm( public OmnipodUIComm(
HasAndroidInjector injector, HasAndroidInjector injector,
AAPSLogger aapsLogger, AAPSLogger aapsLogger,
@ -50,22 +34,9 @@ public class OmnipodUIComm {
} }
private OmnipodCommunicationManagerInterface getCommunicationManager() {
return omnipodCommunicationManager;
}
// public OmnipodUIComm(OmnipodCommunicationManagerInterface communicationManager, OmnipodPumpPluginInterface plugin, OmnipodPumpStatus status) {
// ocmInstance = communicationManager;
// uiPostprocessor = new OmnipodUIPostprocessor(plugin, status);
// }
public OmnipodUITask executeCommand(OmnipodCommandType commandType, Object... parameters) { public OmnipodUITask executeCommand(OmnipodCommandType commandType, Object... parameters) {
if (isLogEnabled()) aapsLogger.warn(LTag.PUMP, "Execute Command: " + commandType.name());
LOG.warn("Execute Command: " + commandType.name());
OmnipodUITask task = new OmnipodUITask(injector, commandType, parameters); OmnipodUITask task = new OmnipodUITask(injector, commandType, parameters);
@ -79,7 +50,7 @@ public class OmnipodUIComm {
// LOG.warn("@@@ End Thread"); // LOG.warn("@@@ End Thread");
// }); // });
task.execute(getCommunicationManager()); task.execute(this.omnipodCommunicationManager);
// for (int i = 0; i < getMaxWaitTime(commandType); i++) { // for (int i = 0; i < getMaxWaitTime(commandType); i++) {
// synchronized (task) { // synchronized (task) {
@ -99,8 +70,8 @@ public class OmnipodUIComm {
// } // }
// } // }
if (!task.isReceived() && isLogEnabled()) { if (!task.isReceived()) {
LOG.warn("Reply not received for " + commandType); aapsLogger.warn(LTag.PUMP, "Reply not received for " + commandType);
} }
task.postProcess(omnipodUIPostprocessor); task.postProcess(omnipodUIPostprocessor);
@ -109,9 +80,4 @@ public class OmnipodUIComm {
} }
private boolean isLogEnabled() {
return L.isEnabled(L.PUMP);
}
} }

View file

@ -8,12 +8,8 @@ import java.util.Date;
import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCustomActionType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodPumpPluginInterface; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodPumpPluginInterface;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodResponseType;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
/** /**
@ -22,6 +18,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
public class OmnipodUIPostprocessor { public class OmnipodUIPostprocessor {
private static final Logger LOG = LoggerFactory.getLogger(L.PUMP); private static final Logger LOG = LoggerFactory.getLogger(L.PUMP);
private OmnipodPumpStatus pumpStatus; private OmnipodPumpStatus pumpStatus;
@ -58,7 +55,8 @@ public class OmnipodUIPostprocessor {
} }
} }
} }
} break; }
break;
case CancelTemporaryBasal: { case CancelTemporaryBasal: {
pumpStatus.tempBasalStart = 0; pumpStatus.tempBasalStart = 0;
@ -100,9 +98,6 @@ public class OmnipodUIPostprocessor {
} }
} }

View file

@ -1,8 +1,5 @@
package info.nightscout.androidaps.plugins.pump.omnipod.driver.ui; package info.nightscout.androidaps.plugins.pump.omnipod.driver.ui;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject; import javax.inject.Inject;
import dagger.android.HasAndroidInjector; import dagger.android.HasAndroidInjector;
@ -10,13 +7,9 @@ import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair; import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
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.PodDeviceState; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState;
@ -41,8 +34,6 @@ public class OmnipodUITask {
private final HasAndroidInjector injector; private final HasAndroidInjector injector;
//private static final Logger LOG = LoggerFactory.getLogger(L.PUMP);
public OmnipodCommandType commandType; public OmnipodCommandType commandType;
public PumpEnactResult returnData; public PumpEnactResult returnData;
private String errorDescription; private String errorDescription;
@ -242,11 +233,6 @@ public class OmnipodUITask {
} }
private boolean isLogEnabled() {
return L.isEnabled(L.PUMP);
}
public PodResponseType getResponseType() { public PodResponseType getResponseType() {
return this.responseType; return this.responseType;
} }

View file

@ -10,27 +10,19 @@ import com.google.gson.Gson;
import javax.inject.Inject; import javax.inject.Inject;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkBLE; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkBLE;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkEncodingType; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkEncodingType;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkService; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkService;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUIPostprocessor;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState; import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin; import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager; import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodManager; import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodManager;
@ -48,12 +40,6 @@ public class RileyLinkOmnipodService extends RileyLinkService {
@Inject OmnipodPumpStatus omnipodPumpStatus; @Inject OmnipodPumpStatus omnipodPumpStatus;
@Inject OmnipodUtil omnipodUtil; @Inject OmnipodUtil omnipodUtil;
//@Inject MedtronicPumpPlugin medtronicPumpPlugin;
//@Inject MedtronicUtil medtronicUtil;
//@Inject MedtronicUIPostprocessor medtronicUIPostprocessor;
//@Inject MedtronicPumpStatus medtronicPumpStatus;
private static RileyLinkOmnipodService instance; private static RileyLinkOmnipodService instance;
private OmnipodCommunicationManager omnipodCommunicationManager; private OmnipodCommunicationManager omnipodCommunicationManager;
@ -99,7 +85,6 @@ public class RileyLinkOmnipodService extends RileyLinkService {
*/ */
public void initRileyLinkServiceData() { public void initRileyLinkServiceData() {
// TODO
rileyLinkServiceData.targetDevice = RileyLinkTargetDevice.Omnipod; rileyLinkServiceData.targetDevice = RileyLinkTargetDevice.Omnipod;
// get most recently used RileyLink address // get most recently used RileyLink address
@ -118,12 +103,13 @@ public class RileyLinkOmnipodService extends RileyLinkService {
private void initializeErosOmnipodManager() { private void initializeErosOmnipodManager() {
if (AapsOmnipodManager.getInstance() == null) { if (AapsOmnipodManager.getInstance() == null) {
PodSessionState podState = null; PodSessionState podState = null;
if (sp.contains(OmnipodConst.Prefs.PodState)) { if (sp.contains(OmnipodConst.Prefs.PodState) && omnipodUtil.getPodSessionState() == null) {
try { try {
Gson gson = OmnipodUtil.getGsonInstance(); Gson gson = omnipodUtil.getGsonInstance();
String storedPodState = sp.getString(OmnipodConst.Prefs.PodState, null); String storedPodState = sp.getString(OmnipodConst.Prefs.PodState, null);
aapsLogger.info(LTag.PUMPCOMM, "PodSessionState-SP: loaded from SharedPreferences: " + storedPodState); aapsLogger.info(LTag.PUMPCOMM, "PodSessionState-SP: loaded from SharedPreferences: " + storedPodState);
podState = gson.fromJson(storedPodState, PodSessionState.class); podState = gson.fromJson(storedPodState, PodSessionState.class);
podState.injectDaggerClass(injector);
omnipodUtil.setPodSessionState(podState); omnipodUtil.setPodSessionState(podState);
} catch (Exception ex) { } catch (Exception ex) {
aapsLogger.error(LTag.PUMPCOMM, "Could not deserialize Pod state", ex); aapsLogger.error(LTag.PUMPCOMM, "Could not deserialize Pod state", ex);
@ -134,7 +120,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
this.omnipodCommunicationManager = omnipodCommunicationService; this.omnipodCommunicationManager = omnipodCommunicationService;
this.aapsOmnipodManager = new AapsOmnipodManager(omnipodCommunicationService, podState, omnipodPumpStatus, this.aapsOmnipodManager = new AapsOmnipodManager(omnipodCommunicationService, podState, omnipodPumpStatus,
omnipodUtil, aapsLogger, rxBus, resourceHelper, injector, activePlugin); omnipodUtil, aapsLogger, rxBus, sp, resourceHelper, injector, activePlugin);
} else { } else {
aapsOmnipodManager = AapsOmnipodManager.getInstance(); aapsOmnipodManager = AapsOmnipodManager.getInstance();
} }
@ -148,16 +134,12 @@ public class RileyLinkOmnipodService extends RileyLinkService {
@Override @Override
public RileyLinkCommunicationManager getDeviceCommunicationManager() { public RileyLinkCommunicationManager getDeviceCommunicationManager() {
// if (omnipodCommunicationManager instanceof AapsOmnipodManager) { // Eros
// return ((AapsOmnipodManager) omnipodCommunicationManager).getCommunicationService();
// }
// // FIXME is this correct for Dash?
return omnipodCommunicationManager; return omnipodCommunicationManager;
} }
@Override @Override
public void setPumpDeviceState(PumpDeviceState pumpDeviceState) { public void setPumpDeviceState(PumpDeviceState pumpDeviceState) {
this.omnipodPumpStatus.setPumpDeviceState(pumpDeviceState);
} }
@ -194,23 +176,18 @@ public class RileyLinkOmnipodService extends RileyLinkService {
} }
public boolean verifyConfiguration() { public boolean verifyConfiguration() {
try { try {
//String regexSN = "[0-9]{6}";
String regexMac = "([\\da-fA-F]{1,2}(?:\\:|$)){6}";
omnipodPumpStatus.errorDescription = "-"; omnipodPumpStatus.errorDescription = "-";
String rileyLinkAddress = info.nightscout.androidaps.utils.SP.getString(RileyLinkConst.Prefs.RileyLinkAddress, null); String rileyLinkAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, null);
if (rileyLinkAddress == null) { if (rileyLinkAddress == null) {
aapsLogger.debug(LTag.PUMPCOMM, "RileyLink address invalid: null"); aapsLogger.debug(LTag.PUMPCOMM, "RileyLink address invalid: null");
omnipodPumpStatus.errorDescription = resourceHelper.gs(R.string.medtronic_error_rileylink_address_invalid); omnipodPumpStatus.errorDescription = resourceHelper.gs(R.string.medtronic_error_rileylink_address_invalid);
return false; return false;
} else { } else {
if (!rileyLinkAddress.matches(regexMac)) { if (!rileyLinkAddress.matches(omnipodPumpStatus.regexMac)) {
omnipodPumpStatus.errorDescription = resourceHelper.gs(R.string.medtronic_error_rileylink_address_invalid); omnipodPumpStatus.errorDescription = resourceHelper.gs(R.string.medtronic_error_rileylink_address_invalid);
aapsLogger.debug(LTag.PUMPCOMM, "RileyLink address invalid: {}", rileyLinkAddress); aapsLogger.debug(LTag.PUMPCOMM, "RileyLink address invalid: {}", rileyLinkAddress);
} else { } else {

View file

@ -1,26 +0,0 @@
package info.nightscout.androidaps.plugins.pump.omnipod.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitReceiver;
public class LogReceiver implements PodInitReceiver {
private static final Logger LOG = LoggerFactory.getLogger(LogReceiver.class);
@Override
public void returnInitTaskStatus(PodInitActionType podInitActionType, boolean isSuccess, String errorMessage) {
if (errorMessage != null) {
LOG.error(podInitActionType.name() + " - Success: " + isSuccess + ", Error Message: " + errorMessage);
} else {
if (isSuccess) {
LOG.info(podInitActionType.name() + " - Success: " + isSuccess);
} else {
LOG.error(podInitActionType.name() + " - NOT Succesful");
}
}
}
}

View file

@ -8,182 +8,108 @@ import com.google.gson.JsonDeserializer;
import com.google.gson.JsonPrimitive; import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializer; import com.google.gson.JsonSerializer;
import org.jetbrains.annotations.NotNull;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.DateTimeZone; import org.joda.time.DateTimeZone;
import org.joda.time.format.ISODateTimeFormat; import org.joda.time.format.ISODateTimeFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.ActivePluginProvider;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; 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.medtronic.driver.MedtronicPumpStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin;
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.OmnipodPodType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodPodType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodPumpPluginInterface;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodDriverState; import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodDriverState;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodDeviceStatusChange; import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodDeviceStatusChange;
import info.nightscout.androidaps.plugins.pump.omnipod.service.RileyLinkOmnipodService;
import info.nightscout.androidaps.plugins.pump.omnipod_dash.OmnipodDashPumpPlugin;
import info.nightscout.androidaps.utils.alertDialogs.OKDialog; import info.nightscout.androidaps.utils.alertDialogs.OKDialog;
/** /**
* Created by andy on 4/8/19. * Created by andy on 4/8/19.
*/ */
// FIXME
@Singleton @Singleton
public class OmnipodUtil { public class OmnipodUtil {
//@Inject RxBusWrapper rxBus;
private static final Logger LOG = LoggerFactory.getLogger(L.PUMPCOMM);
private static boolean lowLevelDebug = true;
private static RileyLinkOmnipodService omnipodService;
//private static OmnipodPumpStatus omnipodPumpStatus;
private static OmnipodCommandType currentCommand;
private static Gson gsonInstance = createGson();
//private static PodSessionState podSessionState;
//private static PodDeviceState podDeviceState;
//private static OmnipodPumpPluginInterface omnipodPumpPlugin;
private static OmnipodPodType omnipodPodType;
private static OmnipodDriverState driverState = OmnipodDriverState.NotInitalized;
//private static PumpType pumpType;
private final AAPSLogger aapsLogger; private final AAPSLogger aapsLogger;
private final RxBusWrapper rxBus; private final RxBusWrapper rxBus;
private final RileyLinkUtil rileyLinkUtil; private final RileyLinkUtil rileyLinkUtil;
private final OmnipodPumpStatus omnipodPumpStatus; private final OmnipodPumpStatus omnipodPumpStatus;
private final ActivePluginProvider activePlugins;
private boolean lowLevelDebug = true;
private OmnipodCommandType currentCommand;
private Gson gsonInstance = createGson();
//private static PodSessionState podSessionState;
//private static PodDeviceState podDeviceState;
private OmnipodPodType omnipodPodType;
private OmnipodDriverState driverState = OmnipodDriverState.NotInitalized;
@Inject @Inject
public OmnipodUtil( public OmnipodUtil(
AAPSLogger aapsLogger, AAPSLogger aapsLogger,
RxBusWrapper rxBus, RxBusWrapper rxBus,
RileyLinkUtil rileyLinkUtil, RileyLinkUtil rileyLinkUtil,
OmnipodPumpStatus omnipodPumpStatus OmnipodPumpStatus omnipodPumpStatus,
ActivePluginProvider activePlugins
) { ) {
this.aapsLogger = aapsLogger; this.aapsLogger = aapsLogger;
this.rxBus = rxBus; this.rxBus = rxBus;
this.rileyLinkUtil = rileyLinkUtil; this.rileyLinkUtil = rileyLinkUtil;
this.omnipodPumpStatus = omnipodPumpStatus; this.omnipodPumpStatus = omnipodPumpStatus;
} this.activePlugins = activePlugins;
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) { public boolean isLowLevelDebug() {
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; return lowLevelDebug;
} }
public static void setLowLevelDebug(boolean lowLevelDebug) { public void setLowLevelDebug(boolean lowLevelDebug) {
OmnipodUtil.lowLevelDebug = lowLevelDebug; this.lowLevelDebug = lowLevelDebug;
} }
// public static OmnipodCommunicationManagerInterface getOmnipodCommunicationManager() { public OmnipodCommandType getCurrentCommand() {
// return (OmnipodCommunicationManagerInterface) RileyLinkUtil.rileyLinkCommunicationManager; return currentCommand;
// }
// public static RileyLinkOmnipodService getOmnipodService() {
// return OmnipodUtil.omnipodService;
// }
public static void setOmnipodService(RileyLinkOmnipodService medtronicService) {
OmnipodUtil.omnipodService = medtronicService;
}
public static OmnipodCommandType getCurrentCommand() {
return OmnipodUtil.currentCommand;
} }
// FIXME
public void setCurrentCommand(OmnipodCommandType currentCommand) { public void setCurrentCommand(OmnipodCommandType currentCommand) {
OmnipodUtil.currentCommand = currentCommand; this.currentCommand = currentCommand;
if (currentCommand != null) if (currentCommand != null)
rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItem(currentCommand)); rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItem(currentCommand));
} }
public static boolean isSame(Double d1, Double d2) {
double diff = d1 - d2;
return (Math.abs(diff) <= 0.000001);
}
public static void displayNotConfiguredDialog(Context context) { public static void displayNotConfiguredDialog(Context context) {
OKDialog.showConfirmation(context, MainApp.gs(R.string.combo_warning), OKDialog.showConfirmation(context, MainApp.gs(R.string.combo_warning),
MainApp.gs(R.string.omnipod_error_operation_not_possible_no_configuration), (Runnable) null); MainApp.gs(R.string.omnipod_error_operation_not_possible_no_configuration), (Runnable) null);
} }
//
// public static OmnipodPumpStatus getPumpStatus() {
// return omnipodPumpStatus;
// }
public static OmnipodDriverState getDriverState() {
return OmnipodUtil.driverState; public OmnipodDriverState getDriverState() {
return driverState;
} }
public static void setDriverState(OmnipodDriverState state) {
if (OmnipodUtil.driverState == state) public void setDriverState(OmnipodDriverState state) {
if (driverState == state)
return; return;
OmnipodUtil.driverState = state; driverState = state;
omnipodPumpStatus.driverState = state;
// TODO maybe remove // TODO maybe remove
// if (OmnipodUtil.omnipodPumpStatus != null) { // if (OmnipodUtil.omnipodPumpStatus != null) {
@ -195,11 +121,8 @@ public class OmnipodUtil {
// } // }
} }
// public static void setPumpStatus(OmnipodPumpStatus omnipodPumpStatus) {
// OmnipodUtil.omnipodPumpStatus = omnipodPumpStatus;
// }
private static Gson createGson() { private Gson createGson() {
GsonBuilder gsonBuilder = new GsonBuilder() GsonBuilder gsonBuilder = new GsonBuilder()
.registerTypeAdapter(DateTime.class, (JsonSerializer<DateTime>) (dateTime, typeOfSrc, context) -> .registerTypeAdapter(DateTime.class, (JsonSerializer<DateTime>) (dateTime, typeOfSrc, context) ->
new JsonPrimitive(ISODateTimeFormat.dateTime().print(dateTime))) new JsonPrimitive(ISODateTimeFormat.dateTime().print(dateTime)))
@ -213,6 +136,7 @@ public class OmnipodUtil {
return gsonBuilder.create(); return gsonBuilder.create();
} }
public void setPodSessionState(PodSessionState podSessionState) { public void setPodSessionState(PodSessionState podSessionState) {
omnipodPumpStatus.podSessionState = podSessionState; omnipodPumpStatus.podSessionState = podSessionState;
rxBus.send(new EventOmnipodDeviceStatusChange(podSessionState)); rxBus.send(new EventOmnipodDeviceStatusChange(podSessionState));
@ -224,26 +148,16 @@ public class OmnipodUtil {
} }
// @NotNull public void setOmnipodPodType(OmnipodPodType omnipodPodType) {
// public static OmnipodPumpPluginInterface getPlugin() { this.omnipodPodType = omnipodPodType;
// return OmnipodUtil.omnipodPumpPlugin;
// }
// @NotNull
// public static void setPlugin(OmnipodPumpPluginInterface pumpPlugin) {
// OmnipodUtil.omnipodPumpPlugin = pumpPlugin;
// }
public static void setOmnipodPodType(OmnipodPodType omnipodPodType) {
OmnipodUtil.omnipodPodType = omnipodPodType;
} }
public static OmnipodPodType getOmnipodPodType() {
return omnipodPodType; public OmnipodPodType getOmnipodPodType() {
return this.omnipodPodType;
} }
public PodDeviceState getPodDeviceState() { public PodDeviceState getPodDeviceState() {
return omnipodPumpStatus.podDeviceState; return omnipodPumpStatus.podDeviceState;
} }
@ -253,29 +167,29 @@ public class OmnipodUtil {
return omnipodPumpStatus.podSessionState; return omnipodPumpStatus.podSessionState;
} }
// public static boolean isOmnipodEros() {
// return OmnipodPumpPlugin.getPlugin().isEnabled(PluginType.PUMP); public boolean isOmnipodEros() {
// } return this.activePlugins.getActivePump().model() == PumpType.Insulet_Omnipod;
// }
// public static boolean isOmnipodDash() {
// return OmnipodDashPumpPlugin.getPlugin().isEnabled(PluginType.PUMP);
// } public boolean isOmnipodDash() {
return this.activePlugins.getActivePump().model() == PumpType.Insulet_Omnipod_Dash;
}
public void setPumpType(PumpType pumpType_) { public void setPumpType(PumpType pumpType_) {
omnipodPumpStatus.pumpType = pumpType_; omnipodPumpStatus.pumpType = pumpType_;
} }
public PumpType getPumpType() { public PumpType getPumpType() {
return omnipodPumpStatus.pumpType; return omnipodPumpStatus.pumpType;
} }
public static Gson getGsonInstance() {
return gsonInstance; public Gson getGsonInstance() {
return this.gsonInstance;
} }
} }

View file

@ -27,12 +27,10 @@ import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodFragment; import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodFragment;
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin; import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUIComm;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodPumpPluginInterface; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodPumpPluginInterface;
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged; import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodRefreshButtonState; import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodRefreshButtonState;
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.util.OmnipodUtil;
import info.nightscout.androidaps.plugins.pump.omnipod_dash.comm.OmnipodDashCommunicationManager; import info.nightscout.androidaps.plugins.pump.omnipod_dash.comm.OmnipodDashCommunicationManager;
import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.TimeChangeType; import info.nightscout.androidaps.utils.TimeChangeType;
@ -44,8 +42,10 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
* *
* @author Andy Rozman (andy.rozman@gmail.com) * @author Andy Rozman (andy.rozman@gmail.com)
*/ */
// FIXME this is just placeholder for now, but this should use most of OmnipodPumpPlugin implementation
public class OmnipodDashPumpPlugin extends OmnipodPumpPlugin implements OmnipodPumpPluginInterface { public class OmnipodDashPumpPlugin extends OmnipodPumpPlugin implements OmnipodPumpPluginInterface {
// TODO Dagger
private static final Logger LOG = LoggerFactory.getLogger(L.PUMP); private static final Logger LOG = LoggerFactory.getLogger(L.PUMP);
protected static OmnipodDashPumpPlugin plugin = null; protected static OmnipodDashPumpPlugin plugin = null;

View file

@ -10,7 +10,6 @@ import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair; import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoRecentPulseLog; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoRecentPulseLog;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface;
@ -18,8 +17,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitReceiver; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitReceiver;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
import info.nightscout.androidaps.utils.SP;
/** /**
* Created by andy on 4.8.2019 * Created by andy on 4.8.2019
@ -27,6 +24,8 @@ import info.nightscout.androidaps.utils.SP;
// TODO refactor to use dagger, just commented out errors // TODO refactor to use dagger, just commented out errors
public class OmnipodDashCommunicationManager implements OmnipodCommunicationManagerInterface { public class OmnipodDashCommunicationManager implements OmnipodCommunicationManagerInterface {
// TODO Dagger
private static final Logger LOG = LoggerFactory.getLogger(L.PUMPCOMM); private static final Logger LOG = LoggerFactory.getLogger(L.PUMPCOMM);
private static OmnipodDashCommunicationManager omnipodCommunicationManager; private static OmnipodDashCommunicationManager omnipodCommunicationManager;

View file

@ -14,7 +14,10 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
public class OmnipodDashPumpStatus extends OmnipodPumpStatus { public class OmnipodDashPumpStatus extends OmnipodPumpStatus {
@Inject @Inject
public OmnipodDashPumpStatus(ResourceHelper resourceHelper, SP sp, RxBusWrapper rxBus, RileyLinkUtil rileyLinkUtil) { public OmnipodDashPumpStatus(ResourceHelper resourceHelper,
SP sp,
RxBusWrapper rxBus,
RileyLinkUtil rileyLinkUtil) {
super(resourceHelper, sp, rxBus, rileyLinkUtil); super(resourceHelper, sp, rxBus, rileyLinkUtil);
this.pumpType = PumpType.Insulet_Omnipod_Dash; this.pumpType = PumpType.Insulet_Omnipod_Dash;
} }