fix: 修复网关无法扫描到的问题
This commit is contained in:
parent
f0de103c46
commit
553cbd8d09
@ -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位,判断前两位
|
||||
// 8位,判断第4、5位
|
||||
String pairStatus = cleanUuid.substring(4, 6); // 第4、5位(索引3和4)
|
||||
for (final prefix in prefixes) {
|
||||
if (cleanUuid.startsWith(prefix)) {
|
||||
return true;
|
||||
if (isSingle) {
|
||||
return true; // isSingle为true,前缀匹配即返回true
|
||||
} else {
|
||||
// 00=未配对,01=已配对
|
||||
if (pairStatus == '00') {
|
||||
return true; // 未配对才返回true
|
||||
}
|
||||
// 已配对(01)不返回true,继续判断下一个uuid
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (cleanUuid.length == 32) {
|
||||
} else {
|
||||
// 128位,判断前8位的第3、第4位
|
||||
final String first8 = cleanUuid.substring(0, 8);
|
||||
if (first8.length >= 4) {
|
||||
final String thirdAndFourth = first8.substring(2, 4); // 索引2和3
|
||||
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); // 索引2和3
|
||||
for (final prefix in prefixes) {
|
||||
if (thirdAndFourth == prefix) {
|
||||
if (isSingle) {
|
||||
return true; // isSingle为true,前缀匹配即返回true
|
||||
} else {
|
||||
// 判断配对状态(带横杠UUID的第31、32位,从1开始计数)
|
||||
if (cleanUuid.length >= 32) {
|
||||
String pairStatus =
|
||||
cleanUuid.substring(30, 32); // 第31、32位(从1开始计数)
|
||||
// 00=未配对,01=已配对
|
||||
if (pairStatus == '00') {
|
||||
return true; // 未配对才返回true
|
||||
}
|
||||
// 已配对(01)不返回true,继续判断下一个uuid
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (deviceType == DeviceType.gateway) {
|
||||
final String thirdAndFourth = cleanUuid.substring(6, 8); // 索引2和3
|
||||
for (final prefix in prefixes) {
|
||||
if (thirdAndFourth == prefix) {
|
||||
if (isSingle) {
|
||||
return true; // isSingle为true,前缀匹配即返回true
|
||||
} else {
|
||||
// 判断配对状态(带横杠UUID的第31、32位,从1开始计数)
|
||||
if (cleanUuid.length >= 32) {
|
||||
String pairStatus =
|
||||
cleanUuid.substring(30, 32); // 第31、32位(从1开始计数)
|
||||
// 00=未配对,01=已配对
|
||||
if (pairStatus == '00') {
|
||||
return true; // 未配对才返回true
|
||||
}
|
||||
// 已配对(01)不返回true,继续判断下一个uuid
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user