class MyFrame(wx.Frame): def __init__(self): self.conf = Conf() self.home = self.conf.home self.currentpath = self.home + self.conf.get( 'GENERAL', 'op_folder') + '/openplotter' Language(self.conf) wx.Frame.__init__(self, None, title=_('SDR receiver'), size=(690, 370)) self.SetFont( wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)) self.icon = wx.Icon(self.currentpath + '/openplotter.ico', wx.BITMAP_TYPE_ICO) self.SetIcon(self.icon) wx.StaticBox(self, label='', size=(400, 170), pos=(10, 10)) self.ais_sdr_enable = wx.CheckBox(self, label=_('Enable AIS reception'), pos=(20, 25)) self.ais_sdr_enable.Bind(wx.EVT_CHECKBOX, self.OnOffAIS) self.gain = wx.TextCtrl(self, -1, size=(55, 32), pos=(150, 60)) self.gain_label = wx.StaticText(self, label=_('Gain'), pos=(20, 65)) self.ppm = wx.TextCtrl(self, -1, size=(55, 32), pos=(150, 95)) self.correction_label = wx.StaticText(self, label=_('Correction (ppm)'), pos=(20, 100)) self.ais_frequencies1 = wx.CheckBox(self, label=_('Channel A 161.975Mhz'), pos=(220, 60)) self.ais_frequencies1.Bind(wx.EVT_CHECKBOX, self.ais_frequencies) self.ais_frequencies2 = wx.CheckBox(self, label=_('Channel B 162.025Mhz'), pos=(220, 95)) self.ais_frequencies2.Bind(wx.EVT_CHECKBOX, self.ais_frequencies) #self.show_kplex6 =wx.Button(self, label=_('Inspector'), pos=(20, 140)) #self.Bind(wx.EVT_BUTTON, self.show_kplex, self.show_kplex6) self.button_test_ppm = wx.Button(self, label=_('Take a look'), pos=(150, 140)) self.Bind(wx.EVT_BUTTON, self.test_ppm, self.button_test_ppm) self.button_test_gain = wx.Button(self, label=_('Calibration'), pos=(275, 140)) self.Bind(wx.EVT_BUTTON, self.test_gain, self.button_test_gain) wx.StaticBox(self, label=_(' Fine calibration using GSM '), size=(260, 170), pos=(420, 10)) self.bands_label = wx.StaticText(self, label=_('Band'), pos=(430, 50)) self.bands_list = ['GSM850', 'GSM-R', 'GSM900', 'EGSM', 'DCS', 'PCS'] self.band = wx.ComboBox(self, choices=self.bands_list, style=wx.CB_READONLY, size=(100, 32), pos=(430, 70)) self.band.SetValue('GSM900') self.check_bands = wx.Button(self, label=_('Check band'), pos=(540, 70)) self.Bind(wx.EVT_BUTTON, self.check_band, self.check_bands) self.channel_label = wx.StaticText(self, label=_('Channel'), pos=(430, 125)) self.channel = wx.TextCtrl(self, -1, size=(55, 32), pos=(430, 143)) self.check_channels = wx.Button(self, label=_('Fine calibration'), pos=(495, 140)) self.Bind(wx.EVT_BUTTON, self.check_channel, self.check_channels) wx.StaticBox(self, label=_(' Radio '), size=(260, 120), pos=(420, 185)) self.button_vhf_Rx = wx.Button(self, label='Gqrx', pos=(430, 210)) self.Bind(wx.EVT_BUTTON, self.vhf_Rx, self.button_vhf_Rx) self.CreateStatusBar() self.Centre() self.Show(True) output = subprocess.check_output('lsusb') supported_dev = [ '0bda:2832', '0bda:2838', '0ccd:00a9', '0ccd:00b3', '0ccd:00d3', '0ccd:00d4', '0ccd:00e0', '185b:0620', '185b:0650', '1f4d:b803', '1f4d:c803', '1b80:d3a4', '1d19:1101', '1d19:1102', '1d19:1103', '0458:707f', '1b80:d393', '1b80:d394', '1b80:d395', '1b80:d39d' ] found = False for i in supported_dev: if i in output: found = True if found: self.gain.SetValue(self.conf.get('AIS-SDR', 'gain')) self.ppm.SetValue(self.conf.get('AIS-SDR', 'ppm')) self.band.SetValue(self.conf.get('AIS-SDR', 'band')) self.channel.SetValue(self.conf.get('AIS-SDR', 'gsm_channel')) if self.conf.get('AIS-SDR', 'enable') == '1': self.ais_sdr_enable.SetValue(True) self.disable_sdr_controls() if self.conf.get('AIS-SDR', 'channel') == 'a': self.ais_frequencies1.SetValue(True) if self.conf.get('AIS-SDR', 'channel') == 'b': self.ais_frequencies2.SetValue(True) else: self.ais_sdr_enable.Disable() self.disable_sdr_controls() self.button_test_gain.Disable() self.button_test_ppm.Disable() self.bands_label.Disable() self.channel_label.Disable() self.band.Disable() self.channel.Disable() self.check_channels.Disable() self.check_bands.Disable() self.button_vhf_Rx.Disable() def kill_sdr(self): subprocess.call(['pkill', '-9', 'aisdecoder']) subprocess.call(['pkill', '-9', 'rtl_fm']) subprocess.call(['pkill', '-f', 'SDR_AIS_waterfall.py']) subprocess.call(['pkill', '-f', 'SDR_AIS_fine_cal.py']) subprocess.call(['pkill', '-9', 'rtl_test']) subprocess.call(['pkill', '-9', 'kal']) subprocess.call(['pkill', '-9', 'gqrx']) def enable_sdr_controls(self): self.gain.Enable() self.ppm.Enable() self.ais_frequencies1.Enable() self.ais_frequencies2.Enable() self.gain_label.Enable() self.correction_label.Enable() self.ais_sdr_enable.SetValue(False) self.conf.set('AIS-SDR', 'enable', '0') def disable_sdr_controls(self): self.gain.Disable() self.ppm.Disable() self.ais_frequencies1.Disable() self.ais_frequencies2.Disable() self.gain_label.Disable() self.correction_label.Disable() def ais_frequencies(self, e): sender = e.GetEventObject() self.ais_frequencies1.SetValue(False) self.ais_frequencies2.SetValue(False) sender.SetValue(True) def OnOffAIS(self, e): self.kill_sdr() isChecked = self.ais_sdr_enable.GetValue() if isChecked: self.disable_sdr_controls() gain = self.gain.GetValue() ppm = self.ppm.GetValue() frecuency = '161975000' channel = 'a' if self.ais_frequencies2.GetValue(): frecuency = '162025000' channel = 'b' rtl_fm = subprocess.Popen([ 'rtl_fm', '-f', frecuency, '-g', gain, '-p', ppm, '-s', '48k' ], stdout=subprocess.PIPE) aisdecoder = subprocess.Popen([ 'aisdecoder', '-h', 'localhost', '-p', '10110', '-a', 'file', '-c', 'mono', '-d', '-f', '/dev/stdin' ], stdin=rtl_fm.stdout) self.conf.set('AIS-SDR', 'enable', '1') self.conf.set('AIS-SDR', 'gain', gain) self.conf.set('AIS-SDR', 'ppm', ppm) self.conf.set('AIS-SDR', 'channel', channel) msg = _('SDR-AIS reception enabled') else: self.enable_sdr_controls() self.conf.set('AIS-SDR', 'enable', '0') msg = _('SDR-AIS reception disabled') self.SetStatusText(msg) def test_ppm(self, event): self.kill_sdr() self.enable_sdr_controls() gain = '25' if self.gain.GetValue(): gain = self.gain.GetValue() gain = gain.replace(',', '.') ppm = '0' if self.ppm.GetValue(): ppm = self.ppm.GetValue() ppm = ppm.replace(',', '.') channel = 'a' if self.ais_frequencies2.GetValue(): channel = 'b' w_open = subprocess.Popen([ 'python', self.currentpath + '/tools/SDR_AIS_waterfall.py', gain, ppm, channel ]) msg = _( 'AIS reception disabled. After closing the new window enable AIS reception again.' ) self.SetStatusText(msg) def test_gain(self, event): self.kill_sdr() self.enable_sdr_controls() subprocess.Popen(['lxterminal', '-e', 'rtl_test', '-p']) msg = _( 'SDR-AIS reception disabled.\nCheck the new window. Copy the maximum supported gain value. Wait for ppm value to stabilize and copy it too.' ) self.ShowMessage(msg) def check_band(self, event): self.kill_sdr() self.enable_sdr_controls() gain = self.gain.GetValue() ppm = self.ppm.GetValue() band = self.band.GetValue() self.conf.set('AIS-SDR', 'gain', gain) self.conf.set('AIS-SDR', 'ppm', ppm) self.conf.set('AIS-SDR', 'band', band) subprocess.Popen( ['python', self.currentpath + '/tools/SDR_AIS_fine_cal.py', 'b']) msg = _( 'AIS reception disabled. After closing the new window enable AIS reception again.' ) self.SetStatusText(msg) def check_channel(self, event): self.kill_sdr() self.enable_sdr_controls() gain = self.gain.GetValue() ppm = self.ppm.GetValue() channel = self.channel.GetValue() self.conf.set('AIS-SDR', 'gain', gain) self.conf.set('AIS-SDR', 'ppm', ppm) self.conf.set('AIS-SDR', 'gsm_channel', channel) if channel: subprocess.Popen([ 'python', self.currentpath + '/tools/SDR_AIS_fine_cal.py', 'c' ]) msg = _( 'AIS reception disabled. After closing the new window enable AIS reception again.' ) self.SetStatusText(msg) def vhf_Rx(self, event): self.kill_sdr() self.enable_sdr_controls() subprocess.Popen(self.home + '/.config/gqrx/run_gqrx.sh') msg = _( 'AIS reception disabled. After closing the new window enable AIS reception again.' ) self.SetStatusText(msg) def ShowMessage(self, w_msg): wx.MessageBox(w_msg, 'Info', wx.OK | wx.ICON_INFORMATION)
def on_setup(event): time.sleep(0.1) context = pyudev.Context() tty_list = [] index = 0 conf = Conf() home = conf.home subprocess.call(["pkill", '-f', "signalk-server-node"]) subprocess.call(["pkill", '-9', "kplex"]) subprocess.call(['pkill', '-f', '1w_d.py']) subprocess.call(['pkill', '-f', 'read_sensors_d.py']) subprocess.call(['pkill', '-f', 'mqtt_d.py']) subprocess.call(['pkill', '-f', 'SK-base_d.py']) subprocess.call(['pkill', '-f', 'N2K-server_d.py']) conf_list = [] data = conf.get('UDEV', 'usbinst') try: temp_list = eval(data) except: temp_list = [] for ii in temp_list: conf_list.append(ii) print print 'search for tty devices' for device in context.list_devices(subsystem='tty'): # print(device) imfd = '' ivfd = '' id_bus = '' id_vendor_id = 'internal' id_modell_id = '' id_serial_short = '' devname = '' devpath = '' if 'ID_MODEL_FROM_DATABASE' in device: imfd = device['ID_MODEL_FROM_DATABASE'] if 'ID_VENDOR_FROM_DATABASE' in device: ivfd = device['ID_VENDOR_FROM_DATABASE'] if 'ID_MODEL_ID' in device: id_modell_id = device['ID_MODEL_ID'] if 'ID_VENDOR_ID' in device: id_vendor_id = device['ID_VENDOR_ID'] if 'ID_SERIAL_SHORT' in device: id_serial_short = device['ID_SERIAL_SHORT'] if 'ID_BUS' in device: id_bus = device['ID_BUS'] if 'DEVNAME' in device: devname = device['DEVNAME'] if 'DEVPATH' in device: devpath = device['DEVPATH'] if 'platform' in devpath or id_bus == 'usb': devpath = devpath[:-(len(devpath) - devpath.find('/tty'))] devpath = devpath[devpath.rfind('/') + 1:] if devname != '/dev/ttyAMA0': print 'found:', devname, id_vendor_id, id_modell_id, id_serial_short, devpath, imfd, ivfd tty_list.append([ '', str(id_vendor_id), str(id_modell_id), str(id_serial_short), str(devpath), 'dev', str(devname[5:11]), str(devname), str(imfd), str(ivfd), 0 ]) # for item in device: # print(item,device[item]) # print(' '+str(item)+':'+str(device[item])) index += 1 print print 'sort tty devices' list_new = [] for i in sorted(tty_list, key=lambda item: (item[2])): list_new.append(i) tty_list = list_new list_new = [] for i in sorted(tty_list, key=lambda item: (item[1])): list_new.append(i) tty_list = list_new list_new = [] for i in sorted(tty_list, key=lambda item: (item[0])): list_new.append(i) tty_list = list_new print print 'check if we have to switch from dev to port' t0 = 'x' t1 = 'x' t2 = 'x' safe = 0 index = 0 for i in tty_list: print 'test ', i if t0 == i[0] and t1 == i[1] and t2 == i[2]: tty_list[safe][5] = 'port' i[5] = 'port' else: t0 = i[0] t1 = i[1] t2 = i[2] safe = index index += 1 print print 'search for NMEA0183 in tty devices' print wx.Yield() # self.update() baudrate_list = ['4800', '38400', '115200', '9600', '19200', '57600'] baudrate_listN2K = ['115200'] auto = AutoDetect() for i in tty_list: for baud in baudrate_list: wx.Yield() if i[10] == 0: if auto.readNMEA0183(i[7], baud): i[10] = str(baud) baud = baudrate_list[-1] print print 'create an autoname for found NMEA0183 devices' for i in tty_list: if i[10] != 0: index = 0 ttyname = 'ttyOP_' + auto.readNMEA0183name(i[7], i[10]) for j in tty_list: if ttyname in j[6]: index += 1 if index != 0: i[0] = str(ttyname + str(index)) else: i[0] = str(ttyname) print 'created the name:', i[0] print print 'search for NMEA2000 in tty devices' wx.Yield() for i in tty_list: if i[7] != '/dev/ttyAMA0' and i[0] == '': print i for baud in baudrate_listN2K: print 'n2k', i, baud wx.Yield() if i[10] == 0: print 'start' wx.Yield() if auto.readNMEA2000(i[7], baud): i[10] = str(baud) i[0] = 'ttyOP_N2K' baud = baudrate_listN2K[-1] i = tty_list[-1] print 'ja' wx.Yield() # break print print '########################## result ################################' wx.Yield() print print 'add new devices to openplotter.conf' data = '' for i in tty_list: if i[10] != 0: exists = False print i for ii in conf_list: if (i[1] == ii[1] and i[2] == ii[2] and i[3] == ii[3]) and i[5] != 'port': exists = True if not exists: for ii in conf_list: if i[0] == ii[0]: exists = True if not exists: conf_list.append( [i[0], i[1], i[2], i[3], i[4], i[5], i[6]]) data += str([i[0], i[1], i[2], i[3], i[4], i[5], i[6] ]) + ',' i[6] = 1 else: print 'The auto created name ' + i[0] + ' already exists' i[10] = 0 if len(data) > 0: print '[UDEV]' print 'usbinst = [' print data[:-1] + ']' else: print '- none -' conf.set('UDEV', 'usbinst', str(conf_list)) for i in tty_list: if 'ttyOP_N2K' == i[0]: if len(conf.get('N2K', 'can_usb')) < 3: conf.set('N2K', 'can_usb', '/dev/ttyOP_N2K') conf.set('N2K', 'enable', '1') print '[N2K]' print 'enable = 1' print 'can_usb = /dev/ttyOP_N2K' print print 'add new devices to kplex (not activated and no filter)' f1 = open(home + '/.kplex.conf', 'r') data = f1.readlines() f1.close() dataa = '' for i in tty_list: if i[6] == 1 and i[0] != 'ttyOP_N2K': auto_name = 'auto_' + i[0][6:].lower() exists = False for index, item in enumerate(data): if auto_name in item: exists = True if not exists: dataa += '#[serial]\n' dataa += '#name=' + auto_name + '\n' dataa += '#direction=in\n' dataa += '#optional=yes\n' dataa += '#filename=/dev/' + i[0] + '\n' dataa += '#baud=' + str(i[10]) + '\n\n' if dataa == '': print '- none -' else: print dataa newdata = '' for index, item in enumerate(data): if '###end of OpenPlotter GUI settings' in item: newdata += dataa newdata += item f1 = open(home + '/.kplex.conf', 'w') f1.write(newdata) f1.close()
class MyForm(wx.Frame): def __init__(self): self.serial = 0 self.conf = Conf() Language(self.conf) wx.Frame.__init__(self, None, wx.ID_ANY, _('tty auto setup'), size=(720, 350)) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) log = wx.TextCtrl(panel, wx.ID_ANY, style=wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL) self.autostart = wx.CheckBox(panel, label=_('setup autostart on every boot')) self.autostart.Bind(wx.EVT_CHECKBOX, self.on_autostart) setup = wx.Button(panel, wx.ID_ANY, 'setup') setup.Bind(wx.EVT_BUTTON, on_setup) close = wx.Button(panel, wx.ID_CLOSE) close.Bind(wx.EVT_BUTTON, self.on_close) # Add widgets to a sizer hbox = wx.BoxSizer(wx.HORIZONTAL) hbox.Add(self.autostart, 0, wx.ALL | wx.EXPAND, 5) hbox.Add((0, 0), 1, wx.ALL | wx.EXPAND, 5) hbox.Add(setup, 0, wx.ALL | wx.EXPAND, 5) hbox.Add(close, 0, wx.ALL | wx.EXPAND, 5) vbox = wx.BoxSizer(wx.VERTICAL) vbox.Add(log, 1, wx.ALL | wx.EXPAND, 5) vbox.Add(hbox, 0, wx.ALL | wx.CENTER | wx.EXPAND, 5) panel.SetSizer(vbox) self.tool_list = [] data = self.conf.get('TOOLS', 'py') try: temp_list = eval(data) except: temp_list = [] for ii in temp_list: self.tool_list.append(ii) self.tool = [] self.tool_exist = False for i in self.tool_list: if i[2] == 'autosetup_tty.py': self.autostart.SetValue(i[3] == '1') self.tool.append(i) self.tool_exist = True # redirect text here redir = RedirectText(log) sys.stdout = redir print _( 'Auto setup detects hardware. Please make sure that all devices are turned on.' ) print def on_autostart(self, event): if self.tool_exist: if self.autostart.GetValue(): self.tool[0][3] = '1' else: self.tool[0][3] = '0' self.conf.set('TOOLS', 'py', str(self.tool_list)) def on_close(self, event): self.Close()
class ConfTestCase(unittest.TestCase): _default_directory = Path.home().joinpath('.svsoft') _default_file_name = 'budgeton.cfg' @classmethod def setUpClass(self): self._cnf = Conf() @classmethod def tearDownClass(self): pass def setUp(self): pass def tearDown(self): pass def delete_all(self): try: # remove all files in directory .svsoft for current_file in os.listdir(self._default_directory): os.remove(self._default_directory.joinpath(current_file)) except FileNotFoundError: pass try: # remove file os.rmdir(self._default_directory) except FileNotFoundError: pass pass def test_creation_file(self): # delete directory if exist self.delete_all() # test if deleted correctly self.assertEqual(self._default_directory.exists(), False) self._cnf = Conf() # test if created correctly self.assertEqual(self._default_directory.exists(), True) # directory self.assertEqual( self._default_directory.joinpath(self._default_file_name).exists(), True) #file def test_init_values(self): self.assertEqual(self._cnf.get('last_opened'), False) def test_if_property_not_exist_is_none(self): self.assertEqual(self._cnf.get("another_random_property"), None) def test_save_method(self): self._cnf.set('toto', True) self.assertEqual(self._cnf.get('toto'), True) f = open(self._default_directory.joinpath(self._default_file_name), 'r', encoding='utf-8') content = f.read() json_obj = json.loads(content) self.assertEqual(json_obj['toto'], True) f.close()
class MyFrame(wx.Frame): def __init__(self): self.conf = Conf() self.home = self.conf.home self.op_folder = self.conf.get('GENERAL', 'op_folder') self.help_bmp = wx.Bitmap( self.op_folder + "/static/icons/help-browser.png", wx.BITMAP_TYPE_ANY) Language(self.conf) self.SK_settings = SK_settings(self.conf) self.opencpnSettings = opencpnSettings() wx.Frame.__init__(self, None, title=_('SDR receiver'), size=(710, 380)) self.SetFont( wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)) self.icon = wx.Icon(self.op_folder + '/static/icons/sdr.ico', wx.BITMAP_TYPE_ICO) self.SetIcon(self.icon) calibrationbox = wx.StaticBox(self, label=_(' Calibration ')) self.button_test_gain = wx.Button(self, label=_('Initial PPM')) self.Bind(wx.EVT_BUTTON, self.test_gain, self.button_test_gain) bands_label = wx.StaticText(self, label=_('Band')) bands_list = ['GSM850', 'GSM-R', 'GSM900', 'EGSM', 'DCS', 'PCS'] self.band = wx.ComboBox(self, choices=bands_list, style=wx.CB_READONLY) self.check_bands = wx.Button(self, label=_('Get channel')) self.Bind(wx.EVT_BUTTON, self.check_band, self.check_bands) channel_label = wx.StaticText(self, label=_('Channel')) self.channel = wx.TextCtrl(self) self.check_channels = wx.Button(self, label=_('Get PPM')) self.Bind(wx.EVT_BUTTON, self.check_channel, self.check_channels) correction_label = wx.StaticText(self, label=_('PPM')) self.ppm = wx.TextCtrl(self) self.button_saveppm = wx.Button(self, label=_('Save PPM')) self.Bind(wx.EVT_BUTTON, self.on_saveppm, self.button_saveppm) aisbox = wx.StaticBox(self, label=' AIS ') self.ais_sdr_enable = wx.CheckBox(self, label=_('Enable')) self.ais_sdr_enable.Bind(wx.EVT_CHECKBOX, self.OnOffAIS) self.button_checkppm = wx.Button(self, label=_('Check AIS frequency')) self.Bind(wx.EVT_BUTTON, self.on_checkppm, self.button_checkppm) radiobox = wx.StaticBox(self, label=_(' Radio ')) self.button_radio_default = wx.Button(self, label=_('Load defaults')) self.Bind(wx.EVT_BUTTON, self.on_radio_default, self.button_radio_default) self.button_radio_16 = wx.Button(self, label=_('Channel 16')) self.Bind(wx.EVT_BUTTON, self.on_radio_16, self.button_radio_16) self.button_radio_9 = wx.Button(self, label=_('Channel 9')) self.Bind(wx.EVT_BUTTON, self.on_radio_9, self.button_radio_9) self.frequency = wx.SpinCtrl(self, min=24000000, max=1766000000, initial=156800000) self.button_radio_freq = wx.Button(self, label=_('Frequency')) self.Bind(wx.EVT_BUTTON, self.on_radio_freq, self.button_radio_freq) help_button = wx.BitmapButton(self, bitmap=self.help_bmp, size=(self.help_bmp.GetWidth() + 40, self.help_bmp.GetHeight() + 10)) help_button.Bind(wx.EVT_BUTTON, self.on_help_sdr) self.CreateStatusBar() self.Centre() self.Show(True) ppm = self.conf.get('AIS-SDR', 'ppm') if not ppm: self.ppm.SetValue('0') else: self.ppm.SetValue(ppm) self.band.SetValue(self.conf.get('AIS-SDR', 'band')) self.channel.SetValue(self.conf.get('AIS-SDR', 'gsm_channel')) if self.conf.get('AIS-SDR', 'enable') == '1': self.ais_sdr_enable.SetValue(True) self.disable_sdr_controls() h_calibration1 = wx.BoxSizer(wx.HORIZONTAL) h_calibration1.AddSpacer(10) h_calibration1.Add(self.button_test_gain, 0, wx.RIGHT, 15) h_calibration1.Add(bands_label, 0, wx.TOP, 6) h_calibration1.Add(self.band, 0, wx.LEFT | wx.RIGHT, 5) h_calibration1.Add(self.check_bands, 0, wx.LEFT | wx.RIGHT, 5) h_calibration1.AddSpacer(10) h_calibration1.Add(channel_label, 0, wx.TOP, 6) h_calibration1.Add(self.channel, 0, wx.LEFT | wx.RIGHT, 5) h_calibration1.Add(self.check_channels, 0, wx.LEFT | wx.RIGHT, 5) h_calibration2 = wx.BoxSizer(wx.HORIZONTAL) h_calibration2.Add(correction_label, 0, wx.TOP, 6) h_calibration2.Add(self.ppm, 0, wx.LEFT | wx.RIGHT, 5) h_calibration2.Add(self.button_saveppm, 0, wx.LEFT | wx.RIGHT, 5) v_calibrationbox = wx.StaticBoxSizer(calibrationbox, wx.VERTICAL) v_calibrationbox.Add(h_calibration1, 0, wx.UP | wx.BOTTOM, 10) v_calibrationbox.Add(h_calibration2, 0, wx.LEFT | wx.BOTTOM, 10) h_aisbox = wx.StaticBoxSizer(aisbox, wx.HORIZONTAL) h_aisbox.Add(self.ais_sdr_enable, 0, wx.ALL, 10) h_aisbox.Add(self.button_checkppm, 0, wx.ALL, 10) h_radiobox = wx.StaticBoxSizer(radiobox, wx.HORIZONTAL) h_radiobox.Add(self.button_radio_default, 0, wx.ALL, 10) h_radiobox.Add(self.button_radio_9, 0, wx.ALL, 10) h_radiobox.Add(self.button_radio_16, 0, wx.ALL, 10) h_radiobox.AddSpacer(10) h_radiobox.Add(self.frequency, 0, wx.UP, 10) h_radiobox.AddSpacer(5) h_radiobox.Add(self.button_radio_freq, 0, wx.UP, 10) vbox = wx.BoxSizer(wx.VERTICAL) vbox.AddSpacer(5) vbox.Add(v_calibrationbox, 0, wx.ALL | wx.EXPAND, 5) vbox.Add(h_aisbox, 0, wx.ALL | wx.EXPAND, 5) vbox.Add(h_radiobox, 0, wx.ALL | wx.EXPAND, 5) vbox.AddStretchSpacer(1) vbox.Add(help_button, 0, wx.LEFT | wx.BOTTOM, 10) self.SetSizer(vbox) def kill_sdr(self): subprocess.call(['pkill', '-15', 'rtl_ais']) subprocess.call(['pkill', '-f', 'SDR_AIS_fine_cal.py']) subprocess.call(['pkill', '-15', 'rtl_test']) subprocess.call(['pkill', '-15', 'kal']) subprocess.call(['pkill', '-15', 'gqrx']) def enable_sdr_controls(self): self.ppm.Enable() self.button_test_gain.Enable() self.button_saveppm.Enable() self.button_checkppm.Enable() self.band.Enable() self.channel.Enable() self.check_bands.Enable() self.check_channels.Enable() self.button_radio_default.Enable() self.button_radio_9.Enable() self.button_radio_16.Enable() self.button_radio_freq.Enable() self.frequency.Enable() def disable_sdr_controls(self): self.ppm.Disable() self.button_test_gain.Disable() self.button_saveppm.Disable() self.button_checkppm.Disable() self.band.Disable() self.channel.Disable() self.check_bands.Disable() self.check_channels.Disable() self.button_radio_default.Disable() self.button_radio_9.Disable() self.button_radio_16.Disable() self.button_radio_freq.Disable() self.frequency.Disable() def OnOffAIS(self, e): self.kill_sdr() isChecked = self.ais_sdr_enable.GetValue() if isChecked: self.disable_sdr_controls() ppm = self.ppm.GetValue() try: int(ppm) except: self.ShowStatusBarRED(_('Failed. Wrong PPM')) return subprocess.Popen(['rtl_ais', '-R', '-p', ppm]) self.conf.set('AIS-SDR', 'enable', '1') self.on_saveppm(0) msg = _('SDR-AIS reception enabled') opencpn = self.opencpnSettings.getConnectionState() if not opencpn: msg = _( 'Failed. The default OpenCPN connection is missing: input TCP localhost:10110' ) elif opencpn == 'disabled': msg = _( 'Failed. The default OpenCPN connection is disabled: input TCP localhost:10110' ) else: self.enable_sdr_controls() self.conf.set('AIS-SDR', 'enable', '0') msg = _('SDR-AIS reception disabled') if self.SK_settings.setSKsettings(): seconds = 12 subprocess.call(['sudo', 'systemctl', 'stop', 'signalk.service']) subprocess.call(['sudo', 'systemctl', 'stop', 'signalk.socket']) subprocess.call(['sudo', 'systemctl', 'start', 'signalk.socket']) subprocess.call(['sudo', 'systemctl', 'start', 'signalk.service']) for i in range(seconds, 0, -1): self.ShowStatusBarRED( _('Restarting Signal K server... ') + str(i)) time.sleep(1) self.ShowStatusBarBLACK(msg) def test_gain(self, event): self.kill_sdr() subprocess.Popen(['lxterminal', '-e', 'rtl_test', '-p']) msg = _( 'Wait for "cumulative PPM" value to stabilize and copy it into "PPM" field' ) self.ShowStatusBarBLACK(msg) def check_band(self, event): self.kill_sdr() band = self.band.GetValue() self.on_saveppm(0) self.conf.set('AIS-SDR', 'band', band) subprocess.Popen([ 'python', self.op_folder + '/tools/SDR_AIS/SDR_AIS_fine_cal.py', 'b' ]) msg = _( 'Select the GSM band used in your country to get the strongest channel' ) self.ShowStatusBarBLACK(msg) def check_channel(self, event): self.kill_sdr() channel = self.channel.GetValue() try: int(channel) except: self.ShowStatusBarRED(_('Failed. Wrong channel')) return self.on_saveppm(0) self.conf.set('AIS-SDR', 'gsm_channel', channel) if channel: subprocess.Popen([ 'python', self.op_folder + '/tools/SDR_AIS/SDR_AIS_fine_cal.py', 'c' ]) msg = _('Use the strongest channel to calculate the final PPM') self.ShowStatusBarBLACK(msg) def on_radio_default(self, event): self.kill_sdr() subprocess.call([ 'cp', '-f', self.op_folder + '/tools/SDR_AIS/default.conf', self.home + '/.config/gqrx/' ]) self.open_gqrx() def on_radio_16(self, event): self.kill_sdr() self.setconf('156800000') self.open_gqrx() def on_radio_9(self, event): self.kill_sdr() self.setconf('156450000') self.open_gqrx() def on_radio_freq(self, event): self.kill_sdr() self.setconf(self.frequency.GetValue()) self.open_gqrx() def on_checkppm(self, event): self.kill_sdr() self.on_saveppm(0) self.setconf('162025000') self.open_gqrx() def setconf(self, frequency): self.gqrx_conf = ConfigParser.SafeConfigParser() self.gqrx_conf.read(self.home + '/.config/gqrx/default.conf') try: self.gqrx_conf.set('General', 'crashed', 'false') except ConfigParser.NoSectionError: self.gqrx_conf.add_section('General') self.gqrx_conf.set('General', 'crashed', 'false') try: self.gqrx_conf.set('input', 'frequency', str(frequency)) except ConfigParser.NoSectionError: self.gqrx_conf.add_section('input') self.gqrx_conf.set('input', 'frequency', str(frequency)) try: self.gqrx_conf.set('receiver', 'demod', '3') except ConfigParser.NoSectionError: self.gqrx_conf.add_section('receiver') self.gqrx_conf.set('receiver', 'demod', '3') with open(self.home + '/.config/gqrx/default.conf', 'wb') as configfile: self.gqrx_conf.write(configfile) def on_saveppm(self, event): ppm = self.ppm.GetValue() try: ppm2 = int(ppm) * 1000000 except: self.ShowStatusBarRED(_('Failed. Wrong PPM')) return self.gqrx_conf = ConfigParser.SafeConfigParser() self.gqrx_conf.read(self.home + '/.config/gqrx/default.conf') try: self.gqrx_conf.set('input', 'corr_freq', str(ppm2)) except ConfigParser.NoSectionError: self.gqrx_conf.add_section('input') self.gqrx_conf.set('input', 'corr_freq', str(ppm2)) with open(self.home + '/.config/gqrx/default.conf', 'wb') as configfile: self.gqrx_conf.write(configfile) self.conf.set('AIS-SDR', 'ppm', ppm) self.ShowStatusBarGREEN(_('Saved PPM')) def open_gqrx(self): subprocess.Popen('gqrx') def on_help_sdr(self, e): url = self.op_folder + "/docs/html/tools/sdr_receiver.html" webbrowser.open(url, new=2) def ShowStatusBar(self, w_msg, colour): self.GetStatusBar().SetForegroundColour(colour) self.SetStatusText(w_msg) def ShowStatusBarRED(self, w_msg): self.ShowStatusBar(w_msg, wx.RED) def ShowStatusBarGREEN(self, w_msg): self.ShowStatusBar(w_msg, wx.GREEN) def ShowStatusBarBLACK(self, w_msg): self.ShowStatusBar(w_msg, wx.BLACK)
class MyFrame(wx.Frame): def __init__(self): self.conf = Conf() self.home = self.conf.home self.currentpath = self.home+self.conf.get('GENERAL', 'op_folder')+'/openplotter' Language(self.conf) title = _('Calculate') wx.Frame.__init__(self, None, title=title, size=(690,400)) self.SetFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)) self.icon = wx.Icon(self.currentpath+'/openplotter.ico', wx.BITMAP_TYPE_ICO) self.SetIcon(self.icon) rate_list = ['0.1', '0.25', '0.5', '0.75', '1', '1.5', '2', '5', '30', '60', '300'] panel = wx.Panel(self) mg_box = wx.StaticBox(panel, -1, _(' Magnetic variation ')) self.mag_var = wx.CheckBox(panel, -1, label=_('Enable')) mg_requires = wx.StaticText(panel, label=_('Requires: position, date.')) mg_accu_label = wx.StaticText(panel, label=_('Accuracy (sec)')) self.mg_accu= wx.ComboBox(panel, choices=rate_list, style=wx.CB_READONLY) mg_rate_label = wx.StaticText(panel, label=_('Rate (sec)')) self.mg_rate= wx.ComboBox(panel, choices=rate_list, style=wx.CB_READONLY) rt_box = wx.StaticBox(panel, -1, _(' Rate of turn ')) self.rate_turn = wx.CheckBox(panel, -1, label=_('Enable')) rt_requires = wx.StaticText(panel, label=_('Requires: magnetic heading.')) rt_accu_label = wx.StaticText(panel, label=_('Accuracy (sec)')) self.rt_accu= wx.ComboBox(panel, choices=rate_list, style=wx.CB_READONLY) rt_rate_label = wx.StaticText(panel, label=_('Rate (sec)')) self.rt_rate= wx.ComboBox(panel, choices=rate_list, style=wx.CB_READONLY) th_box = wx.StaticBox(panel, -1, _(' True heading ')) self.heading_t = wx.CheckBox(panel, -1, label=_('Deviation is included')) self.heading_t.Bind(wx.EVT_CHECKBOX, self.on_select_th) th_requires = wx.StaticText(panel, label=_('Requires: magnetic heading, variation.')) self.add_deviation = wx.CheckBox(panel, -1, label=_('Add deviation table')) self.add_deviation.Bind(wx.EVT_CHECKBOX, self.on_select_th) th_requires2 = wx.StaticText(panel, label=_('Requires: magnetic heading, variation, deviation.')) th_accu_label = wx.StaticText(panel, label=_('Accuracy (sec)')) self.th_accu= wx.ComboBox(panel, choices=rate_list, style=wx.CB_READONLY) th_rate_label = wx.StaticText(panel, label=_('Rate (sec)')) self.th_rate= wx.ComboBox(panel, choices=rate_list, style=wx.CB_READONLY) tw_box = wx.StaticBox(panel, -1, _(' True wind speed and direction ')) self.true_wind = wx.CheckBox(panel, -1, label=_('Use Speed Through Water')) self.true_wind.Bind(wx.EVT_CHECKBOX, self.on_select_tw) tw_requires = wx.StaticText(panel, label=_('Requires: SignalK STW, AWS, AWA.')) self.true_wind2 = wx.CheckBox(panel, -1, label=_('Use Speed Over Ground')) self.true_wind2.Bind(wx.EVT_CHECKBOX, self.on_select_tg) tw_requires2 = wx.StaticText(panel, label=_('Requires: SignalK SOG, COG, HDT, AWS, AWA.')) tw_accu_label = wx.StaticText(panel, label=_('Accuracy (sec)')) self.tw_accu= wx.ComboBox(panel, choices=rate_list, style=wx.CB_READONLY) tw_rate_label = wx.StaticText(panel, label=_('Rate (sec)')) self.tw_rate= wx.ComboBox(panel, choices=rate_list, style=wx.CB_READONLY) button_cancel =wx.Button(panel, label=_('Cancel')) self.Bind(wx.EVT_BUTTON, self.on_cancel, button_cancel) button_ok =wx.Button(panel, label=_('OK')) self.Bind(wx.EVT_BUTTON, self.on_ok, button_ok) #self.true_wind.Disable() #self.true_wind2.Disable() mg_boxSizer = wx.StaticBoxSizer(mg_box, wx.VERTICAL) mg_boxSizer.Add(self.mag_var, 0, wx.ALL | wx.EXPAND, 5) mg_boxSizer.Add(mg_requires, 0, wx.LEFT | wx.EXPAND, 5) mg_h = wx.BoxSizer(wx.HORIZONTAL) mg_h.Add(mg_rate_label, 0, wx.UP | wx.EXPAND, 10) mg_h.Add(self.mg_rate, 0, wx.ALL | wx.EXPAND, 5) mg_h.Add(mg_accu_label, 0, wx.UP | wx.EXPAND, 10) mg_h.Add(self.mg_accu, 0, wx.ALL | wx.EXPAND, 5) mg_boxSizer.Add(mg_h, 0, wx.ALL | wx.EXPAND, 5) rt_boxSizer = wx.StaticBoxSizer(rt_box, wx.VERTICAL) rt_boxSizer.Add(self.rate_turn, 0, wx.ALL | wx.EXPAND, 5) rt_boxSizer.Add(rt_requires, 0, wx.LEFT | wx.EXPAND, 5) rt_h = wx.BoxSizer(wx.HORIZONTAL) rt_h.Add(rt_rate_label, 0, wx.UP | wx.EXPAND, 10) rt_h.Add(self.rt_rate, 0, wx.ALL | wx.EXPAND, 5) rt_h.Add(rt_accu_label, 0, wx.UP | wx.EXPAND, 10) rt_h.Add(self.rt_accu, 0, wx.ALL | wx.EXPAND, 5) rt_boxSizer.Add(rt_h, 0, wx.ALL | wx.EXPAND, 5) th_boxSizer = wx.StaticBoxSizer(th_box, wx.VERTICAL) th_boxSizer.Add(self.heading_t, 0, wx.ALL | wx.EXPAND, 5) th_boxSizer.Add(th_requires, 0, wx.LEFT | wx.EXPAND, 5) th_boxSizer.Add(self.add_deviation, 0, wx.ALL | wx.EXPAND, 5) th_boxSizer.Add(th_requires2, 0, wx.LEFT | wx.EXPAND, 5) th_h = wx.BoxSizer(wx.HORIZONTAL) th_h.Add(th_rate_label, 0, wx.UP | wx.EXPAND, 10) th_h.Add(self.th_rate, 0, wx.ALL | wx.EXPAND, 5) th_h.Add(th_accu_label, 0, wx.UP | wx.EXPAND, 10) th_h.Add(self.th_accu, 0, wx.ALL | wx.EXPAND, 5) th_boxSizer.Add(th_h, 0, wx.ALL | wx.EXPAND, 5) tw_boxSizer = wx.StaticBoxSizer(tw_box, wx.VERTICAL) tw_boxSizer.Add(self.true_wind, 0, wx.ALL | wx.EXPAND, 5) tw_boxSizer.Add(tw_requires, 0, wx.LEFT | wx.EXPAND, 5) tw_boxSizer.Add(self.true_wind2, 0, wx.ALL | wx.EXPAND, 5) tw_boxSizer.Add(tw_requires2, 0, wx.LEFT | wx.EXPAND, 5) tw_h = wx.BoxSizer(wx.HORIZONTAL) tw_h.Add(tw_rate_label, 0, wx.UP | wx.EXPAND, 10) tw_h.Add(self.tw_rate, 0, wx.ALL | wx.EXPAND, 5) tw_h.Add(tw_accu_label, 0, wx.UP | wx.EXPAND, 10) tw_h.Add(self.tw_accu, 0, wx.ALL | wx.EXPAND, 5) tw_boxSizer.Add(tw_h, 0, wx.ALL | wx.EXPAND, 5) vbox = wx.BoxSizer(wx.VERTICAL) vbox.Add(mg_boxSizer, 0, wx.ALL | wx.EXPAND, 5) vbox.Add(tw_boxSizer, 0, wx.ALL | wx.EXPAND, 5) vbox2 = wx.BoxSizer(wx.VERTICAL) vbox2.Add(th_boxSizer, 0, wx.ALL | wx.EXPAND, 5) vbox2.Add(rt_boxSizer, 0, wx.ALL | wx.EXPAND, 5) hbox = wx.BoxSizer(wx.HORIZONTAL) hbox.Add(vbox, 0, wx.ALL | wx.EXPAND, 0) hbox.Add(vbox2, 0, wx.ALL | wx.EXPAND, 0) hbox2 = wx.BoxSizer(wx.HORIZONTAL) hbox2.Add((0,0), 1, wx.ALL | wx.EXPAND, 0) hbox2.Add(button_cancel, 0, wx.ALL | wx.EXPAND, 10) hbox2.Add(button_ok, 0, wx.ALL | wx.EXPAND, 10) vbox3 = wx.BoxSizer(wx.VERTICAL) vbox3.Add(hbox, 0, wx.ALL | wx.EXPAND, 0) vbox3.Add(hbox2, 0, wx.ALL | wx.EXPAND, 0) panel.SetSizer(vbox3) self.Centre() if self.conf.get('CALCULATE', 'mag_var')=='1': self.mag_var.SetValue(True) self.mg_rate.SetValue(self.conf.get('CALCULATE', 'mag_var_rate')) self.mg_accu.SetValue(self.conf.get('CALCULATE', 'mag_var_accuracy')) if self.conf.get('CALCULATE', 'hdt')=='1': self.heading_t.SetValue(True) if self.conf.get('CALCULATE', 'hdt_dev')=='1': self.add_deviation.SetValue(True) #if self.conf.get('COMPASS', 'magnetic_h')=='1': self.add_deviation.Disable() self.th_rate.SetValue(self.conf.get('CALCULATE', 'hdt_rate')) self.th_accu.SetValue(self.conf.get('CALCULATE', 'hdt_accuracy')) if self.conf.get('CALCULATE', 'rot')=='1': self.rate_turn.SetValue(True) self.rt_rate.SetValue(self.conf.get('CALCULATE', 'rot_rate')) self.rt_accu.SetValue(self.conf.get('CALCULATE', 'rot_accuracy')) if self.conf.get('CALCULATE', 'tw_stw')=='1': self.true_wind.SetValue(True) if self.conf.get('CALCULATE', 'tw_sog')=='1': self.true_wind2.SetValue(True) self.tw_rate.SetValue(self.conf.get('CALCULATE', 'tw_rate')) self.tw_accu.SetValue(self.conf.get('CALCULATE', 'tw_accuracy')) def on_ok(self, e): if self.mag_var.GetValue(): if self.mg_rate.GetValue() and self.mg_accu.GetValue(): self.conf.set('CALCULATE', 'mag_var', '1') self.conf.set('CALCULATE', 'mag_var_rate', self.mg_rate.GetValue()) self.conf.set('CALCULATE', 'mag_var_accuracy', self.mg_accu.GetValue()) else: self.ShowMessage(_('You have to provide rate and accuracy values for magnetic variation')) return else: self.conf.set('CALCULATE', 'mag_var', '0') #if self.conf.get('COMPASS', 'magnetic_h')=='1': self.add_deviation.SetValue(False) if self.heading_t.GetValue() or self.add_deviation.GetValue(): if self.th_rate.GetValue() and self.th_accu.GetValue(): if self.heading_t.GetValue(): self.conf.set('CALCULATE', 'hdt', '1') else: self.conf.set('CALCULATE', 'hdt', '0') if self.add_deviation.GetValue(): self.conf.set('CALCULATE', 'hdt_dev', '1') else: self.conf.set('CALCULATE', 'hdt_dev', '0') self.conf.set('CALCULATE', 'hdt_rate', self.th_rate.GetValue()) self.conf.set('CALCULATE', 'hdt_accuracy', self.th_accu.GetValue()) else: self.ShowMessage(_('You have to provide rate and accuracy values for true heading')) return else: self.conf.set('CALCULATE', 'hdt', '0') self.conf.set('CALCULATE', 'hdt_dev', '0') if self.rate_turn.GetValue(): if self.rt_rate.GetValue() and self.rt_accu.GetValue(): self.conf.set('CALCULATE', 'rot', '1') self.conf.set('CALCULATE', 'rot_rate', self.rt_rate.GetValue()) self.conf.set('CALCULATE', 'rot_accuracy', self.rt_accu.GetValue()) else: self.ShowMessage(_('You have to provide rate and accuracy values for rate of turn')) return else: self.conf.set('CALCULATE', 'rot', '0') if self.true_wind.GetValue() or self.true_wind2.GetValue(): if self.tw_rate.GetValue() and self.tw_accu.GetValue(): if self.true_wind.GetValue(): self.conf.set('CALCULATE', 'tw_stw', '1') else: self.conf.set('CALCULATE', 'tw_stw', '0') if self.true_wind2.GetValue(): self.conf.set('CALCULATE', 'tw_sog', '1') else: self.conf.set('CALCULATE', 'tw_sog', '0') self.conf.set('CALCULATE', 'tw_rate', self.tw_rate.GetValue()) self.conf.set('CALCULATE', 'tw_accuracy', self.tw_accu.GetValue()) else: self.ShowMessage(_('You have to provide rate and accuracy values for true wind speed and direction')) return else: self.conf.set('CALCULATE', 'tw_stw', '0') self.conf.set('CALCULATE', 'tw_sog', '0') subprocess.call(['pkill', '-f', 'SK-base_d.py']) subprocess.Popen(['python', self.currentpath + '/SK-base_d.py']) self.Close() def on_cancel(self, e): self.Close() def ShowMessage(self, w_msg): wx.MessageBox(w_msg, 'Info', wx.OK | wx.ICON_INFORMATION) def on_select_tw(self,e): sender = e.GetEventObject() if sender.GetValue(): self.true_wind2.SetValue(False) self.true_wind.SetValue(True) sender.SetValue(True) else: self.true_wind.SetValue(False) sender.SetValue(False) def on_select_tg(self,e): sender = e.GetEventObject() if sender.GetValue(): self.true_wind.SetValue(False) self.true_wind2.SetValue(True) sender.SetValue(True) else: self.true_wind2.SetValue(False) sender.SetValue(False) def on_select_th(self,e): sender = e.GetEventObject() if sender.GetValue(): self.heading_t.SetValue(False) self.add_deviation.SetValue(False) sender.SetValue(True)
class MyFrame(wx.Frame): def __init__(self): self.conf = Conf() self.home = self.conf.home self.currentpath = self.home + self.conf.get( 'GENERAL', 'op_folder') + '/openplotter' Language(self.conf) wx.Frame.__init__(self, None, title=_('Generate N2K from Signal K'), size=(630, 300)) self.Bind(wx.EVT_CLOSE, self.when_closed) #self.SetAutoLayout(1) #self.SetupScrolling() self.icon = wx.Icon(self.currentpath + '/openplotter.ico', wx.BITMAP_TYPE_ICO) self.SetIcon(self.icon) self.panel = wx.Panel(self) self.list_N2Kgen = [ ['126992', 'System Time', ''], ['127245', 'Rudder', 'steering.rudderAngle.value'], ['127250', 'Heading', 'navigation.headingMagnetic.value'], [ '127257', 'Attitude', 'navigation.attitude.pitch.value, navigation.attitude.roll.value, navigation.attitude.yaw.value' ], ['127488', 'Engine_Rapid', 'propulsion.port.revolutions.value'], [ '127488_1', 'Engine_Rapid', 'propulsion.starboard.revolutions.value' ], [ '127489', 'Engine', 'propulsion.port.oilTemperature.value, propulsion.port.temperature.value' ], [ '127489_1', 'Engine', 'propulsion.starboard.oilTemperature.value, propulsion.starboard.temperature.value' ], [ '127505', 'FluidLevel', 'tanks.fuel.standard.capacity.value, tanks.fuel.standard.currentLevel.value' ], [ '127505_1', 'FluidLevel', 'tanks.liveWell.standard.capacity.value, tanks.liveWell.standard.currentLevel.value' ], [ '127505_2', 'FluidLevel', 'tanks.wasteWater.standard.capacity.value, tanks.wasteWater.standard.currentLevel.value' ], [ '127505_3', 'FluidLevel', 'tanks.blackWater.standard.capacity.value, tanks.blackWater.standard.currentLevel.value' ], [ '127508', 'Battery_Status', 'DC Electrical Properties.dcSource.voltage.value, DC Electrical Properties.dcSource.current.value, DC Electrical Properties.dcSource.temperature.value' ], [ '128259', 'Speed', 'navigation.speedOverGround.value, navigation.speedThroughWater.value' ], [ '128267', 'Depth', 'environment.depth.belowTransducer.value, environment.depth.surfaceToTransducer.value' ], [ '128275', 'Distance_Log', 'navigation.log.value, navigation.logTrip.value' ], [ '129025', 'Position_Rapid', 'navigation.position.latitude, navigation.position.longitude' ], [ '129026', 'COG_SOG', 'navigation.courseOverGroundTrue.value, navigation.speedOverGround.value' ], [ '130306_2', 'Wind Data', 'environment.wind.angleApparent.value, environment.wind.speedApparent.value' ], [ '130306_3', 'Wind Data', 'environment.wind.angleTrueWater.value, environment.wind.speedTrue.value' ], [ '130310', 'Environmental_Parameters', 'environment.outside.pressure.value, environment.outside.temperature.value, environment.water.temperature.value' ], [ '130311', 'Environmental_Parameters', 'environment.outside.pressure.value, environment.inside.humidity.value, environment.water.temperature.value' ], [ '130316', 'Temperature', 'environment.inside.refrigerator.temperature.value' ], [ '130316_1', 'Temperature', 'propulsion.port.exhaustTemperature.value' ] ] self.list_N2K = CheckListCtrl(self.panel, 100) self.list_N2K.InsertColumn(0, _('PGN'), width=100) self.list_N2K.InsertColumn(1, _('description'), width=250) self.list_N2K.InsertColumn(2, _('Signal K variable'), width=920) self.list_N2K.Bind(wx.EVT_LIST_ITEM_SELECTED, self.on_selected) OK = wx.Button(self.panel, label=_('OK')) OK.Bind(wx.EVT_BUTTON, self.on_OK) hlistbox = wx.BoxSizer(wx.HORIZONTAL) hlistbox.Add(self.list_N2K, 1, wx.ALL | wx.EXPAND, 5) vbox = wx.BoxSizer(wx.VERTICAL) vbox.Add(hlistbox, 1, wx.ALL | wx.EXPAND, 0) vbox.Add(OK, 0, wx.ALL, 5) self.panel.SetSizer(vbox) for ii in self.list_N2Kgen: self.list_N2K.Append(ii) data = self.conf.get('N2K', 'pgn_generate') try: self.PGN_list = eval(data) except: self.PGN_list = [] i = 0 for ii in self.list_N2Kgen: if str(ii[0]) in self.PGN_list: self.list_N2K.CheckItem(i) i += 1 def on_OK(self, e): result = [] i = 0 for ii in self.list_N2Kgen: if self.list_N2K.IsChecked(i): result.append(str(ii[0])) i += 1 self.conf.set('N2K', 'pgn_generate', str(result)) self.when_closed(e) def on_selected(self, e): pass def when_closed(self, e): self.Destroy()
class MyFrame(wx.Frame): def __init__(self): self.conf = Conf() self.home = self.conf.home self.currentpath = self.home+self.conf.get('GENERAL', 'op_folder')+'/openplotter' Language(self.conf) wx.Frame.__init__(self, None, title=_('NMEA 0183 generator'), size=(690,350)) self.SetFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)) self.icon = wx.Icon(self.currentpath+'/openplotter.ico', wx.BITMAP_TYPE_ICO) self.SetIcon(self.icon) wx.StaticBox(self, label=_(' NMEA 0183 '), size=(670, 230), pos=(10, 10)) self.list_nmea = wx.ListCtrl(self, style=wx.LC_REPORT, size=(565, 200), pos=(15, 30)) self.list_nmea.InsertColumn(0, _('Sentence'), width=100) self.list_nmea.InsertColumn(1, _('Rate'), width=50) self.list_nmea.InsertColumn(2, _('Fields'), width=1500) self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.edit_nmea, self.list_nmea) self.add_nmea_button =wx.Button(self, label=_('add'), pos=(585, 30)) self.Bind(wx.EVT_BUTTON, self.add_nmea, self.add_nmea_button) self.delete_nmea_button =wx.Button(self, label=_('delete'), pos=(585, 65)) self.Bind(wx.EVT_BUTTON, self.delete_nmea, self.delete_nmea_button) self.compat_nmea_button =wx.Button(self, label=_('opencpn\ndefault'), pos=(585, 189)) self.Bind(wx.EVT_BUTTON, self.compat_nmea, self.compat_nmea_button) self.diagnostic_nmea_button=wx.Button(self, label=_('NMEA Diagnostic'), pos=(10, 250)) self.Bind(wx.EVT_BUTTON, self.kplex_diagnostic, self.diagnostic_nmea_button) self.diagnostic_sk_button=wx.Button(self, label=_('SK Diagnostic'), pos=(180, 250)) self.Bind(wx.EVT_BUTTON, self.sk_diagnostic, self.diagnostic_sk_button) self.CreateStatusBar() self.Centre() self.Show(True) self.read_sentences() def start_d(self): subprocess.call(['pkill', '-f', 'SK-base_d.py']) subprocess.Popen(['python',self.currentpath+'/SK-base_d.py']) def read_sentences(self): self.sentences=[] self.list_nmea.DeleteAllItems() data=self.conf.get('NMEA0183', 'sentences') try: temp_list=eval(data) except:temp_list=[] for ii in temp_list: self.sentences.append(ii) fields=',' for i in ii[1]: if type(i) is str: fields+=i+',' elif type(i) is list: fields+=i[1]+',' self.list_nmea.Append([ii[0],ii[2],fields]) def edit_nmea(self,e): selected_sentence=e.GetIndex() edit=[selected_sentence,self.sentences[selected_sentence]] self.edit_add_nmea(edit) def add_nmea(self,e): self.edit_add_nmea(0) def edit_add_nmea(self,edit): self.SetStatusText('') dlg = addNMEA_0183(edit, self.conf) res = dlg.ShowModal() if res == wx.ID_OK: nmea=dlg.nmea if not nmea[0]: return if edit==0: fields=',' for i in nmea[1]: if type(i) is str: fields+=i+',' elif type(i) is list: fields+=i[1]+',' self.list_nmea.Append([nmea[0],nmea[2],fields]) self.sentences.append([nmea[0],nmea[1],nmea[2]]) else: self.list_nmea.SetStringItem(edit[0],0,nmea[0]) self.list_nmea.SetStringItem(edit[0],1,str(nmea[2])) fields=',' for i in nmea[1]: if type(i) is str: fields+=i+',' elif type(i) is list: fields+=i[1]+',' self.list_nmea.SetStringItem(edit[0],2,fields) self.sentences[edit[0]][0]=nmea[0] if '[' in nmea[1]: nmea[1]=eval(nmea[1]) self.sentences[edit[0]][1]=nmea[1] self.sentences[edit[0]][2]=nmea[2] self.conf.set('NMEA0183', 'sentences', str(self.sentences)) self.start_d() dlg.Destroy() def delete_nmea(self,e): self.SetStatusText('') selected_sentence=self.list_nmea.GetFirstSelected() if selected_sentence==-1: self.SetStatusText('Select a sentence to delete.') return del self.sentences[selected_sentence] self.list_nmea.DeleteItem(selected_sentence) self.conf.set('NMEA0183', 'sentences', str(self.sentences)) self.start_d() def compat_nmea(self,e): if self.list_nmea.GetItemCount()>0: self.SetStatusText(_('This function is only allowed when the list is empty.')) return self.conf.set('NMEA0183', 'sentences', "[['HDG', [['navigation.headingMagnetic', 'x.x|deg', '+', 0.0], '', '', '', ''], 0.5], ['XDR', ['A', ['navigation.attitude.roll', 'x.x|deg', '+', 0.0], 'D', 'ROLL'], 1.0], ['XDR', ['A', ['navigation.attitude.pitch', 'x.x|deg', '+', 0.0], 'D', 'PTCH'], 1.0], ['XDR', ['P', ['environment.outside.pressure', 'x.xxxx', '/', 100000.0], 'B', 'Barometer'], 5.0], ['XDR', ['C', ['environment.outside.temperature', 'x.x|C', '+', 0.0], 'C', 'ENV_OUTAIR_T'], 5.0], ['MTW', [['environment.water.temperature', 'x.x|C', '+', 0.0], 'C'], 5.0]]") self.start_d() self.read_sentences() def kplex_diagnostic(self,e): wx.MessageBox('use diagnostic on NMEA0183\nselect system\npush diagnostic', 'Info', wx.OK | wx.ICON_INFORMATION) def sk_diagnostic(self,e): subprocess.call(['pkill', '-f', 'diagnostic-SK-input.py']) subprocess.Popen(['python',self.currentpath+'/diagnostic-SK-input.py'])