Files
flutterApp/lib/features/remote_control/presentation/bloc/remote_control_state.dart

222 lines
7.7 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:equatable/equatable.dart';
import 'package:maibu_satabot_v2/features/devices/domain/entities/device_entity.dart';
import 'package:maibu_satabot_v2/features/remote_control/data/models/running_status_model.dart';
import '../../domain/entities/machine_control_status_entity.dart';
import '../../domain/entities/reverse_camera_data.dart';
enum RemoteControlStatus { initial, controlling, error }
/// 本次遥控会话的最后一次用户操作,不代表设备已执行。
enum MowerLastOperation { none, turnOn, turnOff }
enum PermissionRequestPhase {
idle,
checking,
sending,
waiting,
granted,
failed,
timedOut,
}
class RemoteControlState extends Equatable {
final RemoteControlStatus status;
final MachineControlStatusEntity controlEntity; // 控制业务实体
final MowerLastOperation lastMowerOperation;
final String? errorMessage;
final bool hasPermission; // 是否获得 0x12 权限
final PermissionRequestPhase permissionRequestPhase;
final String permissionFeedbackKey;
final int permissionFeedbackId;
bool get isPermissionRequestBusy =>
permissionRequestPhase == PermissionRequestPhase.checking ||
permissionRequestPhase == PermissionRequestPhase.sending ||
permissionRequestPhase == PermissionRequestPhase.waiting;
final bool isEmergency;
final bool hasEmergencyStatus;
/// 本地急停请求状态,不代表已取得设备动作确认。
final bool isEmergencyRequestPending;
final bool emergencyRequestFailed;
final String emergencyFeedbackKey;
final bool isLocked;
final int ping;
final int battery; //电池量
final int voltage; //电压
final String permissionPlatform;
final String currentPlatform;
final bool showPermissionRequestDialog;
final String? requestingDeviceId; // 🔥 请求权限的设备ID
final String? requestingPlatform; // 🔥 请求权限的平台
final bool showLeftPip;
final bool showRightPip;
final bool topRightIsExpanded; // 顶部右侧按钮展开状态
final bool obstacleRecognitionFlag; // 障碍物识别标志位(这是UI显示的)
final String obstacleFlag; //障碍物标志位
final RunningStatusModel runningStatusModel;
final DeviceEntity? targetDevice;
final bool hasReceivedStatusPush; // 是否收到过设备状态推送
// 🔥 倒车影像数据(来自 ReverseCameraSource:现为 Mock,嵌入式就绪后接真实回传)
final ReverseCameraData reverseCamera;
// 🔥 状态更新类型标记 - 用于区分是设备状态更新还是弹窗状态更新
final String? updateType;
const RemoteControlState({
this.status = RemoteControlStatus.initial,
required this.controlEntity,
this.lastMowerOperation = MowerLastOperation.none,
this.errorMessage,
this.hasPermission = false,
this.permissionRequestPhase = PermissionRequestPhase.idle,
this.permissionFeedbackKey = '',
this.permissionFeedbackId = 0,
this.isEmergency = false,
this.hasEmergencyStatus = false,
this.isEmergencyRequestPending = false,
this.emergencyRequestFailed = false,
this.emergencyFeedbackKey = '',
this.isLocked = false,
this.ping = 0,
this.battery = 0,
this.voltage = 0,
this.permissionPlatform = '',
this.currentPlatform = '',
this.showPermissionRequestDialog = false,
this.requestingDeviceId,
this.requestingPlatform,
this.showLeftPip = true,
this.showRightPip = true,
this.obstacleFlag = '',
required this.runningStatusModel,
this.hasReceivedStatusPush = false,
this.topRightIsExpanded = false,
this.obstacleRecognitionFlag = true,
this.targetDevice,
this.updateType,
this.reverseCamera = const ReverseCameraData.idle(),
});
// 便利 UI 更新部分属性
RemoteControlState copyWith({
RemoteControlStatus? status,
MachineControlStatusEntity? controlEntity,
MowerLastOperation? lastMowerOperation,
String? errorMessage,
bool? hasPermission,
PermissionRequestPhase? permissionRequestPhase,
String? permissionFeedbackKey,
int? permissionFeedbackId,
bool? isEmergency,
bool? hasEmergencyStatus,
bool? isEmergencyRequestPending,
bool? emergencyRequestFailed,
String? emergencyFeedbackKey,
bool? isLocked,
int? ping,
int? battery,
int? voltage,
String? permissionPlatform,
String? currentPlatform,
bool? showPermissionRequestDialog,
String? requestingDeviceId,
String? requestingPlatform,
bool? showLeftPip,
bool? showRightPip,
RunningStatusModel? runningStatusModel,
String? obstacleFlag,
bool? hasReceivedStatusPush,
bool? topRightIsExpanded,
bool? obstacleRecognitionFlag,
DeviceEntity? targetDevice,
bool clearTargetDevice = false,
String? updateType,
ReverseCameraData? reverseCamera,
}) {
return RemoteControlState(
status: status ?? this.status,
controlEntity: controlEntity ?? this.controlEntity,
lastMowerOperation: lastMowerOperation ?? this.lastMowerOperation,
errorMessage: errorMessage ?? this.errorMessage,
hasPermission: hasPermission ?? this.hasPermission,
permissionRequestPhase:
permissionRequestPhase ?? this.permissionRequestPhase,
permissionFeedbackKey:
permissionFeedbackKey ?? this.permissionFeedbackKey,
permissionFeedbackId: permissionFeedbackId ?? this.permissionFeedbackId,
isEmergency: isEmergency ?? this.isEmergency,
hasEmergencyStatus: hasEmergencyStatus ?? this.hasEmergencyStatus,
isEmergencyRequestPending:
isEmergencyRequestPending ?? this.isEmergencyRequestPending,
emergencyRequestFailed:
emergencyRequestFailed ?? this.emergencyRequestFailed,
emergencyFeedbackKey: emergencyFeedbackKey ?? this.emergencyFeedbackKey,
isLocked: isLocked ?? this.isLocked,
ping: ping ?? this.ping,
battery: battery ?? this.battery,
voltage: voltage ?? this.voltage,
permissionPlatform: permissionPlatform ?? this.permissionPlatform,
currentPlatform: currentPlatform ?? this.currentPlatform,
showPermissionRequestDialog:
showPermissionRequestDialog ?? this.showPermissionRequestDialog,
requestingDeviceId: requestingDeviceId ?? this.requestingDeviceId,
requestingPlatform: requestingPlatform ?? this.requestingPlatform,
showLeftPip: showLeftPip ?? this.showLeftPip,
showRightPip: showRightPip ?? this.showRightPip,
runningStatusModel: runningStatusModel ?? this.runningStatusModel,
obstacleFlag: obstacleFlag ?? this.obstacleFlag,
hasReceivedStatusPush:
hasReceivedStatusPush ?? this.hasReceivedStatusPush,
topRightIsExpanded: topRightIsExpanded ?? this.topRightIsExpanded,
obstacleRecognitionFlag:
obstacleRecognitionFlag ?? this.obstacleRecognitionFlag,
targetDevice: clearTargetDevice
? null
: targetDevice ?? this.targetDevice,
updateType: updateType, // 不使用 ??,因为我们想要 null 的时候就是 null
reverseCamera: reverseCamera ?? this.reverseCamera,
);
}
@override
List<Object?> get props => [
status,
controlEntity,
lastMowerOperation,
errorMessage,
hasPermission,
permissionRequestPhase,
permissionFeedbackKey,
permissionFeedbackId,
isEmergency,
hasEmergencyStatus,
isEmergencyRequestPending,
emergencyRequestFailed,
emergencyFeedbackKey,
isLocked,
ping,
battery,
voltage,
permissionPlatform,
currentPlatform,
showPermissionRequestDialog,
requestingDeviceId,
requestingPlatform,
showLeftPip,
showRightPip,
runningStatusModel,
obstacleFlag,
hasReceivedStatusPush,
topRightIsExpanded,
obstacleRecognitionFlag,
targetDevice,
updateType,
reverseCamera,
];
}