app-starlock/lib/talk/udp/io_protocol/udp_mainProtocol.dart
2024-05-18 09:37:50 +08:00

86 lines
1.9 KiB
Dart
Executable File

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;
List<int>? endData;
UDPMainProtocolCommand({
this.command,
this.commandTypeIsCalling,
this.subCommand,
this.lockID,
this.lockIP,
this.userMobile,
this.userMobileIP,
this.endData,
}) : super(CommandUDPType.heart);
@override
List<int> messageDetail() {
List<int> data = [];
// 命令
data.add(command!);
// 命令类型
data.add(commandTypeIsCalling!);
// 子命令
data.add(subCommand!);
// lockID
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);
}
// lockIP
var lockIPList = lockIP!.split(".");
lockIPList.forEach((element) {
data.add(int.parse(element));
});
// userMobile
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);
}
// userMobileIP
var userMobileIPList = lockIP!.split(".");
userMobileIPList.forEach((element) {
data.add(int.parse(element));
});
data.addAll(endData!);
// AppLog.log("datadatadata:$data");
return data;
}
}
class UDPMainProtocolReply extends UDPReply {
UDPMainProtocolReply.parseData(CommandUDPType commandType, List<int> dataDetail)
: super.parseData(commandType, dataDetail) {
data = dataDetail;
}
}