USB 摄像头+远程遥控+中英的适配+topic的集成和状态的使用到相应页面

This commit is contained in:
2026-10-20 17:03:37 +08:00
parent 178cd2533c
commit 582242e9aa
144 changed files with 15759 additions and 406 deletions

View File

@@ -0,0 +1,132 @@
import 'package:equatable/equatable.dart';
/// 主机实时状态消息(MQTT 主题 device/{sn}/host/realTime/message)
///
/// 报文外层套一层信封,真正数据在 `data` 子对象(由 DataSource 提取后传入)。
/// 字段与后端 Java 实体一一对应,采用防御式解析,缺字段用默认值兜底。
class HostRealtimeMessageEntity extends Equatable {
final double batteryPercentage; // 实时电量百分比
final double batteryVoltage; // 实时电压
final double leftMotorCurrent; // 实时左电机电流
final double rightMotorCurrent; // 实时右电机电流
final double leftMotorTemperature; // 实时左电机温度
final double rightMotorTemperature; // 实时右电机温度
final double mainTemperature; // 实时主温度
final double yaw; // 实时航向角度
final double pitch; // 实时俯仰角度
final String headingStatus; // 实时航向状态
final double totalWorkArea; // 累计作业面积
final double totalWorkDuration; // 累计作业时长
final double totalWorkDistance; // 累计作业里程
final String motion; // moving|stopped|blocked 运动状态
final bool emergencyStop; // 急停状态
final double leftTargetRpm; // 实时左电机目标转速
final double rightTargetRpm; // 实时右电机目标转速
final double leftMeasuredRpm; // 实时左电机测量转速
final double rightMeasuredRpm; // 实时右电机测量转速
final double leftMotorRpm; // 实时左电机转速
final double rightMotorRpm; // 实时右电机转速
final double roll; // 实时翻滚角度
final String controlMode; // 当前控制模式(遥控器拨杆对应)
/// 原始 data 报文,便于后端补字段时兜底
final Map<String, dynamic> rawData;
const HostRealtimeMessageEntity({
this.batteryPercentage = 0,
this.batteryVoltage = 0,
this.leftMotorCurrent = 0,
this.rightMotorCurrent = 0,
this.leftMotorTemperature = 0,
this.rightMotorTemperature = 0,
this.mainTemperature = 0,
this.yaw = 0,
this.pitch = 0,
this.headingStatus = '',
this.totalWorkArea = 0,
this.totalWorkDuration = 0,
this.totalWorkDistance = 0,
this.motion = '',
this.emergencyStop = false,
this.leftTargetRpm = 0,
this.rightTargetRpm = 0,
this.leftMeasuredRpm = 0,
this.rightMeasuredRpm = 0,
this.leftMotorRpm = 0,
this.rightMotorRpm = 0,
this.roll = 0,
this.controlMode = '',
this.rawData = const {},
});
/// [data] 为报文 `data` 子对象(由 DataSource 提取,与 MowerLocationEntity 一致)
factory HostRealtimeMessageEntity.fromJson(Map<String, dynamic> data) {
return HostRealtimeMessageEntity(
batteryPercentage: _toDouble(data['battery_percentage']),
batteryVoltage: _toDouble(data['battery_voltage']),
leftMotorCurrent: _toDouble(data['left_motor_current']),
rightMotorCurrent: _toDouble(data['right_motor_current']),
leftMotorTemperature: _toDouble(data['left_motor_temperature']),
rightMotorTemperature: _toDouble(data['right_motor_temperature']),
mainTemperature: _toDouble(data['main_temperature']),
yaw: _toDouble(data['yaw']),
pitch: _toDouble(data['pitch']),
headingStatus: data['heading_status']?.toString() ?? '',
totalWorkArea: _toDouble(data['total_work_area']),
totalWorkDuration: _toDouble(data['total_work_duration']),
totalWorkDistance: _toDouble(data['total_work_distance']),
motion: data['motion']?.toString() ?? '',
emergencyStop: _toBool(data['emergency_stop']),
leftTargetRpm: _toDouble(data['left_target_rpm']),
rightTargetRpm: _toDouble(data['right_target_rpm']),
leftMeasuredRpm: _toDouble(data['left_measured_rpm']),
rightMeasuredRpm: _toDouble(data['right_measured_rpm']),
leftMotorRpm: _toDouble(data['left_motor_rpm']),
rightMotorRpm: _toDouble(data['right_motor_rpm']),
roll: _toDouble(data['roll']),
controlMode: data['control_mode']?.toString() ?? '',
rawData: data,
);
}
static double _toDouble(dynamic value) {
if (value == null) return 0;
if (value is num) return value.toDouble();
return double.tryParse(value.toString()) ?? 0;
}
static bool _toBool(dynamic value) {
if (value == null) return false;
if (value is bool) return value;
if (value is num) return value != 0;
final s = value.toString().toLowerCase();
return s == 'true' || s == '1';
}
@override
List<Object?> get props => [
batteryPercentage,
batteryVoltage,
leftMotorCurrent,
rightMotorCurrent,
leftMotorTemperature,
rightMotorTemperature,
mainTemperature,
yaw,
pitch,
headingStatus,
totalWorkArea,
totalWorkDuration,
totalWorkDistance,
motion,
emergencyStop,
leftTargetRpm,
rightTargetRpm,
leftMeasuredRpm,
rightMeasuredRpm,
leftMotorRpm,
rightMotorRpm,
roll,
controlMode,
];
}

View File

@@ -5,11 +5,13 @@ import '../../../../../core/error/failure.dart';
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';
abstract class MowerRealtimeRepository {
Stream<RealTimeMessageEntity> get vehicleStream;
Stream<MowerLocationEntity> get locationStream;
Stream<RouteStatusEntity> get routeStatusStream;
Stream<HostRealtimeMessageEntity> get hostRealtimeStream;
Future<Either<Failure, void>> startListening({
required String deviceSn,