1.0.81版本打包给宿舍门测试

This commit is contained in:
魏少阳 2024-09-30 10:35:44 +08:00
parent 552c787c5a
commit 9336e83434
7 changed files with 145 additions and 60 deletions

View File

@ -141,14 +141,16 @@ 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();
FlutterBluePlus.isSupported.then((bool isAvailable) async {
if (isAvailable) {
// AppLog.log('startScanSingle 蓝牙状态 系统蓝牙状态:$_adapterState 蓝牙连接状态:$bluetoothConnectionState');
if (_adapterState == BluetoothAdapterState.on) {
try {
BuglyTool.uploadException(
message: 'startScanSingle:$deviceName',
detail: 'startScanSingle$deviceName 开始指定设备名称的扫描蓝牙设备');
//android 3
final int divisor = Platform.isAndroid ? 3 : 1;
FlutterBluePlus.startScan(
@ -166,6 +168,9 @@ class BlueManage {
start.millisecondsSinceEpoch;
AppLog.log(
'扫描到的设备数:${results.length} 是否查找到 $isExit 以查找$milliseconds毫秒');
BuglyTool.uploadException(
message: 'startScanSingle:$deviceName',
detail: 'startScanSingle$deviceName 监听扫描结果 扫描到的设备数:${results.length} 是否查找到 $isExit 以查找$milliseconds毫秒');
if (isExit) {
for (final ScanResult scanResult in results) {
if (((scanResult.advertisementData.serviceUuids.isNotEmpty
@ -187,28 +192,33 @@ class BlueManage {
} else {
scanDevices.add(scanResult);
}
BuglyTool.uploadException(
message: 'startScanSingle:$deviceName',
detail: 'startScanSingle$deviceName 查询到的结果scanResult:$scanResult');
}
}
completer.complete();
}
}, onError: (e) {
AppLog.log(
'扫描失败:$e',
);
BuglyTool.uploadException(
message: 'startScanSingle:$deviceName',
detail: 'startScanSingle$deviceName 监听扫描结果失败 e:${e.toString()}');
AppLog.log('扫描失败:$e',);
});
FlutterBluePlus.cancelWhenScanComplete(subscription);
await completer.future;
scanDevicesCallBack(scanDevices);
subscription.cancel();
} catch (e) {
BuglyTool.uploadException(
message: 'startScanSingle:$deviceName',
detail: 'startScanSingle$deviceName startScanSingle内部逻辑整形失败 e:${e.toString()}');
AppLog.log('扫描失败');
}
} else {
try {
if (Platform.isAndroid) {
await FlutterBluePlus.turnOn();
}
openBlue();
} catch (e) {
AppLog.log('蓝牙打开失败');
}
@ -268,9 +278,7 @@ class BlueManage {
}
} else {
try {
if (Platform.isAndroid) {
await FlutterBluePlus.turnOn();
}
openBlue();
} catch (e) {
AppLog.log('蓝牙打开失败');
}
@ -291,24 +299,36 @@ class BlueManage {
if (_adapterState == BluetoothAdapterState.on) {
//
if (bluetoothConnectionState != BluetoothConnectionState.connected) {
BuglyTool.uploadException(
message: 'blueSendData 蓝牙未连接',
detail: 'blueSendData 蓝牙未连接}');
_connect(deviceName, (BluetoothConnectionState state) {
stateCallBack(bluetoothConnectionState!);
}, isAddEquipment: isAddEquipment);
} else {
BuglyTool.uploadException(
message: 'blueSendData 蓝牙是连接状态',
detail: 'blueSendData 蓝牙是连接状态,直接回调}');
stateCallBack(bluetoothConnectionState!);
}
} else {
BuglyTool.uploadException(
message: 'blueSendData 蓝牙未打开',
detail: 'blueSendData 蓝牙未打开--_adapterState:${BluetoothAdapterState.on}');
try {
stateCallBack(BluetoothConnectionState.disconnected);
openBlue();
} catch (e) {
AppLog.log('蓝牙打开失败');
BuglyTool.uploadException(
message: 'blueSendData 蓝牙打开失败',
detail: 'blueSendData 蓝牙打开失败--_adapterState:${BluetoothAdapterState.on}');
}
}
} else {
BuglyTool.uploadException(
message: 'blueSendData isAvailable状态',
detail: 'blueSendData isAvailable不可用--json');
detail: 'blueSendData isAvailable不可用--isAvailable:$isAvailable');
// FlutterBuglyPlugin.reportException(exceptionName: 'blueSendData isAvailable状态', reason: 'blueSendData isAvailable不可用');
AppLog.log('开始扫描 蓝牙不可用,不能进行蓝牙操作');
}
@ -320,33 +340,47 @@ class BlueManage {
String deviceName, ConnectStateCallBack connectStateCallBack,
{bool isAddEquipment = false}) async {
connectDeviceName = deviceName;
//
final List<ScanResult> devicesList = scanDevices;
// true是有缓存设备
final bool isExistDevice = isExistScanDevices(connectDeviceName);
final bool isCurrentDevice =
CommonDataManage().currentKeyInfo.lockName == deviceName;
//
final bool isCurrentDevice = CommonDataManage().currentKeyInfo.lockName == deviceName;
// mac地址
final String? mac = CommonDataManage().currentKeyInfo.mac;
AppLog.log('开始连接 是否存在缓存:$isExistDevice 是否是当前设备:$isCurrentDevice mac$mac');
if (GetPlatform.isAndroid &&
!isExistDevice &&
isCurrentDevice &&
mac != null) {
if (GetPlatform.isAndroid && !isExistDevice && isCurrentDevice && mac != null) {
// mac地址不为空
BuglyTool.uploadException(
message: '_connect:$deviceName',
detail: '_connect:$deviceName GetPlatform.isAndroid:${GetPlatform.isAndroid} isExistDevice:$isExistDevice mac:$mac');
scanSingleTimer?.cancel();
//android
await doNotSearchBLE(mac, connectStateCallBack,
isAddEquipment: isAddEquipment);
// android
await doNotSearchBLE(mac, connectStateCallBack, isAddEquipment: isAddEquipment);
//
scanSingleTimer = Timer(3.seconds, () {
scanSingleTimer?.cancel();
BuglyTool.uploadException(
message: '_connect:$deviceName',
detail: '_connect$deviceName scanSingleTimer 调用 startScanSingle');
startScanSingle(deviceName, 15, (List<ScanResult> scanDevices) => null);
});
} else if (isAddEquipment == false && isExistDevice == false) {
//使
BuglyTool.uploadException(
message: '_connect:$deviceName',
detail: '_connect$deviceName isAddEquipment:$isAddEquipment isExistDevice:$isExistDevice 下一步调用startScanSingle');
// AppLog.log('无存在设备需要扫描 deviceName:$deviceName isAddEquipment:$isAddEquipment');
startScanSingle(deviceName, 15, (List<ScanResult> scanDevices) {
_connectDevice(scanDevices, deviceName, connectStateCallBack,
isAddEquipment: isAddEquipment);
});
} else {
BuglyTool.uploadException(
message: '_connect:$deviceName',
detail: '_connect$deviceName 直接调用_connectDevice');
// AppLog.log('安卓或者iOS 存在设备不需要扫描 deviceName:$deviceName isAddEquipment:$isAddEquipment');
_connectDevice(devicesList, deviceName, connectStateCallBack,
isAddEquipment: isAddEquipment);
@ -355,21 +389,21 @@ class BlueManage {
//
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;
}
Future<void> _connectDevice(
List<ScanResult> devicesList,
String deviceName,
ConnectStateCallBack connectStateCallBack, {
bool isAddEquipment = false, //
bool isReconnect = true, //
}) async {
ConnectStateCallBack connectStateCallBack,
{
bool isAddEquipment = false, //
bool isReconnect = true, //
}) async {
//
// AppLog.log("devicesList:$devicesList");
final int knownDeviceIndex = devicesList.indexWhere((ScanResult d) =>
(d.device.platformName == deviceName) ||
(d.advertisementData.advName == deviceName));
@ -390,16 +424,27 @@ class BlueManage {
_initListenConnectionState();
}
if (scanResult == null || connectDeviceMacAddress.isEmpty) {
BuglyTool.uploadException(
message: '_connectDevice:$deviceName',
detail: '_connectDevice$deviceName scanResult:$scanResult connectDeviceMacAddress$connectDeviceMacAddress scanResult == null || connectDeviceMacAddress.isEmpty不往下执行');
return;
}
AppLog.log('调用了停止扫描的方法');
await stopScan();
BuglyTool.uploadException(
message: '_connectDevice:$deviceName',
detail: '_connectDevice$deviceName devicesList$devicesList isReconnect:$isReconnect knownDeviceIndex$knownDeviceIndex 调用了停止扫描方法');
if ((scanResult.advertisementData.serviceUuids[0].toString()[31] == '0') &&
isAddEquipment == false) {
//
if (isReconnect == true) {
AppLog.log('该锁已被重置, 重新发送扫描命令');
BuglyTool.uploadException(
message: '_connectDevice:$deviceName',
detail: '_connectDevice$deviceName 该锁已被重置, 重新发送扫描命令 serviceUuids:${scanResult.advertisementData.serviceUuids[0].toString()}');
scanDevices.clear();
startScanSingle(deviceName, 15, (List<ScanResult> scanDevices) {
_connectDevice(scanDevices, deviceName, connectStateCallBack,
@ -420,12 +465,19 @@ class BlueManage {
Future<void> doNotSearchBLE(
String masAdds, ConnectStateCallBack connectStateCallBack,
{bool isAddEquipment = false}) async {
BuglyTool.uploadException(
message: 'doNotSearchBLE:$masAdds',
detail: 'doNotSearchBLE$masAdds 调用doNotSearchBLE');
await FlutterBluePlus.stopScan();
if (bluetoothConnectDevice == null ||
bluetoothConnectDevice?.remoteId.str != masAdds) {
bluetoothConnectDevice = BluetoothDevice.fromId(masAdds);
_initGetMtuSubscription();
_initListenConnectionState();
}else{
BuglyTool.uploadException(
message: 'doNotSearchBLE:$masAdds',
detail: 'doNotSearchBLE$masAdds 未调用_initGetMtuSubscription()、_initListenConnectionState()');
}
//
await bluetoothDeviceConnect(bluetoothConnectDevice!, connectStateCallBack,
@ -454,25 +506,36 @@ class BlueManage {
if (attempt >= maxAttempts) {
AppLog.log('$maxAttempts次后尝试连接失败');
BuglyTool.uploadException(
message: 'bluetoothDeviceConnect:${bluetoothConnectDevice.toString()}',
detail: 'bluetoothDeviceConnect:${bluetoothConnectDevice.toString()} $maxAttempts次后尝试连接失败');
connectStateCallBack(BluetoothConnectionState.disconnected);
}
if (bluetoothConnectionState == BluetoothConnectionState.connected) {
try {
final List<BluetoothService> services =
await bluetoothConnectDevice.discoverServices();
final List<BluetoothService> services = await bluetoothConnectDevice.discoverServices();
//
for (final BluetoothService service in services) {
if (service.uuid == _serviceIdConnect) {
for (final BluetoothCharacteristic characteristic
in service.characteristics) {
if (characteristic.characteristicUuid ==
_characteristicIdSubscription) {
for (final BluetoothCharacteristic characteristic in service.characteristics) {
if (characteristic.characteristicUuid == _characteristicIdSubscription) {
_subScribeToCharacteristic(characteristic);
bluetoothConnectionState = BluetoothConnectionState.connected;
connectStateCallBack(bluetoothConnectionState!);
BuglyTool.uploadException(
message: 'bluetoothDeviceConnect:${bluetoothConnectDevice.toString()}',
detail: 'bluetoothDeviceConnect:${bluetoothConnectDevice.toString()} 发现服务,连接成功,订阅数据');
} else{
BuglyTool.uploadException(
message: 'bluetoothDeviceConnect:${bluetoothConnectDevice.toString()}',
detail: 'bluetoothDeviceConnect:${bluetoothConnectDevice.toString()} characteristic.characteristicUuid != _characteristicIdSubscription 失败');
}
}
}else{
BuglyTool.uploadException(
message: 'bluetoothDeviceConnect:${bluetoothConnectDevice.toString()}',
detail: 'bluetoothDeviceConnect:${bluetoothConnectDevice.toString()} service.uuid != _serviceIdConnec 失败');
}
}
} on Exception catch (e) {
@ -480,6 +543,9 @@ class BlueManage {
connectStateCallBack(bluetoothConnectionState!);
AppLog.log(
'发现设备时失败 e:$e bluetoothConnectionState:$bluetoothConnectionState');
BuglyTool.uploadException(
message: 'bluetoothDeviceConnect:${bluetoothConnectDevice.toString()}',
detail: 'bluetoothDeviceConnect:${bluetoothConnectDevice.toString()} 发现服务时报错 e$e');
rethrow;
}
}

View File

@ -81,7 +81,7 @@ class SenderCancelAddCardCommand extends SenderProtocol {
data.addAll(subData);
if ((data.length % 16) != 0) {
int add = (16 - data.length % 16);
int add = 16 - data.length % 16;
for (int i = 0; i < add; i++) {
data.add(0);
}

View File

@ -206,8 +206,7 @@ class DoorLockLogLogic extends BaseGetXController {
if (entity.errorCode!.codeIsSuccessful) {
state.operateDate = entity.data!.operateDate! ~/ 1000;
state.currentDate = entity.data!.currentDate! ~/ 1000;
AppLog.log(
'entity.data!.currentDate!:${entity.data!.currentDate!} currentDate:${state.currentDate}');
AppLog.log('entity.data!.currentDate!:${entity.data!.currentDate!} currentDate:${state.currentDate}');
senderReferEventRecordTime();
}
}

View File

@ -61,6 +61,8 @@ class LockDetailLogic extends BaseGetXController {
Future<void> _replyOpenLock(Reply reply) async {
final int status = reply.data[6];
BuglyTool.uploadException(message: '_replyOpenLock', detail: '_replyOpenLock:${reply.data}');
switch (status) {
case 0x00:
//
@ -330,14 +332,6 @@ class LockDetailLogic extends BaseGetXController {
//
Future<void> openDoorAction() async {
showBlueConnetctToastTimer(
outTimer: 20,
action: () {
// FlutterBuglyPlugin.reportException(exceptionName: '开门超时处理', reason: '开门超时,断开连接');
BuglyTool.uploadException(message: '开门超时处理', detail: '开门超时,断开连接--json');
resetOpenDoorState();
blueManageDisconnect();
});
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
@ -347,11 +341,31 @@ class LockDetailLogic extends BaseGetXController {
final List<String>? token = await Storage.getStringList(saveBlueToken);
final List<int> getTokenList = changeStringListToIntList(token!);
BlueManage()
.blueSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!,
(BluetoothConnectionState deviceConnectionState) async {
final String command = OpenLockCommand(
lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(),
openMode: state.openDoorModel,
openTime: getUTCNetTime(),
onlineToken: state.lockNetToken,
token: getTokenList,
needAuthor: 1,
signKey: signKeyDataList,
privateKey: getPrivateKeyList,
).toString();
AppLog.log('command:${command}');
showBlueConnetctToastTimer(
outTimer: 20,
action: () {
// FlutterBuglyPlugin.reportException(exceptionName: '开门超时处理', reason: '开门超时,断开连接');
BuglyTool.uploadException(message: '开门超时处理', detail: '开门超时,断开连接--$command');
resetOpenDoorState();
blueManageDisconnect();
});
BlueManage().blueSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!, (BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) {
BuglyTool.uploadException(message: '蓝牙连接成功', detail: '蓝牙连接成功,发送开锁指令--json',data: {'key1':'value1','key2':'value2'});
BuglyTool.uploadException(message: '蓝牙连接成功', detail: '蓝牙连接成功,发送开锁指令--$command');
// FlutterBuglyPlugin.reportException(exceptionName: '蓝牙连接成功', reason: '蓝牙连接成功,发送开锁指令');
IoSenderManage.senderOpenLock(
lockID: BlueManage().connectDeviceName,
@ -364,13 +378,12 @@ class LockDetailLogic extends BaseGetXController {
signKey: signKeyDataList,
privateKey: getPrivateKeyList,
);
} else if (deviceConnectionState ==
BluetoothConnectionState.disconnected) {
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
cancelBlueConnetctToastTimer();
BuglyTool.uploadException(message: '蓝牙连接失败', detail: '蓝牙连接失败,断开连接--$command');
if (state.ifCurrentScreen.value == true) {
showBlueConnetctToast();
}
resetOpenDoorState();
}
});
@ -453,6 +466,9 @@ class LockDetailLogic extends BaseGetXController {
// AppLog.log('从服务器获取联网token:${state.lockNetToken}');
openDoorAction();
} else {
BuglyTool.uploadException(
message: '点击了需要联网开锁 2',
detail: '点击了需要联网开锁 获取连网token失败');
showToast('网络访问失败,请检查网络是否正常'.tr, something: () {
resetOpenDoorState();
cancelBlueConnetctToastTimer();

View File

@ -22,6 +22,7 @@ import '../../../common/XSConstantMacro/XSConstantMacro.dart';
import '../../../tools/appRouteObserver.dart';
import '../../../tools/dateTool.dart';
import '../../../tools/eventBusEventManage.dart';
import '../../../tools/storage.dart';
import '../../../translations/trans_lib.dart';
import '../../lockMian/entity/lockListInfo_entity.dart';
import 'lockDetail_logic.dart';
@ -1432,14 +1433,14 @@ class _LockDetailPageState extends State<LockDetailPage>
state.openLockBtnState.value = 1;
state.animationController!.forward();
AppLog.log('点击开锁');
BuglyTool.time = DateTime.now().millisecondsSinceEpoch;
if (isOpenLockNeedOnline) {
//
state.openDoorModel = 0;
// FlutterBuglyPlugin.reportException(exceptionName: '点击了不需要联网开锁');
BuglyTool.uploadException(
message: '点击了不需要联网开锁',
detail: '点击了不需要联网开锁--------json',
data: {'key1': 'value1', 'key2': 'value2'});
detail: '点击了不需要联网开锁 openDoorModel:${state.openDoorModel}');
AppLog.log('点击开锁 state.openDoorModel = 0 不需要联网');
logic.openDoorAction();
} else {
@ -1448,8 +1449,7 @@ class _LockDetailPageState extends State<LockDetailPage>
// FlutterBuglyPlugin.reportException(exceptionName: '点击了需要联网开锁');
BuglyTool.uploadException(
message: '点击了需要联网开锁',
detail: '点击了需要联网开锁---json',
data: {'key1': 'value1', 'key2': 'value2'});
detail: '点击了需要联网开锁 openDoorModel:${state.openDoorModel}');
AppLog.log('点击开锁 state.openDoorModel = 2 需要联网');
logic.getLockNetToken();
}

View File

@ -13,6 +13,9 @@ import 'package:star_lock/tools/storage.dart';
///
///
class BuglyTool {
static int time = 0;
static Future<void> init() async {
if (F.isProductionEnv) {
//
@ -57,11 +60,11 @@ class BuglyTool {
FlutterBugly.setUserId(userId?.toString() ?? '');
}
static void uploadException({
static Future<void> uploadException({
required String message,
required String detail,
Map? data,
}) {
FlutterBugly.uploadException(message: message, detail: detail, data: data);
}) async {
FlutterBugly.uploadException(message: '${(await Storage.getMobile())!.isNotEmpty ? (await Storage.getMobile()) : (await Storage.getEmail())}+$time ---' + message, detail: detail, data: data);
}
}

View File

@ -92,8 +92,9 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# 1.0.78+2024082701测试国际化功能
# 1.0.79+2024083001测试所有国家国际化功能
# 1.0.79+2024083001测试开完锁数据上传功能
# 1.0.81+2024092901添加开锁数据收集功能
version: 1.0.79+2024090201
version: 1.0.81+2024090201
environment:
sdk: '>=2.12.0 <3.0.0'