2023-12-11 13:44:15 +08:00
|
|
|
|
|
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
|
|
|
|
import '../../blue/io_tool/io_tool.dart';
|
|
|
|
|
|
import 'io_udpType.dart';
|
|
|
|
|
|
|
|
|
|
|
|
abstract class IOData {
|
|
|
|
|
|
List<int> messageDetail();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
abstract class UDPSenderProtocol extends IOData {
|
|
|
|
|
|
// var uint8View1 = Uint8List(300);
|
|
|
|
|
|
|
|
|
|
|
|
CommandUDPType? commandType; //指令类型
|
|
|
|
|
|
// final List<int> header = [0XEF, 0X01, 0XEE, 0X02]; //帧头 固定取值 0XEF01EE02,长度 4 字节
|
|
|
|
|
|
// final int ask = 0X01 ; // 包类型:0X01 表示请求包,0X11 表示应答包,长度 1 字节
|
|
|
|
|
|
|
|
|
|
|
|
List<int>? commandData = []; //数据块
|
|
|
|
|
|
|
|
|
|
|
|
UDPSenderProtocol(this.commandType) {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-15 18:32:11 +08:00
|
|
|
|
// 拼装数据
|
2023-12-11 13:44:15 +08:00
|
|
|
|
List<int> packageData() {
|
|
|
|
|
|
commandData = messageDetail();
|
|
|
|
|
|
List<int> commandList = [];
|
|
|
|
|
|
|
|
|
|
|
|
var cID = "XXXCID";
|
|
|
|
|
|
commandList.addAll(utf8.encode(cID));
|
|
|
|
|
|
commandList = getFixedLengthList(commandList, 6 - utf8.encode(cID).length);
|
|
|
|
|
|
|
|
|
|
|
|
// 数据块
|
|
|
|
|
|
commandList.addAll(commandData!); //数据块
|
2024-04-26 15:38:59 +08:00
|
|
|
|
// AppLog.log("commandList:$commandList");
|
2023-12-11 13:44:15 +08:00
|
|
|
|
return commandList;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|