修复路劲规划暂停和继续和停止的tcp指令的数据格式
This commit is contained in:
@@ -56,14 +56,35 @@ class PathPlanner {
|
||||
final TcpClient tcpClient;
|
||||
bool isStart = false;
|
||||
|
||||
// 🔥 新增:作业控制状态
|
||||
bool _isPaused = false;
|
||||
bool _isStopped = false;
|
||||
|
||||
PathPlanner(this.tcpClient);
|
||||
|
||||
void sendNextLocation() {
|
||||
print("[在发送指令sendNextLocation方法中]");
|
||||
if (isStart && locationQueue.isEmpty) {
|
||||
// if (isStart && locationQueue.isEmpty) {
|
||||
// isStart = false;
|
||||
// print("[track]");
|
||||
// tcpClient.disconnect();
|
||||
// return;
|
||||
// }
|
||||
// 🔥 关键检查:暂停或停止时不再发送
|
||||
if (_isPaused) {
|
||||
print("⏸️ 当前处于暂停状态,停止发送指令");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_isStopped || (isStart && locationQueue.isEmpty)) {
|
||||
isStart = false;
|
||||
print("[track]");
|
||||
tcpClient.disconnect();
|
||||
if (_isStopped) {
|
||||
print("⏹️ 已停止作业,清空队列");
|
||||
locationQueue.clear(); // 清空剩余队列
|
||||
} else {
|
||||
print("[路径点发送完毕]");
|
||||
}
|
||||
_isStopped = false; // 重置停止标志
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -82,14 +103,47 @@ class PathPlanner {
|
||||
}
|
||||
/// 开始
|
||||
void startRoutePlanning(List<DeviceAddPathPointModel> locations) {
|
||||
locationQueue.addAll(locations);
|
||||
isStart = true;
|
||||
/// locationQueue.addAll(locations);
|
||||
/// isStart = true;
|
||||
/// _isPaused = false; // 重置暂停标志
|
||||
/// _isStopped = false; // 重置停止标志
|
||||
/// 🔥 关键修复:只在队列为空时才添加(第一次调用)
|
||||
if (locationQueue.isEmpty) {
|
||||
locationQueue.addAll(locations);
|
||||
isStart = true;
|
||||
_isPaused = false; // 🔥 只在第一次调用时重置
|
||||
_isStopped = false; // 🔥 只在第一次调用时重置
|
||||
print("[首次加载] 队列长度:${locations.length}");
|
||||
} else {
|
||||
// 🔥 后续调用(来自 Dispatcher)只更新队列,不重置状态
|
||||
print("[更新队列] 当前处于 ${_isPaused ? '暂停' : _isStopped ? '停止' : '工作'} 状态");
|
||||
if (!_isPaused && !_isStopped) {
|
||||
// 如果不是暂停/停止状态,才添加新数据
|
||||
locationQueue.addAll(locations);
|
||||
}
|
||||
}
|
||||
|
||||
print("[发送指令要转换类型了完成]");
|
||||
|
||||
// 🔥 关键检查:如果是暂停/停止状态,直接返回
|
||||
if (_isPaused) {
|
||||
print("⏸️ 当前处于暂停状态,拒绝发送指令");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_isStopped) {
|
||||
print("⏹️ 当前处于停止状态,拒绝发送指令");
|
||||
return;
|
||||
}
|
||||
print("[发送指令要转换类型了完成]");
|
||||
sendNextLocation();
|
||||
|
||||
}
|
||||
/// 暂停
|
||||
void pauseRPWork() {
|
||||
print("⏸️ 暂停作业,设置_isPaused = true");
|
||||
_isPaused = true;
|
||||
|
||||
var entity = new RoutePlanSendEntity(
|
||||
commandType: 0x02,
|
||||
pointCounts: 2,
|
||||
@@ -97,11 +151,14 @@ class PathPlanner {
|
||||
targetLongitude: 0,
|
||||
speed: 0,
|
||||
);
|
||||
print("📡 发送暂停指令到设备...");
|
||||
tcpClient.sendDeviceStateChange(entity);
|
||||
//更新APP状态
|
||||
}
|
||||
/// 恢复
|
||||
void resumeRPWork() {
|
||||
print("▶️ 恢复作业,设置_isPaused = false");
|
||||
_isPaused = false;
|
||||
|
||||
var entity = new RoutePlanSendEntity(
|
||||
commandType: 0x02,
|
||||
pointCounts: 3,
|
||||
@@ -109,11 +166,21 @@ class PathPlanner {
|
||||
targetLongitude: 0,
|
||||
speed: 0,
|
||||
);
|
||||
print("📡 发送恢复指令到设备...");
|
||||
tcpClient.sendDeviceStateChange(entity);
|
||||
//更新APP状态
|
||||
|
||||
// 恢复后继续发送下一个点
|
||||
if (locationQueue.isNotEmpty) {
|
||||
print("📍 恢复发送下一个路径点");
|
||||
sendNextLocation();
|
||||
}
|
||||
}
|
||||
/// 停止
|
||||
void stopRoutePlanning() {
|
||||
print("⏹️ 停止作业,设置_isStopped = true");
|
||||
_isStopped = true;
|
||||
_isPaused = false; // 清除暂停状态
|
||||
|
||||
var entity = new RoutePlanSendEntity(
|
||||
commandType: 0x02,
|
||||
pointCounts: 0,
|
||||
@@ -121,11 +188,12 @@ class PathPlanner {
|
||||
targetLongitude: 0,
|
||||
speed: 0,
|
||||
);
|
||||
print("📡 发送停止指令到设备...");
|
||||
tcpClient.sendDeviceStateChange(entity);
|
||||
//更新APP状态
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user