MDT refactor pass 12

This commit is contained in:
Milos Kozak 2020-04-27 18:44:41 +02:00
parent 6add8a8d86
commit e21b1e4d3d
11 changed files with 60 additions and 77 deletions

View file

@ -16,13 +16,11 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.Radi
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RadioResponse;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RLMessageType;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkBLEError;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.WakeAndTuneTask;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
/**
@ -37,7 +35,6 @@ public abstract class RileyLinkCommunicationManager {
@Inject MedtronicPumpStatus medtronicPumpStatus;
@Inject RileyLinkUtil rileyLinkUtil;
@Inject MedtronicUtil medtronicUtil;
private final int SCAN_TIMEOUT = 1500;
@ -151,7 +148,7 @@ public abstract class RileyLinkCommunicationManager {
// **** FIXME: this wakeup doesn't seem to work well... must revisit
// receiverDeviceAwakeForMinutes = duration_minutes;
medtronicUtil.setPumpDeviceState(PumpDeviceState.WakingUp);
medtronicPumpStatus.setPumpDeviceState(PumpDeviceState.WakingUp);
if (force)
nextWakeUpRequired = 0L;

View file

@ -101,7 +101,7 @@ public class RileyLinkStatusActivity extends NoSplashAppCompatActivity {
// FIXME
this.connectedDevice.setText("???");
// FIXME i18n
this.connectionError.setText(rileyLinkServiceData.errorCode.name());
this.connectionError.setText(rileyLinkServiceData.rileyLinkError.name());
} else {
}

View file

@ -104,9 +104,9 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
if (rileyLinkServiceData != null) {
this.configuredAddress.setText(rileyLinkServiceData.rileylinkAddress);
this.connectionError.setText(rileyLinkServiceData.errorCode == null ? //
this.connectionError.setText(rileyLinkServiceData.rileyLinkError == null ? //
"-"
: resourceHelper.gs(rileyLinkServiceData.errorCode.getResourceId(targetDevice)));
: resourceHelper.gs(rileyLinkServiceData.rileyLinkError.getResourceId(targetDevice)));
RileyLinkFirmwareVersion firmwareVersion = rileyLinkServiceData.versionCC110;

View file

@ -25,6 +25,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLin
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceResult;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceTransport;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
@ -41,6 +42,7 @@ public abstract class RileyLinkService extends DaggerService {
@Inject protected RileyLinkUtil rileyLinkUtil;
@Inject protected MedtronicUtil medtronicUtil; // TODO should be avoided here as it's MDT
@Inject protected RileyLinkServiceData rileyLinkServiceData;
@Inject protected MedtronicPumpStatus medtronicPumpStatus;
@NotNull protected RileyLinkBLE rileyLinkBLE; // android-bluetooth management, must be set in initRileyLinkServiceData
protected BluetoothAdapter bluetoothAdapter;
@ -204,7 +206,7 @@ public abstract class RileyLinkService extends DaggerService {
public void doTuneUpDevice() {
rileyLinkServiceData.setRileyLinkServiceState(RileyLinkServiceState.TuneUpDevice);
medtronicUtil.setPumpDeviceState(PumpDeviceState.Sleeping);
medtronicPumpStatus.setPumpDeviceState(PumpDeviceState.Sleeping);
double lastGoodFrequency = 0.0d;
@ -266,7 +268,7 @@ public abstract class RileyLinkService extends DaggerService {
public RileyLinkError getError() {
if (rileyLinkServiceData != null)
return rileyLinkServiceData.errorCode;
return rileyLinkServiceData.rileyLinkError;
else
return null;
}

View file

@ -26,7 +26,7 @@ public class RileyLinkServiceData {
@Inject RxBusWrapper rxBus;
boolean tuneUpDone = false;
public RileyLinkError errorCode;
public RileyLinkError rileyLinkError;
public RileyLinkServiceState rileyLinkServiceState = RileyLinkServiceState.NotStarted;
public String rileylinkAddress;
long lastTuneUpTime = 0L;
@ -70,7 +70,7 @@ public class RileyLinkServiceData {
if (set) {
rileyLinkServiceState = newState;
this.errorCode = errorCode;
this.rileyLinkError = errorCode;
aapsLogger.info(LTag.PUMP, "RileyLink State Changed: {} {}", newState, errorCode == null ? "" : " - Error State: " + errorCode.name());

View file

@ -19,7 +19,6 @@ import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusActivity
@ -188,16 +187,11 @@ class MedtronicFragment : DaggerFragment() {
}
medtronic_rl_status.setTextColor(if (rileyLinkError != null) Color.RED else Color.WHITE)
medtronicPumpStatus.rileyLinkError = checkStatusSet(medtronicPumpStatus.rileyLinkError, medtronicPumpPlugin.rileyLinkService?.error) as RileyLinkError?
medtronic_errors.text =
medtronicPumpStatus.rileyLinkError?.let {
rileyLinkServiceData.rileyLinkError?.let {
resourceHelper.gs(it.getResourceId(RileyLinkTargetDevice.MedtronicPump))
} ?: "-"
medtronicPumpStatus.pumpDeviceState = checkStatusSet(medtronicPumpStatus.pumpDeviceState,
medtronicUtil.pumpDeviceState) as PumpDeviceState?
when (medtronicPumpStatus.pumpDeviceState) {
null,
PumpDeviceState.Sleeping -> medtronic_pump_status.text = "{fa-bed} " // + pumpStatus.pumpDeviceState.name());
@ -239,17 +233,6 @@ class MedtronicFragment : DaggerFragment() {
}
}
private fun checkStatusSet(object1: Any?, object2: Any?): Any? {
return if (object1 == null) {
object2
} else {
if (object1 != object2) {
object2
} else
object1
}
}
private fun displayNotConfiguredDialog() {
context?.let {
OKDialog.show(it, resourceHelper.gs(R.string.combo_warning),

View file

@ -110,10 +110,10 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
*/
public boolean isDeviceReachable(boolean canPreventTuneUp) {
PumpDeviceState state = medtronicUtil.getPumpDeviceState();
PumpDeviceState state = medtronicPumpStatus.getPumpDeviceState();
if (state != PumpDeviceState.PumpUnreachable)
medtronicUtil.setPumpDeviceState(PumpDeviceState.WakingUp);
medtronicPumpStatus.setPumpDeviceState(PumpDeviceState.WakingUp);
for (int retry = 0; retry < 5; retry++) {
@ -129,7 +129,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
}
if (state != PumpDeviceState.PumpUnreachable)
medtronicUtil.setPumpDeviceState(PumpDeviceState.PumpUnreachable);
medtronicPumpStatus.setPumpDeviceState(PumpDeviceState.PumpUnreachable);
if (!canPreventTuneUp) {
@ -146,7 +146,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
private boolean connectToDevice() {
PumpDeviceState state = medtronicUtil.getPumpDeviceState();
PumpDeviceState state = medtronicPumpStatus.getPumpDeviceState();
byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.ReadSimpleData); // simple
RFSpyResponse rfSpyResponse = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte) 0, (byte) 200,
@ -187,9 +187,9 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
if (valid) {
if (state == PumpDeviceState.PumpUnreachable)
medtronicUtil.setPumpDeviceState(PumpDeviceState.WakingUp);
medtronicPumpStatus.setPumpDeviceState(PumpDeviceState.WakingUp);
else
medtronicUtil.setPumpDeviceState(PumpDeviceState.Sleeping);
medtronicPumpStatus.setPumpDeviceState(PumpDeviceState.Sleeping);
rememberLastGoodDeviceCommunicationTime();
@ -197,7 +197,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
} else {
if (state != PumpDeviceState.PumpUnreachable)
medtronicUtil.setPumpDeviceState(PumpDeviceState.PumpUnreachable);
medtronicPumpStatus.setPumpDeviceState(PumpDeviceState.PumpUnreachable);
}
}
@ -312,7 +312,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
aapsLogger.debug(LTag.PUMPBTCOMM, "Current command: " + medtronicUtil.getCurrentCommand());
medtronicUtil.setPumpDeviceState(PumpDeviceState.Active);
medtronicPumpStatus.setPumpDeviceState(PumpDeviceState.Active);
boolean doneWithError = false;
for (int pageNumber = 0; pageNumber < 5; pageNumber++) {
@ -344,7 +344,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
}
if (failed) {
medtronicUtil.setPumpDeviceState(PumpDeviceState.Sleeping);
medtronicPumpStatus.setPumpDeviceState(PumpDeviceState.Sleeping);
return pumpTotalResult;
}
@ -435,7 +435,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
}
if (doneWithError) {
medtronicUtil.setPumpDeviceState(PumpDeviceState.Sleeping);
medtronicPumpStatus.setPumpDeviceState(PumpDeviceState.Sleeping);
return pumpTotalResult;
}
@ -450,13 +450,13 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
aapsLogger.debug(LTag.PUMPBTCOMM, "getPumpHistory: Search status: Search finished: {}", pumpTotalResult.isSearchFinished());
if (pumpTotalResult.isSearchFinished()) {
medtronicUtil.setPumpDeviceState(PumpDeviceState.Sleeping);
medtronicPumpStatus.setPumpDeviceState(PumpDeviceState.Sleeping);
return pumpTotalResult;
}
}
medtronicUtil.setPumpDeviceState(PumpDeviceState.Sleeping);
medtronicPumpStatus.setPumpDeviceState(PumpDeviceState.Sleeping);
return pumpTotalResult;
@ -520,7 +520,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
if (doWakeUpBeforeCommand)
wakeUp(receiverDeviceAwakeForMinutes, false);
medtronicUtil.setPumpDeviceState(PumpDeviceState.Active);
medtronicPumpStatus.setPumpDeviceState(PumpDeviceState.Active);
// create message
PumpMessage msg;
@ -533,7 +533,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
// send and wait for response
PumpMessage response = sendAndListen(msg, timeoutMs);
medtronicUtil.setPumpDeviceState(PumpDeviceState.Sleeping);
medtronicPumpStatus.setPumpDeviceState(PumpDeviceState.Sleeping);
return response;
}
@ -655,7 +655,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
medtronicUtil.setCurrentCommand(commandType);
medtronicUtil.setPumpDeviceState(PumpDeviceState.Active);
medtronicPumpStatus.setPumpDeviceState(PumpDeviceState.Active);
for (int retries = 0; retries <= MAX_COMMAND_TRIES; retries++) {
@ -712,7 +712,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
aapsLogger.debug(LTag.PUMPBTCOMM, "Converted response for {} is {}.", commandType.name(), basalProfile);
medtronicUtil.setCurrentCommand(null);
medtronicUtil.setPumpDeviceState(PumpDeviceState.Sleeping);
medtronicPumpStatus.setPumpDeviceState(PumpDeviceState.Sleeping);
return basalProfile;
}
@ -724,7 +724,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
aapsLogger.warn(LTag.PUMPBTCOMM, "Error reading profile in max retries.");
medtronicUtil.setCurrentCommand(null);
medtronicUtil.setPumpDeviceState(PumpDeviceState.Sleeping);
medtronicPumpStatus.setPumpDeviceState(PumpDeviceState.Sleeping);
return null;

