From 81b1fdd43da152ee2c135183ca01b3113c051f4a Mon Sep 17 00:00:00 2001 From: liyi Date: Thu, 8 May 2025 15:11:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=90=9C=E7=B4=A2=E8=93=9D=E7=89=99?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=8C=BA=E5=88=86,sky=E6=94=B9=E4=B8=BA76?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/blue/blue_manage.dart | 38 ++++++++++++++++++++++++-------------- lib/blue/io_type.dart | 2 +- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/lib/blue/blue_manage.dart b/lib/blue/blue_manage.dart index 064fe984..cdc9ae3e 100755 --- a/lib/blue/blue_manage.dart +++ b/lib/blue/blue_manage.dart @@ -263,7 +263,7 @@ class BlueManage { for (final ScanResult scanResult in results) { if (scanResult.advertisementData.serviceUuids.isNotEmpty) { // AppLog.log( - // '扫描到的设备:${scanResult.advertisementData.serviceUuids[0].toString()}'); + // '扫描到的设备:${scanResult.advertisementData.serviceUuids[0].toString()}====${scanResult.advertisementData.advName}'); } else { continue; } @@ -316,20 +316,30 @@ class BlueManage { } /// 判断是否包含指定的uuid - bool _isMatch(List serviceUuids, - {DeviceType deviceType = DeviceType.blue}) { - // 获取设备类型数组 - List deviceTypeList = getDeviceType(deviceType); - - // 检查 serviceUuids 是否包含 deviceTypeList 中的任意一个值 - if (serviceUuids != null && serviceUuids.isNotEmpty) { - return serviceUuids.any((uuid) { - return deviceTypeList - .any((type) => uuid.toLowerCase().contains(type.toLowerCase())); - }); + bool _isMatch(List serviceUuids, {DeviceType deviceType = DeviceType.blue}) { + final List prefixes = getDeviceType(deviceType).map((e) => e.toLowerCase()).toList(); + for (String uuid in serviceUuids) { + final String cleanUuid = uuid.replaceAll('-', '').toLowerCase(); + if (cleanUuid.length == 8) { + // 8位,判断前两位 + for (final prefix in prefixes) { + if (cleanUuid.startsWith(prefix)) { + return true; + } + } + } else if (cleanUuid.length == 32) { + // 128位,判断前8位的第3、第4位 + final String first8 = cleanUuid.substring(0, 8); + if (first8.length >= 4) { + final String thirdAndFourth = first8.substring(2, 4); // 索引2和3 + for (final prefix in prefixes) { + if (thirdAndFourth == prefix) { + return true; + } + } + } + } } - - // 如果 serviceUuids 为空,则返回 false return false; } diff --git a/lib/blue/io_type.dart b/lib/blue/io_type.dart index ee785811..a5f523b4 100755 --- a/lib/blue/io_type.dart +++ b/lib/blue/io_type.dart @@ -9,7 +9,7 @@ List getDeviceType(DeviceType deviceType) { List t = ['758824']; switch (deviceType) { case DeviceType.blue: - t = ['758824', '75']; + t = ['758824', '75', '768824', '76']; break; case DeviceType.gateway: t = ['758825'];