DigiBB USB Web Bridge v0.9.11
========================

Standalone localhost USB web bridge for DigiBB HF64 or newer.
The GUI title and header show the bridge version explicitly.

Files:
- digibb_web_bridge.py  : small bridge GUI
- usb_tunnel.py         : USB/TCP tunnel implementation
- protocol.py           : serial transport / tunnel integration
- requirements.txt      : Python dependency list
- run_web_bridge.bat    : creates/uses local venv and starts bridge

Usage:
1. Connect DigiBB over USB.
2. Run run_web_bridge.bat.
3. Select the DigiBB COM port and connect.
4. Open the URL shown by the bridge (normally http://127.0.0.1:8080/;
   another localhost port is selected automatically when 8080 is unavailable).

Notes:
- The bridge binds only to 127.0.0.1.
- The full DigiBB USB Controller is not required.
- Do not run the standalone bridge and the full USB Controller on the same COM
  port at the same time.
- Firmware upload through the USB tunnel is supported but slow; W5500 Ethernet
  is recommended for firmware updates.

Protocol v2 / OTA reliability:
- DATA frames use stop-and-wait retransmission.
- Lost ACKs are retried safely because HF64 deduplicates repeated sequence IDs.
- This specifically tolerates short UART/core stalls during ESP32 flash writes.


v0.9.7 firmware flash-stall handling:
- POST /api/firmware keeps the normal 1.5 s ACK timeout as the first warning.
- It then waits passively up to 10 s for a late ACK before retransmitting.
- The firmware DATA retry deadline is 240 s.
- Other web requests retain the normal tunnel timing.
- Intended for HF71 up-front OTA erase with the ESP32 UART RX ring back at 4 KiB.


v0.9.7 timeout-survival fix
---------------------------
Firmware DATA keeps the normal 1.5 s first ACK timeout, then waits quietly 10 s
before retrying the exact same protocol-v2 sequence. This avoids 1.5 s retry
spam during a long ESP32 erase while still recovering a frame that was lost
during the erase. The matching HF71 ESP32 build waits 30 s for USB OTA receive
inactivity, so the retry arrives before the HTTP upload is aborted. Closing a
virtual connection now also wakes any thread waiting for a firmware ACK, and a
stopped/released connection is never retried afterwards.


v0.9.8 USB firmware progress telemetry
--------------------------------------
- GET /__digibb_tunnel/progress is handled locally by the bridge and consumes no
  USB virtual channel.
- During POST /api/firmware it reports firmware body bytes whose tunnel DATA frame
  has actually received DEV_DATA_ACK from the ESP32.
- This avoids the misleading browser/Windows localhost buffering percentage.
- The web page caps transport progress at 99% until final HTTP success.


v0.9.9 local progress endpoint reliability
------------------------------------------
- Fix GET /__digibb_tunnel/progress detection when the HTTP request line is
  split across multiple TCP recv() calls.
- Local progress requests never consume a virtual USB channel.
- Debug build logs LOCAL progress requests.
- Compatible with DigiBB HF75; no ESP32 firmware change is required.

- Consume the complete local GET request before replying so Windows does not
  reset the socket because unread request bytes remain pending.


v0.9.10 firmware Content-Length fix
------------------------------------
- Firmware POST progress now collects the complete HTTP request header before
  parsing Content-Length. Chromium can produce headers larger than the first
  512-byte localhost read; v0.9.9 then reported total=0 and no percentage.
- Collected header/body bytes are still forwarded in protocol-safe chunks of at
  most 512 bytes. No DigiBB tunnel protocol change is required.


v0.9.11 automatic same-port reconnect
--------------------------------------
- After a DigiBB ESP32 reboot, the bridge closes and reopens the exact USB COM
  port selected by the operator. It does not rescan for another COM port and
  does not assume the device number changes.
- A completed web firmware POST also arms the reconnect path, so recovery does
  not depend only on seeing an ESP32 boot banner.
- The localhost TCP listener remains bound while the serial side is recycled.
  Old virtual tunnel sockets are dropped, then SHOW STATUS and TUNNELINFO are
  re-run until the MASTER is ready. Browser HTTP/WebSocket reconnects can then
  return on the same localhost URL without operator intervention.
