Browse Source

刘工测试

newdev_shunjiawei
liwei1dao 3 months ago
parent
commit
27997194b6
  1. 37
      lib/modules/pairing/controllers/pairing_controller.dart

37
lib/modules/pairing/controllers/pairing_controller.dart

@ -788,17 +788,9 @@ class PairingController extends GetxController with WidgetsBindingObserver {
Future<int> authbindingDevice(BluetoothDevice device) async { Future<int> authbindingDevice(BluetoothDevice device) async {
// 检查设备名称是否包含 DeepSound 或 DeapSound // 检查设备名称是否包含 DeepSound 或 DeapSound
final deviceName = device.name; final deviceName = device.name;
DBProduct? product; // 已移除“按设备名匹配 product”逻辑:设备名可被用户改名,不能作为是否支持的判据。
// 检查是否已有BLE绑定的设备 // 是否支持的设备完全交给下面的 BLE 扫描(按 allproductUuids 过滤)+ 广播内 MAC 比对判定。
// 检查是否已有BLE绑定的设备
if (AppConfig.config.products.isNotEmpty) {
final match = AppConfig.config.products.where(
(d) => d.devicename.contains(deviceName),
);
product = match.isNotEmpty ? match.first : null;
}
final currentBleState = await _bleManager.getConnectionState(); final currentBleState = await _bleManager.getConnectionState();
final names = AppConfig.allproductNames();
final uuids = AppConfig.allproductUuids(); final uuids = AppConfig.allproductUuids();
// 检查是否已有绑定的设备 // 检查是否已有绑定的设备
print("device.address${device.address}"); print("device.address${device.address}");
@ -867,7 +859,9 @@ class PairingController extends GetxController with WidgetsBindingObserver {
} }
print( print(
'获取到 deviceName: $deviceName address: ${device.address} uuids:$uuids'); '获取到 deviceName: $deviceName address: ${device.address} uuids:$uuids');
if (product != null && product.devicetype != 1) { // 无条件做 BLE 扫描验证(不再依赖 product)。扫描按 allproductUuids 过滤,
// 命中后用广播内 MAC 与经典蓝牙地址比对确认,由此判定是否为支持的设备。
{
if (currentBleState == 2) { if (currentBleState == 2) {
//已连接直接返回 //已连接直接返回
return 9; return 9;
@ -895,7 +889,7 @@ class PairingController extends GetxController with WidgetsBindingObserver {
// 找到匹配的设备,提取授权码 // 找到匹配的设备,提取授权码
if (Platform.isIOS) { if (Platform.isIOS) {
// iOS设备,提取13-22字节的授权码 // iOS设备,提取13-22字节的授权码
code = extractAndReverseBytes(hexData, 13, 22); code = extractBytesBigEndian(hexData, 13, 22);
_verifiedDevicePid = _verifiedDevicePid =
extractAndReverseBytesToInt(hexData, 4, 5); extractAndReverseBytesToInt(hexData, 4, 5);
final pidHexIos = final pidHexIos =
@ -936,7 +930,7 @@ class PairingController extends GetxController with WidgetsBindingObserver {
} }
} else if (Platform.isAndroid) { } else if (Platform.isAndroid) {
// Android设备,提取15-24字节的授权码 // Android设备,提取15-24字节的授权码
code = extractAndReverseBytes(hexData, 15, 24); code = extractBytesBigEndian(hexData, 15, 24);
_verifiedDevicePid = _verifiedDevicePid =
extractAndReverseBytesToInt(hexData, 6, 7); extractAndReverseBytesToInt(hexData, 6, 7);
final pidHexAndroid = final pidHexAndroid =
@ -989,10 +983,6 @@ class PairingController extends GetxController with WidgetsBindingObserver {
await Future.delayed(Duration(seconds: 1)); await Future.delayed(Duration(seconds: 1));
} }
_bleManager.stopScan(); _bleManager.stopScan();
// if (product != null && product.devicetype != 1) {
// //ble设备 必须要扫描到结果
// return 0;
// }
} }
return 0; return 0;
//可以跳转1 //可以跳转1
@ -1175,6 +1165,19 @@ class PairingController extends GetxController with WidgetsBindingObserver {
.toUpperCase(); .toUpperCase();
} }
/// 大端模式:按原始字节顺序提取 [start, end](含 end),不反转
String extractBytesBigEndian(String hex, int start, int end) {
List<int> bytes = [];
for (int i = 0; i < hex.length; i += 2) {
bytes.add(int.parse(hex.substring(i, i + 2), radix: 16));
}
List<int> slice = bytes.sublist(start, end + 1);
return slice
.map((b) => b.toRadixString(16).padLeft(2, '0'))
.join()
.toUpperCase();
}
int extractAndReverseBytesToInt(String hex, int start, int end) { int extractAndReverseBytesToInt(String hex, int start, int end) {
List<int> bytes = []; List<int> bytes = [];
// 将十六进制字符串解析为字节列表 // 将十六进制字符串解析为字节列表

Loading…
Cancel
Save