开始作业,
暂停作业, 停止作业, 回复作业, ---初步待使用
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:maibu_satabot_v2/features/devices/data/models/device_add_path_point_model.dart';
|
||||
import '../../../../core/network/tcp/tcp_client.dart';
|
||||
import '../../domain/repositories/route_planning_repository.dart';
|
||||
import '../models/route_plan_send_entity.dart';
|
||||
|
||||
class RoutePlanningRepositoryImpl implements RoutePlanningRepository {
|
||||
final TcpClient tcp;
|
||||
late PathPlanner _planner;
|
||||
|
||||
RoutePlanningRepositoryImpl({required this.tcp}) { // ✅ 加 {required} 和类型注解
|
||||
_planner = PathPlanner(tcp);
|
||||
}
|
||||
@override
|
||||
Future<void> startRoutePlanning(Queue<DeviceAddPathPointModel> locationQueue) async {
|
||||
// 直接传入 DeviceAddPathPointModel 列表(无需转换)
|
||||
final List<DeviceAddPathPointModel> locations = locationQueue.toList();
|
||||
_planner.startRoutePlanning(locations);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> pauseRPWork() async {
|
||||
// TODO: implement pauseRPWork
|
||||
_planner.pauseRPWork();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> resumeRPWork() async {
|
||||
// TODO: implement resumeRPWork
|
||||
_planner.resumeRPWork();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> stopRoutePlanning() async {
|
||||
// TODO: implement stopRoutePlanning
|
||||
_planner.stopRoutePlanning();
|
||||
}
|
||||
}
|
||||
|
||||
// PathPlanner
|
||||
class PathPlanner {
|
||||
final Queue<DeviceAddPathPointModel> locationQueue = Queue();
|
||||
final TcpClient tcpClient;
|
||||
bool isStart = false;
|
||||
|
||||
PathPlanner(this.tcpClient);
|
||||
|
||||
void sendNextLocation() {
|
||||
if (isStart && locationQueue.isEmpty) {
|
||||
isStart = false;
|
||||
print("[track]");
|
||||
tcpClient.disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
final entity = locationQueue.removeFirst(); // 类型:DeviceAddPathPointModel
|
||||
final routePlanSendEntity = RoutePlanSendEntity(
|
||||
commandType: 0x01,
|
||||
pointCounts: 1,
|
||||
targetLatitude: entity.latitude,
|
||||
targetLongitude: entity.longitude,
|
||||
speed: 1000,
|
||||
);
|
||||
|
||||
print("====Lat:${entity.latitude} ====Lng:${entity.longitude}");
|
||||
tcpClient.sendPathPoint( routePlanSendEntity);
|
||||
isStart = true;
|
||||
}
|
||||
/// 开始
|
||||
void startRoutePlanning(List<DeviceAddPathPointModel> locations) {
|
||||
locationQueue.addAll(locations);
|
||||
isStart = true;
|
||||
sendNextLocation();
|
||||
}
|
||||
/// 暂停
|
||||
void pauseRPWork() {
|
||||
var entity = new RoutePlanSendEntity(
|
||||
commandType: 0x02,
|
||||
pointCounts: 2,
|
||||
targetLatitude: 0,
|
||||
targetLongitude: 0,
|
||||
speed: 0,
|
||||
);
|
||||
tcpClient.sendDeviceStateChange(entity);
|
||||
//更新APP状态
|
||||
}
|
||||
/// 恢复
|
||||
void resumeRPWork() {
|
||||
var entity = new RoutePlanSendEntity(
|
||||
commandType: 0x02,
|
||||
pointCounts: 3,
|
||||
targetLatitude: 0,
|
||||
targetLongitude: 0,
|
||||
speed: 0,
|
||||
);
|
||||
tcpClient.sendDeviceStateChange(entity);
|
||||
//更新APP状态
|
||||
}
|
||||
/// 停止
|
||||
void stopRoutePlanning() {
|
||||
var entity = new RoutePlanSendEntity(
|
||||
commandType: 0x02,
|
||||
pointCounts: 0,
|
||||
targetLatitude: 0,
|
||||
targetLongitude: 0,
|
||||
speed: 0,
|
||||
);
|
||||
tcpClient.sendDeviceStateChange(entity);
|
||||
//更新APP状态
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user