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,6 +330,9 @@ 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)) {
if (isSingle) {
return true; // isSingle为truetrue
} else {
// 00=01= // 00=01=
if (pairStatus == '00') { if (pairStatus == '00') {
return true; // true return true; // true
@ -332,15 +340,20 @@ class BlueManage {
// 01trueuuid // 01trueuuid
} }
} }
}
} else { } else {
// 128834 // 128834
if (cleanUuid.length >= 32) { if (cleanUuid.length >= 32) {
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) {
if (isSingle) {
return true; // isSingle为truetrue
} else {
// UUID的第31321 // UUID的第31321
if (cleanUuid.length >= 32) { if (cleanUuid.length >= 32) {
String pairStatus = cleanUuid.substring(30, 32); // 31321 String pairStatus =
cleanUuid.substring(30, 32); // 31321
// 00=01= // 00=01=
if (pairStatus == '00') { if (pairStatus == '00') {
return true; // true return true; // true
@ -352,6 +365,7 @@ class BlueManage {
} }
} }
} }
}
return false; return false;
} }