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.IobCobOref1Thread
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.queue.CommandQueue
import info.nightscout.androidaps.queue.commands.*
@ -185,6 +186,14 @@ interface AppComponent : AndroidInjector<MainApp> {
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
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.IobCobOref1Thread
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.queue.CommandQueue
import info.nightscout.androidaps.queue.commands.*
@ -278,6 +279,14 @@ open class AppModule {
@Binds fun bindContext(mainApp: MainApp): Context
@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
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 resetRileyLinkConfiguration();
public abstract void doTuneUpDevice();
@Override
protected void onStart() {
@ -125,7 +126,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
disposable.add(rxBus
.toObservable(EventAppExit.class)
.observeOn(Schedulers.io())
.subscribe(event -> context.unbindService(serviceConnection), exception -> fabricPrivacy.logException(exception))
.subscribe(event -> context.unbindService(serviceConnection), fabricPrivacy::logException)
);
onStartCustomActions();
}

View file

@ -1,13 +1,11 @@
package info.nightscout.androidaps.plugins.pump.common.data;
import org.joda.time.LocalDateTime;
import java.util.Date;
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.PumpType;
import info.nightscout.androidaps.utils.DateUtil;
/**
* Created by andy on 4/28/18.
@ -16,7 +14,7 @@ import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
public abstract class PumpStatus {
// connection
public LocalDateTime lastDataTime;
public long lastDataTime;
public long lastConnection = 0L;
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).
@ -55,18 +53,16 @@ public abstract class PumpStatus {
//protected PumpDescription pumpDescription;
public PumpStatus() {
// public PumpStatus(PumpDescription pumpDescription) {
// this.pumpDescription = pumpDescription;
public PumpStatus() {
// public PumpStatus(PumpDescription pumpDescription) {
// this.pumpDescription = pumpDescription;
// this.initSettings();
}
public void setLastCommunicationToNow() {
this.lastDataTime = LocalDateTime.now();
this.lastDataTime = DateUtil.now();
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.LoggerFactory;
import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
@ -36,6 +39,7 @@ public abstract class RileyLinkCommunicationManager {
private static final int SCAN_TIMEOUT = 1500;
private static final int ALLOWED_PUMP_UNREACHABLE = 10 * 60 * 1000; // 10 minutes
protected final HasAndroidInjector injector;
protected final RFSpy rfspy;
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))
@ -49,7 +53,8 @@ public abstract class RileyLinkCommunicationManager {
private int timeoutCount = 0;
public RileyLinkCommunicationManager(RFSpy rfspy) {
public RileyLinkCommunicationManager(HasAndroidInjector injector, RFSpy rfspy) {
this.injector = injector;
this.rfspy = rfspy;
this.rileyLinkServiceData = RileyLinkUtil.getInstance().getRileyLinkServiceData();
RileyLinkUtil.getInstance().setRileyLinkCommunicationManager(this);
@ -107,7 +112,7 @@ public abstract class RileyLinkCommunicationManager {
if (diff > ALLOWED_PUMP_UNREACHABLE) {
LOG.warn("We reached max time that Pump can be unreachable. Starting Tuning.");
ServiceTaskExecutor.startTask(new WakeAndTuneTask());
ServiceTaskExecutor.startTask(new WakeAndTuneTask(injector));
timeoutCount = 0;
}
}

View file

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

View file

@ -1,5 +1,6 @@
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;
/**
@ -10,11 +11,13 @@ public class DiscoverGattServicesTask extends ServiceTask {
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;
}

View file

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

View file

@ -1,5 +1,6 @@
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;
/**
@ -7,12 +8,12 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.
*/
public class PumpTask extends ServiceTask {
public PumpTask() {
super();
public PumpTask(HasAndroidInjector injector) {
super(injector);
}
public PumpTask(ServiceTransport transport) {
super(transport);
public PumpTask(HasAndroidInjector injector, ServiceTransport transport) {
super(injector, transport);
}
}

View file

@ -1,6 +1,13 @@
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.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.medtronic.MedtronicPumpPlugin;
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 {
@Inject ActivePluginProvider activePlugin;
@Inject RxBusWrapper rxBus;
private static final String TAG = "ResetRileyLinkTask";
public ResetRileyLinkConfigurationTask() {
public ResetRileyLinkConfigurationTask(HasAndroidInjector injector) {
super(injector);
}
public ResetRileyLinkConfigurationTask(ServiceTransport transport) {
super(transport);
public ResetRileyLinkConfigurationTask(HasAndroidInjector injector, ServiceTransport transport) {
super(injector, transport);
}
@Override
public void run() {
RxBus.Companion.getINSTANCE().send(new EventRefreshButtonState(false));
PumpPluginAbstract pump = (PumpPluginAbstract) activePlugin.getActivePump();
rxBus.send(new EventRefreshButtonState(false));
MedtronicPumpPlugin.isBusy = true;
RileyLinkMedtronicService.getInstance().resetRileyLinkConfiguration();
pump.resetRileyLinkConfiguration();
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;
import dagger.android.HasAndroidInjector;
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)";
public boolean completed = false;
protected ServiceTransport mTransport;
protected HasAndroidInjector injector;
public ServiceTask() {
public ServiceTask(HasAndroidInjector injector) {
this.injector = injector;
injector.androidInjector().inject(this);
init(new ServiceTransport());
}
public ServiceTask(ServiceTransport transport) {
public ServiceTask(HasAndroidInjector injector, ServiceTransport transport) {
this.injector = injector;
injector.androidInjector().inject(this);
init(transport);
}

View file

@ -1,6 +1,12 @@
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.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.medtronic.MedtronicPumpPlugin;
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 {
@Inject ActivePluginProvider activePlugin;
@Inject RxBusWrapper rxBus;
private static final String TAG = "WakeAndTuneTask";
public WakeAndTuneTask() {
public WakeAndTuneTask(HasAndroidInjector injector) {
super(injector);
}
public WakeAndTuneTask(ServiceTransport transport) {
super(transport);
public WakeAndTuneTask(HasAndroidInjector injector, ServiceTransport transport) {
super(injector, transport);
}
@Override
public void run() {
RxBus.Companion.getINSTANCE().send(new EventRefreshButtonState(false));
PumpPluginAbstract pump = (PumpPluginAbstract) activePlugin.getActivePump();
rxBus.send(new EventRefreshButtonState(false));
MedtronicPumpPlugin.isBusy = true;
RileyLinkMedtronicService.getInstance().doTuneUpDevice();
pump.doTuneUpDevice();
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 androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.joda.time.LocalDateTime;
@ -100,7 +101,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
private final MedtronicPumpStatus medtronicPumpStatus;
protected static MedtronicPumpPlugin plugin = null;
private RileyLinkMedtronicService medtronicService;
private RileyLinkMedtronicService rileyLinkMedtronicService;
private MedtronicUIComm medtronicUIComm;
// variables for handling statuses and history
@ -156,13 +157,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
public void onServiceDisconnected(ComponentName name) {
aapsLogger.debug(LTag.PUMP, "RileyLinkMedtronicService is disconnected");
medtronicService = null;
rileyLinkMedtronicService = null;
}
public void onServiceConnected(ComponentName name, IBinder service) {
aapsLogger.debug(LTag.PUMP, "RileyLinkMedtronicService is connected");
RileyLinkMedtronicService.LocalBinder mLocalBinder = (RileyLinkMedtronicService.LocalBinder) service;
medtronicService = mLocalBinder.getServiceInstance();
rileyLinkMedtronicService = mLocalBinder.getServiceInstance();
new Thread(() -> {
@ -213,7 +214,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
medtronicUtil.setPumpStatus(medtronicPumpStatus);
medtronicPumpStatus.lastConnection = sp.getLong(RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
medtronicPumpStatus.lastDataTime = new LocalDateTime(medtronicPumpStatus.lastConnection);
medtronicPumpStatus.lastDataTime = medtronicPumpStatus.lastConnection;
medtronicPumpStatus.previousConnection = medtronicPumpStatus.lastConnection;
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() {
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
private boolean isServiceSet() {
return medtronicService != null;
return rileyLinkMedtronicService != null;
}
@Deprecated
@Nullable
public RileyLinkMedtronicService getRileyLinkMedtronicService() {
return rileyLinkMedtronicService;
}
@Override
public boolean isInitialized() {
@ -373,7 +388,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
public boolean isConnected() {
if (displayConnectionMessages)
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() {
if (displayConnectionMessages)
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) {
aapsLogger.error("Number of error counts was 5 or more. Starting tunning.");
setRefreshButtonEnabled(true);
ServiceTaskExecutor.startTask(new WakeAndTuneTask());
ServiceTaskExecutor.startTask(new WakeAndTuneTask(getInjector()));
return;
}
@ -1518,7 +1533,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
case WakeUpAndTune: {
if (medtronicUtil.getPumpStatus().verifyConfiguration()) {
ServiceTaskExecutor.startTask(new WakeAndTuneTask());
ServiceTaskExecutor.startTask(new WakeAndTuneTask(getInjector()));
} else {
Intent i = new Intent(context, ErrorHelperActivity.class);
i.putExtra("soundid", R.raw.boluserror);
@ -1538,7 +1553,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
break;
case ResetRileyLinkConfiguration: {
ServiceTaskExecutor.startTask(new ResetRileyLinkConfigurationTask());
ServiceTaskExecutor.startTask(new ResetRileyLinkConfigurationTask(getInjector()));
}
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) {
this.customActionClearBolusBlock.setEnabled(isEnabled);

View file

@ -10,6 +10,7 @@ import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager;
@ -70,8 +71,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
private boolean doWakeUpBeforeCommand = true;
public MedtronicCommunicationManager(RFSpy rfspy) {
super(rfspy);
public MedtronicCommunicationManager(HasAndroidInjector injector, RFSpy rfspy) {
super(injector, rfspy);
medtronicCommunicationManager = this;
this.medtronicConverter = new MedtronicConverter();
this.pumpHistoryDecoder = new MedtronicPumpHistoryDecoder();
@ -143,7 +144,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
long diff = System.currentTimeMillis() - MedtronicUtil.getInstance().getPumpStatus().lastConnection;
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();
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 dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
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 {
@Inject HasAndroidInjector injector;
@Inject MedtronicPumpPlugin medtronicPumpPlugin;
@Inject MedtronicUtil medtronicUtil;
@Deprecated // TEDO remove this reference
private static RileyLinkMedtronicService instance;
private static ServiceTask currentTask = null;
// 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() {
super();
instance = this;
}
public static RileyLinkMedtronicService getInstance() {
return instance;
}
@ -101,7 +96,7 @@ public class RileyLinkMedtronicService extends RileyLinkService {
rileyLinkUtil.setRileyLinkBLE(rileyLinkBLE);
// init rileyLinkCommunicationManager
medtronicCommunicationManager = new MedtronicCommunicationManager(rfspy);
medtronicCommunicationManager = new MedtronicCommunicationManager(injector, rfspy);
aapsLogger.debug(LTag.PUMPCOMM, "RileyLinkMedtronicService newly constructed");
medtronicUtil.setMedtronicService(this);

View file

@ -72,7 +72,6 @@ public class MedtronicUtil {
@Inject
public MedtronicUtil(
Context context,
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
RileyLinkUtil rileyLinkUtil
@ -93,16 +92,6 @@ public class MedtronicUtil {
return instance;
}
public Gson getGsonInstance() {
return gsonInstance;
}
public Gson getGsonInstanceCore() {
return gsonInstanceCore;
}
public LocalTime getTimeFrom30MinInterval(int interval) {
if (interval % 2 == 0) {
return new LocalTime(interval / 2, 0);
@ -122,12 +111,6 @@ public class MedtronicUtil {
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) {
byte highByte = (byte) (shortValue >> 8 & 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.plugins.bus.RxBus;
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.util.MedtronicUtil;
import info.nightscout.androidaps.utils.FabricPrivacy;
@ -265,9 +266,9 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
if (treatment != null) {
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);
else
createOrUpdateMedtronic(treatment, true);

View file

@ -300,13 +300,13 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
long time = System.currentTimeMillis();
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) {
if (t.date <= time && t.date >= fromTimestamp)
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;
}
}