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