创建项目及AI生成基本代码
This commit is contained in:
57
internal/protocol/base.py
Normal file
57
internal/protocol/base.py
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
协议处理基类模块
|
||||
"""
|
||||
|
||||
import logging
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
# 配置日志
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ProtocolHandler(ABC):
|
||||
"""协议处理基类"""
|
||||
|
||||
def __init__(self, config):
|
||||
"""
|
||||
初始化协议处理器
|
||||
|
||||
Args:
|
||||
config: 配置对象
|
||||
"""
|
||||
self.config = config
|
||||
self.device_manager = None
|
||||
logger.info(f"初始化 {self.__class__.__name__}")
|
||||
|
||||
@abstractmethod
|
||||
def initialize(self):
|
||||
"""初始化协议处理器"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def send_command(self, command, data):
|
||||
"""
|
||||
发送命令到设备
|
||||
|
||||
Args:
|
||||
command (str): 命令类型
|
||||
data (dict): 命令数据
|
||||
|
||||
Returns:
|
||||
dict: 命令执行结果
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def receive_response(self):
|
||||
"""
|
||||
接收设备响应
|
||||
|
||||
Returns:
|
||||
dict: 设备响应数据
|
||||
"""
|
||||
pass
|
||||
Reference in New Issue
Block a user