feat: atxpi — server power & console manager (core, CLI, deploy)
- core/hardware: драйверы real (atxctl/pyserial) + mock, ATXPI_DRIVER - core/power, console, mock: операции питания и RS232-консоли - cli/atxpi: status/on/off/reset/cycle/console (stdlib, без deps) - install.sh: one-shot curl|bash, идемпотентный, хост-агностичный - deploy: systemd-юнит, шаблон env, update.sh - README, AGENTS.md: документация и проектные решения - AGENTS.md и доки очищены от внутренних хостов/адресов (публичный репо)
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
"""Высокоуровневые операции RS232-консоли."""
|
||||
from .hardware import make_console
|
||||
|
||||
|
||||
def send(text: str) -> dict:
|
||||
c = make_console()
|
||||
c.open()
|
||||
try:
|
||||
c.send(text.encode("utf-8", errors="replace"))
|
||||
return {"sent": text, "bytes": len(text.encode("utf-8", errors="replace"))}
|
||||
finally:
|
||||
c.close()
|
||||
|
||||
|
||||
def read_bytes(timeout: float = 0.8) -> dict:
|
||||
c = make_console()
|
||||
c.open()
|
||||
try:
|
||||
data = c.read(timeout)
|
||||
return {"bytes": len(data), "text": data.decode("utf-8", errors="replace")}
|
||||
finally:
|
||||
c.close()
|
||||
|
||||
|
||||
def interact() -> dict:
|
||||
"""Мини-интерактив: отправить строку и вернуть эхо/ответ."""
|
||||
|
||||
try:
|
||||
import sys
|
||||
return {"hint": "используйте `send` и `read_bytes` для скриптового интерактива"}
|
||||
except Exception as e: # pragma: no cover
|
||||
return {"error": str(e)}
|
||||
Reference in New Issue
Block a user