魏少阳 2368bb631c 1、完成网关模块国际化
2、删除蓝牙协议模块不用的蓝牙协议文件
2024-10-15 14:24:35 +08:00

90 lines
2.2 KiB
Dart
Executable File

import 'dart:convert';
import 'package:star_lock/tools/dateTool.dart';
import '../io_reply.dart';
import '../io_sender.dart';
import '../io_tool/io_tool.dart';
import '../io_type.dart';
import '../sm4Encipher/sm4.dart';
// 校时
class TimingCommand extends SenderProtocol {
String? lockID;
String? userID;
int? nowTime;
List<int>? token;
int? needAuthor;
List<int>? signKey;
List<int>? privateKey;
TimingCommand({
this.lockID,
this.userID,
this.nowTime,
this.token,
this.needAuthor,
this.signKey,
this.privateKey
}) : super(CommandType.calibrationTime);
@override
String toString() {
return 'TimingCommand{lockID: $lockID, userID: $userID, '
'nowTime: ${DateTool().dateIntToYMDHNString(nowTime)}, '
'token: $token, needAuthor: $needAuthor, '
'signKey: $signKey, privateKey: $privateKey}';
}
@override
List<int> messageDetail() {
List<int> data = [];
List<int> ebcData = [];
// 指令类型
final int type = commandType!.typeValue;
final double typeDouble = type / 256;
final int type1 = typeDouble.toInt();
final int type2 = type % 256;
data.add(type1);
data.add(type2);
//lockID 40
final int lockIDLength = utf8.encode(lockID!).length;
data.addAll(utf8.encode(lockID!));
data = getFixedLengthList(data, 40 - lockIDLength);
//userID 要接受钥匙的用户的useid 20
final int userIDLength = utf8.encode(userID!).length;
data.addAll(utf8.encode(userID!));
data = getFixedLengthList(data, 20 - userIDLength);
// nowTime 4
final int? d1 = nowTime;
data.add((d1! & 0xff000000) >> 24);
data.add((d1 & 0xff0000) >> 16);
data.add((d1 & 0xff00) >> 8);
data.add(d1 & 0xff);
if ((data.length % 16) != 0) {
final int add = 16 - data.length % 16;
for (int i = 0; i < add; i++) {
data.add(0);
}
}
printLog(data);
ebcData = SM4.encrypt(data, key: privateKey, mode: SM4CryptoMode.ECB);
return ebcData;
}
}
class TimingReply extends Reply {
TimingReply.parseData(CommandType commandType, List<int> dataDetail)
: super.parseData(commandType, dataDetail) {
data = dataDetail;
final int status = data[2];
errorWithStstus(status);
}
}