Stand vor Protokollumbau

This commit is contained in:
2026-03-01 11:11:56 +01:00
parent c914333236
commit 4d88194f7d
17 changed files with 624 additions and 79 deletions

25
buzzer_tool/core/util.py Normal file
View 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()