添加自定义密码协议及逻辑
This commit is contained in:
parent
a487a22580
commit
3a43d89725
146
star_lock/lib/blue/io_protocol/io_senderCustomPasswords.dart
Normal file
146
star_lock/lib/blue/io_protocol/io_senderCustomPasswords.dart
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import '../io_tool/io_tool.dart';
|
||||||
|
import '../sm4Encipher/sm4.dart';
|
||||||
|
import 'io_reply.dart';
|
||||||
|
import 'io_sender.dart';
|
||||||
|
import 'io_type.dart';
|
||||||
|
import 'package:crypto/crypto.dart' as crypto;
|
||||||
|
|
||||||
|
//TODO:设置自定义密码
|
||||||
|
/*
|
||||||
|
备注:删除单个密码规则:pwd 设置为 6 个 0,UseCountLimit 设置为 0。删除全部密码规则:pwd 设置为 6 个 0,UseCountLimit 设置为 0,pwdNo 设置为 255,userId 设置为“DeleteAll !@#”,只有门锁管理员才有权限
|
||||||
|
**/
|
||||||
|
class SenderCustomPasswordsCommand extends SenderProtocol {
|
||||||
|
|
||||||
|
String? keyID;
|
||||||
|
String? userID;
|
||||||
|
int? pwdNo;
|
||||||
|
String? pwd;
|
||||||
|
int? useCountLimit;
|
||||||
|
List<int>? token;
|
||||||
|
int? startTime;
|
||||||
|
int? endTime;
|
||||||
|
int? needAuthor;
|
||||||
|
List<int>? publicKey;
|
||||||
|
List<int>? privateKey;
|
||||||
|
|
||||||
|
SenderCustomPasswordsCommand({
|
||||||
|
this.keyID,
|
||||||
|
this.userID,
|
||||||
|
this.pwdNo,
|
||||||
|
this.pwd,
|
||||||
|
this.useCountLimit,
|
||||||
|
this.token,
|
||||||
|
this.startTime,
|
||||||
|
this.endTime,
|
||||||
|
this.needAuthor,
|
||||||
|
this.publicKey,
|
||||||
|
this.privateKey,
|
||||||
|
}) : super(CommandType.generalExtendedCommond);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<int> messageDetail() {
|
||||||
|
List<int> data = [];
|
||||||
|
List<int> subData = [];
|
||||||
|
List<int> ebcData = [];
|
||||||
|
|
||||||
|
// 指令类型
|
||||||
|
int type = commandType!.typeValue;
|
||||||
|
double typeDouble = type / 256;
|
||||||
|
int type1 = typeDouble.toInt();
|
||||||
|
int type2 = type % 256;
|
||||||
|
data.add(type1);
|
||||||
|
data.add(type2);
|
||||||
|
|
||||||
|
// 子命令类型
|
||||||
|
data.add(3);
|
||||||
|
|
||||||
|
// keyID 40
|
||||||
|
int keyIDLength = utf8.encode(keyID!).length;
|
||||||
|
// print("${commandType!.typeValue}LockIDLength:$lockIDLength utf8.encode(lockID!)${utf8.encode(lockID!)}");
|
||||||
|
subData.addAll(utf8.encode(keyID!));
|
||||||
|
subData = getFixedLengthList(subData, 40 - keyIDLength);
|
||||||
|
|
||||||
|
//userID 20
|
||||||
|
int userIDLength = utf8.encode(userID!).length;
|
||||||
|
// print("${commandType!.typeValue}IDLength:$authUserIDLength utf8.encode(authUserID!)${utf8.encode(authUserID!)}");
|
||||||
|
subData.addAll(utf8.encode(userID!));
|
||||||
|
subData = getFixedLengthList(subData, 20 - userIDLength);
|
||||||
|
|
||||||
|
// PwdNo
|
||||||
|
subData.add(1);
|
||||||
|
|
||||||
|
// pwd 20
|
||||||
|
int pwdLength = utf8.encode(pwd!).length;
|
||||||
|
// print("${commandType!.typeValue}keyIDLength:$keyIDLength utf8.encode(keyID!)${utf8.encode(keyID!)}");
|
||||||
|
subData.addAll(utf8.encode(pwd!));
|
||||||
|
subData = getFixedLengthList(subData, 20 - pwdLength);
|
||||||
|
|
||||||
|
// UseCountLimit
|
||||||
|
subData.add(0xff);
|
||||||
|
|
||||||
|
// token
|
||||||
|
subData.addAll(token!);
|
||||||
|
|
||||||
|
// startTime 4
|
||||||
|
subData.add((startTime! & 0xff000000) >> 24);
|
||||||
|
subData.add((startTime! & 0xff0000) >> 16);
|
||||||
|
subData.add((startTime! & 0xff00) >> 8);
|
||||||
|
subData.add((startTime! & 0xff));
|
||||||
|
|
||||||
|
// endTime 4
|
||||||
|
subData.add((endTime! & 0xff000000) >> 24);
|
||||||
|
subData.add((endTime! & 0xff0000) >> 16);
|
||||||
|
subData.add((endTime! & 0xff00) >> 8);
|
||||||
|
subData.add((endTime! & 0xff));
|
||||||
|
|
||||||
|
if(needAuthor == 0){
|
||||||
|
//AuthCodeLen 1
|
||||||
|
subData.add(0);
|
||||||
|
} else {
|
||||||
|
List<int> authCodeData = [];
|
||||||
|
|
||||||
|
//authUserID
|
||||||
|
authCodeData.addAll(utf8.encode(userID!));
|
||||||
|
|
||||||
|
//KeyID
|
||||||
|
authCodeData.addAll(utf8.encode(keyID!));
|
||||||
|
|
||||||
|
//token 4 首次请求 Token 填 0,如果锁需要鉴权操作者身份,则会分配动态口令并在应答消息中返回,二次请求时带上。
|
||||||
|
authCodeData.addAll(token!);
|
||||||
|
|
||||||
|
authCodeData.addAll(publicKey!);
|
||||||
|
|
||||||
|
print("${commandType!.typeValue}-authCodeData:$authCodeData");
|
||||||
|
|
||||||
|
// 把KeyID、authUserID、时间戳、公钥通过md5加密之后就是authCode
|
||||||
|
var authCode = crypto.md5.convert(authCodeData);
|
||||||
|
|
||||||
|
subData.add(authCode.bytes.length);
|
||||||
|
subData.addAll(authCode.bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
data.add(subData.length);
|
||||||
|
data.addAll(subData);
|
||||||
|
|
||||||
|
if ((data.length % 16) != 0) {
|
||||||
|
int add = (16 - data.length % 16);
|
||||||
|
for (int i = 0; i < add; i++) {
|
||||||
|
data.add(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print("${commandType!.typeName} SM4Data:$data");
|
||||||
|
// 拿到数据之后通过LockId进行SM4 ECB加密 key:544d485f633335373034383064613864
|
||||||
|
ebcData = SM4.encrypt(data, key: privateKey, mode: SM4CryptoMode.ECB);
|
||||||
|
return ebcData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class SenderCustomPasswordsReply extends Reply {
|
||||||
|
SenderCustomPasswordsReply.parseData(CommandType commandType, List<int> dataDetail)
|
||||||
|
: super.parseData(commandType, dataDetail) {
|
||||||
|
data = dataDetail;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -16,6 +16,7 @@ import 'io_protocol/io_getPrivateKey.dart';
|
|||||||
import 'io_protocol/io_getPublicKey.dart';
|
import 'io_protocol/io_getPublicKey.dart';
|
||||||
import 'io_protocol/io_openLock.dart';
|
import 'io_protocol/io_openLock.dart';
|
||||||
import 'io_protocol/io_reply.dart';
|
import 'io_protocol/io_reply.dart';
|
||||||
|
import 'io_protocol/io_senderCustomPasswords.dart';
|
||||||
import 'io_protocol/io_type.dart';
|
import 'io_protocol/io_type.dart';
|
||||||
import 'io_tool/io_manager.dart';
|
import 'io_tool/io_manager.dart';
|
||||||
import 'io_tool/io_tool.dart';
|
import 'io_tool/io_tool.dart';
|
||||||
@ -143,8 +144,36 @@ class CommandReciverManager {
|
|||||||
reply = FactoryDataResetReply.parseData(commandType, data);
|
reply = FactoryDataResetReply.parseData(commandType, data);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case CommandType.generalExtendedCommond:
|
||||||
|
{
|
||||||
|
// 子命令类型
|
||||||
|
int subType = data[3];
|
||||||
|
switch(subType){
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
// 设置开锁密码
|
||||||
|
reply = SenderCustomPasswordsReply.parseData(commandType, data);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<Reply?> replySubCommand(CommandType commandType, List<int> data){
|
||||||
|
int subType = data[3];
|
||||||
|
var reply;
|
||||||
|
switch(subType){
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
// 设置开锁密码
|
||||||
|
reply = SenderCustomPasswordsReply.parseData(commandType, data);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return reply;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -8,6 +8,7 @@ import 'io_protocol/io_factoryDataReset.dart';
|
|||||||
import 'io_protocol/io_getPrivateKey.dart';
|
import 'io_protocol/io_getPrivateKey.dart';
|
||||||
import 'io_protocol/io_getPublicKey.dart';
|
import 'io_protocol/io_getPublicKey.dart';
|
||||||
import 'io_protocol/io_openLock.dart';
|
import 'io_protocol/io_openLock.dart';
|
||||||
|
import 'io_protocol/io_senderCustomPasswords.dart';
|
||||||
import 'io_protocol/io_transferPermissions.dart';
|
import 'io_protocol/io_transferPermissions.dart';
|
||||||
import 'sender_data.dart';
|
import 'sender_data.dart';
|
||||||
|
|
||||||
@ -175,15 +176,15 @@ class IoSenderManage {
|
|||||||
|
|
||||||
//todo:转移权限
|
//todo:转移权限
|
||||||
static void senderTransferPermissions({
|
static void senderTransferPermissions({
|
||||||
String? lockID,
|
required String? lockID,
|
||||||
String? authUserID,
|
required String? authUserID,
|
||||||
String? keyID,
|
required String? keyID,
|
||||||
String? oldUserID,
|
required String? oldUserID,
|
||||||
String? newUserID,
|
required String? newUserID,
|
||||||
int? needAuthor,
|
required int? needAuthor,
|
||||||
List<int>? publicKey,
|
required List<int>? publicKey,
|
||||||
List<int>? privateKey,
|
required List<int>? privateKey,
|
||||||
List<int>? token,
|
required List<int>? token,
|
||||||
CommandSendCallBack? callBack}) {
|
CommandSendCallBack? callBack}) {
|
||||||
CommandSenderManager().managerSendData(
|
CommandSenderManager().managerSendData(
|
||||||
command: TransferPermissionsCommand(
|
command: TransferPermissionsCommand(
|
||||||
@ -201,13 +202,13 @@ class IoSenderManage {
|
|||||||
|
|
||||||
//todo:恢复出厂设置
|
//todo:恢复出厂设置
|
||||||
static void senderFactoryDataReset({
|
static void senderFactoryDataReset({
|
||||||
String? lockID,
|
required String? lockID,
|
||||||
String? userID,
|
required String? userID,
|
||||||
String? keyID,
|
required String? keyID,
|
||||||
List<int>? publicKey,
|
required List<int>? publicKey,
|
||||||
List<int>? privateKey,
|
required List<int>? privateKey,
|
||||||
List<int>? token,
|
required List<int>? token,
|
||||||
int? needAuthor,
|
required int? needAuthor,
|
||||||
CommandSendCallBack? callBack}) {
|
CommandSendCallBack? callBack}) {
|
||||||
CommandSenderManager().managerSendData(
|
CommandSenderManager().managerSendData(
|
||||||
command: FactoryDataResetCommand(
|
command: FactoryDataResetCommand(
|
||||||
@ -221,4 +222,33 @@ class IoSenderManage {
|
|||||||
), callBack:callBack);
|
), callBack:callBack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//todo:设置开锁密码
|
||||||
|
static void senderCustomPasswordsCommand({
|
||||||
|
required String? keyID,
|
||||||
|
required String? userID,
|
||||||
|
required int? pwdNo,
|
||||||
|
required String? pwd,
|
||||||
|
required int? useCountLimit,
|
||||||
|
required List<int>? token,
|
||||||
|
required int? startTime,
|
||||||
|
required int? endTime,
|
||||||
|
required int? needAuthor,
|
||||||
|
required List<int>? publicKey,
|
||||||
|
required List<int>? privateKey,
|
||||||
|
CommandSendCallBack? callBack}) {
|
||||||
|
CommandSenderManager().managerSendData(
|
||||||
|
command: SenderCustomPasswordsCommand(
|
||||||
|
keyID: keyID,
|
||||||
|
userID: userID,
|
||||||
|
pwdNo: pwdNo,
|
||||||
|
pwd:pwd,
|
||||||
|
useCountLimit: useCountLimit,
|
||||||
|
token: token,
|
||||||
|
startTime: startTime,
|
||||||
|
endTime: endTime,
|
||||||
|
needAuthor: needAuthor,
|
||||||
|
publicKey: publicKey,
|
||||||
|
privateKey: privateKey,
|
||||||
|
), callBack:callBack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -0,0 +1,133 @@
|
|||||||
|
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
|
||||||
|
import 'package:star_lock/blue/io_protocol/io_type.dart';
|
||||||
|
|
||||||
|
import '../../../../blue/blue_manage.dart';
|
||||||
|
import '../../../../blue/io_protocol/io_reply.dart';
|
||||||
|
import '../../../../blue/io_protocol/io_transferPermissions.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 'authorizedAdmin_state.dart';
|
||||||
|
|
||||||
|
class AuthorizedAdminLogic extends BaseGetXController {
|
||||||
|
final AuthorizedAdminState state = AuthorizedAdminState();
|
||||||
|
|
||||||
|
// 监听设备返回的数据
|
||||||
|
late StreamSubscription<Reply> _replySubscription;
|
||||||
|
void _initReplySubscription() {
|
||||||
|
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((reply) async {
|
||||||
|
// 开门
|
||||||
|
if(reply is TransferPermissionsReply) {
|
||||||
|
var token = reply.data.sublist(2, 6);
|
||||||
|
var saveStrList = changeIntListToStringList(token);
|
||||||
|
print("_replyFactoryDataResetKeyToken:$token");
|
||||||
|
Storage.setStringList(saveBlueToken, saveStrList);
|
||||||
|
|
||||||
|
int status = reply.data[6];
|
||||||
|
print("status:$status");
|
||||||
|
|
||||||
|
switch(status){
|
||||||
|
case 0x00:
|
||||||
|
//成功
|
||||||
|
print("${reply.commandType!.typeValue} 数据解析成功");
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 0x06:
|
||||||
|
//无权限
|
||||||
|
print("${reply.commandType!.typeValue} 需要鉴权");
|
||||||
|
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!);
|
||||||
|
|
||||||
|
IoSenderManage.senderFactoryDataReset(
|
||||||
|
lockID:BlueManage().connectDeviceName,
|
||||||
|
userID:await Storage.getUserId(),
|
||||||
|
keyID:"1",
|
||||||
|
needAuthor:1,
|
||||||
|
publicKey:publicKeyDataList,
|
||||||
|
privateKey:getPrivateKeyList,
|
||||||
|
token: getTokenList
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case 0x07:
|
||||||
|
//无权限
|
||||||
|
print("${reply.commandType!.typeValue} 用户无权限");
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 0x09:
|
||||||
|
// 权限校验错误
|
||||||
|
print("${reply.commandType!.typeValue} 权限校验错误");
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//失败
|
||||||
|
print("${reply.commandType!.typeValue} 失败");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 转移权限
|
||||||
|
Future<void> transferPermissionsAction() async {
|
||||||
|
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (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.senderTransferPermissions(
|
||||||
|
lockID:BlueManage().connectDeviceName,
|
||||||
|
authUserID:await Storage.getUserId(),
|
||||||
|
keyID:"1",
|
||||||
|
oldUserID:await Storage.getUserId(),
|
||||||
|
newUserID:"100002",
|
||||||
|
needAuthor:1,
|
||||||
|
publicKey:publicKeyDataList,
|
||||||
|
privateKey:getPrivateKeyList,
|
||||||
|
token: getTokenList
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onReady() {
|
||||||
|
// TODO: implement onReady
|
||||||
|
super.onReady();
|
||||||
|
|
||||||
|
_initReplySubscription();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onInit() {
|
||||||
|
// TODO: implement onInit
|
||||||
|
super.onInit();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onClose() {
|
||||||
|
// TODO: implement onClose
|
||||||
|
_replySubscription.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -13,16 +13,20 @@ import '../../../../app_settings/app_colors.dart';
|
|||||||
import '../../../../tools/commonItem.dart';
|
import '../../../../tools/commonItem.dart';
|
||||||
import '../../../../tools/submitBtn.dart';
|
import '../../../../tools/submitBtn.dart';
|
||||||
import '../../../../translations/trans_lib.dart';
|
import '../../../../translations/trans_lib.dart';
|
||||||
|
import 'authorizedAdmin_logic.dart';
|
||||||
|
|
||||||
class AuthorizedAdminPage extends StatefulWidget {
|
class AuthorizedAdminPage extends StatefulWidget {
|
||||||
final String type;
|
final String type;
|
||||||
AuthorizedAdminPage({Key? key, required this.type}) : super(key: key);
|
const AuthorizedAdminPage({Key? key, required this.type}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<AuthorizedAdminPage> createState() => _AuthorizedAdminPageState();
|
State<AuthorizedAdminPage> createState() => _AuthorizedAdminPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _AuthorizedAdminPageState extends State<AuthorizedAdminPage> {
|
class _AuthorizedAdminPageState extends State<AuthorizedAdminPage> {
|
||||||
|
final logic = Get.put(AuthorizedAdminLogic());
|
||||||
|
final state = Get.find<AuthorizedAdminLogic>().state;
|
||||||
|
|
||||||
final FlutterContactPicker _contactPicker = FlutterContactPicker();
|
final FlutterContactPicker _contactPicker = FlutterContactPicker();
|
||||||
late Contact _contact;
|
late Contact _contact;
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
class AuthorizedAdminState {
|
||||||
|
|
||||||
|
}
|
||||||
@ -373,35 +373,6 @@ class LockDetailLogic extends BaseGetXController{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 转移权限
|
|
||||||
Future<void> transferPermissionsAction() async {
|
|
||||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (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.senderTransferPermissions(
|
|
||||||
lockID:BlueManage().connectDeviceName,
|
|
||||||
authUserID:await Storage.getUserId(),
|
|
||||||
keyID:"1",
|
|
||||||
oldUserID:await Storage.getUserId(),
|
|
||||||
newUserID:"100002",
|
|
||||||
needAuthor:1,
|
|
||||||
publicKey:publicKeyDataList,
|
|
||||||
privateKey:getPrivateKeyList,
|
|
||||||
token: getTokenList
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 恢复出厂设置
|
// 恢复出厂设置
|
||||||
Future<void> factoryDataResetAction() async {
|
Future<void> factoryDataResetAction() async {
|
||||||
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
||||||
|
|||||||
@ -0,0 +1,133 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
|
||||||
|
import 'package:star_lock/blue/io_protocol/io_type.dart';
|
||||||
|
|
||||||
|
import '../../../../blue/blue_manage.dart';
|
||||||
|
import '../../../../blue/io_protocol/io_reply.dart';
|
||||||
|
import '../../../../blue/io_protocol/io_senderCustomPasswords.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';
|
||||||
|
|
||||||
|
class PasswordKeyPerpetualLogic extends BaseGetXController {
|
||||||
|
|
||||||
|
// 监听设备返回的数据
|
||||||
|
late StreamSubscription<Reply> _replySubscription;
|
||||||
|
void _initReplySubscription() {
|
||||||
|
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((reply) async {
|
||||||
|
// 设置自定义密码
|
||||||
|
if(reply is SenderCustomPasswordsReply) {
|
||||||
|
var token = reply.data.sublist(2, 6);
|
||||||
|
var saveStrList = changeIntListToStringList(token);
|
||||||
|
print("_replyFactoryDataResetKeyToken:$token");
|
||||||
|
Storage.setStringList(saveBlueToken, saveStrList);
|
||||||
|
|
||||||
|
int status = reply.data[6];
|
||||||
|
print("status:$status");
|
||||||
|
|
||||||
|
switch(status){
|
||||||
|
case 0x00:
|
||||||
|
//成功
|
||||||
|
print("${reply.commandType!.typeValue} 数据解析成功");
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 0x06:
|
||||||
|
//无权限
|
||||||
|
print("${reply.commandType!.typeValue} 需要鉴权");
|
||||||
|
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||||
|
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||||
|
|
||||||
|
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
||||||
|
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
||||||
|
|
||||||
|
IoSenderManage.senderCustomPasswordsCommand(
|
||||||
|
keyID:"1",
|
||||||
|
userID:await Storage.getUserId(),
|
||||||
|
pwdNo:1,
|
||||||
|
pwd: "123456",
|
||||||
|
useCountLimit:0xff,
|
||||||
|
startTime:0x11223344,
|
||||||
|
endTime:0x11223344,
|
||||||
|
needAuthor:1,
|
||||||
|
publicKey:publicKeyDataList,
|
||||||
|
privateKey:getPrivateKeyList,
|
||||||
|
token: token
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case 0x07:
|
||||||
|
//无权限
|
||||||
|
print("${reply.commandType!.typeValue} 用户无权限");
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 0x09:
|
||||||
|
// 权限校验错误
|
||||||
|
print("${reply.commandType!.typeValue} 权限校验错误");
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//失败
|
||||||
|
print("${reply.commandType!.typeValue} 失败");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置自定义密码
|
||||||
|
Future<void> senderCustomPasswords() async {
|
||||||
|
BlueManage().judgeReconnect(BlueManage().connectDeviceMacAddress, BlueManage().connectDeviceName, (DeviceConnectionState state) async {
|
||||||
|
if (state == DeviceConnectionState.connected){
|
||||||
|
var publicKey = await Storage.getStringList(saveBluePublicKey);
|
||||||
|
List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
||||||
|
|
||||||
|
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||||
|
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||||
|
|
||||||
|
var token = await Storage.getStringList(saveBlueToken);
|
||||||
|
List<int> getTokenList = changeStringListToIntList(token!);
|
||||||
|
print("openDoorTokenPubToken:$getTokenList");
|
||||||
|
|
||||||
|
IoSenderManage.senderCustomPasswordsCommand(
|
||||||
|
keyID:"1",
|
||||||
|
userID:await Storage.getUserId(),
|
||||||
|
pwdNo:1,
|
||||||
|
pwd: "123456",
|
||||||
|
useCountLimit:0xff,
|
||||||
|
startTime:0x11223344,
|
||||||
|
endTime:0x11223344,
|
||||||
|
needAuthor:1,
|
||||||
|
publicKey:publicKeyDataList,
|
||||||
|
privateKey:getPrivateKeyList,
|
||||||
|
token: getTokenList
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onReady() {
|
||||||
|
// TODO: implement onReady
|
||||||
|
super.onReady();
|
||||||
|
|
||||||
|
_initReplySubscription();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onInit() {
|
||||||
|
// TODO: implement onInit
|
||||||
|
super.onInit();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onClose() {
|
||||||
|
// TODO: implement onClose
|
||||||
|
_replySubscription.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user