优化和路径规划新适配
This commit is contained in:
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user