114 lines
3.0 KiB
Dart
114 lines
3.0 KiB
Dart
|
|
import 'dart:convert';
|
|
|
|
import '../io_reply.dart';
|
|
import '../io_sender.dart';
|
|
import '../io_tool/io_tool.dart';
|
|
import '../io_type.dart';
|
|
import '../sm4Encipher/sm4.dart';
|
|
|
|
class GetStarLockStatuInfoCommand extends SenderProtocol {
|
|
|
|
String? lockID;
|
|
String? userID;
|
|
List<int>? privateKey;
|
|
GetStarLockStatuInfoCommand({
|
|
this.lockID,
|
|
this.userID,
|
|
this.privateKey
|
|
}) : super(CommandType.readStarLockStatusInfo);
|
|
|
|
@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 GetStarLockStatuInfoReply extends Reply {
|
|
GetStarLockStatuInfoReply.parseData(CommandType commandType, List<int> dataDetail)
|
|
: super.parseData(commandType, dataDetail) {
|
|
data = dataDetail;
|
|
|
|
int status = data[2];
|
|
switch(status){
|
|
case 0x00:
|
|
//成功
|
|
print("${commandType.typeValue} 数据解析成功");
|
|
|
|
// 厂商名称
|
|
var vendor = data.sublist(3, 23);
|
|
// print("softVersion:$softVersion");
|
|
|
|
// 锁设备类型
|
|
var product = data[23];
|
|
// print("product:product");
|
|
|
|
// 产品名称
|
|
var model = data.sublist(24, 44);
|
|
// print("model:model");
|
|
|
|
// 软件版本
|
|
var fwVersion = data.sublist(44, 64);
|
|
// print("fwVersion:fwVersion");
|
|
|
|
// 硬件版本
|
|
var hwVersion = data.sublist(64, 84);
|
|
// print("hwVersion:hwVersion");
|
|
|
|
|
|
break;
|
|
case 0x06:
|
|
//无权限
|
|
print("${commandType.typeValue} 需要鉴权");
|
|
|
|
break;
|
|
case 0x07:
|
|
//无权限
|
|
print("${commandType.typeValue} 用户无权限");
|
|
|
|
break;
|
|
case 0x09:
|
|
// 权限校验错误
|
|
print("${commandType.typeValue} 权限校验错误");
|
|
|
|
break;
|
|
default:
|
|
//失败
|
|
print("${commandType.typeValue} 领锁失败");
|
|
|
|
break;
|
|
}
|
|
}
|
|
} |