Merge pull request #52 from AAPS-Omnipod/omnipod_eros_dev_rl_scan_fixes

RL scan fixes
This commit is contained in:
bartsopers 2020-12-25 12:59:01 +01:00 committed by GitHub
commit 2eebaddb1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 73 additions and 136 deletions

View file

@ -180,7 +180,7 @@ public class RileyLinkMedtronicService extends RileyLinkService {
}
public boolean verifyConfiguration() {
public boolean verifyConfiguration(boolean forceRileyLinkAddressRenewal) {
try {
String regexSN = "[0-9]{6}";
String regexMac = "([\\da-fA-F]{1,2}(?:\\:|$)){6}";
@ -316,7 +316,7 @@ public class RileyLinkMedtronicService extends RileyLinkService {
//boolean bolusDebug = bolusDebugEnabled != null && bolusDebugEnabled.equals(resourceHelper.gs(R.string.common_on));
//MedtronicHistoryData.doubleBolusDebug = bolusDebug;
reconfigureService();
reconfigureService(forceRileyLinkAddressRenewal);
return true;
@ -327,7 +327,7 @@ public class RileyLinkMedtronicService extends RileyLinkService {
}
}
private boolean reconfigureService() {
private boolean reconfigureService(boolean forceRileyLinkAddressRenewal) {
if (!inPreInit) {
@ -336,7 +336,7 @@ public class RileyLinkMedtronicService extends RileyLinkService {
serialChanged = false;
}
if (rileyLinkAddressChanged) {
if (rileyLinkAddressChanged || forceRileyLinkAddressRenewal) {
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet, this);
rileyLinkAddressChanged = false;
}
@ -380,6 +380,6 @@ public class RileyLinkMedtronicService extends RileyLinkService {
public boolean setNotInPreInit() {
this.inPreInit = false;
return reconfigureService();
return reconfigureService(false);
}
}

View file

@ -109,7 +109,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
}
@Override
public boolean verifyConfiguration() {
public boolean verifyConfiguration(boolean forceRileyLinkAddressRenewal) {
try {
errorDescription = null;
@ -133,7 +133,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
rileyLinkServiceData.rileyLinkTargetFrequency = RileyLinkTargetFrequency.Omnipod;
reconfigureService();
reconfigureService(forceRileyLinkAddressRenewal);
return true;
@ -144,9 +144,9 @@ public class RileyLinkOmnipodService extends RileyLinkService {
}
}
private boolean reconfigureService() {
private boolean reconfigureService(boolean forceRileyLinkAddressRenewal) {
if (!inPreInit) {
if (rileyLinkAddressChanged) {
if (rileyLinkAddressChanged || forceRileyLinkAddressRenewal) {
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet, this);
rileyLinkAddressChanged = false;
}
@ -158,6 +158,6 @@ public class RileyLinkOmnipodService extends RileyLinkService {
public boolean setNotInPreInit() {
this.inPreInit = false;
return reconfigureService();
return reconfigureService(false);
}
}

View file

@ -79,6 +79,8 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
private String actionTitleStart, actionTitleStop;
private MenuItem menuItem;
private boolean rlDisconnected;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -106,7 +108,7 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
sp.putString(RileyLinkConst.Prefs.RileyLinkAddress, bleAddress);
RileyLinkPumpDevice rileyLinkPump = (RileyLinkPumpDevice) activePlugin.getActivePump();
rileyLinkPump.getRileyLinkService().verifyConfiguration(); // force reloading of address
rileyLinkPump.getRileyLinkService().verifyConfiguration(true); // force reloading of address to assure that the RL gets reconnected (even if the address didn't change)
rileyLinkPump.triggerPumpConfigurationChangedEvent();
finish();
@ -115,10 +117,12 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
toolbarBTScan = findViewById(R.id.rileylink_toolbarBTScan);
toolbarBTScan.setTitle(R.string.rileylink_scanner_title);
setSupportActionBar(toolbarBTScan);
prepareForScanning();
}
@Override protected void onResume() {
super.onResume();
prepareForScanning();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
@ -138,6 +142,10 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getTitle().equals(actionTitleStart)) {
// disable currently selected RL, so that we can discover it
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkDisconnect, this);
rlDisconnected = true;
scanLeDevice(true);
return true;
} else if (item.getTitle().equals(actionTitleStop)) {
@ -148,8 +156,21 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
}
}
@Override public void onBackPressed() {
super.onBackPressed();
if (rlDisconnected) {
// Reconnect RL if it was disconnected for the scan
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet, this);
}
}
public void prepareForScanning() {
@Override protected void onDestroy() {
super.onDestroy();
mScanning = false;
mLEScanner.stopScan(mScanCallback2);
}
private void prepareForScanning() {
boolean checkOK = blePrecheck.prerequisitesCheck(this);
if (checkOK) {
@ -158,9 +179,6 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
filters = Collections.singletonList(new ScanFilter.Builder().setServiceUuid(
ParcelUuid.fromString(GattAttributes.SERVICE_RADIO)).build());
}
// disable currently selected RL, so that we can discover it
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkDisconnect, this);
}

View file

@ -112,18 +112,6 @@ 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);
if (result.resultCode == BLECommOperationResult.RESULT_SUCCESS) {

View file

@ -151,8 +151,8 @@ public class RileyLinkBLE {
} else if ((newState == BluetoothProfile.STATE_CONNECTING) || //
(newState == BluetoothProfile.STATE_DISCONNECTING)) {
aapsLogger.debug(LTag.PUMPBTCOMM,"We are in {} state.", status == BluetoothProfile.STATE_CONNECTING ? "Connecting" :
"Disconnecting");
aapsLogger.debug(LTag.PUMPBTCOMM, "We are in {} state.", status == BluetoothProfile.STATE_CONNECTING ? "Connecting" :
"Disconnecting");
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkDisconnected, context);
if (manualDisconnect)
@ -392,6 +392,9 @@ public class RileyLinkBLE {
if (gattDebugEnabled) {
aapsLogger.debug(LTag.PUMPBTCOMM, "Gatt Connected.");
}
rileyLinkServiceData.rileylinkAddress = bluetoothConnectionGatt.getDevice().getAddress();
rileyLinkServiceData.rileyLinkName = bluetoothConnectionGatt.getDevice().getName();
}
}

View file

@ -16,7 +16,6 @@ import java.util.List;
import javax.inject.Inject;
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
import info.nightscout.androidaps.plugins.pump.common.R;
import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface;
@ -66,50 +65,14 @@ public class RileyLinkStatusActivity extends NoSplashAppCompatActivity {
RefreshableInterface selectableInterface = (RefreshableInterface) mSectionsPagerAdapter
.getItem(tabLayout.getSelectedTabPosition());
selectableInterface.refreshData();
// refreshData(tabLayout.getSelectedTabPosition());
// Toast.makeText(getApplicationContext(), "Test pos: " + tabLayout.getSelectedTabPosition(),
// Toast.LENGTH_LONG);
});
this.connectionStatus = findViewById(R.id.rls_t1_connection_status);
this.configuredAddress = findViewById(R.id.rls_t1_configured_address);
this.connectedDevice = findViewById(R.id.rls_t1_connected_device);
this.connectionError = findViewById(R.id.rls_t1_connection_error);
// // 7-12
// 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, //
// 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};
//
// for (int id : ids) {
//
// TextView tv = (TextView) findViewById(id);
// tv.setText(tv.getText() + ":");
// }
// refreshData(0);
// refreshData(1);
}
public void refreshData(int position) {
if (position == 0) {
// FIXME i18n
this.connectionStatus.setText(rileyLinkServiceData.rileyLinkServiceState.name());
this.configuredAddress.setText(rileyLinkServiceData.rileylinkAddress);
// FIXME
this.connectedDevice.setText("???");
// FIXME i18n
this.connectionError.setText(rileyLinkServiceData.rileyLinkError.name());
} else {
}
}
public void setupViewPager(ViewPager pager) {
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

View file

@ -40,29 +40,24 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
@Inject RileyLinkServiceData rileyLinkServiceData;
@Inject DateUtil dateUtil;
TextView connectionStatus;
TextView configuredAddress;
TextView connectedRileyLinkName;
TextView connectedDevice;
TextView connectionError;
TextView deviceType;
TextView deviceModel;
TextView serialNumber;
TextView pumpFrequency;
TextView lastUsedFrequency;
TextView lastDeviceContact;
TextView firmwareVersion;
boolean first = false;
private TextView connectionStatus;
private TextView configuredAddress;
private TextView connectedRileyLinkName;
private TextView connectedDevice;
private TextView connectionError;
private TextView deviceType;
private TextView deviceModel;
private TextView serialNumber;
private TextView pumpFrequency;
private TextView lastUsedFrequency;
private TextView lastDeviceContact;
private TextView firmwareVersion;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.rileylink_status_general, container, false);
return rootView;
return inflater.inflate(R.layout.rileylink_status_general, container, false);
}
@Override
public void onStart() {
super.onStart();
@ -80,28 +75,10 @@ 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_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) {
TextView tv = getActivity().findViewById(id);
tv.setText(tv.getText() + ":");
}
first = true;
}
refreshData();
}
public void refreshData() {
RileyLinkTargetDevice targetDevice = rileyLinkServiceData.targetDevice;
this.connectionStatus.setText(resourceHelper.gs(rileyLinkServiceData.rileyLinkServiceState.getResourceId()));

View file

@ -139,7 +139,6 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
} else {
rileyLinkServiceData.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.BluetoothDisabled);
}
rileyLinkServiceData.rileyLinkName = null;
return true;
} else if (action.equals(RileyLinkConst.Intents.RileyLinkReady)) {
@ -153,9 +152,6 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
String bleVersion = rileyLinkService.rfspy.getBLEVersionCached();
RileyLinkFirmwareVersion rlVersion = rileyLinkServiceData.firmwareVersion;
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;
@ -170,7 +166,6 @@ 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 {
@ -183,8 +178,6 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
return true;
} else if (action.equals(RileyLinkConst.Intents.RileyLinkDisconnect)) {
rileyLinkService.disconnectRileyLink();
rileyLinkServiceData.rileyLinkName = null;
return true;
} else {
return false;

View file

@ -230,6 +230,7 @@ public abstract class RileyLinkService extends DaggerService {
if (rileyLinkBLE.isConnected()) {
rileyLinkBLE.disconnect();
rileyLinkServiceData.rileylinkAddress = null;
rileyLinkServiceData.rileyLinkName = null;
}
rileyLinkServiceData.setRileyLinkServiceState(RileyLinkServiceState.BluetoothReady);
@ -260,5 +261,9 @@ public abstract class RileyLinkService extends DaggerService {
return null;
}
public abstract boolean verifyConfiguration();
public boolean verifyConfiguration() {
return verifyConfiguration(false);
}
public abstract boolean verifyConfiguration(boolean forceRileyLinkAddressRenewal);
}

View file

@ -37,7 +37,6 @@
android:orientation="horizontal">
<TextView
android:id="@+id/rls_t1_tv02"
android:layout_width="58dp"
android:layout_height="match_parent"
android:layout_marginLeft="30dp"
@ -65,7 +64,6 @@
android:orientation="horizontal">
<TextView
android:id="@+id/rls_t1_tv14"
android:layout_width="58dp"
android:layout_height="match_parent"
android:layout_marginLeft="30dp"
@ -93,7 +91,6 @@
android:orientation="horizontal">
<TextView
android:id="@+id/rls_t1_tv03"
android:layout_width="58dp"
android:layout_height="match_parent"
android:layout_marginLeft="30dp"
@ -122,7 +119,6 @@
android:orientation="horizontal">
<TextView
android:id="@+id/rls_t1_tv04"
android:layout_width="58dp"
android:layout_height="match_parent"
android:layout_marginLeft="30dp"
@ -151,7 +147,6 @@
android:orientation="horizontal">
<TextView
android:id="@+id/rls_t1_tv05"
android:layout_width="58dp"
android:layout_height="match_parent"
android:layout_marginLeft="30dp"
@ -179,7 +174,6 @@
android:orientation="horizontal">
<TextView
android:id="@+id/rls_t1_tv13"
android:layout_width="58dp"
android:layout_height="match_parent"
android:layout_marginLeft="30dp"
@ -222,7 +216,6 @@
android:orientation="horizontal">
<TextView
android:id="@+id/rls_t1_tv07"
android:layout_width="58dp"
android:layout_height="match_parent"
android:layout_marginLeft="30dp"
@ -251,7 +244,6 @@
android:orientation="horizontal">
<TextView
android:id="@+id/rls_t1_tv08"
android:layout_width="58dp"
android:layout_height="match_parent"
android:layout_marginLeft="30dp"
@ -280,13 +272,12 @@
android:orientation="horizontal">
<TextView
android:id="@+id/rls_t1_tv09"
android:layout_width="58dp"
android:layout_height="match_parent"
android:layout_marginLeft="30dp"
android:layout_weight="35"
android:gravity="center_vertical"
android:text="@string/medtronic_serial_number" />
android:text="@string/rileylink_pump_serial_number" />
<TextView
android:id="@+id/rls_t1_serial_number"
@ -309,13 +300,12 @@
android:orientation="horizontal">
<TextView
android:id="@+id/rls_t1_tv10"
android:layout_width="58dp"
android:layout_height="match_parent"
android:layout_marginLeft="30dp"
android:layout_weight="35"
android:gravity="center_vertical"
android:text="@string/medtronic_pump_frequency" />
android:text="@string/rileylink_pump_frequency" />
<TextView
android:id="@+id/rls_t1_pump_frequency"
@ -337,7 +327,6 @@
android:orientation="horizontal">
<TextView
android:id="@+id/rls_t1_tv11"
android:layout_width="58dp"
android:layout_height="match_parent"
android:layout_marginLeft="30dp"
@ -366,7 +355,6 @@
android:orientation="horizontal">
<TextView
android:id="@+id/rls_t1_tv12"
android:layout_width="58dp"
android:layout_height="match_parent"
android:layout_marginLeft="30dp"

View file

@ -20,16 +20,19 @@
<string name="medtronic_pump_status">Pump Status</string>
<string name="title_activity_rileylink_settings">RileyLink Settings</string>
<string name="rileylink_title">RileyLink</string>
<string name="rileylink_configured_address">Configured Address</string>
<string name="rileylink_connected_device">Connected Device</string>
<string name="rileylink_connection_status">Connection Status</string>
<string name="rileylink_connection_error">Connection Error</string>
<string name="rileylink_configured_address">Configured Address:</string>
<string name="rileylink_connected_device">Connected Device:</string>
<string name="rileylink_connection_status">Connection Status:</string>
<string name="rileylink_connection_error">Connection Error:</string>
<string name="rileylink_device">Device</string>
<string name="rileylink_device_type">Device Type</string>
<string name="rileylink_device_model">Device Model</string>
<string name="rileylink_last_used_frequency">Last used frequency</string>
<string name="rileylink_last_device_contact">Last device contact</string>
<string name="rileylink_firmware_version">Firmware</string>
<string name="rileylink_device_type">Device Type:</string>
<string name="rileylink_device_model">Device Model:</string>
<string name="rileylink_last_used_frequency">Last Used Frequency:</string>
<string name="rileylink_last_device_contact">Last Device Contact:</string>
<string name="rileylink_firmware_version">Firmware Version:</string>
<string name="rileylink_connected_riley_link_name">Connected RileyLink Name:</string>
<string name="rileylink_pump_serial_number">Pump Serial Number:</string>
<string name="rileylink_pump_frequency">Pump Frequency:</string>
<!-- RL State -->
@ -64,7 +67,6 @@
<string name="key_medtronic_encoding" translatable="false">pref_medtronic_encoding</string>
<string name="mdt_last_bolus" translatable="false">%1$.1f %2$s (%3$s)</string>
<string name="rileylink_connected_riley_link_name">Connected RileyLink name</string>
<plurals name="duration_days">
<item quantity="one">%1$d day</item>