diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java index 6e502e6c36..4df1a22389 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java @@ -112,6 +112,17 @@ public class RFSpy { reader.newDataIsAvailable(); } + public String getBleDeviceName() { + BLECommOperationResult result = rileyLinkBle.readCharacteristic_blocking(UUID.fromString(GattAttributes.SERVICE_GAP), UUID.fromString(GattAttributes.CHARA_GAP_NAME)); + if (result.resultCode == BLECommOperationResult.RESULT_SUCCESS) { + String value = new String(result.value); + aapsLogger.debug(LTag.PUMPBTCOMM, "BLE device name: {}", value); + return value; + } else { + aapsLogger.error(LTag.PUMPBTCOMM, "getBleDeviceName failed with code: " + result.resultCode); + return null; + } + } public Integer getBatteryLevel() { BLECommOperationResult result = rileyLinkBle.readCharacteristic_blocking(batteryServiceUUID, batteryLevelUUID); diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java index 576e04e436..3c0a156c76 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java @@ -6,6 +6,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; +import org.apache.commons.lang3.StringUtils; import org.joda.time.LocalDateTime; import java.util.Locale; @@ -31,6 +32,8 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper; public class RileyLinkStatusGeneralFragment extends DaggerFragment implements RefreshableInterface { + private static final String PLACEHOLDER = "-"; + @Inject ActivePluginProvider activePlugin; @Inject ResourceHelper resourceHelper; @Inject AAPSLogger aapsLogger; @@ -39,6 +42,7 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re TextView connectionStatus; TextView configuredAddress; + TextView connectedRileyLinkName; TextView connectedDevice; TextView connectionError; TextView deviceType; @@ -65,6 +69,7 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re this.connectionStatus = getActivity().findViewById(R.id.rls_t1_connection_status); this.configuredAddress = getActivity().findViewById(R.id.rls_t1_configured_address); + this.connectedRileyLinkName = getActivity().findViewById(R.id.rls_t1_connected_riley_link_name); this.connectedDevice = getActivity().findViewById(R.id.rls_t1_connected_device); this.connectionError = getActivity().findViewById(R.id.rls_t1_connection_error); this.deviceType = getActivity().findViewById(R.id.rls_t1_device_type); @@ -75,10 +80,11 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re this.lastDeviceContact = getActivity().findViewById(R.id.rls_t1_last_device_contact); this.firmwareVersion = getActivity().findViewById(R.id.rls_t1_firmware_version); + // BS: FIXME Remove if (!first) { // 7-14 - int[] ids = {R.id.rls_t1_tv02, R.id.rls_t1_tv03, R.id.rls_t1_tv04, R.id.rls_t1_tv05, R.id.rls_t1_tv07, // + int[] ids = {R.id.rls_t1_tv02, R.id.rls_t1_tv14, R.id.rls_t1_tv03, R.id.rls_t1_tv04, R.id.rls_t1_tv05, R.id.rls_t1_tv07, // R.id.rls_t1_tv08, R.id.rls_t1_tv09, R.id.rls_t1_tv10, R.id.rls_t1_tv11, R.id.rls_t1_tv12, R.id.rls_t1_tv13}; for (int id : ids) { @@ -100,14 +106,16 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re this.connectionStatus.setText(resourceHelper.gs(rileyLinkServiceData.rileyLinkServiceState.getResourceId())); + // BS FIXME rileyLinkServiceData is injected so I suppose it cannot be null? if (rileyLinkServiceData != null) { - this.configuredAddress.setText(rileyLinkServiceData.rileylinkAddress); + this.configuredAddress.setText(StringUtils.isEmpty(rileyLinkServiceData.rileylinkAddress) ? PLACEHOLDER : rileyLinkServiceData.rileylinkAddress); + this.connectedRileyLinkName.setText(StringUtils.isEmpty(rileyLinkServiceData.rileyLinkName) ? PLACEHOLDER : rileyLinkServiceData.rileyLinkName); this.connectionError.setText(rileyLinkServiceData.rileyLinkError == null ? // - "-" + PLACEHOLDER : resourceHelper.gs(rileyLinkServiceData.rileyLinkError.getResourceId(targetDevice))); if (firmwareVersion == null) { - this.firmwareVersion.setText("BLE113: -\nCC110: -"); + this.firmwareVersion.setText("BLE113: " + PLACEHOLDER + "\nCC110: " + PLACEHOLDER); } else { this.firmwareVersion.setText("BLE113: " + rileyLinkServiceData.versionBLE113 + "\nCC110: " + rileyLinkServiceData.versionCC110); diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java index b240f8bc0b..387e2922c8 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java @@ -84,7 +84,7 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver { } private RileyLinkService getServiceInstance() { - RileyLinkPumpDevice pumpDevice = (RileyLinkPumpDevice)activePlugin.getActivePump(); + RileyLinkPumpDevice pumpDevice = (RileyLinkPumpDevice) activePlugin.getActivePump(); return pumpDevice.getRileyLinkService(); } @@ -139,10 +139,10 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver { } else { rileyLinkServiceData.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.BluetoothDisabled); } + rileyLinkServiceData.rileyLinkName = null; return true; } else if (action.equals(RileyLinkConst.Intents.RileyLinkReady)) { - aapsLogger.warn(LTag.PUMPBTCOMM, "RileyLinkConst.Intents.RileyLinkReady"); // sendIPCNotification(RT2Const.IPC.MSG_note_WakingPump); @@ -153,7 +153,9 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver { String bleVersion = rileyLinkService.rfspy.getBLEVersionCached(); RileyLinkFirmwareVersion rlVersion = rileyLinkServiceData.firmwareVersion; -// if (isLoggingEnabled()) + rileyLinkServiceData.rileyLinkName = rileyLinkService.rfspy.getBleDeviceName(); + aapsLogger.debug(LTag.PUMPBTCOMM, "BLE device name: {}", rileyLinkServiceData.rileyLinkName); + aapsLogger.debug(LTag.PUMPBTCOMM, "RfSpy version (BLE113): " + bleVersion); rileyLinkService.rileyLinkServiceData.versionBLE113 = bleVersion; @@ -168,6 +170,7 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver { return true; } else if (action.equals(RileyLinkConst.Intents.RileyLinkNewAddressSet)) { String RileylinkBLEAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, ""); + rileyLinkServiceData.rileyLinkName = null; if (RileylinkBLEAddress.equals("")) { aapsLogger.error("No Rileylink BLE Address saved in app"); } else { @@ -180,6 +183,7 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver { return true; } else if (action.equals(RileyLinkConst.Intents.RileyLinkDisconnect)) { rileyLinkService.disconnectRileyLink(); + rileyLinkServiceData.rileyLinkName = null; return true; } else { diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java index 6307c7ad87..10eb06373c 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java @@ -35,6 +35,7 @@ public class RileyLinkServiceData { public RileyLinkFirmwareVersion firmwareVersion; // here we have "compatibility level" version public RileyLinkTargetFrequency rileyLinkTargetFrequency; public String rileylinkAddress; + public String rileyLinkName; long lastTuneUpTime = 0L; public Double lastGoodFrequency; diff --git a/rileylink/src/main/res/layout/rileylink_status_general.xml b/rileylink/src/main/res/layout/rileylink_status_general.xml index dfa5f94d82..ac72198024 100644 --- a/rileylink/src/main/res/layout/rileylink_status_general.xml +++ b/rileylink/src/main/res/layout/rileylink_status_general.xml @@ -56,6 +56,34 @@ android:textAlignment="center" /> + + + + + + + pref_medtronic_encoding %1$.1f %2$s (%3$s) + Connected RileyLink name %1$d day