2024-07-23 11:16:18 +08:00
|
|
|
|
|
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:star_lock/tools/dateTool.dart';
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
2024-10-15 14:24:35 +08:00
|
|
|
|
/// 添加遥控
|
2024-07-23 11:16:18 +08:00
|
|
|
|
class SenderAddRemoteControlWithTimeCycleCoercionCommand extends SenderProtocol {
|
|
|
|
|
|
|
|
|
|
|
|
SenderAddRemoteControlWithTimeCycleCoercionCommand({
|
|
|
|
|
|
this.keyID,
|
|
|
|
|
|
this.userID,
|
|
|
|
|
|
this.remoteControlNo,
|
|
|
|
|
|
this.useCountLimit,
|
|
|
|
|
|
this.isForce,
|
|
|
|
|
|
this.operate,
|
|
|
|
|
|
this.isAdmin,
|
|
|
|
|
|
this.token,
|
|
|
|
|
|
this.isRound,
|
|
|
|
|
|
this.weekRound,
|
|
|
|
|
|
this.startDate,
|
|
|
|
|
|
this.endDate,
|
|
|
|
|
|
this.startTime,
|
|
|
|
|
|
this.endTime,
|
|
|
|
|
|
this.needAuthor,
|
|
|
|
|
|
this.signKey,
|
|
|
|
|
|
this.privateKey,
|
|
|
|
|
|
}) : super(CommandType.generalExtendedCommond);
|
|
|
|
|
|
|
|
|
|
|
|
String? keyID;
|
|
|
|
|
|
String? userID;
|
|
|
|
|
|
int? remoteControlNo;
|
|
|
|
|
|
int? useCountLimit;
|
|
|
|
|
|
int? isForce;
|
|
|
|
|
|
int? operate;
|
|
|
|
|
|
int? isAdmin;
|
|
|
|
|
|
List<int>? token;
|
|
|
|
|
|
int? isRound;
|
|
|
|
|
|
int? weekRound;
|
|
|
|
|
|
int? startDate;
|
|
|
|
|
|
int? endDate;
|
|
|
|
|
|
String? startTime;
|
|
|
|
|
|
String? endTime;
|
|
|
|
|
|
int? needAuthor;
|
|
|
|
|
|
List<int>? signKey;
|
|
|
|
|
|
List<int>? privateKey;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
String toString() {
|
|
|
|
|
|
return 'SenderAddRemoteControlWithTimeCycleCoercionCommand{keyID: $keyID, '
|
|
|
|
|
|
'userID: $userID, remoteControlNo: $remoteControlNo, useCountLimit: $useCountLimit, '
|
|
|
|
|
|
'isForce: $isForce, token: $token, isRound: $isRound, '
|
|
|
|
|
|
'weekRound: $weekRound, '
|
|
|
|
|
|
'startDate: ${DateTool().dateIntToYMDHNString(startDate)}, '
|
|
|
|
|
|
'endDate: ${DateTool().dateIntToYMDHNString(endDate)}, '
|
|
|
|
|
|
'startTime: $startTime,'
|
|
|
|
|
|
'endTime: $endTime, '
|
|
|
|
|
|
'needAuthor: $needAuthor, signKey: $signKey, privateKey: $privateKey}';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
List<int> messageDetail() {
|
|
|
|
|
|
final List<int> data = [];
|
|
|
|
|
|
List<int> subData = [];
|
|
|
|
|
|
List<int> ebcData = [];
|
|
|
|
|
|
|
|
|
|
|
|
// 指令类型
|
|
|
|
|
|
data.addAll(intChangList(commandType!.typeValue));
|
|
|
|
|
|
|
|
|
|
|
|
// 子命令类型
|
|
|
|
|
|
data.add(26);
|
|
|
|
|
|
|
|
|
|
|
|
// keyID 40
|
|
|
|
|
|
final int keyIDLength = utf8.encode(keyID!).length;
|
|
|
|
|
|
subData.addAll(utf8.encode(keyID!));
|
|
|
|
|
|
subData = getFixedLengthList(subData, 40 - keyIDLength);
|
|
|
|
|
|
|
|
|
|
|
|
//userID 20
|
|
|
|
|
|
final int userIDLength = utf8.encode(userID!).length;
|
|
|
|
|
|
subData.addAll(utf8.encode(userID!));
|
|
|
|
|
|
subData = getFixedLengthList(subData, 20 - userIDLength);
|
|
|
|
|
|
|
|
|
|
|
|
// remoteControlNo
|
|
|
|
|
|
subData.addAll(intChangList(remoteControlNo!));
|
|
|
|
|
|
|
|
|
|
|
|
// UseCountLimit
|
|
|
|
|
|
subData.addAll(intChangList(useCountLimit!));
|
|
|
|
|
|
|
|
|
|
|
|
// Operate 0:注册 1:修改 2:删除 3:删除全部
|
|
|
|
|
|
subData.add(operate!);
|
|
|
|
|
|
// AppLog.log("addCard operate:$operate");
|
|
|
|
|
|
|
|
|
|
|
|
// isAdmin
|
|
|
|
|
|
subData.add(isAdmin!);
|
|
|
|
|
|
// AppLog.log("addCard isAdmin:$isAdmin");
|
|
|
|
|
|
|
|
|
|
|
|
// isForce
|
|
|
|
|
|
subData.add(isForce!);
|
|
|
|
|
|
// AppLog.log("addCard isForce:$isForce");
|
|
|
|
|
|
|
|
|
|
|
|
// token
|
|
|
|
|
|
subData.addAll(token!);
|
|
|
|
|
|
|
|
|
|
|
|
// isRound
|
|
|
|
|
|
subData.add(isRound!);
|
|
|
|
|
|
|
|
|
|
|
|
// weekRound
|
|
|
|
|
|
subData.add(weekRound!);
|
|
|
|
|
|
|
|
|
|
|
|
// startDate 4
|
|
|
|
|
|
subData.add((startDate! & 0xff000000) >> 24);
|
|
|
|
|
|
subData.add((startDate! & 0xff0000) >> 16);
|
|
|
|
|
|
subData.add((startDate! & 0xff00) >> 8);
|
|
|
|
|
|
subData.add(startDate! & 0xff);
|
|
|
|
|
|
|
|
|
|
|
|
// endDate 4
|
|
|
|
|
|
subData.add((endDate! & 0xff000000) >> 24);
|
|
|
|
|
|
subData.add((endDate! & 0xff0000) >> 16);
|
|
|
|
|
|
subData.add((endDate! & 0xff00) >> 8);
|
|
|
|
|
|
subData.add(endDate! & 0xff);
|
|
|
|
|
|
|
|
|
|
|
|
// startTime 4
|
|
|
|
|
|
final List<int> startTimeList = [0,0,0,0];
|
|
|
|
|
|
if(startTime!.contains(':')){
|
|
|
|
|
|
final List<String> getStartTimeList = startTime!.split(':');
|
|
|
|
|
|
startTimeList[2] = int.parse(getStartTimeList[0]);
|
|
|
|
|
|
startTimeList[3] = int.parse(getStartTimeList[1]);
|
|
|
|
|
|
}
|
|
|
|
|
|
subData.addAll(startTimeList);
|
|
|
|
|
|
|
|
|
|
|
|
// endTime 4
|
|
|
|
|
|
final List<int> endTimeList = [0,0,0,0];
|
|
|
|
|
|
if(endTime!.contains(':')){
|
|
|
|
|
|
final List<String> getendTimeList = endTime!.split(':');
|
|
|
|
|
|
endTimeList[2] = int.parse(getendTimeList[0]);
|
|
|
|
|
|
endTimeList[3] = int.parse(getendTimeList[1]);
|
|
|
|
|
|
}
|
|
|
|
|
|
subData.addAll(endTimeList);
|
|
|
|
|
|
|
|
|
|
|
|
if(needAuthor == 0){
|
|
|
|
|
|
//AuthCodeLen 1
|
|
|
|
|
|
subData.add(0);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
final List<int> authCodeData = [];
|
|
|
|
|
|
//KeyID
|
|
|
|
|
|
authCodeData.addAll(utf8.encode(keyID!));
|
|
|
|
|
|
|
|
|
|
|
|
//authUserID
|
|
|
|
|
|
authCodeData.addAll(utf8.encode(userID!));
|
|
|
|
|
|
|
|
|
|
|
|
//token 4 首次请求 Token 填 0,如果锁需要鉴权操作者身份,则会分配动态口令并在应答消息中返回,二次请求时带上。
|
|
|
|
|
|
authCodeData.addAll(token!);
|
|
|
|
|
|
|
|
|
|
|
|
authCodeData.addAll(signKey!);
|
|
|
|
|
|
|
|
|
|
|
|
// 把KeyID、authUserID、时间戳、公钥通过md5加密之后就是authCode
|
|
|
|
|
|
final 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) {
|
|
|
|
|
|
final int add = 16 - data.length % 16;
|
|
|
|
|
|
for (int i = 0; i < add; i++) {
|
|
|
|
|
|
data.add(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
printLog(data);
|
|
|
|
|
|
// 拿到数据之后通过LockId进行SM4 ECB加密 key:544d485f633335373034383064613864
|
|
|
|
|
|
ebcData = SM4.encrypt(data, key: privateKey, mode: SM4CryptoMode.ECB);
|
|
|
|
|
|
return ebcData;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class SenderAddRemoteControlWithTimeCycleCoercionReply extends Reply {
|
|
|
|
|
|
SenderAddRemoteControlWithTimeCycleCoercionReply.parseData(CommandType commandType, List<int> dataDetail)
|
|
|
|
|
|
: super.parseData(commandType, dataDetail) {
|
|
|
|
|
|
data = dataDetail;
|
|
|
|
|
|
final int status = data[2];
|
|
|
|
|
|
errorWithStstus(status);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class SenderAddRemoteControlConfirmationReply extends Reply {
|
|
|
|
|
|
SenderAddRemoteControlConfirmationReply.parseData(CommandType commandType, List<int> dataDetail)
|
|
|
|
|
|
: super.parseData(commandType, dataDetail) {
|
|
|
|
|
|
data = dataDetail;
|
|
|
|
|
|
final int status = data[2];
|
|
|
|
|
|
errorWithStstus(status);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|