完成路及规划的作业的开始工作成功.
完成路径规划的暂停功能的对接 完成路径规划的继续功能的对接 完成路径规划的停止功能的对接
This commit is contained in:
@@ -8,6 +8,8 @@ import '../models/route_plan_send_entity.dart';
|
||||
class RoutePlanningRepositoryImpl implements RoutePlanningRepository {
|
||||
final TcpClient tcp;
|
||||
late PathPlanner _planner;
|
||||
// 🔥 新增:存储 AppState 的引用
|
||||
dynamic _appState;
|
||||
|
||||
RoutePlanningRepositoryImpl({required this.tcp}) { // ✅ 加 {required} 和类型注解
|
||||
_planner = PathPlanner(tcp);
|
||||
@@ -15,6 +17,7 @@ class RoutePlanningRepositoryImpl implements RoutePlanningRepository {
|
||||
@override
|
||||
Future<void> startRoutePlanning(Queue<DeviceAddPathPointModel> locationQueue) async {
|
||||
// 直接传入 DeviceAddPathPointModel 列表(无需转换)
|
||||
print("[底层开始发送指令了]");
|
||||
final List<DeviceAddPathPointModel> locations = locationQueue.toList();
|
||||
_planner.startRoutePlanning(locations);
|
||||
}
|
||||
@@ -36,6 +39,15 @@ class RoutePlanningRepositoryImpl implements RoutePlanningRepository {
|
||||
// TODO: implement stopRoutePlanning
|
||||
_planner.stopRoutePlanning();
|
||||
}
|
||||
|
||||
@override
|
||||
getCurrentAppState() {
|
||||
// TODO: implement getCurrentAppState
|
||||
return _appState;
|
||||
}
|
||||
void setAppState(dynamic state) {
|
||||
_appState = state;
|
||||
}
|
||||
}
|
||||
|
||||
// PathPlanner
|
||||
@@ -47,6 +59,7 @@ class PathPlanner {
|
||||
PathPlanner(this.tcpClient);
|
||||
|
||||
void sendNextLocation() {
|
||||
print("[在发送指令sendNextLocation方法中]");
|
||||
if (isStart && locationQueue.isEmpty) {
|
||||
isStart = false;
|
||||
print("[track]");
|
||||
@@ -71,7 +84,9 @@ class PathPlanner {
|
||||
void startRoutePlanning(List<DeviceAddPathPointModel> locations) {
|
||||
locationQueue.addAll(locations);
|
||||
isStart = true;
|
||||
print("[发送指令要转换类型了完成]");
|
||||
sendNextLocation();
|
||||
|
||||
}
|
||||
/// 暂停
|
||||
void pauseRPWork() {
|
||||
|
||||
@@ -15,4 +15,6 @@ abstract class RoutePlanningRepository {
|
||||
Future<void> pauseRPWork();
|
||||
/// Resume
|
||||
Future<void> resumeRPWork();
|
||||
/// Get current app state
|
||||
getCurrentAppState() {}
|
||||
}
|
||||
|
||||
@@ -351,13 +351,20 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
|
||||
// 开始路径规划
|
||||
Future<void> startRoutePlanning(Queue<DeviceAddPathPointModel> locationQueue) async {
|
||||
print("cubit层开始路径规划");
|
||||
// 清空全局 Service 中的队列
|
||||
// _routePlanningUseCase.clearLocationQueue();
|
||||
_pathPlanningService.updateQueue(locationQueue as List<DeviceAddPathPointModel>);
|
||||
final List<DeviceAddPathPointModel> pathList = locationQueue.toList();
|
||||
print('✅ 队列转换为 List,长度:${pathList.length}');
|
||||
|
||||
_pathPlanningService.updateQueue(pathList);
|
||||
print('✅ 队列更新成功');
|
||||
|
||||
// 开始路径规划
|
||||
emit(state.copyWith(isLoading: true));
|
||||
//传入全局的Service 中路径规划队列
|
||||
Queue<DeviceAddPathPointModel> queue = _pathPlanningService.getQueue() ;
|
||||
print('📦 从 Service 获取的队列长度:${queue.length}');
|
||||
final result = await _routePlanningUseCase.startRoutePlanning(queue);
|
||||
result.fold(
|
||||
(failure) => emit(state.copyWith(isLoading: false, errorMessage: failure.message ?? '路径规划启动失败')),
|
||||
@@ -386,4 +393,9 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
final result = await _routePlanningUseCase.stopRoutePlanning();
|
||||
result.fold((failure) => emit(state.copyWith(isLoading: false, errorMessage: failure.message ?? '停止失败')), (_) => emit(state.copyWith(isLoading: false)));
|
||||
}
|
||||
|
||||
void updateAppState(AppState appState) {
|
||||
emit(state.copyWith(appState: appState));
|
||||
(_routePlanningUseCase as dynamic).repository.setAppState(appState);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ class DevicesState extends Equatable {
|
||||
DeviceOperationType? operationType,
|
||||
List<Map<String, dynamic>>? pathData,
|
||||
List<DeviceAddPathPointModel>? generatedPath,
|
||||
AppState? appState,
|
||||
}) {
|
||||
return DevicesState(
|
||||
devices: devices ?? this.devices,
|
||||
@@ -68,6 +69,7 @@ class DevicesState extends Equatable {
|
||||
workRecords: workRecords ?? this.workRecords,
|
||||
operationType: operationType ?? this.operationType, // 更新操作类型
|
||||
generatedPath: generatedPath ?? this.generatedPath, // 更新生成的路径数据
|
||||
appState: appState ?? this.appState, // 更新应用状态
|
||||
);
|
||||
}
|
||||
|
||||
@@ -80,5 +82,6 @@ class DevicesState extends Equatable {
|
||||
pathData,
|
||||
operationType,
|
||||
generatedPath,
|
||||
appState,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ class PathPlanningService {
|
||||
|
||||
/// 🔥 存:生成路径后立即存储
|
||||
void updateQueue(List<DeviceAddPathPointModel> locations) {
|
||||
debugPrint('进入[PathPlanningService]updateQueue方法尝试更新空队列');
|
||||
if (locations.isEmpty) {
|
||||
debugPrint('⚠️ [PathPlanningService] 尝试更新空队列');
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user