37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
# core/commands/info.py
|
|
from core.connection import BuzzerError
|
|
|
|
def execute(conn) -> dict:
|
|
"""Holt die Systeminformationen und gibt sie als strukturiertes Dictionary zurück."""
|
|
protocol_version = conn.get_protocol_version()
|
|
if protocol_version != 1:
|
|
raise BuzzerError(f"Inkompatibles Protokoll: Gerät nutzt v{protocol_version}, Host erwartet v1.")
|
|
|
|
status_code, app_version = conn.get_firmware_status()
|
|
flash = conn.get_flash_status()
|
|
|
|
f_frsize = flash["block_size"]
|
|
f_blocks = flash["total_blocks"]
|
|
f_bfree = flash["free_blocks"]
|
|
|
|
status_map = {
|
|
1: "CONFIRMED",
|
|
2: "TESTING",
|
|
3: "PENDING",
|
|
}
|
|
image_status = status_map.get(status_code, f"UNKNOWN({status_code})")
|
|
|
|
total_kb = (f_blocks * f_frsize) / 1024
|
|
free_kb = (f_bfree * f_frsize) / 1024
|
|
used_kb = total_kb - free_kb
|
|
percent_used = (used_kb / total_kb) * 100 if total_kb > 0 else 0
|
|
|
|
return {
|
|
"protocol_version": protocol_version,
|
|
"app_version": app_version,
|
|
"total_kb": total_kb,
|
|
"free_kb": free_kb,
|
|
"used_kb": used_kb,
|
|
"percent_used": percent_used,
|
|
"image_status": image_status
|
|
} |