MDT refactor pass 6
This commit is contained in:
parent
3598e00290
commit
7b9247b1a0
15 changed files with 388 additions and 484 deletions
|
@ -72,8 +72,6 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
.enacted(false).comment(MainApp.gs(R.string.pump_operation_not_yet_supported_by_pump));
|
.enacted(false).comment(MainApp.gs(R.string.pump_operation_not_yet_supported_by_pump));
|
||||||
*/
|
*/
|
||||||
protected PumpDescription pumpDescription = new PumpDescription();
|
protected PumpDescription pumpDescription = new PumpDescription();
|
||||||
@Deprecated // TODO remove this reference
|
|
||||||
protected PumpStatus pumpStatus;
|
|
||||||
protected ServiceConnection serviceConnection = null;
|
protected ServiceConnection serviceConnection = null;
|
||||||
protected boolean serviceRunning = false;
|
protected boolean serviceRunning = false;
|
||||||
// protected boolean isInitialized = false;
|
// protected boolean isInitialized = false;
|
||||||
|
@ -158,9 +156,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
*/
|
*/
|
||||||
public abstract Class getServiceClass();
|
public abstract Class getServiceClass();
|
||||||
|
|
||||||
public PumpStatus getPumpStatusData() {
|
public abstract PumpStatus getPumpStatusData();
|
||||||
return pumpStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public boolean isInitialized() {
|
public boolean isInitialized() {
|
||||||
|
@ -224,12 +220,6 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
aapsLogger.debug(LTag.PUMP, "finishHandshaking [PumpPluginAbstract] - default (empty) implementation.");
|
aapsLogger.debug(LTag.PUMP, "finishHandshaking [PumpPluginAbstract] - default (empty) implementation.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void getPumpStatus() {
|
|
||||||
aapsLogger.debug(LTag.PUMP, "getPumpStatus [PumpPluginAbstract] - Not implemented.");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Upload to pump new basal profile
|
// Upload to pump new basal profile
|
||||||
@NonNull public PumpEnactResult setNewBasalProfile(Profile profile) {
|
@NonNull public PumpEnactResult setNewBasalProfile(Profile profile) {
|
||||||
aapsLogger.debug(LTag.PUMP, "setNewBasalProfile [PumpPluginAbstract] - Not implemented.");
|
aapsLogger.debug(LTag.PUMP, "setNewBasalProfile [PumpPluginAbstract] - Not implemented.");
|
||||||
|
@ -245,7 +235,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
|
|
||||||
public long lastDataTime() {
|
public long lastDataTime() {
|
||||||
aapsLogger.debug(LTag.PUMP, "lastDataTime [PumpPluginAbstract].");
|
aapsLogger.debug(LTag.PUMP, "lastDataTime [PumpPluginAbstract].");
|
||||||
return pumpStatus.lastConnection;
|
return getPumpStatusData().lastConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -334,7 +324,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
@NonNull @Override
|
@NonNull @Override
|
||||||
public JSONObject getJSONStatus(Profile profile, String profileName) {
|
public JSONObject getJSONStatus(Profile profile, String profileName) {
|
||||||
|
|
||||||
if ((pumpStatus.lastConnection + 5 * 60 * 1000L) < System.currentTimeMillis()) {
|
if ((getPumpStatusData().lastConnection + 5 * 60 * 1000L) < System.currentTimeMillis()) {
|
||||||
return new JSONObject();
|
return new JSONObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,8 +333,8 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
JSONObject status = new JSONObject();
|
JSONObject status = new JSONObject();
|
||||||
JSONObject extended = new JSONObject();
|
JSONObject extended = new JSONObject();
|
||||||
try {
|
try {
|
||||||
battery.put("percent", pumpStatus.batteryRemaining);
|
battery.put("percent", getPumpStatusData().batteryRemaining);
|
||||||
status.put("status", pumpStatus.pumpStatusType != null ? pumpStatus.pumpStatusType.getStatus() : "normal");
|
status.put("status", getPumpStatusData().pumpStatusType != null ? getPumpStatusData().pumpStatusType.getStatus() : "normal");
|
||||||
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
|
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
|
||||||
try {
|
try {
|
||||||
extended.put("ActiveProfile", profileName);
|
extended.put("ActiveProfile", profileName);
|
||||||
|
@ -371,7 +361,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
pump.put("battery", battery);
|
pump.put("battery", battery);
|
||||||
pump.put("status", status);
|
pump.put("status", status);
|
||||||
pump.put("extended", extended);
|
pump.put("extended", extended);
|
||||||
pump.put("reservoir", pumpStatus.reservoirRemainingUnits);
|
pump.put("reservoir", getPumpStatusData().reservoirRemainingUnits);
|
||||||
pump.put("clock", DateUtil.toISOString(new Date()));
|
pump.put("clock", DateUtil.toISOString(new Date()));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
aapsLogger.error("Unhandled exception", e);
|
aapsLogger.error("Unhandled exception", e);
|
||||||
|
@ -384,14 +374,14 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
@NonNull @Override
|
@NonNull @Override
|
||||||
public String shortStatus(boolean veryShort) {
|
public String shortStatus(boolean veryShort) {
|
||||||
String ret = "";
|
String ret = "";
|
||||||
if (pumpStatus.lastConnection != 0) {
|
if (getPumpStatusData().lastConnection != 0) {
|
||||||
long agoMsec = System.currentTimeMillis() - pumpStatus.lastConnection;
|
long agoMsec = System.currentTimeMillis() - getPumpStatusData().lastConnection;
|
||||||
int agoMin = (int) (agoMsec / 60d / 1000d);
|
int agoMin = (int) (agoMsec / 60d / 1000d);
|
||||||
ret += "LastConn: " + agoMin + " min ago\n";
|
ret += "LastConn: " + agoMin + " min ago\n";
|
||||||
}
|
}
|
||||||
if (pumpStatus.lastBolusTime != null && pumpStatus.lastBolusTime.getTime() != 0) {
|
if (getPumpStatusData().lastBolusTime != null && getPumpStatusData().lastBolusTime.getTime() != 0) {
|
||||||
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pumpStatus.lastBolusAmount) + "U @" + //
|
ret += "LastBolus: " + DecimalFormatter.to2Decimal(getPumpStatusData().lastBolusAmount) + "U @" + //
|
||||||
android.text.format.DateFormat.format("HH:mm", pumpStatus.lastBolusTime) + "\n";
|
android.text.format.DateFormat.format("HH:mm", getPumpStatusData().lastBolusTime) + "\n";
|
||||||
}
|
}
|
||||||
TemporaryBasal activeTemp = activePlugin.getActiveTreatments().getRealTempBasalFromHistory(System.currentTimeMillis());
|
TemporaryBasal activeTemp = activePlugin.getActiveTreatments().getRealTempBasalFromHistory(System.currentTimeMillis());
|
||||||
if (activeTemp != null) {
|
if (activeTemp != null) {
|
||||||
|
@ -406,9 +396,9 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
// ret += "TDD: " + DecimalFormatter.to0Decimal(pumpStatus.dailyTotalUnits) + " / "
|
// ret += "TDD: " + DecimalFormatter.to0Decimal(pumpStatus.dailyTotalUnits) + " / "
|
||||||
// + pumpStatus.maxDailyTotalUnits + " U\n";
|
// + pumpStatus.maxDailyTotalUnits + " U\n";
|
||||||
// }
|
// }
|
||||||
ret += "IOB: " + pumpStatus.iob + "U\n";
|
ret += "IOB: " + getPumpStatusData().iob + "U\n";
|
||||||
ret += "Reserv: " + DecimalFormatter.to0Decimal(pumpStatus.reservoirRemainingUnits) + "U\n";
|
ret += "Reserv: " + DecimalFormatter.to0Decimal(getPumpStatusData().reservoirRemainingUnits) + "U\n";
|
||||||
ret += "Batt: " + pumpStatus.batteryRemaining + "\n";
|
ret += "Batt: " + getPumpStatusData().batteryRemaining + "\n";
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,6 @@ public abstract class PumpStatus {
|
||||||
public Double dailyTotalUnits;
|
public Double dailyTotalUnits;
|
||||||
public String maxDailyTotalUnits;
|
public String maxDailyTotalUnits;
|
||||||
public boolean validBasalRateProfileSelectedOnPump = true;
|
public boolean validBasalRateProfileSelectedOnPump = true;
|
||||||
public PumpType pumpType = PumpType.GenericAAPS;
|
|
||||||
public ProfileStore profileStore;
|
public ProfileStore profileStore;
|
||||||
public String units; // Constants.MGDL or Constants.MMOL
|
public String units; // Constants.MGDL or Constants.MMOL
|
||||||
public PumpStatusType pumpStatusType = PumpStatusType.Running;
|
public PumpStatusType pumpStatusType = PumpStatusType.Running;
|
||||||
|
@ -70,23 +69,5 @@ public abstract class PumpStatus {
|
||||||
this.lastErrorConnection = System.currentTimeMillis();
|
this.lastErrorConnection = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public abstract String getErrorInfo();
|
public abstract String getErrorInfo();
|
||||||
|
|
||||||
|
|
||||||
public abstract void refreshConfiguration();
|
|
||||||
|
|
||||||
|
|
||||||
public PumpType getPumpType() {
|
|
||||||
return pumpType;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setPumpType(PumpType pumpType) {
|
|
||||||
this.pumpType = pumpType;
|
|
||||||
}
|
|
||||||
|
|
||||||
// public Date last_bolus_time;
|
|
||||||
// public double last_bolus_amount = 0;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCons
|
||||||
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.ble.data.GattAttributes;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.GattAttributes;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.LocationHelper;
|
import info.nightscout.androidaps.plugins.pump.common.utils.LocationHelper;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
|
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicPumpConfigurationChanged;
|
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicPumpConfigurationChanged;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||||
|
@ -62,7 +63,7 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
|
||||||
@Inject ResourceHelper resourceHelper;
|
@Inject ResourceHelper resourceHelper;
|
||||||
@Inject RileyLinkUtil rileyLinkUtil;
|
@Inject RileyLinkUtil rileyLinkUtil;
|
||||||
@Inject MedtronicUtil medtronicUtil;
|
@Inject MedtronicUtil medtronicUtil;
|
||||||
@Inject MedtronicPumpStatus medtronicPumpStatus;
|
@Inject MedtronicPumpPlugin medtronicPumpPlugin;
|
||||||
|
|
||||||
private static final int PERMISSION_REQUEST_COARSE_LOCATION = 30241; // arbitrary.
|
private static final int PERMISSION_REQUEST_COARSE_LOCATION = 30241; // arbitrary.
|
||||||
private static final int REQUEST_ENABLE_BT = 30242; // arbitrary
|
private static final int REQUEST_ENABLE_BT = 30242; // arbitrary
|
||||||
|
@ -113,7 +114,7 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
|
||||||
|
|
||||||
rileyLinkUtil.getRileyLinkSelectPreference().setSummary(bleAddress);
|
rileyLinkUtil.getRileyLinkSelectPreference().setSummary(bleAddress);
|
||||||
|
|
||||||
medtronicPumpStatus.verifyConfiguration(); // force reloading of address
|
medtronicPumpPlugin.getRileyLinkService().verifyConfiguration(); // force reloading of address
|
||||||
|
|
||||||
rxBus.send(new EventMedtronicPumpConfigurationChanged());
|
rxBus.send(new EventMedtronicPumpConfigurationChanged());
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLin
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
|
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
|
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||||
|
@ -35,6 +36,7 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
|
||||||
@Inject MedtronicUtil medtronicUtil;
|
@Inject MedtronicUtil medtronicUtil;
|
||||||
@Inject MedtronicPumpStatus medtronicPumpStatus;
|
@Inject MedtronicPumpStatus medtronicPumpStatus;
|
||||||
@Inject ResourceHelper resourceHelper;
|
@Inject ResourceHelper resourceHelper;
|
||||||
|
@Inject MedtronicPumpPlugin medtronicPumpPlugin;
|
||||||
|
|
||||||
TextView connectionStatus;
|
TextView connectionStatus;
|
||||||
TextView configuredAddress;
|
TextView configuredAddress;
|
||||||
|
@ -128,7 +130,7 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
|
||||||
|
|
||||||
if (medtronicPumpStatus != null) {
|
if (medtronicPumpStatus != null) {
|
||||||
this.deviceType.setText(resourceHelper.gs(RileyLinkTargetDevice.MedtronicPump.getResourceId()));
|
this.deviceType.setText(resourceHelper.gs(RileyLinkTargetDevice.MedtronicPump.getResourceId()));
|
||||||
this.deviceModel.setText(medtronicPumpStatus.pumpType.getDescription());
|
this.deviceModel.setText(medtronicPumpPlugin.getPumpDescription().pumpType.getDescription());
|
||||||
this.serialNumber.setText(medtronicPumpStatus.serialNumber);
|
this.serialNumber.setText(medtronicPumpStatus.serialNumber);
|
||||||
this.pumpFrequency.setText(resourceHelper.gs(medtronicPumpStatus.pumpFrequency.equals("medtronic_pump_frequency_us_ca") ? R.string.medtronic_pump_frequency_us_ca : R.string.medtronic_pump_frequency_worldwide));
|
this.pumpFrequency.setText(resourceHelper.gs(medtronicPumpStatus.pumpFrequency.equals("medtronic_pump_frequency_us_ca") ? R.string.medtronic_pump_frequency_us_ca : R.string.medtronic_pump_frequency_worldwide));
|
||||||
|
|
||||||
|
|
|
@ -37,9 +37,9 @@ import info.nightscout.androidaps.queue.Callback
|
||||||
import info.nightscout.androidaps.queue.events.EventQueueChanged
|
import info.nightscout.androidaps.queue.events.EventQueueChanged
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
|
||||||
import info.nightscout.androidaps.utils.T
|
import info.nightscout.androidaps.utils.T
|
||||||
import info.nightscout.androidaps.utils.WarnColors
|
import info.nightscout.androidaps.utils.WarnColors
|
||||||
|
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||||
import info.nightscout.androidaps.utils.extensions.plusAssign
|
import info.nightscout.androidaps.utils.extensions.plusAssign
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
|
@ -88,7 +88,7 @@ class MedtronicFragment : DaggerFragment() {
|
||||||
medtronic_pump_status.text = "{fa-bed}"
|
medtronic_pump_status.text = "{fa-bed}"
|
||||||
|
|
||||||
medtronic_history.setOnClickListener {
|
medtronic_history.setOnClickListener {
|
||||||
if (medtronicPumpStatus.verifyConfiguration()) {
|
if (medtronicPumpPlugin.rileyLinkService?.verifyConfiguration() == true) {
|
||||||
startActivity(Intent(context, MedtronicHistoryActivity::class.java))
|
startActivity(Intent(context, MedtronicHistoryActivity::class.java))
|
||||||
} else {
|
} else {
|
||||||
displayNotConfiguredDialog()
|
displayNotConfiguredDialog()
|
||||||
|
@ -96,7 +96,7 @@ class MedtronicFragment : DaggerFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
medtronic_refresh.setOnClickListener {
|
medtronic_refresh.setOnClickListener {
|
||||||
if (!medtronicPumpStatus.verifyConfiguration()) {
|
if (medtronicPumpPlugin.rileyLinkService?.verifyConfiguration() != true) {
|
||||||
displayNotConfiguredDialog()
|
displayNotConfiguredDialog()
|
||||||
} else {
|
} else {
|
||||||
medtronic_refresh.isEnabled = false
|
medtronic_refresh.isEnabled = false
|
||||||
|
@ -110,7 +110,7 @@ class MedtronicFragment : DaggerFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
medtronic_stats.setOnClickListener {
|
medtronic_stats.setOnClickListener {
|
||||||
if (medtronicPumpStatus.verifyConfiguration()) {
|
if (medtronicPumpPlugin.rileyLinkService?.verifyConfiguration() == true) {
|
||||||
startActivity(Intent(context, RileyLinkStatusActivity::class.java))
|
startActivity(Intent(context, RileyLinkStatusActivity::class.java))
|
||||||
} else {
|
} else {
|
||||||
displayNotConfiguredDialog()
|
displayNotConfiguredDialog()
|
||||||
|
@ -150,7 +150,7 @@ class MedtronicFragment : DaggerFragment() {
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe({
|
.subscribe({
|
||||||
aapsLogger.debug(LTag.PUMP, "EventMedtronicPumpConfigurationChanged triggered")
|
aapsLogger.debug(LTag.PUMP, "EventMedtronicPumpConfigurationChanged triggered")
|
||||||
medtronicPumpStatus.verifyConfiguration()
|
medtronicPumpPlugin.rileyLinkService?.verifyConfiguration()
|
||||||
updateGUI()
|
updateGUI()
|
||||||
}, { fabricPrivacy.logException(it) })
|
}, { fabricPrivacy.logException(it) })
|
||||||
disposable += rxBus
|
disposable += rxBus
|
||||||
|
@ -322,7 +322,7 @@ class MedtronicFragment : DaggerFragment() {
|
||||||
?: ""
|
?: ""
|
||||||
|
|
||||||
// battery
|
// battery
|
||||||
if (medtronicUtil.getBatteryType() == BatteryType.None || medtronicPumpStatus.batteryVoltage == null) {
|
if (medtronicPumpStatus.batteryType == BatteryType.None || medtronicPumpStatus.batteryVoltage == null) {
|
||||||
medtronic_pumpstate_battery.text = "{fa-battery-" + medtronicPumpStatus.batteryRemaining / 25 + "} "
|
medtronic_pumpstate_battery.text = "{fa-battery-" + medtronicPumpStatus.batteryRemaining / 25 + "} "
|
||||||
} else {
|
} else {
|
||||||
medtronic_pumpstate_battery.text = "{fa-battery-" + medtronicPumpStatus.batteryRemaining / 25 + "} " + medtronicPumpStatus.batteryRemaining + "%" + String.format(" (%.2f V)", medtronicPumpStatus.batteryVoltage)
|
medtronic_pumpstate_battery.text = "{fa-battery-" + medtronicPumpStatus.batteryRemaining / 25 + "} " + medtronicPumpStatus.batteryRemaining + "%" + String.format(" (%.2f V)", medtronicPumpStatus.batteryVoltage)
|
||||||
|
@ -333,6 +333,7 @@ class MedtronicFragment : DaggerFragment() {
|
||||||
medtronic_reservoir.text = resourceHelper.gs(R.string.reservoirvalue, medtronicPumpStatus.reservoirRemainingUnits, medtronicPumpStatus.reservoirFullUnits)
|
medtronic_reservoir.text = resourceHelper.gs(R.string.reservoirvalue, medtronicPumpStatus.reservoirRemainingUnits, medtronicPumpStatus.reservoirFullUnits)
|
||||||
warnColors.setColorInverse(medtronic_reservoir, medtronicPumpStatus.reservoirRemainingUnits, 50.0, 20.0)
|
warnColors.setColorInverse(medtronic_reservoir, medtronicPumpStatus.reservoirRemainingUnits, 50.0, 20.0)
|
||||||
|
|
||||||
|
medtronicPumpPlugin.rileyLinkService?.verifyConfiguration()
|
||||||
medtronic_errors.text = medtronicPumpStatus.errorInfo
|
medtronic_errors.text = medtronicPumpStatus.errorInfo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract;
|
import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract;
|
||||||
|
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.RileyLinkConst;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
||||||
|
@ -167,7 +168,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
SystemClock.sleep(5000);
|
SystemClock.sleep(5000);
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMP, "Starting Medtronic-RileyLink service");
|
aapsLogger.debug(LTag.PUMP, "Starting Medtronic-RileyLink service");
|
||||||
if (medtronicPumpStatus.setNotInPreInit()) {
|
if (rileyLinkMedtronicService.setNotInPreInit()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,12 +209,10 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
medtronicPumpStatus.lastDataTime = medtronicPumpStatus.lastConnection;
|
medtronicPumpStatus.lastDataTime = medtronicPumpStatus.lastConnection;
|
||||||
medtronicPumpStatus.previousConnection = medtronicPumpStatus.lastConnection;
|
medtronicPumpStatus.previousConnection = medtronicPumpStatus.lastConnection;
|
||||||
|
|
||||||
medtronicPumpStatus.refreshConfiguration();
|
if (rileyLinkMedtronicService != null) rileyLinkMedtronicService.verifyConfiguration();
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMP, "initPumpStatusData: " + this.medtronicPumpStatus);
|
aapsLogger.debug(LTag.PUMP, "initPumpStatusData: " + this.medtronicPumpStatus);
|
||||||
|
|
||||||
this.pumpStatus = medtronicPumpStatus;
|
|
||||||
|
|
||||||
// this is only thing that can change, by being configured
|
// this is only thing that can change, by being configured
|
||||||
pumpDescription.maxTempAbsolute = (medtronicPumpStatus.maxBasal != null) ? medtronicPumpStatus.maxBasal : 35.0d;
|
pumpDescription.maxTempAbsolute = (medtronicPumpStatus.maxBasal != null) ? medtronicPumpStatus.maxBasal : 35.0d;
|
||||||
|
|
||||||
|
@ -285,6 +284,9 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
return RileyLinkMedtronicService.class;
|
return RileyLinkMedtronicService.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public PumpStatus getPumpStatusData() {
|
||||||
|
return medtronicPumpStatus;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String deviceID() {
|
public String deviceID() {
|
||||||
|
@ -633,7 +635,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
boolean invalid = false;
|
boolean invalid = false;
|
||||||
Double[] basalsByHour = medtronicPumpStatus.basalsByHour;
|
Double[] basalsByHour = medtronicPumpStatus.basalsByHour;
|
||||||
PumpType pumpType = medtronicPumpStatus.getPumpType();
|
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMP, "Current Basals (h): "
|
aapsLogger.debug(LTag.PUMP, "Current Basals (h): "
|
||||||
+ (basalsByHour == null ? "null" : BasalProfile.getProfilesByHourToString(basalsByHour)));
|
+ (basalsByHour == null ? "null" : BasalProfile.getProfilesByHourToString(basalsByHour)));
|
||||||
|
@ -647,7 +648,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
for (Profile.ProfileValue basalValue : profile.getBasalValues()) {
|
for (Profile.ProfileValue basalValue : profile.getBasalValues()) {
|
||||||
|
|
||||||
double basalValueValue = pumpType.determineCorrectBasalSize(basalValue.value);
|
double basalValueValue = pumpDescription.pumpType.determineCorrectBasalSize(basalValue.value);
|
||||||
|
|
||||||
int hour = basalValue.timeAsSeconds / (60 * 60);
|
int hour = basalValue.timeAsSeconds / (60 * 60);
|
||||||
|
|
||||||
|
@ -1046,7 +1047,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
return setTempBasalAbsolute(0.0d, durationInMinutes, profile, enforceNew);
|
return setTempBasalAbsolute(0.0d, durationInMinutes, profile, enforceNew);
|
||||||
} else {
|
} else {
|
||||||
double absoluteValue = profile.getBasal() * (percent / 100.0d);
|
double absoluteValue = profile.getBasal() * (percent / 100.0d);
|
||||||
absoluteValue = medtronicPumpStatus.pumpType.determineCorrectBasalSize(absoluteValue);
|
absoluteValue = pumpDescription.pumpType.determineCorrectBasalSize(absoluteValue);
|
||||||
aapsLogger.warn(LTag.PUMP, "setTempBasalPercent [MedtronicPumpPlugin] - You are trying to use setTempBasalPercent with percent other then 0% (" + percent + "). This will start setTempBasalAbsolute, with calculated value (" + absoluteValue + "). Result might not be 100% correct.");
|
aapsLogger.warn(LTag.PUMP, "setTempBasalPercent [MedtronicPumpPlugin] - You are trying to use setTempBasalPercent with percent other then 0% (" + percent + "). This will start setTempBasalAbsolute, with calculated value (" + absoluteValue + "). Result might not be 100% correct.");
|
||||||
return setTempBasalAbsolute(absoluteValue, durationInMinutes, profile, enforceNew);
|
return setTempBasalAbsolute(absoluteValue, durationInMinutes, profile, enforceNew);
|
||||||
}
|
}
|
||||||
|
@ -1083,7 +1084,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
if (this.medtronicPumpStatus.basalProfileStatus != BasalProfileStatus.NotInitialized
|
if (this.medtronicPumpStatus.basalProfileStatus != BasalProfileStatus.NotInitialized
|
||||||
&& medtronicHistoryData.hasBasalProfileChanged()) {
|
&& medtronicHistoryData.hasBasalProfileChanged()) {
|
||||||
medtronicHistoryData.processLastBasalProfileChange(medtronicPumpStatus);
|
medtronicHistoryData.processLastBasalProfileChange(pumpDescription.pumpType, medtronicPumpStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
PumpDriverState previousState = this.pumpState;
|
PumpDriverState previousState = this.pumpState;
|
||||||
|
@ -1373,12 +1374,12 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
@NonNull @Override
|
@NonNull @Override
|
||||||
public ManufacturerType manufacturer() {
|
public ManufacturerType manufacturer() {
|
||||||
return medtronicPumpStatus.pumpType.getManufacturer();
|
return pumpDescription.pumpType.getManufacturer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull @Override
|
@NonNull @Override
|
||||||
public PumpType model() {
|
public PumpType model() {
|
||||||
return medtronicPumpStatus.pumpType;
|
return pumpDescription.pumpType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull @Override
|
@NonNull @Override
|
||||||
|
@ -1462,14 +1463,12 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
@NonNull
|
@NonNull
|
||||||
private BasalProfile convertProfileToMedtronicProfile(Profile profile) {
|
private BasalProfile convertProfileToMedtronicProfile(Profile profile) {
|
||||||
|
|
||||||
PumpType pumpType = pumpStatus.pumpType;
|
|
||||||
|
|
||||||
BasalProfile basalProfile = new BasalProfile();
|
BasalProfile basalProfile = new BasalProfile();
|
||||||
|
|
||||||
for (int i = 0; i < 24; i++) {
|
for (int i = 0; i < 24; i++) {
|
||||||
double rate = profile.getBasalTimeFromMidnight(i * 60 * 60);
|
double rate = profile.getBasalTimeFromMidnight(i * 60 * 60);
|
||||||
|
|
||||||
double v = pumpType.determineCorrectBasalSize(rate);
|
double v = pumpDescription.pumpType.determineCorrectBasalSize(rate);
|
||||||
|
|
||||||
BasalProfileEntry basalEntry = new BasalProfileEntry(v, i, 0);
|
BasalProfileEntry basalEntry = new BasalProfileEntry(v, i, 0);
|
||||||
basalProfile.addEntry(basalEntry);
|
basalProfile.addEntry(basalEntry);
|
||||||
|
@ -1516,7 +1515,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
switch (mcat) {
|
switch (mcat) {
|
||||||
|
|
||||||
case WakeUpAndTune: {
|
case WakeUpAndTune: {
|
||||||
if (medtronicPumpStatus.verifyConfiguration()) {
|
if (rileyLinkMedtronicService.verifyConfiguration()) {
|
||||||
ServiceTaskExecutor.startTask(new WakeAndTuneTask(getInjector()));
|
ServiceTaskExecutor.startTask(new WakeAndTuneTask(getInjector()));
|
||||||
} else {
|
} else {
|
||||||
Intent i = new Intent(context, ErrorHelperActivity.class);
|
Intent i = new Intent(context, ErrorHelperActivity.class);
|
||||||
|
|
|
@ -3,7 +3,6 @@ package info.nightscout.androidaps.plugins.pump.medtronic.comm;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
|
||||||
import org.joda.time.LocalDateTime;
|
import org.joda.time.LocalDateTime;
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
@ -13,8 +12,8 @@ import java.util.Map;
|
||||||
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.RileyLinkCommunicationManager;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
||||||
|
@ -29,6 +28,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.WakeAndTuneTask;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.WakeAndTuneTask;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
|
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.RawHistoryPage;
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.RawHistoryPage;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.MedtronicPumpHistoryDecoder;
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.MedtronicPumpHistoryDecoder;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry;
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry;
|
||||||
|
@ -60,9 +60,10 @@ import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||||
*/
|
*/
|
||||||
public class MedtronicCommunicationManager extends RileyLinkCommunicationManager {
|
public class MedtronicCommunicationManager extends RileyLinkCommunicationManager {
|
||||||
|
|
||||||
|
@Inject AAPSLogger aapsLogger;
|
||||||
@Inject MedtronicPumpStatus medtronicPumpStatus;
|
@Inject MedtronicPumpStatus medtronicPumpStatus;
|
||||||
|
@Inject MedtronicPumpPlugin medtronicPumpPlugin;
|
||||||
|
|
||||||
private final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
|
|
||||||
private final int MAX_COMMAND_TRIES = 3;
|
private final int MAX_COMMAND_TRIES = 3;
|
||||||
private final int DEFAULT_TIMEOUT = 2000;
|
private final int DEFAULT_TIMEOUT = 2000;
|
||||||
private final long RILEYLINK_TIMEOUT = 15 * 60 * 1000; // 15 min
|
private final long RILEYLINK_TIMEOUT = 15 * 60 * 1000; // 15 min
|
||||||
|
@ -123,8 +124,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
|
|
||||||
for (int retry = 0; retry < 5; retry++) {
|
for (int retry = 0; retry < 5; retry++) {
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMPBTCOMM, "isDeviceReachable. Waking pump... " + (retry != 0 ? " (retry " + retry + ")" : ""));
|
||||||
LOG.debug("isDeviceReachable. Waking pump... " + (retry != 0 ? " (retry " + retry + ")" : ""));
|
|
||||||
|
|
||||||
boolean connected = connectToDevice();
|
boolean connected = connectToDevice();
|
||||||
|
|
||||||
|
@ -158,11 +158,10 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.ReadSimpleData); // simple
|
byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.ReadSimpleData); // simple
|
||||||
RFSpyResponse rfSpyResponse = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte) 0, (byte) 200,
|
RFSpyResponse rfSpyResponse = 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(rfSpyResponse.getRaw()));
|
||||||
LOG.info("wakeup: raw response is " + ByteUtil.shortHexString(rfSpyResponse.getRaw()));
|
|
||||||
|
|
||||||
if (rfSpyResponse.wasTimeout()) {
|
if (rfSpyResponse.wasTimeout()) {
|
||||||
LOG.error("isDeviceReachable. Failed to find pump (timeout).");
|
aapsLogger.error(LTag.PUMPBTCOMM, "isDeviceReachable. Failed to find pump (timeout).");
|
||||||
} else if (rfSpyResponse.looksLikeRadioPacket()) {
|
} else if (rfSpyResponse.looksLikeRadioPacket()) {
|
||||||
RadioResponse radioResponse = new RadioResponse();
|
RadioResponse radioResponse = new RadioResponse();
|
||||||
|
|
||||||
|
@ -175,12 +174,12 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
PumpMessage pumpResponse = createResponseMessage(radioResponse.getPayload(), PumpMessage.class);
|
PumpMessage pumpResponse = createResponseMessage(radioResponse.getPayload(), PumpMessage.class);
|
||||||
|
|
||||||
if (!pumpResponse.isValid()) {
|
if (!pumpResponse.isValid()) {
|
||||||
LOG.warn("Response is invalid ! [interrupted={}, timeout={}]", rfSpyResponse.wasInterrupted(),
|
aapsLogger.warn(LTag.PUMPBTCOMM, "Response is invalid ! [interrupted={}, timeout={}]", rfSpyResponse.wasInterrupted(),
|
||||||
rfSpyResponse.wasTimeout());
|
rfSpyResponse.wasTimeout());
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// radioResponse.rssi;
|
// radioResponse.rssi;
|
||||||
Object dataResponse = medtronicConverter.convertResponse(MedtronicCommandType.PumpModel,
|
Object dataResponse = medtronicConverter.convertResponse(medtronicPumpPlugin.getPumpDescription().pumpType, MedtronicCommandType.PumpModel,
|
||||||
pumpResponse.getRawContent());
|
pumpResponse.getRawContent());
|
||||||
|
|
||||||
MedtronicDeviceType pumpModel = (MedtronicDeviceType) dataResponse;
|
MedtronicDeviceType pumpModel = (MedtronicDeviceType) dataResponse;
|
||||||
|
@ -190,8 +189,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
MedtronicUtil.getInstance().setMedtronicPumpModel(pumpModel);
|
MedtronicUtil.getInstance().setMedtronicPumpModel(pumpModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMPBTCOMM, "isDeviceReachable. PumpModel is {} - Valid: {} (rssi={})", pumpModel.name(), valid,
|
||||||
LOG.debug("isDeviceReachable. PumpModel is {} - Valid: {} (rssi={})", pumpModel.name(), valid,
|
|
||||||
radioResponse.rssi);
|
radioResponse.rssi);
|
||||||
|
|
||||||
if (valid) {
|
if (valid) {
|
||||||
|
@ -212,17 +210,17 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
LOG.warn("isDeviceReachable. Failed to parse radio response: "
|
aapsLogger.warn(LTag.PUMPBTCOMM, "isDeviceReachable. Failed to parse radio response: "
|
||||||
+ ByteUtil.shortHexString(rfSpyResponse.getRaw()));
|
+ ByteUtil.shortHexString(rfSpyResponse.getRaw()));
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (RileyLinkCommunicationException e) {
|
} catch (RileyLinkCommunicationException e) {
|
||||||
LOG.warn("isDeviceReachable. Failed to decode radio response: "
|
aapsLogger.warn(LTag.PUMPBTCOMM, "isDeviceReachable. Failed to decode radio response: "
|
||||||
+ ByteUtil.shortHexString(rfSpyResponse.getRaw()));
|
+ ByteUtil.shortHexString(rfSpyResponse.getRaw()));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
LOG.warn("isDeviceReachable. Unknown response: " + ByteUtil.shortHexString(rfSpyResponse.getRaw()));
|
aapsLogger.warn(LTag.PUMPBTCOMM, "isDeviceReachable. Unknown response: " + ByteUtil.shortHexString(rfSpyResponse.getRaw()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -238,7 +236,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
private PumpMessage runCommandWithArgs(PumpMessage msg) throws RileyLinkCommunicationException {
|
private PumpMessage runCommandWithArgs(PumpMessage msg) throws RileyLinkCommunicationException {
|
||||||
|
|
||||||
if (debugSetCommands)
|
if (debugSetCommands)
|
||||||
LOG.debug("Run command with Args: ");
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Run command with Args: ");
|
||||||
|
|
||||||
PumpMessage rval;
|
PumpMessage rval;
|
||||||
PumpMessage shortMessage = makePumpMessage(msg.commandType, new CarelinkShortMessageBody(new byte[]{0}));
|
PumpMessage shortMessage = makePumpMessage(msg.commandType, new CarelinkShortMessageBody(new byte[]{0}));
|
||||||
|
@ -246,16 +244,15 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
PumpMessage shortResponse = sendAndListen(shortMessage);
|
PumpMessage shortResponse = sendAndListen(shortMessage);
|
||||||
if (shortResponse.commandType == MedtronicCommandType.CommandACK) {
|
if (shortResponse.commandType == MedtronicCommandType.CommandACK) {
|
||||||
if (debugSetCommands)
|
if (debugSetCommands)
|
||||||
LOG.debug("Run command with Args: Got ACK response");
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Run command with Args: Got ACK response");
|
||||||
|
|
||||||
rval = sendAndListen(msg);
|
rval = sendAndListen(msg);
|
||||||
if (debugSetCommands)
|
if (debugSetCommands)
|
||||||
LOG.debug("2nd Response: {}", rval);
|
aapsLogger.debug(LTag.PUMPBTCOMM, "2nd Response: {}", rval);
|
||||||
|
|
||||||
return rval;
|
return rval;
|
||||||
} else {
|
} else {
|
||||||
if (isLogEnabled())
|
aapsLogger.error(LTag.PUMPBTCOMM, "runCommandWithArgs: Pump did not ack Attention packet");
|
||||||
LOG.error("runCommandWithArgs: Pump did not ack Attention packet");
|
|
||||||
return new PumpMessage("No ACK after Attention packet.");
|
return new PumpMessage("No ACK after Attention packet.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -264,8 +261,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
private PumpMessage runCommandWithFrames(MedtronicCommandType commandType, List<List<Byte>> frames)
|
private PumpMessage runCommandWithFrames(MedtronicCommandType commandType, List<List<Byte>> frames)
|
||||||
throws RileyLinkCommunicationException {
|
throws RileyLinkCommunicationException {
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Run command with Frames: {}", commandType.name());
|
||||||
LOG.debug("Run command with Frames: {}", commandType.name());
|
|
||||||
|
|
||||||
PumpMessage rval = null;
|
PumpMessage rval = null;
|
||||||
PumpMessage shortMessage = makePumpMessage(commandType, new CarelinkShortMessageBody(new byte[]{0}));
|
PumpMessage shortMessage = makePumpMessage(commandType, new CarelinkShortMessageBody(new byte[]{0}));
|
||||||
|
@ -273,13 +269,11 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
PumpMessage shortResponse = sendAndListen(shortMessage);
|
PumpMessage shortResponse = sendAndListen(shortMessage);
|
||||||
|
|
||||||
if (shortResponse.commandType != MedtronicCommandType.CommandACK) {
|
if (shortResponse.commandType != MedtronicCommandType.CommandACK) {
|
||||||
if (isLogEnabled())
|
aapsLogger.error(LTag.PUMPBTCOMM, "runCommandWithFrames: Pump did not ack Attention packet");
|
||||||
LOG.error("runCommandWithFrames: Pump did not ack Attention packet");
|
|
||||||
|
|
||||||
return new PumpMessage("No ACK after start message.");
|
return new PumpMessage("No ACK after start message.");
|
||||||
} else {
|
} else {
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Run command with Frames: Got ACK response for Attention packet");
|
||||||
LOG.debug("Run command with Frames: Got ACK response for Attention packet");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int frameNr = 1;
|
int frameNr = 1;
|
||||||
|
@ -288,24 +282,23 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
|
|
||||||
byte[] frameData = MedtronicUtil.getInstance().createByteArray(frame);
|
byte[] frameData = MedtronicUtil.getInstance().createByteArray(frame);
|
||||||
|
|
||||||
// LOG.debug("Frame {} data:\n{}", frameNr, ByteUtil.getCompactString(frameData));
|
// aapsLogger.debug(LTag.PUMPBTCOMM,"Frame {} data:\n{}", frameNr, ByteUtil.getCompactString(frameData));
|
||||||
|
|
||||||
PumpMessage msg = makePumpMessage(commandType, new CarelinkLongMessageBody(frameData));
|
PumpMessage msg = makePumpMessage(commandType, new CarelinkLongMessageBody(frameData));
|
||||||
|
|
||||||
rval = sendAndListen(msg);
|
rval = sendAndListen(msg);
|
||||||
|
|
||||||
// LOG.debug("PumpResponse: " + rval);
|
// aapsLogger.debug(LTag.PUMPBTCOMM,"PumpResponse: " + rval);
|
||||||
|
|
||||||
if (rval.commandType != MedtronicCommandType.CommandACK) {
|
if (rval.commandType != MedtronicCommandType.CommandACK) {
|
||||||
LOG.error("runCommandWithFrames: Pump did not ACK frame #{}", frameNr);
|
aapsLogger.error(LTag.PUMPBTCOMM, "runCommandWithFrames: Pump did not ACK frame #{}", frameNr);
|
||||||
|
|
||||||
LOG.error("Run command with Frames FAILED (command={}, response={})", commandType.name(),
|
aapsLogger.error(LTag.PUMPBTCOMM, "Run command with Frames FAILED (command={}, response={})", commandType.name(),
|
||||||
rval.toString());
|
rval.toString());
|
||||||
|
|
||||||
return new PumpMessage("No ACK after frame #" + frameNr);
|
return new PumpMessage("No ACK after frame #" + frameNr);
|
||||||
} else {
|
} else {
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Run command with Frames: Got ACK response for frame #{}", (frameNr));
|
||||||
LOG.debug("Run command with Frames: Got ACK response for frame #{}", (frameNr));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
frameNr++;
|
frameNr++;
|
||||||
|
@ -324,8 +317,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
if (doWakeUpBeforeCommand)
|
if (doWakeUpBeforeCommand)
|
||||||
wakeUp(receiverDeviceAwakeForMinutes, false);
|
wakeUp(receiverDeviceAwakeForMinutes, false);
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Current command: " + MedtronicUtil.getInstance().getCurrentCommand());
|
||||||
LOG.debug("Current command: " + MedtronicUtil.getInstance().getCurrentCommand());
|
|
||||||
|
|
||||||
MedtronicUtil.getInstance().setPumpDeviceState(PumpDeviceState.Active);
|
MedtronicUtil.getInstance().setPumpDeviceState(PumpDeviceState.Active);
|
||||||
boolean doneWithError = false;
|
boolean doneWithError = false;
|
||||||
|
@ -337,9 +329,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
PumpMessage getHistoryMsg = makePumpMessage(MedtronicCommandType.GetHistoryData,
|
PumpMessage getHistoryMsg = makePumpMessage(MedtronicCommandType.GetHistoryData,
|
||||||
new GetHistoryPageCarelinkMessageBody(pageNumber));
|
new GetHistoryPageCarelinkMessageBody(pageNumber));
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.info(LTag.PUMPBTCOMM, "getPumpHistory: Page {}", pageNumber);
|
||||||
LOG.info("getPumpHistory: Page {}", pageNumber);
|
// aapsLogger.info(LTag.PUMPBTCOMM,"getPumpHistoryPage("+pageNumber+"): "+ByteUtil.shortHexString(getHistoryMsg.getTxData()));
|
||||||
// LOG.info("getPumpHistoryPage("+pageNumber+"): "+ByteUtil.shortHexString(getHistoryMsg.getTxData()));
|
|
||||||
// Ask the pump to transfer history (we get first frame?)
|
// Ask the pump to transfer history (we get first frame?)
|
||||||
|
|
||||||
PumpMessage firstResponse = null;
|
PumpMessage firstResponse = null;
|
||||||
|
@ -354,8 +345,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
failed = false;
|
failed = false;
|
||||||
break;
|
break;
|
||||||
} catch (RileyLinkCommunicationException e) {
|
} catch (RileyLinkCommunicationException e) {
|
||||||
if (isLogEnabled())
|
aapsLogger.error(LTag.PUMPBTCOMM, "First call for PumpHistory failed (retry={})", retries);
|
||||||
LOG.error("First call for PumpHistory failed (retry={})", retries);
|
|
||||||
failed = true;
|
failed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -365,7 +355,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
return pumpTotalResult;
|
return pumpTotalResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
// LOG.info("getPumpHistoryPage("+pageNumber+"): " + ByteUtil.shortHexString(firstResponse.getContents()));
|
// aapsLogger.info(LTag.PUMPBTCOMM,"getPumpHistoryPage("+pageNumber+"): " + ByteUtil.shortHexString(firstResponse.getContents()));
|
||||||
|
|
||||||
PumpMessage ackMsg = makePumpMessage(MedtronicCommandType.CommandACK, new PumpAckMessageBody());
|
PumpMessage ackMsg = makePumpMessage(MedtronicCommandType.CommandACK, new PumpAckMessageBody());
|
||||||
GetHistoryPageCarelinkMessageBody currentResponse = new GetHistoryPageCarelinkMessageBody(firstResponse
|
GetHistoryPageCarelinkMessageBody currentResponse = new GetHistoryPageCarelinkMessageBody(firstResponse
|
||||||
|
@ -382,8 +372,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
&& currentResponse.getFrameNumber() == expectedFrameNum) {
|
&& currentResponse.getFrameNumber() == expectedFrameNum) {
|
||||||
// success! got a frame.
|
// success! got a frame.
|
||||||
if (frameData.length != 64) {
|
if (frameData.length != 64) {
|
||||||
if (isLogEnabled())
|
aapsLogger.warn(LTag.PUMPBTCOMM, "Expected frame of length 64, got frame of length " + frameData.length);
|
||||||
LOG.warn("Expected frame of length 64, got frame of length " + frameData.length);
|
|
||||||
// but append it anyway?
|
// but append it anyway?
|
||||||
}
|
}
|
||||||
// handle successful frame data
|
// handle successful frame data
|
||||||
|
@ -393,8 +382,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
MedtronicUtil.getInstance().setCurrentCommand(MedtronicCommandType.GetHistoryData, pageNumber,
|
MedtronicUtil.getInstance().setCurrentCommand(MedtronicCommandType.GetHistoryData, pageNumber,
|
||||||
currentResponse.getFrameNumber());
|
currentResponse.getFrameNumber());
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.info(LTag.PUMPBTCOMM, "getPumpHistory: Got frame {} of Page {}", currentResponse.getFrameNumber(), pageNumber);
|
||||||
LOG.info("getPumpHistory: Got frame {} of Page {}", currentResponse.getFrameNumber(), pageNumber);
|
|
||||||
// Do we need to ask for the next frame?
|
// Do we need to ask for the next frame?
|
||||||
if (expectedFrameNum < 16) { // This number may not be correct for pumps other than 522/722
|
if (expectedFrameNum < 16) { // This number may not be correct for pumps other than 522/722
|
||||||
expectedFrameNum++;
|
expectedFrameNum++;
|
||||||
|
@ -403,20 +391,16 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (frameData == null) {
|
if (frameData == null) {
|
||||||
if (isLogEnabled())
|
aapsLogger.error(LTag.PUMPBTCOMM, "null frame data, retrying");
|
||||||
LOG.error("null frame data, retrying");
|
|
||||||
} else if (currentResponse.getFrameNumber() != expectedFrameNum) {
|
} else if (currentResponse.getFrameNumber() != expectedFrameNum) {
|
||||||
if (isLogEnabled())
|
aapsLogger.warn(LTag.PUMPBTCOMM, "Expected frame number {}, received {} (retrying)", expectedFrameNum,
|
||||||
LOG.warn("Expected frame number {}, received {} (retrying)", expectedFrameNum,
|
|
||||||
currentResponse.getFrameNumber());
|
currentResponse.getFrameNumber());
|
||||||
} else if (frameData.length == 0) {
|
} else if (frameData.length == 0) {
|
||||||
if (isLogEnabled())
|
aapsLogger.warn(LTag.PUMPBTCOMM, "Frame has zero length, retrying");
|
||||||
LOG.warn("Frame has zero length, retrying");
|
|
||||||
}
|
}
|
||||||
failures++;
|
failures++;
|
||||||
if (failures == 6) {
|
if (failures == 6) {
|
||||||
if (isLogEnabled())
|
aapsLogger.error(LTag.PUMPBTCOMM,
|
||||||
LOG.error(
|
|
||||||
"getPumpHistory: 6 failures in attempting to download frame {} of page {}, giving up.",
|
"getPumpHistory: 6 failures in attempting to download frame {} of page {}, giving up.",
|
||||||
expectedFrameNum, pageNumber);
|
expectedFrameNum, pageNumber);
|
||||||
done = true; // failure completion.
|
done = true; // failure completion.
|
||||||
|
@ -434,30 +418,26 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
nextMsg = sendAndListen(ackMsg);
|
nextMsg = sendAndListen(ackMsg);
|
||||||
break;
|
break;
|
||||||
} catch (RileyLinkCommunicationException e) {
|
} catch (RileyLinkCommunicationException e) {
|
||||||
if (isLogEnabled())
|
aapsLogger.error(LTag.PUMPBTCOMM, "Problem acknowledging frame response. (retry={})", retries);
|
||||||
LOG.error("Problem acknowledging frame response. (retry={})", retries);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextMsg != null)
|
if (nextMsg != null)
|
||||||
currentResponse = new GetHistoryPageCarelinkMessageBody(nextMsg.getMessageBody().getTxData());
|
currentResponse = new GetHistoryPageCarelinkMessageBody(nextMsg.getMessageBody().getTxData());
|
||||||
else {
|
else {
|
||||||
if (isLogEnabled())
|
aapsLogger.error(LTag.PUMPBTCOMM, "We couldn't acknowledge frame from pump, aborting operation.");
|
||||||
LOG.error("We couldn't acknowledge frame from pump, aborting operation.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rawHistoryPage.getLength() != 1024) {
|
if (rawHistoryPage.getLength() != 1024) {
|
||||||
if (isLogEnabled())
|
aapsLogger.warn(LTag.PUMPBTCOMM, "getPumpHistory: short page. Expected length of 1024, found length of "
|
||||||
LOG.warn("getPumpHistory: short page. Expected length of 1024, found length of "
|
|
||||||
+ rawHistoryPage.getLength());
|
+ rawHistoryPage.getLength());
|
||||||
doneWithError = true;
|
doneWithError = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rawHistoryPage.isChecksumOK()) {
|
if (!rawHistoryPage.isChecksumOK()) {
|
||||||
if (isLogEnabled())
|
aapsLogger.error(LTag.PUMPBTCOMM, "getPumpHistory: checksum is wrong");
|
||||||
LOG.error("getPumpHistory: checksum is wrong");
|
|
||||||
doneWithError = true;
|
doneWithError = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -471,13 +451,11 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
List<PumpHistoryEntry> medtronicHistoryEntries = pumpHistoryDecoder
|
List<PumpHistoryEntry> medtronicHistoryEntries = pumpHistoryDecoder
|
||||||
.processPageAndCreateRecords(rawHistoryPage);
|
.processPageAndCreateRecords(rawHistoryPage);
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMPBTCOMM, "getPumpHistory: Found {} history entries.", medtronicHistoryEntries.size());
|
||||||
LOG.debug("getPumpHistory: Found {} history entries.", medtronicHistoryEntries.size());
|
|
||||||
|
|
||||||
pumpTotalResult.addHistoryEntries(medtronicHistoryEntries, pageNumber);
|
pumpTotalResult.addHistoryEntries(medtronicHistoryEntries, pageNumber);
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMPBTCOMM, "getPumpHistory: Search status: Search finished: {}", pumpTotalResult.isSearchFinished());
|
||||||
LOG.debug("getPumpHistory: Search status: Search finished: {}", pumpTotalResult.isSearchFinished());
|
|
||||||
|
|
||||||
if (pumpTotalResult.isSearchFinished()) {
|
if (pumpTotalResult.isSearchFinished()) {
|
||||||
MedtronicUtil.getInstance().setPumpDeviceState(PumpDeviceState.Sleeping);
|
MedtronicUtil.getInstance().setPumpDeviceState(PumpDeviceState.Sleeping);
|
||||||
|
@ -588,8 +566,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
|
|
||||||
private Object sendAndGetResponseWithCheck(MedtronicCommandType commandType, byte[] bodyData) {
|
private Object sendAndGetResponseWithCheck(MedtronicCommandType commandType, byte[] bodyData) {
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMPBTCOMM, "getDataFromPump: {}", commandType);
|
||||||
LOG.debug("getDataFromPump: {}", commandType);
|
|
||||||
|
|
||||||
for (int retries = 0; retries < MAX_COMMAND_TRIES; retries++) {
|
for (int retries = 0; retries < MAX_COMMAND_TRIES; retries++) {
|
||||||
|
|
||||||
|
@ -603,12 +580,11 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
|
|
||||||
if (check == null) {
|
if (check == null) {
|
||||||
|
|
||||||
Object dataResponse = medtronicConverter.convertResponse(commandType, response.getRawContent());
|
Object dataResponse = medtronicConverter.convertResponse(medtronicPumpPlugin.getPumpDescription().pumpType, commandType, response.getRawContent());
|
||||||
|
|
||||||
if (dataResponse != null) {
|
if (dataResponse != null) {
|
||||||
this.errorMessage = null;
|
this.errorMessage = null;
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Converted response for {} is {}.", commandType.name(), dataResponse);
|
||||||
LOG.debug("Converted response for {} is {}.", commandType.name(), dataResponse);
|
|
||||||
|
|
||||||
return dataResponse;
|
return dataResponse;
|
||||||
} else {
|
} else {
|
||||||
|
@ -620,8 +596,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (RileyLinkCommunicationException e) {
|
} catch (RileyLinkCommunicationException e) {
|
||||||
if (isLogEnabled())
|
aapsLogger.warn(LTag.PUMPBTCOMM, "Error getting response from RileyLink (error={}, retry={})", e.getMessage(), retries + 1);
|
||||||
LOG.warn("Error getting response from RileyLink (error={}, retry={})", e.getMessage(), retries + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -634,8 +609,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
|
|
||||||
if (!response.isValid()) {
|
if (!response.isValid()) {
|
||||||
String responseData = String.format("%s: Invalid response.", method);
|
String responseData = String.format("%s: Invalid response.", method);
|
||||||
if (isLogEnabled())
|
aapsLogger.warn(LTag.PUMPBTCOMM, responseData);
|
||||||
LOG.warn(responseData);
|
|
||||||
return responseData;
|
return responseData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -643,7 +617,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
|
|
||||||
if (contents != null) {
|
if (contents != null) {
|
||||||
if (contents.length >= expectedLength) {
|
if (contents.length >= expectedLength) {
|
||||||
LOG.trace("{}: Content: {}", method, ByteUtil.shortHexString(contents));
|
aapsLogger.debug(LTag.PUMPBTCOMM, "{}: Content: {}", method, ByteUtil.shortHexString(contents));
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -651,13 +625,12 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
"%s: Cannot return data. Data is too short [expected=%s, received=%s].", method, ""
|
"%s: Cannot return data. Data is too short [expected=%s, received=%s].", method, ""
|
||||||
+ expectedLength, "" + contents.length);
|
+ expectedLength, "" + contents.length);
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.warn(LTag.PUMPBTCOMM, responseData);
|
||||||
LOG.warn(responseData);
|
|
||||||
return responseData;
|
return responseData;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String responseData = String.format("%s: Cannot return data. Null response.", method);
|
String responseData = String.format("%s: Cannot return data. Null response.", method);
|
||||||
LOG.warn(responseData);
|
aapsLogger.warn(LTag.PUMPBTCOMM, responseData);
|
||||||
return responseData;
|
return responseData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -689,8 +662,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
|
|
||||||
MedtronicCommandType commandType = MedtronicCommandType.GetBasalProfileSTD;
|
MedtronicCommandType commandType = MedtronicCommandType.GetBasalProfileSTD;
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMPBTCOMM, "getDataFromPump: {}", commandType);
|
||||||
LOG.debug("getDataFromPump: {}", commandType);
|
|
||||||
|
|
||||||
MedtronicUtil.getInstance().setCurrentCommand(commandType);
|
MedtronicUtil.getInstance().setCurrentCommand(commandType);
|
||||||
|
|
||||||
|
@ -709,8 +681,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
|
|
||||||
response = sendAndListen(msg, DEFAULT_TIMEOUT + (DEFAULT_TIMEOUT * retries));
|
response = sendAndListen(msg, DEFAULT_TIMEOUT + (DEFAULT_TIMEOUT * retries));
|
||||||
|
|
||||||
// LOG.debug("1st Response: " + HexDump.toHexStringDisplayable(response.getRawContent()));
|
// aapsLogger.debug(LTag.PUMPBTCOMM,"1st Response: " + HexDump.toHexStringDisplayable(response.getRawContent()));
|
||||||
// LOG.debug("1st Response: " + HexDump.toHexStringDisplayable(response.getMessageBody().getTxData()));
|
// aapsLogger.debug(LTag.PUMPBTCOMM,"1st Response: " + HexDump.toHexStringDisplayable(response.getMessageBody().getTxData()));
|
||||||
|
|
||||||
String check = checkResponseContent(response, commandType.commandDescription, 1);
|
String check = checkResponseContent(response, commandType.commandDescription, 1);
|
||||||
|
|
||||||
|
@ -726,8 +698,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
|
|
||||||
response = sendAndListen(ackMsg, DEFAULT_TIMEOUT + (DEFAULT_TIMEOUT * retries));
|
response = sendAndListen(ackMsg, DEFAULT_TIMEOUT + (DEFAULT_TIMEOUT * retries));
|
||||||
|
|
||||||
// LOG.debug("{} Response: {}", runs, HexDump.toHexStringDisplayable(response2.getRawContent()));
|
// aapsLogger.debug(LTag.PUMPBTCOMM,"{} Response: {}", runs, HexDump.toHexStringDisplayable(response2.getRawContent()));
|
||||||
// LOG.debug("{} Response: {}", runs,
|
// aapsLogger.debug(LTag.PUMPBTCOMM,"{} Response: {}", runs,
|
||||||
// HexDump.toHexStringDisplayable(response2.getMessageBody().getTxData()));
|
// HexDump.toHexStringDisplayable(response2.getMessageBody().getTxData()));
|
||||||
|
|
||||||
String check2 = checkResponseContent(response, commandType.commandDescription, 1);
|
String check2 = checkResponseContent(response, commandType.commandDescription, 1);
|
||||||
|
@ -738,7 +710,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.errorMessage = check2;
|
this.errorMessage = check2;
|
||||||
LOG.error("Error with response got GetProfile: " + check2);
|
aapsLogger.error(LTag.PUMPBTCOMM, "Error with response got GetProfile: " + check2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -746,11 +718,10 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
errorMessage = check;
|
errorMessage = check;
|
||||||
}
|
}
|
||||||
|
|
||||||
BasalProfile basalProfile = (BasalProfile) medtronicConverter.convertResponse(commandType, data);
|
BasalProfile basalProfile = (BasalProfile) medtronicConverter.convertResponse(medtronicPumpPlugin.getPumpDescription().pumpType, commandType, data);
|
||||||
|
|
||||||
if (basalProfile != null) {
|
if (basalProfile != null) {
|
||||||
if (isLogEnabled())
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Converted response for {} is {}.", commandType.name(), basalProfile);
|
||||||
LOG.debug("Converted response for {} is {}.", commandType.name(), basalProfile);
|
|
||||||
|
|
||||||
MedtronicUtil.getInstance().setCurrentCommand(null);
|
MedtronicUtil.getInstance().setCurrentCommand(null);
|
||||||
MedtronicUtil.getInstance().setPumpDeviceState(PumpDeviceState.Sleeping);
|
MedtronicUtil.getInstance().setPumpDeviceState(PumpDeviceState.Sleeping);
|
||||||
|
@ -759,11 +730,11 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (RileyLinkCommunicationException e) {
|
} catch (RileyLinkCommunicationException e) {
|
||||||
LOG.error("Error getting response from RileyLink (error={}, retry={})", e.getMessage(), retries + 1);
|
aapsLogger.error(LTag.PUMPBTCOMM, "Error getting response from RileyLink (error={}, retry={})", e.getMessage(), retries + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.warn("Error reading profile in max retries.");
|
aapsLogger.warn(LTag.PUMPBTCOMM, "Error reading profile in max retries.");
|
||||||
MedtronicUtil.getInstance().setCurrentCommand(null);
|
MedtronicUtil.getInstance().setCurrentCommand(null);
|
||||||
MedtronicUtil.getInstance().setPumpDeviceState(PumpDeviceState.Sleeping);
|
MedtronicUtil.getInstance().setPumpDeviceState(PumpDeviceState.Sleeping);
|
||||||
|
|
||||||
|
@ -781,7 +752,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
|
|
||||||
int last = responseRaw.length - 1;
|
int last = responseRaw.length - 1;
|
||||||
|
|
||||||
LOG.debug("Length: " + data.length);
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Length: " + data.length);
|
||||||
|
|
||||||
if (data.length >= BasalProfile.MAX_RAW_DATA_SIZE) {
|
if (data.length >= BasalProfile.MAX_RAW_DATA_SIZE) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -833,8 +804,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
|
|
||||||
public Boolean setBolus(double units) {
|
public Boolean setBolus(double units) {
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.info(LTag.PUMPBTCOMM, "setBolus: " + units);
|
||||||
LOG.info("setBolus: " + units);
|
|
||||||
|
|
||||||
return setCommand(MedtronicCommandType.SetBolus, MedtronicUtil.getInstance().getBolusStrokes(units));
|
return setCommand(MedtronicCommandType.SetBolus, MedtronicUtil.getInstance().getBolusStrokes(units));
|
||||||
|
|
||||||
|
@ -843,8 +813,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
|
|
||||||
public boolean setTBR(TempBasalPair tbr) {
|
public boolean setTBR(TempBasalPair tbr) {
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.info(LTag.PUMPBTCOMM, "setTBR: " + tbr.getDescription());
|
||||||
LOG.info("setTBR: " + tbr.getDescription());
|
|
||||||
|
|
||||||
return setCommand(MedtronicCommandType.SetTemporaryBasal, tbr.getAsRawData());
|
return setCommand(MedtronicCommandType.SetTemporaryBasal, tbr.getAsRawData());
|
||||||
}
|
}
|
||||||
|
@ -855,8 +824,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
GregorianCalendar gc = new GregorianCalendar();
|
GregorianCalendar gc = new GregorianCalendar();
|
||||||
gc.add(Calendar.SECOND, 5);
|
gc.add(Calendar.SECOND, 5);
|
||||||
|
|
||||||
if (isLogEnabled())
|
aapsLogger.info(LTag.PUMPBTCOMM, "setPumpTime: " + DateTimeUtil.toString(gc));
|
||||||
LOG.info("setPumpTime: " + DateTimeUtil.toString(gc));
|
|
||||||
|
|
||||||
int i = 1;
|
int i = 1;
|
||||||
byte[] data = new byte[8];
|
byte[] data = new byte[8];
|
||||||
|
@ -873,7 +841,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
data[i + 5] = (byte) (gc.get(Calendar.MONTH) + 1);
|
data[i + 5] = (byte) (gc.get(Calendar.MONTH) + 1);
|
||||||
data[i + 6] = (byte) gc.get(Calendar.DAY_OF_MONTH);
|
data[i + 6] = (byte) gc.get(Calendar.DAY_OF_MONTH);
|
||||||
|
|
||||||
//LOG.info("setPumpTime: Body: " + ByteUtil.getHex(data));
|
//aapsLogger.info(LTag.PUMPBTCOMM,"setPumpTime: Body: " + ByteUtil.getHex(data));
|
||||||
|
|
||||||
return setCommand(MedtronicCommandType.SetRealTimeClock, data);
|
return setCommand(MedtronicCommandType.SetRealTimeClock, data);
|
||||||
|
|
||||||
|
@ -889,7 +857,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
wakeUp(false);
|
wakeUp(false);
|
||||||
|
|
||||||
if (debugSetCommands)
|
if (debugSetCommands)
|
||||||
LOG.debug("{}: Body - {}", commandType.getCommandDescription(),
|
aapsLogger.debug(LTag.PUMPBTCOMM, "{}: Body - {}", commandType.getCommandDescription(),
|
||||||
ByteUtil.getHex(body));
|
ByteUtil.getHex(body));
|
||||||
|
|
||||||
PumpMessage msg = makePumpMessage(commandType, new CarelinkLongMessageBody(body));
|
PumpMessage msg = makePumpMessage(commandType, new CarelinkLongMessageBody(body));
|
||||||
|
@ -897,17 +865,16 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
PumpMessage pumpMessage = runCommandWithArgs(msg);
|
PumpMessage pumpMessage = runCommandWithArgs(msg);
|
||||||
|
|
||||||
if (debugSetCommands)
|
if (debugSetCommands)
|
||||||
LOG.debug("{}: {}", commandType.getCommandDescription(), pumpMessage.getResponseContent());
|
aapsLogger.debug(LTag.PUMPBTCOMM, "{}: {}", commandType.getCommandDescription(), pumpMessage.getResponseContent());
|
||||||
|
|
||||||
if (pumpMessage.commandType == MedtronicCommandType.CommandACK) {
|
if (pumpMessage.commandType == MedtronicCommandType.CommandACK) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
LOG.warn("We received non-ACK response from pump: {}", pumpMessage.getResponseContent());
|
aapsLogger.warn(LTag.PUMPBTCOMM, "We received non-ACK response from pump: {}", pumpMessage.getResponseContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (RileyLinkCommunicationException e) {
|
} catch (RileyLinkCommunicationException e) {
|
||||||
if (isLogEnabled())
|
aapsLogger.warn(LTag.PUMPBTCOMM, "Error getting response from RileyLink (error={}, retry={})", e.getMessage(), retries + 1);
|
||||||
LOG.warn("Error getting response from RileyLink (error={}, retry={})", e.getMessage(), retries + 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -943,24 +910,19 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} catch (RileyLinkCommunicationException e) {
|
} catch (RileyLinkCommunicationException e) {
|
||||||
LOG.warn("Error getting response from RileyLink (error={}, retry={})", e.getMessage(), retries + 1);
|
aapsLogger.warn(LTag.PUMPBTCOMM, "Error getting response from RileyLink (error={}, retry={})", e.getMessage(), retries + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (responseMessage != null)
|
if (responseMessage != null)
|
||||||
LOG.warn("Set Basal Profile: Invalid response: commandType={},rawData={}", responseMessage.commandType, ByteUtil.shortHexString(responseMessage.getRawContent()));
|
aapsLogger.warn(LTag.PUMPBTCOMM, "Set Basal Profile: Invalid response: commandType={},rawData={}", responseMessage.commandType, ByteUtil.shortHexString(responseMessage.getRawContent()));
|
||||||
else
|
else
|
||||||
LOG.warn("Set Basal Profile: Null response.");
|
aapsLogger.warn(LTag.PUMPBTCOMM, "Set Basal Profile: Null response.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean isLogEnabled() {
|
|
||||||
return L.isEnabled(L.PUMPCOMM);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public PumpStatus getPumpStatus() {
|
@Override public PumpStatus getPumpStatus() {
|
||||||
return medtronicPumpStatus;
|
return medtronicPumpStatus;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,13 @@ package info.nightscout.androidaps.plugins.pump.medtronic.comm;
|
||||||
import org.joda.time.IllegalFieldValueException;
|
import org.joda.time.IllegalFieldValueException;
|
||||||
import org.joda.time.LocalDateTime;
|
import org.joda.time.LocalDateTime;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
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.defs.PumpType;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
|
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BasalProfile;
|
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BasalProfile;
|
||||||
|
@ -33,7 +33,7 @@ public class MedtronicConverter {
|
||||||
MedtronicDeviceType pumpModel;
|
MedtronicDeviceType pumpModel;
|
||||||
|
|
||||||
|
|
||||||
public Object convertResponse(MedtronicCommandType commandType, byte[] rawContent) {
|
public Object convertResponse(PumpType pumpType, MedtronicCommandType commandType, byte[] rawContent) {
|
||||||
|
|
||||||
if ((rawContent == null || rawContent.length < 1) && commandType != MedtronicCommandType.PumpModel) {
|
if ((rawContent == null || rawContent.length < 1) && commandType != MedtronicCommandType.PumpModel) {
|
||||||
LOG.warn("Content is empty or too short, no data to convert (type={},isNull={},length={})",
|
LOG.warn("Content is empty or too short, no data to convert (type={},isNull={},length={})",
|
||||||
|
@ -67,7 +67,7 @@ public class MedtronicConverter {
|
||||||
case GetBasalProfileSTD:
|
case GetBasalProfileSTD:
|
||||||
case GetBasalProfileA:
|
case GetBasalProfileA:
|
||||||
case GetBasalProfileB: {
|
case GetBasalProfileB: {
|
||||||
return decodeBasalProfile(rawContent);
|
return decodeBasalProfile(pumpType, rawContent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,11 +96,11 @@ public class MedtronicConverter {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private BasalProfile decodeBasalProfile(byte[] rawContent) {
|
private BasalProfile decodeBasalProfile(PumpType pumpType, byte[] rawContent) {
|
||||||
|
|
||||||
BasalProfile basalProfile = new BasalProfile(rawContent);
|
BasalProfile basalProfile = new BasalProfile(rawContent);
|
||||||
|
|
||||||
return basalProfile.verify() ? basalProfile : null;
|
return basalProfile.verify(pumpType) ? basalProfile : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.medtronic.comm.ui;
|
package info.nightscout.androidaps.plugins.pump.medtronic.comm.ui;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
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;
|
||||||
|
@ -20,7 +18,6 @@ public class MedtronicUIComm {
|
||||||
private final MedtronicCommunicationManager medtronicCommunicationManager;
|
private final MedtronicCommunicationManager medtronicCommunicationManager;
|
||||||
private final MedtronicUIPostprocessor medtronicUIPostprocessor;
|
private final MedtronicUIPostprocessor medtronicUIPostprocessor;
|
||||||
|
|
||||||
@Inject
|
|
||||||
public MedtronicUIComm(
|
public MedtronicUIComm(
|
||||||
HasAndroidInjector injector,
|
HasAndroidInjector injector,
|
||||||
AAPSLogger aapsLogger,
|
AAPSLogger aapsLogger,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.medtronic.comm.ui;
|
package info.nightscout.androidaps.plugins.pump.medtronic.comm.ui;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.joda.time.DateTimeZone;
|
import org.joda.time.DateTimeZone;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
|
|
||||||
|
@ -13,6 +12,7 @@ import javax.inject.Singleton;
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BasalProfile;
|
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BasalProfile;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BatteryStatusDTO;
|
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BatteryStatusDTO;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.ClockDTO;
|
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.ClockDTO;
|
||||||
|
@ -32,19 +32,27 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||||
@Singleton
|
@Singleton
|
||||||
public class MedtronicUIPostprocessor {
|
public class MedtronicUIPostprocessor {
|
||||||
|
|
||||||
@NotNull private final AAPSLogger aapsLogger;
|
private final AAPSLogger aapsLogger;
|
||||||
@NotNull private final RxBusWrapper rxBus;
|
private final RxBusWrapper rxBus;
|
||||||
@NotNull private final ResourceHelper resourceHelper;
|
private final ResourceHelper resourceHelper;
|
||||||
@NotNull private final MedtronicUtil medtronicUtil;
|
private final MedtronicUtil medtronicUtil;
|
||||||
@NotNull private final MedtronicPumpStatus medtronicPumpStatus;
|
private final MedtronicPumpStatus medtronicPumpStatus;
|
||||||
|
private final MedtronicPumpPlugin medtronicPumpPlugin;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public MedtronicUIPostprocessor(AAPSLogger aapsLogger, RxBusWrapper rxBus, ResourceHelper resourceHelper, MedtronicUtil medtronicUtil, MedtronicPumpStatus medtronicPumpStatus) {
|
public MedtronicUIPostprocessor(
|
||||||
|
AAPSLogger aapsLogger,
|
||||||
|
RxBusWrapper rxBus,
|
||||||
|
ResourceHelper resourceHelper,
|
||||||
|
MedtronicUtil medtronicUtil,
|
||||||
|
MedtronicPumpStatus medtronicPumpStatus,
|
||||||
|
MedtronicPumpPlugin medtronicPumpPlugin) {
|
||||||
this.aapsLogger = aapsLogger;
|
this.aapsLogger = aapsLogger;
|
||||||
this.rxBus = rxBus;
|
this.rxBus = rxBus;
|
||||||
this.resourceHelper = resourceHelper;
|
this.resourceHelper = resourceHelper;
|
||||||
this.medtronicUtil = medtronicUtil;
|
this.medtronicUtil = medtronicUtil;
|
||||||
this.medtronicPumpStatus = medtronicPumpStatus;
|
this.medtronicPumpStatus = medtronicPumpStatus;
|
||||||
|
this.medtronicPumpPlugin = medtronicPumpPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,7 +68,7 @@ public class MedtronicUIPostprocessor {
|
||||||
if (response) {
|
if (response) {
|
||||||
BasalProfile basalProfile = (BasalProfile) uiTask.getParameter(0);
|
BasalProfile basalProfile = (BasalProfile) uiTask.getParameter(0);
|
||||||
|
|
||||||
medtronicPumpStatus.basalsByHour = basalProfile.getProfilesByHour();
|
medtronicPumpStatus.basalsByHour = basalProfile.getProfilesByHour(medtronicPumpPlugin.getPumpDescription().pumpType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -69,7 +77,7 @@ public class MedtronicUIPostprocessor {
|
||||||
BasalProfile basalProfile = (BasalProfile) uiTask.returnData;
|
BasalProfile basalProfile = (BasalProfile) uiTask.returnData;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Double[] profilesByHour = basalProfile.getProfilesByHour();
|
Double[] profilesByHour = basalProfile.getProfilesByHour(medtronicPumpPlugin.getPumpDescription().pumpType);
|
||||||
|
|
||||||
if (profilesByHour != null) {
|
if (profilesByHour != null) {
|
||||||
medtronicPumpStatus.basalsByHour = profilesByHour;
|
medtronicPumpStatus.basalsByHour = profilesByHour;
|
||||||
|
@ -197,7 +205,7 @@ public class MedtronicUIPostprocessor {
|
||||||
|
|
||||||
PumpSettingDTO checkValue = null;
|
PumpSettingDTO checkValue = null;
|
||||||
|
|
||||||
medtronicPumpStatus.verifyConfiguration();
|
medtronicPumpPlugin.getRileyLinkService().verifyConfiguration();
|
||||||
|
|
||||||
// check profile
|
// check profile
|
||||||
if (!"Yes".equals(settings.get("PCFG_BASAL_PROFILES_ENABLED").value)) {
|
if (!"Yes".equals(settings.get("PCFG_BASAL_PROFILES_ENABLED").value)) {
|
||||||
|
|
|
@ -31,6 +31,7 @@ import info.nightscout.androidaps.interfaces.ActivePluginProvider;
|
||||||
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.general.nsclient.NSUpload;
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||||
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.utils.DateTimeUtil;
|
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
|
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
|
||||||
|
@ -1397,7 +1398,7 @@ public class MedtronicHistoryData {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void processLastBasalProfileChange(MedtronicPumpStatus mdtPumpStatus) {
|
public void processLastBasalProfileChange(PumpType pumpType, MedtronicPumpStatus mdtPumpStatus) {
|
||||||
|
|
||||||
List<PumpHistoryEntry> filteredItems = getFilteredItems(PumpHistoryEntryType.ChangeBasalProfile_NewProfile);
|
List<PumpHistoryEntry> filteredItems = getFilteredItems(PumpHistoryEntryType.ChangeBasalProfile_NewProfile);
|
||||||
|
|
||||||
|
@ -1423,7 +1424,7 @@ public class MedtronicHistoryData {
|
||||||
aapsLogger.debug(LTag.PUMP, "processLastBasalProfileChange. item found, setting new basalProfileLocally: " + newProfile);
|
aapsLogger.debug(LTag.PUMP, "processLastBasalProfileChange. item found, setting new basalProfileLocally: " + newProfile);
|
||||||
BasalProfile basalProfile = (BasalProfile) newProfile.getDecodedData().get("Object");
|
BasalProfile basalProfile = (BasalProfile) newProfile.getDecodedData().get("Object");
|
||||||
|
|
||||||
mdtPumpStatus.basalsByHour = basalProfile.getProfilesByHour();
|
mdtPumpStatus.basalsByHour = basalProfile.getProfilesByHour(pumpType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -278,7 +277,7 @@ public class BasalProfile {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Double[] getProfilesByHour() {
|
public Double[] getProfilesByHour(PumpType pumpType) {
|
||||||
|
|
||||||
List<BasalProfileEntry> entries = null;
|
List<BasalProfileEntry> entries = null;
|
||||||
|
|
||||||
|
@ -305,8 +304,6 @@ public class BasalProfile {
|
||||||
|
|
||||||
Double[] basalByHour = new Double[24];
|
Double[] basalByHour = new Double[24];
|
||||||
|
|
||||||
PumpType pumpType = MedtronicPumpPlugin.getPlugin().getMedtronicPumpStatus().pumpType;
|
|
||||||
|
|
||||||
for (int i = 0; i < entries.size(); i++) {
|
for (int i = 0; i < entries.size(); i++) {
|
||||||
BasalProfileEntry current = entries.get(i);
|
BasalProfileEntry current = entries.get(i);
|
||||||
|
|
||||||
|
@ -368,7 +365,7 @@ public class BasalProfile {
|
||||||
return L.isEnabled(L.PUMPCOMM);
|
return L.isEnabled(L.PUMPCOMM);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean verify() {
|
public boolean verify(PumpType pumpType) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
getEntries();
|
getEntries();
|
||||||
|
@ -376,7 +373,7 @@ public class BasalProfile {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Double[] profilesByHour = getProfilesByHour();
|
Double[] profilesByHour = getProfilesByHour(pumpType);
|
||||||
|
|
||||||
for (Double aDouble : profilesByHour) {
|
for (Double aDouble : profilesByHour) {
|
||||||
if (aDouble > 35.0d)
|
if (aDouble > 35.0d)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.medtronic.driver;
|
package info.nightscout.androidaps.plugins.pump.medtronic.driver;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
@ -9,25 +11,15 @@ import java.util.Map;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
|
||||||
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.defs.PumpType;
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkEncodingType;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkTargetFrequency;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
|
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.RileyLinkServiceState;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.BasalProfileStatus;
|
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.BatteryType;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType;
|
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
|
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
||||||
|
|
||||||
|
@ -38,17 +30,14 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
||||||
@Singleton
|
@Singleton
|
||||||
public class MedtronicPumpStatus extends PumpStatus {
|
public class MedtronicPumpStatus extends PumpStatus {
|
||||||
|
|
||||||
private final AAPSLogger aapsLogger;
|
|
||||||
private final ResourceHelper resourceHelper;
|
private final ResourceHelper resourceHelper;
|
||||||
private final SP sp;
|
private final SP sp;
|
||||||
|
|
||||||
private String errorDescription = null;
|
public String errorDescription = null;
|
||||||
public String serialNumber;
|
public String serialNumber;
|
||||||
public String pumpFrequency = null;
|
public String pumpFrequency = null;
|
||||||
private String rileyLinkAddress = null;
|
|
||||||
public Double maxBolus;
|
public Double maxBolus;
|
||||||
public Double maxBasal;
|
public Double maxBasal;
|
||||||
private boolean inPreInit = true;
|
|
||||||
|
|
||||||
// statuses
|
// statuses
|
||||||
public RileyLinkServiceState rileyLinkServiceState = RileyLinkServiceState.NotStarted;
|
public RileyLinkServiceState rileyLinkServiceState = RileyLinkServiceState.NotStarted;
|
||||||
|
@ -65,32 +54,18 @@ public class MedtronicPumpStatus extends PumpStatus {
|
||||||
// fixme
|
// fixme
|
||||||
public Integer tempBasalLength = 0;
|
public Integer tempBasalLength = 0;
|
||||||
|
|
||||||
private String regexMac = "([\\da-fA-F]{1,2}(?:\\:|$)){6}";
|
|
||||||
private String regexSN = "[0-9]{6}";
|
|
||||||
|
|
||||||
private boolean serialChanged = false;
|
|
||||||
private boolean rileyLinkAddressChanged = false;
|
|
||||||
private boolean encodingChanged = false;
|
|
||||||
private boolean targetFrequencyChanged = false;
|
|
||||||
|
|
||||||
private RileyLinkEncodingType encodingType;
|
|
||||||
private String[] frequencies;
|
|
||||||
private boolean isFrequencyUS = false;
|
|
||||||
private Map<String, PumpType> medtronicPumpMap = null;
|
private Map<String, PumpType> medtronicPumpMap = null;
|
||||||
private Map<String, MedtronicDeviceType> medtronicDeviceTypeMap = null;
|
private Map<String, MedtronicDeviceType> medtronicDeviceTypeMap = null;
|
||||||
private RileyLinkTargetFrequency targetFrequency;
|
|
||||||
public BasalProfileStatus basalProfileStatus = BasalProfileStatus.NotInitialized;
|
public BasalProfileStatus basalProfileStatus = BasalProfileStatus.NotInitialized;
|
||||||
public BatteryType batteryType = BatteryType.None;
|
public BatteryType batteryType = BatteryType.None;
|
||||||
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public MedtronicPumpStatus(
|
public MedtronicPumpStatus(
|
||||||
AAPSLogger aapsLogger,
|
|
||||||
ResourceHelper resourceHelper,
|
ResourceHelper resourceHelper,
|
||||||
SP sp
|
SP sp
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
this.aapsLogger = aapsLogger;
|
|
||||||
this.resourceHelper = resourceHelper;
|
this.resourceHelper = resourceHelper;
|
||||||
this.sp = sp;
|
this.sp = sp;
|
||||||
initSettings();
|
initSettings();
|
||||||
|
@ -145,241 +120,15 @@ public class MedtronicPumpStatus extends PumpStatus {
|
||||||
medtronicPumpMap.put("554", PumpType.Medtronic_554_754_Veo);
|
medtronicPumpMap.put("554", PumpType.Medtronic_554_754_Veo);
|
||||||
medtronicPumpMap.put("754", PumpType.Medtronic_554_754_Veo);
|
medtronicPumpMap.put("754", PumpType.Medtronic_554_754_Veo);
|
||||||
|
|
||||||
frequencies = new String[2];
|
|
||||||
frequencies[0] = resourceHelper.gs(R.string.key_medtronic_pump_frequency_us_ca);
|
|
||||||
frequencies[1] = resourceHelper.gs(R.string.key_medtronic_pump_frequency_worldwide);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, PumpType> getMedtronicPumpMap() {
|
||||||
public boolean verifyConfiguration() {
|
return medtronicPumpMap;
|
||||||
try {
|
|
||||||
|
|
||||||
// FIXME don't reload information several times
|
|
||||||
if (this.medtronicPumpMap == null)
|
|
||||||
createMedtronicPumpMap();
|
|
||||||
|
|
||||||
if (this.medtronicDeviceTypeMap == null)
|
|
||||||
createMedtronicDeviceTypeMap();
|
|
||||||
|
|
||||||
this.errorDescription = "-";
|
|
||||||
|
|
||||||
String serialNr = sp.getStringOrNull(MedtronicConst.Prefs.PumpSerial, null);
|
|
||||||
|
|
||||||
if (serialNr == null) {
|
|
||||||
this.errorDescription = resourceHelper.gs(R.string.medtronic_error_serial_not_set);
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
if (!serialNr.matches(regexSN)) {
|
|
||||||
this.errorDescription = resourceHelper.gs(R.string.medtronic_error_serial_invalid);
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
if (!serialNr.equals(this.serialNumber)) {
|
|
||||||
this.serialNumber = serialNr;
|
|
||||||
serialChanged = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String pumpType = sp.getStringOrNull(MedtronicConst.Prefs.PumpType, null);
|
public Map<String, MedtronicDeviceType> getMedtronicDeviceTypeMap() {
|
||||||
|
return medtronicDeviceTypeMap;
|
||||||
if (pumpType == null) {
|
|
||||||
this.errorDescription = resourceHelper.gs(R.string.medtronic_error_pump_type_not_set);
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
String pumpTypePart = pumpType.substring(0, 3);
|
|
||||||
|
|
||||||
if (!pumpTypePart.matches("[0-9]{3}")) {
|
|
||||||
this.errorDescription = resourceHelper.gs(R.string.medtronic_error_pump_type_invalid);
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
this.pumpType = medtronicPumpMap.get(pumpTypePart);
|
|
||||||
this.medtronicDeviceType = medtronicDeviceTypeMap.get(pumpTypePart);
|
|
||||||
MedtronicPumpPlugin.getPlugin().getPumpDescription().setPumpDescription(this.pumpType);
|
|
||||||
|
|
||||||
if (pumpTypePart.startsWith("7"))
|
|
||||||
this.reservoirFullUnits = 300;
|
|
||||||
else
|
|
||||||
this.reservoirFullUnits = 176;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
String pumpFrequency = sp.getStringOrNull(MedtronicConst.Prefs.PumpFrequency, null);
|
|
||||||
|
|
||||||
if (pumpFrequency == null) {
|
|
||||||
this.errorDescription = resourceHelper.gs(R.string.medtronic_error_pump_frequency_not_set);
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
if (!pumpFrequency.equals(frequencies[0]) && !pumpFrequency.equals(frequencies[1])) {
|
|
||||||
this.errorDescription = resourceHelper.gs(R.string.medtronic_error_pump_frequency_invalid);
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
this.pumpFrequency = pumpFrequency;
|
|
||||||
this.isFrequencyUS = pumpFrequency.equals(frequencies[0]);
|
|
||||||
|
|
||||||
RileyLinkTargetFrequency newTargetFrequency = this.isFrequencyUS ? //
|
|
||||||
RileyLinkTargetFrequency.Medtronic_US
|
|
||||||
: RileyLinkTargetFrequency.Medtronic_WorldWide;
|
|
||||||
|
|
||||||
if (targetFrequency != newTargetFrequency) {
|
|
||||||
RileyLinkUtil.getInstance().setRileyLinkTargetFrequency(newTargetFrequency);
|
|
||||||
targetFrequency = newTargetFrequency;
|
|
||||||
targetFrequencyChanged = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String rileyLinkAddress = sp.getStringOrNull(RileyLinkConst.Prefs.RileyLinkAddress, null);
|
|
||||||
|
|
||||||
if (rileyLinkAddress == null) {
|
|
||||||
aapsLogger.debug(LTag.PUMP, "RileyLink address invalid: null");
|
|
||||||
this.errorDescription = resourceHelper.gs(R.string.medtronic_error_rileylink_address_invalid);
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
if (!rileyLinkAddress.matches(regexMac)) {
|
|
||||||
this.errorDescription = resourceHelper.gs(R.string.medtronic_error_rileylink_address_invalid);
|
|
||||||
aapsLogger.debug(LTag.PUMP, "RileyLink address invalid: {}", rileyLinkAddress);
|
|
||||||
} else {
|
|
||||||
if (!rileyLinkAddress.equals(this.rileyLinkAddress)) {
|
|
||||||
this.rileyLinkAddress = rileyLinkAddress;
|
|
||||||
rileyLinkAddressChanged = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double maxBolusLcl = checkParameterValue(MedtronicConst.Prefs.MaxBolus, "25.0", 25.0d);
|
|
||||||
|
|
||||||
if (maxBolus == null || !maxBolus.equals(maxBolusLcl)) {
|
|
||||||
maxBolus = maxBolusLcl;
|
|
||||||
|
|
||||||
//LOG.debug("Max Bolus from AAPS settings is " + maxBolus);
|
|
||||||
}
|
|
||||||
|
|
||||||
double maxBasalLcl = checkParameterValue(MedtronicConst.Prefs.MaxBasal, "35.0", 35.0d);
|
|
||||||
|
|
||||||
if (maxBasal == null || !maxBasal.equals(maxBasalLcl)) {
|
|
||||||
maxBasal = maxBasalLcl;
|
|
||||||
|
|
||||||
//LOG.debug("Max Basal from AAPS settings is " + maxBasal);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
String encodingTypeStr = sp.getStringOrNull(MedtronicConst.Prefs.Encoding, null);
|
|
||||||
|
|
||||||
if (encodingTypeStr == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
RileyLinkEncodingType newEncodingType = RileyLinkEncodingType.getByDescription(encodingTypeStr);
|
|
||||||
|
|
||||||
if (this.encodingType == null) {
|
|
||||||
this.encodingType = newEncodingType;
|
|
||||||
} else if (this.encodingType != newEncodingType) {
|
|
||||||
this.encodingType = newEncodingType;
|
|
||||||
this.encodingChanged = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
String batteryTypeStr = sp.getStringOrNull(MedtronicConst.Prefs.BatteryType, null);
|
|
||||||
|
|
||||||
if (batteryTypeStr == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
BatteryType batteryType = getBatteryTypeByDescription(batteryTypeStr);
|
|
||||||
|
|
||||||
if (this.batteryType != batteryType) {
|
|
||||||
this.batteryType = batteryType;
|
|
||||||
MedtronicUtil.getInstance().setBatteryType(this.batteryType);
|
|
||||||
}
|
|
||||||
|
|
||||||
String bolusDebugEnabled = sp.getStringOrNull(MedtronicConst.Prefs.BolusDebugEnabled, null);
|
|
||||||
|
|
||||||
boolean bolusDebug = bolusDebugEnabled != null && bolusDebugEnabled.equals(resourceHelper.gs(R.string.common_on));
|
|
||||||
|
|
||||||
MedtronicHistoryData.doubleBolusDebug = bolusDebug;
|
|
||||||
|
|
||||||
reconfigureService();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
} catch (Exception ex) {
|
|
||||||
this.errorDescription = ex.getMessage();
|
|
||||||
aapsLogger.error(LTag.PUMP, "Error on Verification: " + ex.getMessage(), ex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private boolean reconfigureService() {
|
|
||||||
|
|
||||||
if (!inPreInit && MedtronicUtil.getInstance().getMedtronicService() != null) {
|
|
||||||
|
|
||||||
if (serialChanged) {
|
|
||||||
MedtronicUtil.getInstance().getMedtronicService().setPumpIDString(this.serialNumber); // short operation
|
|
||||||
serialChanged = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rileyLinkAddressChanged) {
|
|
||||||
RileyLinkUtil.getInstance().sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet);
|
|
||||||
rileyLinkAddressChanged = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (encodingChanged) {
|
|
||||||
RileyLinkUtil.getInstance().getRileyLinkService().changeRileyLinkEncoding(encodingType);
|
|
||||||
encodingChanged = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// if (targetFrequencyChanged && !inPreInit && MedtronicUtil.getMedtronicService() != null) {
|
|
||||||
// RileyLinkUtil.setRileyLinkTargetFrequency(targetFrequency);
|
|
||||||
// // RileyLinkUtil.getRileyLinkCommunicationManager().refreshRileyLinkTargetFrequency();
|
|
||||||
// targetFrequencyChanged = false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
return (!rileyLinkAddressChanged && !serialChanged && !encodingChanged); // && !targetFrequencyChanged);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private double checkParameterValue(int key, String defaultValue, double defaultValueDouble) {
|
|
||||||
double val = 0.0d;
|
|
||||||
|
|
||||||
String value = sp.getString(key, defaultValue);
|
|
||||||
|
|
||||||
try {
|
|
||||||
val = Double.parseDouble(value);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
aapsLogger.error("Error parsing setting: {}, value found {}", key, value);
|
|
||||||
val = defaultValueDouble;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (val > defaultValueDouble) {
|
|
||||||
sp.putString(key, defaultValue);
|
|
||||||
val = defaultValueDouble;
|
|
||||||
}
|
|
||||||
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getErrorInfo() {
|
|
||||||
verifyConfiguration();
|
|
||||||
|
|
||||||
return (this.errorDescription == null) ? "-" : this.errorDescription;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refreshConfiguration() {
|
|
||||||
verifyConfiguration();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public boolean setNotInPreInit() {
|
|
||||||
this.inPreInit = false;
|
|
||||||
|
|
||||||
return reconfigureService();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public double getBasalProfileForHour() {
|
public double getBasalProfileForHour() {
|
||||||
if (basalsByHour != null) {
|
if (basalsByHour != null) {
|
||||||
|
@ -395,7 +144,7 @@ public class MedtronicPumpStatus extends PumpStatus {
|
||||||
// Battery type
|
// Battery type
|
||||||
private Map<String, BatteryType> mapByDescription;
|
private Map<String, BatteryType> mapByDescription;
|
||||||
|
|
||||||
private BatteryType getBatteryTypeByDescription(String batteryTypeStr) {
|
public BatteryType getBatteryTypeByDescription(String batteryTypeStr) {
|
||||||
if (mapByDescription == null) {
|
if (mapByDescription == null) {
|
||||||
mapByDescription = new HashMap<>();
|
mapByDescription = new HashMap<>();
|
||||||
for (BatteryType value : BatteryType.values()) {
|
for (BatteryType value : BatteryType.values()) {
|
||||||
|
@ -408,4 +157,8 @@ public class MedtronicPumpStatus extends PumpStatus {
|
||||||
return BatteryType.None;
|
return BatteryType.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public String getErrorInfo() {
|
||||||
|
return (errorDescription == null) ? "-" : errorDescription;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,14 @@ import android.os.IBinder;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector;
|
import dagger.android.HasAndroidInjector;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
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.defs.PumpType;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkBLE;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkBLE;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkEncodingType;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkEncodingType;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkTargetFrequency;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
|
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.defs.RileyLinkTargetDevice;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkService;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkService;
|
||||||
|
@ -24,9 +26,13 @@ import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager;
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUIComm;
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUIComm;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUIPostprocessor;
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUIPostprocessor;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
|
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RileyLinkMedtronicService is intended to stay running when the gui-app is closed.
|
* RileyLinkMedtronicService is intended to stay running when the gui-app is closed.
|
||||||
|
@ -34,15 +40,26 @@ import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||||
public class RileyLinkMedtronicService extends RileyLinkService {
|
public class RileyLinkMedtronicService extends RileyLinkService {
|
||||||
|
|
||||||
@Inject HasAndroidInjector injector;
|
@Inject HasAndroidInjector injector;
|
||||||
|
@Inject ResourceHelper resourceHelper;
|
||||||
@Inject MedtronicPumpPlugin medtronicPumpPlugin;
|
@Inject MedtronicPumpPlugin medtronicPumpPlugin;
|
||||||
@Inject MedtronicUtil medtronicUtil;
|
@Inject MedtronicUtil medtronicUtil;
|
||||||
@Inject MedtronicUIPostprocessor medtronicUIPostprocessor;
|
@Inject MedtronicUIPostprocessor medtronicUIPostprocessor;
|
||||||
|
@Inject MedtronicPumpStatus medtronicPumpStatus;
|
||||||
|
|
||||||
|
|
||||||
private MedtronicUIComm medtronicUIComm;
|
private MedtronicUIComm medtronicUIComm;
|
||||||
private MedtronicCommunicationManager medtronicCommunicationManager;
|
private MedtronicCommunicationManager medtronicCommunicationManager;
|
||||||
private IBinder mBinder = new LocalBinder();
|
private IBinder mBinder = new LocalBinder();
|
||||||
|
|
||||||
|
private boolean serialChanged = false;
|
||||||
|
private String[] frequencies;
|
||||||
|
private RileyLinkTargetFrequency targetFrequency;
|
||||||
|
private String rileyLinkAddress = null;
|
||||||
|
private boolean rileyLinkAddressChanged = false;
|
||||||
|
private RileyLinkEncodingType encodingType;
|
||||||
|
private boolean encodingChanged = false;
|
||||||
|
private boolean inPreInit = true;
|
||||||
|
|
||||||
|
|
||||||
public RileyLinkMedtronicService() {
|
public RileyLinkMedtronicService() {
|
||||||
super();
|
super();
|
||||||
|
@ -73,6 +90,10 @@ public class RileyLinkMedtronicService extends RileyLinkService {
|
||||||
*/
|
*/
|
||||||
public void initRileyLinkServiceData() {
|
public void initRileyLinkServiceData() {
|
||||||
|
|
||||||
|
frequencies = new String[2];
|
||||||
|
frequencies[0] = resourceHelper.gs(R.string.key_medtronic_pump_frequency_us_ca);
|
||||||
|
frequencies[1] = resourceHelper.gs(R.string.key_medtronic_pump_frequency_worldwide);
|
||||||
|
|
||||||
rileyLinkServiceData = new RileyLinkServiceData(RileyLinkTargetDevice.MedtronicPump);
|
rileyLinkServiceData = new RileyLinkServiceData(RileyLinkTargetDevice.MedtronicPump);
|
||||||
|
|
||||||
rileyLinkUtil.setRileyLinkServiceData(rileyLinkServiceData);
|
rileyLinkUtil.setRileyLinkServiceData(rileyLinkServiceData);
|
||||||
|
@ -185,4 +206,210 @@ public class RileyLinkMedtronicService extends RileyLinkService {
|
||||||
@Override
|
@Override
|
||||||
public void registerDeviceSpecificBroadcasts(IntentFilter intentFilter) {
|
public void registerDeviceSpecificBroadcasts(IntentFilter intentFilter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean verifyConfiguration() {
|
||||||
|
try {
|
||||||
|
String regexSN = "[0-9]{6}";
|
||||||
|
String regexMac = "([\\da-fA-F]{1,2}(?:\\:|$)){6}";
|
||||||
|
|
||||||
|
medtronicPumpStatus.errorDescription = "-";
|
||||||
|
|
||||||
|
String serialNr = sp.getStringOrNull(MedtronicConst.Prefs.PumpSerial, null);
|
||||||
|
|
||||||
|
if (serialNr == null) {
|
||||||
|
medtronicPumpStatus.errorDescription = resourceHelper.gs(R.string.medtronic_error_serial_not_set);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (!serialNr.matches(regexSN)) {
|
||||||
|
medtronicPumpStatus.errorDescription = resourceHelper.gs(R.string.medtronic_error_serial_invalid);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (!serialNr.equals(medtronicPumpStatus.serialNumber)) {
|
||||||
|
medtronicPumpStatus.serialNumber = serialNr;
|
||||||
|
serialChanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String pumpTypePref = sp.getStringOrNull(MedtronicConst.Prefs.PumpType, null);
|
||||||
|
|
||||||
|
if (pumpTypePref == null) {
|
||||||
|
medtronicPumpStatus.errorDescription = resourceHelper.gs(R.string.medtronic_error_pump_type_not_set);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
String pumpTypePart = pumpTypePref.substring(0, 3);
|
||||||
|
|
||||||
|
if (!pumpTypePart.matches("[0-9]{3}")) {
|
||||||
|
medtronicPumpStatus.errorDescription = resourceHelper.gs(R.string.medtronic_error_pump_type_invalid);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
PumpType pumpType = medtronicPumpStatus.getMedtronicPumpMap().get(pumpTypePart);
|
||||||
|
medtronicPumpStatus.medtronicDeviceType = medtronicPumpStatus.getMedtronicDeviceTypeMap().get(pumpTypePart);
|
||||||
|
medtronicPumpPlugin.getPumpDescription().setPumpDescription(pumpType);
|
||||||
|
|
||||||
|
if (pumpTypePart.startsWith("7"))
|
||||||
|
medtronicPumpStatus.reservoirFullUnits = 300;
|
||||||
|
else
|
||||||
|
medtronicPumpStatus.reservoirFullUnits = 176;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String pumpFrequency = sp.getStringOrNull(MedtronicConst.Prefs.PumpFrequency, null);
|
||||||
|
|
||||||
|
if (pumpFrequency == null) {
|
||||||
|
medtronicPumpStatus.errorDescription = resourceHelper.gs(R.string.medtronic_error_pump_frequency_not_set);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (!pumpFrequency.equals(frequencies[0]) && !pumpFrequency.equals(frequencies[1])) {
|
||||||
|
medtronicPumpStatus.errorDescription = resourceHelper.gs(R.string.medtronic_error_pump_frequency_invalid);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
medtronicPumpStatus.pumpFrequency = pumpFrequency;
|
||||||
|
boolean isFrequencyUS = pumpFrequency.equals(frequencies[0]);
|
||||||
|
|
||||||
|
RileyLinkTargetFrequency newTargetFrequency = isFrequencyUS ? //
|
||||||
|
RileyLinkTargetFrequency.Medtronic_US
|
||||||
|
: RileyLinkTargetFrequency.Medtronic_WorldWide;
|
||||||
|
|
||||||
|
if (targetFrequency != newTargetFrequency) {
|
||||||
|
rileyLinkUtil.setRileyLinkTargetFrequency(newTargetFrequency);
|
||||||
|
targetFrequency = newTargetFrequency;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String rileyLinkAddress = sp.getStringOrNull(RileyLinkConst.Prefs.RileyLinkAddress, null);
|
||||||
|
|
||||||
|
if (rileyLinkAddress == null) {
|
||||||
|
aapsLogger.debug(LTag.PUMP, "RileyLink address invalid: null");
|
||||||
|
medtronicPumpStatus.errorDescription = resourceHelper.gs(R.string.medtronic_error_rileylink_address_invalid);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (!rileyLinkAddress.matches(regexMac)) {
|
||||||
|
medtronicPumpStatus.errorDescription = resourceHelper.gs(R.string.medtronic_error_rileylink_address_invalid);
|
||||||
|
aapsLogger.debug(LTag.PUMP, "RileyLink address invalid: {}", rileyLinkAddress);
|
||||||
|
} else {
|
||||||
|
if (!rileyLinkAddress.equals(this.rileyLinkAddress)) {
|
||||||
|
this.rileyLinkAddress = rileyLinkAddress;
|
||||||
|
rileyLinkAddressChanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double maxBolusLcl = checkParameterValue(MedtronicConst.Prefs.MaxBolus, "25.0", 25.0d);
|
||||||
|
|
||||||
|
if (medtronicPumpStatus.maxBolus == null || !medtronicPumpStatus.maxBolus.equals(maxBolusLcl)) {
|
||||||
|
medtronicPumpStatus.maxBolus = maxBolusLcl;
|
||||||
|
|
||||||
|
//LOG.debug("Max Bolus from AAPS settings is " + maxBolus);
|
||||||
|
}
|
||||||
|
|
||||||
|
double maxBasalLcl = checkParameterValue(MedtronicConst.Prefs.MaxBasal, "35.0", 35.0d);
|
||||||
|
|
||||||
|
if (medtronicPumpStatus.maxBasal == null || !medtronicPumpStatus.maxBasal.equals(maxBasalLcl)) {
|
||||||
|
medtronicPumpStatus.maxBasal = maxBasalLcl;
|
||||||
|
|
||||||
|
//LOG.debug("Max Basal from AAPS settings is " + maxBasal);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String encodingTypeStr = sp.getStringOrNull(MedtronicConst.Prefs.Encoding, null);
|
||||||
|
|
||||||
|
if (encodingTypeStr == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
RileyLinkEncodingType newEncodingType = RileyLinkEncodingType.getByDescription(encodingTypeStr);
|
||||||
|
|
||||||
|
if (encodingType == null) {
|
||||||
|
encodingType = newEncodingType;
|
||||||
|
} else if (encodingType != newEncodingType) {
|
||||||
|
encodingType = newEncodingType;
|
||||||
|
encodingChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String batteryTypeStr = sp.getStringOrNull(MedtronicConst.Prefs.BatteryType, null);
|
||||||
|
|
||||||
|
if (batteryTypeStr == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
BatteryType batteryType = medtronicPumpStatus.getBatteryTypeByDescription(batteryTypeStr);
|
||||||
|
|
||||||
|
if (medtronicPumpStatus.batteryType != batteryType) {
|
||||||
|
medtronicPumpStatus.batteryType = batteryType;
|
||||||
|
}
|
||||||
|
|
||||||
|
String bolusDebugEnabled = sp.getStringOrNull(MedtronicConst.Prefs.BolusDebugEnabled, null);
|
||||||
|
|
||||||
|
boolean bolusDebug = bolusDebugEnabled != null && bolusDebugEnabled.equals(resourceHelper.gs(R.string.common_on));
|
||||||
|
|
||||||
|
MedtronicHistoryData.doubleBolusDebug = bolusDebug;
|
||||||
|
|
||||||
|
reconfigureService();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
medtronicPumpStatus.errorDescription = ex.getMessage();
|
||||||
|
aapsLogger.error(LTag.PUMP, "Error on Verification: " + ex.getMessage(), ex);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean reconfigureService() {
|
||||||
|
|
||||||
|
if (!inPreInit) {
|
||||||
|
|
||||||
|
if (serialChanged) {
|
||||||
|
setPumpIDString(medtronicPumpStatus.serialNumber); // short operation
|
||||||
|
serialChanged = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rileyLinkAddressChanged) {
|
||||||
|
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet);
|
||||||
|
rileyLinkAddressChanged = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (encodingChanged) {
|
||||||
|
changeRileyLinkEncoding(encodingType);
|
||||||
|
encodingChanged = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// if (targetFrequencyChanged && !inPreInit && MedtronicUtil.getMedtronicService() != null) {
|
||||||
|
// RileyLinkUtil.setRileyLinkTargetFrequency(targetFrequency);
|
||||||
|
// // RileyLinkUtil.getRileyLinkCommunicationManager().refreshRileyLinkTargetFrequency();
|
||||||
|
// targetFrequencyChanged = false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
return (!rileyLinkAddressChanged && !serialChanged && !encodingChanged); // && !targetFrequencyChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
private double checkParameterValue(int key, String defaultValue, double defaultValueDouble) {
|
||||||
|
double val;
|
||||||
|
|
||||||
|
String value = sp.getString(key, defaultValue);
|
||||||
|
|
||||||
|
try {
|
||||||
|
val = Double.parseDouble(value);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
aapsLogger.error("Error parsing setting: {}, value found {}", key, value);
|
||||||
|
val = defaultValueDouble;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (val > defaultValueDouble) {
|
||||||
|
sp.putString(key, defaultValue);
|
||||||
|
val = defaultValueDouble;
|
||||||
|
}
|
||||||
|
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean setNotInPreInit() {
|
||||||
|
this.inPreInit = false;
|
||||||
|
|
||||||
|
return reconfigureService();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,6 @@ public class MedtronicUtil {
|
||||||
private ClockDTO pumpTime;
|
private ClockDTO pumpTime;
|
||||||
public Gson gsonInstance = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
public Gson gsonInstance = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
||||||
public Gson gsonInstanceCore = new GsonBuilder().create();
|
public Gson gsonInstanceCore = new GsonBuilder().create();
|
||||||
private BatteryType batteryType = BatteryType.None;
|
|
||||||
|
|
||||||
@NotNull private final AAPSLogger aapsLogger;
|
@NotNull private final AAPSLogger aapsLogger;
|
||||||
@NotNull private final RxBusWrapper rxBus;
|
@NotNull private final RxBusWrapper rxBus;
|
||||||
|
@ -507,29 +506,15 @@ public class MedtronicUtil {
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setSettings(Map<String, PumpSettingDTO> settings) {
|
public void setSettings(Map<String, PumpSettingDTO> settings) {
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setPumpTime(ClockDTO pumpTime) {
|
public void setPumpTime(ClockDTO pumpTime) {
|
||||||
this.pumpTime = pumpTime;
|
this.pumpTime = pumpTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ClockDTO getPumpTime() {
|
public ClockDTO getPumpTime() {
|
||||||
return this.pumpTime;
|
return this.pumpTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBatteryType(BatteryType batteryType) {
|
|
||||||
this.batteryType = batteryType;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public BatteryType getBatteryType() {
|
|
||||||
return this.batteryType;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue