- changes to OL module

This commit is contained in:
Andy Rozman 2021-10-16 13:27:24 +01:00
parent 57c5401243
commit 63a78a35ca
6 changed files with 52 additions and 36 deletions

View file

@ -109,7 +109,7 @@ android {
defaultConfig { defaultConfig {
multiDexEnabled true multiDexEnabled true
versionCode 1500 versionCode 1500
version "2.8.2.5-dev_mdt2" version "2.8.2.5-dev_mdt3"
buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "VERSION", '"' + version + '"'
buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"' buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"'
buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"' buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"'

View file

@ -69,7 +69,7 @@ public class RileyLinkBLE {
this.context = context; this.context = context;
this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
orangeLink.rileyLinkBLE = this; //orangeLink.rileyLinkBLE = this;
bluetoothGattCallback = new BluetoothGattCallback() { bluetoothGattCallback = new BluetoothGattCallback() {
@ -89,7 +89,7 @@ public class RileyLinkBLE {
radioResponseCountNotified.run(); radioResponseCountNotified.run();
} }
orangeLink.onCharacteristicChanged(gatt, characteristic); orangeLink.onCharacteristicChanged(characteristic);
} }
@ -229,6 +229,9 @@ public class RileyLinkBLE {
final List<BluetoothGattService> services = gatt.getServices(); final List<BluetoothGattService> services = gatt.getServices();
boolean rileyLinkFound = false; boolean rileyLinkFound = false;
orangeLink.resetOrangeLinkData();
StringBuilder stringBuilder = new StringBuilder("RileyLink Device Debug\n");
for (BluetoothGattService service : services) { for (BluetoothGattService service : services) {
final UUID uuidService = service.getUuid(); final UUID uuidService = service.getUuid();
@ -238,13 +241,14 @@ public class RileyLinkBLE {
} }
if (gattDebugEnabled) { if (gattDebugEnabled) {
debugService(service, 0); debugService(service, 0, stringBuilder);
} }
orangeLink.checkIsOrange(uuidService); orangeLink.checkIsOrange(uuidService);
} }
if (gattDebugEnabled) { if (gattDebugEnabled) {
aapsLogger.warn(LTag.PUMPBTCOMM, stringBuilder.toString());
aapsLogger.warn(LTag.PUMPBTCOMM, "onServicesDiscovered " + getGattStatusMessage(status)); aapsLogger.warn(LTag.PUMPBTCOMM, "onServicesDiscovered " + getGattStatusMessage(status));
} }
@ -270,6 +274,7 @@ public class RileyLinkBLE {
@Inject @Inject
public void onInit() { public void onInit() {
aapsLogger.debug(LTag.PUMPBTCOMM, "BT Adapter: " + this.bluetoothAdapter); aapsLogger.debug(LTag.PUMPBTCOMM, "BT Adapter: " + this.bluetoothAdapter);
this.orangeLink.rileyLinkBLE = this;
} }
@ -299,7 +304,7 @@ public class RileyLinkBLE {
} }
public void debugService(BluetoothGattService service, int indentCount) { public void debugService(BluetoothGattService service, int indentCount, StringBuilder stringBuilder) {
String indentString = StringUtils.repeat(' ', indentCount); String indentString = StringUtils.repeat(' ', indentCount);
@ -308,7 +313,7 @@ public class RileyLinkBLE {
if (gattDebugEnabled) { if (gattDebugEnabled) {
final String uuidServiceString = uuidService.toString(); final String uuidServiceString = uuidService.toString();
StringBuilder stringBuilder = new StringBuilder(); //StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(indentString); stringBuilder.append(indentString);
stringBuilder.append(GattAttributes.lookup(uuidServiceString, "Unknown service")); stringBuilder.append(GattAttributes.lookup(uuidServiceString, "Unknown service"));
@ -325,12 +330,12 @@ public class RileyLinkBLE {
stringBuilder.append("\n\n"); stringBuilder.append("\n\n");
aapsLogger.warn(LTag.PUMPBTCOMM, stringBuilder.toString()); //aapsLogger.warn(LTag.PUMPBTCOMM, stringBuilder.toString());
List<BluetoothGattService> includedServices = service.getIncludedServices(); List<BluetoothGattService> includedServices = service.getIncludedServices();
for (BluetoothGattService serviceI : includedServices) { for (BluetoothGattService serviceI : includedServices) {
debugService(serviceI, indentCount + 4); debugService(serviceI, indentCount + 4, stringBuilder);
} }
} }
} }
@ -377,20 +382,22 @@ public class RileyLinkBLE {
return true; return true;
} }
public void findRileyLink(String RileyLinkAddress) {
aapsLogger.debug(LTag.PUMPBTCOMM, "RileyLink address: " + RileyLinkAddress); public void findRileyLink(String rileyLinkAddress) {
aapsLogger.debug(LTag.PUMPBTCOMM, "RileyLink address: " + rileyLinkAddress);
// Must verify that this is a valid MAC, or crash. // Must verify that this is a valid MAC, or crash.
//macAddress = RileyLinkAddress; //macAddress = RileyLinkAddress;
boolean useScanning = sp.getBoolean(RileyLinkConst.Prefs.OrangeUseScanning, false); boolean useScanning = sp.getBoolean(RileyLinkConst.Prefs.OrangeUseScanning, false);
if (useScanning) { if (useScanning) {
aapsLogger.debug(LTag.PUMPBTCOMM, "Start scan for OrangeLink device.");
orangeLink.startScan(); orangeLink.startScan();
} else { } else {
rileyLinkDevice = bluetoothAdapter.getRemoteDevice(RileyLinkAddress); rileyLinkDevice = bluetoothAdapter.getRemoteDevice(rileyLinkAddress);
// if this succeeds, we get a connection state change callback? // if this succeeds, we get a connection state change callback?
if (rileyLinkDevice != null) { if (rileyLinkDevice != null) {
connectGattInternal(); connectGattInternal();
} else { } else {
aapsLogger.error(LTag.PUMPBTCOMM, "RileyLink device not found with address: " + RileyLinkAddress); aapsLogger.error(LTag.PUMPBTCOMM, "RileyLink device not found with address: " + rileyLinkAddress);
} }
} }
} }
@ -398,6 +405,7 @@ public class RileyLinkBLE {
public void connectGatt() { public void connectGatt() {
boolean useScanning = sp.getBoolean(RileyLinkConst.Prefs.OrangeUseScanning, false); boolean useScanning = sp.getBoolean(RileyLinkConst.Prefs.OrangeUseScanning, false);
if (useScanning) { if (useScanning) {
aapsLogger.debug(LTag.PUMPBTCOMM, "Start scan for OrangeLink device.");
orangeLink.startScan(); orangeLink.startScan();
} else { } else {
connectGattInternal(); connectGattInternal();

View file

@ -30,7 +30,7 @@ public class GattAttributes {
public static String CHARA_RADIO_VERSION = "30d99dc9-7c91-4295-a051-0a104d238cf2"; public static String CHARA_RADIO_VERSION = "30d99dc9-7c91-4295-a051-0a104d238cf2";
public static String CHARA_RADIO_LED_MODE = "c6d84241-f1a7-4f9c-a25f-fce16732f14e"; public static String CHARA_RADIO_LED_MODE = "c6d84241-f1a7-4f9c-a25f-fce16732f14e";
//Orange Radio Service // Orange Radio Service
public static String SERVICE_RADIO_ORANGE = "6e400001-b5a3-f393-e0a9-e50e24dcca9e"; public static String SERVICE_RADIO_ORANGE = "6e400001-b5a3-f393-e0a9-e50e24dcca9e";
public static String CHARA_NOTIFICATION_ORANGE = "6e400003-b5a3-f393-e0a9-e50e24dcca9e"; public static String CHARA_NOTIFICATION_ORANGE = "6e400003-b5a3-f393-e0a9-e50e24dcca9e";

View file

@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.device
import android.bluetooth.BluetoothAdapter import android.bluetooth.BluetoothAdapter
import android.bluetooth.BluetoothAdapter.LeScanCallback import android.bluetooth.BluetoothAdapter.LeScanCallback
import android.bluetooth.BluetoothGatt
import android.bluetooth.BluetoothGattCharacteristic import android.bluetooth.BluetoothGattCharacteristic
import android.bluetooth.le.BluetoothLeScanner import android.bluetooth.le.BluetoothLeScanner
import android.bluetooth.le.ScanCallback import android.bluetooth.le.ScanCallback
@ -34,7 +33,7 @@ class OrangeLinkImpl @Inject constructor(
lateinit var rileyLinkBLE: RileyLinkBLE lateinit var rileyLinkBLE: RileyLinkBLE
fun onCharacteristicChanged(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic) { fun onCharacteristicChanged(characteristic: BluetoothGattCharacteristic) {
if (characteristic.uuid.toString().equals(GattAttributes.CHARA_NOTIFICATION_ORANGE)) { if (characteristic.uuid.toString().equals(GattAttributes.CHARA_NOTIFICATION_ORANGE)) {
val data = characteristic.value val data = characteristic.value
val first = 0xff and data[0].toInt() val first = 0xff and data[0].toInt()
@ -50,6 +49,15 @@ class OrangeLinkImpl @Inject constructor(
} }
fun resetOrangeLinkData() {
rileyLinkServiceData.isOrange = false
rileyLinkServiceData.versionOrangeFirmware = null
rileyLinkServiceData.versionOrangeHardware = null
}
/**
* We are checking if this is special Orange (with ORANGE_NOTIFICTION_SERVICE)
*/
fun checkIsOrange(uuidService: UUID) { fun checkIsOrange(uuidService: UUID) {
if (GattAttributes.isOrange(uuidService)) { if (GattAttributes.isOrange(uuidService)) {
rileyLinkServiceData.isOrange = true rileyLinkServiceData.isOrange = true
@ -94,7 +102,7 @@ class OrangeLinkImpl @Inject constructor(
val bluetoothAdapter = rileyLinkBLE.getBluetoothAdapter() val bluetoothAdapter = rileyLinkBLE.getBluetoothAdapter()
aapsLogger.debug(LTag.PUMPBTCOMM, "startScan") aapsLogger.debug(LTag.PUMPBTCOMM, "startScan")
handler.sendEmptyMessageDelayed(TIME_OUT_WHAT, TIME_OUT.toLong()) handler.sendEmptyMessageDelayed(TIME_OUT_WHAT, TIME_OUT.toLong())
val bluetoothLeScanner: BluetoothLeScanner = bluetoothAdapter.getBluetoothLeScanner() val bluetoothLeScanner: BluetoothLeScanner = bluetoothAdapter.bluetoothLeScanner
// if (bluetoothLeScanner == null) { // if (bluetoothLeScanner == null) {
// bluetoothAdapter.startLeScan(mLeScanCallback) // bluetoothAdapter.startLeScan(mLeScanCallback)
// return // return

View file

@ -91,30 +91,29 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re
this.connectionStatus.setText(resourceHelper.gs(rileyLinkServiceData.rileyLinkServiceState.getResourceId())); this.connectionStatus.setText(resourceHelper.gs(rileyLinkServiceData.rileyLinkServiceState.getResourceId()));
// BS FIXME rileyLinkServiceData is injected so I suppose it cannot be null? this.configuredRileyLinkAddress.setText(Optional.ofNullable(rileyLinkServiceData.rileyLinkAddress).orElse(PLACEHOLDER));
if (rileyLinkServiceData != null) { this.configuredRileyLinkName.setText(Optional.ofNullable(rileyLinkServiceData.rileyLinkName).orElse(PLACEHOLDER));
this.configuredRileyLinkAddress.setText(Optional.ofNullable(rileyLinkServiceData.rileyLinkAddress).orElse(PLACEHOLDER));
this.configuredRileyLinkName.setText(Optional.ofNullable(rileyLinkServiceData.rileyLinkName).orElse(PLACEHOLDER));
if (sp.getBoolean(resourceHelper.gs(R.string.key_riley_link_show_battery_level), false)) { if (sp.getBoolean(resourceHelper.gs(R.string.key_riley_link_show_battery_level), false)) {
batteryLevelRow.setVisibility(View.VISIBLE); batteryLevelRow.setVisibility(View.VISIBLE);
Integer batteryLevel = rileyLinkServiceData.batteryLevel; Integer batteryLevel = rileyLinkServiceData.batteryLevel;
this.batteryLevel.setText(batteryLevel == null ? PLACEHOLDER : resourceHelper.gs(R.string.rileylink_battery_level_value, batteryLevel)); this.batteryLevel.setText(batteryLevel == null ? PLACEHOLDER : resourceHelper.gs(R.string.rileylink_battery_level_value, batteryLevel));
} else { } else {
batteryLevelRow.setVisibility(View.GONE); batteryLevelRow.setVisibility(View.GONE);
} }
RileyLinkError rileyLinkError = rileyLinkServiceData.rileyLinkError; RileyLinkError rileyLinkError = rileyLinkServiceData.rileyLinkError;
this.connectionError.setText(rileyLinkError == null ? PLACEHOLDER : resourceHelper.gs(rileyLinkError.getResourceId(targetDevice))); this.connectionError.setText(rileyLinkError == null ? PLACEHOLDER : resourceHelper.gs(rileyLinkError.getResourceId(targetDevice)));
if(rileyLinkServiceData.isOrange){ if (rileyLinkServiceData.isOrange) {
this.firmwareVersion.setText("FV:"+Optional.ofNullable(rileyLinkServiceData.versionOrangeFirmware).orElse(PLACEHOLDER)+"\nHV:"+Optional.ofNullable(rileyLinkServiceData.versionOrangeHardware).orElse(PLACEHOLDER)); this.firmwareVersion.setText(resourceHelper.gs(R.string.rileylink_firmware_version_value_orange,
}else{ Optional.ofNullable(rileyLinkServiceData.versionOrangeFirmware).orElse(PLACEHOLDER),
this.firmwareVersion.setText(resourceHelper.gs(R.string.rileylink_firmware_version_value, Optional.ofNullable(rileyLinkServiceData.versionOrangeHardware).orElse(PLACEHOLDER)));
Optional.ofNullable(rileyLinkServiceData.versionBLE113).orElse(PLACEHOLDER), Optional.ofNullable(rileyLinkServiceData.versionCC110).orElse(PLACEHOLDER))); } else {
this.firmwareVersion.setText(resourceHelper.gs(R.string.rileylink_firmware_version_value,
} Optional.ofNullable(rileyLinkServiceData.versionBLE113).orElse(PLACEHOLDER),
Optional.ofNullable(rileyLinkServiceData.versionCC110).orElse(PLACEHOLDER)));
} }
RileyLinkPumpDevice rileyLinkPumpDevice = (RileyLinkPumpDevice) activePlugin.getActivePump(); RileyLinkPumpDevice rileyLinkPumpDevice = (RileyLinkPumpDevice) activePlugin.getActivePump();

View file

@ -45,6 +45,7 @@
<string name="rileylink_last_device_contact">Last Device Contact:</string> <string name="rileylink_last_device_contact">Last Device Contact:</string>
<string name="rileylink_firmware_version">Firmware Version:</string> <string name="rileylink_firmware_version">Firmware Version:</string>
<string name="rileylink_firmware_version_value">BLE113: %1$s\nCC110: %2$s</string> <string name="rileylink_firmware_version_value">BLE113: %1$s\nCC110: %2$s</string>
<string name="rileylink_firmware_version_value_orange">FW: %1$s\nHW: %2$s</string>
<string name="rileylink_pump_serial_number">Pump Serial Number:</string> <string name="rileylink_pump_serial_number">Pump Serial Number:</string>
<string name="rileylink_pump_frequency">Pump Frequency:</string> <string name="rileylink_pump_frequency">Pump Frequency:</string>
<string name="rileylink_pump_frequency_value">%1$.2f MHz</string> <string name="rileylink_pump_frequency_value">%1$.2f MHz</string>