diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java index a96dcb6e11..b639c61aec 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java @@ -369,7 +369,9 @@ public class RileyLinkBLE { rileyLinkDevice = bluetoothAdapter.getRemoteDevice(RileyLinkAddress); // if this succeeds, we get a connection state change callback? - connectGatt(); + + if (rileyLinkDevice!=null) + connectGatt(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneral.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneral.java index 63bcb11958..b886861b00 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneral.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneral.java @@ -16,6 +16,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkFirmwareVersion; +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.service.RileyLinkServiceData; import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil; @@ -94,7 +95,10 @@ public class RileyLinkStatusGeneral extends Fragment implements RefreshableInter RileyLinkTargetDevice targetDevice = RileyLinkUtil.getTargetDevice(); - this.connectionStatus.setText(MainApp.gs(RileyLinkUtil.getServiceState().getResourceId(targetDevice))); + if (RileyLinkUtil.getServiceState()==null) + this.connectionStatus.setText(MainApp.gs(RileyLinkServiceState.NotStarted.getResourceId(targetDevice))); + else + this.connectionStatus.setText(MainApp.gs(RileyLinkUtil.getServiceState().getResourceId(targetDevice))); if (rileyLinkServiceData != null) { this.configuredAddress.setText(rileyLinkServiceData.rileylinkAddress); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java index f67082cd93..b6258b7de8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java @@ -384,11 +384,15 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter RileyLinkServiceState rileyLinkServiceState = MedtronicUtil.getServiceState(); + if (rileyLinkServiceState==null) { + LOG.error("RileyLink unreachable. RileyLinkServiceState is null."); + return false; + } + if (rileyLinkServiceState != RileyLinkServiceState.PumpConnectorReady // && rileyLinkServiceState != RileyLinkServiceState.RileyLinkReady // && rileyLinkServiceState != RileyLinkServiceState.TuneUpDevice) { - if (isLoggingEnabled()) - LOG.error("RileyLink unreachable."); + LOG.error("RileyLink unreachable."); return false; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.java index d53d59197e..27bd436364 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicCommunicationManager.java @@ -951,11 +951,13 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager return true; } catch (RileyLinkCommunicationException e) { - if (isLogEnabled()) - LOG.warn("Error getting response from RileyLink (error={}, retry={})", e.getMessage(), retries + 1); + LOG.warn("Error getting response from RileyLink (error={}, retry={})", e.getMessage(), retries + 1); } - LOG.warn("Set Basal Profile: Invalid response: commandType={},rawData={}", responseMessage.commandType, ByteUtil.shortHexString(responseMessage.getRawContent())); + if (responseMessage!=null) + LOG.warn("Set Basal Profile: Invalid response: commandType={},rawData={}", responseMessage.commandType, ByteUtil.shortHexString(responseMessage.getRawContent())); + else + LOG.warn("Set Basal Profile: Null response."); } return false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalPair.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalPair.java index 1c45cdbcef..7a17767243 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalPair.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalPair.java @@ -63,7 +63,7 @@ public class TempBasalPair { public TempBasalPair(byte[] response) { if (L.isEnabled(L.PUMPCOMM)) - LOG.debug("Received response: " + response); + LOG.debug("Received TempBasal response: " + ByteUtil.getHex(response)); isPercent = response[0] == 1; @@ -75,7 +75,13 @@ public class TempBasalPair { insulinRate = strokes / 40.0d; } - durationMinutes = MedtronicUtil.makeUnsignedShort(response[4], response[5]); + if (response.length<6) { + durationMinutes = ByteUtil.asUINT8(response[4]); + } else { + durationMinutes = MedtronicUtil.makeUnsignedShort(response[4], response[5]); + } + + LOG.warn("TempBasalPair (with {} byte response): {}", response.length, toString()); }