fix:调整蓝牙命令时的搜索逻辑

This commit is contained in:
liyi 2025-05-13 09:47:35 +08:00
parent 905368ec8d
commit 6dc1627622

View File

@ -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); // 4534
for (final prefix in prefixes) {
if (cleanUuid.startsWith(prefix)) {
// 00=01=
if (pairStatus == '00') {
return true; // true
if (isSingle) {
return true; // isSingle为truetrue
} else {
// 00=01=
if (pairStatus == '00') {
return true; // true
}
// 01trueuuid
}
// 01trueuuid
}
}
} else {
@ -338,14 +347,19 @@ class BlueManage {
final String thirdAndFourth = cleanUuid.substring(2, 4); // 23
for (final prefix in prefixes) {
if (thirdAndFourth == prefix) {
// UUID的第31321
if (cleanUuid.length >= 32) {
String pairStatus = cleanUuid.substring(30, 32); // 31321
// 00=01=
if (pairStatus == '00') {
return true; // true
if (isSingle) {
return true; // isSingle为truetrue
} else {
// UUID的第31321
if (cleanUuid.length >= 32) {
String pairStatus =
cleanUuid.substring(30, 32); // 31321
// 00=01=
if (pairStatus == '00') {
return true; // true
}
// 01trueuuid
}
// 01trueuuid
}
}
}