269 lines
8.8 KiB
Markdown
269 lines
8.8 KiB
Markdown
# Chiarimento: GUI Come Test Client del Modulo ARTOS
|
|
|
|
## La Tua Richiesta (Corretta!)
|
|
|
|
> La GUI deve usare **esattamente le stesse API** che userà ARTOS.
|
|
> Il progetto diventa lo strumento per **sviluppare, implementare e testare** il modulo.
|
|
> Il modulo deve essere **autocontenuto** e riusabile ovunque.
|
|
|
|
✅ **Sono completamente d'accordo!** Questo è l'approccio corretto.
|
|
|
|
---
|
|
|
|
## Situazione Attuale vs. Target
|
|
|
|
### ❌ ATTUALMENTE (Sbagliato)
|
|
|
|
```
|
|
┌─────────────────────────────────────────┐
|
|
│ GUI Tkinter │
|
|
│ │
|
|
│ Accede direttamente a: │
|
|
│ • ConnectionManager.init_library() │ ← API sbagliata!
|
|
│ • ConnectionManager.start() │
|
|
│ • ConnectionManager.stop() │
|
|
└─────────────────────────────────────────┘
|
|
|
|
┌─────────────────────────────────────────┐
|
|
│ ARTOS Collector │
|
|
│ │
|
|
│ Userebbe: │
|
|
│ • BusMonitorCore.initialize() │ ← API diversa!
|
|
│ • BusMonitorCore.start_session() │
|
|
│ • BusMonitorCore.stop_session() │
|
|
└─────────────────────────────────────────┘
|
|
```
|
|
|
|
**Problema**: Due code path diversi! Non stiamo testando quello che verrà usato in produzione.
|
|
|
|
---
|
|
|
|
### ✅ TARGET (Corretto)
|
|
|
|
```
|
|
┌──────────────────────────────────────────────────────────────┐
|
|
│ BusMonitorCore Module │
|
|
│ (BaseModule Interface) │
|
|
│ • initialize(config: Dict) → bool │
|
|
│ • start_session() → None │
|
|
│ • stop_session() → None │
|
|
│ • get_status() → Dict │
|
|
│ • get_message(label) → Message │
|
|
│ • register_callback(label, func) │
|
|
└──────────────────┬───────────────────────────────────────────┘
|
|
│
|
|
┌──────────┴────────────┐
|
|
│ │
|
|
▼ ▼
|
|
┌───────────────────┐ ┌──────────────────┐
|
|
│ GUI Tkinter │ │ ARTOS Collector │
|
|
│ (Test Client) │ │ (Prod Client) │
|
|
│ │ │ │
|
|
│ Same imports: │ │ Same imports: │
|
|
│ BusMonitorCore() │ │ BusMonitorCore()│
|
|
│ .initialize() │ │ .initialize() │
|
|
│ .start_session() │ │ .start_session()│
|
|
└───────────────────┘ └──────────────────┘
|
|
```
|
|
|
|
**Soluzione**: Un solo code path! Se la GUI funziona, ARTOS funzionerà.
|
|
|
|
---
|
|
|
|
## Struttura del Modulo Auto-contenuto
|
|
|
|
### Core Module (Esportabile, Zero Dipendenze Esterne)
|
|
|
|
```
|
|
pybusmonitor1553/
|
|
├── core/
|
|
│ ├── __init__.py # Export: BusMonitorCore
|
|
│ ├── base_module.py # ARTOS interface (ABC)
|
|
│ ├── bus_monitor_core.py # Implementation
|
|
│ ├── data_recorder.py # Recording system
|
|
│ └── connection_manager.py # Internal (non esposto)
|
|
│
|
|
└── Grifo_E_1553lib/ # Protocol layer
|
|
├── messages/ # Message definitions
|
|
├── udp_parser.py # UDP framing
|
|
└── ...
|
|
```
|
|
|
|
**Public API** (l'unica cosa che ARTOS deve sapere):
|
|
```python
|
|
from pybusmonitor1553.core import BusMonitorCore
|
|
|
|
monitor = BusMonitorCore()
|
|
monitor.initialize({'ip': '127.0.0.1', 'port': 5001})
|
|
monitor.start_session()
|
|
```
|
|
|
|
### GUI (Development Tool, Non Parte del Core)
|
|
|
|
```
|
|
pybusmonitor1553/
|
|
└── gui/
|
|
├── monitor.py # GUI application
|
|
├── details_pane.py # Helper widgets
|
|
└── ...
|
|
```
|
|
|
|
**GUI importa il core come client esterno**:
|
|
```python
|
|
# gui/monitor.py
|
|
from pybusmonitor1553.core import BusMonitorCore # ← Same as ARTOS!
|
|
|
|
class MonitorApp:
|
|
def __init__(self):
|
|
self.bus_monitor = BusMonitorCore() # ← Same instance type
|
|
|
|
def on_init(self):
|
|
config = {'ip': '127.0.0.1', 'port': 5001}
|
|
self.bus_monitor.initialize(config) # ← Same method call
|
|
|
|
def on_start(self):
|
|
self.bus_monitor.start_session() # ← Same method call
|
|
```
|
|
|
|
---
|
|
|
|
## Workflow Identico: GUI vs ARTOS
|
|
|
|
### GUI Test Tool
|
|
```python
|
|
# User clicks "Initialize" button
|
|
def on_init_button():
|
|
bus_monitor = BusMonitorCore()
|
|
config = get_config_from_gui()
|
|
success = bus_monitor.initialize(config)
|
|
if success:
|
|
enable_start_button()
|
|
|
|
# User clicks "Start" button
|
|
def on_start_button():
|
|
bus_monitor.start_session()
|
|
bus_monitor.register_callback("msg_a2", update_tree_view)
|
|
```
|
|
|
|
### ARTOS Collector
|
|
```python
|
|
# Orchestrator initializes module
|
|
def setup_test():
|
|
bus_monitor = BusMonitorCore()
|
|
config = load_from_test_scenario()
|
|
success = bus_monitor.initialize(config)
|
|
if not success:
|
|
abort_test()
|
|
|
|
# Test execution
|
|
def run_test():
|
|
bus_monitor.start_session()
|
|
bus_monitor.register_callback("msg_a2", validate_radar_mode)
|
|
```
|
|
|
|
**Identico!** Stesso flusso, stessi metodi, stessi parametri.
|
|
|
|
---
|
|
|
|
## Benefici di Questo Approccio
|
|
|
|
### 1. True Integration Testing
|
|
La GUI diventa uno **strumento di test reale** del modulo:
|
|
- Se funziona nella GUI → funzionerà in ARTOS
|
|
- Zero sorprese durante l'integrazione
|
|
- Bug scoperti durante lo sviluppo, non in produzione
|
|
|
|
### 2. Modulo Veramente Auto-contenuto
|
|
```python
|
|
# ARTOS project (altro repository)
|
|
pip install pybusmonitor1553
|
|
|
|
# In collector.py
|
|
from pybusmonitor1553.core import BusMonitorCore
|
|
# That's it! Zero dipendenze da GUI, Tkinter, etc.
|
|
```
|
|
|
|
### 3. Facile Estensione Futura
|
|
Domani puoi creare:
|
|
- CLI tool → usa BusMonitorCore
|
|
- REST API server → usa BusMonitorCore
|
|
- Test automatici → usano BusMonitorCore
|
|
- Web UI → usa BusMonitorCore
|
|
|
|
Tutti testano **lo stesso codice** che andrà in produzione!
|
|
|
|
### 4. Clean Separation of Concerns
|
|
```
|
|
Core Module (Production)
|
|
↓ Dipendenze: ZERO (solo stdlib Python)
|
|
↓ API: BaseModule interface
|
|
↓ Test: tramite GUI tool
|
|
|
|
GUI Tool (Development)
|
|
↓ Dipende da: Core Module
|
|
↓ Scopo: Test, debug, sviluppo
|
|
↓ Non incluso in ARTOS deployment
|
|
```
|
|
|
|
---
|
|
|
|
## Piano di Implementazione
|
|
|
|
### Step 1: Completare BusMonitorCore ⚠️ PRIORITÀ
|
|
- [x] Interfaccia BaseModule (fatto)
|
|
- [x] Recording system (fatto)
|
|
- [ ] **Integrare MessageDB** (manca!)
|
|
- [ ] **Testare initialize() con ConnectionManager** (manca!)
|
|
|
|
### Step 2: Refactorare GUI 🎯 FOCUS
|
|
- [ ] Cambiare import: `BusMonitorCore` invece di `ConnectionManager`
|
|
- [ ] Mappare metodi: `initialize()` / `start_session()` / `stop_session()`
|
|
- [ ] Usare callbacks per aggiornamenti real-time
|
|
- [ ] Verificare che tutto funzioni come prima
|
|
|
|
### Step 3: Validazione
|
|
- [ ] Test manuale completo della GUI
|
|
- [ ] Recording/replay con messaggi reali
|
|
- [ ] Verifica che API sia identica per ARTOS
|
|
|
|
### Step 4: Packaging (Futuro)
|
|
- [ ] `setup.py` con extras_require={'gui': [...]}
|
|
- [ ] Documentazione API pubblica
|
|
- [ ] Esempi ARTOS integration
|
|
|
|
---
|
|
|
|
## Risposta alla Tua Domanda
|
|
|
|
> "Io vorrei che il software PyBusMonitor1553 utilizzi la stessa metodologia di utilizzo del modulo di busmonitor che poi verrà utilizzato da ARTOS."
|
|
|
|
✅ **Esatto! Ed è quello che implementeremo.**
|
|
|
|
La GUI diventerà un **test client** che usa:
|
|
- Stessi import
|
|
- Stesse API calls
|
|
- Stesso workflow
|
|
|
|
Quando ARTOS importerà il modulo, userà **identico codice** già testato dalla GUI.
|
|
|
|
> "Il modulo ovviamente dovrà essere autocontenuto, ossia dovrà essere facilmente utilizzabile dove voglio senza dipendenze incrociate."
|
|
|
|
✅ **Perfetto!**
|
|
|
|
Il core module:
|
|
- Zero dipendenze esterne (solo Python stdlib)
|
|
- Export pulito: `from pybusmonitor1553.core import BusMonitorCore`
|
|
- GUI è separata e opzionale
|
|
|
|
---
|
|
|
|
## Vuoi che Proceda?
|
|
|
|
Posso iniziare il refactoring in questo ordine:
|
|
|
|
1. **Completare `bus_monitor_core.py`** (integrare MessageDB)
|
|
2. **Refactorare `gui/monitor.py`** (usare BusMonitorCore)
|
|
3. **Testare** che tutto funzioni
|
|
|
|
Procedo?
|