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;
}
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相同的元素
@ -272,11 +273,11 @@ class BlueManage {
}
final isMatch = _isMatch(
scanResult.advertisementData.serviceUuids
.map((e) => e.uuid)
.toList(),
deviceType: deviceType,
);
scanResult.advertisementData.serviceUuids
.map((e) => e.uuid)
.toList(),
deviceType: deviceType,
isSingle: false);
//
if (isMatch && (scanResult.rssi >= -100)) {
// id相同的元素
@ -320,26 +321,69 @@ class BlueManage {
/// uuid
bool _isMatch(List<String> serviceUuids,
{DeviceType deviceType = DeviceType.blue}) {
{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.replaceAll('-', '').toLowerCase();
final String cleanUuid = uuid.toLowerCase();
if (cleanUuid.length == 8) {
// 8
// 845
String pairStatus = cleanUuid.substring(4, 6); // 4534
for (final prefix in prefixes) {
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
final String first8 = cleanUuid.substring(0, 8);
if (first8.length >= 4) {
final String thirdAndFourth = first8.substring(2, 4); // 23
for (final prefix in prefixes) {
if (thirdAndFourth == prefix) {
return true;
if (cleanUuid.length >= 32) {
if (deviceType == DeviceType.blue) {
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
}
}
}
}
} 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'];
switch (deviceType) {
case DeviceType.blue:
t = ['758824', '75', '768824', '76'];
t = ['758824', '75', '768824', '76','24'];
break;
case DeviceType.gateway:
t = ['758825'];
t = ['758825','25'];
break;
}
return t;