MDT refactor pass 4
This commit is contained in:
parent
331c1c3ab5
commit
e2e0de25bc
|
@ -11,6 +11,7 @@ interface AAPSLogger {
|
||||||
fun debug(tag: LTag, message: String)
|
fun debug(tag: LTag, message: String)
|
||||||
fun debug(tag: LTag, format: String, vararg arguments: Any?)
|
fun debug(tag: LTag, format: String, vararg arguments: Any?)
|
||||||
fun warn(tag: LTag, message: String)
|
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, message: String)
|
||||||
fun info(tag: LTag, format: String, vararg arguments: Any?)
|
fun info(tag: LTag, format: String, vararg arguments: Any?)
|
||||||
fun error(tag: LTag, message: String)
|
fun error(tag: LTag, message: String)
|
||||||
|
|
|
@ -28,6 +28,10 @@ class AAPSLoggerDebug : AAPSLogger {
|
||||||
Log.w(tag.tag, message)
|
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) {
|
override fun info(tag: LTag, message: String) {
|
||||||
Log.i(tag.tag, message)
|
Log.i(tag.tag, message)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
override fun info(tag: LTag, message: String) {
|
||||||
if (L.isEnabled(tag.tag)) {
|
if (L.isEnabled(tag.tag)) {
|
||||||
LoggerFactory.getLogger(tag.tag).info(stackLogMarker() + message)
|
LoggerFactory.getLogger(tag.tag).info(stackLogMarker() + message)
|
||||||
|
|
|
@ -26,6 +26,10 @@ class AAPSLoggerTest : AAPSLogger {
|
||||||
println("WARN: " + tag.tag + " " + message)
|
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) {
|
override fun info(tag: LTag, message: String) {
|
||||||
println("INFO: " + tag.tag + " " + message)
|
println("INFO: " + tag.tag + " " + message)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.data.PumpStatus;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState;
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.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.pump.medtronic.data.MedtronicHistoryData;
|
||||||
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
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 initPumpStatusData();
|
||||||
public abstract void resetRileyLinkConfiguration();
|
public abstract void resetRileyLinkConfiguration();
|
||||||
public abstract void doTuneUpDevice();
|
public abstract void doTuneUpDevice();
|
||||||
|
public abstract RileyLinkService getRileyLinkService();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink;
|
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector;
|
import dagger.android.HasAndroidInjector;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
|
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkCommunicationException;
|
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 {
|
public abstract class RileyLinkCommunicationManager {
|
||||||
|
|
||||||
@Inject MedtronicPumpStatus medtronicPumpStatus;
|
@Inject protected AAPSLogger aapsLogger;
|
||||||
@Inject protected SP sp;
|
@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 HasAndroidInjector injector;
|
||||||
protected final RFSpy rfspy;
|
protected final RFSpy rfspy;
|
||||||
|
@ -61,8 +60,7 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
this.injector = injector;
|
this.injector = injector;
|
||||||
injector.androidInjector().inject(this);
|
injector.androidInjector().inject(this);
|
||||||
this.rfspy = rfspy;
|
this.rfspy = rfspy;
|
||||||
this.rileyLinkServiceData = RileyLinkUtil.getInstance().getRileyLinkServiceData();
|
this.rileyLinkServiceData = rileyLinkUtil.getRileyLinkServiceData();
|
||||||
RileyLinkUtil.getInstance().setRileyLinkCommunicationManager(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,8 +85,7 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
throws RileyLinkCommunicationException {
|
throws RileyLinkCommunicationException {
|
||||||
|
|
||||||
if (showPumpMessages) {
|
if (showPumpMessages) {
|
||||||
if (isLogEnabled())
|
aapsLogger.info(LTag.PUMPBTCOMM, "Sent:" + ByteUtil.shortHexString(msg.getTxData()));
|
||||||
LOG.info("Sent:" + ByteUtil.shortHexString(msg.getTxData()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RFSpyResponse rfSpyResponse = rfspy.transmitThenReceive(new RadioPacket(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.
|
// Mark this as the last time we heard from the pump.
|
||||||
rememberLastGoodDeviceCommunicationTime();
|
rememberLastGoodDeviceCommunicationTime();
|
||||||
} else {
|
} 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());
|
rfSpyResponse.wasTimeout(), rfSpyResponse.isUnknownCommand(), rfSpyResponse.isInvalidParam());
|
||||||
|
|
||||||
if (rfSpyResponse.wasTimeout()) {
|
if (rfSpyResponse.wasTimeout()) {
|
||||||
|
@ -111,7 +108,7 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
long diff = System.currentTimeMillis() - getPumpStatus().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.");
|
aapsLogger.warn(LTag.PUMPBTCOMM, "We reached max time that Pump can be unreachable. Starting Tuning.");
|
||||||
ServiceTaskExecutor.startTask(new WakeAndTuneTask(injector));
|
ServiceTaskExecutor.startTask(new WakeAndTuneTask(injector));
|
||||||
timeoutCount = 0;
|
timeoutCount = 0;
|
||||||
}
|
}
|
||||||
|
@ -124,8 +121,7 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showPumpMessages) {
|
if (showPumpMessages) {
|
||||||
if (isLogEnabled())
|
aapsLogger.info(LTag.PUMPBTCOMM, "Received:" + ByteUtil.shortHexString(rfSpyResponse.getRadioResponse().getPayload()));
|
||||||
LOG.info("Received:" + ByteUtil.shortHexString(rfSpyResponse.getRadioResponse().getPayload()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
@ -162,21 +158,18 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
nextWakeUpRequired = 0L;
|
nextWakeUpRequired = 0L;
|
||||||
|
|
||||||
if (System.currentTimeMillis() > nextWakeUpRequired) {
|
if (System.currentTimeMillis() > nextWakeUpRequired) {
|
||||||
if (isLogEnabled())
|
aapsLogger.info(LTag.PUMPBTCOMM, "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())
|
aapsLogger.info(LTag.PUMPBTCOMM, "wakeup: raw response is " + ByteUtil.shortHexString(resp.getRaw()));
|
||||||
LOG.info("wakeup: raw response is " + ByteUtil.shortHexString(resp.getRaw()));
|
|
||||||
|
|
||||||
// FIXME wakeUp successful !!!!!!!!!!!!!!!!!!
|
// FIXME wakeUp successful !!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
nextWakeUpRequired = System.currentTimeMillis() + (receiverDeviceAwakeForMinutes * 60 * 1000);
|
nextWakeUpRequired = System.currentTimeMillis() + (receiverDeviceAwakeForMinutes * 60 * 1000);
|
||||||
} else {
|
} else {
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Last pump communication was recent, not waking pump.");
|
||||||
LOG.trace("Last pump communication was recent, not waking pump.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// long lastGoodPlus = getLastGoodReceiverCommunicationTime() + (receiverDeviceAwakeForMinutes * 60 * 1000);
|
// long lastGoodPlus = getLastGoodReceiverCommunicationTime() + (receiverDeviceAwakeForMinutes * 60 * 1000);
|
||||||
|
@ -233,8 +226,7 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
|
|
||||||
|
|
||||||
public double scanForDevice(double[] frequencies) {
|
public double scanForDevice(double[] frequencies) {
|
||||||
if (isLogEnabled())
|
aapsLogger.info(LTag.PUMPBTCOMM, "Scanning for receiver ({})", receiverDeviceID);
|
||||||
LOG.info("Scanning for receiver ({})", receiverDeviceID);
|
|
||||||
wakeUp(receiverDeviceAwakeForMinutes, false);
|
wakeUp(receiverDeviceAwakeForMinutes, false);
|
||||||
FrequencyScanResults results = new FrequencyScanResults();
|
FrequencyScanResults results = new FrequencyScanResults();
|
||||||
|
|
||||||
|
@ -251,7 +243,7 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
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]);
|
aapsLogger.error(LTag.PUMPBTCOMM, "scanForPump: Failed to find pump at frequency {}", frequencies[i]);
|
||||||
} else if (resp.looksLikeRadioPacket()) {
|
} else if (resp.looksLikeRadioPacket()) {
|
||||||
RadioResponse radioResponse = new RadioResponse();
|
RadioResponse radioResponse = new RadioResponse();
|
||||||
|
|
||||||
|
@ -265,17 +257,17 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
trial.rssiList.add(rssi);
|
trial.rssiList.add(rssi);
|
||||||
trial.successes++;
|
trial.successes++;
|
||||||
} else {
|
} 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);
|
trial.rssiList.add(-99);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (RileyLinkCommunicationException rle) {
|
} 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);
|
trial.rssiList.add(-99);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} 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.rssiList.add(-99);
|
||||||
}
|
}
|
||||||
trial.tries++;
|
trial.tries++;
|
||||||
|
@ -299,7 +291,7 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
+ one.frequencyMHz, "" + one.averageRSSI + ", RSSIs =" + one.rssiList));
|
+ one.frequencyMHz, "" + one.averageRSSI + ", RSSIs =" + one.rssiList));
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.info(stringBuilder.toString());
|
aapsLogger.info(LTag.PUMPCOMM, stringBuilder.toString());
|
||||||
|
|
||||||
results.sort(); // sorts in ascending order
|
results.sort(); // sorts in ascending order
|
||||||
|
|
||||||
|
@ -307,11 +299,10 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
results.bestFrequencyMHz = bestTrial.frequencyMHz;
|
results.bestFrequencyMHz = bestTrial.frequencyMHz;
|
||||||
if (bestTrial.successes > 0) {
|
if (bestTrial.successes > 0) {
|
||||||
rfspy.setBaseFrequency(results.bestFrequencyMHz);
|
rfspy.setBaseFrequency(results.bestFrequencyMHz);
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Best frequency found: " + results.bestFrequencyMHz);
|
||||||
LOG.debug("Best frequency found: " + results.bestFrequencyMHz);
|
|
||||||
return results.bestFrequencyMHz;
|
return results.bestFrequencyMHz;
|
||||||
} else {
|
} else {
|
||||||
LOG.error("No pump response during scan.");
|
aapsLogger.error(LTag.PUMPBTCOMM, "No pump response during scan.");
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -340,22 +331,22 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
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);
|
aapsLogger.warn(LTag.PUMPBTCOMM, "tune_tryFrequency: no pump response at frequency {}", freqMHz);
|
||||||
} else if (resp.looksLikeRadioPacket()) {
|
} else if (resp.looksLikeRadioPacket()) {
|
||||||
RadioResponse radioResponse = new RadioResponse();
|
RadioResponse radioResponse = new RadioResponse();
|
||||||
try {
|
try {
|
||||||
radioResponse.init(resp.getRaw());
|
radioResponse.init(resp.getRaw());
|
||||||
|
|
||||||
if (radioResponse.isValid()) {
|
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);
|
return calculateRssi(radioResponse.rssi);
|
||||||
} else {
|
} else {
|
||||||
LOG.warn("tune_tryFrequency: invalid radio response:"
|
aapsLogger.warn(LTag.PUMPBTCOMM, "tune_tryFrequency: invalid radio response:"
|
||||||
+ ByteUtil.shortHexString(radioResponse.getPayload()));
|
+ ByteUtil.shortHexString(radioResponse.getPayload()));
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (RileyLinkCommunicationException e) {
|
} 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) {
|
if (betterFrequency == 0.0) {
|
||||||
// we've failed... caller should try a full scan for pump
|
// we've failed... caller should try a full scan for pump
|
||||||
if (isLogEnabled())
|
aapsLogger.error(LTag.PUMPBTCOMM, "quickTuneForPump: failed to find pump");
|
||||||
LOG.error("quickTuneForPump: failed to find pump");
|
|
||||||
} else {
|
} else {
|
||||||
rfspy.setBaseFrequency(betterFrequency);
|
rfspy.setBaseFrequency(betterFrequency);
|
||||||
if (betterFrequency != startFrequencyMHz) {
|
if (betterFrequency != startFrequencyMHz) {
|
||||||
if (isLogEnabled())
|
aapsLogger.info(LTag.PUMPBTCOMM, "quickTuneForPump: new frequency is {}MHz", betterFrequency);
|
||||||
LOG.info("quickTuneForPump: new frequency is {}MHz", betterFrequency);
|
|
||||||
} else {
|
} else {
|
||||||
if (isLogEnabled())
|
aapsLogger.info(LTag.PUMPBTCOMM, "quickTuneForPump: pump frequency is the same: {}MHz", startFrequencyMHz);
|
||||||
LOG.info("quickTuneForPump: pump frequency is the same: {}MHz", startFrequencyMHz);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return betterFrequency;
|
return betterFrequency;
|
||||||
|
@ -399,8 +387,7 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
|
|
||||||
|
|
||||||
private double quickTunePumpStep(double startFrequencyMHz, double stepSizeMHz) {
|
private double quickTunePumpStep(double startFrequencyMHz, double stepSizeMHz) {
|
||||||
if (isLogEnabled())
|
aapsLogger.info(LTag.PUMPBTCOMM, "Doing quick radio tune for receiver ({})", receiverDeviceID);
|
||||||
LOG.info("Doing quick radio tune for receiver ({})", receiverDeviceID);
|
|
||||||
wakeUp(false);
|
wakeUp(false);
|
||||||
int startRssi = tune_tryFrequency(startFrequencyMHz);
|
int startRssi = tune_tryFrequency(startFrequencyMHz);
|
||||||
double lowerFrequency = startFrequencyMHz - stepSizeMHz;
|
double lowerFrequency = startFrequencyMHz - stepSizeMHz;
|
||||||
|
@ -438,8 +425,7 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
// 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);
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Last good pump communication was " + minutesAgo + " minutes ago.");
|
||||||
LOG.trace("Last good pump communication was " + minutesAgo + " minutes ago.");
|
|
||||||
return lastGoodReceiverCommunicationTime;
|
return lastGoodReceiverCommunicationTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,9 +435,7 @@ public abstract class RileyLinkCommunicationManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isLogEnabled() {
|
|
||||||
return L.isEnabled(L.PUMPCOMM);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract PumpStatus getPumpStatus();
|
public abstract PumpStatus getPumpStatus();
|
||||||
|
|
||||||
|
public abstract boolean isDeviceReachable();
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,17 +190,6 @@ public class RileyLinkUtil {
|
||||||
this.rileyLinkService = rileyLinkService;
|
this.rileyLinkService = rileyLinkService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public RileyLinkCommunicationManager getRileyLinkCommunicationManager() {
|
|
||||||
return rileyLinkCommunicationManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void setRileyLinkCommunicationManager(RileyLinkCommunicationManager rileyLinkCommunicationManager) {
|
|
||||||
this.rileyLinkCommunicationManager = rileyLinkCommunicationManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean sendNotification(ServiceNotification notification, Integer clientHashcode) {
|
public static boolean sendNotification(ServiceNotification notification, Integer clientHashcode) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,6 @@ public abstract class RileyLinkService extends DaggerService {
|
||||||
|
|
||||||
public abstract RileyLinkCommunicationManager getDeviceCommunicationManager();
|
public abstract RileyLinkCommunicationManager getDeviceCommunicationManager();
|
||||||
|
|
||||||
|
|
||||||
// Here is where the wake-lock begins:
|
// Here is where the wake-lock begins:
|
||||||
// We've received a service startCommand, we grab the lock.
|
// We've received a service startCommand, we grab the lock.
|
||||||
@Override
|
@Override
|
||||||
|
@ -236,7 +235,7 @@ public abstract class RileyLinkService extends DaggerService {
|
||||||
// error tuning pump, pump not present ??
|
// error tuning pump, pump not present ??
|
||||||
rileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorError, RileyLinkError.TuneUpOfDeviceFailed);
|
rileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorError, RileyLinkError.TuneUpOfDeviceFailed);
|
||||||
} else {
|
} else {
|
||||||
rileyLinkUtil.getRileyLinkCommunicationManager().clearNotConnectedCount();
|
getDeviceCommunicationManager().clearNotConnectedCount();
|
||||||
rileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorReady);
|
rileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorReady);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,14 @@ package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.task
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector;
|
import dagger.android.HasAndroidInjector;
|
||||||
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
|
||||||
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.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.RileyLinkConst;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
|
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 {
|
public class InitializePumpManagerTask extends ServiceTask {
|
||||||
|
|
||||||
|
@Inject ActivePluginProvider activePlugin;
|
||||||
|
|
||||||
private static final String TAG = "InitPumpManagerTask";
|
private static final String TAG = "InitPumpManagerTask";
|
||||||
private RileyLinkTargetDevice targetDevice;
|
private RileyLinkTargetDevice targetDevice;
|
||||||
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
|
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
|
||||||
|
@ -54,17 +61,19 @@ public class InitializePumpManagerTask extends ServiceTask {
|
||||||
lastGoodFrequency = RileyLinkUtil.getInstance().getRileyLinkServiceData().lastGoodFrequency;
|
lastGoodFrequency = RileyLinkUtil.getInstance().getRileyLinkServiceData().lastGoodFrequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RileyLinkCommunicationManager rileyLinkCommunicationManager = ((PumpPluginAbstract)activePlugin.getActivePump()).getRileyLinkService().getDeviceCommunicationManager();
|
||||||
|
|
||||||
if ((lastGoodFrequency > 0.0d)
|
if ((lastGoodFrequency > 0.0d)
|
||||||
&& RileyLinkUtil.getInstance().getRileyLinkCommunicationManager().isValidFrequency(lastGoodFrequency)) {
|
&& rileyLinkCommunicationManager.isValidFrequency(lastGoodFrequency)) {
|
||||||
|
|
||||||
RileyLinkUtil.getInstance().setServiceState(RileyLinkServiceState.RileyLinkReady);
|
RileyLinkUtil.getInstance().setServiceState(RileyLinkServiceState.RileyLinkReady);
|
||||||
|
|
||||||
if (L.isEnabled(L.PUMPCOMM))
|
if (L.isEnabled(L.PUMPCOMM))
|
||||||
LOG.info("Setting radio frequency to {} MHz", lastGoodFrequency);
|
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) {
|
if (foundThePump) {
|
||||||
RileyLinkUtil.getInstance().setServiceState(RileyLinkServiceState.PumpConnectorReady);
|
RileyLinkUtil.getInstance().setServiceState(RileyLinkServiceState.PumpConnectorReady);
|
||||||
|
|
|
@ -110,7 +110,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
private Map<MedtronicStatusRefreshType, Long> statusRefreshMap = new HashMap<>();
|
private Map<MedtronicStatusRefreshType, Long> statusRefreshMap = new HashMap<>();
|
||||||
private boolean isInitialized = false;
|
private boolean isInitialized = false;
|
||||||
private MedtronicHistoryData medtronicHistoryData;
|
private MedtronicHistoryData medtronicHistoryData;
|
||||||
private MedtronicCommunicationManager medtronicCommunicationManager;
|
|
||||||
private PumpHistoryEntry lastPumpHistoryEntry;
|
private PumpHistoryEntry lastPumpHistoryEntry;
|
||||||
|
|
||||||
public static boolean isBusy = false;
|
public static boolean isBusy = false;
|
||||||
|
@ -316,9 +315,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
return rileyLinkMedtronicService != null;
|
return rileyLinkMedtronicService != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public RileyLinkMedtronicService getRileyLinkMedtronicService() {
|
public RileyLinkMedtronicService getRileyLinkService() {
|
||||||
return rileyLinkMedtronicService;
|
return rileyLinkMedtronicService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -432,7 +430,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
return false;
|
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");
|
aapsLogger.info(LTag.PUMP, getLogPrefix() + "initializePump - start");
|
||||||
|
|
||||||
if (medtronicCommunicationManager == null) {
|
rileyLinkMedtronicService.getDeviceCommunicationManager().setDoWakeUpBeforeCommand(false);
|
||||||
medtronicCommunicationManager = MedtronicCommunicationManager.getInstance();
|
|
||||||
medtronicCommunicationManager.setDoWakeUpBeforeCommand(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
setRefreshButtonEnabled(false);
|
setRefreshButtonEnabled(false);
|
||||||
|
|
||||||
|
@ -633,11 +628,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
return isProfileSame(profile);
|
return isProfileSame(profile);
|
||||||
} else if (medtronicPumpStatus.basalProfileStatus == BasalProfileStatus.ProfileChanged) {
|
} else if (medtronicPumpStatus.basalProfileStatus == BasalProfileStatus.ProfileChanged) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return (medtronicPumpStatus.basalProfileStatus != BasalProfileStatus.ProfileOK) || isProfileSame(profile);
|
return (medtronicPumpStatus.basalProfileStatus != BasalProfileStatus.ProfileOK) || isProfileSame(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,10 +62,10 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
|
|
||||||
@Inject MedtronicPumpStatus medtronicPumpStatus;
|
@Inject MedtronicPumpStatus medtronicPumpStatus;
|
||||||
|
|
||||||
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
|
private final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
|
||||||
private static final int MAX_COMMAND_TRIES = 3;
|
private final int MAX_COMMAND_TRIES = 3;
|
||||||
private static final int DEFAULT_TIMEOUT = 2000;
|
private final int DEFAULT_TIMEOUT = 2000;
|
||||||
private static final long RILEYLINK_TIMEOUT = 15 * 60 * 1000; // 15 min
|
private final long RILEYLINK_TIMEOUT = 15 * 60 * 1000; // 15 min
|
||||||
|
|
||||||
static MedtronicCommunicationManager medtronicCommunicationManager;
|
static MedtronicCommunicationManager medtronicCommunicationManager;
|
||||||
String errorMessage;
|
String errorMessage;
|
||||||
|
@ -102,6 +102,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isDeviceReachable() {
|
public boolean isDeviceReachable() {
|
||||||
return isDeviceReachable(false);
|
return isDeviceReachable(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,13 +8,11 @@ import javax.inject.Singleton;
|
||||||
import dagger.android.HasAndroidInjector;
|
import dagger.android.HasAndroidInjector;
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
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.RileyLinkConst;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager;
|
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.defs.MedtronicCommandType;
|
||||||
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 6/14/18.
|
* Created by andy on 6/14/18.
|
||||||
|
@ -32,13 +30,11 @@ public class MedtronicUIComm {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public MedtronicUIComm(
|
public MedtronicUIComm(
|
||||||
HasAndroidInjector injector,
|
@NotNull HasAndroidInjector injector,
|
||||||
AAPSLogger aapsLogger,
|
@NotNull AAPSLogger aapsLogger,
|
||||||
RxBusWrapper rxBus,
|
@NotNull RileyLinkUtil rileyLinkUtil,
|
||||||
ResourceHelper resourceHelper,
|
@NotNull MedtronicUtil medtronicUtil,
|
||||||
RileyLinkUtil rileyLinkUtil,
|
@NotNull MedtronicUIPostprocessor medtronicUIPostprocessor
|
||||||
MedtronicUtil medtronicUtil,
|
|
||||||
MedtronicUIPostprocessor medtronicUIPostprocessor
|
|
||||||
) {
|
) {
|
||||||
this.injector = injector;
|
this.injector = injector;
|
||||||
this.aapsLogger = aapsLogger;
|
this.aapsLogger = aapsLogger;
|
||||||
|
|
|
@ -98,8 +98,7 @@ public class RileyLinkMedtronicService extends RileyLinkService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
public MedtronicCommunicationManager getDeviceCommunicationManager() {
|
||||||
public RileyLinkCommunicationManager getDeviceCommunicationManager() {
|
|
||||||
return this.medtronicCommunicationManager;
|
return this.medtronicCommunicationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue