完善遥控权限、控制发送和急停反馈
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import 'dart:async';
|
||||
import 'package:maibu_satabot_v2/features/device_control_mode/domain/entities/device_control_mode.dart';
|
||||
import 'package:maibu_satabot_v2/features/device_control_mode/presentation/widgets/control_mode_entry_gate.dart';
|
||||
import 'package:maibu_satabot_v2/features/device_control_mode/presentation/widgets/mode_independent_control.dart';
|
||||
import 'dart:io';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../remote_control/presentation/widgets/emergency_stop_confirmation.dart';
|
||||
import '../../../remote_control/presentation/widgets/emergency_stop_button.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
@@ -12,13 +15,14 @@ import 'package:path_provider/path_provider.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/core/consts/tcp_consts.dart';
|
||||
import 'package:maibu_satabot_v2/core/env/env_config.dart';
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
import 'package:maibu_satabot_v2/features/auth/presentation/bloc/auth_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/device_status_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/device_status_state.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/presentation/bloc/remote_control_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/presentation/widgets/remote_control_link_feedback.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/presentation/bloc/remote_control_state.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/local_camera/presentation/cubit/local_camera_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/usb_camera/data/uvc_camera_service.dart';
|
||||
@@ -75,7 +79,6 @@ class _PvControlPageState extends State<PvControlPage> {
|
||||
final GlobalKey _videoKey = GlobalKey();
|
||||
|
||||
/// 本批次使用 Mock 遥测数据
|
||||
final PvTelemetry _telemetry = const PvTelemetry();
|
||||
|
||||
/// 遥控指令传输通道:当前为 TCP 实现(委托 `RemoteControlCubit`),
|
||||
/// 以后接蓝牙 / 下位机只换一个实现类,HUD 与本页面代码零改动。
|
||||
@@ -89,13 +92,11 @@ class _PvControlPageState extends State<PvControlPage> {
|
||||
/// 尾部那次 stopControlLoop() 会把刚起来的循环又关掉,HUD 就变成
|
||||
/// “摇杆推了没反应”。故延后到 deactivate 收尾再起循环。
|
||||
bool _deactivating = false;
|
||||
bool _emergencyConfirming = false;
|
||||
|
||||
/// deactivate 期间收到过重新进入控制态的请求。
|
||||
bool _restartAfterDeactivate = false;
|
||||
|
||||
/// 急停开关态:HUD 急停钮每点一次翻转,经通道下发 updateEmergency。
|
||||
bool _emergencyOn = false;
|
||||
|
||||
/// 远程控制单例(HUD 与原远程遥控页共用它,指令通道内部也委托它)。
|
||||
RemoteControlCubit get _cubit => sl<RemoteControlCubit>();
|
||||
|
||||
@@ -147,41 +148,12 @@ class _PvControlPageState extends State<PvControlPage> {
|
||||
: AppLocalizations.of(context).translate('pv_control.no_device');
|
||||
}
|
||||
|
||||
/// 实际下发的遥测:真实字段来自全局 [DeviceStatusBloc] 的 host 实时数据
|
||||
/// (电量/巡检里程/设备温度),未收到时置 null 由 UI 显示"未知";
|
||||
/// 开启「模拟障碍物信息」相当于收到机器告警推送,叠加 obstacleAlert。
|
||||
/// 使用当前设备的实时快照;未上报的字段由 UI 显示未知。
|
||||
PvTelemetry _resolveTelemetry(DeviceStatusState dsState, String deviceName) {
|
||||
double? battery;
|
||||
double? mileage;
|
||||
double? temp;
|
||||
int? fixStatus;
|
||||
int? satelliteCount;
|
||||
String? controlMode;
|
||||
if (dsState is DeviceStatusUpdated) {
|
||||
final s = dsState.status;
|
||||
// 定位质量:来自 location/post 的 fix_status(qual)
|
||||
fixStatus = s.qual;
|
||||
// 控制模式:与“设备数据监控”同一口径,只要收到状态就跟随,不加 host 门控
|
||||
controlMode = s.controlMode;
|
||||
// 卫星数:realtime/post 尚未推送,无数据源时保持 null 显示"未知"
|
||||
if (s.satelliteCnt > 0) satelliteCount = s.satelliteCnt;
|
||||
// 以下三项来自 host 实时话题(device/{sn}/host/realTime/message)
|
||||
if (s.hostDataReceived) {
|
||||
battery = double.tryParse(s.battery);
|
||||
mileage = s.totalWorkDistance;
|
||||
temp = s.chipTemp;
|
||||
}
|
||||
}
|
||||
return _telemetry.copyWith(
|
||||
// 设备名用真实选中的设备,不再用 PvTelemetry 里写死的占位名
|
||||
return PvTelemetry.fromRunningStatus(
|
||||
dsState is DeviceStatusUpdated ? dsState.status : null,
|
||||
deviceName: deviceName,
|
||||
obstacleAlert: _simObstacle,
|
||||
battery: battery,
|
||||
mileage: mileage,
|
||||
temperature: temp,
|
||||
fixStatus: fixStatus,
|
||||
satelliteCount: satelliteCount,
|
||||
controlMode: controlMode,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -230,7 +202,7 @@ class _PvControlPageState extends State<PvControlPage> {
|
||||
if (widget.deviceId.isNotEmpty && token != null) {
|
||||
setState(() {
|
||||
_streamUrl =
|
||||
'webrtc://${TCPConsts.TCP_IP}/live/livestream/${widget.deviceId}?token=$token';
|
||||
'webrtc://${EnvConfig.webRtcStreamAuthority}/live/livestream/${widget.deviceId}?token=$token';
|
||||
});
|
||||
} else {
|
||||
debugPrint('❌ [PvControl] 视频URL初始化失败:deviceId 或 token 为空');
|
||||
@@ -310,15 +282,43 @@ class _PvControlPageState extends State<PvControlPage> {
|
||||
);
|
||||
}
|
||||
|
||||
void _onEmergencyStop() {
|
||||
// HUD 急停钮为“点一下急停 / 再点一下恢复”的切换态(按钮自身不携带 on/off)。
|
||||
_emergencyOn = !_emergencyOn;
|
||||
_channel.sendEmergencyStop(_emergencyOn);
|
||||
Future<void> _onEmergencyStop() async {
|
||||
if (_emergencyConfirming || _cubit.state.isEmergencyRequestPending) return;
|
||||
final sn = _cubit.state.targetDevice?.deviceName;
|
||||
final on = !_cubit.state.isEmergency;
|
||||
if (!_cubit.checkEmergencyRequest(on)) {
|
||||
CapsuleToast.show(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('remote_control.${_cubit.state.emergencyFeedbackKey}'),
|
||||
showCheck: false,
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!_cubit.checkEmergencyRequest(on)) {
|
||||
CapsuleToast.show(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('remote_control.${_cubit.state.emergencyFeedbackKey}'),
|
||||
showCheck: false,
|
||||
);
|
||||
return;
|
||||
}
|
||||
_emergencyConfirming = true;
|
||||
bool confirmed;
|
||||
try {
|
||||
confirmed = await confirmEmergencyStop(context, engage: on, sn: sn ?? '');
|
||||
} finally {
|
||||
_emergencyConfirming = false;
|
||||
}
|
||||
if (!confirmed || !mounted || sn != _cubit.state.targetDevice?.deviceName) {
|
||||
return;
|
||||
}
|
||||
await _channel.sendEmergencyStop(on);
|
||||
if (!mounted || sn != _cubit.state.targetDevice?.deviceName) return;
|
||||
final tr = AppLocalizations.of(context);
|
||||
CapsuleToast.show(
|
||||
_emergencyOn
|
||||
? tr.translate('pv_control.toast_emergency_sent')
|
||||
: tr.translate('pv_control.toast_emergency_released'),
|
||||
tr.translate('remote_control.${_cubit.state.emergencyFeedbackKey}'),
|
||||
showCheck: false,
|
||||
);
|
||||
}
|
||||
@@ -338,8 +338,7 @@ class _PvControlPageState extends State<PvControlPage> {
|
||||
return;
|
||||
}
|
||||
_controlActive = true;
|
||||
// deactivate 会清除急停态,重新进入从“未急停”开始,与通道保持同步。
|
||||
_emergencyOn = false;
|
||||
// 急停由共享 Cubit 保持,重新进入页面不自动解除。
|
||||
_channel.activate();
|
||||
}
|
||||
|
||||
@@ -679,6 +678,7 @@ class _PvControlPageState extends State<PvControlPage> {
|
||||
deviceName: widget.deviceName,
|
||||
target: ControlModeTarget.remote,
|
||||
cancelToPreview: true,
|
||||
emergencyStopControl: const EmergencyStopButton(),
|
||||
onReady: _startControl,
|
||||
child: _buildPage(context),
|
||||
);
|
||||
@@ -863,15 +863,20 @@ class _PvTopNav extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: onSettings,
|
||||
visualDensity: VisualDensity.compact,
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(minWidth: 32, minHeight: 32),
|
||||
icon: const Icon(
|
||||
Icons.settings,
|
||||
color: PvColors.textSecondary,
|
||||
size: 20,
|
||||
RemoteControlHeartbeatIndicator(
|
||||
heartbeats: sl<RemoteControlCubit>().serverHeartbeats,
|
||||
),
|
||||
ModeIndependentControl(
|
||||
child: IconButton(
|
||||
onPressed: onSettings,
|
||||
visualDensity: VisualDensity.compact,
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(minWidth: 32, minHeight: 32),
|
||||
icon: const Icon(
|
||||
Icons.settings,
|
||||
color: PvColors.textSecondary,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
|
||||
Reference in New Issue
Block a user