Stand vor Protokollumbau
This commit is contained in:
@@ -3,7 +3,7 @@ import argparse
|
||||
import sys
|
||||
from core.config import load_config
|
||||
from core.connection import BuzzerConnection, BuzzerError
|
||||
from core.commands import info, ls, put, mkdir, rm, confirm, reboot, play, check
|
||||
from core.commands import info, ls, put, mkdir, rm, confirm, reboot, play, check, get_tag
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Edis Buzzer Host Tool")
|
||||
@@ -52,6 +52,10 @@ def main():
|
||||
# Befehl: reboot
|
||||
reboot_parser = subparsers.add_parser("reboot", help="Startet den Buzzer neu")
|
||||
|
||||
# Befehl: get_tag
|
||||
get_tag_parser = subparsers.add_parser("get_tag", help="Holt die Tags einer Datei")
|
||||
get_tag_parser.add_argument("path", type=str, help="Pfad der Datei (z.B. /lfs/a/neu)")
|
||||
|
||||
# Argumente parsen
|
||||
args = parser.parse_args()
|
||||
config = load_config(args)
|
||||
@@ -105,6 +109,14 @@ def main():
|
||||
print(f"CRC32 von '{args.path}': 0x{CRC32['crc32']:08x}")
|
||||
else:
|
||||
print(f"Fehler: Keine CRC32-Information für '{args.path}' erhalten.")
|
||||
elif args.command == "get_tag":
|
||||
tags = get_tag.execute(conn, path=args.path)
|
||||
if tags:
|
||||
print(f"Tags von '{args.path}':")
|
||||
for key, value in tags.items():
|
||||
print(f" {key}: {value}")
|
||||
else:
|
||||
print(f"Fehler: Keine Tags für '{args.path}' erhalten.")
|
||||
elif args.command == "info" or args.command is None:
|
||||
# Wurde kein Befehl oder explizit 'info' angegeben, sind wir hier schon fertig
|
||||
pass
|
||||
|
||||
5
buzzer_tool/config.yaml
Normal file
5
buzzer_tool/config.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
# config.yaml
|
||||
serial:
|
||||
port: "COM17"
|
||||
baudrate: 250000
|
||||
timeout: 10
|
||||
@@ -8,13 +8,10 @@ def execute(conn, path: str) -> dict:
|
||||
raise BuzzerError("Keine Antwort auf 'check' empfangen.")
|
||||
|
||||
parts = lines[0].split()
|
||||
if len(parts) != 3 or parts[0] != "CRC32":
|
||||
if len(parts) != 1:
|
||||
raise BuzzerError(f"Unerwartetes Check-Format: {lines[0]}")
|
||||
|
||||
if parts[1] != path:
|
||||
raise BuzzerError(f"Unerwarteter Pfad in Check-Antwort: {parts[1]} (erwartet: {path})")
|
||||
|
||||
crc32 = int(parts[2], 16)
|
||||
crc32 = int(parts[0], 16)
|
||||
|
||||
return {
|
||||
"crc32": crc32
|
||||
|
||||
56
buzzer_tool/core/commands/get_tag.py
Normal file
56
buzzer_tool/core/commands/get_tag.py
Normal file
@@ -0,0 +1,56 @@
|
||||
# core/commands/get_tag.py
|
||||
from core.connection import BuzzerError
|
||||
from core.util import hex_to_bytearray
|
||||
|
||||
def execute(conn, path: str) -> dict:
|
||||
"""Holt Tags einer Datei und gibt sie als strukturiertes Dictionary zurück."""
|
||||
lines = conn.send_command("get_tag " + path)
|
||||
if not lines:
|
||||
raise BuzzerError("Keine Antwort auf 'get_tag' empfangen.")
|
||||
|
||||
parts = lines[0].split()
|
||||
if len(parts) != 1:
|
||||
raise BuzzerError(f"Unerwartetes get_tag-Format: {lines[0]}")
|
||||
|
||||
data = hex_to_bytearray(parts[0])
|
||||
if data is None:
|
||||
raise BuzzerError("Ungültiger Hex-String in get_tag-Antwort.")
|
||||
|
||||
pos = 0
|
||||
tags = {}
|
||||
while pos < len(data):
|
||||
tag_type = data[pos]
|
||||
pos += 1
|
||||
if pos >= len(data):
|
||||
raise BuzzerError(f"Unerwartetes Ende des Hex-Strings bei get_tag (Tag-Typ erwartet). Position: {pos}/{len(data)}")
|
||||
|
||||
match tag_type:
|
||||
case 0x01: # Kommentar
|
||||
length = data[pos]
|
||||
pos += 1
|
||||
if pos + length > len(data):
|
||||
raise BuzzerError(f"Unerwartetes Ende des Hex-Strings bei get_tag (Kommentar erwartet). Position: {pos}")
|
||||
comment = data[pos:pos+length].decode('utf-8')
|
||||
pos += length
|
||||
tags["comment"] = comment
|
||||
|
||||
case 0x02: # Author
|
||||
length = data[pos]
|
||||
pos += 1
|
||||
if pos + length > len(data):
|
||||
raise BuzzerError(f"Unerwartetes Ende des Hex-Strings bei get_tag (Author erwartet). Position: {pos}")
|
||||
author = data[pos:pos+length].decode('utf-8')
|
||||
pos += length
|
||||
tags["author"] = author
|
||||
|
||||
case 0x10: # CRC32
|
||||
if pos + 4 > len(data):
|
||||
raise BuzzerError(f"Unerwartetes Ende des Hex-Strings bei get_tag (CRC32 erwartet). Position: {pos}")
|
||||
crc32 = int.from_bytes(data[pos:pos+4], byteorder='big')
|
||||
pos += 4
|
||||
tags["crc32"] = hex(crc32)
|
||||
|
||||
case _: # Default / Unbekannter Tag
|
||||
tags[f"unknown_0x{tag_type:02x}"] = tag_value_raw.hex()
|
||||
|
||||
return tags
|
||||
25
buzzer_tool/core/util.py
Normal file
25
buzzer_tool/core/util.py
Normal file
@@ -0,0 +1,25 @@
|
||||
def hex_to_bytearray(hex_string):
|
||||
"""
|
||||
Wandelt einen Hex-String (z.B. "deadbeef") in ein bytearray um.
|
||||
Entfernt vorher Leerzeichen und prüft auf Gültigkeit.
|
||||
"""
|
||||
try:
|
||||
# Whitespace entfernen (falls vorhanden)
|
||||
clean_hex = hex_string.strip().replace(" ", "")
|
||||
|
||||
# Konvertierung
|
||||
return bytearray.fromhex(clean_hex)
|
||||
|
||||
except ValueError as e:
|
||||
print(f"Fehler bei der Konvertierung: {e}")
|
||||
return None
|
||||
|
||||
def string_to_hexstring(text):
|
||||
"""
|
||||
Wandelt einen String in einen UTF-8-kodierten Hex-String um.
|
||||
"""
|
||||
# 1. String zu UTF-8 Bytes
|
||||
utf8_bytes = text.encode('utf-8')
|
||||
|
||||
# 2. Bytes zu Hex-String
|
||||
return utf8_bytes.hex()
|
||||
Reference in New Issue
Block a user