修复路径规划暂停
修复路径规划继续 修复路径规开始工作 修复路径规停止工作+
This commit is contained in:
@@ -181,6 +181,11 @@ class TcpClient {
|
|||||||
_socket!.write(jsonEncode(data));
|
_socket!.write(jsonEncode(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sendnew(List<int> data){
|
||||||
|
_socket!.add(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void sendRaw(int cmd, List<int> payload) {
|
void sendRaw(int cmd, List<int> payload) {
|
||||||
if (_socket == null) return;
|
if (_socket == null) return;
|
||||||
|
|
||||||
@@ -268,7 +273,8 @@ class TcpClient {
|
|||||||
if (_socket == null) return;
|
if (_socket == null) return;
|
||||||
final payload = routePlanSendEntity.toBytes();
|
final payload = routePlanSendEntity.toBytes();
|
||||||
print("sendPathPoint-0x01开始发送路径点数据");
|
print("sendPathPoint-0x01开始发送路径点数据");
|
||||||
sendRaw(0x01, payload); // 第1种的测试 声明指令结构和类型0x01 为命令类型
|
//sendRaw(0x01, payload); // 第1种的测试 声明指令结构和类型0x01 为命令类型
|
||||||
|
sendnew(payload); // 第1种的测试 声明指令结构和类型0x01 为命令类型
|
||||||
// _socket!.add(payload);//第二种的测试
|
// _socket!.add(payload);//第二种的测试
|
||||||
print("底层发送指令完成");
|
print("底层发送指令完成");
|
||||||
}
|
}
|
||||||
@@ -276,11 +282,26 @@ class TcpClient {
|
|||||||
|
|
||||||
void sendDeviceStateChange(RoutePlanSendEntity routePlanSendEntity) {
|
void sendDeviceStateChange(RoutePlanSendEntity routePlanSendEntity) {
|
||||||
if (_socket == null) return;
|
if (_socket == null) return;
|
||||||
|
|
||||||
|
// 🔥 核心修复:构造完整的协议包(包含头部)
|
||||||
final payload = routePlanSendEntity.toBytes();
|
final payload = routePlanSendEntity.toBytes();
|
||||||
// 🔥 核心修复:直接发送字节数组,不再用 sendRaw 包装
|
|
||||||
_socket!.add(payload);
|
// final builder = BytesBuilder()
|
||||||
|
// ..addByte(0xAB)
|
||||||
|
// ..addByte(0xAA)
|
||||||
|
// ..addByte(0x02) // ✅ 设备状态控制指令
|
||||||
|
// ..add(payload)
|
||||||
|
// ..add([0x00, 0x00]) // CRC 占位
|
||||||
|
// ..addByte(0xAA)
|
||||||
|
// ..addByte(0xAB);
|
||||||
|
//
|
||||||
|
// final packet = builder.takeBytes();
|
||||||
|
sendnew(payload);
|
||||||
|
// _socket!.add(packet);
|
||||||
|
|
||||||
var counts = routePlanSendEntity.pointCounts;
|
var counts = routePlanSendEntity.pointCounts;
|
||||||
print("sendDeviceStateChange 底层发送指令完成,数据:$counts");
|
print("sendDeviceStateChange 底层发送指令完成,数据:$counts");
|
||||||
|
/// print("📡 发送的完整数据包:${builder.takeBytes()}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class AuthCubit extends Cubit<AuthState> {
|
|||||||
/// 当 HTTP 登录/注册成功后调用
|
/// 当 HTTP 登录/注册成功后调用
|
||||||
Future<void> loginSuccess(UserEntity user) async {
|
Future<void> loginSuccess(UserEntity user) async {
|
||||||
await storage.saveUser(user);
|
await storage.saveUser(user);
|
||||||
//await tcp.connect(host: TCPConsts.TCP_IP, port: TCPConsts.TCP_PORT);
|
await tcp.connect(host: TCPConsts.TCP_IP, port: TCPConsts.TCP_PORT);
|
||||||
// await _authTcpDatasource.sendAuthPacket(); //包括发送认证包和获取列表和切换函数
|
// await _authTcpDatasource.sendAuthPacket(); //包括发送认证包和获取列表和切换函数
|
||||||
//tcp.startHeartbeat(interval: const Duration(seconds: 4)); //启动心跳
|
//tcp.startHeartbeat(interval: const Duration(seconds: 4)); //启动心跳
|
||||||
appCubit.setAuth(user);
|
appCubit.setAuth(user);
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
// lib/features/devices/data/models/route_plan_send_entity.dart
|
import 'dart:typed_data';
|
||||||
import 'dart:typed_data'; // ✅ 必须添加
|
import 'dart:convert';
|
||||||
|
|
||||||
class RoutePlanSendEntity {
|
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 commandType;
|
||||||
final int pointCounts;
|
final int pointCounts;
|
||||||
final double targetLatitude;
|
final double targetLatitude;
|
||||||
@@ -16,23 +22,46 @@ class RoutePlanSendEntity {
|
|||||||
required this.speed,
|
required this.speed,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// 生成和Java二进制完全等效的字节数组(解决服务器识别问题)
|
||||||
|
Uint8List toBytes() {
|
||||||
|
final byteData = ByteData(27);
|
||||||
|
int offset = 0;
|
||||||
|
|
||||||
List<int> toBytes() {
|
// 1. 严格按Java的byte类型写入(有符号单字节)
|
||||||
final bytes = <int>[];
|
byteData.setInt8(offset++, header1); // 0xAB → 有符号-85
|
||||||
bytes.add(commandType);
|
byteData.setInt8(offset++, header2); // 0xAA → 有符号-86
|
||||||
bytes.addAll(_shortToBytes(pointCounts));
|
|
||||||
bytes.addAll(_doubleToBytes(targetLatitude));
|
|
||||||
bytes.addAll(_doubleToBytes(targetLongitude));
|
|
||||||
bytes.addAll(_shortToBytes(speed));
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<int> _shortToBytes(int value) {
|
// 2. 命令类型(有符号byte)
|
||||||
return [(value >> 8) & 0xFF, value & 0xFF];
|
byteData.setInt8(offset++, commandType);
|
||||||
}
|
|
||||||
|
|
||||||
List<int> _doubleToBytes(double value) {
|
// 3. pointCounts(Java short → 有符号16位,小端)
|
||||||
final byteData = ByteData(8)..setFloat64(0, value);
|
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();
|
return byteData.buffer.asUint8List();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/// 发送给服务器的核心方法(模拟Java的OutputStream传输)
|
||||||
|
}
|
||||||
@@ -145,7 +145,7 @@ class PathPlanner {
|
|||||||
_isPaused = true;
|
_isPaused = true;
|
||||||
|
|
||||||
var entity = new RoutePlanSendEntity(
|
var entity = new RoutePlanSendEntity(
|
||||||
commandType: 0x02,
|
commandType: 0x01,
|
||||||
pointCounts: 2,
|
pointCounts: 2,
|
||||||
targetLatitude: 0,
|
targetLatitude: 0,
|
||||||
targetLongitude: 0,
|
targetLongitude: 0,
|
||||||
@@ -160,7 +160,7 @@ class PathPlanner {
|
|||||||
_isPaused = false;
|
_isPaused = false;
|
||||||
|
|
||||||
var entity = new RoutePlanSendEntity(
|
var entity = new RoutePlanSendEntity(
|
||||||
commandType: 0x02,
|
commandType: 0x01,
|
||||||
pointCounts: 3,
|
pointCounts: 3,
|
||||||
targetLatitude: 0,
|
targetLatitude: 0,
|
||||||
targetLongitude: 0,
|
targetLongitude: 0,
|
||||||
@@ -182,7 +182,7 @@ class PathPlanner {
|
|||||||
_isPaused = false; // 清除暂停状态
|
_isPaused = false; // 清除暂停状态
|
||||||
|
|
||||||
var entity = new RoutePlanSendEntity(
|
var entity = new RoutePlanSendEntity(
|
||||||
commandType: 0x02,
|
commandType: 0x01,
|
||||||
pointCounts: 0,
|
pointCounts: 0,
|
||||||
targetLatitude: 0,
|
targetLatitude: 0,
|
||||||
targetLongitude: 0,
|
targetLongitude: 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user