绑定设备+覆盖模式+控制显示bug+在线更新
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
/// 割草机定位消息实体(MQTT 主题 mower/{sn}/property/location/post,5-10Hz)
|
||||
///
|
||||
/// 报文格式尚未最终确认(第一阶段仅打印),fromLen 对常见字段名做宽容解析,
|
||||
/// 确认后如与实际不符在此调整即可,不影响上层。
|
||||
class MowerLocationEntity extends Equatable {
|
||||
final double? latitude;
|
||||
final double? longitude;
|
||||
final double? altitude;
|
||||
|
||||
/// 航向角
|
||||
final double? heading;
|
||||
|
||||
/// 速度
|
||||
final double? speed;
|
||||
final String? timestamp;
|
||||
|
||||
/// 原始报文,便于解析格式确认后补充字段
|
||||
final Map<String, dynamic> rawData;
|
||||
|
||||
const MowerLocationEntity({
|
||||
this.latitude,
|
||||
this.longitude,
|
||||
this.altitude,
|
||||
this.heading,
|
||||
this.speed,
|
||||
this.timestamp,
|
||||
this.rawData = const {},
|
||||
});
|
||||
|
||||
bool get isValid => latitude != null && longitude != null;
|
||||
|
||||
factory MowerLocationEntity.fromJson(Map<String, dynamic> json) {
|
||||
return MowerLocationEntity(
|
||||
latitude: _toDouble(json['latitude'] ?? json['lat']),
|
||||
longitude: _toDouble(json['longitude'] ?? json['lng'] ?? json['lon']),
|
||||
altitude: _toDouble(json['altitude'] ?? json['height']),
|
||||
heading: _toDouble(json['heading'] ?? json['yaw']),
|
||||
speed: _toDouble(json['speed']),
|
||||
timestamp: json['timestamp']?.toString(),
|
||||
rawData: json,
|
||||
);
|
||||
}
|
||||
|
||||
static double? _toDouble(dynamic value) {
|
||||
if (value == null) return null;
|
||||
if (value is num) return value.toDouble();
|
||||
return double.tryParse(value.toString());
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [latitude, longitude, altitude, heading, speed, timestamp];
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
/// MQTT 路径规划消息实体
|
||||
/// 对应后端 Java DTO: WebRouteStatusMessageDTO
|
||||
/// Topic: device/{deviceId}/route/post
|
||||
class RouteStatusEntity extends Equatable {
|
||||
final List<LatAndLngEntity> data;
|
||||
final String deviceId;
|
||||
final int taskId;
|
||||
final String type;
|
||||
|
||||
const RouteStatusEntity({
|
||||
required this.data,
|
||||
required this.deviceId,
|
||||
required this.taskId,
|
||||
required this.type,
|
||||
});
|
||||
|
||||
factory RouteStatusEntity.fromJson(Map<String, dynamic> json) {
|
||||
final dataList = json['data'] as List<dynamic>? ?? [];
|
||||
return RouteStatusEntity(
|
||||
data: dataList.map((item) => LatAndLngEntity.fromJson(item)).toList(),
|
||||
deviceId: json['deviceId'] as String? ?? '',
|
||||
taskId: (json['taskId'] as num?)?.toInt() ?? 0,
|
||||
type: json['type'] as String? ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [data, deviceId, taskId, type];
|
||||
}
|
||||
|
||||
/// 经纬度坐标实体
|
||||
/// 对应后端 Java DTO: LatAndLngEntity
|
||||
class LatAndLngEntity extends Equatable {
|
||||
final double lat;
|
||||
final double lng;
|
||||
|
||||
const LatAndLngEntity({required this.lat, required this.lng});
|
||||
|
||||
factory LatAndLngEntity.fromJson(Map<String, dynamic> json) {
|
||||
return LatAndLngEntity(
|
||||
lat: (json['lat'] as num?)?.toDouble() ?? 0.0,
|
||||
lng: (json['lng'] as num?)?.toDouble() ?? 0.0,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [lat, lng];
|
||||
}
|
||||
@@ -81,6 +81,21 @@ class MqttConfig extends Equatable {
|
||||
);
|
||||
}
|
||||
|
||||
/// 🔥 割草机机器状态(TCP MQTT)——独立连接,地址 1.95.137.212:59007
|
||||
/// 仅用于 mower/{sn}/property/realtime/post 和 mower/{sn}/property/location/post
|
||||
factory MqttConfig.mowerRealtime() {
|
||||
return const MqttConfig(
|
||||
host: '1.95.137.212',
|
||||
port: 59007,
|
||||
username: 'maibu',
|
||||
password: 'jsmbzn520',
|
||||
protocol: MqttProtocol.tcp,
|
||||
clientId: 'mower_realtime_client',
|
||||
cleanSession: true,
|
||||
reconnectDelayMs: 3000,
|
||||
);
|
||||
}
|
||||
|
||||
MqttConfig copyWith({
|
||||
String? host,
|
||||
int? port,
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'dart:async';
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
|
||||
import '../../../../../core/error/failure.dart';
|
||||
import '../entities/mower_location_entity.dart';
|
||||
import '../entities/real_time_message_entity.dart';
|
||||
import '../entities/route_status_entity.dart';
|
||||
|
||||
abstract class MowerRealtimeRepository {
|
||||
Stream<RealTimeMessageEntity> get vehicleStream;
|
||||
Stream<MowerLocationEntity> get locationStream;
|
||||
Stream<RouteStatusEntity> get routeStatusStream;
|
||||
|
||||
Future<Either<Failure, void>> startListening({
|
||||
required String deviceSn,
|
||||
});
|
||||
|
||||
Future<void> stopListening();
|
||||
}
|
||||
Reference in New Issue
Block a user