Thisi is a fork of antlampas/rapiscope-python original code.
- Modular Design: Each hardware/software function (e.g., camera, light source, cuvette sensor, analysis, logger, GUI) is implemented as a separate module class (see
camera.py,lightSource.py, etc.), inheriting from the abstractModulebase class (module.py). - EventManager: Central orchestrator (
eventManager.py) runs as a process, routes messages between modules, and manages lifecycle (registration, shutdown, etc.). - Inter-Process Communication: Modules communicate via message queues managed by the
Communicatorclass. Messages are dictionaries withSender,Destination, andMessage(withtypeandpayload). - Configuration: All runtime configuration is loaded from
config.jsonviaConfigLoader. Module enablement, hardware parameters, and network settings are defined here. - Startup:
main.pyloads config, starts enabled modules as separate processes, and launches the EventManager. Shutdown is coordinated via signals.
- Unit Tests: Located in
tests/unit/. Each module has a corresponding test file. Run all tests with:Or run individual tests as in CI (python -m unittest discover tests/unit
.github/workflows/unitTests.yml). - Dependencies: Install with
pip install -r requirements.txt. Some modules require hardware-specific libraries (seerequirements.txt). - Debugging: Each module logs via the Logger module. Use log messages for tracing inter-module communication and errors.
- Configuration Changes: Edit
config.jsonto enable/disable modules or change hardware/network settings. Restart the app to apply changes.
- Message Routing: All inter-module communication uses the message queue pattern. Always use
sendMessage(destination, msgType, payload)fromModule. - Lifecycle Hooks: Modules override
onStart,mainLoop,handleMessage, andonStopfor custom logic. - Registration: Modules register with EventManager on startup by sending a
Registermessage. - Logging: Use the
log(level, message)method to send logs to the Logger module. Do not print directly except for startup/shutdown. - Threading: Each module runs its own thread for communication. Main logic runs in a separate process.
- Kivy GUI: The GUI module (
gui.py,gui.kv) uses Kivy for the user interface. It is started as a module and communicates via the same message system. - Hardware: GPIO, camera, and sensor modules use hardware-specific libraries (see
requirements.txt). - Diagrams: Architecture and activity diagrams are in
diagrams/for reference.
- To add a new module, inherit from
Module, implement lifecycle methods, and updatemain.pyandconfig.json. - To send a message from a module:
self.sendMessage("EventManager", "Register") self.sendMessage("Logger", "LogMessage", {"level": "INFO", "message": "Started"})
main.py: Startup and process orchestrationmodule.py: Base class for all moduleseventManager.py: Central message routerconfig.json: Configuration for modules and systemrequirements.txt: Python dependenciestests/unit/: Unit tests for each modulediagrams/: Architecture diagrams
If any section is unclear or missing, please provide feedback for further refinement.
ITALIANO
- Design modulare: Ogni funzione hardware/software (es. fotocamera, sorgente luminosa, sensore della cuvetta, analisi, logger, GUI) è implementata come classe modulo separata (vedi
camera.py,lightSource.py, ecc.), che eredita dalla classe base astrattaModule(module.py). - EventManager: L’orchestratore centrale (
eventManager.py) viene eseguito come processo, instrada i messaggi tra i moduli e gestisce il ciclo di vita (registrazione, arresto, ecc.). - Comunicazione inter‑processo: I moduli comunicano tramite code di messaggi gestite dalla classe
Communicator. I messaggi sono dizionari conSender,DestinationeMessage(che contienetypeepayload). - Configurazione: Tutta la configurazione a runtime è caricata da
config.jsontramiteConfigLoader. L’abilitazione dei moduli, i parametri hardware e le impostazioni di rete sono definiti qui. - Avvio:
main.pycarica la configurazione, avvia i moduli abilitati come processi separati e lancia l’EventManager. L’arresto è coordinato tramite segnali.
-
Test unitari: In
tests/unit/. Ogni modulo ha un file di test corrispondente. Per eseguire tutti i test:python -m unittest discover tests/unit
Oppure esegui test singoli come in CI (
.github/workflows/unitTests.yml). -
Dipendenze: Installa con:
pip install -r requirements.txt
Alcuni moduli richiedono librerie specifiche per l’hardware (vedi
requirements.txt). -
Debug: Ogni modulo effettua logging tramite il modulo Logger. Usa i messaggi di log per tracciare la comunicazione inter‑modulo e gli errori.
-
Modifiche di configurazione: Modifica
config.jsonper abilitare/disabilitare moduli o cambiare impostazioni hardware/rete. Riavvia l’app per applicare le modifiche.
- Instradamento dei messaggi: Tutta la comunicazione tra moduli utilizza il pattern delle code di messaggi. Usa sempre
sendMessage(destination, msgType, payload)dalla classeModule. - Hook di ciclo di vita: I moduli sovrascrivono
onStart,mainLoop,handleMessageeonStopper la logica personalizzata. - Registrazione: I moduli si registrano con l’EventManager all’avvio inviando un messaggio
Register. - Logging: Usa il metodo
log(level, message)per inviare log al modulo Logger. Evitaprint, tranne che per avvio/arresto. - Threading: Ogni modulo esegue un proprio thread per la comunicazione. La logica principale gira in un processo separato.
- GUI Kivy: Il modulo GUI (
gui.py,gui.kv) usa Kivy per l’interfaccia utente. È avviato come modulo e comunica tramite lo stesso sistema di messaggistica. - Hardware: I moduli GPIO, fotocamera e sensori usano librerie specifiche all’hardware (vedi
requirements.txt). - Diagrammi: I diagrammi di architettura e delle attività si trovano in
diagrams/.
- Aggiungere un nuovo modulo: eredita da
Module, implementa i metodi del ciclo di vita e aggiornamain.pyeconfig.json. - Inviare un messaggio da un modulo:
self.sendMessage("EventManager", "Register") self.sendMessage("Logger", "LogMessage", {"level": "INFO", "message": "Avviato"})
main.py: Avvio e orchestrazione dei processimodule.py: Classe base per tutti i modulieventManager.py: Router centrale dei messaggiconfig.json: Configurazione di moduli e sistemarequirements.txt: Dipendenze Pythontests/unit/: Test unitari per ogni modulodiagrams/: Diagrammi architetturali
Se qualche sezione risulta poco chiara o mancante, lascia un commento per ulteriori miglioramenti.