开始作业,

暂停作业,
停止作业,
回复作业,
---初步待使用
This commit is contained in:
2026-03-02 14:11:04 +08:00
parent fe9b763783
commit e416416e85
9 changed files with 334 additions and 5 deletions

View File

@@ -4,4 +4,5 @@ abstract class PathHttpDatasource {
Future<List<DeviceAddPathPointModel>> generatePathRaw({
required Map<String, dynamic> body,
});
}

View File

@@ -0,0 +1,38 @@
// lib/features/devices/data/models/route_plan_send_entity.dart
import 'dart:typed_data'; // ✅ 必须添加
class RoutePlanSendEntity {
final int commandType;
final int pointCounts;
final double targetLatitude;
final double targetLongitude;
final int speed;
RoutePlanSendEntity({
required this.commandType,
required this.pointCounts,
required this.targetLatitude,
required this.targetLongitude,
required this.speed,
});
List<int> toBytes() {
final bytes = <int>[];
bytes.add(commandType);
bytes.addAll(_shortToBytes(pointCounts));
bytes.addAll(_doubleToBytes(targetLatitude));
bytes.addAll(_doubleToBytes(targetLongitude));
bytes.addAll(_shortToBytes(speed));
return bytes;
}
List<int> _shortToBytes(int value) {
return [(value >> 8) & 0xFF, value & 0xFF];
}
List<int> _doubleToBytes(double value) {
final byteData = ByteData(8)..setFloat64(0, value);
return byteData.buffer.asUint8List();
}
}

View File

@@ -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状态
}
}