47 lines
2.3 KiB
Python
47 lines
2.3 KiB
Python
"""Firmware-qualified commands, separate from desired configuration/profile writes."""
|
||
|
||
from k1link.device_plugins.arnavi_b2.usb_protocol import decode_configuration
|
||
|
||
from .independent_equipment import Document, EquipmentError, EquipmentStore
|
||
|
||
KINDS = {"request-position", "pulse-output", "set-output", "restart"}
|
||
|
||
|
||
def plan(equipment: EquipmentStore, row: Document, command: Document) -> Document:
|
||
if row["model_id"] != "arnavi-b2" or row["observed"]["firmware"] != "0.01":
|
||
raise EquipmentError("Команды для этой версии устройства не проверены.")
|
||
kind = command.get("kind")
|
||
if kind not in KINDS:
|
||
raise EquipmentError("Эта команда не поддерживается.")
|
||
config = decode_configuration(
|
||
(equipment.root / "evidence" / row["evidence_id"] / "configuration.bin").read_bytes()
|
||
)
|
||
allowed = {"kind"}
|
||
if kind in ("pulse-output", "set-output"):
|
||
allowed |= {"pin", "seconds" if kind == "pulse-output" else "enabled"}
|
||
pin = command.get("pin")
|
||
if type(pin) is not int or pin not in (4, 5, 6):
|
||
raise EquipmentError("Выберите выход PIN4–PIN6.")
|
||
seconds = command.get("seconds")
|
||
if kind == "pulse-output" and (type(seconds) is not int or not 1 <= seconds <= 5):
|
||
raise EquipmentError("Длительность импульса — от 1 до 5 секунд.")
|
||
if kind == "set-output" and type(command.get("enabled")) is not bool:
|
||
raise EquipmentError("Укажите включение или выключение выхода.")
|
||
if config.integer(16 + pin, 1) != 1:
|
||
raise EquipmentError("У выбранного выхода не подтверждён ручной режим управления.")
|
||
if set(command) != allowed:
|
||
raise EquipmentError("Некорректные параметры команды.")
|
||
private = (
|
||
{}
|
||
if kind in ("request-position", "restart")
|
||
else {"encoding": "text", "password": config.text(5)}
|
||
)
|
||
return {
|
||
**command,
|
||
**private,
|
||
"imei": row["identity_key"],
|
||
"model": 231,
|
||
"firmware": "0.01",
|
||
"secondary": {"host": config.text(3), "port": config.integer(4, 2)},
|
||
}
|