54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
"""HTTP REST client for the i.MX 8M Mini target.
|
|
|
|
Talks to the Flask server in `server/app.py`. The target must run that server
|
|
with appropriate privileges to access /sys/kernel/debug, memtool, and i2c-2.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
import requests
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
class TargetController:
|
|
def __init__(self, ip: str, port: int, timeout_s: float = 10.0) -> None:
|
|
self.base_url = f"http://{ip}:{port}"
|
|
self.timeout = timeout_s
|
|
probe = requests.get(f"{self.base_url}/registers", timeout=timeout_s)
|
|
probe.raise_for_status()
|
|
log.info("Target reachable at %s", self.base_url)
|
|
|
|
def _get(self, path: str) -> dict:
|
|
r = requests.get(f"{self.base_url}{path}", timeout=self.timeout)
|
|
r.raise_for_status()
|
|
return r.json()
|
|
|
|
def _put(self, path: str, payload: dict) -> dict:
|
|
r = requests.put(f"{self.base_url}{path}", json=payload, timeout=self.timeout)
|
|
r.raise_for_status()
|
|
return r.json()
|
|
|
|
def get_dsim_registers(self) -> dict:
|
|
return self._get("/registers")
|
|
|
|
def get_sn65_registers(self) -> dict:
|
|
return self._get("/sn65_registers")
|
|
|
|
def get_sn65_settling(self) -> dict:
|
|
return self._get("/sn65_settling")
|
|
|
|
def display_on(self) -> dict:
|
|
return self._put("/display", {"state": "on"})
|
|
|
|
def display_off(self) -> dict:
|
|
return self._put("/display", {"state": "off"})
|
|
|
|
def video_start(self, mode: str = "static-pink") -> dict:
|
|
return self._put("/video", {"action": "start", "mode": mode})
|
|
|
|
def video_stop(self) -> dict:
|
|
return self._put("/video", {"action": "stop"})
|