第二次提交
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user