From 36c399c00967effce9aca5b90fbc5b413cf33fcf Mon Sep 17 00:00:00 2001 From: root <13910913995@163.com> Date: Fri, 9 Jan 2026 14:51:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/config.ini | 12 ++--- backend/devices/device_coordinator.py | 4 +- backend/devices/utils/config_manager.py | 52 ++++++++++++++++--- frontend/src/renderer/src/views/Detection.vue | 5 ++ 4 files changed, 58 insertions(+), 15 deletions(-) diff --git a/backend/config.ini b/backend/config.ini index df117eef..e2355d0f 100644 --- a/backend/config.ini +++ b/backend/config.ini @@ -19,7 +19,7 @@ max_backups = 7 path = D:/BodyCheck/file/ [CAMERA1] -enabled = True +enabled = False device_index = 0 width = 1280 height = 720 @@ -29,7 +29,7 @@ fourcc = MJPG backend = directshow [CAMERA2] -enabled = True +enabled = False device_index = 3 width = 1280 height = 720 @@ -39,7 +39,7 @@ fourcc = MJPG backend = directshow [FEMTOBOLT] -enabled = True +enabled = False algorithm_type = plt color_resolution = 1080P depth_mode = NFOV_2X2BINNED @@ -50,22 +50,22 @@ fps = 15 synchronized_images_only = False [DEVICES] -imu_enabled = True +imu_enabled = False imu_device_type = ble imu_port = COM9 imu_mac_address = ef:3c:1a:0a:fe:02 imu_baudrate = 9600 -pressure_enabled = True +pressure_enabled = False pressure_device_type = real pressure_use_mock = False pressure_port = COM5 pressure_baudrate = 115200 [REMOTE] +enable = False port = COM6 baudrate = 115200 timeout = 0.1 -enable = True strict_crc = False [SYSTEM] diff --git a/backend/devices/device_coordinator.py b/backend/devices/device_coordinator.py index 1e6760b9..5eb4f852 100644 --- a/backend/devices/device_coordinator.py +++ b/backend/devices/device_coordinator.py @@ -165,9 +165,9 @@ class DeviceCoordinator: # 普通相机:初始化两个实例(camera1 与 camera2) # camera1 使用 [CAMERA1] 配置;camera2 使用 [CAMERA2](若不存在则回退为 device_index+1) - if self.device_configs.get('camera1', {}).get('enabled', True): + if self.device_configs.get('camera1', {}).get('enabled', False): futures.append(('camera1', self.executor.submit(self._init_camera_by_name, 'camera1', 'CAMERA1'))) - if self.device_configs.get('camera2', {}).get('enabled', True): + if self.device_configs.get('camera2', {}).get('enabled', False): futures.append(('camera2', self.executor.submit(self._init_camera_by_name, 'camera2', 'CAMERA2'))) # IMU传感器 diff --git a/backend/devices/utils/config_manager.py b/backend/devices/utils/config_manager.py index c5895d89..d152e93a 100644 --- a/backend/devices/utils/config_manager.py +++ b/backend/devices/utils/config_manager.py @@ -163,6 +163,8 @@ class ConfigManager: config = self._get_imu_config() elif device_name == 'pressure': config = self._get_pressure_config() + elif device_name == 'remote': + config = self._get_remote_config() else: self.logger.warning(f"未知设备类型: {device_name}") @@ -255,6 +257,21 @@ class ConfigManager: 'calibration_samples': self.config.getint('DEVICES', 'pressure_calibration_samples', fallback=50) } + def _get_remote_config(self) -> Dict[str, Any]: + """ + 获取远程控制配置 + + Returns: + Dict[str, Any]: 远程控制配置 + """ + return { + 'enabled': self.config.getboolean('REMOTE', 'enable', fallback=True), + 'port': self.config.get('REMOTE', 'port', fallback='COM6'), + 'baudrate': self.config.getint('REMOTE', 'baudrate', fallback=115200), + 'timeout': self.config.getfloat('REMOTE', 'timeout', fallback=0.1), + 'strict_crc': self.config.getboolean('REMOTE', 'strict_crc', fallback=False) + } + def get_system_config(self) -> Dict[str, Any]: """ 获取系统配置 @@ -614,13 +631,7 @@ class ConfigManager: 'camera1': self.get_device_config('camera1'), 'camera2': self.get_device_config('camera2'), 'femtobolt': self.get_device_config('femtobolt'), - 'remote': { - 'enabled': self.config.getboolean('DEVICES', 'remote_enabled', fallback=True), - 'port': self.config.get('REMOTE', 'port', fallback='COM6'), - 'baudrate': self.config.getint('REMOTE', 'baudrate', fallback=115200), - 'timeout': self.config.getfloat('REMOTE', 'timeout', fallback=0.1), - 'strict_crc': self.config.getboolean('REMOTE', 'strict_crc', fallback=False) - } + 'remote': self.get_device_config('remote') } def _batch_update_device_configs(self, configs: Dict[str, Dict[str, Any]]) -> Dict[str, Any]: @@ -787,6 +798,33 @@ class ConfigManager: errors.append(f"FemtoBolt: {error_msg}") self.logger.error(error_msg) + # Remote配置 + if 'remote' in configs: + try: + config_data = configs['remote'] + if 'enabled' in config_data: + self.set_config_value('REMOTE', 'enable', str(config_data['enabled'])) + if 'port' in config_data: + self.set_config_value('REMOTE', 'port', config_data['port']) + if 'baudrate' in config_data: + self.set_config_value('REMOTE', 'baudrate', str(config_data['baudrate'])) + if 'timeout' in config_data: + self.set_config_value('REMOTE', 'timeout', str(config_data['timeout'])) + if 'strict_crc' in config_data: + self.set_config_value('REMOTE', 'strict_crc', str(config_data['strict_crc'])) + + results['remote'] = { + 'success': True, + 'message': '遥控器配置更新成功', + 'config': config_data + } + self.logger.info(f"遥控器配置已更新: {config_data}") + except Exception as e: + error_msg = f'设置遥控器配置失败: {str(e)}' + results['remote'] = {'success': False, 'message': error_msg} + errors.append(f"Remote: {error_msg}") + self.logger.error(error_msg) + # 一次性保存所有配置 if results: # 只有在有配置更新时才保存 self.save_config() diff --git a/frontend/src/renderer/src/views/Detection.vue b/frontend/src/renderer/src/views/Detection.vue index 2bc5380f..5d77171d 100644 --- a/frontend/src/renderer/src/views/Detection.vue +++ b/frontend/src/renderer/src/views/Detection.vue @@ -752,6 +752,7 @@ const cameraStatus = computed(() => (camera1Status.value === '已连接' || came const femtoboltStatus = ref('未连接') // 深度相机(FemtoBolt)设备状态 const imuStatus = ref('未连接') // IMU设备状态 const pressureStatus = ref('未连接') // 压力传感器设备状态 +const remoteStatus = ref('未连接') // 遥控器设备状态 // 为了向后兼容,保留videoStatus但映射到cameraStatus const videoStatus = computed(() => cameraStatus.value) @@ -1141,6 +1142,10 @@ function connectWebSocket() { pressureStatus.value = statusText console.log(`⚖️ 压力传感器状态: ${statusText}`) break + case 'remote': + remoteStatus.value = statusText + console.log(`📡 遥控器状态: ${statusText}`) + break default: console.warn('⚠️ 未知设备类型:', device_type) }