View file

@ -21,14 +21,12 @@ import javax.inject.Inject;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpHistoryEntryGroup;
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry;
import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData;
public class MedtronicHistoryActivity extends NoSplashAppCompatActivity {
@Inject MedtronicPumpPlugin medtronicPumpPlugin;
@Inject MedtronicHistoryData medtronicHistoryData;
Spinner historyTypeSpinner;

View file

@ -11,13 +11,17 @@ import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.BasalProfileStatus;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicDeviceStatusChange;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
@ -31,6 +35,8 @@ public class MedtronicPumpStatus extends PumpStatus {
private final ResourceHelper resourceHelper;
private final SP sp;
private final RileyLinkUtil rileyLinkUtil;
private final RxBusWrapper rxBus;
public String errorDescription = null;
public String serialNumber;
@ -39,8 +45,7 @@ public class MedtronicPumpStatus extends PumpStatus {
public Double maxBasal;
// statuses
public RileyLinkError rileyLinkError;
public PumpDeviceState pumpDeviceState = PumpDeviceState.NeverContacted;
private PumpDeviceState pumpDeviceState = PumpDeviceState.NeverContacted;
public MedtronicDeviceType medtronicDeviceType = null;
public Date tempBasalStart;
public Double tempBasalAmount = 0.0d;
@ -57,11 +62,15 @@ public class MedtronicPumpStatus extends PumpStatus {
@Inject
public MedtronicPumpStatus(
ResourceHelper resourceHelper,
SP sp
SP sp,
RxBusWrapper rxBus,
RileyLinkUtil rileyLinkUtil
) {
super();
this.resourceHelper = resourceHelper;
this.sp = sp;
this.rxBus = rxBus;
this.rileyLinkUtil = rileyLinkUtil;
initSettings();
}
@ -155,4 +164,17 @@ public class MedtronicPumpStatus extends PumpStatus {
public String getErrorInfo() {
return (errorDescription == null) ? "-" : errorDescription;
}
public PumpDeviceState getPumpDeviceState() {
return pumpDeviceState;
}
public void setPumpDeviceState(PumpDeviceState pumpDeviceState) {
this.pumpDeviceState = pumpDeviceState;
rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItem(pumpDeviceState, RileyLinkTargetDevice.MedtronicPump));
rxBus.send(new EventMedtronicDeviceStatusChange(pumpDeviceState));
}
}

View file

@ -162,7 +162,7 @@ public class RileyLinkMedtronicService extends RileyLinkService {
return;
}
medtronicUtil.setPumpDeviceState(PumpDeviceState.InvalidConfiguration);
medtronicPumpStatus.setPumpDeviceState(PumpDeviceState.InvalidConfiguration);
// LOG.info("setPumpIDString: saved pumpID " + idString);
}

View file

@ -22,7 +22,6 @@ import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotifi
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.ClockDTO;
@ -30,7 +29,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.PumpSettingDTO
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicNotificationType;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicDeviceStatusChange;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
@ -43,7 +42,6 @@ public class MedtronicUtil {
private int ENVELOPE_SIZE = 4; // 0xA7 S1 S2 S3 CMD PARAM_COUNT [PARAMS]
private static boolean lowLevelDebug = true;
private PumpDeviceState pumpDeviceState;
private MedtronicDeviceType medtronicPumpModel;
private MedtronicCommandType currentCommand;
private Map<String, PumpSettingDTO> settings;
@ -51,24 +49,23 @@ public class MedtronicUtil {
private int doneBit = 1 << 7;
private ClockDTO pumpTime;
public Gson gsonInstance = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
public Gson gsonInstanceCore = new GsonBuilder().create();
private final AAPSLogger aapsLogger;
private final RxBusWrapper rxBus;
private final RileyLinkUtil rileyLinkUtil;
private final RileyLinkServiceData rileyLinkServiceData;
private final MedtronicPumpStatus medtronicPumpStatus;
@Inject
public MedtronicUtil(
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
RileyLinkUtil rileyLinkUtil,
RileyLinkServiceData rileyLinkServiceData
MedtronicPumpStatus medtronicPumpStatus
) {
this.aapsLogger = aapsLogger;
this.rxBus = rxBus;
this.rileyLinkUtil = rileyLinkUtil;
this.rileyLinkServiceData = rileyLinkServiceData;
this.medtronicPumpStatus = medtronicPumpStatus;
}
public LocalTime getTimeFrom30MinInterval(int interval) {
@ -393,30 +390,14 @@ public class MedtronicUtil {
return lowLevelDebug;
}
public PumpDeviceState getPumpDeviceState() {
return pumpDeviceState;
}
public void setPumpDeviceState(PumpDeviceState pumpDeviceState) {
this.pumpDeviceState = pumpDeviceState;
rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItem(pumpDeviceState, RileyLinkTargetDevice.MedtronicPump));
rxBus.send(new EventMedtronicDeviceStatusChange(pumpDeviceState));
}
public boolean isModelSet() {
return medtronicPumpModel != null;
}
public MedtronicDeviceType getMedtronicPumpModel() {
return medtronicPumpModel;
}
public void setMedtronicPumpModel(MedtronicDeviceType medtronicPumpModel) {
this.medtronicPumpModel = medtronicPumpModel;
}
@ -445,7 +426,7 @@ public class MedtronicUtil {
setCurrentCommand(currentCommand);
}
rxBus.send(new EventMedtronicDeviceStatusChange(pumpDeviceState));
rxBus.send(new EventMedtronicDeviceStatusChange(medtronicPumpStatus.getPumpDeviceState()));
}