修复代码, 现在可以正常接收平台心跳包并返回设备状态

This commit is contained in:
2025-09-09 16:12:34 +08:00
parent 5d7a745a59
commit d14b18e99a
6 changed files with 342 additions and 280 deletions

View File

@@ -20,12 +20,22 @@ class Config:
config_file (str): 配置文件路径
"""
# 获取项目根目录
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
config_path = os.path.join(project_root, config_file)
self.project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
self.config_file = config_file
self.config_path = os.path.join(self.project_root, config_file)
# 加载配置文件
with open(config_path, 'r', encoding='utf-8') as f:
self._config = yaml.safe_load(f)
self._config = self._load_config()
def _load_config(self):
"""加载配置文件"""
with open(self.config_path, 'r', encoding='utf-8') as f:
return yaml.safe_load(f)
def reload_config(self):
"""重新加载配置文件"""
self._config = self._load_config()
return self._config
@property
def simulation_enabled(self):
@@ -48,14 +58,9 @@ class Config:
return self._config.get('websocket', {})
@property
def websocket_address(self):
"""获取WebSocket服务器地址"""
return self.websocket_config.get('address', '127.0.0.1')
@property
def websocket_port(self):
"""获取WebSocket服务器端口"""
return self.websocket_config.get('port', 8080)
def relay_config(self):
"""获取中继器配置"""
return self._config.get('relay', {})
# 全局配置实例