第二次提交

This commit is contained in:
cc
2026-01-18 20:21:14 +08:00
parent 4346601481
commit 289e706337
129 changed files with 4615 additions and 135 deletions

View File

@@ -0,0 +1,28 @@
import 'dart:typed_data';
/// 极简化的 Codec:只负责中间那段变化的“负载数据”
class MachineProtocolCodec {
/// 仅封装 0x00 指令的数据部分 (Byte 3 到 Byte 10,共 8 字节)
static Uint8List encodeRemoteControlPayload({
required int left,
required int right,
int lift = 0,
int mower = 0,
int ignition = 0,
int emergency = 0,
}) {
final bd = ByteData(8); // 只分配 8 字节
int pos = 0;
bd.setInt16(pos, left, Endian.little);
pos += 2;
bd.setInt16(pos, right, Endian.little);
pos += 2;
bd.setUint8(pos++, lift);
bd.setUint8(pos++, mower);
bd.setUint8(pos++, ignition);
bd.setUint8(pos++, emergency);
return bd.buffer.asUint8List();
}
}

View File

@@ -0,0 +1,18 @@
class MachineProtocolConstants {
// 固定字节
static const int header1 = 0xAB;
static const int header2 = 0xAA;
static const int endFlag1 = 0xAA;
static const int endFlag2 = 0xAB;
// 指令类型 (根据你的 CSV 文件)
static const int cmdRemoteControl = 0x00; // 远程遥控
static const int cmdPathPlanning = 0x01; // 路径规划
static const int cmdStatusInfo = 0x02; // 状态信息
static const int cmdGetId = 0x03; // 连接请求/查询ID
static const int cmdGetAuth = 0x04; // 获取授权
static const int cmdReadConfig = 0x05; // 读配置
static const int cmdWriteConfig = 0x06; // 写配置
static const int cmdObstacleAvoid = 0x07; // 避障
static const int cmdHeartbeat = 0xFF; // 心跳包
}