完善遥控权限、控制发送和急停反馈
This commit is contained in:
@@ -5,6 +5,8 @@ import 'package:equatable/equatable.dart';
|
||||
/// 报文外层套一层信封,真正数据在 `data` 子对象(由 DataSource 提取后传入)。
|
||||
/// 字段与后端 Java 实体一一对应,采用防御式解析,缺字段用默认值兜底。
|
||||
class HostRealtimeMessageEntity extends Equatable {
|
||||
final String? deviceSn;
|
||||
final DateTime? receivedAt;
|
||||
final double batteryPercentage; // 实时电量百分比
|
||||
final double batteryVoltage; // 实时电压
|
||||
final double leftMotorCurrent; // 实时左电机电流
|
||||
@@ -19,7 +21,7 @@ class HostRealtimeMessageEntity extends Equatable {
|
||||
final double totalWorkDuration; // 累计作业时长
|
||||
final double totalWorkDistance; // 累计作业里程
|
||||
final String motion; // moving|stopped|blocked 运动状态
|
||||
final bool emergencyStop; // 急停状态
|
||||
final bool? emergencyStop; // 急停状态;null 表示未上报或值无效
|
||||
final double leftTargetRpm; // 实时左电机目标转速
|
||||
final double rightTargetRpm; // 实时右电机目标转速
|
||||
final double leftMeasuredRpm; // 实时左电机测量转速
|
||||
@@ -35,6 +37,8 @@ class HostRealtimeMessageEntity extends Equatable {
|
||||
final Map<String, dynamic> rawData;
|
||||
|
||||
const HostRealtimeMessageEntity({
|
||||
this.deviceSn,
|
||||
this.receivedAt,
|
||||
this.batteryPercentage = 0,
|
||||
this.batteryVoltage = 0,
|
||||
this.leftMotorCurrent = 0,
|
||||
@@ -49,7 +53,7 @@ class HostRealtimeMessageEntity extends Equatable {
|
||||
this.totalWorkDuration = 0,
|
||||
this.totalWorkDistance = 0,
|
||||
this.motion = '',
|
||||
this.emergencyStop = false,
|
||||
this.emergencyStop,
|
||||
this.leftTargetRpm = 0,
|
||||
this.rightTargetRpm = 0,
|
||||
this.leftMeasuredRpm = 0,
|
||||
@@ -64,9 +68,16 @@ class HostRealtimeMessageEntity extends Equatable {
|
||||
});
|
||||
|
||||
/// [data] 为报文 `data` 子对象(由 DataSource 提取,与 MowerLocationEntity 一致)
|
||||
factory HostRealtimeMessageEntity.fromJson(Map<String, dynamic> data) {
|
||||
factory HostRealtimeMessageEntity.fromJson(
|
||||
Map<String, dynamic> data, {
|
||||
String? deviceSn,
|
||||
DateTime? receivedAt,
|
||||
}) {
|
||||
return HostRealtimeMessageEntity(
|
||||
batteryPercentage: parseBatteryPercentage(data['battery_percentage']) ?? 0,
|
||||
deviceSn: deviceSn,
|
||||
receivedAt: receivedAt,
|
||||
batteryPercentage:
|
||||
parseBatteryPercentage(data['battery_percentage']) ?? 0,
|
||||
batteryVoltage: _toDouble(data['battery_voltage']),
|
||||
leftMotorCurrent: _toDouble(data['left_motor_current']),
|
||||
rightMotorCurrent: _toDouble(data['right_motor_current']),
|
||||
@@ -115,40 +126,43 @@ class HostRealtimeMessageEntity extends Equatable {
|
||||
return double.tryParse(value.toString()) ?? 0;
|
||||
}
|
||||
|
||||
static bool _toBool(dynamic value) {
|
||||
if (value == null) return false;
|
||||
static bool? _toBool(dynamic value) {
|
||||
if (value is bool) return value;
|
||||
if (value is num) return value != 0;
|
||||
final s = value.toString().toLowerCase();
|
||||
return s == 'true' || s == '1';
|
||||
if (value == 1) return true;
|
||||
if (value == 0) return false;
|
||||
final s = value?.toString().trim().toLowerCase();
|
||||
if (s == 'true' || s == '1') return true;
|
||||
if (s == 'false' || s == '0') return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
@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,
|
||||
linearSpeed,
|
||||
angularSpeed,
|
||||
];
|
||||
batteryPercentage,
|
||||
batteryVoltage,
|
||||
leftMotorCurrent,
|
||||
rightMotorCurrent,
|
||||
leftMotorTemperature,
|
||||
rightMotorTemperature,
|
||||
mainTemperature,
|
||||
yaw,
|
||||
pitch,
|
||||
headingStatus,
|
||||
totalWorkArea,
|
||||
totalWorkDuration,
|
||||
totalWorkDistance,
|
||||
motion,
|
||||
emergencyStop,
|
||||
leftTargetRpm,
|
||||
rightTargetRpm,
|
||||
leftMeasuredRpm,
|
||||
rightMeasuredRpm,
|
||||
leftMotorRpm,
|
||||
rightMotorRpm,
|
||||
roll,
|
||||
controlMode,
|
||||
linearSpeed,
|
||||
angularSpeed,
|
||||
rawData,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class DeviceDataPoint extends Equatable {
|
||||
factory DeviceDataPoint.fromJson(Map<String, dynamic> json) {
|
||||
return DeviceDataPoint(
|
||||
name: json['name'] as String? ?? '',
|
||||
value: json['value'] as String? ?? '',
|
||||
value: json['value']?.toString() ?? '',
|
||||
unit: json['unit'] as String? ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user