MDT refactor pass 3
This commit is contained in:
parent
0d063ca73f
commit
331c1c3ab5
15 changed files with 173 additions and 165 deletions
|
@ -29,7 +29,10 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobOref1Thread
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobOref1Thread
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobThread
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobThread
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.*
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.*
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUITask
|
||||||
import info.nightscout.androidaps.plugins.treatments.Treatment
|
import info.nightscout.androidaps.plugins.treatments.Treatment
|
||||||
import info.nightscout.androidaps.queue.CommandQueue
|
import info.nightscout.androidaps.queue.CommandQueue
|
||||||
import info.nightscout.androidaps.queue.commands.*
|
import info.nightscout.androidaps.queue.commands.*
|
||||||
|
@ -187,6 +190,9 @@ interface AppComponent : AndroidInjector<MainApp> {
|
||||||
fun injectGraphData(graphData: GraphData)
|
fun injectGraphData(graphData: GraphData)
|
||||||
|
|
||||||
//Medtronic
|
//Medtronic
|
||||||
|
fun injectRileyLinkCommunicationManager(rileyLinkCommunicationManager: RileyLinkCommunicationManager)
|
||||||
|
fun injectMedtronicCommunicationManager(medtronicCommunicationManager: MedtronicCommunicationManager)
|
||||||
|
fun injectMedtronicUITask(medtronicUITask: MedtronicUITask)
|
||||||
fun injectServiceTask(serviceTask: ServiceTask)
|
fun injectServiceTask(serviceTask: ServiceTask)
|
||||||
fun injectPumpTask(pumpTask: PumpTask)
|
fun injectPumpTask(pumpTask: PumpTask)
|
||||||
fun injectDiscoverGattServicesTask(discoverGattServicesTask: DiscoverGattServicesTask)
|
fun injectDiscoverGattServicesTask(discoverGattServicesTask: DiscoverGattServicesTask)
|
||||||
|
|
|
@ -46,7 +46,10 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobOref1Thread
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobOref1Thread
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobThread
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobThread
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.*
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.*
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUITask
|
||||||
import info.nightscout.androidaps.plugins.treatments.Treatment
|
import info.nightscout.androidaps.plugins.treatments.Treatment
|
||||||
import info.nightscout.androidaps.queue.CommandQueue
|
import info.nightscout.androidaps.queue.CommandQueue
|
||||||
import info.nightscout.androidaps.queue.commands.*
|
import info.nightscout.androidaps.queue.commands.*
|
||||||
|
@ -280,6 +283,9 @@ open class AppModule {
|
||||||
@Binds fun bindInjector(mainApp: MainApp): HasAndroidInjector
|
@Binds fun bindInjector(mainApp: MainApp): HasAndroidInjector
|
||||||
|
|
||||||
// Medtronic
|
// Medtronic
|
||||||
|
@ContributesAndroidInjector fun rileyLinkCommunicationManagerProvider(): RileyLinkCommunicationManager
|
||||||
|
@ContributesAndroidInjector fun medtronicCommunicationManagerProvider(): MedtronicCommunicationManager
|
||||||
|
@ContributesAndroidInjector fun medtronicUITaskProvider(): MedtronicUITask
|
||||||
@ContributesAndroidInjector fun serviceTaskProvider(): ServiceTask
|
@ContributesAndroidInjector fun serviceTaskProvider(): ServiceTask
|
||||||
@ContributesAndroidInjector fun pumpTaskProvider(): PumpTask
|
@ContributesAndroidInjector fun pumpTaskProvider(): PumpTask
|
||||||
@ContributesAndroidInjector fun discoverGattServicesTaskProvider(): DiscoverGattServicesTask
|
@ContributesAndroidInjector fun discoverGattServicesTaskProvider(): DiscoverGattServicesTask
|
||||||
|
|
|
@ -62,6 +62,7 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
|
||||||
@Inject ResourceHelper resourceHelper;
|
@Inject ResourceHelper resourceHelper;
|
||||||
@Inject RileyLinkUtil rileyLinkUtil;
|
@Inject RileyLinkUtil rileyLinkUtil;
|
||||||
@Inject MedtronicUtil medtronicUtil;
|
@Inject MedtronicUtil medtronicUtil;
|
||||||
|
@Inject MedtronicPumpStatus medtronicPumpStatus;
|
||||||
|
|
||||||
private static final int PERMISSION_REQUEST_COARSE_LOCATION = 30241; // arbitrary.
|
private static final int PERMISSION_REQUEST_COARSE_LOCATION = 30241; // arbitrary.
|
||||||
private static final int REQUEST_ENABLE_BT = 30242; // arbitrary
|
private static final int REQUEST_ENABLE_BT = 30242; // arbitrary
|
||||||
|
@ -112,8 +113,7 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
|
||||||
|
|
||||||
rileyLinkUtil.getRileyLinkSelectPreference().setSummary(bleAddress);
|
rileyLinkUtil.getRileyLinkSelectPreference().setSummary(bleAddress);
|
||||||
|
|
||||||
MedtronicPumpStatus pumpStatus = medtronicUtil.getPumpStatus();
|
medtronicPumpStatus.verifyConfiguration(); // force reloading of address
|
||||||
pumpStatus.verifyConfiguration(); // force reloading of address
|
|
||||||
|
|
||||||
rxBus.send(new EventMedtronicPumpConfigurationChanged());
|
rxBus.send(new EventMedtronicPumpConfigurationChanged());
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,9 @@ 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.plugins.pump.medtronic.util.MedtronicUtil;
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is abstract class for RileyLink Communication, this one needs to be extended by specific "Pump" class.
|
* This is abstract class for RileyLink Communication, this one needs to be extended by specific "Pump" class.
|
||||||
|
@ -34,6 +35,9 @@ import info.nightscout.androidaps.utils.SP;
|
||||||
*/
|
*/
|
||||||
public abstract class RileyLinkCommunicationManager {
|
public abstract class RileyLinkCommunicationManager {
|
||||||
|
|
||||||
|
@Inject MedtronicPumpStatus medtronicPumpStatus;
|
||||||
|
@Inject protected SP sp;
|
||||||
|
|
||||||
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
|
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
|
||||||
|
|
||||||
private static final int SCAN_TIMEOUT = 1500;
|
private static final int SCAN_TIMEOUT = 1500;
|
||||||
|
@ -44,7 +48,7 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
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))
|
||||||
protected long lastGoodReceiverCommunicationTime = 0;
|
protected long lastGoodReceiverCommunicationTime = 0;
|
||||||
protected PumpStatus pumpStatus;
|
// protected PumpStatus pumpStatus;
|
||||||
protected RileyLinkServiceData rileyLinkServiceData;
|
protected RileyLinkServiceData rileyLinkServiceData;
|
||||||
private long nextWakeUpRequired = 0L;
|
private long nextWakeUpRequired = 0L;
|
||||||
|
|
||||||
|
@ -55,17 +59,13 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
|
|
||||||
public RileyLinkCommunicationManager(HasAndroidInjector injector, RFSpy rfspy) {
|
public RileyLinkCommunicationManager(HasAndroidInjector injector, RFSpy rfspy) {
|
||||||
this.injector = injector;
|
this.injector = injector;
|
||||||
|
injector.androidInjector().inject(this);
|
||||||
this.rfspy = rfspy;
|
this.rfspy = rfspy;
|
||||||
this.rileyLinkServiceData = RileyLinkUtil.getInstance().getRileyLinkServiceData();
|
this.rileyLinkServiceData = RileyLinkUtil.getInstance().getRileyLinkServiceData();
|
||||||
RileyLinkUtil.getInstance().setRileyLinkCommunicationManager(this);
|
RileyLinkUtil.getInstance().setRileyLinkCommunicationManager(this);
|
||||||
|
|
||||||
configurePumpSpecificSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected abstract void configurePumpSpecificSettings();
|
|
||||||
|
|
||||||
|
|
||||||
// All pump communications go through this function.
|
// All pump communications go through this function.
|
||||||
public <E extends RLMessage> E sendAndListen(RLMessage msg, int timeout_ms, Class<E> clazz)
|
public <E extends RLMessage> E sendAndListen(RLMessage msg, int timeout_ms, Class<E> clazz)
|
||||||
throws RileyLinkCommunicationException {
|
throws RileyLinkCommunicationException {
|
||||||
|
@ -92,7 +92,7 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
RFSpyResponse rfSpyResponse = rfspy.transmitThenReceive(new RadioPacket(msg.getTxData()),
|
RFSpyResponse rfSpyResponse = rfspy.transmitThenReceive(new RadioPacket(msg.getTxData()),
|
||||||
(byte)0, (byte)repeatCount, (byte)0, (byte)0, timeout_ms, (byte)retryCount, extendPreamble_ms);
|
(byte) 0, (byte) repeatCount, (byte) 0, (byte) 0, timeout_ms, (byte) retryCount, extendPreamble_ms);
|
||||||
|
|
||||||
RadioResponse radioResponse = rfSpyResponse.getRadioResponse();
|
RadioResponse radioResponse = rfSpyResponse.getRadioResponse();
|
||||||
E response = createResponseMessage(radioResponse.getPayload(), clazz);
|
E response = createResponseMessage(radioResponse.getPayload(), clazz);
|
||||||
|
@ -108,7 +108,7 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
if (hasTunning()) {
|
if (hasTunning()) {
|
||||||
timeoutCount++;
|
timeoutCount++;
|
||||||
|
|
||||||
long diff = System.currentTimeMillis() - pumpStatus.lastConnection;
|
long diff = System.currentTimeMillis() - getPumpStatus().lastConnection;
|
||||||
|
|
||||||
if (diff > ALLOWED_PUMP_UNREACHABLE) {
|
if (diff > ALLOWED_PUMP_UNREACHABLE) {
|
||||||
LOG.warn("We reached max time that Pump can be unreachable. Starting Tuning.");
|
LOG.warn("We reached max time that Pump can be unreachable. Starting Tuning.");
|
||||||
|
@ -166,8 +166,8 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
LOG.info("Waking pump...");
|
LOG.info("Waking pump...");
|
||||||
|
|
||||||
byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.ReadSimpleData); // simple
|
byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.ReadSimpleData); // simple
|
||||||
RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte)0, (byte)200,
|
RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte) 0, (byte) 200,
|
||||||
(byte)0, (byte)0, 25000, (byte)0);
|
(byte) 0, (byte) 0, 25000, (byte) 0);
|
||||||
if (isLogEnabled())
|
if (isLogEnabled())
|
||||||
LOG.info("wakeup: raw response is " + ByteUtil.shortHexString(resp.getRaw()));
|
LOG.info("wakeup: raw response is " + ByteUtil.shortHexString(resp.getRaw()));
|
||||||
|
|
||||||
|
@ -248,8 +248,8 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
for (int j = 0; j < tries; j++) {
|
for (int j = 0; j < tries; j++) {
|
||||||
|
|
||||||
byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.ReadSimpleData);
|
byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.ReadSimpleData);
|
||||||
RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte)0, (byte)0,
|
RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte) 0, (byte) 0,
|
||||||
(byte)0, (byte)0, 1250, (byte)0);
|
(byte) 0, (byte) 0, 1250, (byte) 0);
|
||||||
if (resp.wasTimeout()) {
|
if (resp.wasTimeout()) {
|
||||||
LOG.error("scanForPump: Failed to find pump at frequency {}", frequencies[i]);
|
LOG.error("scanForPump: Failed to find pump at frequency {}", frequencies[i]);
|
||||||
} else if (resp.looksLikeRadioPacket()) {
|
} else if (resp.looksLikeRadioPacket()) {
|
||||||
|
@ -281,7 +281,7 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
trial.tries++;
|
trial.tries++;
|
||||||
}
|
}
|
||||||
sumRSSI += -99.0 * (trial.tries - trial.successes);
|
sumRSSI += -99.0 * (trial.tries - trial.successes);
|
||||||
trial.averageRSSI2 = (double)(sumRSSI) / (double)(trial.tries);
|
trial.averageRSSI2 = (double) (sumRSSI) / (double) (trial.tries);
|
||||||
|
|
||||||
trial.calculateAverage();
|
trial.calculateAverage();
|
||||||
|
|
||||||
|
@ -296,7 +296,7 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
FrequencyTrial one = results.trials.get(k);
|
FrequencyTrial one = results.trials.get(k);
|
||||||
|
|
||||||
stringBuilder.append(String.format("Scan Result[%s]: Freq=%s, avg RSSI = %s\n", "" + k, ""
|
stringBuilder.append(String.format("Scan Result[%s]: Freq=%s, avg RSSI = %s\n", "" + k, ""
|
||||||
+ one.frequencyMHz, "" + one.averageRSSI + ", RSSIs =" + one.rssiList));
|
+ one.frequencyMHz, "" + one.averageRSSI + ", RSSIs =" + one.rssiList));
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.info(stringBuilder.toString());
|
LOG.info(stringBuilder.toString());
|
||||||
|
@ -338,7 +338,7 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
// RLMessage msg = makeRLMessage(RLMessageType.ReadSimpleData);
|
// RLMessage msg = makeRLMessage(RLMessageType.ReadSimpleData);
|
||||||
byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.ReadSimpleData);
|
byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.ReadSimpleData);
|
||||||
RadioPacket pkt = new RadioPacket(pumpMsgContent);
|
RadioPacket pkt = new RadioPacket(pumpMsgContent);
|
||||||
RFSpyResponse resp = rfspy.transmitThenReceive(pkt, (byte)0, (byte)0, (byte)0, (byte)0, SCAN_TIMEOUT, (byte)0);
|
RFSpyResponse resp = rfspy.transmitThenReceive(pkt, (byte) 0, (byte) 0, (byte) 0, (byte) 0, SCAN_TIMEOUT, (byte) 0);
|
||||||
if (resp.wasTimeout()) {
|
if (resp.wasTimeout()) {
|
||||||
LOG.warn("tune_tryFrequency: no pump response at frequency {}", freqMHz);
|
LOG.warn("tune_tryFrequency: no pump response at frequency {}", freqMHz);
|
||||||
} else if (resp.looksLikeRadioPacket()) {
|
} else if (resp.looksLikeRadioPacket()) {
|
||||||
|
@ -350,8 +350,8 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
LOG.warn("tune_tryFrequency: saw response level {} at frequency {}", radioResponse.rssi, freqMHz);
|
LOG.warn("tune_tryFrequency: saw response level {} at frequency {}", radioResponse.rssi, freqMHz);
|
||||||
return calculateRssi(radioResponse.rssi);
|
return calculateRssi(radioResponse.rssi);
|
||||||
} else {
|
} else {
|
||||||
LOG.warn("tune_tryFrequency: invalid radio response:"
|
LOG.warn("tune_tryFrequency: invalid radio response:"
|
||||||
+ ByteUtil.shortHexString(radioResponse.getPayload()));
|
+ ByteUtil.shortHexString(radioResponse.getPayload()));
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (RileyLinkCommunicationException e) {
|
} catch (RileyLinkCommunicationException e) {
|
||||||
|
@ -373,7 +373,7 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
// Try again at larger step size
|
// Try again at larger step size
|
||||||
stepsize += 0.05;
|
stepsize += 0.05;
|
||||||
} else {
|
} else {
|
||||||
if ((int)(evenBetterFrequency * 100) == (int)(betterFrequency * 100)) {
|
if ((int) (evenBetterFrequency * 100) == (int) (betterFrequency * 100)) {
|
||||||
// value did not change, so we're done.
|
// value did not change, so we're done.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -426,17 +426,15 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
protected void rememberLastGoodDeviceCommunicationTime() {
|
protected void rememberLastGoodDeviceCommunicationTime() {
|
||||||
lastGoodReceiverCommunicationTime = System.currentTimeMillis();
|
lastGoodReceiverCommunicationTime = System.currentTimeMillis();
|
||||||
|
|
||||||
SP.putLong(RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, lastGoodReceiverCommunicationTime);
|
sp.putLong(RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, lastGoodReceiverCommunicationTime);
|
||||||
if(pumpStatus != null) {
|
getPumpStatus().setLastCommunicationToNow();
|
||||||
pumpStatus.setLastCommunicationToNow();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private long getLastGoodReceiverCommunicationTime() {
|
private long getLastGoodReceiverCommunicationTime() {
|
||||||
// If we have a value of zero, we need to load from prefs.
|
// If we have a value of zero, we need to load from prefs.
|
||||||
if (lastGoodReceiverCommunicationTime == 0L) {
|
if (lastGoodReceiverCommunicationTime == 0L) {
|
||||||
lastGoodReceiverCommunicationTime = SP.getLong(RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
|
lastGoodReceiverCommunicationTime = sp.getLong(RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
|
||||||
// Might still be zero, but that's fine.
|
// Might still be zero, but that's fine.
|
||||||
}
|
}
|
||||||
double minutesAgo = (System.currentTimeMillis() - lastGoodReceiverCommunicationTime) / (1000.0 * 60.0);
|
double minutesAgo = (System.currentTimeMillis() - lastGoodReceiverCommunicationTime) / (1000.0 * 60.0);
|
||||||
|
@ -445,12 +443,6 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
return lastGoodReceiverCommunicationTime;
|
return lastGoodReceiverCommunicationTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public PumpStatus getPumpStatus() {
|
|
||||||
return pumpStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void clearNotConnectedCount() {
|
public void clearNotConnectedCount() {
|
||||||
if (rfspy != null) {
|
if (rfspy != null) {
|
||||||
rfspy.notConnectedCount = 0;
|
rfspy.notConnectedCount = 0;
|
||||||
|
@ -461,7 +453,5 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
return L.isEnabled(L.PUMPCOMM);
|
return L.isEnabled(L.PUMPCOMM);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPumpStatus(PumpStatus pumpStatus) {
|
public abstract PumpStatus getPumpStatus();
|
||||||
this.pumpStatus = pumpStatus;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ import java.util.Locale;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import dagger.android.support.DaggerFragment;
|
import dagger.android.support.DaggerFragment;
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface;
|
import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
||||||
|
@ -24,6 +23,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.Riley
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
|
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
|
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by andy on 5/19/18.
|
* Created by andy on 5/19/18.
|
||||||
|
@ -33,6 +33,8 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
|
||||||
|
|
||||||
@Inject RileyLinkUtil rileyLinkUtil;
|
@Inject RileyLinkUtil rileyLinkUtil;
|
||||||
@Inject MedtronicUtil medtronicUtil;
|
@Inject MedtronicUtil medtronicUtil;
|
||||||
|
@Inject MedtronicPumpStatus medtronicPumpStatus;
|
||||||
|
@Inject ResourceHelper resourceHelper;
|
||||||
|
|
||||||
TextView connectionStatus;
|
TextView connectionStatus;
|
||||||
TextView configuredAddress;
|
TextView configuredAddress;
|
||||||
|
@ -100,15 +102,15 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
|
||||||
RileyLinkTargetDevice targetDevice = rileyLinkUtil.getTargetDevice();
|
RileyLinkTargetDevice targetDevice = rileyLinkUtil.getTargetDevice();
|
||||||
|
|
||||||
if (rileyLinkUtil.getServiceState() == null)
|
if (rileyLinkUtil.getServiceState() == null)
|
||||||
this.connectionStatus.setText(MainApp.gs(RileyLinkServiceState.NotStarted.getResourceId(targetDevice)));
|
this.connectionStatus.setText(resourceHelper.gs(RileyLinkServiceState.NotStarted.getResourceId(targetDevice)));
|
||||||
else
|
else
|
||||||
this.connectionStatus.setText(MainApp.gs(rileyLinkUtil.getServiceState().getResourceId(targetDevice)));
|
this.connectionStatus.setText(resourceHelper.gs(rileyLinkUtil.getServiceState().getResourceId(targetDevice)));
|
||||||
|
|
||||||
if (rileyLinkServiceData != null) {
|
if (rileyLinkServiceData != null) {
|
||||||
this.configuredAddress.setText(rileyLinkServiceData.rileylinkAddress);
|
this.configuredAddress.setText(rileyLinkServiceData.rileylinkAddress);
|
||||||
this.connectionError.setText(rileyLinkServiceData.errorCode == null ? //
|
this.connectionError.setText(rileyLinkServiceData.errorCode == null ? //
|
||||||
"-"
|
"-"
|
||||||
: MainApp.gs(rileyLinkServiceData.errorCode.getResourceId(targetDevice)));
|
: resourceHelper.gs(rileyLinkServiceData.errorCode.getResourceId(targetDevice)));
|
||||||
|
|
||||||
|
|
||||||
RileyLinkFirmwareVersion firmwareVersion = rileyLinkServiceData.versionCC110;
|
RileyLinkFirmwareVersion firmwareVersion = rileyLinkServiceData.versionCC110;
|
||||||
|
@ -123,13 +125,12 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO add handling for Omnipod pump status
|
// TODO add handling for Omnipod pump status
|
||||||
MedtronicPumpStatus medtronicPumpStatus = medtronicUtil.getPumpStatus();
|
|
||||||
|
|
||||||
if (medtronicPumpStatus != null) {
|
if (medtronicPumpStatus != null) {
|
||||||
this.deviceType.setText(MainApp.gs(RileyLinkTargetDevice.MedtronicPump.getResourceId()));
|
this.deviceType.setText(resourceHelper.gs(RileyLinkTargetDevice.MedtronicPump.getResourceId()));
|
||||||
this.deviceModel.setText(medtronicPumpStatus.pumpType.getDescription());
|
this.deviceModel.setText(medtronicPumpStatus.pumpType.getDescription());
|
||||||
this.serialNumber.setText(medtronicPumpStatus.serialNumber);
|
this.serialNumber.setText(medtronicPumpStatus.serialNumber);
|
||||||
this.pumpFrequency.setText(MainApp.gs(medtronicPumpStatus.pumpFrequency.equals("medtronic_pump_frequency_us_ca") ? R.string.medtronic_pump_frequency_us_ca : R.string.medtronic_pump_frequency_worldwide));
|
this.pumpFrequency.setText(resourceHelper.gs(medtronicPumpStatus.pumpFrequency.equals("medtronic_pump_frequency_us_ca") ? R.string.medtronic_pump_frequency_us_ca : R.string.medtronic_pump_frequency_worldwide));
|
||||||
|
|
||||||
// TODO extend when Omnipod used
|
// TODO extend when Omnipod used
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,7 @@ class MedtronicFragment : DaggerFragment() {
|
||||||
@Inject lateinit var warnColors: WarnColors
|
@Inject lateinit var warnColors: WarnColors
|
||||||
@Inject lateinit var rileyLinkUtil: RileyLinkUtil
|
@Inject lateinit var rileyLinkUtil: RileyLinkUtil
|
||||||
@Inject lateinit var medtronicUtil: MedtronicUtil
|
@Inject lateinit var medtronicUtil: MedtronicUtil
|
||||||
|
@Inject lateinit var medtronicPumpStatus: MedtronicPumpStatus
|
||||||
|
|
||||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||||
|
|
||||||
|
@ -87,7 +88,7 @@ class MedtronicFragment : DaggerFragment() {
|
||||||
medtronic_pump_status.text = "{fa-bed}"
|
medtronic_pump_status.text = "{fa-bed}"
|
||||||
|
|
||||||
medtronic_history.setOnClickListener {
|
medtronic_history.setOnClickListener {
|
||||||
if (medtronicUtil.getPumpStatus().verifyConfiguration()) {
|
if (medtronicPumpStatus.verifyConfiguration()) {
|
||||||
startActivity(Intent(context, MedtronicHistoryActivity::class.java))
|
startActivity(Intent(context, MedtronicHistoryActivity::class.java))
|
||||||
} else {
|
} else {
|
||||||
displayNotConfiguredDialog()
|
displayNotConfiguredDialog()
|
||||||
|
@ -95,7 +96,7 @@ class MedtronicFragment : DaggerFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
medtronic_refresh.setOnClickListener {
|
medtronic_refresh.setOnClickListener {
|
||||||
if (!medtronicUtil.getPumpStatus().verifyConfiguration()) {
|
if (!medtronicPumpStatus.verifyConfiguration()) {
|
||||||
displayNotConfiguredDialog()
|
displayNotConfiguredDialog()
|
||||||
} else {
|
} else {
|
||||||
medtronic_refresh.isEnabled = false
|
medtronic_refresh.isEnabled = false
|
||||||
|
@ -109,7 +110,7 @@ class MedtronicFragment : DaggerFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
medtronic_stats.setOnClickListener {
|
medtronic_stats.setOnClickListener {
|
||||||
if (medtronicUtil.getPumpStatus().verifyConfiguration()) {
|
if (medtronicPumpStatus.verifyConfiguration()) {
|
||||||
startActivity(Intent(context, RileyLinkStatusActivity::class.java))
|
startActivity(Intent(context, RileyLinkStatusActivity::class.java))
|
||||||
} else {
|
} else {
|
||||||
displayNotConfiguredDialog()
|
displayNotConfiguredDialog()
|
||||||
|
@ -149,7 +150,7 @@ class MedtronicFragment : DaggerFragment() {
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe({
|
.subscribe({
|
||||||
aapsLogger.debug(LTag.PUMP, "EventMedtronicPumpConfigurationChanged triggered")
|
aapsLogger.debug(LTag.PUMP, "EventMedtronicPumpConfigurationChanged triggered")
|
||||||
medtronicUtil.getPumpStatus().verifyConfiguration()
|
medtronicPumpStatus.verifyConfiguration()
|
||||||
updateGUI()
|
updateGUI()
|
||||||
}, { fabricPrivacy.logException(it) })
|
}, { fabricPrivacy.logException(it) })
|
||||||
disposable += rxBus
|
disposable += rxBus
|
||||||
|
@ -173,33 +174,32 @@ class MedtronicFragment : DaggerFragment() {
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun setDeviceStatus() {
|
private fun setDeviceStatus() {
|
||||||
val pumpStatus: MedtronicPumpStatus = medtronicUtil.getPumpStatus()
|
medtronicPumpStatus.rileyLinkServiceState = checkStatusSet(medtronicPumpStatus.rileyLinkServiceState,
|
||||||
pumpStatus.rileyLinkServiceState = checkStatusSet(pumpStatus.rileyLinkServiceState,
|
|
||||||
rileyLinkUtil.getServiceState()) as RileyLinkServiceState?
|
rileyLinkUtil.getServiceState()) as RileyLinkServiceState?
|
||||||
|
|
||||||
val resourceId = pumpStatus.rileyLinkServiceState.getResourceId(RileyLinkTargetDevice.MedtronicPump)
|
val resourceId = medtronicPumpStatus.rileyLinkServiceState.getResourceId(RileyLinkTargetDevice.MedtronicPump)
|
||||||
val rileyLinkError = rileyLinkUtil.getError()
|
val rileyLinkError = rileyLinkUtil.getError()
|
||||||
medtronic_rl_status.text =
|
medtronic_rl_status.text =
|
||||||
when {
|
when {
|
||||||
pumpStatus.rileyLinkServiceState == RileyLinkServiceState.NotStarted -> resourceHelper.gs(resourceId)
|
medtronicPumpStatus.rileyLinkServiceState == RileyLinkServiceState.NotStarted -> resourceHelper.gs(resourceId)
|
||||||
pumpStatus.rileyLinkServiceState.isConnecting -> "{fa-bluetooth-b spin} " + resourceHelper.gs(resourceId)
|
medtronicPumpStatus.rileyLinkServiceState.isConnecting -> "{fa-bluetooth-b spin} " + resourceHelper.gs(resourceId)
|
||||||
pumpStatus.rileyLinkServiceState.isError && rileyLinkError == null -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
|
medtronicPumpStatus.rileyLinkServiceState.isError && rileyLinkError == null -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
|
||||||
pumpStatus.rileyLinkServiceState.isError && rileyLinkError != null -> "{fa-bluetooth-b} " + resourceHelper.gs(rileyLinkError.getResourceId(RileyLinkTargetDevice.MedtronicPump))
|
medtronicPumpStatus.rileyLinkServiceState.isError && rileyLinkError != null -> "{fa-bluetooth-b} " + resourceHelper.gs(rileyLinkError.getResourceId(RileyLinkTargetDevice.MedtronicPump))
|
||||||
else -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
|
else -> "{fa-bluetooth-b} " + resourceHelper.gs(resourceId)
|
||||||
}
|
}
|
||||||
medtronic_rl_status.setTextColor(if (rileyLinkError != null) Color.RED else Color.WHITE)
|
medtronic_rl_status.setTextColor(if (rileyLinkError != null) Color.RED else Color.WHITE)
|
||||||
|
|
||||||
pumpStatus.rileyLinkError = checkStatusSet(pumpStatus.rileyLinkError, rileyLinkUtil.getError()) as RileyLinkError?
|
medtronicPumpStatus.rileyLinkError = checkStatusSet(medtronicPumpStatus.rileyLinkError, rileyLinkUtil.getError()) as RileyLinkError?
|
||||||
|
|
||||||
medtronic_errors.text =
|
medtronic_errors.text =
|
||||||
pumpStatus.rileyLinkError?.let {
|
medtronicPumpStatus.rileyLinkError?.let {
|
||||||
resourceHelper.gs(it.getResourceId(RileyLinkTargetDevice.MedtronicPump))
|
resourceHelper.gs(it.getResourceId(RileyLinkTargetDevice.MedtronicPump))
|
||||||
} ?: "-"
|
} ?: "-"
|
||||||
|
|
||||||
pumpStatus.pumpDeviceState = checkStatusSet(pumpStatus.pumpDeviceState,
|
medtronicPumpStatus.pumpDeviceState = checkStatusSet(medtronicPumpStatus.pumpDeviceState,
|
||||||
medtronicUtil.getPumpDeviceState()) as PumpDeviceState?
|
medtronicUtil.pumpDeviceState) as PumpDeviceState?
|
||||||
|
|
||||||
when (pumpStatus.pumpDeviceState) {
|
when (medtronicPumpStatus.pumpDeviceState) {
|
||||||
null,
|
null,
|
||||||
PumpDeviceState.Sleeping -> medtronic_pump_status.text = "{fa-bed} " // + pumpStatus.pumpDeviceState.name());
|
PumpDeviceState.Sleeping -> medtronic_pump_status.text = "{fa-bed} " // + pumpStatus.pumpDeviceState.name());
|
||||||
PumpDeviceState.NeverContacted,
|
PumpDeviceState.NeverContacted,
|
||||||
|
@ -207,12 +207,12 @@ class MedtronicFragment : DaggerFragment() {
|
||||||
PumpDeviceState.PumpUnreachable,
|
PumpDeviceState.PumpUnreachable,
|
||||||
PumpDeviceState.ErrorWhenCommunicating,
|
PumpDeviceState.ErrorWhenCommunicating,
|
||||||
PumpDeviceState.TimeoutWhenCommunicating,
|
PumpDeviceState.TimeoutWhenCommunicating,
|
||||||
PumpDeviceState.InvalidConfiguration -> medtronic_pump_status.text = " " + resourceHelper.gs(pumpStatus.pumpDeviceState.resourceId)
|
PumpDeviceState.InvalidConfiguration -> medtronic_pump_status.text = " " + resourceHelper.gs(medtronicPumpStatus.pumpDeviceState.resourceId)
|
||||||
|
|
||||||
PumpDeviceState.Active -> {
|
PumpDeviceState.Active -> {
|
||||||
val cmd = medtronicUtil.getCurrentCommand()
|
val cmd = medtronicUtil.getCurrentCommand()
|
||||||
if (cmd == null)
|
if (cmd == null)
|
||||||
medtronic_pump_status.text = " " + resourceHelper.gs(pumpStatus.pumpDeviceState.resourceId)
|
medtronic_pump_status.text = " " + resourceHelper.gs(medtronicPumpStatus.pumpDeviceState.resourceId)
|
||||||
else {
|
else {
|
||||||
aapsLogger.debug(LTag.PUMP, "Command: " + cmd)
|
aapsLogger.debug(LTag.PUMP, "Command: " + cmd)
|
||||||
val cmdResourceId = cmd.resourceId
|
val cmdResourceId = cmd.resourceId
|
||||||
|
@ -228,7 +228,7 @@ class MedtronicFragment : DaggerFragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> aapsLogger.warn(LTag.PUMP, "Unknown pump state: " + pumpStatus.pumpDeviceState)
|
else -> aapsLogger.warn(LTag.PUMP, "Unknown pump state: " + medtronicPumpStatus.pumpDeviceState)
|
||||||
}
|
}
|
||||||
|
|
||||||
val status = commandQueue.spannedStatus()
|
val status = commandQueue.spannedStatus()
|
||||||
|
@ -262,18 +262,17 @@ class MedtronicFragment : DaggerFragment() {
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun updateGUI() {
|
fun updateGUI() {
|
||||||
if (medtronic_rl_status == null) return
|
if (medtronic_rl_status == null) return
|
||||||
val pumpStatus = medtronicUtil.getPumpStatus()
|
|
||||||
|
|
||||||
setDeviceStatus()
|
setDeviceStatus()
|
||||||
|
|
||||||
// last connection
|
// last connection
|
||||||
if (pumpStatus.lastConnection != 0L) {
|
if (medtronicPumpStatus.lastConnection != 0L) {
|
||||||
val minAgo = DateUtil.minAgo(resourceHelper, pumpStatus.lastConnection)
|
val minAgo = DateUtil.minAgo(resourceHelper, medtronicPumpStatus.lastConnection)
|
||||||
val min = (System.currentTimeMillis() - pumpStatus.lastConnection) / 1000 / 60
|
val min = (System.currentTimeMillis() - medtronicPumpStatus.lastConnection) / 1000 / 60
|
||||||
if (pumpStatus.lastConnection + 60 * 1000 > System.currentTimeMillis()) {
|
if (medtronicPumpStatus.lastConnection + 60 * 1000 > System.currentTimeMillis()) {
|
||||||
medtronic_lastconnection.setText(R.string.combo_pump_connected_now)
|
medtronic_lastconnection.setText(R.string.combo_pump_connected_now)
|
||||||
medtronic_lastconnection.setTextColor(Color.WHITE)
|
medtronic_lastconnection.setTextColor(Color.WHITE)
|
||||||
} else if (pumpStatus.lastConnection + 30 * 60 * 1000 < System.currentTimeMillis()) {
|
} else if (medtronicPumpStatus.lastConnection + 30 * 60 * 1000 < System.currentTimeMillis()) {
|
||||||
|
|
||||||
if (min < 60) {
|
if (min < 60) {
|
||||||
medtronic_lastconnection.text = resourceHelper.gs(R.string.minago, min)
|
medtronic_lastconnection.text = resourceHelper.gs(R.string.minago, min)
|
||||||
|
@ -296,19 +295,19 @@ class MedtronicFragment : DaggerFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// last bolus
|
// last bolus
|
||||||
val bolus = pumpStatus.lastBolusAmount
|
val bolus = medtronicPumpStatus.lastBolusAmount
|
||||||
val bolusTime = pumpStatus.lastBolusTime
|
val bolusTime = medtronicPumpStatus.lastBolusTime
|
||||||
if (bolus != null && bolusTime != null) {
|
if (bolus != null && bolusTime != null) {
|
||||||
val agoMsc = System.currentTimeMillis() - pumpStatus.lastBolusTime.time
|
val agoMsc = System.currentTimeMillis() - medtronicPumpStatus.lastBolusTime.time
|
||||||
val bolusMinAgo = agoMsc.toDouble() / 60.0 / 1000.0
|
val bolusMinAgo = agoMsc.toDouble() / 60.0 / 1000.0
|
||||||
val unit = resourceHelper.gs(R.string.insulin_unit_shortname)
|
val unit = resourceHelper.gs(R.string.insulin_unit_shortname)
|
||||||
val ago: String
|
val ago: String
|
||||||
if (agoMsc < 60 * 1000) {
|
if (agoMsc < 60 * 1000) {
|
||||||
ago = resourceHelper.gs(R.string.combo_pump_connected_now)
|
ago = resourceHelper.gs(R.string.combo_pump_connected_now)
|
||||||
} else if (bolusMinAgo < 60) {
|
} else if (bolusMinAgo < 60) {
|
||||||
ago = DateUtil.minAgo(resourceHelper, pumpStatus.lastBolusTime.time)
|
ago = DateUtil.minAgo(resourceHelper, medtronicPumpStatus.lastBolusTime.time)
|
||||||
} else {
|
} else {
|
||||||
ago = DateUtil.hourAgo(pumpStatus.lastBolusTime.time, resourceHelper)
|
ago = DateUtil.hourAgo(medtronicPumpStatus.lastBolusTime.time, resourceHelper)
|
||||||
}
|
}
|
||||||
medtronic_lastbolus.text = resourceHelper.gs(R.string.combo_last_bolus, bolus, unit, ago)
|
medtronic_lastbolus.text = resourceHelper.gs(R.string.combo_last_bolus, bolus, unit, ago)
|
||||||
} else {
|
} else {
|
||||||
|
@ -316,24 +315,24 @@ class MedtronicFragment : DaggerFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// base basal rate
|
// base basal rate
|
||||||
medtronic_basabasalrate.text = ("(" + pumpStatus.activeProfileName + ") "
|
medtronic_basabasalrate.text = ("(" + medtronicPumpStatus.activeProfileName + ") "
|
||||||
+ resourceHelper.gs(R.string.pump_basebasalrate, medtronicPumpPlugin.baseBasalRate))
|
+ resourceHelper.gs(R.string.pump_basebasalrate, medtronicPumpPlugin.baseBasalRate))
|
||||||
|
|
||||||
medtronic_tempbasal.text = activePlugin.activeTreatments.getTempBasalFromHistory(System.currentTimeMillis())?.toStringFull()
|
medtronic_tempbasal.text = activePlugin.activeTreatments.getTempBasalFromHistory(System.currentTimeMillis())?.toStringFull()
|
||||||
?: ""
|
?: ""
|
||||||
|
|
||||||
// battery
|
// battery
|
||||||
if (medtronicUtil.getBatteryType() == BatteryType.None || pumpStatus.batteryVoltage == null) {
|
if (medtronicUtil.getBatteryType() == BatteryType.None || medtronicPumpStatus.batteryVoltage == null) {
|
||||||
medtronic_pumpstate_battery.text = "{fa-battery-" + pumpStatus.batteryRemaining / 25 + "} "
|
medtronic_pumpstate_battery.text = "{fa-battery-" + medtronicPumpStatus.batteryRemaining / 25 + "} "
|
||||||
} else {
|
} else {
|
||||||
medtronic_pumpstate_battery.text = "{fa-battery-" + pumpStatus.batteryRemaining / 25 + "} " + pumpStatus.batteryRemaining + "%" + String.format(" (%.2f V)", pumpStatus.batteryVoltage)
|
medtronic_pumpstate_battery.text = "{fa-battery-" + medtronicPumpStatus.batteryRemaining / 25 + "} " + medtronicPumpStatus.batteryRemaining + "%" + String.format(" (%.2f V)", medtronicPumpStatus.batteryVoltage)
|
||||||
}
|
}
|
||||||
warnColors.setColorInverse(medtronic_pumpstate_battery, pumpStatus.batteryRemaining.toDouble(), 25.0, 10.0)
|
warnColors.setColorInverse(medtronic_pumpstate_battery, medtronicPumpStatus.batteryRemaining.toDouble(), 25.0, 10.0)
|
||||||
|
|
||||||
// reservoir
|
// reservoir
|
||||||
medtronic_reservoir.text = resourceHelper.gs(R.string.reservoirvalue, pumpStatus.reservoirRemainingUnits, pumpStatus.reservoirFullUnits)
|
medtronic_reservoir.text = resourceHelper.gs(R.string.reservoirvalue, medtronicPumpStatus.reservoirRemainingUnits, medtronicPumpStatus.reservoirFullUnits)
|
||||||
warnColors.setColorInverse(medtronic_reservoir, pumpStatus.reservoirRemainingUnits, 50.0, 20.0)
|
warnColors.setColorInverse(medtronic_reservoir, medtronicPumpStatus.reservoirRemainingUnits, 50.0, 20.0)
|
||||||
|
|
||||||
medtronic_errors.text = pumpStatus.errorInfo
|
medtronic_errors.text = medtronicPumpStatus.errorInfo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,10 +99,10 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
private final RileyLinkUtil rileyLinkUtil;
|
private final RileyLinkUtil rileyLinkUtil;
|
||||||
private final MedtronicUtil medtronicUtil;
|
private final MedtronicUtil medtronicUtil;
|
||||||
private final MedtronicPumpStatus medtronicPumpStatus;
|
private final MedtronicPumpStatus medtronicPumpStatus;
|
||||||
|
private final MedtronicUIComm medtronicUIComm;
|
||||||
|
|
||||||
protected static MedtronicPumpPlugin plugin = null;
|
protected static MedtronicPumpPlugin plugin = null;
|
||||||
private RileyLinkMedtronicService rileyLinkMedtronicService;
|
private RileyLinkMedtronicService rileyLinkMedtronicService;
|
||||||
private MedtronicUIComm medtronicUIComm;
|
|
||||||
|
|
||||||
// variables for handling statuses and history
|
// variables for handling statuses and history
|
||||||
private boolean firstRun = true;
|
private boolean firstRun = true;
|
||||||
|
@ -131,7 +131,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
FabricPrivacy fabricPrivacy,
|
FabricPrivacy fabricPrivacy,
|
||||||
RileyLinkUtil rileyLinkUtil,
|
RileyLinkUtil rileyLinkUtil,
|
||||||
MedtronicUtil medtronicUtil,
|
MedtronicUtil medtronicUtil,
|
||||||
MedtronicPumpStatus medtronicPumpStatus
|
MedtronicPumpStatus medtronicPumpStatus,
|
||||||
|
MedtronicUIComm medtronicUIComm
|
||||||
) {
|
) {
|
||||||
|
|
||||||
super(new PluginDescription() //
|
super(new PluginDescription() //
|
||||||
|
@ -150,6 +151,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
this.medtronicUtil = medtronicUtil;
|
this.medtronicUtil = medtronicUtil;
|
||||||
this.sp = sp;
|
this.sp = sp;
|
||||||
this.medtronicPumpStatus = medtronicPumpStatus;
|
this.medtronicPumpStatus = medtronicPumpStatus;
|
||||||
|
this.medtronicUIComm = medtronicUIComm;
|
||||||
|
|
||||||
displayConnectionMessages = false;
|
displayConnectionMessages = false;
|
||||||
|
|
||||||
|
@ -170,11 +172,9 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
for (int i = 0; i < 20; i++) {
|
for (int i = 0; i < 20; i++) {
|
||||||
SystemClock.sleep(5000);
|
SystemClock.sleep(5000);
|
||||||
|
|
||||||
if (medtronicUtil.getPumpStatus() != null) {
|
aapsLogger.debug(LTag.PUMP, "Starting Medtronic-RileyLink service");
|
||||||
aapsLogger.debug(LTag.PUMP, "Starting Medtronic-RileyLink service");
|
if (medtronicPumpStatus.setNotInPreInit()) {
|
||||||
if (medtronicUtil.getPumpStatus().setNotInPreInit()) {
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
@ -186,7 +186,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
medtronicUIComm = new MedtronicUIComm(aapsLogger, rxBus, getResourceHelper(), rileyLinkUtil, medtronicUtil);
|
|
||||||
medtronicHistoryData = new MedtronicHistoryData(aapsLogger, sp, activePlugin);
|
medtronicHistoryData = new MedtronicHistoryData(aapsLogger, sp, activePlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,8 +210,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
@Override
|
@Override
|
||||||
public void initPumpStatusData() {
|
public void initPumpStatusData() {
|
||||||
|
|
||||||
medtronicUtil.setPumpStatus(medtronicPumpStatus);
|
|
||||||
|
|
||||||
medtronicPumpStatus.lastConnection = sp.getLong(RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
|
medtronicPumpStatus.lastConnection = sp.getLong(RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
|
||||||
medtronicPumpStatus.lastDataTime = medtronicPumpStatus.lastConnection;
|
medtronicPumpStatus.lastDataTime = medtronicPumpStatus.lastConnection;
|
||||||
medtronicPumpStatus.previousConnection = medtronicPumpStatus.lastConnection;
|
medtronicPumpStatus.previousConnection = medtronicPumpStatus.lastConnection;
|
||||||
|
@ -1532,7 +1529,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
switch (mcat) {
|
switch (mcat) {
|
||||||
|
|
||||||
case WakeUpAndTune: {
|
case WakeUpAndTune: {
|
||||||
if (medtronicUtil.getPumpStatus().verifyConfiguration()) {
|
if (medtronicPumpStatus.verifyConfiguration()) {
|
||||||
ServiceTaskExecutor.startTask(new WakeAndTuneTask(getInjector()));
|
ServiceTaskExecutor.startTask(new WakeAndTuneTask(getInjector()));
|
||||||
} else {
|
} else {
|
||||||
Intent i = new Intent(context, ErrorHelperActivity.class);
|
Intent i = new Intent(context, ErrorHelperActivity.class);
|
||||||
|
@ -1583,5 +1580,9 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
refreshCustomActionsList();
|
refreshCustomActionsList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public MedtronicPumpStatus getMedtronicPumpStatus() {
|
||||||
|
return medtronicPumpStatus;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,12 @@ import java.util.GregorianCalendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector;
|
import dagger.android.HasAndroidInjector;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
||||||
|
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;
|
||||||
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.ble.RFSpy;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy;
|
||||||
|
@ -45,8 +48,8 @@ import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.TempBasalPair;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType;
|
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType;
|
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType;
|
||||||
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.medtronic.util.MedtronicUtil;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Original file created by geoff on 5/30/16.
|
* Original file created by geoff on 5/30/16.
|
||||||
|
@ -57,6 +60,8 @@ import info.nightscout.androidaps.utils.SP;
|
||||||
*/
|
*/
|
||||||
public class MedtronicCommunicationManager extends RileyLinkCommunicationManager {
|
public class MedtronicCommunicationManager extends RileyLinkCommunicationManager {
|
||||||
|
|
||||||
|
@Inject MedtronicPumpStatus medtronicPumpStatus;
|
||||||
|
|
||||||
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
|
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
|
||||||
private static final int MAX_COMMAND_TRIES = 3;
|
private static final int MAX_COMMAND_TRIES = 3;
|
||||||
private static final int DEFAULT_TIMEOUT = 2000;
|
private static final int DEFAULT_TIMEOUT = 2000;
|
||||||
|
@ -76,7 +81,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
medtronicCommunicationManager = this;
|
medtronicCommunicationManager = this;
|
||||||
this.medtronicConverter = new MedtronicConverter();
|
this.medtronicConverter = new MedtronicConverter();
|
||||||
this.pumpHistoryDecoder = new MedtronicPumpHistoryDecoder();
|
this.pumpHistoryDecoder = new MedtronicPumpHistoryDecoder();
|
||||||
MedtronicUtil.getInstance().getPumpStatus().previousConnection = SP.getLong(
|
medtronicPumpStatus.previousConnection = sp.getLong(
|
||||||
RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
|
RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,13 +90,6 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
return medtronicCommunicationManager;
|
return medtronicCommunicationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configurePumpSpecificSettings() {
|
|
||||||
pumpStatus = MedtronicUtil.getInstance().getPumpStatus();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends RLMessage> E createResponseMessage(byte[] payload, Class<E> clazz) {
|
public <E extends RLMessage> E createResponseMessage(byte[] payload, Class<E> clazz) {
|
||||||
PumpMessage pumpMessage = new PumpMessage(payload);
|
PumpMessage pumpMessage = new PumpMessage(payload);
|
||||||
|
@ -141,7 +139,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
|
|
||||||
if (!canPreventTuneUp) {
|
if (!canPreventTuneUp) {
|
||||||
|
|
||||||
long diff = System.currentTimeMillis() - MedtronicUtil.getInstance().getPumpStatus().lastConnection;
|
long diff = System.currentTimeMillis() - medtronicPumpStatus.lastConnection;
|
||||||
|
|
||||||
if (diff > RILEYLINK_TIMEOUT) {
|
if (diff > RILEYLINK_TIMEOUT) {
|
||||||
ServiceTaskExecutor.startTask(new WakeAndTuneTask(injector));
|
ServiceTaskExecutor.startTask(new WakeAndTuneTask(injector));
|
||||||
|
@ -962,5 +960,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
return L.isEnabled(L.PUMPCOMM);
|
return L.isEnabled(L.PUMPCOMM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public PumpStatus getPumpStatus() {
|
||||||
|
return medtronicPumpStatus;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,10 @@ package info.nightscout.androidaps.plugins.pump.medtronic.comm.ui;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import dagger.android.HasAndroidInjector;
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
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;
|
||||||
|
@ -15,27 +19,32 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||||
/**
|
/**
|
||||||
* Created by andy on 6/14/18.
|
* Created by andy on 6/14/18.
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class MedtronicUIComm {
|
public class MedtronicUIComm {
|
||||||
|
|
||||||
|
@NotNull private final HasAndroidInjector injector;
|
||||||
@NotNull private final AAPSLogger aapsLogger;
|
@NotNull private final AAPSLogger aapsLogger;
|
||||||
@NotNull private final RileyLinkUtil rileyLinkUtil;
|
@NotNull private final RileyLinkUtil rileyLinkUtil;
|
||||||
@NotNull private final MedtronicUtil medtronicUtil;
|
@NotNull private final MedtronicUtil medtronicUtil;
|
||||||
|
|
||||||
MedtronicCommunicationManager mcmInstance = null;
|
MedtronicCommunicationManager mcmInstance = null;
|
||||||
MedtronicUIPostprocessor uiPostprocessor;
|
@NotNull private final MedtronicUIPostprocessor medtronicUIPostprocessor;
|
||||||
|
|
||||||
|
@Inject
|
||||||
public MedtronicUIComm(
|
public MedtronicUIComm(
|
||||||
|
HasAndroidInjector injector,
|
||||||
AAPSLogger aapsLogger,
|
AAPSLogger aapsLogger,
|
||||||
RxBusWrapper rxBus,
|
RxBusWrapper rxBus,
|
||||||
ResourceHelper resourceHelper,
|
ResourceHelper resourceHelper,
|
||||||
RileyLinkUtil rileyLinkUtil,
|
RileyLinkUtil rileyLinkUtil,
|
||||||
MedtronicUtil medtronicUtil
|
MedtronicUtil medtronicUtil,
|
||||||
|
MedtronicUIPostprocessor medtronicUIPostprocessor
|
||||||
) {
|
) {
|
||||||
|
this.injector = injector;
|
||||||
this.aapsLogger = aapsLogger;
|
this.aapsLogger = aapsLogger;
|
||||||
this.rileyLinkUtil = rileyLinkUtil;
|
this.rileyLinkUtil = rileyLinkUtil;
|
||||||
this.medtronicUtil = medtronicUtil;
|
this.medtronicUtil = medtronicUtil;
|
||||||
|
this.medtronicUIPostprocessor = medtronicUIPostprocessor;
|
||||||
uiPostprocessor = new MedtronicUIPostprocessor(aapsLogger, rxBus, resourceHelper, medtronicUtil);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,7 +61,7 @@ public class MedtronicUIComm {
|
||||||
|
|
||||||
aapsLogger.warn(LTag.PUMP, "Execute Command: " + commandType.name());
|
aapsLogger.warn(LTag.PUMP, "Execute Command: " + commandType.name());
|
||||||
|
|
||||||
MedtronicUITask task = new MedtronicUITask(commandType, parameters);
|
MedtronicUITask task = new MedtronicUITask(injector, commandType, parameters);
|
||||||
|
|
||||||
medtronicUtil.setCurrentCommand(commandType);
|
medtronicUtil.setCurrentCommand(commandType);
|
||||||
|
|
||||||
|
@ -88,7 +97,7 @@ public class MedtronicUIComm {
|
||||||
aapsLogger.warn(LTag.PUMP, "Reply not received for " + commandType);
|
aapsLogger.warn(LTag.PUMP, "Reply not received for " + commandType);
|
||||||
}
|
}
|
||||||
|
|
||||||
task.postProcess(uiPostprocessor);
|
task.postProcess(medtronicUIPostprocessor);
|
||||||
|
|
||||||
return task;
|
return task;
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,9 @@ import org.joda.time.Duration;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
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;
|
||||||
|
@ -26,18 +29,22 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||||
* Created by andy on 6/15/18.
|
* Created by andy on 6/15/18.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@Singleton
|
||||||
class MedtronicUIPostprocessor {
|
class MedtronicUIPostprocessor {
|
||||||
|
|
||||||
@NotNull private final AAPSLogger aapsLogger;
|
@NotNull private final AAPSLogger aapsLogger;
|
||||||
@NotNull private final RxBusWrapper rxBus;
|
@NotNull private final RxBusWrapper rxBus;
|
||||||
@NotNull private final ResourceHelper resourceHelper;
|
@NotNull private final ResourceHelper resourceHelper;
|
||||||
@NotNull private final MedtronicUtil medtronicUtil;
|
@NotNull private final MedtronicUtil medtronicUtil;
|
||||||
|
@NotNull private final MedtronicPumpStatus medtronicPumpStatus;
|
||||||
|
|
||||||
public MedtronicUIPostprocessor(AAPSLogger aapsLogger, RxBusWrapper rxBus, ResourceHelper resourceHelper, MedtronicUtil medtronicUtil) {
|
@Inject
|
||||||
|
public MedtronicUIPostprocessor(AAPSLogger aapsLogger, RxBusWrapper rxBus, ResourceHelper resourceHelper, MedtronicUtil medtronicUtil, MedtronicPumpStatus medtronicPumpStatus) {
|
||||||
this.aapsLogger = aapsLogger;
|
this.aapsLogger = aapsLogger;
|
||||||
this.rxBus = rxBus;
|
this.rxBus = rxBus;
|
||||||
this.resourceHelper = resourceHelper;
|
this.resourceHelper = resourceHelper;
|
||||||
this.medtronicUtil = medtronicUtil;
|
this.medtronicUtil = medtronicUtil;
|
||||||
|
this.medtronicPumpStatus = medtronicPumpStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,7 +60,7 @@ class MedtronicUIPostprocessor {
|
||||||
if (response) {
|
if (response) {
|
||||||
BasalProfile basalProfile = (BasalProfile) uiTask.getParameter(0);
|
BasalProfile basalProfile = (BasalProfile) uiTask.getParameter(0);
|
||||||
|
|
||||||
medtronicUtil.getPumpStatus().basalsByHour = basalProfile.getProfilesByHour();
|
medtronicPumpStatus.basalsByHour = basalProfile.getProfilesByHour();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -65,8 +72,8 @@ class MedtronicUIPostprocessor {
|
||||||
Double[] profilesByHour = basalProfile.getProfilesByHour();
|
Double[] profilesByHour = basalProfile.getProfilesByHour();
|
||||||
|
|
||||||
if (profilesByHour != null) {
|
if (profilesByHour != null) {
|
||||||
medtronicUtil.getPumpStatus().basalsByHour = profilesByHour;
|
medtronicPumpStatus.basalsByHour = profilesByHour;
|
||||||
medtronicUtil.getPumpStatus().basalProfileStatus = BasalProfileStatus.ProfileOK;
|
medtronicPumpStatus.basalProfileStatus = BasalProfileStatus.ProfileOK;
|
||||||
} else {
|
} else {
|
||||||
uiTask.responseType = MedtronicUIResponseType.Error;
|
uiTask.responseType = MedtronicUIResponseType.Error;
|
||||||
uiTask.errorDescription = "No profile found.";
|
uiTask.errorDescription = "No profile found.";
|
||||||
|
@ -81,20 +88,20 @@ class MedtronicUIPostprocessor {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SetBolus: {
|
case SetBolus: {
|
||||||
medtronicUtil.getPumpStatus().lastBolusAmount = uiTask.getDoubleFromParameters(0);
|
medtronicPumpStatus.lastBolusAmount = uiTask.getDoubleFromParameters(0);
|
||||||
medtronicUtil.getPumpStatus().lastBolusTime = new Date();
|
medtronicPumpStatus.lastBolusTime = new Date();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GetRemainingInsulin: {
|
case GetRemainingInsulin: {
|
||||||
medtronicUtil.getPumpStatus().reservoirRemainingUnits = (Float) uiTask.returnData;
|
medtronicPumpStatus.reservoirRemainingUnits = (Float) uiTask.returnData;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CancelTBR: {
|
case CancelTBR: {
|
||||||
medtronicUtil.getPumpStatus().tempBasalStart = null;
|
medtronicPumpStatus.tempBasalStart = null;
|
||||||
medtronicUtil.getPumpStatus().tempBasalAmount = null;
|
medtronicPumpStatus.tempBasalAmount = null;
|
||||||
medtronicUtil.getPumpStatus().tempBasalLength = null;
|
medtronicPumpStatus.tempBasalLength = null;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -118,10 +125,10 @@ class MedtronicUIPostprocessor {
|
||||||
case GetBatteryStatus: {
|
case GetBatteryStatus: {
|
||||||
BatteryStatusDTO batteryStatusDTO = (BatteryStatusDTO) uiTask.returnData;
|
BatteryStatusDTO batteryStatusDTO = (BatteryStatusDTO) uiTask.returnData;
|
||||||
|
|
||||||
medtronicUtil.getPumpStatus().batteryRemaining = batteryStatusDTO.getCalculatedPercent(medtronicUtil.getPumpStatus().batteryType);
|
medtronicPumpStatus.batteryRemaining = batteryStatusDTO.getCalculatedPercent(medtronicPumpStatus.batteryType);
|
||||||
|
|
||||||
if (batteryStatusDTO.voltage != null) {
|
if (batteryStatusDTO.voltage != null) {
|
||||||
medtronicUtil.getPumpStatus().batteryVoltage = batteryStatusDTO.voltage;
|
medtronicPumpStatus.batteryVoltage = batteryStatusDTO.voltage;
|
||||||
}
|
}
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMP, "BatteryStatus: {}", batteryStatusDTO.toString());
|
aapsLogger.debug(LTag.PUMP, "BatteryStatus: {}", batteryStatusDTO.toString());
|
||||||
|
@ -130,7 +137,7 @@ class MedtronicUIPostprocessor {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PumpModel: {
|
case PumpModel: {
|
||||||
if (medtronicUtil.getPumpStatus().medtronicDeviceType != medtronicUtil.getMedtronicPumpModel()) {
|
if (medtronicPumpStatus.medtronicDeviceType != medtronicUtil.getMedtronicPumpModel()) {
|
||||||
aapsLogger.warn(LTag.PUMP, "Configured pump is different then pump detected !");
|
aapsLogger.warn(LTag.PUMP, "Configured pump is different then pump detected !");
|
||||||
medtronicUtil.sendNotification(MedtronicNotificationType.PumpTypeNotSame, resourceHelper, rxBus);
|
medtronicUtil.sendNotification(MedtronicNotificationType.PumpTypeNotSame, resourceHelper, rxBus);
|
||||||
}
|
}
|
||||||
|
@ -190,11 +197,7 @@ class MedtronicUIPostprocessor {
|
||||||
|
|
||||||
PumpSettingDTO checkValue = null;
|
PumpSettingDTO checkValue = null;
|
||||||
|
|
||||||
if (medtronicUtil.getPumpStatus() == null) {
|
medtronicPumpStatus.verifyConfiguration();
|
||||||
aapsLogger.debug(LTag.PUMP, "Pump Status: was null");
|
|
||||||
}
|
|
||||||
|
|
||||||
medtronicUtil.getPumpStatus().verifyConfiguration();
|
|
||||||
|
|
||||||
// check profile
|
// check profile
|
||||||
if (!"Yes".equals(settings.get("PCFG_BASAL_PROFILES_ENABLED").value)) {
|
if (!"Yes".equals(settings.get("PCFG_BASAL_PROFILES_ENABLED").value)) {
|
||||||
|
@ -223,16 +226,16 @@ class MedtronicUIPostprocessor {
|
||||||
|
|
||||||
checkValue = settings.get("PCFG_MAX_BOLUS");
|
checkValue = settings.get("PCFG_MAX_BOLUS");
|
||||||
|
|
||||||
if (!medtronicUtil.isSame(Double.parseDouble(checkValue.value), medtronicUtil.getPumpStatus().maxBolus)) {
|
if (!medtronicUtil.isSame(Double.parseDouble(checkValue.value), medtronicPumpStatus.maxBolus)) {
|
||||||
aapsLogger.error("Wrong Max Bolus set on Pump (current={}, required={}).", checkValue.value, medtronicUtil.getPumpStatus().maxBolus);
|
aapsLogger.error("Wrong Max Bolus set on Pump (current={}, required={}).", checkValue.value, medtronicPumpStatus.maxBolus);
|
||||||
medtronicUtil.sendNotification(MedtronicNotificationType.PumpWrongMaxBolusSet, resourceHelper, rxBus, medtronicUtil.getPumpStatus().maxBolus);
|
medtronicUtil.sendNotification(MedtronicNotificationType.PumpWrongMaxBolusSet, resourceHelper, rxBus, medtronicPumpStatus.maxBolus);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkValue = settings.get("PCFG_MAX_BASAL");
|
checkValue = settings.get("PCFG_MAX_BASAL");
|
||||||
|
|
||||||
if (!medtronicUtil.isSame(Double.parseDouble(checkValue.value), medtronicUtil.getPumpStatus().maxBasal)) {
|
if (!medtronicUtil.isSame(Double.parseDouble(checkValue.value), medtronicPumpStatus.maxBasal)) {
|
||||||
aapsLogger.error("Wrong Max Basal set on Pump (current={}, required={}).", checkValue.value, medtronicUtil.getPumpStatus().maxBasal);
|
aapsLogger.error("Wrong Max Basal set on Pump (current={}, required={}).", checkValue.value, medtronicPumpStatus.maxBasal);
|
||||||
medtronicUtil.sendNotification(MedtronicNotificationType.PumpWrongMaxBasalSet, resourceHelper, rxBus, medtronicUtil.getPumpStatus().maxBasal);
|
medtronicUtil.sendNotification(MedtronicNotificationType.PumpWrongMaxBasalSet, resourceHelper, rxBus, medtronicPumpStatus.maxBasal);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.medtronic.comm.ui;
|
package info.nightscout.androidaps.plugins.pump.medtronic.comm.ui;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.joda.time.LocalDateTime;
|
import org.joda.time.LocalDateTime;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import dagger.android.HasAndroidInjector;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
|
@ -15,6 +17,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.TempBasalPair;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType;
|
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicUIResponseType;
|
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicUIResponseType;
|
||||||
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.events.EventMedtronicDeviceStatusChange;
|
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicDeviceStatusChange;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicPumpValuesChanged;
|
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicPumpValuesChanged;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||||
|
@ -25,6 +28,10 @@ import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||||
|
|
||||||
public class MedtronicUITask {
|
public class MedtronicUITask {
|
||||||
|
|
||||||
|
@Inject MedtronicPumpStatus medtronicPumpStatus;
|
||||||
|
|
||||||
|
@NotNull private final HasAndroidInjector injector;
|
||||||
|
|
||||||
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMP);
|
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMP);
|
||||||
|
|
||||||
public MedtronicCommandType commandType;
|
public MedtronicCommandType commandType;
|
||||||
|
@ -36,12 +43,16 @@ public class MedtronicUITask {
|
||||||
MedtronicUIResponseType responseType;
|
MedtronicUIResponseType responseType;
|
||||||
|
|
||||||
|
|
||||||
public MedtronicUITask(MedtronicCommandType commandType) {
|
public MedtronicUITask(HasAndroidInjector injector, MedtronicCommandType commandType) {
|
||||||
|
this.injector = injector;
|
||||||
|
injector.androidInjector().inject(this);
|
||||||
this.commandType = commandType;
|
this.commandType = commandType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public MedtronicUITask(MedtronicCommandType commandType, Object... parameters) {
|
public MedtronicUITask(HasAndroidInjector injector, MedtronicCommandType commandType, Object... parameters) {
|
||||||
|
this.injector = injector;
|
||||||
|
injector.androidInjector().inject(this);
|
||||||
this.commandType = commandType;
|
this.commandType = commandType;
|
||||||
this.parameters = parameters;
|
this.parameters = parameters;
|
||||||
}
|
}
|
||||||
|
@ -200,7 +211,7 @@ public class MedtronicUITask {
|
||||||
errorDescription));
|
errorDescription));
|
||||||
} else {
|
} else {
|
||||||
RxBus.Companion.getINSTANCE().send(new EventMedtronicPumpValuesChanged());
|
RxBus.Companion.getINSTANCE().send(new EventMedtronicPumpValuesChanged());
|
||||||
MedtronicUtil.getInstance().getPumpStatus().setLastCommunicationToNow();
|
medtronicPumpStatus.setLastCommunicationToNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
MedtronicUtil.getInstance().setCurrentCommand(null);
|
MedtronicUtil.getInstance().setCurrentCommand(null);
|
||||||
|
|
|
@ -4,7 +4,6 @@ import com.google.gson.annotations.Expose;
|
||||||
|
|
||||||
import org.joda.time.Instant;
|
import org.joda.time.Instant;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -13,6 +12,7 @@ import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
||||||
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.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.util.MedtronicUtil;
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -305,7 +305,7 @@ public class BasalProfile {
|
||||||
|
|
||||||
Double[] basalByHour = new Double[24];
|
Double[] basalByHour = new Double[24];
|
||||||
|
|
||||||
PumpType pumpType = MedtronicUtil.getInstance().getPumpStatus().pumpType;
|
PumpType pumpType = MedtronicPumpPlugin.getPlugin().getMedtronicPumpStatus().pumpType;
|
||||||
|
|
||||||
for (int i = 0; i < entries.size(); i++) {
|
for (int i = 0; i < entries.size(); i++) {
|
||||||
BasalProfileEntry current = entries.get(i);
|
BasalProfileEntry current = entries.get(i);
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.medtronic.driver;
|
package info.nightscout.androidaps.plugins.pump.medtronic.driver;
|
||||||
|
|
||||||
import org.joda.time.LocalDateTime;
|
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
@ -44,10 +42,10 @@ public class MedtronicPumpStatus extends PumpStatus {
|
||||||
private final ResourceHelper resourceHelper;
|
private final ResourceHelper resourceHelper;
|
||||||
private final SP sp;
|
private final SP sp;
|
||||||
|
|
||||||
public String errorDescription = null;
|
private String errorDescription = null;
|
||||||
public String serialNumber;
|
public String serialNumber;
|
||||||
public String pumpFrequency = null;
|
public String pumpFrequency = null;
|
||||||
public String rileyLinkAddress = null;
|
private String rileyLinkAddress = null;
|
||||||
public Double maxBolus;
|
public Double maxBolus;
|
||||||
public Double maxBasal;
|
public Double maxBasal;
|
||||||
private boolean inPreInit = true;
|
private boolean inPreInit = true;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.medtronic.service;
|
package info.nightscout.androidaps.plugins.pump.medtronic.service;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
@ -10,11 +9,9 @@ import android.os.IBinder;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector;
|
import dagger.android.HasAndroidInjector;
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
|
||||||
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;
|
||||||
|
@ -22,15 +19,12 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLin
|
||||||
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.common.hw.rileylink.service.RileyLinkServiceData;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTask;
|
|
||||||
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.MedtronicPumpPlugin;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager;
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager;
|
||||||
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.MedtronicConst;
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RileyLinkMedtronicService is intended to stay running when the gui-app is closed.
|
* RileyLinkMedtronicService is intended to stay running when the gui-app is closed.
|
||||||
|
@ -41,12 +35,8 @@ public class RileyLinkMedtronicService extends RileyLinkService {
|
||||||
@Inject MedtronicPumpPlugin medtronicPumpPlugin;
|
@Inject MedtronicPumpPlugin medtronicPumpPlugin;
|
||||||
@Inject MedtronicUtil medtronicUtil;
|
@Inject MedtronicUtil medtronicUtil;
|
||||||
|
|
||||||
@Deprecated // TEDO remove this reference
|
|
||||||
private static ServiceTask currentTask = null;
|
|
||||||
|
|
||||||
// cache of most recently received set of pump history pages. Probably shouldn't be here.
|
// cache of most recently received set of pump history pages. Probably shouldn't be here.
|
||||||
public MedtronicCommunicationManager medtronicCommunicationManager;
|
private MedtronicCommunicationManager medtronicCommunicationManager;
|
||||||
MedtronicPumpStatus pumpStatus = null;
|
|
||||||
private IBinder mBinder = new LocalBinder();
|
private IBinder mBinder = new LocalBinder();
|
||||||
|
|
||||||
|
|
||||||
|
@ -100,8 +90,6 @@ public class RileyLinkMedtronicService extends RileyLinkService {
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "RileyLinkMedtronicService newly constructed");
|
aapsLogger.debug(LTag.PUMPCOMM, "RileyLinkMedtronicService newly constructed");
|
||||||
medtronicUtil.setMedtronicService(this);
|
medtronicUtil.setMedtronicService(this);
|
||||||
pumpStatus = (MedtronicPumpStatus) medtronicPumpPlugin.getPumpStatusData();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,6 @@ public class MedtronicUtil {
|
||||||
private MedtronicDeviceType medtronicPumpModel;
|
private MedtronicDeviceType medtronicPumpModel;
|
||||||
private RileyLinkMedtronicService medtronicService;
|
private RileyLinkMedtronicService medtronicService;
|
||||||
@Deprecated // TODO remove this reference
|
@Deprecated // TODO remove this reference
|
||||||
private MedtronicPumpStatus medtronicPumpStatus;
|
|
||||||
private MedtronicCommandType currentCommand;
|
private MedtronicCommandType currentCommand;
|
||||||
private Map<String, PumpSettingDTO> settings;
|
private Map<String, PumpSettingDTO> settings;
|
||||||
private int BIG_FRAME_LENGTH = 65;
|
private int BIG_FRAME_LENGTH = 65;
|
||||||
|
@ -69,17 +68,20 @@ public class MedtronicUtil {
|
||||||
@NotNull private final AAPSLogger aapsLogger;
|
@NotNull private final AAPSLogger aapsLogger;
|
||||||
@NotNull private final RxBusWrapper rxBus;
|
@NotNull private final RxBusWrapper rxBus;
|
||||||
@NotNull private final RileyLinkUtil rileyLinkUtil;
|
@NotNull private final RileyLinkUtil rileyLinkUtil;
|
||||||
|
@NotNull private final MedtronicPumpStatus medtronicPumpStatus;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public MedtronicUtil(
|
public MedtronicUtil(
|
||||||
AAPSLogger aapsLogger,
|
AAPSLogger aapsLogger,
|
||||||
RxBusWrapper rxBus,
|
RxBusWrapper rxBus,
|
||||||
RileyLinkUtil rileyLinkUtil
|
RileyLinkUtil rileyLinkUtil,
|
||||||
|
MedtronicPumpStatus medtronicPumpStatus
|
||||||
|
|
||||||
) {
|
) {
|
||||||
this.aapsLogger = aapsLogger;
|
this.aapsLogger = aapsLogger;
|
||||||
this.rxBus = rxBus;
|
this.rxBus = rxBus;
|
||||||
this.rileyLinkUtil = rileyLinkUtil;
|
this.rileyLinkUtil = rileyLinkUtil;
|
||||||
|
this.medtronicPumpStatus = medtronicPumpStatus;
|
||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,16 +467,10 @@ public class MedtronicUtil {
|
||||||
|
|
||||||
|
|
||||||
@Deprecated // TODO use singleton
|
@Deprecated // TODO use singleton
|
||||||
public MedtronicPumpStatus getPumpStatus() {
|
public MedtronicPumpStatus getPumpStatus1() {
|
||||||
return medtronicPumpStatus;
|
return medtronicPumpStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated // TODO use singleton
|
|
||||||
public void setPumpStatus(MedtronicPumpStatus medtronicPumpStatus) {
|
|
||||||
this.medtronicPumpStatus = medtronicPumpStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public MedtronicCommandType getCurrentCommand() {
|
public MedtronicCommandType getCurrentCommand() {
|
||||||
return this.currentCommand;
|
return this.currentCommand;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue