From 230a0503fd39369b109cd7cdce7e45d944d8edbf Mon Sep 17 00:00:00 2001 From: root <13910913995@163.com> Date: Tue, 19 Aug 2025 15:37:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E4=BF=AE=E6=94=B9=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app.spec | 4 +- backend/devices/config_api.py | 32 +++++++++++ backend/devices/utils/config_manager.py | 72 ++++++++++++++++++++++++- backend/main.py | 70 +++++++++++++++--------- 4 files changed, 150 insertions(+), 28 deletions(-) diff --git a/backend/app.spec b/backend/app.spec index 9d7bb7fe..3112d45f 100644 --- a/backend/app.spec +++ b/backend/app.spec @@ -14,8 +14,8 @@ a = Analysis( ('dll/femtobolt/bin/ob_usb.dll', 'dll/femtobolt/bin'), # Orbbec USB库 ('dll/femtobolt/bin/live555.dll', 'dll/femtobolt/bin'), # Live555库 ('dll/femtobolt/bin/OrbbecSDKConfig_v1.0.xml', 'dll/femtobolt/bin'), # Orbbec配置文件 ('dll/smitsense/SMiTSenseUsb-F3.0.dll', 'dll/smitsense'), # SMiTSense传感器库 - ('dll/smitsense/Wrapper.dll', 'dll/smitsense'), # Wrapper - ('dll/smitsense/SMiTSenseUsb-F3.0.dll', 'dll/smitsense'), # Wrapper + ('dll/smitsense/SMiTSenseUsb-F3.0.dll', 'dll/smitsense'), # SMiTSenseUsb库 + ('dll/smitsense/Wrapper.dll', 'dll/smitsense'), # SMiTSense传感器库包装类 ], hiddenimports=[ 'flask', diff --git a/backend/devices/config_api.py b/backend/devices/config_api.py index 9215b88b..6fb334c4 100644 --- a/backend/devices/config_api.py +++ b/backend/devices/config_api.py @@ -179,6 +179,38 @@ class ConfigAPI: 'message': f'设置FemtoBolt配置失败: {str(e)}' }), 500 + # 批量设置所有设备配置 + @self.app.route('/api/config/devices/all', methods=['POST']) + def set_all_device_configs(): + """批量设置所有设备配置""" + try: + data = request.get_json() + if not data: + return jsonify({ + 'success': False, + 'message': '请求数据不能为空' + }), 400 + + # 验证数据格式 + supported_devices = ['imu', 'pressure', 'camera', 'femtobolt'] + for device_name in data.keys(): + if device_name not in supported_devices: + return jsonify({ + 'success': False, + 'message': f'不支持的设备类型: {device_name},支持的设备类型: {", ".join(supported_devices)}' + }), 400 + + result = self.config_manager.set_all_device_configs(data) + status_code = 200 if result['success'] else 400 + return jsonify(result), status_code + + except Exception as e: + self.logger.error(f"批量设置设备配置失败: {e}") + return jsonify({ + 'success': False, + 'message': f'批量设置设备配置失败: {str(e)}' + }), 500 + # 重新加载配置 @self.app.route('/api/config/reload', methods=['POST']) def reload_config(): diff --git a/backend/devices/utils/config_manager.py b/backend/devices/utils/config_manager.py index fef59656..84f5ea69 100644 --- a/backend/devices/utils/config_manager.py +++ b/backend/devices/utils/config_manager.py @@ -528,4 +528,74 @@ class ConfigManager: 'pressure': self.get_device_config('pressure'), 'camera': self.get_device_config('camera'), 'femtobolt': self.get_device_config('femtobolt') - } \ No newline at end of file + } + + def set_all_device_configs(self, configs: Dict[str, Dict[str, Any]]) -> Dict[str, Any]: + """ + 批量设置所有设备配置 + + Args: + configs: 所有设备配置数据 + { + 'imu': {'device_type': 'real', 'port': 'COM7', 'baudrate': 9600}, + 'pressure': {'device_type': 'real', 'port': 'COM8', 'baudrate': 115200}, + 'camera': {'device_index': 0, 'width': 1280, 'height': 720, 'fps': 30}, + 'femtobolt': {'color_resolution': '1080P', 'depth_mode': 'NFOV_UNBINNED', 'fps': 15} + } + + Returns: + Dict[str, Any]: 设置结果 + """ + try: + results = {} + errors = [] + + # 逐个设置每个设备的配置 + if 'imu' in configs: + result = self.set_imu_config(configs['imu']) + results['imu'] = result + if not result['success']: + errors.append(f"IMU: {result['message']}") + + if 'pressure' in configs: + result = self.set_pressure_config(configs['pressure']) + results['pressure'] = result + if not result['success']: + errors.append(f"压力板: {result['message']}") + + if 'camera' in configs: + result = self.set_camera_config(configs['camera']) + results['camera'] = result + if not result['success']: + errors.append(f"相机: {result['message']}") + + if 'femtobolt' in configs: + result = self.set_femtobolt_config(configs['femtobolt']) + results['femtobolt'] = result + if not result['success']: + errors.append(f"FemtoBolt: {result['message']}") + + # 如果有错误,返回部分成功的结果 + if errors: + self.logger.warning(f"部分设备配置设置失败: {'; '.join(errors)}") + return { + 'success': False, + 'message': f'部分设备配置设置失败: {"; ".join(errors)}', + 'results': results, + 'updated_configs': self.get_all_device_configs() + } + else: + self.logger.info("所有设备配置设置成功") + return { + 'success': True, + 'message': '所有设备配置设置成功', + 'results': results, + 'updated_configs': self.get_all_device_configs() + } + + except Exception as e: + self.logger.error(f"批量设置设备配置失败: {e}") + return { + 'success': False, + 'message': f'批量设置设备配置失败: {str(e)}' + } \ No newline at end of file diff --git a/backend/main.py b/backend/main.py index 8f7a4155..48e355fb 100644 --- a/backend/main.py +++ b/backend/main.py @@ -205,9 +205,9 @@ class AppServer: self.logger.info('正在初始化设备管理器...') self.device_managers = { 'camera': CameraManager(self.socketio, self.config_manager), - # 'femtobolt': FemtoBoltManager(self.socketio, self.config_manager), - # 'imu': IMUManager(self.socketio, self.config_manager), - # 'pressure': PressureManager(self.socketio, self.config_manager) + 'femtobolt': FemtoBoltManager(self.socketio, self.config_manager), + 'imu': IMUManager(self.socketio, self.config_manager), + 'pressure': PressureManager(self.socketio, self.config_manager) } # 为每个设备添加状态变化回调 @@ -223,9 +223,9 @@ class AppServer: self.logger.info('设备协调器初始化完成') # 启动Flask应用 - host = app_config.get('host', self.host) - port = app_config.get('port', self.port) - debug = app_config.get('debug', self.debug) + host = self.host + port = self.port + debug = self.debug self.logger.info(f'启动Flask应用 - Host: {host}, Port: {port}, Debug: {debug}') @@ -559,15 +559,25 @@ class AppServer: if not data.get(field): return jsonify({'success': False, 'error': f'{field}不能为空'}), 400 - patient_id = self.db_manager.create_patient( - name=data['name'], - gender=data['gender'], - age=data['age'], - height=data.get('height'), - weight=data.get('weight'), - medical_history=data.get('medical_history', ''), - notes=data.get('notes', '') - ) + patient_data = { + 'name': data['name'], + 'gender': data['gender'], + 'age': data['age'], + 'birth_date': data.get('birth_date'), + 'nationality': data.get('nationality'), + 'residence': data.get('residence'), + 'height': data.get('height'), + 'weight': data.get('weight'), + 'shoe_size': data.get('shoe_size'), + 'phone': data.get('phone'), + 'email': data.get('email'), + 'occupation': data.get('occupation'), + 'workplace': data.get('workplace'), + 'medical_history': data.get('medical_history', ''), + 'notes': data.get('notes', '') + } + + patient_id = self.db_manager.create_patient(patient_data) if patient_id: return jsonify({ @@ -603,16 +613,26 @@ class AppServer: try: data = flask_request.get_json() - result = self.db_manager.update_patient( - patient_id=patient_id, - name=data.get('name'), - gender=data.get('gender'), - age=data.get('age'), - height=data.get('height'), - weight=data.get('weight'), - medical_history=data.get('medical_history'), - notes=data.get('notes') - ) + patient_data = { + 'name': data.get('name'), + 'gender': data.get('gender'), + 'age': data.get('age'), + 'birth_date': data.get('birth_date'), + 'nationality': data.get('nationality'), + 'residence': data.get('residence'), + 'height': data.get('height'), + 'weight': data.get('weight'), + 'shoe_size': data.get('shoe_size'), + 'phone': data.get('phone'), + 'email': data.get('email'), + 'occupation': data.get('occupation'), + 'workplace': data.get('workplace'), + 'medical_history': data.get('medical_history'), + 'notes': data.get('notes') + } + + self.db_manager.update_patient(patient_id, patient_data) + result = True if result: return jsonify({'success': True, 'message': '患者信息更新成功'})