From d9bd86bb84ee9ad36effee79c14acea1dd7f6e4e Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Mon, 31 Aug 2026 03:45:38 +0200 Subject: [PATCH] Move RS-232 status under debug. Fix #2 from list. --- docs/agent/code-map.md | 2 +- docs/agent/current-state.md | 14 +++++++------- docs/command_reference.md | 2 +- docs/electrical_tests.md | 2 +- docs/roadmap.md | 2 +- docs/user_administration_tests.md | 4 ++-- src/console_completion.c | 3 ++- src/rs232_hw_test.c | 11 ++++------- 8 files changed, 19 insertions(+), 21 deletions(-) diff --git a/docs/agent/code-map.md b/docs/agent/code-map.md index a8fe3d1..dc94c46 100644 --- a/docs/agent/code-map.md +++ b/docs/agent/code-map.md @@ -137,7 +137,7 @@ This is a semantic map, not a complete file inventory. Start here, then read the - Files: `src/board_pins.h`, `src/rs232_hw_test.{h,c}`, `src/local_ui_hw_test.{h,c}`, `src/status_led.{h,c}` - Documentation: `docs/wiring.md`, `docs/electrical_tests.md` -- Called by: startup and `debug`/`status` commands +- Called by: startup and `debug` commands - Dependencies: physical RS-232 owner, serial/display services, ESP-IDF GPIO/UART/I2C/LED drivers - Ownership: RS-232 diagnostics refuse to run while the service owns the port; display diagnostics reuse `local_display`. - Constraint: wiring and voltage assumptions are safety-relevant; verify target hardware before running diagnostics. RGB LED initialization is currently boot-fatal, and its colors report diagnostic state rather than aggregate firmware health. diff --git a/docs/agent/current-state.md b/docs/agent/current-state.md index 585b750..49049b1 100644 --- a/docs/agent/current-state.md +++ b/docs/agent/current-state.md @@ -46,13 +46,13 @@ These observations should be checked when touching the relevant area; they are n ## Active Task -- **Objective:** Prevent USB CDC host line coding from implicitly reconfiguring UART1 when USB becomes writer. -- **Relevant files:** `src/usb_cdc_transport.{c,h}`, `src/usb_console.c`, USB serial documentation. -- **Findings:** The transport converted cached CDC line coding into `serial_config_t` and called `serial_service_apply_config()` after writer acquisition. That deliberately stopped/restarted UART1 and changed its RAM configuration. -- **Decision:** Treat CDC line coding as diagnostic metadata only. UART1 configuration remains exclusively controlled by explicit `serial` commands and their NVS persistence. -- **Changes completed:** Removed the pending line-coding apply path and its counters; retained the latest host setting for `usb status`; updated the contract documentation. -- **Remaining work:** Target-hardware verification: acquire/release USB writer ownership after changing a host terminal's line coding and confirm UART1 remains at the configured framing. -- **Risks / things to remember:** Host terminal line-coding selectors no longer configure the physical RS-232 port; use `serial set`/`serial save` instead. `pio run` passed after the change. +- **Objective:** Keep UART1 configuration independent of USB CDC host line coding and move the Phase 0 RS-232 signal status command under `debug`. +- **Relevant files:** `src/usb_cdc_transport.{c,h}`, `src/usb_console.c`, `src/rs232_hw_test.c`, `src/console_completion.c`, related documentation. +- **Findings:** The USB transport converted cached CDC line coding into `serial_config_t` and called `serial_service_apply_config()` after writer acquisition. Separately, root `status` was a Phase 0 diagnostic that needed to claim the RS-232 port and therefore failed while the production serial service owned it. +- **Decision:** Treat CDC line coding as diagnostic metadata only. UART1 configuration remains exclusively controlled by explicit `serial` commands and their NVS persistence. Keep all Phase 0 RS-232 diagnostics, including signal status, under `debug`. +- **Changes completed:** Removed the pending line-coding apply path and its counters; retained the latest host setting for `usb status`. Replaced root `status` with `debug status`, updated completion and documentation. +- **Remaining work:** Target-hardware verification: acquire/release USB writer ownership after changing a host terminal's line coding and confirm UART1 remains at the configured framing. Verify `debug status` works after `serial stop` and root `status` is unknown. +- **Risks / things to remember:** Host terminal line-coding selectors no longer configure the physical RS-232 port; use `serial set`/`serial save` instead. `debug status` remains ownership-protected and requires UART1 to be stopped. `pio run` passed after both changes. ### Handoff template diff --git a/docs/command_reference.md b/docs/command_reference.md index 6e6a39d..96e2648 100644 --- a/docs/command_reference.md +++ b/docs/command_reference.md @@ -8,7 +8,6 @@ UART0 and authenticated `admin` SSH sessions use the same registered command imp |---|---| | `memory` | Show free memory, minimum free memory, and largest blocks for internal RAM, DMA-capable RAM, and PSRAM. | | `reboot` | Drain console output briefly and restart the ESP32. | -| `status` | Show quick MAX3243 signal state. | ## Role-based users @@ -150,6 +149,7 @@ UART0 and admin SSH use shared whole-line Tab completion. A unique/common prefix | Command | Description | |---|---| +| `debug status` | Show MAX3243 driver, receiver, VLD, and shutdown states. It requires UART1 to be stopped. | | `debug transceiver ` | Enable or shut down the MAX3243. | | `debug drivers ` | Drive static TX, DTR, and RTS logic levels for measurement. | | `debug loopback-a` / `debug loopback-b` | Test MAX3243 driver/receiver loopback configurations. | diff --git a/docs/electrical_tests.md b/docs/electrical_tests.md index 0307636..fe274e2 100644 --- a/docs/electrical_tests.md +++ b/docs/electrical_tests.md @@ -276,7 +276,7 @@ Each output should be negative. Exact voltages depend on supply, load, meter, an ## Recommended order -1. With no DE-9 jumpers, run `status`. +1. With no DE-9 jumpers and after `serial stop`, run `debug status`. 2. Measure output polarity with `debug drivers 0 0 0` and `debug drivers 1 1 1`. 3. Power down, install configuration A, power up, and run `debug loopback-a`. 4. Run `debug valid-test` with configuration A still installed. diff --git a/docs/roadmap.md b/docs/roadmap.md index f187288..de7c145 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -57,7 +57,7 @@ Implemented and hardware-validated: - Hardware CTS transmit gating and RTS receive-backpressure tests. - Exclusive RS-232 port ownership and fault-safe cleanup. - RGB status indication for diagnostic state. -- Potentially disruptive tests isolated under the `debug` CLI submenu; top-level `status` retained. +- Phase 0 hardware diagnostics, including signal status, are isolated under the `debug` CLI submenu. Detailed procedures are in [Electrical tests](electrical_tests.md) and [Hardware wiring](wiring.md). diff --git a/docs/user_administration_tests.md b/docs/user_administration_tests.md index 75944e8..331a46d 100644 --- a/docs/user_administration_tests.md +++ b/docs/user_administration_tests.md @@ -14,7 +14,7 @@ Upgrade a device that already has working HTTPS/SSH credentials and no `user_db` 2. Confirm exactly one `admin`-named account exists with role `user`, `bootstrapped=no`, no displayed password/salt/verifier, and no public keys. 3. Confirm the pre-upgrade credential still authenticates to HTTPS and SSH and that serial terminal behavior is unchanged. 4. Reboot and confirm `user status` reports the same account ID and authentication generation. -5. Confirm routine boot logs, `status`, `web status`, and `ssh status` contain no user password, verifier, salt, or raw public-key blob. +5. Confirm routine boot logs, `web status`, and `ssh status` contain no user password, verifier, salt, or raw public-key blob. A transient failure reading the legacy web credential must not create or commit an empty user database. If a valid `user_db` blob already exists, it must still load without the legacy credential being readable. @@ -130,7 +130,7 @@ Use one disposable `admin` and one disposable `user`. Keep UART0 attached throug ### 1. Route separation and normal shells 1. Connect as the normal user and confirm the existing broker-backed UART1 serial stream, broker client, and writer/observer behavior are unchanged. -2. Connect as the administrator and confirm the `admin@serial-tool>` prompt appears. Run `help`, `status`, `memory`, `serial status`, `wifi status`, `web status`, `broker status`, and `broker clients`. Compare representative output with UART0 and confirm both routes execute the same registered command implementations. +2. Connect as the administrator and confirm the `admin@serial-tool>` prompt appears. Run `help`, `memory`, `serial status`, `wifi status`, `web status`, `broker status`, and `broker clients`. Compare representative output with UART0 and confirm both routes execute the same registered command implementations. 3. From UART0 run `ssh sessions` and `broker clients`. The user session must show `route=broker`; the admin session must show `route=admin-console`, `broker=0`, `broker-role=n/a`, and no writer lease. The admin session must not start UART1 or alter broker client/writer counts merely by connecting. ### 2. Bounded command processing diff --git a/src/console_completion.c b/src/console_completion.c index 4e81955..a85d8ee 100644 --- a/src/console_completion.c +++ b/src/console_completion.c @@ -11,13 +11,14 @@ #include "linenoise/linenoise.h" static const char *const s_root_candidates[] = { - "help", "status", "debug", "display", "serial", "broker", "usb", "user", + "help", "debug", "display", "serial", "broker", "usb", "user", "wifi", "web", "ssh", "ping", "nslookup", "traceroute", "reboot", "memory", }; /* Keep full-line candidate strings grouped by their registered root command. */ static const char *const s_completion_candidates[] = { /* Hardware debug commands and safe fixed arguments. */ + "debug status", "debug transceiver", "debug transceiver enable", "debug transceiver disable", diff --git a/src/rs232_hw_test.c b/src/rs232_hw_test.c index c7325e7..5e56ed5 100644 --- a/src/rs232_hw_test.c +++ b/src/rs232_hw_test.c @@ -1579,6 +1579,7 @@ DEFINE_OWNED_COMMAND(rts_flow_test) static void print_debug_usage(void) { printf("Usage:\n"); + printf(" debug status\n"); printf(" debug transceiver \n"); printf(" debug drivers \n"); printf(" debug loopback-a|loopback-b|valid-test\n"); @@ -1595,6 +1596,9 @@ static int command_debug(int argc, char **argv) } /* Existing handlers expect their own command name in argv[0]. */ + if (strcmp(argv[1], "status") == 0) { + return command_status(argc - 1, argv + 1); + } if (strcmp(argv[1], "transceiver") == 0) { return command_transceiver(argc - 1, argv + 1); } @@ -1647,13 +1651,6 @@ esp_err_t rs232_hw_test_register_console_commands(void) } const esp_console_cmd_t commands[] = { - { - .command = "status", - .help = "Show MAX3243 driver, receiver, VLD, and shutdown states", - .hint = NULL, - .func = &command_status, - .argtable = NULL, - }, { .command = "debug", .help = "Low-level RS-232 and local-UI hardware diagnostics; run 'debug' for subcommands",