## ✅ Network Sniffer - Modifiche Completate ### Problema Iniziale Lo sniffer **non vedeva i messaggi B** perché: 1. I messaggi B in GRIFOSCOPE_MODE sono **richieste senza payload** (REQUEST_MODE=True) 2. Lo sniffer scartava messaggi con payload vuoto: `if payload_words: messages.append(...)` ### Modifiche Implementate #### 1. Supporto B-Request Vuoti **File**: `tools/network_sniffer.py` (linea ~172-179) ```python # PRIMA (bug): hex_str = ' '.join(payload_words) if payload_words: # <-- Scartava B-requests vuoti! messages.append((msg_name, hex_str)) # DOPO (fix): if payload_words: hex_str = ' '.join(payload_words) else: hex_str = "(REQUEST - no payload, tr=1)" # Placeholder per B-requests messages.append((msg_name, hex_str)) # Sempre includi messaggi ``` #### 2. Fix Header Parsing **File**: `tools/network_sniffer.py` (linea ~85-93) ```python # Message header structure (16 bytes total): # - marker (2B) + CW (2B) + SW (2B) + errcode (2B) = 8 bytes (UDP1553MessageHeader) # - reserved/padding = 8 bytes (GrifoScope compatibility) # Read only the first 8 bytes for UDP1553MessageHeader msg_header = UDP1553MessageHeader.from_buffer_copy(data[offset:offset+8]) offset += 16 # Move past FULL header (8 bytes struct + 8 bytes reserved) ``` **Problema**: Il PacketBuilder aggiunge 8 bytes reserved dopo i campi header, ma lo sniffer leggeva 16 bytes nella struttura che ne contiene solo 8. #### 3. Debug Output Migliorato **File**: `tools/network_sniffer.py` (linea ~290-297) ```python direction = "BC→RT (command)" if msg_type == 'A' else "BC→RT (request)" # Highlight REQUEST messages if "(REQUEST" in hex_payload: display = f"{msg_name}: {hex_payload}" else: display = f"{msg_name}: {hex_payload[:60]}..." ``` ### Test di Verifica **File**: `tools/test_sniffer_b_messages.py` Crea un frame UDP1553 mock con: - 1 A-message (A1) con payload 6 words - 3 B-messages (B6, B7, B8) come REQUEST (tr=1, payload vuoto) **Risultato**: ``` [OK] Parsed 4 messages: - A1 (SA1): Command - B6 (SA16): Request → (REQUEST - no payload, tr=1) - B7 (SA17): Request → (REQUEST - no payload, tr=1) - B8 (SA18): Request → (REQUEST - no payload, tr=1) Verification: A-messages: 1/1 [OK] B-messages: 3/3 [OK] B-messages are REQUEST: [OK] [SUCCESS] TEST PASSED! ``` ### Come Usare 1. **Avvia PyBusMonitor** (GRIFOSCOPE_MODE attivo di default): ```bash python -m pybusmonitor1553 ``` 2. **In ALTRO terminale ADMIN**, avvia sniffer: ```bash python tools/network_sniffer.py --source python --debug ``` 3. **Attendi 5-10 secondi**, poi Ctrl+C per fermare 4. **Controlla output**: ``` captured_a_messages_commands_python.txt # A-messages (comandi BC→RT) captured_b_messages_status_python.txt # B-messages (richieste BC→RT) ``` ### Output Atteso ``` [ 1] BC→RT (command) | A1 (SA1): 0000 0000 0000 0000 0000 0000... [ 2] BC→RT (command) | A2 (SA2): 0000 0000... ... [ 8] BC→RT (request) | B1 (SA11): (REQUEST - no payload, tr=1) [ 9] BC→RT (request) | B2 (SA12): (REQUEST - no payload, tr=1) ... [ 18] BC→RT (request) | B8 (SA18): (REQUEST - no payload, tr=1) ``` ### Note Importanti ⚠️ **Permessi**: Lo sniffer richiede **Administrator** su Windows per raw sockets ⚠️ **Npcap/WinPcap**: Deve essere installato per supporto raw socket ⚠️ **Nessun Radar**: Senza radar server attivo, NON vedrai **risposte** dai B-messages (RT→BC status). Vedrai solo le **richieste** (BC→RT poll). ### Prossimi Passi Per catturare anche le **risposte** B-message (RT→BC): 1. Avvia `tools/simple_rt_responder.py` per simulare il radar 2. O connetti al radar reale 3. Lo sniffer catturerà traffico bidirezionale su entrambe le porte (61553/51553)