201 lines
7.3 KiB
Dart
Executable File
201 lines
7.3 KiB
Dart
Executable File
import 'dart:async';
|
|
import 'dart:math';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:rxdart/rxdart.dart';
|
|
import 'package:star_lock/app_settings/app_colors.dart';
|
|
import 'package:star_lock/app_settings/app_settings.dart';
|
|
import 'package:star_lock/blue/blue_manage.dart';
|
|
import 'package:star_lock/blue/io_tool/io_tool.dart';
|
|
import 'package:star_lock/blue/sender_manage.dart';
|
|
import 'package:star_lock/main/lockMian/entity/lockListInfo_entity.dart';
|
|
import 'package:star_lock/mine/about/debug/log.dart';
|
|
import 'package:star_lock/tools/commonDataManage.dart';
|
|
import 'package:star_lock/tools/dateTool.dart';
|
|
import 'package:star_lock/tools/storage.dart';
|
|
|
|
class DebugConsoleController {
|
|
final List<DebugConsoleLog> logs;
|
|
final _streamController = BehaviorSubject<List<DebugConsoleLog>>();
|
|
|
|
DebugConsoleController({List<DebugConsoleLog>? logs}) : logs = logs ?? [];
|
|
|
|
Stream<List<DebugConsoleLog>> get stream => _streamController.stream;
|
|
|
|
void close() => _streamController.close();
|
|
|
|
void notifyUpdate() => _streamController.add(logs);
|
|
|
|
void log(
|
|
Object? message, {
|
|
DebugConsoleLevel level = DebugConsoleLevel.normal,
|
|
DateTime? timestamp,
|
|
StackTrace? stackTrace,
|
|
}) {
|
|
logs.add(DebugConsoleLog(
|
|
message: message,
|
|
level: level,
|
|
timestamp: timestamp,
|
|
stackTrace: stackTrace,
|
|
));
|
|
notifyUpdate();
|
|
}
|
|
|
|
List<DebugConsoleLog> getLogsByLevel(DebugConsoleLevel level) {
|
|
return logs.where((log) => log.level == level).toList();
|
|
}
|
|
|
|
void clear() {
|
|
logs.clear();
|
|
notifyUpdate();
|
|
}
|
|
|
|
void showMore(BuildContext context) {
|
|
showBottomSheet(
|
|
context: context,
|
|
builder: (context) {
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
border: Border.all(width: 1, color: AppColors.btnDisableColor),
|
|
borderRadius: BorderRadius.circular(30.w),
|
|
),
|
|
height: Get.height * 0.7,
|
|
width: Get.width,
|
|
padding: EdgeInsets.all(16.w),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text('辅助测试的按钮'),
|
|
SizedBox(
|
|
height: 25.h,
|
|
),
|
|
Expanded(
|
|
child: Wrap(
|
|
children: [
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
EasyLoading.show();
|
|
randomlyCreate32Users(0, 33)
|
|
.then((value) => EasyLoading.dismiss())
|
|
.catchError(EasyLoading.dismiss);
|
|
},
|
|
child: const Text('给锁设备创建 32个用户')),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
EasyLoading.show();
|
|
sendCleanUpUsers()
|
|
.then((value) => EasyLoading.dismiss())
|
|
.catchError(EasyLoading.dismiss);
|
|
},
|
|
child: const Text('清除用户,只保留超级管理员')),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
});
|
|
}
|
|
|
|
//随机创建 32个用户
|
|
Future<void> randomlyCreate32Users(int count, int max) async {
|
|
if (count >= max) {
|
|
return;
|
|
}
|
|
|
|
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
|
(BluetoothConnectionState deviceConnectionState) async {
|
|
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
|
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
|
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
|
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
|
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
|
var token = await Storage.getStringList(saveBlueToken);
|
|
List<int> tokenList = changeStringListToIntList(token!);
|
|
LockListInfoItemEntity currentKeyInfo =
|
|
CommonDataManage().currentKeyInfo;
|
|
DateTime startTime = DateTime.fromMillisecondsSinceEpoch(
|
|
currentKeyInfo.startDate! ~/ 1000);
|
|
DateTime endTime = DateTime.fromMillisecondsSinceEpoch(
|
|
currentKeyInfo.endDate! ~/ 1000);
|
|
|
|
IoSenderManage.senderAddUser(
|
|
lockID: BlueManage().connectDeviceName,
|
|
authUserID:
|
|
CommonDataManage().currentKeyInfo.senderUserId!.toString(),
|
|
keyID: CommonDataManage().currentKeyInfo.keyId.toString(),
|
|
userID: generateRandomString(6),
|
|
openMode: 1,
|
|
keyType: 0,
|
|
startDate: CommonDataManage().currentKeyInfo.startDate! ~/ 1000,
|
|
expireDate: CommonDataManage().currentKeyInfo.endDate! ~/ 1000,
|
|
useCountLimit: 0xFFFF,
|
|
isRound: currentKeyInfo.keyType == 2 ? 1 : 0,
|
|
weekRound: DateTool().accordingTheCycleIntoTheCorrespondingNumber(
|
|
currentKeyInfo.weekDays!),
|
|
startHour: startTime.hour,
|
|
startMin: startTime.minute,
|
|
endHour: endTime.hour,
|
|
endMin: endTime.minute,
|
|
role: CommonDataManage().currentKeyInfo.keyRight == 1 ? 1 : 0,
|
|
password: "0",
|
|
needAuthor: 1,
|
|
publicKey: publicKeyDataList,
|
|
privateKey: getPrivateKeyList,
|
|
token: tokenList);
|
|
}
|
|
|
|
AppLog.log('--> 添加第$count 用户');
|
|
});
|
|
|
|
await Future.delayed(const Duration(seconds: 3));
|
|
count++;
|
|
await randomlyCreate32Users(count, max);
|
|
}
|
|
|
|
//创建指定的随机字符串
|
|
String generateRandomString(int length) {
|
|
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
final random = Random();
|
|
return List.generate(length, (index) => chars[random.nextInt(chars.length)])
|
|
.join();
|
|
}
|
|
|
|
//获取清除用户列表指令
|
|
Future<void> sendCleanUpUsers({List<int>? tokenList}) async {
|
|
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
|
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
|
|
|
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
|
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
|
|
|
if (tokenList == null) {
|
|
var tokenKey = await Storage.getStringList(saveBlueToken);
|
|
tokenList = changeStringListToIntList(tokenKey!);
|
|
}
|
|
|
|
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
|
(BluetoothConnectionState deviceConnectionState) async {
|
|
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
|
IoSenderManage.senderCleanUpUsersCommand(
|
|
lockID: BlueManage().connectDeviceName,
|
|
authUserID:
|
|
CommonDataManage().currentKeyInfo.senderUserId!.toString(),
|
|
keyID: CommonDataManage().currentKeyInfo.keyId.toString(),
|
|
userID: await Storage.getUid(),
|
|
needAuthor: 1,
|
|
publicKey: publicKeyDataList,
|
|
privateKey: getPrivateKeyList,
|
|
userNoList: [1],
|
|
token: tokenList,
|
|
);
|
|
}
|
|
});
|
|
}
|
|
}
|