第二次提交
This commit is contained in:
28
lib/core/protocol/machine_protocol_codec.dart
Normal file
28
lib/core/protocol/machine_protocol_codec.dart
Normal 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();
|
||||
}
|
||||
}
|
||||
18
lib/core/protocol/machine_protocol_constants.dart
Normal file
18
lib/core/protocol/machine_protocol_constants.dart
Normal 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; // 心跳包
|
||||
}
|
||||
Reference in New Issue
Block a user