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