完成路及规划的作业的开始工作成功.
完成路径规划的暂停功能的对接 完成路径规划的继续功能的对接 完成路径规划的停止功能的对接
This commit is contained in:
@@ -13,13 +13,17 @@ class NetMessageDispatcher {
|
||||
final TcpClient tcpClient;
|
||||
final PathPlanningService _pathPlanningService;
|
||||
final RoutePlanningRepository routePlanningRepository;
|
||||
// 🔥 修改:使用回调函数获取 AppState
|
||||
final Function? getAppState;
|
||||
|
||||
NetMessageDispatcher(this.tcpClient, this.routePlanningRepository, this._pathPlanningService);
|
||||
|
||||
NetMessageDispatcher(this.tcpClient, this.routePlanningRepository, this._pathPlanningService, {this.getAppState});
|
||||
|
||||
|
||||
/// 过滤特定指令的流
|
||||
Stream<RawPacket> onCommand(int commandCode) {
|
||||
return tcpClient.packetStream.where((p) => p.command == commandCode);
|
||||
|
||||
}
|
||||
|
||||
/// 示例解析方法:将 0x02 指令解析为 String
|
||||
@@ -59,9 +63,19 @@ class NetMessageDispatcher {
|
||||
/// 验证头部:data[0]=0xAB, data[1]=0xAA, data[2]=0x01
|
||||
/// 检查状态位:data[5] == 0x01 表示回复成功
|
||||
Stream<RawPacket> onPathPlanningResponse() {
|
||||
|
||||
|
||||
debugPrint('[Dispatcher] 开始监听路径规划指令应答 (CMD: 0x01)');
|
||||
|
||||
return onCommand(0x01).where((packet) {
|
||||
// 🔥 修改:使用回调检查 AppState
|
||||
if (getAppState != null) {
|
||||
final currentState = getAppState!();
|
||||
if (currentState.toString() == 'AppState.none') {
|
||||
debugPrint('⚠️ [Dispatcher] 当前 AppState 为 none,停止处理路径规划指令');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// 构造完整数据包用于验证
|
||||
final fullData = <int>[
|
||||
0xAB, 0xAA, 0x01,
|
||||
@@ -76,7 +90,6 @@ class NetMessageDispatcher {
|
||||
fullData[2] == 0x01) {
|
||||
|
||||
debugPrint('[Dispatcher] 下位机回复成功 - 完整数据包:${fullData.join(" ")}');
|
||||
|
||||
// 检查状态位 (索引 5 对应 payload 的第 2 个字节)
|
||||
if (fullData.length > 5 && fullData[5] == 0x01) {
|
||||
debugPrint('✅ [Dispatcher] 状态位验证通过:0x01 - 可以发送下一个指令');
|
||||
|
||||
@@ -267,16 +267,22 @@ class TcpClient {
|
||||
void sendPathPoint(RoutePlanSendEntity routePlanSendEntity) {
|
||||
if (_socket == null) return;
|
||||
final payload = routePlanSendEntity.toBytes();
|
||||
final packet = sendRaw(0x01, payload); // 第1种的测试 声明指令结构和类型0x01 为命令类型
|
||||
//_socket!.add(payload);//第二种的测试
|
||||
print("sendPathPoint-0x01开始发送路径点数据");
|
||||
sendRaw(0x01, payload); // 第1种的测试 声明指令结构和类型0x01 为命令类型
|
||||
// _socket!.add(payload);//第二种的测试
|
||||
print("底层发送指令完成");
|
||||
}
|
||||
|
||||
|
||||
void sendDeviceStateChange(RoutePlanSendEntity routePlanSendEntity) {
|
||||
if (_socket == null) return;
|
||||
final payload = routePlanSendEntity.toBytes();
|
||||
_socket!.add(payload);
|
||||
// final packet = sendRaw(0x02, payload);
|
||||
//_socket!.add(payload);
|
||||
sendRaw(0x02, payload);
|
||||
var counts = routePlanSendEntity.pointCounts;
|
||||
var string = routePlanSendEntity.toString();
|
||||
print("sendDeviceStateChange 底层发送指令完成,数据:$counts");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user