app-starlock/lib/talk/udp/io_protocol/udp_mainProtocol.dart

86 lines
1.9 KiB
Dart
Raw Normal View History

2023-12-11 13:44:15 +08:00
import 'dart:convert';
import '../../../blue/io_tool/io_tool.dart';
import '../io_udpSender.dart';
import '../io_udpType.dart';
import '../udp_reply.dart';
class UDPMainProtocolCommand extends UDPSenderProtocol {
int? command;
int? commandTypeIsCalling;
int? subCommand;
String? lockID;
String? lockIP;
String? userMobile;
String? userMobileIP;
2023-12-21 10:21:25 +08:00
List<int>? endData;
2023-12-11 13:44:15 +08:00
UDPMainProtocolCommand({
this.command,
this.commandTypeIsCalling,
this.subCommand,
this.lockID,
this.lockIP,
this.userMobile,
this.userMobileIP,
2023-12-21 10:21:25 +08:00
this.endData,
2023-12-11 13:44:15 +08:00
}) : super(CommandUDPType.heart);
@override
List<int> messageDetail() {
List<int> data = [];
// 命令
data.add(command!);
// 命令类型
data.add(commandTypeIsCalling!);
// 子命令
data.add(subCommand!);
// lockID
2023-12-29 14:28:47 +08:00
List<int> lockIDData = utf8.encode(lockID!);
data.addAll(lockIDData);
// topBytes = getFixedLengthList(lockIDData, 20 - lockIDData.length);
for (int i = 0; i < 20 - lockIDData.length; i++) {
data.add(0);
}
2023-12-11 13:44:15 +08:00
// lockIP
var lockIPList = lockIP!.split(".");
lockIPList.forEach((element) {
data.add(int.parse(element));
});
// userMobile
2023-12-29 14:28:47 +08:00
List<int> userMobileData = utf8.encode(userMobile!);
data.addAll(userMobileData);
// topBytes = getFixedLengthList(topBytes, 20 - userMobileData.length);
for (int i = 0; i < 20 - userMobileData.length; i++) {
data.add(0);
}
2023-12-11 13:44:15 +08:00
// userMobileIP
var userMobileIPList = lockIP!.split(".");
userMobileIPList.forEach((element) {
data.add(int.parse(element));
});
2023-12-22 14:26:58 +08:00
data.addAll(endData!);
2024-04-26 15:38:59 +08:00
// AppLog.log("datadatadata:$data");
2023-12-11 13:44:15 +08:00
return data;
}
}
class UDPMainProtocolReply extends UDPReply {
UDPMainProtocolReply.parseData(CommandUDPType commandType, List<int> dataDetail)
: super.parseData(commandType, dataDetail) {
data = dataDetail;
}
}