完善路线返航和障碍物显示
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
/// mower/{sn}/perception/obstacle/post 中的单个感知目标。
|
||||
/// class_id 是类别依据;x/y/z 为设备局部坐标,地图只使用经纬度。
|
||||
class MowerObstacleEntity {
|
||||
const MowerObstacleEntity({
|
||||
required this.classId,
|
||||
required this.latitude,
|
||||
required this.longitude,
|
||||
this.trackId,
|
||||
this.confidence,
|
||||
this.distance,
|
||||
});
|
||||
|
||||
final int classId;
|
||||
final double latitude;
|
||||
final double longitude;
|
||||
final int? trackId;
|
||||
final double? confidence;
|
||||
final double? distance;
|
||||
|
||||
/// 协议定义:0 bus / 1 car / 2 motorcycle / 3 person / 4 truck。
|
||||
String get categoryKey => switch (classId) {
|
||||
0 => 'bus',
|
||||
1 => 'car',
|
||||
2 => 'motorcycle',
|
||||
3 => 'person',
|
||||
4 => 'truck',
|
||||
_ => 'unknown',
|
||||
};
|
||||
|
||||
static MowerObstacleEntity? tryParse(Map<dynamic, dynamic> json) {
|
||||
final lat = _number(json['latitude']);
|
||||
final lng = _number(json['longitude']);
|
||||
if (lat == null ||
|
||||
lng == null ||
|
||||
lat.abs() > 90 ||
|
||||
lng.abs() > 180 ||
|
||||
(lat == 0 && lng == 0)) {
|
||||
return null;
|
||||
}
|
||||
return MowerObstacleEntity(
|
||||
classId: _number(json['class_id'])?.toInt() ?? -1,
|
||||
latitude: lat,
|
||||
longitude: lng,
|
||||
trackId: _number(json['track_id'])?.toInt(),
|
||||
confidence: _number(json['confidence']),
|
||||
distance: _number(json['distance']),
|
||||
);
|
||||
}
|
||||
|
||||
static double? _number(dynamic value) {
|
||||
final number = value is num
|
||||
? value.toDouble()
|
||||
: double.tryParse(value?.toString() ?? '');
|
||||
return number != null && number.isFinite ? number : null;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import '../entities/mower_location_entity.dart';
|
||||
import '../entities/real_time_message_entity.dart';
|
||||
import '../entities/route_status_entity.dart';
|
||||
import '../entities/host_realtime_message_entity.dart';
|
||||
import '../entities/mower_obstacle_entity.dart';
|
||||
import '../entities/mower_task_status_entity.dart';
|
||||
|
||||
abstract class MowerRealtimeRepository {
|
||||
@@ -14,6 +15,9 @@ abstract class MowerRealtimeRepository {
|
||||
Stream<RouteStatusEntity> get routeStatusStream;
|
||||
Stream<HostRealtimeMessageEntity> get hostRealtimeStream;
|
||||
|
||||
/// 按地图使用的设备 SN 订阅感知目标,取消监听时释放该主题引用。
|
||||
Stream<List<MowerObstacleEntity>> watchObstacles(String deviceSn);
|
||||
|
||||
/// 原始任务状态流,由场站共享订阅管理器维护其主题引用。
|
||||
Stream<MowerTaskStatusEntity> watchTaskStatus(String deviceSn);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user