优化和路径规划新适配

This commit is contained in:
2026-07-11 16:46:53 +08:00
parent 2124f3bc02
commit 1a4d0aedfd
43 changed files with 2454 additions and 685 deletions

View File

@@ -34,4 +34,14 @@ abstract class DroneStationDataSource {
VideoQualityType qualityType = VideoQualityType.adaptive,
int videoExpire = 720000000,
});
/// 暂停飞行任务(通过 flightTaskCommand 接口)
Future<Map<String, dynamic>> pauseFlightTask({
required String deviceSn,
});
/// 返航(通过 flightTaskCommand 接口)
Future<Map<String, dynamic>> returnHome({
required String deviceSn,
});
}

View File

@@ -330,4 +330,88 @@ class DroneStationDataSourceImpl implements DroneStationDataSource {
return 'high';
}
}
@override
Future<Map<String, dynamic>> pauseFlightTask({
required String deviceSn,
}) async {
final response = await dio.post(
HttpApiConsts.flightTaskCommand,
data: {
'command': 'flighttask_pause',
'deviceSn': deviceSn,
},
);
if (response.statusCode != 200) {
throw Exception('网络请求失败: ${response.statusCode}');
}
// 🔥 重要:接口返回的是 text/plain,需要手动解析 JSON
dynamic responseData;
if (response.data is String) {
try {
responseData = jsonDecode(response.data as String);
} catch (e) {
throw Exception('响应数据解析失败: $e');
}
} else {
responseData = response.data;
}
// 确保 responseData 是 Map
if (responseData is! Map<String, dynamic>) {
throw Exception('响应数据格式错误');
}
// 🔥 直接返回接口返回的 message,不自己拟定
if (responseData['code'] != 200) {
final message = responseData['message'] ?? '操作失败';
throw Exception(message);
}
return responseData;
}
@override
Future<Map<String, dynamic>> returnHome({
required String deviceSn,
}) async {
final response = await dio.post(
HttpApiConsts.flightTaskCommand,
data: {
'command': 'return_home',
'deviceSn': deviceSn,
},
);
if (response.statusCode != 200) {
throw Exception('网络请求失败: ${response.statusCode}');
}
// 🔥 重要:接口返回的是 text/plain,需要手动解析 JSON
dynamic responseData;
if (response.data is String) {
try {
responseData = jsonDecode(response.data as String);
} catch (e) {
throw Exception('响应数据解析失败: $e');
}
} else {
responseData = response.data;
}
// 确保 responseData 是 Map
if (responseData is! Map<String, dynamic>) {
throw Exception('响应数据格式错误');
}
// 🔥 直接返回接口返回的 message,不自己拟定
if (responseData['code'] != 200) {
final message = responseData['message'] ?? '操作失败';
throw Exception(message);
}
return responseData;
}
}