fix: 修复网关无法扫描到的问题

This commit is contained in:
liuyanfeng 2025-08-22 14:45:08 +08:00
parent f0de103c46
commit 553cbd8d09
2 changed files with 66 additions and 22 deletions

View File

@ -190,10 +190,11 @@ 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相同的元素
@ -272,11 +273,11 @@ class BlueManage {
} }
final isMatch = _isMatch( final isMatch = _isMatch(
scanResult.advertisementData.serviceUuids scanResult.advertisementData.serviceUuids
.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)) {
// id相同的元素 // id相同的元素
@ -320,26 +321,69 @@ class BlueManage {
/// uuid /// uuid
bool _isMatch(List<String> serviceUuids, bool _isMatch(List<String> serviceUuids,
{DeviceType deviceType = DeviceType.blue}) { {DeviceType deviceType = DeviceType.blue, required bool isSingle}) {
final List<String> prefixes = final List<String> prefixes =
getDeviceType(deviceType).map((e) => e.toLowerCase()).toList(); getDeviceType(deviceType).map((e) => e.toLowerCase()).toList();
for (String uuid in serviceUuids) { for (String uuid in serviceUuids) {
final String cleanUuid = uuid.replaceAll('-', '').toLowerCase(); final String cleanUuid = uuid.toLowerCase();
if (cleanUuid.length == 8) { if (cleanUuid.length == 8) {
// 8 // 845
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)) {
return true; if (isSingle) {
return true; // isSingle为truetrue
} else {
// 00=01=
if (pairStatus == '00') {
return true; // true
}
// 01trueuuid
}
} }
} }
} else if (cleanUuid.length == 32) { } else {
// 128834 // 128834
final String first8 = cleanUuid.substring(0, 8); if (cleanUuid.length >= 32) {
if (first8.length >= 4) { if (deviceType == DeviceType.blue) {
final String thirdAndFourth = first8.substring(2, 4); // 23 final String thirdAndFourth = cleanUuid.substring(6, 8); // 23
for (final prefix in prefixes) { for (final prefix in prefixes) {
if (thirdAndFourth == prefix) { if (thirdAndFourth == prefix) {
return 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
}
}
}
}
} else if (deviceType == DeviceType.gateway) {
final String thirdAndFourth = cleanUuid.substring(6, 8); // 23
for (final prefix in prefixes) {
if (thirdAndFourth == prefix) {
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
}
}
}
} }
} }
} }

View File

@ -9,10 +9,10 @@ List<String> getDeviceType(DeviceType deviceType) {
List<String> t = ['758824']; List<String> t = ['758824'];
switch (deviceType) { switch (deviceType) {
case DeviceType.blue: case DeviceType.blue:
t = ['758824', '75', '768824', '76']; t = ['758824', '75', '768824', '76','24'];
break; break;
case DeviceType.gateway: case DeviceType.gateway:
t = ['758825']; t = ['758825','25'];
break; break;
} }
return t; return t;