79 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			79 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Python
		
	
	
	
| """
 | |
| Generische Applikationsdaten
 | |
| 
 | |
| """
 | |
| 
 | |
| import os
 | |
| from web import WebInterface
 | |
| from tracker import Tracker
 | |
| from navtex import NAVTEX
 | |
| 
 | |
| class AppData():
 | |
| 
 | |
|     def __init__(self, logger, cfg):
 | |
|         self.shutdown = False # Globaler Ausschalter
 | |
|         self.log = logger
 | |
|         if cfg['navtex']:
 | |
|             self.navtex = NAVTEX(logger, cfg)
 | |
|         else:
 | |
|             self.navtex = None
 | |
|         if cfg['tide']:
 | |
|             self.web = WebInterface(logger, cfg)
 | |
|         else:
 | |
|             self.web = None
 | |
|         self.track = Tracker(logger, cfg)
 | |
|         self.frontend = None
 | |
|         self.bv_lat = None
 | |
|         self.bv_lon = None
 | |
| 
 | |
|         # Für u.a. Header-Indikatoren
 | |
|         # TODO
 | |
|         self.status = {
 | |
|             'AP': False,    # Accesspoint
 | |
|             'WIFI': False,  # Wireless Client
 | |
|             'TCP': False,   # TCP Network
 | |
|             'N2K': False,   # NMEA2000
 | |
|             '183': False,   # NMEA0183
 | |
|             'USB': False,   # USB Datenverbindung
 | |
|             'GPS': False,   # GPS-Fix und -daten
 | |
|             'TRK': False    # Tracker
 | |
|         }
 | |
| 
 | |
|     def setFrontend(self, frontend):
 | |
|         self.frontend = frontend # Referenz zur GUI
 | |
|         self.bv_lat = frontend.boatdata.getRef("LAT")
 | |
|         self.bv_lon = frontend.boatdata.getRef("LON")
 | |
| 
 | |
|     def refreshStatus(self):
 | |
|         self.status['AP'] = False # nicht implementiert
 | |
| 
 | |
|         self.status['TCP'] = False
 | |
|         self.status['WIFI'] = False
 | |
|         for intf in os.listdir('/sys/class/net'):
 | |
|             statefile = os.path.join('/sys/class/net', intf, 'operstate')
 | |
|             wififile = os.path.join('/sys/class/net', intf, 'wireless')
 | |
|             if os.path.exists(statefile):
 | |
|                 with open(statefile) as fh:
 | |
|                     state = fh.read().strip()
 | |
|                 if state == 'up':
 | |
|                     if os.path.exists(wififile):
 | |
|                         self.status['WIFI'] = True
 | |
|                     else:
 | |
|                         self.status['TCP'] = True
 | |
| 
 | |
|         # TODO NMEA2000
 | |
|         # can-Interface can0 im Netzwerk. Identifikation?
 | |
| 
 | |
|         # TODO NMEA0183 tty auf Konfiguration
 | |
|         # enabled in Konfiguration
 | |
|         # port muß gültige Schnittstelle sein
 | |
| 
 | |
|         # TODO USB /dev/ttyUSB0?
 | |
| 
 | |
|         # GPS
 | |
|         # Kann ein Empfänger am USB sein. Siehe Konfiguration
 | |
|         self.status['GPS'] = self.bv_lat and self.bv_lon and self.bv_lat.valid and self.bv_lon.valid
 | |
|         
 | |
|         # Tracker
 | |
|         self.status['TRK'] = self.track.is_active()
 |