From 4a725be23fa953e970023aa0d377bef79ee4b8a2 Mon Sep 17 00:00:00 2001 From: liyi Date: Mon, 12 May 2025 13:57:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=B0=83=E6=95=B4=E8=93=9D=E7=89=99?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=97=B6=E5=88=A4=E6=96=AD=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=88=B0=E7=9A=84=E8=AE=BE=E5=A4=87=E6=98=AF=E5=90=A6=E9=85=8D?= =?UTF-8?q?=E5=AF=B9=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/blue/blue_manage.dart | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/blue/blue_manage.dart b/lib/blue/blue_manage.dart index cdc9ae3e..0259a5c0 100755 --- a/lib/blue/blue_manage.dart +++ b/lib/blue/blue_manage.dart @@ -319,22 +319,34 @@ class BlueManage { 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(); + final String cleanUuid = uuid.toLowerCase(); if (cleanUuid.length == 8) { - // 8位,判断前两位 + // 8位,判断第4、5位 + String pairStatus = cleanUuid.substring(4, 6); // 第4、5位(索引3和4) for (final prefix in prefixes) { if (cleanUuid.startsWith(prefix)) { - return true; + // 00=未配对,01=已配对 + if (pairStatus == '00') { + return true; // 未配对才返回true + } + // 已配对(01)不返回true,继续判断下一个uuid } } - } else if (cleanUuid.length == 32) { + } else { // 128位,判断前8位的第3、第4位 - final String first8 = cleanUuid.substring(0, 8); - if (first8.length >= 4) { - final String thirdAndFourth = first8.substring(2, 4); // 索引2和3 + if (cleanUuid.length >= 32) { + final String thirdAndFourth = cleanUuid.substring(2, 4); // 索引2和3 for (final prefix in prefixes) { if (thirdAndFourth == prefix) { - return true; + // 判断配对状态(带横杠UUID的第31、32位,从1开始计数) + if (cleanUuid.length >= 32) { + String pairStatus = cleanUuid.substring(30, 32); // 第31、32位(从1开始计数) + // 00=未配对,01=已配对 + if (pairStatus == '00') { + return true; // 未配对才返回true + } + // 已配对(01)不返回true,继续判断下一个uuid + } } } }