feat: Android设备首次直连开锁失败后捅过扫描设备开锁。
This commit is contained in:
parent
b8e6c52afe
commit
07aa8a720c
@ -73,6 +73,7 @@ class BlueManage {
|
|||||||
List<int> lastTimeData = <int>[];
|
List<int> lastTimeData = <int>[];
|
||||||
int? dataLen;
|
int? dataLen;
|
||||||
Timer? scanSingleTimer;
|
Timer? scanSingleTimer;
|
||||||
|
bool needScanSingle = false;
|
||||||
|
|
||||||
static BlueManage? _manager;
|
static BlueManage? _manager;
|
||||||
|
|
||||||
@ -141,7 +142,8 @@ class BlueManage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 开始指定设备名称的扫描蓝牙设备
|
/// 开始指定设备名称的扫描蓝牙设备
|
||||||
Future<void> startScanSingle(String deviceName, int timeout, ScanDevicesCallBack scanDevicesCallBack) async {
|
Future<void> startScanSingle(String deviceName, int timeout,
|
||||||
|
ScanDevicesCallBack scanDevicesCallBack) async {
|
||||||
final DateTime start = DateTime.now();
|
final DateTime start = DateTime.now();
|
||||||
FlutterBluePlus.isSupported.then((bool isAvailable) async {
|
FlutterBluePlus.isSupported.then((bool isAvailable) async {
|
||||||
if (isAvailable) {
|
if (isAvailable) {
|
||||||
@ -151,8 +153,7 @@ class BlueManage {
|
|||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '开始指定设备名称的扫描蓝牙设备',
|
message: '开始指定设备名称的扫描蓝牙设备',
|
||||||
detail: '调用方法是:startScanSingle 指定设备名称是:$deviceName',
|
detail: '调用方法是:startScanSingle 指定设备名称是:$deviceName',
|
||||||
upload: false
|
upload: false);
|
||||||
);
|
|
||||||
//android 扫描比较慢,取样只要 3 分之一
|
//android 扫描比较慢,取样只要 3 分之一
|
||||||
final int divisor = Platform.isAndroid ? 3 : 1;
|
final int divisor = Platform.isAndroid ? 3 : 1;
|
||||||
FlutterBluePlus.startScan(
|
FlutterBluePlus.startScan(
|
||||||
@ -172,9 +173,9 @@ class BlueManage {
|
|||||||
'扫描到的设备数:${results.length} 是否查找到 $isExit 以查找$milliseconds毫秒');
|
'扫描到的设备数:${results.length} 是否查找到 $isExit 以查找$milliseconds毫秒');
|
||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '指定设备名称的扫描蓝牙设备 监听扫描结果',
|
message: '指定设备名称的扫描蓝牙设备 监听扫描结果',
|
||||||
detail: 'startScanSingle$deviceName 监听扫描结果 是否查找到 $isExit 以查找$milliseconds毫秒 扫描到的设备数:${results.length} results:$results',
|
detail:
|
||||||
upload: false
|
'startScanSingle$deviceName 监听扫描结果 是否查找到 $isExit 以查找$milliseconds毫秒 扫描到的设备数:${results.length} results:$results',
|
||||||
);
|
upload: false);
|
||||||
if (isExit) {
|
if (isExit) {
|
||||||
for (final ScanResult scanResult in results) {
|
for (final ScanResult scanResult in results) {
|
||||||
if (((scanResult.advertisementData.serviceUuids.isNotEmpty
|
if (((scanResult.advertisementData.serviceUuids.isNotEmpty
|
||||||
@ -198,21 +199,22 @@ class BlueManage {
|
|||||||
}
|
}
|
||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '遍历扫描到的结果跟缓存的结果对比,如果有最新的就更新缓存',
|
message: '遍历扫描到的结果跟缓存的结果对比,如果有最新的就更新缓存',
|
||||||
detail: 'startScanSingle deviceName:$deviceName 查询到的结果scanResult:$scanResult',
|
detail:
|
||||||
upload: false
|
'startScanSingle deviceName:$deviceName 查询到的结果scanResult:$scanResult',
|
||||||
);
|
upload: false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
completer.complete();
|
completer.complete();
|
||||||
}
|
}
|
||||||
}, onError: (e) {
|
}, onError: (e) {
|
||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '指定设备名称的扫描蓝牙设备 监听扫描结果失败',
|
message: '指定设备名称的扫描蓝牙设备 监听扫描结果失败',
|
||||||
detail: '打印失败问题 e:${e.toString()}',
|
detail: '打印失败问题 e:${e.toString()}',
|
||||||
upload: false
|
upload: false);
|
||||||
);
|
AppLog.log(
|
||||||
AppLog.log('扫描失败:$e',);
|
'扫描失败:$e',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
FlutterBluePlus.cancelWhenScanComplete(subscription);
|
FlutterBluePlus.cancelWhenScanComplete(subscription);
|
||||||
await completer.future;
|
await completer.future;
|
||||||
@ -222,8 +224,7 @@ class BlueManage {
|
|||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '指定设备名称的扫描蓝牙设备 内部逻辑整形失败',
|
message: '指定设备名称的扫描蓝牙设备 内部逻辑整形失败',
|
||||||
detail: 'tartScanSingle内部逻辑整形失败 e:${e.toString()}',
|
detail: 'tartScanSingle内部逻辑整形失败 e:${e.toString()}',
|
||||||
upload: false
|
upload: false);
|
||||||
);
|
|
||||||
AppLog.log('扫描失败');
|
AppLog.log('扫描失败');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -311,26 +312,26 @@ class BlueManage {
|
|||||||
if (bluetoothConnectionState != BluetoothConnectionState.connected) {
|
if (bluetoothConnectionState != BluetoothConnectionState.connected) {
|
||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '点击按钮 蓝牙未连接 下一步扫描连接蓝牙',
|
message: '点击按钮 蓝牙未连接 下一步扫描连接蓝牙',
|
||||||
detail: 'blueSendData 蓝牙连接状态 bluetoothConnectionState:$bluetoothConnectionState deviceName:$deviceName',
|
detail:
|
||||||
upload: false
|
'blueSendData 蓝牙连接状态 bluetoothConnectionState:$bluetoothConnectionState deviceName:$deviceName',
|
||||||
);
|
upload: false);
|
||||||
_connect(deviceName, (BluetoothConnectionState state) {
|
_connect(deviceName, (BluetoothConnectionState state) {
|
||||||
stateCallBack(bluetoothConnectionState!);
|
stateCallBack(bluetoothConnectionState!);
|
||||||
}, isAddEquipment: isAddEquipment);
|
}, isAddEquipment: isAddEquipment);
|
||||||
} else {
|
} else {
|
||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '点击按钮 蓝牙已经连接 下一步扫描连接蓝牙',
|
message: '点击按钮 蓝牙已经连接 下一步扫描连接蓝牙',
|
||||||
detail: 'blueSendData 直接回调状态 蓝牙连接状态bluetoothConnectionState:$bluetoothConnectionState deviceName:$deviceName',
|
detail:
|
||||||
upload: false
|
'blueSendData 直接回调状态 蓝牙连接状态bluetoothConnectionState:$bluetoothConnectionState deviceName:$deviceName',
|
||||||
);
|
upload: false);
|
||||||
stateCallBack(bluetoothConnectionState!);
|
stateCallBack(bluetoothConnectionState!);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '点击按钮 蓝牙未打开',
|
message: '点击按钮 蓝牙未打开',
|
||||||
detail: 'blueSendData 蓝牙未打开--_adapterState:${BluetoothAdapterState.on} deviceName:$deviceName',
|
detail:
|
||||||
upload: false
|
'blueSendData 蓝牙未打开--_adapterState:${BluetoothAdapterState.on} deviceName:$deviceName',
|
||||||
);
|
upload: false);
|
||||||
try {
|
try {
|
||||||
stateCallBack(BluetoothConnectionState.disconnected);
|
stateCallBack(BluetoothConnectionState.disconnected);
|
||||||
openBlue();
|
openBlue();
|
||||||
@ -338,17 +339,16 @@ class BlueManage {
|
|||||||
AppLog.log('蓝牙打开失败');
|
AppLog.log('蓝牙打开失败');
|
||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '点击按钮 蓝牙未打开 然后蓝牙打开失败',
|
message: '点击按钮 蓝牙未打开 然后蓝牙打开失败',
|
||||||
detail: 'blueSendData 蓝牙打开失败--_adapterState:${BluetoothAdapterState.on} deviceName:$deviceName',
|
detail:
|
||||||
upload: false
|
'blueSendData 蓝牙打开失败--_adapterState:${BluetoothAdapterState.on} deviceName:$deviceName',
|
||||||
);
|
upload: false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '点击按钮 蓝牙状态不可用',
|
message: '点击按钮 蓝牙状态不可用',
|
||||||
detail: 'blueSendData 蓝牙状态不可用--isAvailable:$isAvailable',
|
detail: 'blueSendData 蓝牙状态不可用--isAvailable:$isAvailable',
|
||||||
upload: false
|
upload: false);
|
||||||
);
|
|
||||||
stateCallBack(BluetoothConnectionState.disconnected);
|
stateCallBack(BluetoothConnectionState.disconnected);
|
||||||
AppLog.log('开始扫描 蓝牙不可用,不能进行蓝牙操作');
|
AppLog.log('开始扫描 蓝牙不可用,不能进行蓝牙操作');
|
||||||
}
|
}
|
||||||
@ -365,38 +365,74 @@ class BlueManage {
|
|||||||
// 是否有缓存设备 true是有缓存设备
|
// 是否有缓存设备 true是有缓存设备
|
||||||
final bool isExistDevice = isExistScanDevices(connectDeviceName);
|
final bool isExistDevice = isExistScanDevices(connectDeviceName);
|
||||||
// 是否是当前设备
|
// 是否是当前设备
|
||||||
final bool isCurrentDevice = CommonDataManage().currentKeyInfo.lockName == deviceName;
|
final bool isCurrentDevice =
|
||||||
|
CommonDataManage().currentKeyInfo.lockName == deviceName;
|
||||||
// mac地址
|
// mac地址
|
||||||
final String? mac = CommonDataManage().currentKeyInfo.mac;
|
final String? mac = CommonDataManage().currentKeyInfo.mac;
|
||||||
|
|
||||||
AppLog.log('开始连接 是否存在缓存:$isExistDevice 是否是当前设备:$isCurrentDevice mac:$mac');
|
AppLog.log('开始连接 是否存在缓存:$isExistDevice 是否是当前设备:$isCurrentDevice mac:$mac');
|
||||||
if (GetPlatform.isAndroid && !isExistDevice && isCurrentDevice && mac != null) {
|
if (GetPlatform.isAndroid &&
|
||||||
|
!isExistDevice &&
|
||||||
|
isCurrentDevice &&
|
||||||
|
mac != null) {
|
||||||
// 当是安卓设备 且不存在缓存设备 且是当前设备 且mac地址不为空
|
// 当是安卓设备 且不存在缓存设备 且是当前设备 且mac地址不为空
|
||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '开始连接 当是安卓设备 且不存在缓存设备 且是当前设备 且mac地址不为空 上传记录当前方法是:_connect',
|
message: '开始连接 当是安卓设备 且不存在缓存设备 且是当前设备 且mac地址不为空 上传记录当前方法是:_connect',
|
||||||
detail: '调用方法_connect deviceName:$deviceName GetPlatform.isAndroid:${GetPlatform.isAndroid} isExistDevice:$isExistDevice mac:$mac',
|
detail:
|
||||||
upload: false
|
'调用方法_connect deviceName:$deviceName GetPlatform.isAndroid:${GetPlatform.isAndroid} isExistDevice:$isExistDevice mac:$mac needScanSingle:$needScanSingle',
|
||||||
);
|
upload: false);
|
||||||
scanSingleTimer?.cancel();
|
// scanSingleTimer?.cancel();
|
||||||
// 兼容android 的低配手机
|
// 兼容android 的低配手机
|
||||||
await doNotSearchBLE(mac, connectStateCallBack, isAddEquipment: isAddEquipment);
|
try {
|
||||||
//
|
if (!needScanSingle) {
|
||||||
scanSingleTimer = Timer(3.seconds, () {
|
BuglyTool.uploadException(
|
||||||
scanSingleTimer?.cancel();
|
message:
|
||||||
|
'开始连接 当是安卓设备 且不存在缓存设备 且是当前设备 且mac地址不为空 上传记录当前方法是:_connect',
|
||||||
|
detail: '调用方法doNotSearchBLE,直接连接,needScanSingle:$needScanSingle',
|
||||||
|
upload: false);
|
||||||
|
await doNotSearchBLE(mac, connectStateCallBack,
|
||||||
|
isAddEquipment: isAddEquipment);
|
||||||
|
} else {
|
||||||
|
BuglyTool.uploadException(
|
||||||
|
message:
|
||||||
|
'开始连接 当是安卓设备 且不存在缓存设备 且是当前设备 且mac地址不为空 上传记录当前方法是:_connect',
|
||||||
|
detail:
|
||||||
|
'调用方法startScanSingle,执行扫描函数,needScanSingle:$needScanSingle',
|
||||||
|
upload: false);
|
||||||
|
startScanSingle(deviceName, 15, (List<ScanResult> scanDevices) {
|
||||||
|
_connectDevice(scanDevices, deviceName, connectStateCallBack,
|
||||||
|
isAddEquipment: isAddEquipment);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '开始连接 当是安卓设备 且不存在缓存设备 且是当前设备 且mac地址不为空 3秒以后调用startScanSingle 上传记录当前方法是:_connect',
|
message: '开始连接 当是安卓设备 且不存在缓存设备 且是当前设备 且mac地址不为空 上传记录当前方法是:_connect',
|
||||||
detail: '_connect deviceName:$deviceName scanSingleTimer调用startScanSingle',
|
detail: '调用方法doNotSearchBLE发生异常,执行扫描函数 startScanSingle,异常信息:$e',
|
||||||
upload: false
|
upload: false);
|
||||||
);
|
startScanSingle(deviceName, 15, (List<ScanResult> scanDevices) {
|
||||||
startScanSingle(deviceName, 15, (List<ScanResult> scanDevices) => null);
|
_connectDevice(scanDevices, deviceName, connectStateCallBack,
|
||||||
});
|
isAddEquipment: isAddEquipment);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// scanSingleTimer = Timer(3.seconds, () {
|
||||||
|
// scanSingleTimer?.cancel();
|
||||||
|
// BuglyTool.uploadException(
|
||||||
|
// message:
|
||||||
|
// '开始连接 当是安卓设备 且不存在缓存设备 且是当前设备 且mac地址不为空 3秒以后调用startScanSingle 上传记录当前方法是:_connect',
|
||||||
|
// detail:
|
||||||
|
// '_connect deviceName:$deviceName scanSingleTimer调用startScanSingle',
|
||||||
|
// upload: false);
|
||||||
|
// startScanSingle(deviceName, 15, (List<ScanResult> scanDevices) => null);
|
||||||
|
// });ƒ
|
||||||
} else if (isAddEquipment == false && isExistDevice == false) {
|
} else if (isAddEquipment == false && isExistDevice == false) {
|
||||||
// 取消缓存直接使用,存在配对场景设备信息会更变
|
// 取消缓存直接使用,存在配对场景设备信息会更变
|
||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '取消缓存直接使用,存在配对场景设备信息会更变 然后开始指定设备名称的扫描蓝牙设备 上传记录当前方法是:_connect',
|
message:
|
||||||
detail: '符合条件(isAddEquipment == false && isExistDevice == false) 下一步调用startScanSingle',
|
'取消缓存直接使用,存在配对场景设备信息会更变 然后开始指定设备名称的扫描蓝牙设备 上传记录当前方法是:_connect',
|
||||||
upload: false
|
detail:
|
||||||
);
|
'符合条件(isAddEquipment == false && isExistDevice == false) 下一步调用startScanSingle',
|
||||||
|
upload: false);
|
||||||
|
|
||||||
// AppLog.log('无存在设备需要扫描 deviceName:$deviceName isAddEquipment:$isAddEquipment');
|
// AppLog.log('无存在设备需要扫描 deviceName:$deviceName isAddEquipment:$isAddEquipment');
|
||||||
startScanSingle(deviceName, 15, (List<ScanResult> scanDevices) {
|
startScanSingle(deviceName, 15, (List<ScanResult> scanDevices) {
|
||||||
@ -406,9 +442,9 @@ class BlueManage {
|
|||||||
} else {
|
} else {
|
||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '没有扫描直接调用连接设备 上传记录当前方法是:_connect',
|
message: '没有扫描直接调用连接设备 上传记录当前方法是:_connect',
|
||||||
detail: '走这个方法是有缓存或者添加设备的时候以及不符合(GetPlatform.isAndroid && !isExistDevice && isCurrentDevice && mac != null) deviceName:$deviceName 直接调用_connectDevice',
|
detail:
|
||||||
upload: false
|
'走这个方法是有缓存或者添加设备的时候以及不符合(GetPlatform.isAndroid && !isExistDevice && isCurrentDevice && mac != null) deviceName:$deviceName 直接调用_connectDevice',
|
||||||
);
|
upload: false);
|
||||||
// AppLog.log('安卓或者iOS 存在设备不需要扫描 deviceName:$deviceName isAddEquipment:$isAddEquipment');
|
// AppLog.log('安卓或者iOS 存在设备不需要扫描 deviceName:$deviceName isAddEquipment:$isAddEquipment');
|
||||||
_connectDevice(devicesList, deviceName, connectStateCallBack,
|
_connectDevice(devicesList, deviceName, connectStateCallBack,
|
||||||
isAddEquipment: isAddEquipment);
|
isAddEquipment: isAddEquipment);
|
||||||
@ -417,18 +453,19 @@ class BlueManage {
|
|||||||
|
|
||||||
//查找缓存里面是否有设备
|
//查找缓存里面是否有设备
|
||||||
bool isExistScanDevices(String connectDeviceName) {
|
bool isExistScanDevices(String connectDeviceName) {
|
||||||
final bool isExistDevice = scanDevices.any((ScanResult element) => element.device.platformName == connectDeviceName || element.advertisementData.advName == connectDeviceName);
|
final bool isExistDevice = scanDevices.any((ScanResult element) =>
|
||||||
|
element.device.platformName == connectDeviceName ||
|
||||||
|
element.advertisementData.advName == connectDeviceName);
|
||||||
return isExistDevice;
|
return isExistDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _connectDevice(
|
Future<void> _connectDevice(
|
||||||
List<ScanResult> devicesList,
|
List<ScanResult> devicesList,
|
||||||
String deviceName,
|
String deviceName,
|
||||||
ConnectStateCallBack connectStateCallBack,
|
ConnectStateCallBack connectStateCallBack, {
|
||||||
{
|
bool isAddEquipment = false, // 是否是添加设备之前
|
||||||
bool isAddEquipment = false, // 是否是添加设备之前
|
bool isReconnect = true, // 是否是重连
|
||||||
bool isReconnect = true, // 是否是重连
|
}) async {
|
||||||
}) async {
|
|
||||||
// 判断数组列表里面是否有这个设备
|
// 判断数组列表里面是否有这个设备
|
||||||
// AppLog.log("devicesList:$devicesList");
|
// AppLog.log("devicesList:$devicesList");
|
||||||
|
|
||||||
@ -453,25 +490,27 @@ class BlueManage {
|
|||||||
}
|
}
|
||||||
if (scanResult == null || connectDeviceMacAddress.isEmpty) {
|
if (scanResult == null || connectDeviceMacAddress.isEmpty) {
|
||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '扫描结果scanResult == null || connectDeviceMacAddress.isEmpty不往下执行 return 上传记录当前方法是:_connectDevice',
|
message:
|
||||||
detail: 'scanResult:$scanResult connectDeviceMacAddress:$connectDeviceMacAddress',
|
'扫描结果scanResult == null || connectDeviceMacAddress.isEmpty不往下执行 return 上传记录当前方法是:_connectDevice',
|
||||||
upload: false
|
detail:
|
||||||
);
|
'scanResult:$scanResult connectDeviceMacAddress:$connectDeviceMacAddress',
|
||||||
|
upload: false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AppLog.log('调用了停止扫描的方法');
|
AppLog.log('调用了停止扫描的方法');
|
||||||
await stopScan();
|
await stopScan();
|
||||||
|
|
||||||
if ((scanResult.advertisementData.serviceUuids[0].toString()[31] == '0') && isAddEquipment == false) {
|
if ((scanResult.advertisementData.serviceUuids[0].toString()[31] == '0') &&
|
||||||
|
isAddEquipment == false) {
|
||||||
// 添加这个判断是因为有些苹果设备或者安卓等性能比较好的设备时,添加完锁之后,锁板未改变为已添加状态之前,就进行了蓝牙连接,导致添加完锁就失败,这里进行了判断,如果第一次连接失败,就清除缓存重新扫描连接
|
// 添加这个判断是因为有些苹果设备或者安卓等性能比较好的设备时,添加完锁之后,锁板未改变为已添加状态之前,就进行了蓝牙连接,导致添加完锁就失败,这里进行了判断,如果第一次连接失败,就清除缓存重新扫描连接
|
||||||
if (isReconnect == true) {
|
if (isReconnect == true) {
|
||||||
AppLog.log('该锁已被重置, 重新发送扫描命令');
|
AppLog.log('该锁已被重置, 重新发送扫描命令');
|
||||||
|
|
||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '该锁已被重置, 重新发送扫描命令startScanSingle 上传记录当前方法是:_connectDevice',
|
message: '该锁已被重置, 重新发送扫描命令startScanSingle 上传记录当前方法是:_connectDevice',
|
||||||
detail: '添加这个判断是因为有些苹果设备或者安卓等性能比较好的设备时,添加完锁之后,锁板未改变为已添加状态之前,就进行了蓝牙连接,导致添加完锁就失败,这里进行了判断,如果第一次连接失败,就清除缓存重新扫描连接 该锁已被重置, 重新发送扫描命令 serviceUuids:${scanResult.advertisementData.serviceUuids[0].toString()}',
|
detail:
|
||||||
upload: false
|
'添加这个判断是因为有些苹果设备或者安卓等性能比较好的设备时,添加完锁之后,锁板未改变为已添加状态之前,就进行了蓝牙连接,导致添加完锁就失败,这里进行了判断,如果第一次连接失败,就清除缓存重新扫描连接 该锁已被重置, 重新发送扫描命令 serviceUuids:${scanResult.advertisementData.serviceUuids[0].toString()}',
|
||||||
);
|
upload: false);
|
||||||
|
|
||||||
scanDevices.clear();
|
scanDevices.clear();
|
||||||
startScanSingle(deviceName, 15, (List<ScanResult> scanDevices) {
|
startScanSingle(deviceName, 15, (List<ScanResult> scanDevices) {
|
||||||
@ -485,18 +524,18 @@ class BlueManage {
|
|||||||
|
|
||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '提示该锁已被重置, 回调断开连接, 清除缓存,上传记录当前方法是:_connectDevice',
|
message: '提示该锁已被重置, 回调断开连接, 清除缓存,上传记录当前方法是:_connectDevice',
|
||||||
detail: 'isReconnect:$isReconnect serviceUuids:${scanResult.advertisementData.serviceUuids[0].toString()}',
|
detail:
|
||||||
upload: false
|
'isReconnect:$isReconnect serviceUuids:${scanResult.advertisementData.serviceUuids[0].toString()}',
|
||||||
);
|
upload: false);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '从devicesList里面查到了设备 下一步连接设备 上传记录当前方法是:_connectDevice',
|
message: '从devicesList里面查到了设备 下一步连接设备 上传记录当前方法是:_connectDevice',
|
||||||
detail: 'devicesList:$devicesList scanResult:${scanResult.toString()} bluetoothConnectDevice:${bluetoothConnectDevice.toString()} connectDeviceMacAddress:$connectDeviceMacAddress',
|
detail:
|
||||||
upload: false
|
'devicesList:$devicesList scanResult:${scanResult.toString()} bluetoothConnectDevice:${bluetoothConnectDevice.toString()} connectDeviceMacAddress:$connectDeviceMacAddress',
|
||||||
);
|
upload: false);
|
||||||
|
|
||||||
//连接设备
|
//连接设备
|
||||||
await bluetoothDeviceConnect(bluetoothConnectDevice!, connectStateCallBack);
|
await bluetoothDeviceConnect(bluetoothConnectDevice!, connectStateCallBack);
|
||||||
@ -516,14 +555,13 @@ class BlueManage {
|
|||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '直接给蓝牙设备写入 上传记录当前方法是:doNotSearchBLE',
|
message: '直接给蓝牙设备写入 上传记录当前方法是:doNotSearchBLE',
|
||||||
detail: '直接给蓝牙设备写入 通过fromId方法创建一个BluetoothDevice masAdds:$masAdds',
|
detail: '直接给蓝牙设备写入 通过fromId方法创建一个BluetoothDevice masAdds:$masAdds',
|
||||||
upload: false
|
upload: false);
|
||||||
);
|
} else {
|
||||||
}else{
|
|
||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '直接给蓝牙设备写入 上传记录当前方法是:doNotSearchBLE',
|
message: '直接给蓝牙设备写入 上传记录当前方法是:doNotSearchBLE',
|
||||||
detail: '直接给蓝牙设备写入 用传入的bluetoothConnectDevice:${bluetoothConnectDevice.toString()}连接 masAdds:$masAdds',
|
detail:
|
||||||
upload: false
|
'直接给蓝牙设备写入 用传入的bluetoothConnectDevice:${bluetoothConnectDevice.toString()}连接 masAdds:$masAdds',
|
||||||
);
|
upload: false);
|
||||||
}
|
}
|
||||||
//尝试连接设备
|
//尝试连接设备
|
||||||
await bluetoothDeviceConnect(bluetoothConnectDevice!, connectStateCallBack,
|
await bluetoothDeviceConnect(bluetoothConnectDevice!, connectStateCallBack,
|
||||||
@ -554,54 +592,60 @@ class BlueManage {
|
|||||||
AppLog.log('$maxAttempts次后尝试连接失败');
|
AppLog.log('$maxAttempts次后尝试连接失败');
|
||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '连接三次超时断开连接 回调断开连接 上传记录当前方法是:bluetoothDeviceConnect',
|
message: '连接三次超时断开连接 回调断开连接 上传记录当前方法是:bluetoothDeviceConnect',
|
||||||
detail: 'bluetoothDeviceConnect:${bluetoothConnectDevice.toString()} $maxAttempts次后尝试连接失败',
|
detail:
|
||||||
upload: false
|
'bluetoothDeviceConnect:${bluetoothConnectDevice.toString()} $maxAttempts次后尝试连接失败',
|
||||||
);
|
upload: false);
|
||||||
|
needScanSingle = true;
|
||||||
connectStateCallBack(BluetoothConnectionState.disconnected);
|
connectStateCallBack(BluetoothConnectionState.disconnected);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bluetoothConnectionState == BluetoothConnectionState.connected) {
|
if (bluetoothConnectionState == BluetoothConnectionState.connected) {
|
||||||
try {
|
try {
|
||||||
final List<BluetoothService> services = await bluetoothConnectDevice.discoverServices();
|
needScanSingle = false;
|
||||||
|
final List<BluetoothService> services =
|
||||||
|
await bluetoothConnectDevice.discoverServices();
|
||||||
//循环判断服务
|
//循环判断服务
|
||||||
for (final BluetoothService service in services) {
|
for (final BluetoothService service in services) {
|
||||||
if (service.uuid == _serviceIdConnect) {
|
if (service.uuid == _serviceIdConnect) {
|
||||||
for (final BluetoothCharacteristic characteristic in service.characteristics) {
|
for (final BluetoothCharacteristic characteristic
|
||||||
if (characteristic.characteristicUuid == _characteristicIdSubscription) {
|
in service.characteristics) {
|
||||||
|
if (characteristic.characteristicUuid ==
|
||||||
|
_characteristicIdSubscription) {
|
||||||
_subScribeToCharacteristic(characteristic);
|
_subScribeToCharacteristic(characteristic);
|
||||||
bluetoothConnectionState = BluetoothConnectionState.connected;
|
bluetoothConnectionState = BluetoothConnectionState.connected;
|
||||||
connectStateCallBack(bluetoothConnectionState!);
|
connectStateCallBack(bluetoothConnectionState!);
|
||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '订阅成功 上传记录当前方法是:bluetoothDeviceConnect',
|
message: '订阅成功 上传记录当前方法是:bluetoothDeviceConnect',
|
||||||
detail: '发现服务,连接成功,订阅数据 bluetoothDeviceConnect:${bluetoothConnectDevice.toString()} ',
|
detail:
|
||||||
upload: false
|
'发现服务,连接成功,订阅数据 bluetoothDeviceConnect:${bluetoothConnectDevice.toString()} ',
|
||||||
);
|
upload: false);
|
||||||
} else{
|
} else {
|
||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '订阅失败 上传记录当前方法是:bluetoothDeviceConnect',
|
message: '订阅失败 上传记录当前方法是:bluetoothDeviceConnect',
|
||||||
detail: '失败原因: characteristic.characteristicUuid:${characteristic.characteristicUuid} != _characteristicIdSubscription:$_characteristicIdSubscription bluetoothDeviceConnect:${bluetoothConnectDevice.toString()}',
|
detail:
|
||||||
upload: false
|
'失败原因: characteristic.characteristicUuid:${characteristic.characteristicUuid} != _characteristicIdSubscription:$_characteristicIdSubscription bluetoothDeviceConnect:${bluetoothConnectDevice.toString()}',
|
||||||
);
|
upload: false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '订阅失败 上传记录当前方法是:bluetoothDeviceConnect',
|
message: '订阅失败 上传记录当前方法是:bluetoothDeviceConnect',
|
||||||
detail: '失败原因: service.uuid:${service.uuid} != _serviceIdConnect:$_serviceIdConnect bluetoothDeviceConnect:${bluetoothConnectDevice.toString()}',
|
detail:
|
||||||
upload: false
|
'失败原因: service.uuid:${service.uuid} != _serviceIdConnect:$_serviceIdConnect bluetoothDeviceConnect:${bluetoothConnectDevice.toString()}',
|
||||||
);
|
upload: false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
|
needScanSingle = true;
|
||||||
bluetoothConnectionState = BluetoothConnectionState.disconnected;
|
bluetoothConnectionState = BluetoothConnectionState.disconnected;
|
||||||
connectStateCallBack(bluetoothConnectionState!);
|
connectStateCallBack(bluetoothConnectionState!);
|
||||||
AppLog.log(
|
AppLog.log(
|
||||||
'发现设备时失败 e:$e bluetoothConnectionState:$bluetoothConnectionState');
|
'发现设备时失败 e:$e bluetoothConnectionState:$bluetoothConnectionState');
|
||||||
BuglyTool.uploadException(
|
BuglyTool.uploadException(
|
||||||
message: '发现服务时失败',
|
message: '发现服务时失败',
|
||||||
detail: '发现服务时报错原因e:$e bluetoothDeviceConnect:${bluetoothConnectDevice.toString()}',
|
detail:
|
||||||
upload: false
|
'发现服务时报错原因e:$e bluetoothDeviceConnect:${bluetoothConnectDevice.toString()}',
|
||||||
);
|
upload: false);
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user