Files
flutterApp/lib/features/devices/data/models/route_plan_send_entity.dart
Songzex 31c399937f 修复路径规划暂停
修复路径规划继续
修复路径规开始工作
修复路径规停止工作+
2026-03-12 12:49:31 +08:00

67 lines
2.1 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'dart:typed_data';
import 'dart:convert';
class RoutePlanSendEntity {
final int header1 = 0xAB;
final int header2 = 0xAA;
final int endFlag1 = 0xAA;
final int endFlag2 = 0xAB;
final int crc16 = 0;
final int commandType;
final int pointCounts;
final double targetLatitude;
final double targetLongitude;
final int speed;
RoutePlanSendEntity({
required this.commandType,
required this.pointCounts,
required this.targetLatitude,
required this.targetLongitude,
required this.speed,
});
/// 生成和Java二进制完全等效的字节数组(解决服务器识别问题)
Uint8List toBytes() {
final byteData = ByteData(27);
int offset = 0;
// 1. 严格按Java的byte类型写入(有符号单字节)
byteData.setInt8(offset++, header1); // 0xAB → 有符号-85
byteData.setInt8(offset++, header2); // 0xAA → 有符号-86
// 2. 命令类型(有符号byte)
byteData.setInt8(offset++, commandType);
// 3. pointCounts(Java short → 有符号16位,小端)
byteData.setInt16(offset, pointCounts, Endian.little);
offset += 2;
// 4. 纬度(Java double → 64位浮点,小端)
byteData.setFloat64(offset, targetLatitude, Endian.little);
offset += 8;
// 5. 经度(Java double → 64位浮点,小端)
byteData.setFloat64(offset, targetLongitude, Endian.little);
offset += 8;
// 6. speed(Java short → 有符号16位,小端)
byteData.setInt16(offset, speed, Endian.little);
offset += 2;
// 7. CRC16(Java short → 有符号16位,小端)
byteData.setInt16(offset, crc16, Endian.little);
offset += 2;
// 8. 包尾(有符号byte)
byteData.setInt8(offset++, endFlag1); // 0xAA → -86
byteData.setInt8(offset++, endFlag2); // 0xAB → -85
var uint8list = byteData.buffer.asUint8List();
// 关键:直接返回原始二进制字节(不做任何映射/转换)
print("发送的指令字节数组,$uint8list");
return byteData.buffer.asUint8List();
}
/// 发送给服务器的核心方法(模拟Java的OutputStream传输)
}