MDT refactor pass 2

This commit is contained in:
Milos Kozak 2020-04-26 22:47:13 +02:00
parent c0f6f1a5e9
commit 0d063ca73f
19 changed files with 137 additions and 86 deletions

View file

@ -29,6 +29,7 @@ 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.service.tasks.*
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.*
@ -185,6 +186,14 @@ interface AppComponent : AndroidInjector<MainApp> {
fun injectGraphData(graphData: GraphData) fun injectGraphData(graphData: GraphData)
//Medtronic
fun injectServiceTask(serviceTask: ServiceTask)
fun injectPumpTask(pumpTask: PumpTask)
fun injectDiscoverGattServicesTask(discoverGattServicesTask: DiscoverGattServicesTask)
fun injectInitializePumpManagerTask(initializePumpManagerTask: InitializePumpManagerTask)
fun injectResetRileyLinkConfigurationTask(resetRileyLinkConfigurationTask: ResetRileyLinkConfigurationTask)
fun injectWakeAndTuneTask(wakeAndTuneTask: WakeAndTuneTask)
@Component.Builder @Component.Builder
interface Builder { interface Builder {

View file

@ -46,6 +46,7 @@ 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.service.tasks.*
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.*
@ -278,6 +279,14 @@ open class AppModule {
@Binds fun bindContext(mainApp: MainApp): Context @Binds fun bindContext(mainApp: MainApp): Context
@Binds fun bindInjector(mainApp: MainApp): HasAndroidInjector @Binds fun bindInjector(mainApp: MainApp): HasAndroidInjector
// Medtronic
@ContributesAndroidInjector fun serviceTaskProvider(): ServiceTask
@ContributesAndroidInjector fun pumpTaskProvider(): PumpTask
@ContributesAndroidInjector fun discoverGattServicesTaskProvider(): DiscoverGattServicesTask
@ContributesAndroidInjector fun initializePumpManagerTaskProvider(): InitializePumpManagerTask
@ContributesAndroidInjector fun resetRileyLinkConfigurationTaskProvider(): ResetRileyLinkConfigurationTask
@ContributesAndroidInjector fun wakeAndTuneTaskProvider(): WakeAndTuneTask
@Binds @Binds
fun bindActivePluginProvider(pluginStore: PluginStore): ActivePluginProvider fun bindActivePluginProvider(pluginStore: PluginStore): ActivePluginProvider

View file

@ -109,7 +109,8 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
public abstract void initPumpStatusData(); public abstract void initPumpStatusData();
public abstract void resetRileyLinkConfiguration();
public abstract void doTuneUpDevice();
@Override @Override
protected void onStart() { protected void onStart() {
@ -125,7 +126,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
disposable.add(rxBus disposable.add(rxBus
.toObservable(EventAppExit.class) .toObservable(EventAppExit.class)
.observeOn(Schedulers.io()) .observeOn(Schedulers.io())
.subscribe(event -> context.unbindService(serviceConnection), exception -> fabricPrivacy.logException(exception)) .subscribe(event -> context.unbindService(serviceConnection), fabricPrivacy::logException)
); );
onStartCustomActions(); onStartCustomActions();
} }

View file

@ -1,13 +1,11 @@
package info.nightscout.androidaps.plugins.pump.common.data; package info.nightscout.androidaps.plugins.pump.common.data;
import org.joda.time.LocalDateTime;
import java.util.Date; import java.util.Date;
import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpStatusType; import info.nightscout.androidaps.plugins.pump.common.defs.PumpStatusType;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.utils.DateUtil;
/** /**
* Created by andy on 4/28/18. * Created by andy on 4/28/18.
@ -16,7 +14,7 @@ import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
public abstract class PumpStatus { public abstract class PumpStatus {
// connection // connection
public LocalDateTime lastDataTime; public long lastDataTime;
public long lastConnection = 0L; public long lastConnection = 0L;
public long previousConnection = 0L; // here should be stored last connection of previous session (so needs to be public long previousConnection = 0L; // here should be stored last connection of previous session (so needs to be
// read before lastConnection is modified for first time). // read before lastConnection is modified for first time).
@ -63,10 +61,8 @@ public abstract class PumpStatus {
} }
public void setLastCommunicationToNow() { public void setLastCommunicationToNow() {
this.lastDataTime = LocalDateTime.now(); this.lastDataTime = DateUtil.now();
this.lastConnection = System.currentTimeMillis(); this.lastConnection = System.currentTimeMillis();
} }

View file

@ -3,6 +3,9 @@ package info.nightscout.androidaps.plugins.pump.common.hw.rileylink;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
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.pump.common.data.PumpStatus; import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
@ -36,6 +39,7 @@ public abstract class RileyLinkCommunicationManager {
private static final int SCAN_TIMEOUT = 1500; private static final int SCAN_TIMEOUT = 1500;
private static final int ALLOWED_PUMP_UNREACHABLE = 10 * 60 * 1000; // 10 minutes private static final int ALLOWED_PUMP_UNREACHABLE = 10 * 60 * 1000; // 10 minutes
protected final HasAndroidInjector injector;
protected final RFSpy rfspy; protected final RFSpy rfspy;
protected int receiverDeviceAwakeForMinutes = 1; // override this in constructor of specific implementation protected int receiverDeviceAwakeForMinutes = 1; // override this in constructor of specific implementation
protected String receiverDeviceID; // String representation of receiver device (ex. Pump (xxxxxx) or Pod (yyyyyy)) protected String receiverDeviceID; // String representation of receiver device (ex. Pump (xxxxxx) or Pod (yyyyyy))
@ -49,7 +53,8 @@ public abstract class RileyLinkCommunicationManager {
private int timeoutCount = 0; private int timeoutCount = 0;
public RileyLinkCommunicationManager(RFSpy rfspy) { public RileyLinkCommunicationManager(HasAndroidInjector injector, RFSpy rfspy) {
this.injector = injector;
this.rfspy = rfspy; this.rfspy = rfspy;
this.rileyLinkServiceData = RileyLinkUtil.getInstance().getRileyLinkServiceData(); this.rileyLinkServiceData = RileyLinkUtil.getInstance().getRileyLinkServiceData();
RileyLinkUtil.getInstance().setRileyLinkCommunicationManager(this); RileyLinkUtil.getInstance().setRileyLinkCommunicationManager(this);
@ -107,7 +112,7 @@ public abstract class RileyLinkCommunicationManager {
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.");
ServiceTaskExecutor.startTask(new WakeAndTuneTask()); ServiceTaskExecutor.startTask(new WakeAndTuneTask(injector));
timeoutCount = 0; timeoutCount = 0;
} }
} }

View file

@ -21,6 +21,7 @@ import java.util.Map;
import javax.inject.Inject; import javax.inject.Inject;
import dagger.android.DaggerBroadcastReceiver; import dagger.android.DaggerBroadcastReceiver;
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.hw.rileylink.RileyLinkConst; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
@ -42,6 +43,7 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
*/ */
public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver { public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
@Inject HasAndroidInjector injector;
@Inject RileyLinkUtil rileyLinkUtil; @Inject RileyLinkUtil rileyLinkUtil;
@Inject SP sp; @Inject SP sp;
@ -171,7 +173,7 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
LOG.debug("RfSpy Radio version (CC110): " + rlVersion.name()); LOG.debug("RfSpy Radio version (CC110): " + rlVersion.name());
this.serviceInstance.rileyLinkServiceData.versionCC110 = rlVersion; this.serviceInstance.rileyLinkServiceData.versionCC110 = rlVersion;
ServiceTask task = new InitializePumpManagerTask(rileyLinkUtil.getTargetDevice()); ServiceTask task = new InitializePumpManagerTask(injector, rileyLinkUtil.getTargetDevice());
ServiceTaskExecutor.startTask(task); ServiceTaskExecutor.startTask(task);
if (isLoggingEnabled()) if (isLoggingEnabled())
LOG.info("Announcing RileyLink open For business"); LOG.info("Announcing RileyLink open For business");
@ -205,7 +207,7 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
if (action.equals(RileyLinkConst.Intents.BluetoothConnected)) { if (action.equals(RileyLinkConst.Intents.BluetoothConnected)) {
if (isLoggingEnabled()) if (isLoggingEnabled())
LOG.debug("Bluetooth - Connected"); LOG.debug("Bluetooth - Connected");
ServiceTaskExecutor.startTask(new DiscoverGattServicesTask()); ServiceTaskExecutor.startTask(new DiscoverGattServicesTask(injector));
return true; return true;
@ -214,7 +216,7 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
LOG.debug("Bluetooth - Reconnecting"); LOG.debug("Bluetooth - Reconnecting");
serviceInstance.bluetoothInit(); serviceInstance.bluetoothInit();
ServiceTaskExecutor.startTask(new DiscoverGattServicesTask(true)); ServiceTaskExecutor.startTask(new DiscoverGattServicesTask(injector, true));
return true; return true;
} else { } else {
@ -229,7 +231,7 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
if (this.broadcastIdentifiers.get("TuneUp").contains(action)) { if (this.broadcastIdentifiers.get("TuneUp").contains(action)) {
if (serviceInstance.getRileyLinkTargetDevice().isTuneUpEnabled()) { if (serviceInstance.getRileyLinkTargetDevice().isTuneUpEnabled()) {
ServiceTaskExecutor.startTask(new WakeAndTuneTask()); ServiceTaskExecutor.startTask(new WakeAndTuneTask(injector));
} }
return true; return true;
} else { } else {

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks; package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
/** /**
@ -10,11 +11,13 @@ public class DiscoverGattServicesTask extends ServiceTask {
public boolean needToConnect = false; public boolean needToConnect = false;
public DiscoverGattServicesTask() { public DiscoverGattServicesTask(HasAndroidInjector injector) {
super(injector);
} }
public DiscoverGattServicesTask(boolean needToConnect) { public DiscoverGattServicesTask(HasAndroidInjector injector, boolean needToConnect) {
super(injector);
this.needToConnect = needToConnect; this.needToConnect = needToConnect;
} }

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.task
import org.slf4j.Logger; import org.slf4j.Logger;
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.hw.rileylink.RileyLinkConst; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
@ -23,14 +24,14 @@ public class InitializePumpManagerTask extends ServiceTask {
private RileyLinkTargetDevice targetDevice; private RileyLinkTargetDevice targetDevice;
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM); private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
public InitializePumpManagerTask(RileyLinkTargetDevice targetDevice) { public InitializePumpManagerTask(HasAndroidInjector injector, RileyLinkTargetDevice targetDevice) {
super(); super(injector);
this.targetDevice = targetDevice; this.targetDevice = targetDevice;
} }
public InitializePumpManagerTask(ServiceTransport transport) { public InitializePumpManagerTask(HasAndroidInjector injector, ServiceTransport transport) {
super(transport); super(injector, transport);
} }

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks; package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceTransport; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceTransport;
/** /**
@ -7,12 +8,12 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.
*/ */
public class PumpTask extends ServiceTask { public class PumpTask extends ServiceTask {
public PumpTask() { public PumpTask(HasAndroidInjector injector) {
super(); super(injector);
} }
public PumpTask(ServiceTransport transport) { public PumpTask(HasAndroidInjector injector, ServiceTransport transport) {
super(transport); super(injector, transport);
} }
} }

View file

@ -1,6 +1,13 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks; package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks;
import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceTransport; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceTransport;
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin; import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventRefreshButtonState; import info.nightscout.androidaps.plugins.pump.medtronic.events.EventRefreshButtonState;
@ -11,25 +18,30 @@ import info.nightscout.androidaps.plugins.pump.medtronic.service.RileyLinkMedtro
*/ */
public class ResetRileyLinkConfigurationTask extends PumpTask { public class ResetRileyLinkConfigurationTask extends PumpTask {
@Inject ActivePluginProvider activePlugin;
@Inject RxBusWrapper rxBus;
private static final String TAG = "ResetRileyLinkTask"; private static final String TAG = "ResetRileyLinkTask";
public ResetRileyLinkConfigurationTask() { public ResetRileyLinkConfigurationTask(HasAndroidInjector injector) {
super(injector);
} }
public ResetRileyLinkConfigurationTask(ServiceTransport transport) { public ResetRileyLinkConfigurationTask(HasAndroidInjector injector, ServiceTransport transport) {
super(transport); super(injector, transport);
} }
@Override @Override
public void run() { public void run() {
RxBus.Companion.getINSTANCE().send(new EventRefreshButtonState(false)); PumpPluginAbstract pump = (PumpPluginAbstract) activePlugin.getActivePump();
rxBus.send(new EventRefreshButtonState(false));
MedtronicPumpPlugin.isBusy = true; MedtronicPumpPlugin.isBusy = true;
RileyLinkMedtronicService.getInstance().resetRileyLinkConfiguration(); pump.resetRileyLinkConfiguration();
MedtronicPumpPlugin.isBusy = false; MedtronicPumpPlugin.isBusy = false;
RxBus.Companion.getINSTANCE().send(new EventRefreshButtonState(true)); rxBus.send(new EventRefreshButtonState(true));
} }
} }

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks; package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceTransport; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceTransport;
/** /**
@ -10,14 +11,19 @@ public class ServiceTask implements Runnable {
private static final String TAG = "ServiceTask(base)"; private static final String TAG = "ServiceTask(base)";
public boolean completed = false; public boolean completed = false;
protected ServiceTransport mTransport; protected ServiceTransport mTransport;
protected HasAndroidInjector injector;
public ServiceTask() { public ServiceTask(HasAndroidInjector injector) {
this.injector = injector;
injector.androidInjector().inject(this);
init(new ServiceTransport()); init(new ServiceTransport());
} }
public ServiceTask(ServiceTransport transport) { public ServiceTask(HasAndroidInjector injector, ServiceTransport transport) {
this.injector = injector;
injector.androidInjector().inject(this);
init(transport); init(transport);
} }

View file

@ -1,6 +1,12 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks; package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks;
import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceTransport; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceTransport;
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin; import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventRefreshButtonState; import info.nightscout.androidaps.plugins.pump.medtronic.events.EventRefreshButtonState;
@ -11,24 +17,29 @@ import info.nightscout.androidaps.plugins.pump.medtronic.service.RileyLinkMedtro
*/ */
public class WakeAndTuneTask extends PumpTask { public class WakeAndTuneTask extends PumpTask {
@Inject ActivePluginProvider activePlugin;
@Inject RxBusWrapper rxBus;
private static final String TAG = "WakeAndTuneTask"; private static final String TAG = "WakeAndTuneTask";
public WakeAndTuneTask() { public WakeAndTuneTask(HasAndroidInjector injector) {
super(injector);
} }
public WakeAndTuneTask(ServiceTransport transport) { public WakeAndTuneTask(HasAndroidInjector injector, ServiceTransport transport) {
super(transport); super(injector, transport);
} }
@Override @Override
public void run() { public void run() {
RxBus.Companion.getINSTANCE().send(new EventRefreshButtonState(false)); PumpPluginAbstract pump = (PumpPluginAbstract) activePlugin.getActivePump();
rxBus.send(new EventRefreshButtonState(false));
MedtronicPumpPlugin.isBusy = true; MedtronicPumpPlugin.isBusy = true;
RileyLinkMedtronicService.getInstance().doTuneUpDevice(); pump.doTuneUpDevice();
MedtronicPumpPlugin.isBusy = false; MedtronicPumpPlugin.isBusy = false;
RxBus.Companion.getINSTANCE().send(new EventRefreshButtonState(true)); rxBus.send(new EventRefreshButtonState(true));
} }
} }

View file

@ -8,6 +8,7 @@ import android.os.IBinder;
import android.os.SystemClock; import android.os.SystemClock;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.joda.time.LocalDateTime; import org.joda.time.LocalDateTime;
@ -100,7 +101,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
private final MedtronicPumpStatus medtronicPumpStatus; private final MedtronicPumpStatus medtronicPumpStatus;
protected static MedtronicPumpPlugin plugin = null; protected static MedtronicPumpPlugin plugin = null;
private RileyLinkMedtronicService medtronicService; private RileyLinkMedtronicService rileyLinkMedtronicService;
private MedtronicUIComm medtronicUIComm; private MedtronicUIComm medtronicUIComm;
// variables for handling statuses and history // variables for handling statuses and history
@ -156,13 +157,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
public void onServiceDisconnected(ComponentName name) { public void onServiceDisconnected(ComponentName name) {
aapsLogger.debug(LTag.PUMP, "RileyLinkMedtronicService is disconnected"); aapsLogger.debug(LTag.PUMP, "RileyLinkMedtronicService is disconnected");
medtronicService = null; rileyLinkMedtronicService = null;
} }
public void onServiceConnected(ComponentName name, IBinder service) { public void onServiceConnected(ComponentName name, IBinder service) {
aapsLogger.debug(LTag.PUMP, "RileyLinkMedtronicService is connected"); aapsLogger.debug(LTag.PUMP, "RileyLinkMedtronicService is connected");
RileyLinkMedtronicService.LocalBinder mLocalBinder = (RileyLinkMedtronicService.LocalBinder) service; RileyLinkMedtronicService.LocalBinder mLocalBinder = (RileyLinkMedtronicService.LocalBinder) service;
medtronicService = mLocalBinder.getServiceInstance(); rileyLinkMedtronicService = mLocalBinder.getServiceInstance();
new Thread(() -> { new Thread(() -> {
@ -213,7 +214,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
medtronicUtil.setPumpStatus(medtronicPumpStatus); medtronicUtil.setPumpStatus(medtronicPumpStatus);
medtronicPumpStatus.lastConnection = sp.getLong(RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L); medtronicPumpStatus.lastConnection = sp.getLong(RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
medtronicPumpStatus.lastDataTime = new LocalDateTime(medtronicPumpStatus.lastConnection); medtronicPumpStatus.lastDataTime = medtronicPumpStatus.lastConnection;
medtronicPumpStatus.previousConnection = medtronicPumpStatus.lastConnection; medtronicPumpStatus.previousConnection = medtronicPumpStatus.lastConnection;
medtronicPumpStatus.refreshConfiguration(); medtronicPumpStatus.refreshConfiguration();
@ -234,6 +235,15 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
} }
@Override
public void resetRileyLinkConfiguration() {
rileyLinkMedtronicService.resetRileyLinkConfiguration();
}
@Override public void doTuneUpDevice() {
rileyLinkMedtronicService.doTuneUpDevice();
}
private void migrateSettings() { private void migrateSettings() {
if ("US (916 MHz)".equals(sp.getString(MedtronicConst.Prefs.PumpFrequency, "US (916 MHz)"))) { if ("US (916 MHz)".equals(sp.getString(MedtronicConst.Prefs.PumpFrequency, "US (916 MHz)"))) {
@ -306,9 +316,14 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
// Pump Plugin // Pump Plugin
private boolean isServiceSet() { private boolean isServiceSet() {
return medtronicService != null; return rileyLinkMedtronicService != null;
} }
@Deprecated
@Nullable
public RileyLinkMedtronicService getRileyLinkMedtronicService() {
return rileyLinkMedtronicService;
}
@Override @Override
public boolean isInitialized() { public boolean isInitialized() {
@ -373,7 +388,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
public boolean isConnected() { public boolean isConnected() {
if (displayConnectionMessages) if (displayConnectionMessages)
aapsLogger.debug(LTag.PUMP, "MedtronicPumpPlugin::isConnected"); aapsLogger.debug(LTag.PUMP, "MedtronicPumpPlugin::isConnected");
return isServiceSet() && medtronicService.isInitialized(); return isServiceSet() && rileyLinkMedtronicService.isInitialized();
} }
@ -381,7 +396,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
public boolean isConnecting() { public boolean isConnecting() {
if (displayConnectionMessages) if (displayConnectionMessages)
aapsLogger.debug(LTag.PUMP, "MedtronicPumpPlugin::isConnecting"); aapsLogger.debug(LTag.PUMP, "MedtronicPumpPlugin::isConnecting");
return !isServiceSet() || !medtronicService.isInitialized(); return !isServiceSet() || !rileyLinkMedtronicService.isInitialized();
} }
@ -581,7 +596,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
if (errorCount >= 5) { if (errorCount >= 5) {
aapsLogger.error("Number of error counts was 5 or more. Starting tunning."); aapsLogger.error("Number of error counts was 5 or more. Starting tunning.");
setRefreshButtonEnabled(true); setRefreshButtonEnabled(true);
ServiceTaskExecutor.startTask(new WakeAndTuneTask()); ServiceTaskExecutor.startTask(new WakeAndTuneTask(getInjector()));
return; return;
} }
@ -1518,7 +1533,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
case WakeUpAndTune: { case WakeUpAndTune: {
if (medtronicUtil.getPumpStatus().verifyConfiguration()) { if (medtronicUtil.getPumpStatus().verifyConfiguration()) {
ServiceTaskExecutor.startTask(new WakeAndTuneTask()); ServiceTaskExecutor.startTask(new WakeAndTuneTask(getInjector()));
} else { } else {
Intent i = new Intent(context, ErrorHelperActivity.class); Intent i = new Intent(context, ErrorHelperActivity.class);
i.putExtra("soundid", R.raw.boluserror); i.putExtra("soundid", R.raw.boluserror);
@ -1538,7 +1553,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
break; break;
case ResetRileyLinkConfiguration: { case ResetRileyLinkConfiguration: {
ServiceTaskExecutor.startTask(new ResetRileyLinkConfigurationTask()); ServiceTaskExecutor.startTask(new ResetRileyLinkConfigurationTask(getInjector()));
} }
break; break;
@ -1557,7 +1572,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
} }
public void setEnableCustomAction(MedtronicCustomActionType customAction, boolean isEnabled) { private void setEnableCustomAction(MedtronicCustomActionType customAction, boolean isEnabled) {
if (customAction == MedtronicCustomActionType.ClearBolusBlock) { if (customAction == MedtronicCustomActionType.ClearBolusBlock) {
this.customActionClearBolusBlock.setEnabled(isEnabled); this.customActionClearBolusBlock.setEnabled(isEnabled);

View file

@ -10,6 +10,7 @@ import java.util.GregorianCalendar;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
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.hw.rileylink.RileyLinkCommunicationManager; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager;
@ -70,8 +71,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
private boolean doWakeUpBeforeCommand = true; private boolean doWakeUpBeforeCommand = true;
public MedtronicCommunicationManager(RFSpy rfspy) { public MedtronicCommunicationManager(HasAndroidInjector injector, RFSpy rfspy) {
super(rfspy); super(injector, rfspy);
medtronicCommunicationManager = this; medtronicCommunicationManager = this;
this.medtronicConverter = new MedtronicConverter(); this.medtronicConverter = new MedtronicConverter();
this.pumpHistoryDecoder = new MedtronicPumpHistoryDecoder(); this.pumpHistoryDecoder = new MedtronicPumpHistoryDecoder();
@ -143,7 +144,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
long diff = System.currentTimeMillis() - MedtronicUtil.getInstance().getPumpStatus().lastConnection; long diff = System.currentTimeMillis() - MedtronicUtil.getInstance().getPumpStatus().lastConnection;
if (diff > RILEYLINK_TIMEOUT) { if (diff > RILEYLINK_TIMEOUT) {
ServiceTaskExecutor.startTask(new WakeAndTuneTask()); ServiceTaskExecutor.startTask(new WakeAndTuneTask(injector));
} }
} }

View file

@ -112,7 +112,7 @@ public class MedtronicPumpStatus extends PumpStatus {
createMedtronicDeviceTypeMap(); createMedtronicDeviceTypeMap();
this.lastConnection = sp.getLong(MedtronicConst.Statistics.LastGoodPumpCommunicationTime, 0L); this.lastConnection = sp.getLong(MedtronicConst.Statistics.LastGoodPumpCommunicationTime, 0L);
this.lastDataTime = new LocalDateTime(this.lastConnection); this.lastDataTime = this.lastConnection;
} }

View file

@ -9,6 +9,7 @@ import android.os.IBinder;
import javax.inject.Inject; import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.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;
@ -36,11 +37,11 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
*/ */
public class RileyLinkMedtronicService extends RileyLinkService { public class RileyLinkMedtronicService extends RileyLinkService {
@Inject HasAndroidInjector injector;
@Inject MedtronicPumpPlugin medtronicPumpPlugin; @Inject MedtronicPumpPlugin medtronicPumpPlugin;
@Inject MedtronicUtil medtronicUtil; @Inject MedtronicUtil medtronicUtil;
@Deprecated // TEDO remove this reference @Deprecated // TEDO remove this reference
private static RileyLinkMedtronicService instance;
private static ServiceTask currentTask = null; 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.
@ -51,12 +52,6 @@ public class RileyLinkMedtronicService extends RileyLinkService {
public RileyLinkMedtronicService() { public RileyLinkMedtronicService() {
super(); super();
instance = this;
}
public static RileyLinkMedtronicService getInstance() {
return instance;
} }
@ -101,7 +96,7 @@ public class RileyLinkMedtronicService extends RileyLinkService {
rileyLinkUtil.setRileyLinkBLE(rileyLinkBLE); rileyLinkUtil.setRileyLinkBLE(rileyLinkBLE);
// init rileyLinkCommunicationManager // init rileyLinkCommunicationManager
medtronicCommunicationManager = new MedtronicCommunicationManager(rfspy); medtronicCommunicationManager = new MedtronicCommunicationManager(injector, rfspy);
aapsLogger.debug(LTag.PUMPCOMM, "RileyLinkMedtronicService newly constructed"); aapsLogger.debug(LTag.PUMPCOMM, "RileyLinkMedtronicService newly constructed");
medtronicUtil.setMedtronicService(this); medtronicUtil.setMedtronicService(this);

View file

@ -72,7 +72,6 @@ public class MedtronicUtil {
@Inject @Inject
public MedtronicUtil( public MedtronicUtil(
Context context,
AAPSLogger aapsLogger, AAPSLogger aapsLogger,
RxBusWrapper rxBus, RxBusWrapper rxBus,
RileyLinkUtil rileyLinkUtil RileyLinkUtil rileyLinkUtil
@ -93,16 +92,6 @@ public class MedtronicUtil {
return instance; return instance;
} }
public Gson getGsonInstance() {
return gsonInstance;
}
public Gson getGsonInstanceCore() {
return gsonInstanceCore;
}
public LocalTime getTimeFrom30MinInterval(int interval) { public LocalTime getTimeFrom30MinInterval(int interval) {
if (interval % 2 == 0) { if (interval % 2 == 0) {
return new LocalTime(interval / 2, 0); return new LocalTime(interval / 2, 0);
@ -122,12 +111,6 @@ public class MedtronicUtil {
return k; return k;
} }
public boolean isMedtronicPump() {
return MedtronicPumpPlugin.getPlugin().isEnabled(PluginType.PUMP);
//return ConfigBuilderPlugin.getPlugin().getActivePump().deviceID().equals("Medtronic");
}
public byte[] getByteArrayFromUnsignedShort(int shortValue, boolean returnFixedSize) { public byte[] getByteArrayFromUnsignedShort(int shortValue, boolean returnFixedSize) {
byte highByte = (byte) (shortValue >> 8 & 0xFF); byte highByte = (byte) (shortValue >> 8 & 0xFF);
byte lowByte = (byte) (shortValue & 0xFF); byte lowByte = (byte) (shortValue & 0xFF);

View file

@ -40,6 +40,7 @@ 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;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData;
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData; import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil; import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.FabricPrivacy;
@ -265,9 +266,9 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
if (treatment != null) { if (treatment != null) {
if (MedtronicHistoryData.doubleBolusDebug) if (MedtronicHistoryData.doubleBolusDebug)
log.debug("DoubleBolusDebug: createTreatmentFromJsonIfNotExists:: medtronicPump={}", MedtronicUtil.getInstance().isMedtronicPump()); log.debug("DoubleBolusDebug: createTreatmentFromJsonIfNotExists:: medtronicPump={}", MedtronicPumpPlugin.getPlugin().isEnabled());
if (!MedtronicUtil.getInstance().isMedtronicPump()) if (!MedtronicPumpPlugin.getPlugin().isEnabled())
createOrUpdate(treatment); createOrUpdate(treatment);
else else
createOrUpdateMedtronic(treatment, true); createOrUpdateMedtronic(treatment, true);

View file

@ -300,13 +300,13 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
synchronized (treatments) { synchronized (treatments) {
getAapsLogger().debug(MedtronicHistoryData.doubleBolusDebug, LTag.DATATREATMENTS, "DoubleBolusDebug: AllTreatmentsInDb: " + new GsonBuilder().create().toJson(treatments)); getAapsLogger().debug(MedtronicHistoryData.doubleBolusDebug, LTag.DATATREATMENTS, "DoubleBolusDebug: AllTreatmentsInDb: " + new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(treatments));
for (Treatment t : treatments) { for (Treatment t : treatments) {
if (t.date <= time && t.date >= fromTimestamp) if (t.date <= time && t.date >= fromTimestamp)
in5minback.add(t); in5minback.add(t);
} }
getAapsLogger().debug(MedtronicHistoryData.doubleBolusDebug, LTag.DATATREATMENTS, "DoubleBolusDebug: FilteredTreatments: AfterTime={}, Items={} " + fromTimestamp + " " + new GsonBuilder().create().toJson(in5minback)); getAapsLogger().debug(MedtronicHistoryData.doubleBolusDebug, LTag.DATATREATMENTS, "DoubleBolusDebug: FilteredTreatments: AfterTime={}, Items={} " + fromTimestamp + " " + new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(in5minback));
return in5minback; return in5minback;
} }
} }