diff --git a/lib/blue/blue_manage.dart b/lib/blue/blue_manage.dart index f90753b4..6fb305c5 100755 --- a/lib/blue/blue_manage.dart +++ b/lib/blue/blue_manage.dart @@ -190,10 +190,11 @@ class BlueManage { continue; } - final isMatch = _isMatch(scanResult - .advertisementData.serviceUuids - .map((e) => e.uuid) - .toList()); + final isMatch = _isMatch( + scanResult.advertisementData.serviceUuids + .map((e) => e.uuid) + .toList(), + isSingle: true); if (isMatch && (scanResult.rssi >= -100)) { // 查询id相同的元素 @@ -272,11 +273,11 @@ class BlueManage { } final isMatch = _isMatch( - scanResult.advertisementData.serviceUuids - .map((e) => e.uuid) - .toList(), - deviceType: deviceType, - ); + scanResult.advertisementData.serviceUuids + .map((e) => e.uuid) + .toList(), + deviceType: deviceType, + isSingle: false); // 判断名字为空的直接剔除 if (isMatch && (scanResult.rssi >= -100)) { // 查询id相同的元素 @@ -320,26 +321,69 @@ class BlueManage { /// 判断是否包含指定的uuid bool _isMatch(List serviceUuids, - {DeviceType deviceType = DeviceType.blue}) { + {DeviceType deviceType = DeviceType.blue, required bool isSingle}) { 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; + if (isSingle) { + return true; // isSingle为true,前缀匹配即返回true + } else { + // 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 - for (final prefix in prefixes) { - if (thirdAndFourth == prefix) { - return true; + if (cleanUuid.length >= 32) { + if (deviceType == DeviceType.blue) { + final String thirdAndFourth = cleanUuid.substring(6, 8); // 索引2和3 + for (final prefix in prefixes) { + if (thirdAndFourth == prefix) { + if (isSingle) { + return true; // isSingle为true,前缀匹配即返回true + } else { + // 判断配对状态(带横杠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 + } + } + } + } + } else if (deviceType == DeviceType.gateway) { + final String thirdAndFourth = cleanUuid.substring(6, 8); // 索引2和3 + for (final prefix in prefixes) { + if (thirdAndFourth == prefix) { + if (isSingle) { + return true; // isSingle为true,前缀匹配即返回true + } else { + // 判断配对状态(带横杠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 + } + } + } } } } diff --git a/lib/blue/io_type.dart b/lib/blue/io_type.dart index a5f523b4..e234a5dd 100755 --- a/lib/blue/io_type.dart +++ b/lib/blue/io_type.dart @@ -9,10 +9,10 @@ List getDeviceType(DeviceType deviceType) { List t = ['758824']; switch (deviceType) { case DeviceType.blue: - t = ['758824', '75', '768824', '76']; + t = ['758824', '75', '768824', '76','24']; break; case DeviceType.gateway: - t = ['758825']; + t = ['758825','25']; break; } return t;