Daisy a5817cffeb 1,新增人脸部分命令协议调试
2,新增人脸相关接口处理 更新人脸信息、删除人脸、清空人脸(未完成)
3,部分人脸详情处理(待完善)
2024-01-24 18:51:18 +08:00

154 lines
4.3 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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:添加人脸
/*
备注:
删除单个人脸规则UseCountLimit 设置为 0。删除全部人脸规则 UseCountLimit 设置为 0FaceNo 设置为 255userId 设置为“Delete All !@#”,只有门锁管理员才有权限
**/
class SenderAddFaceCommand extends SenderProtocol {
String? keyID;
String? userID;
int? faceNo;
int? useCountLimit;
List<int>? token;
int? startTime;
int? endTime;
int? needAuthor;
List<int>? publicKey;
List<int>? privateKey;
SenderAddFaceCommand({
this.keyID,
this.userID,
this.faceNo,
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(81);
// 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(faceNo!);
// UseCountLimit
subData.add(useCountLimit!);
// 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 SenderAddFaceReply extends Reply {
SenderAddFaceReply.parseData(CommandType commandType, List<int> dataDetail)
: super.parseData(commandType, dataDetail) {
data = dataDetail;
}
}
class SenderAddFaceProcessReply extends Reply {
SenderAddFaceProcessReply.parseData(
CommandType commandType, List<int> dataDetail)
: super.parseData(commandType, dataDetail) {
data = dataDetail;
}
}
class SenderAddFaceConfirmationReply extends Reply {
SenderAddFaceConfirmationReply.parseData(
CommandType commandType, List<int> dataDetail)
: super.parseData(commandType, dataDetail) {
data = dataDetail;
}
}