#!/usr/bin/env python3 # This file is part of OpenPlotter. # Copyright (C) 2022 by Sailoog # # Openplotter is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # any later version. # Openplotter is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Openplotter. If not, see . import time, os, subprocess, sys from openplotterSettings import language from openplotterSignalkInstaller import connections class Start(): def __init__(self, conf, currentLanguage): self.conf = conf currentdir = os.path.dirname(os.path.abspath(__file__)) language.Language(currentdir,'openplotter-maiana',currentLanguage) self.initialMessage = _('Starting MAIANA transponder...') def start(self): green = '' black = '' red = '' subprocess.call(['pkill', '-f', 'openplotter-maiana-read']) subprocess.Popen('openplotter-maiana-read') time.sleep(1) return {'green': green,'black': black,'red': red} class Check(): def __init__(self, conf, currentLanguage): self.conf = conf currentdir = os.path.dirname(os.path.abspath(__file__)) language.Language(currentdir,'openplotter-maiana',currentLanguage) self.initialMessage = _('Checking MAIANA transponder...') def check(self): green = '' black = '' red = '' #TODO check localhost 10110 and "Suppress nmea0183 event" in sk connection #device device = self.conf.get('MAIANA', 'device') if not device: msg = _('There is no MAIANA device defined') if not red: red = msg else: red+= '\n '+msg else: msg = _('MAIANA device')+': '+device if not green: green = msg else: green+= ' | '+msg #access skConnections = connections.Connections('MAIANA') result = skConnections.checkConnection() if result[0] == 'pending' or result[0] == 'error' or result[0] == 'repeat' or result[0] == 'permissions': if not red: red = result[1] else: red+= '\n '+result[1] if result[0] == 'approved' or result[0] == 'validated': msg = _('Access to Signal K server validated') if not green: green = msg else: green+= ' | '+msg # check service test = subprocess.check_output(['ps','aux']).decode(sys.stdin.encoding) if device and (result[0] == 'approved' or result[0] == 'validated'): if 'openplotter-maiana-read' in test: msg = _('running') if not green: green = msg else: green+= ' | '+msg else: msg = _('not running') if red: red += '\n '+msg else: red = msg else: if 'openplotter-maiana-read' in test: msg = _('running') if red: red += '\n '+msg else: red = msg else: msg = _('not running') if not black: black = msg else: black+= ' | '+msg return {'green': green,'black': black,'red': red}