112 lines
3.1 KiB
Dart
112 lines
3.1 KiB
Dart
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
|
|
import 'package:star_lock/blue/io_protocol/io_deletUser.dart';
|
|
|
|
import '../../../../blue/blue_manage.dart';
|
|
import '../../../../blue/io_protocol/io_reply.dart';
|
|
import '../../../../blue/io_tool/io_manager.dart';
|
|
import '../../../../blue/io_tool/io_tool.dart';
|
|
import '../../../../blue/io_tool/manager_event_bus.dart';
|
|
import '../../../../blue/sender_manage.dart';
|
|
import '../../../../tools/baseGetXController.dart';
|
|
import '../../../../tools/storage.dart';
|
|
import 'lockSet_state.dart';
|
|
|
|
class LockSetLogic extends BaseGetXController{
|
|
final LockSetState state = LockSetState();
|
|
|
|
late StreamSubscription<Reply> _replySubscription;
|
|
void _initReplySubscription() {
|
|
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((reply) async {
|
|
if(reply is DeletUserReply) {
|
|
var tokenData = reply.data.sublist(2, 6);
|
|
var saveStrList = changeIntListToStringList(tokenData);
|
|
print("openDoorToken:$tokenData");
|
|
Storage.setStringList(saveBlueToken, saveStrList);
|
|
|
|
int status = reply.data[6];
|
|
switch(status){
|
|
case 0x00:
|
|
//成功
|
|
print("${reply.commandType}解析成功");
|
|
|
|
break;
|
|
case 0x06:
|
|
//无权限
|
|
print("${reply.commandType}需要鉴权");
|
|
|
|
break;
|
|
case 0x07:
|
|
//无权限
|
|
print("${reply.commandType}用户无权限");
|
|
|
|
break;
|
|
case 0x09:
|
|
// 权限校验错误
|
|
print("${reply.commandType}权限校验错误");
|
|
|
|
break;
|
|
default:
|
|
//失败
|
|
print("${reply.commandType}失败");
|
|
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
Future<void> deletUserAction() async {
|
|
BlueManage().judgeReconnect("AD01447A-30B5-A780-E778-DED3BDCB613E", "TMH_c3570480da8d", (DeviceConnectionState state) async {
|
|
if (state == DeviceConnectionState.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> getTokenList = changeStringListToIntList(token!);
|
|
print("openDoorTokenPubToken:$getTokenList");
|
|
|
|
IoSenderManage.deletUser(
|
|
lockID:BlueManage().connectDeviceName,
|
|
authUserID:"100001",
|
|
keyID:"1",
|
|
delUserID:"100001",
|
|
needAuthor:1,
|
|
publicKey:publicKeyDataList,
|
|
privateKey:getPrivateKeyList,
|
|
token: getTokenList
|
|
);
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
void onReady() {
|
|
// TODO: implement onReady
|
|
super.onReady();
|
|
print("onReady()");
|
|
_initReplySubscription();
|
|
}
|
|
|
|
@override
|
|
void onInit() {
|
|
// TODO: implement onInit
|
|
super.onInit();
|
|
print("onInit()");
|
|
|
|
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
// TODO: implement onClose
|
|
_replySubscription.cancel();
|
|
}
|
|
|
|
} |