feat:初始化工程

This commit is contained in:
2025-10-23 23:09:48 +08:00
commit 9117c3ac1e
10 changed files with 366 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
from config.logger_config import logger
from model.index import UNKNOWN_MESSAGE
from parser.test_parser import TestParser
class TcpMessageProcessor:
"""消息处理器,负责将消息路由到正确的设备解析器"""
def __init__(self):
# 注册所有支持的设备解析器
self.parsers = [TestParser()]
def process(self, message):
"""处理消息,返回响应"""
# 尝试找到能处理该消息的解析器
for parser in self.parsers:
if parser.check(message):
parsed_data = parser.parse(message)
if parsed_data:
logger.info(f"处理{parser.name}消息: {message}")
return parser.response(parsed_data)
# 没有找到合适的解析器
logger.warning(f"未识别的消息格式: {message}")
return UNKNOWN_MESSAGE