134 lines
3.7 KiB
Dart
134 lines
3.7 KiB
Dart
|
|
//TODO:获取锁状态
|
|
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';
|
|
|
|
class GetLockStatuCommand extends SenderProtocol {
|
|
|
|
String? lockID;
|
|
String? userID;
|
|
List<int>? privateKey;
|
|
GetLockStatuCommand({
|
|
this.lockID,
|
|
this.userID,
|
|
this.privateKey
|
|
}) : super(CommandType.readLockStatusInfo);
|
|
|
|
@override
|
|
List<int> messageDetail() {
|
|
List<int> data = [];
|
|
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);
|
|
|
|
// 锁id 40
|
|
int lockIDLength = utf8.encode(lockID!).length;
|
|
// print("addUserLockIDLength:$lockIDLength utf8.encode(lockID!)${utf8.encode(lockID!)}");
|
|
data.addAll(utf8.encode(lockID!));
|
|
data = getFixedLengthList(data, 40 - lockIDLength);
|
|
|
|
//userID 要接受钥匙的用户的useid 20
|
|
int userIDLength = utf8.encode(userID!).length;
|
|
// print("userIDLength:$userIDLength utf8.encode(userID!)${utf8.encode(userID!)}");
|
|
data.addAll(utf8.encode(userID!));
|
|
data = getFixedLengthList(data, 20 - userIDLength);
|
|
|
|
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 GetLockStatuReply extends Reply {
|
|
GetLockStatuReply.parseData(CommandType commandType, List<int> dataDetail)
|
|
: super.parseData(commandType, dataDetail) {
|
|
data = dataDetail;
|
|
|
|
int status = data[2];
|
|
switch(status){
|
|
case 0x00:
|
|
//成功
|
|
print("${commandType.typeValue} 数据解析成功");
|
|
var softVersion = data.sublist(3, 7);
|
|
// print("softVersion:$softVersion");
|
|
|
|
var power = data[7];
|
|
// print("power:$power");
|
|
|
|
// APP 用户数量
|
|
var appUserCount = data.sublist(50, 53);
|
|
// print("appUserCount:$appUserCount");
|
|
|
|
// 黑名单用户数量
|
|
var blacklistCount = data[53];
|
|
// print("blacklistCount:$blacklistCount");
|
|
|
|
// 蓝牙钥匙数量
|
|
var bleKeyCount = data[54];
|
|
// print("bleKeyCount:$bleKeyCount");
|
|
|
|
// 剩余可添加用户数量
|
|
var remainCount = data.sublist(54, 56);
|
|
// print("remainCount:$remainCount");
|
|
|
|
// 未上传开锁记录数量
|
|
var notUploadCount = data.sublist(56, 58);
|
|
// print("notUploadCount:$notUploadCount");
|
|
|
|
// 已设置开门密码数量
|
|
var pwdCount = data[58];
|
|
// print("pwdCount:$pwdCount");
|
|
|
|
// 已设置开门指纹数量
|
|
var fingerprintCount = data[59];
|
|
// print("fingerprintCount:$fingerprintCount");
|
|
|
|
// 锁当前时间
|
|
var lockTime = data.sublist(60, 64);
|
|
// print("lockTime:$lockTime");
|
|
|
|
// 硬件版本信息,为固件升级提供判断依据
|
|
var hardVersion = data.sublist(64, 68);
|
|
// print("hardVersion:$hardVersion");
|
|
break;
|
|
case 0x06:
|
|
//无权限
|
|
print("${commandType.typeValue} 需要鉴权");
|
|
|
|
break;
|
|
case 0x07:
|
|
//无权限
|
|
print("${commandType.typeValue} 用户无权限");
|
|
|
|
break;
|
|
case 0x09:
|
|
// 权限校验错误
|
|
print("${commandType.typeValue} 权限校验错误");
|
|
|
|
break;
|
|
default:
|
|
//失败
|
|
print("${commandType.typeValue} 领锁失败");
|
|
|
|
break;
|
|
}
|
|
}
|
|
} |