This commit is contained in:
2026-02-27 12:27:26 +01:00
parent 74dc8642c7
commit f70ef5c259
6 changed files with 98 additions and 10 deletions

View File

@@ -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
from core.commands import info, ls, put, mkdir, rm, confirm, reboot
def main():
parser = argparse.ArgumentParser(description="Edis Buzzer Host Tool")
@@ -73,7 +73,11 @@ def main():
elif args.command == "mkdir":
mkdir.execute(conn, path=args.path)
elif args.command == "rm":
rm.execute(conn, path=args.path, recursive=args.recursive)
rm.execute(conn, path=args.path, recursive=args.recursive)
elif args.command == "confirm":
confirm.execute(conn)
elif args.command == "reboot":
reboot.execute(conn)
elif args.command == "info" or args.command is None:
# Wurde kein Befehl oder explizit 'info' angegeben, sind wir hier schon fertig
pass

View File

@@ -1,4 +1,6 @@
# core/commands/rm.py
import fnmatch
import posixpath
from core.connection import BuzzerError
from core.commands.ls import get_file_tree
@@ -21,10 +23,37 @@ def _try_rm(conn, path, is_dir=False):
print(f" ❌ Fehler bei {path}: {e}")
def execute(conn, path: str, recursive: bool = False):
"""Löscht eine Datei oder ein Verzeichnis."""
"""Löscht eine Datei, ein Verzeichnis oder löst Wildcards (*) auf."""
# 1. Wildcard-Behandlung (z.B. /lfs/a/* oder *.wav)
if '*' in path or '?' in path:
dirname, pattern = posixpath.split(path)
if not dirname:
dirname = "/"
print(f"Suche nach Dateien passend zu '{pattern}' in '{dirname}'...")
tree = get_file_tree(conn, target_path=dirname, recursive=False)
# Fehler beim Verzeichnis-Lesen abfangen
if len(tree) == 1 and tree[0].get("type") == "E":
print(f"❌ Verzeichnis '{dirname}' nicht gefunden.")
return
# Filtern mit fnmatch (funktioniert wie in der Linux-Shell)
matches = [node for node in tree if node.get("type") == "F" and fnmatch.fnmatch(node["name"], pattern)]
if not matches:
print(f"Keine passenden Dateien für '{path}' gefunden.")
return
for match in matches:
_try_rm(conn, match["path"], is_dir=False)
return # Fertig mit Wildcard-Löschen
# 2. Rekursives Löschen (-r)
if recursive:
print(f"Sammle Dateibaum für rekursives Löschen von '{path}'...")
# Lade den kompletten Baum ab diesem Pfad
tree = get_file_tree(conn, target_path=path, recursive=True)
if len(tree) == 1 and tree[0].get("type") == "E":
@@ -36,7 +65,7 @@ def execute(conn, path: str, recursive: bool = False):
else:
_delete_recursive(conn, tree)
# Am Ende das eigentliche Ziel löschen (die Datei oder den nun leeren Ordner)
# 3. Standard-Löschen (Einzeldatei oder am Ende der Rekursion der leere Ordner)
try:
conn.send_command(f"rm {path}")
print(f"🗑️ '{path}' erfolgreich gelöscht.")

View File

@@ -1,5 +1,5 @@
VERSION_MAJOR = 0
VERSION_MINOR = 0
PATCHLEVEL = 9
PATCHLEVEL = 12
VERSION_TWEAK = 0
EXTRAVERSION = 0

View File

@@ -48,10 +48,17 @@ int main(void)
LOG_INF("All subsystems initialized. Starting application threads.");
audio_system_ready();
k_sleep(K_SECONDS(5)); // Kurze Pause, damit die READY-Antworten der Subsysteme noch rausgehen
volatile uint32_t *invalid_pointer = (volatile uint32_t *)0xFFFFFFFF;
*invalid_pointer = 0xDEADBEEF;
while (1) {
if (!boot_is_img_confirmed())
{
LOG_INF("Confirmation of firmware image pending. Inform user...");
audio_play("/lfs/sys/update");
}
else
{
LOG_INF("Firmware image already confirmed. No need to confirm again.");
}
while (1)
{
k_sleep(K_FOREVER);
}
}

View File

@@ -267,6 +267,26 @@ int rm(const char *path) {
return rc;
}
int confirm_firmware() {
int rc = boot_write_img_confirmed();
if (rc < 0)
{
LOG_ERR("Failed to confirm firmware: %d", rc);
return rc;
}
LOG_INF("Firmware confirmed successfully");
return 0;
}
int reboot_device() {
LOG_INF("Rebooting device as requested by host...");
send_ok();
k_sleep(K_MSEC(100)); // Kurze Pause, damit die OK-Antwort noch rausgeht
while (log_process());
sys_reboot(SYS_REBOOT_COLD);
return 0; // Dieser Code wird nie erreicht, aber wir geben ihn der Vollständigkeit halber zurück
}
void execute_current_command(void)
{
int rc;
@@ -346,6 +366,24 @@ void execute_current_command(void)
send_error(rc);
}
break;
case CMD_CONFIRM:
LOG_DBG("Executing CONFIRM command");
rc = confirm_firmware();
if (rc == 0)
{ send_ok();
}
else
{
send_error(rc);
}
break;
case CMD_REBOOT:
LOG_DBG("Executing REBOOT command");
rc = reboot_device();
if (rc != 0) {
send_error(rc);
}
break;
default:
LOG_ERR("No execution logic for command %d", current_command);
send_error(ENOSYS);
@@ -396,6 +434,14 @@ protocol_state_t reading_command(uint8_t byte)
{
LOG_DBG("Received RM command");
current_command = CMD_RM;
} else if (strcmp((char *)buffer, "confirm") == 0)
{
LOG_DBG("Received CONFIRM command");
current_command = CMD_CONFIRM;
} else if (strcmp((char *)buffer, "reboot") == 0)
{
LOG_DBG("Received REBOOT command");
current_command = CMD_REBOOT;
}
else
{

View File

@@ -15,6 +15,8 @@ typedef enum {
CMD_PUT_BINARY_FILE,
CMD_MKDIR,
CMD_RM,
CMD_CONFIRM,
CMD_REBOOT,
/* Weitere Kommandos folgen hier */
} protocol_cmd_t;