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