You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.6 KiB
47 lines
1.6 KiB
"""
|
|
PLNK服务模块
|
|
"""
|
|
import asyncio
|
|
import time
|
|
import socket
|
|
import serial
|
|
from typing import Optional, Dict, Any
|
|
from app.core.device.manager import device_manager
|
|
from app.schemas.plnk import PLNKRequest, PLNKResponse, TCPConnectionInfo, PLNKConnectionInfo
|
|
from app.utils.log import get_logger
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
class PlnkService:
|
|
"""PLNK服务类"""
|
|
|
|
def __init__(self):
|
|
self.device_manager = device_manager
|
|
|
|
async def get_devices(self):
|
|
"""获取所有PLNK设备"""
|
|
try:
|
|
devices = await self.device_manager.get_all_devices()
|
|
plnk_devices = [d for d in devices if d.protocol_type == "plnk"]
|
|
return plnk_devices
|
|
except Exception as e:
|
|
logger.error(f"获取PLNK设备失败: {e}")
|
|
return []
|
|
|
|
async def execute_command(self, device_id: str, command: str):
|
|
"""在指定设备上执行PLNK命令"""
|
|
try:
|
|
device = await self.device_manager.get_device(device_id)
|
|
if not device:
|
|
raise ValueError(f"设备 {device_id} 不存在")
|
|
|
|
if device.protocol_type != "plnk":
|
|
raise ValueError(f"设备 {device_id} 不是PLNK设备")
|
|
|
|
# 这里应该实现具体的PLNK命令执行逻辑
|
|
logger.info(f"在设备 {device_id} 上执行PLNK命令: {command}")
|
|
return {"success": True, "command": command, "device_id": device_id}
|
|
|
|
except Exception as e:
|
|
logger.error(f"执行PLNK命令失败: {e}")
|
|
return {"success": False, "error": str(e)}
|