无人机视频对接+支持无人机未在线时候5S执行一下查询操作。便于视频正常展示。
无人机视频的摄像头切换功能和参数切换功能(广角和红外 和等) 无人机航线任务创建页面的开发和接口对接 无人机航线任务搜索接口(支持时间过滤) 无人机执行航线任务功能开发和接口对接 无人机暂停执行任务功能开发和接口对接 无人机返航任务和取消返航功能开发和接口对接 无人机机场详情页中的展示信息的更正。
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import '../../domain/entities/drone_station_entity.dart';
|
||||
import '../../domain/entities/video_stream_entity.dart';
|
||||
import '../../domain/entities/flight_task_entity.dart';
|
||||
import '../../domain/entities/uav_video_stream_entity.dart';
|
||||
|
||||
abstract class DroneStationDataSource {
|
||||
Future<List<DroneStationEntity>> getDroneStationList(int siteId);
|
||||
@@ -17,4 +18,20 @@ abstract class DroneStationDataSource {
|
||||
required int beginAt,
|
||||
required int endAt,
|
||||
});
|
||||
}
|
||||
|
||||
Future<FlightTaskEntity> getFlightTaskDetail(String taskId);
|
||||
|
||||
Future<Map<String, dynamic>> updateFlightTaskStatus({
|
||||
required String taskId,
|
||||
required String status,
|
||||
});
|
||||
|
||||
/// 切换无人机镜头获取实时视频流
|
||||
Future<UavVideoStreamEntity> getUavVideoStream({
|
||||
required String sn,
|
||||
required String cameraIndex,
|
||||
UavLensType? lensType,
|
||||
VideoQualityType qualityType = VideoQualityType.adaptive,
|
||||
int videoExpire = 720000000,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import 'dart:convert';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:maibu_satabot_v2/core/consts/http_api_consts.dart';
|
||||
import '../datasources/drone_station_datasource.dart';
|
||||
import '../../domain/entities/drone_station_entity.dart';
|
||||
import '../../domain/entities/video_stream_entity.dart';
|
||||
import '../../domain/entities/flight_task_entity.dart';
|
||||
import '../../domain/entities/uav_video_stream_entity.dart';
|
||||
|
||||
class DroneStationDataSourceImpl implements DroneStationDataSource {
|
||||
final Dio dio;
|
||||
@@ -134,4 +136,198 @@ class DroneStationDataSourceImpl implements DroneStationDataSource {
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<FlightTaskEntity> getFlightTaskDetail(String taskId) async {
|
||||
final response = await dio.get(
|
||||
HttpApiConsts.getFlightTaskDetail,
|
||||
queryParameters: {'taskId': taskId},
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('网络请求失败: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseData = response.data;
|
||||
|
||||
if (responseData['code'] != 0 && responseData['code'] != 200) {
|
||||
throw Exception(responseData['message'] ?? '业务异常');
|
||||
}
|
||||
|
||||
return FlightTaskEntity.fromJson(responseData['data']);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> updateFlightTaskStatus({
|
||||
required String taskId,
|
||||
required String status,
|
||||
}) async {
|
||||
final response = await dio.post(
|
||||
HttpApiConsts.updateFlightTaskStatus,
|
||||
queryParameters: {
|
||||
'taskId': taskId,
|
||||
'status': status,
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('网络请求失败: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseData = response.data;
|
||||
|
||||
if (responseData['code'] != 0) {
|
||||
throw Exception(responseData['message'] ?? '业务异常');
|
||||
}
|
||||
|
||||
return responseData;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<UavVideoStreamEntity> getUavVideoStream({
|
||||
required String sn,
|
||||
required String cameraIndex,
|
||||
UavLensType? lensType,
|
||||
VideoQualityType qualityType = VideoQualityType.adaptive,
|
||||
int videoExpire = 720000000,
|
||||
}) async {
|
||||
try {
|
||||
print('=== 开始请求无人机视频流 ===');
|
||||
print('URL: ${HttpApiConsts.changeUAVLens}');
|
||||
print('📤 请求参数:');
|
||||
print(' sn: $sn');
|
||||
print(' cameraIndex: $cameraIndex ⬅️ 重点检查这个');
|
||||
print(' lensType: ${_lensTypeToString(lensType)}');
|
||||
print(' qualityType: ${_qualityTypeToString(qualityType)}');
|
||||
print(' videoExpire: $videoExpire');
|
||||
|
||||
final response = await dio.post(
|
||||
HttpApiConsts.changeUAVLens,
|
||||
data: {
|
||||
'sn': sn,
|
||||
'lensType': lensType != null ? _lensTypeToString(lensType) : '',
|
||||
'cameraIndex': cameraIndex,
|
||||
'qualityType': _qualityTypeToString(qualityType),
|
||||
'videoExpire': videoExpire,
|
||||
},
|
||||
options: Options(
|
||||
receiveTimeout: const Duration(seconds: 30),
|
||||
sendTimeout: const Duration(seconds: 30),
|
||||
),
|
||||
);
|
||||
|
||||
print('响应状态码: ${response.statusCode}');
|
||||
print('响应数据类型: ${response.data.runtimeType}');
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('网络请求失败: ${response.statusCode}');
|
||||
}
|
||||
|
||||
var responseData = response.data;
|
||||
|
||||
// 打印完整响应,方便调试
|
||||
print('完整响应: $responseData');
|
||||
|
||||
// 检查是否为字符串类型,需要手动解析
|
||||
if (responseData is String) {
|
||||
print('检测到响应为字符串类型,尝试 JSON 解析...');
|
||||
try {
|
||||
final parsed = jsonDecode(responseData);
|
||||
if (parsed is Map<String, dynamic>) {
|
||||
print('JSON 解析成功');
|
||||
responseData = parsed;
|
||||
} else {
|
||||
throw Exception('JSON 解析结果不是 Map 类型');
|
||||
}
|
||||
} catch (e) {
|
||||
print('JSON 解析失败: $e');
|
||||
throw Exception('响应数据格式错误: $e');
|
||||
}
|
||||
}
|
||||
|
||||
print('响应数据键列表: ${(responseData as Map).keys?.toList()}');
|
||||
|
||||
if (responseData['code'] != 200) {
|
||||
final errorMsg = responseData['msg'] ?? '业务异常';
|
||||
print('业务错误: $errorMsg');
|
||||
throw Exception(errorMsg);
|
||||
}
|
||||
|
||||
final data = responseData['data'];
|
||||
print('\n=== data 字段内容 ===');
|
||||
print('data: $data');
|
||||
print('data 类型: ${data.runtimeType}');
|
||||
|
||||
if (data == null) {
|
||||
print('错误: data 字段为 null!');
|
||||
throw Exception('服务器返回的 data 字段为空');
|
||||
}
|
||||
|
||||
print('data.sn: ${data['sn']}');
|
||||
print('data.camera_index: ${data['camera_index']}');
|
||||
print('data.url: ${data['url']}');
|
||||
print('data.expire_ts: ${data['expire_ts']}');
|
||||
print('data.url_type: ${data['url_type']}');
|
||||
print('=========================\n');
|
||||
|
||||
return UavVideoStreamEntity.fromJson(data);
|
||||
} on DioException catch (e) {
|
||||
print('=== Dio 异常捕获 ===');
|
||||
print('异常类型: ${e.type}');
|
||||
print('异常消息: ${e.message}');
|
||||
print('异常详情: $e');
|
||||
|
||||
String errorMessage;
|
||||
switch (e.type) {
|
||||
case DioExceptionType.connectionTimeout:
|
||||
case DioExceptionType.sendTimeout:
|
||||
case DioExceptionType.receiveTimeout:
|
||||
errorMessage = '网络连接超时,请检查网络';
|
||||
break;
|
||||
case DioExceptionType.connectionError:
|
||||
errorMessage = '网络连接失败,请检查网络设置';
|
||||
break;
|
||||
case DioExceptionType.badResponse:
|
||||
errorMessage = '服务器响应错误: ${e.response?.statusCode}';
|
||||
break;
|
||||
default:
|
||||
errorMessage = '网络请求失败: ${e.message}';
|
||||
}
|
||||
|
||||
throw Exception(errorMessage);
|
||||
} catch (e) {
|
||||
print('=== 未知异常 ===');
|
||||
print('异常类型: ${e.runtimeType}');
|
||||
print('异常消息: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
/// 将镜头类型枚举转换为字符串
|
||||
String _lensTypeToString(UavLensType? type) {
|
||||
switch (type) {
|
||||
case UavLensType.wide:
|
||||
return 'wide';
|
||||
case UavLensType.zoom:
|
||||
return 'zoom';
|
||||
case UavLensType.ir:
|
||||
return 'ir';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/// 将质量类型枚举转换为字符串
|
||||
String _qualityTypeToString(VideoQualityType type) {
|
||||
switch (type) {
|
||||
case VideoQualityType.adaptive:
|
||||
return 'adaptive';
|
||||
case VideoQualityType.low:
|
||||
return 'low';
|
||||
case VideoQualityType.medium:
|
||||
return 'medium';
|
||||
case VideoQualityType.high:
|
||||
return 'high';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ import '../../../../../core/error/failure.dart';
|
||||
import '../datasources/drone_station_datasource.dart';
|
||||
import '../../domain/entities/drone_station_entity.dart';
|
||||
import '../../domain/entities/video_stream_entity.dart';
|
||||
import '../../domain/entities/flight_task_entity.dart';
|
||||
import '../../domain/entities/uav_video_stream_entity.dart';
|
||||
import '../../domain/repositories/drone_station_repository.dart';
|
||||
|
||||
class DroneStationRepositoryImpl implements DroneStationRepository {
|
||||
@@ -52,4 +54,70 @@ class DroneStationRepositoryImpl implements DroneStationRepository {
|
||||
return Left(Failure(e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, Map<String, List<FlightTaskEntity>?>>> getFlightTasks({
|
||||
required List<String> sns,
|
||||
required int beginAt,
|
||||
required int endAt,
|
||||
}) async {
|
||||
try {
|
||||
final tasks = await dataSource.getFlightTasks(
|
||||
sns: sns,
|
||||
beginAt: beginAt,
|
||||
endAt: endAt,
|
||||
);
|
||||
return Right(tasks);
|
||||
} catch (e) {
|
||||
return Left(Failure(e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, FlightTaskEntity>> getFlightTaskDetail(String taskId) async {
|
||||
try {
|
||||
final detail = await dataSource.getFlightTaskDetail(taskId);
|
||||
return Right(detail);
|
||||
} catch (e) {
|
||||
return Left(Failure(e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, Map<String, dynamic>>> updateFlightTaskStatus({
|
||||
required String taskId,
|
||||
required String status,
|
||||
}) async {
|
||||
try {
|
||||
final result = await dataSource.updateFlightTaskStatus(
|
||||
taskId: taskId,
|
||||
status: status,
|
||||
);
|
||||
return Right(result);
|
||||
} catch (e) {
|
||||
return Left(Failure(e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, UavVideoStreamEntity>> getUavVideoStream({
|
||||
required String sn,
|
||||
required String cameraIndex,
|
||||
UavLensType? lensType,
|
||||
VideoQualityType qualityType = VideoQualityType.adaptive,
|
||||
int videoExpire = 720000000,
|
||||
}) async {
|
||||
try {
|
||||
final videoStream = await dataSource.getUavVideoStream(
|
||||
sn: sn,
|
||||
cameraIndex: cameraIndex,
|
||||
lensType: lensType,
|
||||
qualityType: qualityType,
|
||||
videoExpire: videoExpire,
|
||||
);
|
||||
return Right(videoStream);
|
||||
} catch (e) {
|
||||
return Left(Failure(e.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user