fix:调整蓝牙命令时的搜索逻辑
This commit is contained in:
parent
905368ec8d
commit
6dc1627622
@ -187,10 +187,12 @@ 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相同的元素
|
||||
@ -273,6 +275,7 @@ class BlueManage {
|
||||
.map((e) => e.uuid)
|
||||
.toList(),
|
||||
deviceType: deviceType,
|
||||
isSingle: false,
|
||||
);
|
||||
// 判断名字为空的直接剔除
|
||||
if (isMatch && (scanResult.rssi >= -100)) {
|
||||
@ -316,8 +319,10 @@ class BlueManage {
|
||||
}
|
||||
|
||||
/// 判断是否包含指定的uuid
|
||||
bool _isMatch(List<String> serviceUuids, {DeviceType deviceType = DeviceType.blue}) {
|
||||
final List<String> prefixes = getDeviceType(deviceType).map((e) => e.toLowerCase()).toList();
|
||||
bool _isMatch(List<String> serviceUuids,
|
||||
{DeviceType deviceType = DeviceType.blue, required bool isSingle}) {
|
||||
final List<String> prefixes =
|
||||
getDeviceType(deviceType).map((e) => e.toLowerCase()).toList();
|
||||
for (String uuid in serviceUuids) {
|
||||
final String cleanUuid = uuid.toLowerCase();
|
||||
if (cleanUuid.length == 8) {
|
||||
@ -325,11 +330,15 @@ class BlueManage {
|
||||
String pairStatus = cleanUuid.substring(4, 6); // 第4、5位(索引3和4)
|
||||
for (final prefix in prefixes) {
|
||||
if (cleanUuid.startsWith(prefix)) {
|
||||
// 00=未配对,01=已配对
|
||||
if (pairStatus == '00') {
|
||||
return true; // 未配对才返回true
|
||||
if (isSingle) {
|
||||
return true; // isSingle为true,前缀匹配即返回true
|
||||
} else {
|
||||
// 00=未配对,01=已配对
|
||||
if (pairStatus == '00') {
|
||||
return true; // 未配对才返回true
|
||||
}
|
||||
// 已配对(01)不返回true,继续判断下一个uuid
|
||||
}
|
||||
// 已配对(01)不返回true,继续判断下一个uuid
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -338,14 +347,19 @@ class BlueManage {
|
||||
final String thirdAndFourth = cleanUuid.substring(2, 4); // 索引2和3
|
||||
for (final prefix in prefixes) {
|
||||
if (thirdAndFourth == prefix) {
|
||||
// 判断配对状态(带横杠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
|
||||
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
|
||||
}
|
||||
// 已配对(01)不返回true,继续判断下一个uuid
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user