How leonelnieto/uart_sniffer works
Project type and purpose
• This is a desktop GUI application written in Python, using PySide6/Qt6 for the interface and pyserial for UART communication.
• Its sole purpose is to sniff and display UART traffic on two channels (TX and RX), in real time, with logging capabilities.
File structure
• Top‐level files:
• sniffer_app.py – main application entry point and logic
• ui_sniffer_uart.py – auto-generated Qt UI layout
• uart_sniffer.ui – Qt Designer form (source of ui_sniffer_uart.py)
• requirements.txt – Python dependencies
• README.md, LICENSE, .gitignore
• Runtime‐generated logs/ directory (not under source control)
README for additional insights
• Dual‐threaded model: one thread per UART channel, communicating via Qt signals.
• MVC‐style separation: UI (UserInterface) vs. worker threads (UART readers) vs. data persistence (log files).
• Configuration options exposed in the UI for COM port and baud rate.
• Data flow: Serial port → Worker thread → Qt signal → UI display → Optional log writer
Main components
a. Frontend/UI Layer
• UserInterface (QMainWindow subclass)
• Ui_MainWindow (layout and controls)
• Configuration panel (port selectors, baudrate dropdowns, enable/disable checkboxes)
• Control buttons (Start, Stop, Save)
• Tab widget (TX tab, RX tab, Combined tab)
b. Backend/Worker Layer
• TX Reader Thread (pyserial.Serial reader)
• RX Reader Thread (pyserial.Serial reader)
• UartSignals (custom Qt signals for data emission)
c. Persistence Layer
• Log Writer (file I/O module writing to logs/log_YYYY_MM_DD_HH_MM_SS.txt)
d. External Interfaces
• Physical UART devices (two COM ports)
• Filesystem (logs directory)
e. Resources
Relationships and interactions
• On “Start”: UI creates/configures each serial thread (TX and/or RX), opens ports
• Worker threads read bytes asynchronously, package them into hex strings
• Worker threads emit Qt signals (via UartSignals) carrying data payloads
• UI slots receive signals and append text to the appropriate tab(s)
• UI “Save” action invokes the Log Writer, writing accumulated data to a timestamped file
• On “Stop” or exit: threads are signaled to terminate, ports are closed, resources cleaned up
Architectural patterns and design principles
• Model–View–Controller separation:
• Model: Data coming from UART and data stored in logs
• View: Qt UI elements, tabs, text widgets
• Controller: sniffer_app.py orchestrates threads and signal-slot wiring
• Producer–Consumer pattern: UART reading threads produce data, UI consumes via queued signals
• Threading for non-blocking UI: daemon threads + Qt signal/event loop for thread-safe updates
Relevant technologies and frameworks
• PySide6/Qt6: UI framework, signals & slots, threading integration
• pyserial: Serial port communication
• Python standard library: threading, logging, file I/O
• Qt Designer: ui_sniffer_uart.ui