From e2e0de25bc919ad3d913853e25e8879e4919b1f7 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 27 Apr 2020 01:12:04 +0200 Subject: [PATCH] MDT refactor pass 4 --- .../androidaps/logging/AAPSLogger.kt | 1 + .../androidaps/logging/AAPSLoggerDebug.kt | 4 + .../logging/AAPSLoggerProduction.kt | 4 + .../androidaps/logging/AAPSLoggerTest.kt | 4 + .../pump/common/PumpPluginAbstract.java | 3 + .../RileyLinkCommunicationManager.java | 86 ++++++++----------- .../common/hw/rileylink/RileyLinkUtil.java | 11 --- .../rileylink/service/RileyLinkService.java | 3 +- .../tasks/InitializePumpManagerTask.java | 15 +++- .../pump/medtronic/MedtronicPumpPlugin.java | 14 +-- .../comm/MedtronicCommunicationManager.java | 9 +- .../medtronic/comm/ui/MedtronicUIComm.java | 14 ++- .../service/RileyLinkMedtronicService.java | 3 +- 13 files changed, 78 insertions(+), 93 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/logging/AAPSLogger.kt b/app/src/main/java/info/nightscout/androidaps/logging/AAPSLogger.kt index 8c24805261..fe47fea99d 100644 --- a/app/src/main/java/info/nightscout/androidaps/logging/AAPSLogger.kt +++ b/app/src/main/java/info/nightscout/androidaps/logging/AAPSLogger.kt @@ -11,6 +11,7 @@ interface AAPSLogger { fun debug(tag: LTag, message: String) fun debug(tag: LTag, format: String, vararg arguments: Any?) fun warn(tag: LTag, message: String) + fun warn(tag: LTag, format: String, vararg arguments: Any?) fun info(tag: LTag, message: String) fun info(tag: LTag, format: String, vararg arguments: Any?) fun error(tag: LTag, message: String) diff --git a/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerDebug.kt b/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerDebug.kt index b930eb4728..ba7f88712d 100644 --- a/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerDebug.kt +++ b/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerDebug.kt @@ -28,6 +28,10 @@ class AAPSLoggerDebug : AAPSLogger { Log.w(tag.tag, message) } + override fun warn(tag: LTag, format: String, vararg arguments: Any?) { + Log.w(tag.tag, String.format(format, arguments)) + } + override fun info(tag: LTag, message: String) { Log.i(tag.tag, message) } diff --git a/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerProduction.kt b/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerProduction.kt index 27b0946749..6b3c9832a6 100644 --- a/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerProduction.kt +++ b/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerProduction.kt @@ -35,6 +35,10 @@ class AAPSLoggerProduction : AAPSLogger { } } + override fun warn(tag: LTag, format: String, vararg arguments: Any?) { + LoggerFactory.getLogger(tag.tag).warn(stackLogMarker() + String.format(format, arguments)) + } + override fun info(tag: LTag, message: String) { if (L.isEnabled(tag.tag)) { LoggerFactory.getLogger(tag.tag).info(stackLogMarker() + message) diff --git a/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerTest.kt b/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerTest.kt index 0503db143f..5f6b798e36 100644 --- a/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerTest.kt +++ b/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerTest.kt @@ -26,6 +26,10 @@ class AAPSLoggerTest : AAPSLogger { println("WARN: " + tag.tag + " " + message) } + override fun warn(tag: LTag, format: String, vararg arguments: Any?) { + println("INFO: : " + tag.tag + " " + String.format(format, arguments)) + } + override fun info(tag: LTag, message: String) { println("INFO: " + tag.tag + " " + message) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java index 70edbcec19..8bf2f21455 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java @@ -37,6 +37,8 @@ import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewB import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus; 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.hw.rileylink.RileyLinkCommunicationManager; +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkService; import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData; import info.nightscout.androidaps.plugins.treatments.Treatment; import info.nightscout.androidaps.utils.DateUtil; @@ -111,6 +113,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI public abstract void initPumpStatusData(); public abstract void resetRileyLinkConfiguration(); public abstract void doTuneUpDevice(); + public abstract RileyLinkService getRileyLinkService(); @Override protected void onStart() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java index 35cfd48a5b..91e9be0e1a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkCommunicationManager.java @@ -1,13 +1,10 @@ package info.nightscout.androidaps.plugins.pump.common.hw.rileylink; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import javax.inject.Inject; import dagger.android.HasAndroidInjector; -import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; +import info.nightscout.androidaps.logging.AAPSLogger; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkCommunicationException; @@ -35,13 +32,15 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP; */ public abstract class RileyLinkCommunicationManager { - @Inject MedtronicPumpStatus medtronicPumpStatus; + @Inject protected AAPSLogger aapsLogger; @Inject protected SP sp; - private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM); + @Inject MedtronicPumpStatus medtronicPumpStatus; + @Inject RileyLinkUtil rileyLinkUtil; - private static final int SCAN_TIMEOUT = 1500; - private static final int ALLOWED_PUMP_UNREACHABLE = 10 * 60 * 1000; // 10 minutes + + private final int SCAN_TIMEOUT = 1500; + private final int ALLOWED_PUMP_UNREACHABLE = 10 * 60 * 1000; // 10 minutes protected final HasAndroidInjector injector; protected final RFSpy rfspy; @@ -61,8 +60,7 @@ public abstract class RileyLinkCommunicationManager { this.injector = injector; injector.androidInjector().inject(this); this.rfspy = rfspy; - this.rileyLinkServiceData = RileyLinkUtil.getInstance().getRileyLinkServiceData(); - RileyLinkUtil.getInstance().setRileyLinkCommunicationManager(this); + this.rileyLinkServiceData = rileyLinkUtil.getRileyLinkServiceData(); } @@ -87,8 +85,7 @@ public abstract class RileyLinkCommunicationManager { throws RileyLinkCommunicationException { if (showPumpMessages) { - if (isLogEnabled()) - LOG.info("Sent:" + ByteUtil.shortHexString(msg.getTxData())); + aapsLogger.info(LTag.PUMPBTCOMM, "Sent:" + ByteUtil.shortHexString(msg.getTxData())); } RFSpyResponse rfSpyResponse = rfspy.transmitThenReceive(new RadioPacket(msg.getTxData()), @@ -101,7 +98,7 @@ public abstract class RileyLinkCommunicationManager { // Mark this as the last time we heard from the pump. rememberLastGoodDeviceCommunicationTime(); } else { - LOG.warn("isDeviceReachable. Response is invalid ! [interrupted={}, timeout={}, unknownCommand={}, invalidParam={}]", rfSpyResponse.wasInterrupted(), + aapsLogger.warn(LTag.PUMPBTCOMM, "isDeviceReachable. Response is invalid ! [interrupted={}, timeout={}, unknownCommand={}, invalidParam={}]", rfSpyResponse.wasInterrupted(), rfSpyResponse.wasTimeout(), rfSpyResponse.isUnknownCommand(), rfSpyResponse.isInvalidParam()); if (rfSpyResponse.wasTimeout()) { @@ -111,7 +108,7 @@ public abstract class RileyLinkCommunicationManager { long diff = System.currentTimeMillis() - getPumpStatus().lastConnection; if (diff > ALLOWED_PUMP_UNREACHABLE) { - LOG.warn("We reached max time that Pump can be unreachable. Starting Tuning."); + aapsLogger.warn(LTag.PUMPBTCOMM, "We reached max time that Pump can be unreachable. Starting Tuning."); ServiceTaskExecutor.startTask(new WakeAndTuneTask(injector)); timeoutCount = 0; } @@ -124,8 +121,7 @@ public abstract class RileyLinkCommunicationManager { } if (showPumpMessages) { - if (isLogEnabled()) - LOG.info("Received:" + ByteUtil.shortHexString(rfSpyResponse.getRadioResponse().getPayload())); + aapsLogger.info(LTag.PUMPBTCOMM, "Received:" + ByteUtil.shortHexString(rfSpyResponse.getRadioResponse().getPayload())); } return response; @@ -162,21 +158,18 @@ public abstract class RileyLinkCommunicationManager { nextWakeUpRequired = 0L; if (System.currentTimeMillis() > nextWakeUpRequired) { - if (isLogEnabled()) - LOG.info("Waking pump..."); + aapsLogger.info(LTag.PUMPBTCOMM, "Waking pump..."); byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.ReadSimpleData); // simple RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte) 0, (byte) 200, (byte) 0, (byte) 0, 25000, (byte) 0); - if (isLogEnabled()) - LOG.info("wakeup: raw response is " + ByteUtil.shortHexString(resp.getRaw())); + aapsLogger.info(LTag.PUMPBTCOMM, "wakeup: raw response is " + ByteUtil.shortHexString(resp.getRaw())); // FIXME wakeUp successful !!!!!!!!!!!!!!!!!! nextWakeUpRequired = System.currentTimeMillis() + (receiverDeviceAwakeForMinutes * 60 * 1000); } else { - if (isLogEnabled()) - LOG.trace("Last pump communication was recent, not waking pump."); + aapsLogger.debug(LTag.PUMPBTCOMM, "Last pump communication was recent, not waking pump."); } // long lastGoodPlus = getLastGoodReceiverCommunicationTime() + (receiverDeviceAwakeForMinutes * 60 * 1000); @@ -233,8 +226,7 @@ public abstract class RileyLinkCommunicationManager { public double scanForDevice(double[] frequencies) { - if (isLogEnabled()) - LOG.info("Scanning for receiver ({})", receiverDeviceID); + aapsLogger.info(LTag.PUMPBTCOMM, "Scanning for receiver ({})", receiverDeviceID); wakeUp(receiverDeviceAwakeForMinutes, false); FrequencyScanResults results = new FrequencyScanResults(); @@ -251,7 +243,7 @@ public abstract class RileyLinkCommunicationManager { RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte) 0, (byte) 0, (byte) 0, (byte) 0, 1250, (byte) 0); if (resp.wasTimeout()) { - LOG.error("scanForPump: Failed to find pump at frequency {}", frequencies[i]); + aapsLogger.error(LTag.PUMPBTCOMM, "scanForPump: Failed to find pump at frequency {}", frequencies[i]); } else if (resp.looksLikeRadioPacket()) { RadioResponse radioResponse = new RadioResponse(); @@ -265,17 +257,17 @@ public abstract class RileyLinkCommunicationManager { trial.rssiList.add(rssi); trial.successes++; } else { - LOG.warn("Failed to parse radio response: " + ByteUtil.shortHexString(resp.getRaw())); + aapsLogger.warn(LTag.PUMPBTCOMM, "Failed to parse radio response: " + ByteUtil.shortHexString(resp.getRaw())); trial.rssiList.add(-99); } } catch (RileyLinkCommunicationException rle) { - LOG.warn("Failed to decode radio response: " + ByteUtil.shortHexString(resp.getRaw())); + aapsLogger.warn(LTag.PUMPBTCOMM, "Failed to decode radio response: " + ByteUtil.shortHexString(resp.getRaw())); trial.rssiList.add(-99); } } else { - LOG.error("scanForPump: raw response is " + ByteUtil.shortHexString(resp.getRaw())); + aapsLogger.error(LTag.PUMPBTCOMM, "scanForPump: raw response is " + ByteUtil.shortHexString(resp.getRaw())); trial.rssiList.add(-99); } trial.tries++; @@ -299,7 +291,7 @@ public abstract class RileyLinkCommunicationManager { + one.frequencyMHz, "" + one.averageRSSI + ", RSSIs =" + one.rssiList)); } - LOG.info(stringBuilder.toString()); + aapsLogger.info(LTag.PUMPCOMM, stringBuilder.toString()); results.sort(); // sorts in ascending order @@ -307,11 +299,10 @@ public abstract class RileyLinkCommunicationManager { results.bestFrequencyMHz = bestTrial.frequencyMHz; if (bestTrial.successes > 0) { rfspy.setBaseFrequency(results.bestFrequencyMHz); - if (isLogEnabled()) - LOG.debug("Best frequency found: " + results.bestFrequencyMHz); + aapsLogger.debug(LTag.PUMPBTCOMM, "Best frequency found: " + results.bestFrequencyMHz); return results.bestFrequencyMHz; } else { - LOG.error("No pump response during scan."); + aapsLogger.error(LTag.PUMPBTCOMM, "No pump response during scan."); return 0.0; } } @@ -340,22 +331,22 @@ public abstract class RileyLinkCommunicationManager { RadioPacket pkt = new RadioPacket(pumpMsgContent); RFSpyResponse resp = rfspy.transmitThenReceive(pkt, (byte) 0, (byte) 0, (byte) 0, (byte) 0, SCAN_TIMEOUT, (byte) 0); if (resp.wasTimeout()) { - LOG.warn("tune_tryFrequency: no pump response at frequency {}", freqMHz); + aapsLogger.warn(LTag.PUMPBTCOMM, "tune_tryFrequency: no pump response at frequency {}", freqMHz); } else if (resp.looksLikeRadioPacket()) { RadioResponse radioResponse = new RadioResponse(); try { radioResponse.init(resp.getRaw()); if (radioResponse.isValid()) { - LOG.warn("tune_tryFrequency: saw response level {} at frequency {}", radioResponse.rssi, freqMHz); + aapsLogger.warn(LTag.PUMPBTCOMM, "tune_tryFrequency: saw response level {} at frequency {}", radioResponse.rssi, freqMHz); return calculateRssi(radioResponse.rssi); } else { - LOG.warn("tune_tryFrequency: invalid radio response:" + aapsLogger.warn(LTag.PUMPBTCOMM, "tune_tryFrequency: invalid radio response:" + ByteUtil.shortHexString(radioResponse.getPayload())); } } catch (RileyLinkCommunicationException e) { - LOG.warn("Failed to decode radio response: " + ByteUtil.shortHexString(resp.getRaw())); + aapsLogger.warn(LTag.PUMPBTCOMM, "Failed to decode radio response: " + ByteUtil.shortHexString(resp.getRaw())); } } @@ -382,16 +373,13 @@ public abstract class RileyLinkCommunicationManager { } if (betterFrequency == 0.0) { // we've failed... caller should try a full scan for pump - if (isLogEnabled()) - LOG.error("quickTuneForPump: failed to find pump"); + aapsLogger.error(LTag.PUMPBTCOMM, "quickTuneForPump: failed to find pump"); } else { rfspy.setBaseFrequency(betterFrequency); if (betterFrequency != startFrequencyMHz) { - if (isLogEnabled()) - LOG.info("quickTuneForPump: new frequency is {}MHz", betterFrequency); + aapsLogger.info(LTag.PUMPBTCOMM, "quickTuneForPump: new frequency is {}MHz", betterFrequency); } else { - if (isLogEnabled()) - LOG.info("quickTuneForPump: pump frequency is the same: {}MHz", startFrequencyMHz); + aapsLogger.info(LTag.PUMPBTCOMM, "quickTuneForPump: pump frequency is the same: {}MHz", startFrequencyMHz); } } return betterFrequency; @@ -399,8 +387,7 @@ public abstract class RileyLinkCommunicationManager { private double quickTunePumpStep(double startFrequencyMHz, double stepSizeMHz) { - if (isLogEnabled()) - LOG.info("Doing quick radio tune for receiver ({})", receiverDeviceID); + aapsLogger.info(LTag.PUMPBTCOMM, "Doing quick radio tune for receiver ({})", receiverDeviceID); wakeUp(false); int startRssi = tune_tryFrequency(startFrequencyMHz); double lowerFrequency = startFrequencyMHz - stepSizeMHz; @@ -438,8 +425,7 @@ public abstract class RileyLinkCommunicationManager { // Might still be zero, but that's fine. } double minutesAgo = (System.currentTimeMillis() - lastGoodReceiverCommunicationTime) / (1000.0 * 60.0); - if (isLogEnabled()) - LOG.trace("Last good pump communication was " + minutesAgo + " minutes ago."); + aapsLogger.debug(LTag.PUMPBTCOMM, "Last good pump communication was " + minutesAgo + " minutes ago."); return lastGoodReceiverCommunicationTime; } @@ -449,9 +435,7 @@ public abstract class RileyLinkCommunicationManager { } } - private boolean isLogEnabled() { - return L.isEnabled(L.PUMPCOMM); - } - public abstract PumpStatus getPumpStatus(); + + public abstract boolean isDeviceReachable(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkUtil.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkUtil.java index 22edb8ce1a..c47720e383 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkUtil.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkUtil.java @@ -190,17 +190,6 @@ public class RileyLinkUtil { this.rileyLinkService = rileyLinkService; } - - public RileyLinkCommunicationManager getRileyLinkCommunicationManager() { - return rileyLinkCommunicationManager; - } - - - void setRileyLinkCommunicationManager(RileyLinkCommunicationManager rileyLinkCommunicationManager) { - this.rileyLinkCommunicationManager = rileyLinkCommunicationManager; - } - - public static boolean sendNotification(ServiceNotification notification, Integer clientHashcode) { return false; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java index 5779dd63f1..e31eb51412 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java @@ -125,7 +125,6 @@ public abstract class RileyLinkService extends DaggerService { public abstract RileyLinkCommunicationManager getDeviceCommunicationManager(); - // Here is where the wake-lock begins: // We've received a service startCommand, we grab the lock. @Override @@ -236,7 +235,7 @@ public abstract class RileyLinkService extends DaggerService { // error tuning pump, pump not present ?? rileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorError, RileyLinkError.TuneUpOfDeviceFailed); } else { - rileyLinkUtil.getRileyLinkCommunicationManager().clearNotConnectedCount(); + getDeviceCommunicationManager().clearNotConnectedCount(); rileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorReady); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/InitializePumpManagerTask.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/InitializePumpManagerTask.java index 0bf78f08c1..64f7c8343b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/InitializePumpManagerTask.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/InitializePumpManagerTask.java @@ -2,9 +2,14 @@ package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.task import org.slf4j.Logger; +import javax.inject.Inject; + import dagger.android.HasAndroidInjector; +import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; +import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract; +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.RileyLinkUtil; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError; @@ -20,6 +25,8 @@ import info.nightscout.androidaps.utils.SP; */ public class InitializePumpManagerTask extends ServiceTask { + @Inject ActivePluginProvider activePlugin; + private static final String TAG = "InitPumpManagerTask"; private RileyLinkTargetDevice targetDevice; private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM); @@ -54,17 +61,19 @@ public class InitializePumpManagerTask extends ServiceTask { lastGoodFrequency = RileyLinkUtil.getInstance().getRileyLinkServiceData().lastGoodFrequency; } + RileyLinkCommunicationManager rileyLinkCommunicationManager = ((PumpPluginAbstract)activePlugin.getActivePump()).getRileyLinkService().getDeviceCommunicationManager(); + if ((lastGoodFrequency > 0.0d) - && RileyLinkUtil.getInstance().getRileyLinkCommunicationManager().isValidFrequency(lastGoodFrequency)) { + && rileyLinkCommunicationManager.isValidFrequency(lastGoodFrequency)) { RileyLinkUtil.getInstance().setServiceState(RileyLinkServiceState.RileyLinkReady); if (L.isEnabled(L.PUMPCOMM)) LOG.info("Setting radio frequency to {} MHz", lastGoodFrequency); - RileyLinkUtil.getInstance().getRileyLinkCommunicationManager().setRadioFrequencyForPump(lastGoodFrequency); + rileyLinkCommunicationManager.setRadioFrequencyForPump(lastGoodFrequency); - boolean foundThePump = RileyLinkUtil.getInstance().getRileyLinkCommunicationManager().tryToConnectToDevice(); + boolean foundThePump = rileyLinkCommunicationManager.tryToConnectToDevice(); if (foundThePump) { RileyLinkUtil.getInstance().setServiceState(RileyLinkServiceState.PumpConnectorReady); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java index fe50f06a04..47962883fe 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java @@ -110,7 +110,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter private Map statusRefreshMap = new HashMap<>(); private boolean isInitialized = false; private MedtronicHistoryData medtronicHistoryData; - private MedtronicCommunicationManager medtronicCommunicationManager; private PumpHistoryEntry lastPumpHistoryEntry; public static boolean isBusy = false; @@ -316,9 +315,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter return rileyLinkMedtronicService != null; } - @Deprecated @Nullable - public RileyLinkMedtronicService getRileyLinkMedtronicService() { + public RileyLinkMedtronicService getRileyLinkService() { return rileyLinkMedtronicService; } @@ -432,7 +430,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter return false; } - return (!medtronicCommunicationManager.isDeviceReachable()); + return (!rileyLinkMedtronicService.getDeviceCommunicationManager().isDeviceReachable()); } @@ -537,10 +535,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter aapsLogger.info(LTag.PUMP, getLogPrefix() + "initializePump - start"); - if (medtronicCommunicationManager == null) { - medtronicCommunicationManager = MedtronicCommunicationManager.getInstance(); - medtronicCommunicationManager.setDoWakeUpBeforeCommand(false); - } + rileyLinkMedtronicService.getDeviceCommunicationManager().setDoWakeUpBeforeCommand(false); setRefreshButtonEnabled(false); @@ -633,11 +628,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter return isProfileSame(profile); } else if (medtronicPumpStatus.basalProfileStatus == BasalProfileStatus.ProfileChanged) { return false; - } else { - } - return (medtronicPumpStatus.basalProfileStatus != BasalProfileStatus.ProfileOK) || isProfileSame(profile); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.java index d0ac644376..7c3dff66fb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.java @@ -62,10 +62,10 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager @Inject MedtronicPumpStatus medtronicPumpStatus; - private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM); - private static final int MAX_COMMAND_TRIES = 3; - private static final int DEFAULT_TIMEOUT = 2000; - private static final long RILEYLINK_TIMEOUT = 15 * 60 * 1000; // 15 min + private final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM); + private final int MAX_COMMAND_TRIES = 3; + private final int DEFAULT_TIMEOUT = 2000; + private final long RILEYLINK_TIMEOUT = 15 * 60 * 1000; // 15 min static MedtronicCommunicationManager medtronicCommunicationManager; String errorMessage; @@ -102,6 +102,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager } + @Override public boolean isDeviceReachable() { return isDeviceReachable(false); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUIComm.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUIComm.java index 8405e11e82..f3d6aa7d9a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUIComm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUIComm.java @@ -8,13 +8,11 @@ import javax.inject.Singleton; import dagger.android.HasAndroidInjector; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; -import info.nightscout.androidaps.plugins.bus.RxBusWrapper; 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.medtronic.comm.MedtronicCommunicationManager; import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType; import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil; -import info.nightscout.androidaps.utils.resources.ResourceHelper; /** * Created by andy on 6/14/18. @@ -32,13 +30,11 @@ public class MedtronicUIComm { @Inject public MedtronicUIComm( - HasAndroidInjector injector, - AAPSLogger aapsLogger, - RxBusWrapper rxBus, - ResourceHelper resourceHelper, - RileyLinkUtil rileyLinkUtil, - MedtronicUtil medtronicUtil, - MedtronicUIPostprocessor medtronicUIPostprocessor + @NotNull HasAndroidInjector injector, + @NotNull AAPSLogger aapsLogger, + @NotNull RileyLinkUtil rileyLinkUtil, + @NotNull MedtronicUtil medtronicUtil, + @NotNull MedtronicUIPostprocessor medtronicUIPostprocessor ) { this.injector = injector; this.aapsLogger = aapsLogger; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java index 160cbd9f25..b349f9c341 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java @@ -98,8 +98,7 @@ public class RileyLinkMedtronicService extends RileyLinkService { } - @Override - public RileyLinkCommunicationManager getDeviceCommunicationManager() { + public MedtronicCommunicationManager getDeviceCommunicationManager() { return this.medtronicCommunicationManager; }