Example #1
0
class MainFrame(wx.Frame):
		
		def __init__(self):

			self.option=sys.argv[1]

			paths=Paths()
			self.currentpath=paths.currentpath

			self.conf=Conf()

			Language(self.conf.get('GENERAL','lang'))

			wx.Frame.__init__(self, None, title=_('Fine calibration'), size=(500,300))

			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)

			self.CreateStatusBar()

			self.text=wx.StaticText(self, label=_('Error'), pos=(10, 10))

			self.output = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_DONTWRAP, size=(480,110), pos=(10,90))
			
			self.button_close =wx.Button(self, label=_('Close'), pos=(300, 210))
			self.Bind(wx.EVT_BUTTON, self.close, self.button_close)

			self.button_calculate =wx.Button(self, label=_('Calculate'), pos=(400, 210))
			self.Bind(wx.EVT_BUTTON, self.calculate, self.button_calculate)
			
			if self.option=='c': 
				self.text.SetLabel(_('Press Calculate and wait for the system to calculate\nthe ppm value with the selected channel. Put the obtained\nvalue in "Correction (ppm)" field and enable SDR-AIS\nreception. Estimated time: 1 min.'))
			if self.option=='b':
				self.text.SetLabel(_('Press Calculate and wait for the system to check the band.\nWrite down the strongest channel (power). If you do not find\nany channel try another band. Estimated time: 5 min.'))

			self.Centre()
 	
		def calculate(self,e):
			self.SetStatusText(_('Working...'))
			self.output.SetValue('')
			gain=self.conf.get('AIS-SDR', 'gain')
			ppm=self.conf.get('AIS-SDR', 'ppm')
			if self.option=='c': 
				channel=self.conf.get('AIS-SDR', 'gsm_channel')
				try: output=subprocess.check_output(['kal', '-c', channel, '-g', gain, '-e', ppm])
				except: output=_('error')
			if self.option=='b': 
				band=self.conf.get('AIS-SDR', 'band')
				try: output=subprocess.check_output(['kal', '-s', band, '-g', gain, '-e', ppm])
				except: output=_('error')
			self.output.SetValue(output)
			self.SetStatusText(_('Finished'))

		def close(self,e):
			self.Destroy()
Example #2
0
    def __init__(self):

        self.option = sys.argv[1]
        self.text_sms = sys.argv[2]
        self.text_sms = unicode(self.text_sms, 'utf-8')
        self.phone = sys.argv[3]

        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=_('Test SMS'), size=(500, 260))

        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)

        self.CreateStatusBar()

        self.text = wx.StaticText(self, label=_('Error'), pos=(10, 10))

        self.output = wx.TextCtrl(self,
                                  style=wx.TE_MULTILINE | wx.TE_READONLY
                                  | wx.TE_DONTWRAP,
                                  size=(480, 110),
                                  pos=(10, 50))

        self.button_close = wx.Button(self, label=_('Close'), pos=(300, 170))
        self.Bind(wx.EVT_BUTTON, self.close, self.button_close)

        self.button_calculate = wx.Button(self,
                                          label=_('Start'),
                                          pos=(400, 170))
        self.Bind(wx.EVT_BUTTON, self.calculate, self.button_calculate)

        if self.option == 'i':
            self.text.SetLabel(
                _('Press start to check the settings and connect to the GSM device'
                  ))

        if self.option == 't':
            self.text.SetLabel(
                _('Press start to send the text "').decode('utf8') +
                self.text_sms + _('"\nto the number "').decode('utf8') +
                self.phone + '"')

        self.Centre()
Example #3
0
    def __init__(self):
        self.list_SK = []
        self.static_list = [[]]
        self.sortCol = 0

        self.conf = Conf()
        self.home = self.conf.home
        self.currentpath = self.home + self.conf.get(
            'GENERAL', 'op_folder') + '/openplotter'

        Language(self.conf)

        self.data = []
Example #4
0
    def __init__(self):
        self.list_SK = []
        self.static_list = [[]]
        self.sortCol = 0

        self.conf = Conf()
        self.home = self.conf.home
        self.currentpath = self.conf.get('GENERAL', 'op_folder')

        SK_ = SK_settings(self.conf)
        self.ws_name = SK_.ws + SK_.ip + ":" + str(
            SK_.aktport) + "/signalk/v1/stream?subscribe=self"

        self.data = []
        self.start()
Example #5
0
 def __init__(self, parent):
     conf = Conf()
     Language(conf)
     wx.Frame.__init__(self, parent)
     dlg = wx.MessageDialog(self, text, _('Message'),
                            wx.OK | wx.ICON_WARNING)
     dlg.ShowModal()
     sys.exit()
Example #6
0
		def __init__(self):

			self.option=sys.argv[1]

			paths=Paths()
			self.currentpath=paths.currentpath

			self.conf=Conf()

			Language(self.conf.get('GENERAL','lang'))

			wx.Frame.__init__(self, None, title=_('Fine calibration'), size=(500,300))

			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)

			self.CreateStatusBar()

			self.text=wx.StaticText(self, label=_('Error'), pos=(10, 10))

			self.output = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_DONTWRAP, size=(480,110), pos=(10,90))
			
			self.button_close =wx.Button(self, label=_('Close'), pos=(300, 210))
			self.Bind(wx.EVT_BUTTON, self.close, self.button_close)

			self.button_calculate =wx.Button(self, label=_('Calculate'), pos=(400, 210))
			self.Bind(wx.EVT_BUTTON, self.calculate, self.button_calculate)
			
			if self.option=='c': 
				self.text.SetLabel(_('Press Calculate and wait for the system to calculate\nthe ppm value with the selected channel. Put the obtained\nvalue in "Correction (ppm)" field and enable SDR-AIS\nreception. Estimated time: 1 min.'))
			if self.option=='b':
				self.text.SetLabel(_('Press Calculate and wait for the system to check the band.\nWrite down the strongest channel (power). If you do not find\nany channel try another band. Estimated time: 5 min.'))

			self.Centre()
Example #7
0
		def __init__(self):

			self.option=sys.argv[1]
			self.text_sms=sys.argv[2]
			self.text_sms=unicode(self.text_sms,'utf-8')
			self.phone=sys.argv[3]

			paths=Paths()
			self.currentpath=paths.currentpath

			self.conf=Conf()

			Language(self.conf.get('GENERAL','lang'))

			wx.Frame.__init__(self, None, title=_('Test SMS'), size=(500,260))

			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)

			self.CreateStatusBar()

			self.text=wx.StaticText(self, label=_('Error'), pos=(10, 10))

			self.output = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_DONTWRAP, size=(480,110), pos=(10,50))
			
			self.button_close =wx.Button(self, label=_('Close'), pos=(300, 170))
			self.Bind(wx.EVT_BUTTON, self.close, self.button_close)

			self.button_calculate =wx.Button(self, label=_('Start'), pos=(400, 170))
			self.Bind(wx.EVT_BUTTON, self.calculate, self.button_calculate)

			if self.option=='i': 
				self.text.SetLabel(_('Press start to check the settings and connect to the GSM device'))

			if self.option=='t':
				self.text.SetLabel(_('Press start to send the text "')+self.text_sms+_('"\nto the number "')+self.phone+'"')

			self.Centre()
Example #8
0
# 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 <http://www.gnu.org/licenses/>.

import sys, subprocess, wx
from classes.conf import Conf
from classes.language import Language

action=sys.argv[1]

#see actions.py
start_all_actions='ACT19'

conf = Conf()
currentpath = conf.home+conf.get('GENERAL', 'op_folder')+'/openplotter'

Language(conf)

triggers=[]
data=conf.get('ACTIONS', 'triggers')
try:
	triggers=eval(data)
except:triggers=[]

#stop all
if action=='0':
	i=0
	for ii in triggers:
		templist=ii[4]
Example #9
0
class MyFrame(wx.Frame):
    def __init__(self):
        self.list_SK = []
        self.data_SK_unit_private = []
        self.SK_unit = ''
        self.SK_description = ''

        self.conf = Conf()
        self.home = self.conf.home
        self.currentpath = self.home + self.conf.get(
            'GENERAL', 'op_folder') + '/openplotter'

        Language(self.conf)

        logging.basicConfig()
        self.buffer = []
        self.sortCol = 0

        wx.Frame.__init__(self,
                          None,
                          title='diagnostic SignalK input',
                          size=(650, 435))
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        panel = wx.Panel(self, wx.ID_ANY)

        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)

        self.list = wx.ListCtrl(panel,
                                -1,
                                style=wx.LC_REPORT | wx.SUNKEN_BORDER)
        self.list.InsertColumn(0, 'SignalK', width=400)
        self.list.InsertColumn(1, _('SK Unit'), width=80)
        self.list.InsertColumn(2, _('Unit'), width=80)
        self.list.InsertColumn(3, _('Description'), width=500)

        self.sort_UnitSK = wx.Button(panel, label=_('Sort SK Unit'))
        self.sort_UnitSK.Bind(wx.EVT_BUTTON, self.on_sort_UnitSK)

        self.sort_Unit = wx.Button(panel, label=_('Sort Unit'))
        self.Bind(wx.EVT_BUTTON, self.on_sort_Unit, self.sort_Unit)

        self.sort_SK = wx.Button(panel, label=_('Sort SK'))
        self.sort_SK.Bind(wx.EVT_BUTTON, self.on_sort_SK)

        self.change_selected = wx.Button(panel, label=_('change selected'))
        self.change_selected.Bind(wx.EVT_BUTTON, self.on_change_selected)

        list_convert = [
            'Hz', 'Hz RPM', 'J', 'J Ah(12V)', 'J Ah(24V)', 'K', 'K C', 'K F',
            'm', 'm ft', 'm nm', 'm km', 'm/s', 'm/s kn', 'm/s kmh', 'm/s mph',
            'm3', 'm3 dm3', 'm3 gal', 'm3/s', 'm3/s l/h', 'm3/s gal/h', 'Pa',
            'Pa hPa', 'Pa Bar', 'rad', 'rad deg', 's', 's h', 's d', 's y',
            'ratio', 'ratio %'
        ]
        self.select_Unit_t = wx.StaticText(panel, label=_('convert'))
        self.select_Unit = wx.ComboBox(panel,
                                       choices=list_convert,
                                       style=wx.CB_READONLY,
                                       size=(150, 32))

        vbox = wx.BoxSizer(wx.VERTICAL)
        hlistbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hlistbox.Add(self.list, 1, wx.ALL | wx.EXPAND, 5)
        hbox.Add(self.sort_SK, 0, wx.RIGHT | wx.LEFT, 5)
        hbox.Add(self.sort_UnitSK, 0, wx.RIGHT | wx.LEFT, 5)
        hbox.Add(self.sort_Unit, 0, wx.RIGHT | wx.LEFT, 5)
        hbox.Add((0, 0), 1, wx.RIGHT | wx.LEFT, 5)
        hbox.Add(self.change_selected, 0, wx.RIGHT | wx.LEFT, 5)
        hbox.Add(self.select_Unit_t, 0, wx.LEFT | wx.TOP, 5)
        hbox.Add(self.select_Unit, 0, wx.RIGHT | wx.LEFT, 5)
        vbox.Add(hlistbox, 1, wx.ALL | wx.EXPAND, 0)
        vbox.Add(hbox, 0, wx.ALL | wx.EXPAND, 0)
        panel.SetSizer(vbox)

        self.CreateStatusBar()

        self.read()
        self.sorting()

        self.Show(True)

    def read(self):
        self.list_SK = []

        try:
            with open(
                    self.home +
                    '/.config/signalk-server-node/node_modules/@signalk/signalk-schema/dist/keyswithmetadata.json'
            ) as data_file:
                data = json.load(data_file)
        except:
            #old signalk
            with open(
                    self.home +
                    '/.config/signalk-server-node/node_modules/@signalk/signalk-schema/src/keyswithmetadata.json'
            ) as data_file:
                data = json.load(data_file)

        self.data_SK_unit_private = []
        if os.path.isfile(self.home + '/.openplotter/private_unit.json'):
            with open(self.home +
                      '/.openplotter/private_unit.json') as data_file:
                self.data_SK_unit_private = json.load(data_file)

        for i in data:
            if 'units' in data[i].keys():
                if 'description' in data[i].keys():
                    ii = i.replace('/vessels/*/', '')
                    ii = ii.replace('RegExp', '*')
                    ii = ii.replace('/', '.')
                    self.list_SK.append([
                        str(ii),
                        str(data[i]['units']), '',
                        str(data[i]['description'])
                    ])
                else:
                    self.list_SK.append(
                        [str(ii), str(data[i]['units']), '', ''])
        for j in self.data_SK_unit_private:
            for i in self.list_SK:
                if j[0] == i[0]:
                    i[2] = j[2]

        self.list_SK.sort(key=lambda tup: tup[0])
        self.list_SK.sort(key=lambda tup: tup[1])

    def lookup_star(self, name):
        skip = -1
        index = 0
        st = ''
        for i in name.split('.'):
            if index > -1:
                if skip == 0:
                    st += '.*'
                else:
                    if i in ['propulsion', 'inventory']:
                        skip = 1
                    elif i == 'resources':
                        skip = 2
                    st += '.' + i
            index += 1
            skip -= 1

        st = st[1:]
        self.SK_unit = ''
        self.SK_description = ''
        exist = False
        for j in self.list_SK:
            if j[2] == st:
                self.SK_unit = j[0]
                self.SK_description = j[3]
                exist = True
                break
        if not exist:
            print 'no unit for ', st

    def on_sort_Unit(self, e):
        self.sortCol = 2
        self.sorting()

    def on_sort_UnitSK(self, e):
        self.sortCol = 1
        self.sorting()

    def on_sort_SK(self, e):
        self.sortCol = 0
        self.sorting()

    def on_change_selected(self, e):
        orig_unit = self.select_Unit.GetValue().split(' ')
        if len(orig_unit) == 1:
            orig_unit = [orig_unit[0], '']
        if orig_unit[0] != '':
            list_select = []
            item = self.list.GetFirstSelected()
            while item != -1:
                # do something with the item
                self.list_SK[item][2] = orig_unit[1]

                list_select.append(self.get_by_index(item))
                item = self.list.GetNextSelected(item)

            self.data_SK_unit_private = []
            for i in self.list_SK:
                if i[2] != '':
                    self.data_SK_unit_private.append([i[0], i[1], i[2]])
            with open(self.home + '/.openplotter/private_unit.json',
                      'w') as data_file:
                json.dump(self.data_SK_unit_private, data_file)

            self.data_SK_unit_private = []
            with open(self.home +
                      '/.openplotter/private_unit.json') as data_file:
                self.data_SK_unit_private = json.load(data_file)
            self.read()
            self.sorting()

    def get_by_index(self, item):
        index = 0
        for i in self.list_SK:
            if index == item:
                return i
            index += 1
        return False

    def sorting(self):
        self.list.DeleteAllItems()
        self.list_SK.sort(key=lambda tup: tup[self.sortCol])
        index = 0
        for i in self.list_SK:
            self.list.InsertStringItem(index, i[0])
            self.list.SetStringItem(index, 1, i[1])
            self.list.SetStringItem(index, 2, i[2])
            self.list.SetStringItem(index, 3, i[3])
            index += 1

    def OnClose(self, e):
        self.Destroy()
Example #10
0
	def __init__(self):
		logging.basicConfig()
		self.conf = Conf()
		self.home = self.conf.home
		self.currentpath = self.home+self.conf.get('GENERAL', 'op_folder')+'/openplotter'
		#self.Check127488_pos=100
		#self.Check127489_pos=100
		#self.Check127505_pos=100
		#self.Check130316_pos=100
		self.N2K=N2K_send()
		self.tick=0
		self.list_SK=[]

		Language(self.conf)

		wx.Frame.__init__(self, None, title="N2K-from-SK", size=(650,435))
		self.Bind(wx.EVT_CLOSE, self.OnClose)
		
		self.ttimer=100
		self.timer = wx.Timer(self)
		self.Bind(wx.EVT_TIMER, self.timer_act, self.timer)		
		
		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)

		iL=20;
		self.Check126992 = wx.CheckBox(self, label=_('126992 System_Time'), pos=(20, iL))
		iL+=20;
		self.Check127245 = wx.CheckBox(self, label=_('127245 Rudder'), pos=(20, iL))
		iL+=20;
		self.Check127250 = wx.CheckBox(self, label=_('127250 Heading'), pos=(20, iL))
		iL+=20
		self.Check127257 = wx.CheckBox(self, label=_('127257 Attitude'), pos=(20, iL))	
		iL+=20
		self.Check127488 = wx.CheckBox(self, label=_('127488 Engine_Rapid'), pos=(20, iL))	
		iL+=20
		self.Check127488_1 = wx.CheckBox(self, label=_('127488 Engine_Rapid starbord'), pos=(20, iL))	
		iL+=20
		self.Check127489 = wx.CheckBox(self, label=_('127489 Engine'), pos=(20, iL))	
		iL+=20
		self.Check127489_1 = wx.CheckBox(self, label=_('127489 Engine starbord'), pos=(20, iL))	
		iL+=20
		self.Check127505 = wx.CheckBox(self, label=_('127505 FluidLevel fuel'), pos=(20, iL))	
		iL+=20
		self.Check127505_1 = wx.CheckBox(self, label=_('127505 FluidLevel water'), pos=(20, iL))	
		iL+=20
		self.Check127505_2 = wx.CheckBox(self, label=_('127505 FluidLevel gray water'), pos=(20, iL))	
		iL+=20
		self.Check127505_3 = wx.CheckBox(self, label=_('127505 FluidLevel black water'), pos=(20, iL))	
		iL+=20
		self.Check127508 = wx.CheckBox(self, label=_('127508 Battery_Status'), pos=(20, iL))
		iL+=20;
		self.Check128259 = wx.CheckBox(self, label=_('128259 Speed'), pos=(20, iL))	
		iL+=20
		self.Check128267 = wx.CheckBox(self, label=_('128267 Depth'), pos=(20, iL))	
		iL+=20
		self.Check128275 = wx.CheckBox(self, label=_('128275 Distance_Log'), pos=(20, iL))	
		iL+=20
		self.Check129025 = wx.CheckBox(self, label=_('129025 Position_Rapid'), pos=(20, iL))	
		iL+=20
		self.Check129026 = wx.CheckBox(self, label=_('129026 COG_SOG'), pos=(20, iL))	
		iL=100
		self.Check130306 = wx.CheckBox(self, label=_('130306 Wind Data'), pos=(320, iL))	
		iL+=20
		self.Check130310 = wx.CheckBox(self, label=_('130310 Environmental_Parameters'), pos=(320, iL))	
		iL+=20
		self.Check130311 = wx.CheckBox(self, label=_('130311 Environmental_Parameters'), pos=(320, iL))	
		iL+=20
		self.Check130316 = wx.CheckBox(self, label=_('130316 Temperature refrigerator'), pos=(320, iL))	
		iL+=20
		self.Check130316_1 = wx.CheckBox(self, label=_('130316 Temperature exhaust'), pos=(320, iL))
		self.Bind(wx.EVT_CHECKBOX, self.updCB)

		self.XallBtn = wx.Button(self, label=_('all'),size=(70, 32), pos=(550, 20))
		self.Bind(wx.EVT_BUTTON, self.allBtn, self.XallBtn)
		
		self.XnoneBtn = wx.Button(self, label=_('none'),size=(70, 32), pos=(550, 60))
		self.Bind(wx.EVT_BUTTON, self.noneBtn, self.XnoneBtn)
		
		self.Centre()

		self.Show(True)
		
		self.defvar()
		self.aktPGN()

		self.cycle250=time.time()
		self.cycle250_2=time.time()+0.111
		self.cycle500=time.time()+0.123
		self.cycle500_2=time.time()+0.241
		self.cycle500_3=time.time()+0.363
		self.cycle500_4=time.time()-0.025
		self.cycle1000=time.time()+0.087
		self.cycle1000_2=time.time()+0.207
		
		self.start()

		self.timer.Start(self.ttimer)
Example #11
0
    def __init__(self):
        self.ttimer = 40

        self.conf = Conf()
        self.home = self.conf.home
        self.currentpath = self.conf.get('GENERAL', 'op_folder')

        self.SK_settings = SK_settings(self.conf)

        baudrate = self.SK_settings.ngt1_baudrate
        can_device = self.SK_settings.ngt1_device
        if baudrate and can_device:
            try:
                self.ser = serial.Serial(can_device, baudrate, timeout=0.5)
            except:
                print 'failed to start N2K input diagnostic on ' + can_device
                sys.exit(0)
        else:
            sys.exit(0)

        Language(self.conf)

        list_N2K_txt = []
        self.list_N2K = []
        with open(self.currentpath + '/classes/N2K_PGN.csv') as f:
            list_N2K_txt = [x.strip('\n\r').split(',') for x in f.readlines()]

        for ii in list_N2K_txt:
            pgn = int(ii[0])
            self.list_N2K.append([pgn, ii[1]])

        self.Buffer = [0] * 500
        self.Zustand = 6
        self.list_iter = []

        wx.Frame.__init__(self,
                          None,
                          title='diagnostic N2K input',
                          size=(650, 435))
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        panel = wx.Panel(self, wx.ID_ANY)

        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.timer_act, self.timer)

        self.SetFont(
            wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL,
                    wx.FONTWEIGHT_NORMAL))

        self.icon = wx.Icon(self.currentpath + '/static/icons/openplotter.ico',
                            wx.BITMAP_TYPE_ICO)
        self.SetIcon(self.icon)

        self.list = wx.ListCtrl(panel,
                                -1,
                                style=wx.LC_REPORT | wx.SUNKEN_BORDER)
        self.list.InsertColumn(0, _('PGN'), wx.LIST_FORMAT_RIGHT, width=62)
        self.list.InsertColumn(1, _('SRC'), wx.LIST_FORMAT_RIGHT, width=38)
        self.list.InsertColumn(2, _('DST'), wx.LIST_FORMAT_RIGHT, width=38)
        self.list.InsertColumn(3, _('Name'), width=180)
        self.list.InsertColumn(4,
                               _('Interval'),
                               wx.LIST_FORMAT_RIGHT,
                               width=45)
        self.list.InsertColumn(5, _('Data'), width=350)

        sort_SRC = wx.Button(panel, label=_('Sort SRC'))
        sort_SRC.Bind(wx.EVT_BUTTON, self.on_sort_SRC)

        sort_PGN = wx.Button(panel, label=_('Sort PGN'))
        sort_PGN.Bind(wx.EVT_BUTTON, self.on_sort_PGN)

        hlistbox = wx.BoxSizer(wx.HORIZONTAL)
        hlistbox.Add(self.list, 1, wx.ALL | wx.EXPAND, 5)

        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(sort_SRC, 0, wx.RIGHT | wx.LEFT, 5)
        hbox.Add(sort_PGN, 0, wx.RIGHT | wx.LEFT, 5)

        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(hlistbox, 1, wx.ALL | wx.EXPAND, 0)
        vbox.Add(hbox, 0, wx.ALL | wx.EXPAND, 0)
        panel.SetSizer(vbox)

        self.CreateStatusBar()

        self.Show(True)

        self.status = ''
        self.data = []
        self.baudc = 0
        self.baud = 0

        self.timer.Start(self.ttimer)
Example #12
0
# along with Openplotter. If not, see <http://www.gnu.org/licenses/>.

import sys, subprocess, wx
from classes.conf import Conf
from classes.paths import Paths
from classes.language import Language

action=sys.argv[1]

#see actions.py
start_all_actions='ACT19'

paths=Paths()
currentpath=paths.currentpath

conf=Conf()

Language(conf.get('GENERAL','lang'))

triggers=[]
data=conf.get('ACTIONS', 'triggers')
try:
	triggers=eval(data)
except:triggers=[]

#stop all
if action=='0':
	i=0
	for ii in triggers:
		templist=ii[4]
		start_all=False
Example #13
0
# 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 <http://www.gnu.org/licenses/>.
import matplotlib.pyplot as plt
import sys
from classes.conf import Conf
from classes.language import Language

conf = Conf()
Language(conf)

data = conf.get('COMPASS', 'deviation')
listsave = []
try:
	listsave = eval(data)
except:
	listsave = []

x=[]
y=[]
for ii in listsave:
	x.append(ii[1] - ii[0])
	y.append(ii[0])
Example #14
0
# 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 <http://www.gnu.org/licenses/>.

import subprocess, os, shutil, sys, pyudev
from classes.paths import Paths
from classes.conf import Conf

conf = Conf()

wifi_server = sys.argv[1]
wlan = conf.get('WIFI', 'device')
passw = conf.get('WIFI', 'password')
ssid = conf.get('WIFI', 'ssid')
hw_mode = conf.get('WIFI', 'hw_mode')
channel = conf.get('WIFI', 'channel')
wpa = conf.get('WIFI', 'wpa')
share = conf.get('WIFI', 'share')

paths = Paths()
currentpath = paths.currentpath

subprocess.call(['service', 'hostapd', 'stop'])
subprocess.call(['service', 'dnsmasq', 'stop'])
Example #15
0
# 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 <http://www.gnu.org/licenses/>.
import matplotlib.pyplot as plt
import sys
from classes.conf import Conf
from classes.language import Language

edit = sys.argv[1]

conf = Conf()
Language(conf)
data = conf.get('SPI', 'value_' + str(edit))
listsave = []
try:
    temp_list = eval(data)
except:
    temp_list = []
for ii in temp_list:
    listsave.append(ii)
plt.plot(*zip(*listsave))
plt.suptitle(_(
    'settings to convert raw adc values (unlinear and/or no factor and/or no offset)\n to useable values  for input '
).decode('utf8') + str(edit),
             fontsize=12)
plt.xlabel(_('row adc value'), fontsize=12)
Example #16
0
# 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 <http://www.gnu.org/licenses/>.

import socket, time, pynmea2, RTIMU, math, csv
from classes.paths import Paths
from classes.conf import Conf

paths = Paths()
currentpath = paths.currentpath

conf = Conf()

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

nmea_hdg_b = conf.get('STARTUP', 'nmea_hdg') == '1'
nmea_heel_b = conf.get('STARTUP', 'nmea_heel') == '1'
nmea_pitch_b = conf.get('STARTUP', 'nmea_pitch') == '1'
poll_interval = 1

imu_b = False
pressure_val_b = False
humidity_val_b = False
log_list_b = False

nmea_press_b = conf.get('STARTUP', 'nmea_press') == '1'
nmea_temp_p_b = conf.get('STARTUP', 'nmea_temp_p') == '1'
Example #17
0
            publish_sk(i[1], channel, current_state, name)
        c += 1


def publish_sk(io, channel, current_state, name):
    if io == 'in': io = 'input'
    else: io = 'output'
    if current_state: current_state = '1'
    else: current_state = '0'
    SignalK = '{"updates":[{"$source":"OPnotifications.GPIO.' + io + '.' + str(
        channel
    ) + '","values":[{"path":"sensors.' + name + '","value":' + current_state + '}]}]}\n'
    sock.sendto(SignalK, ('127.0.0.1', 55558))


conf = Conf()
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

#init SPI MCP
rate_ana = 0.1
MCP = []
adjust_point = []
SignalK = ''
data = conf.get('SPI', 'mcp')
try:
    temp_list = eval(data)
except:
    temp_list = []
analog_ = False
for ii in temp_list:
    if '.*.' in ii[2]: ii[2] = ii[2].replace('*', ii[3])
Example #18
0
# 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 <http://www.gnu.org/licenses/>.

import socket, pynmea2, time
from w1thermsensor import W1ThermSensor
from classes.conf import Conf

conf=Conf()

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

sensors_list=eval(conf.get('1W', 'DS18B20'))

sensors=[]
for index,item in enumerate(sensors_list):
	try:
		type=W1ThermSensor.THERM_SENSOR_DS18B20
		for sensor in W1ThermSensor.get_available_sensors():
			if item[3] == sensor.id:
				type = sensor.type
		
		sensors.append(W1ThermSensor(type, item[3]))
	except Exception,e: 
Example #19
0
# 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 <http://www.gnu.org/licenses/>.

import socket, time, pynmea2, RTIMU, math, csv
from classes.paths import Paths
from classes.conf import Conf

paths=Paths()
currentpath=paths.currentpath

conf=Conf()

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

nmea_hdg_b = conf.get('STARTUP', 'nmea_hdg')=='1'
nmea_heel_b = conf.get('STARTUP', 'nmea_heel')=='1'
nmea_pitch_b = conf.get('STARTUP', 'nmea_pitch')=='1'
poll_interval = 1

imu_b = False
pressure_val_b = False
humidity_val_b = False
log_list_b = False

nmea_press_b = conf.get('STARTUP', 'nmea_press')=='1'
nmea_temp_p_b = conf.get('STARTUP', 'nmea_temp_p')=='1'
Example #20
0
# 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 <http://www.gnu.org/licenses/>.

import socket, time, pynmea2, RTIMU, math, csv
from classes.paths import Paths
from classes.conf import Conf

paths=Paths()
currentpath=paths.currentpath

conf=Conf()

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)


if conf.get('STARTUP', 'nmea_hdg')=='1' or conf.get('STARTUP', 'nmea_heel')=='1':
	SETTINGS_FILE = "RTIMULib"
	s = RTIMU.Settings(SETTINGS_FILE)
	imu = RTIMU.RTIMU(s)
	imu.IMUInit()
	imu.setSlerpPower(0.02)
	imu.setGyroEnable(True)
	imu.setAccelEnable(True)
	imu.setCompassEnable(True)
	poll_interval = imu.IMUGetPollInterval()
Example #21
0
class MySK:
    def __init__(self):
        self.list_SK = []
        self.static_list = [[]]
        self.sortCol = 0

        self.conf = Conf()
        self.home = self.conf.home
        self.currentpath = self.conf.get('GENERAL', 'op_folder')

        SK_ = SK_settings(self.conf)
        self.ws_name = SK_.ws + SK_.ip + ":" + str(
            SK_.aktport) + "/signalk/v1/stream?subscribe=self"

        self.data = []
        self.start()

    def json_interval(self, time_old, time_new):
        sek_n = float(time_new[17:22])
        sek_o = float(time_old[17:22])
        if sek_n >= sek_o:
            dif = sek_n - sek_o
        else:
            dif = sek_n + 60 - sek_o
        return float(dif)

    def OnClose(self, e):
        self.stop()

    def on_message(self, ws, message):
        js_up = ujson.loads(message)
        if 'updates' not in js_up:
            return
        js_up = js_up['updates'][0]
        label = ''
        src = ''
        type = ''
        value = ''

        if 'source' in js_up.keys():
            source = js_up['source']
            label = source['label']
            if 'type' in source:
                type = source['type']
                if type == 'NMEA0183':
                    if 'talker' in source:
                        src = label + '.' + source['talker']
                        if 'sentence' in source:
                            src = label + '.' + source['sentence']
                elif type == 'NMEA2000':
                    if 'src' in source:
                        src = label + '.' + source['src']
                        if 'pgn' in source: src += '.' + str(source['pgn'])
        if '$source' in js_up and src == '':
            src = js_up['$source']

        if 'timestamp' in js_up.keys():
            timestamp = js_up['timestamp']
        else:
            timestamp = '2000-01-01T00:00:00.000Z'

        values_ = js_up['values']

        for values in values_:
            path = values['path']
            value = values['value']
            src2 = src
            timestamp2 = timestamp

            if isinstance(value, dict):
                if 'timestamp' in value: timestamp2 = value['timestamp']

                if '$source' in value and src == '':
                    src = value['$source']
                elif 'source' in value:
                    source = value['source']
                    label = source['label']
                    if 'type' in source:
                        type = source['type']
                        if type == 'NMEA0183':
                            if 'talker' in source:
                                src = label + '.' + source['talker']
                                if 'sentence' in source:
                                    src = label + '.' + source['sentence']
                        elif type == 'NMEA2000':
                            if 'src' in source:
                                src = label + '.' + source['src']
                                if 'pgn' in source:
                                    src += '.' + str(source['pgn'])

                for lvalue in value:
                    result = True
                    if lvalue in ['source', '$source']:
                        result = False
                    elif lvalue == 'timestamp':
                        if 'position' in path and 'RMC' in src2:
                            self.update_add(timestamp2, 'navigation.datetime',
                                            src2, timestamp2)
                        result = False
                    if result:
                        path2 = path + '.' + lvalue
                        value2 = value[lvalue]
                        self.update_add(value2, path2, src2, timestamp2)
            else:
                self.update_add(value, path, src, timestamp)

    def update_add(self, value, path, src, timestamp):
        # SRC SignalK Value Unit Interval Status Description timestamp	private_Unit private_Value priv_Faktor priv_Offset
        #  0    1      2     3      4        5        6          7           8             9           10          11
        if type(value) is list: value = value[0]

        if isinstance(value, float): pass
        elif isinstance(value, basestring): value = str(value)
        elif isinstance(value, int): value = float(value)
        elif value is None: value = 'None'
        else: value = 0.0

        index = 0
        exists = False
        for i in self.list_SK:
            if path == i[1] and i[0] == src:
                exists = True
                i[2] = value
                i[7] = timestamp
                break
            index += 1
        if not exists:

            self.list_SK.append(
                [src, path, value, '', 0.0, 1, '', timestamp, '', 1, 0])

            for il in self.static_list:
                indexm = 0
                for im in il:
                    if im[0] == path:
                        im[1] = self.list_SK[-1]
                        #break
                    indexm += 1

    def on_error(self, ws, error):
        print error

    def on_close(self, ws):
        time.sleep(1)
        if self.ws is not None:
            self.ws.close()
        time.sleep(5)
        self.start()

    def on_open(self, ws):
        pass

    def run(self):
        self.ws = websocket.WebSocketApp(
            self.ws_name,
            on_message=lambda ws, msg: self.on_message(ws, msg),
            on_error=lambda ws, err: self.on_error(ws, err),
            on_close=lambda ws: self.on_close(ws))
        self.ws.on_open = lambda ws: self.on_open(ws)
        self.ws.run_forever()
        self.ws = None

    def start(self):
        def run():
            self.run()

        self.thread = threading.Thread(target=run)
        self.thread.start()

    def stop(self):
        time.sleep(1)
        if self.ws is not None:
            self.ws.close()
        self.thread.join()
Example #22
0
# 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 <http://www.gnu.org/licenses/>.

import subprocess, os, shutil, sys, pyudev
from classes.paths import Paths
from classes.conf import Conf

conf=Conf()

wifi_server=sys.argv[1]
wlan = conf.get('WIFI', 'device')
passw = conf.get('WIFI', 'password')
ssid = conf.get('WIFI', 'ssid')
hw_mode = conf.get('WIFI', 'hw_mode')
channel = conf.get('WIFI', 'channel')
wpa = conf.get('WIFI', 'wpa')
share = conf.get('WIFI', 'share')

paths=Paths()
currentpath=paths.currentpath

subprocess.call(['service', 'hostapd', 'stop'])
subprocess.call(['service', 'dnsmasq', 'stop'])
Example #23
0
home=paths.home
currentpath=paths.currentpath

device=''
ssid=''
passw=''

try:
	boot_conf = ConfigParser.SafeConfigParser()
	boot_conf.read('/boot/config.txt')
	device=boot_conf.get('OPENPLOTTER', 'device')
	ssid=boot_conf.get('OPENPLOTTER', 'ssid')
	passw=boot_conf.get('OPENPLOTTER', 'pass')
except Exception,e: print str(e)

conf=Conf()

if device and ssid and passw:
	conf.set('WIFI', 'enable', '1')
	conf.set('WIFI', 'device', device)
	conf.set('WIFI', 'ssid', ssid)
	conf.set('WIFI', 'password', passw)

delay=int(conf.get('STARTUP', 'delay'))

kplex=conf.get('STARTUP', 'kplex')
opencpn=conf.get('STARTUP', 'opencpn')
opencpn_no=conf.get('STARTUP', 'opencpn_no_opengl')
opencpn_fullscreen=conf.get('STARTUP', 'opencpn_fullscreen')
x11vnc=conf.get('STARTUP', 'x11vnc')
gps_time=conf.get('STARTUP', 'gps_time')
Example #24
0
		def __init__(self, parent):

			paths=Paths()
			self.currentpath=paths.currentpath

			self.conf=Conf()

			Language(self.conf.get('GENERAL','lang'))

			wx.Frame.__init__(self, parent, title="Inspector", size=(650,435))
			
			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)

			self.logger = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_DONTWRAP, size=(650,150), pos=(0,0))

			self.list = wx.ListCtrl(self, -1, style=wx.LC_REPORT | wx.SUNKEN_BORDER, size=(540, 220), pos=(5, 155))
			self.list.InsertColumn(0, _('Type'), width=205)
			self.list.InsertColumn(1, _('Value'), width=130)
			self.list.InsertColumn(2, _('Source'), width=90)
			self.list.InsertColumn(3, _('NMEA'), width=50)
			self.list.InsertColumn(4, _('Age'), width=59)

			self.button_pause =wx.Button(self, label=_('Pause'), pos=(555, 160))
			self.Bind(wx.EVT_BUTTON, self.pause, self.button_pause)

			self.button_reset =wx.Button(self, label=_('Reset'), pos=(555, 200))
			self.Bind(wx.EVT_BUTTON, self.reset, self.button_reset)

			self.button_nmea =wx.Button(self, label=_('NMEA info'), pos=(555, 240))
			self.Bind(wx.EVT_BUTTON, self.nmea_info, self.button_nmea)

			self.a=DataStream()

			index=0
			for i in self.a.DataList:
				data=eval('self.a.'+i+'[0]')
				self.list.InsertStringItem(index,data)
				index=index+1

			self.pause_all=0

			self.CreateStatusBar()

			self.Centre()

			self.Show(True)

			self.thread1=threading.Thread(target=self.parse_data)
			self.thread2=threading.Thread(target=self.refresh_loop)
			
			self.s2=''
			self.error=''
			self.frase_nmea_log=''
			self.data=[]
			self.read_conf=1
			GPIO.setmode(GPIO.BCM)
			GPIO.setwarnings(False)

			if not self.thread1.isAlive(): self.thread1.start()
			if not self.thread2.isAlive(): self.thread2.start()
Example #25
0
class MainFrame(wx.Frame):
		
		def __init__(self):

			self.conf=Conf()
			Language(self.conf.get('GENERAL','lang'))

			wx.Frame.__init__(self, None, title=_('Connection'), size=(550,385))
			
			self.SetFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
			
			self.icon = wx.Icon(currentpath+'/openplotter.ico', wx.BITMAP_TYPE_ICO)
			self.SetIcon(self.icon)

			self.in_out=sys.argv[1]
			self.con_type=sys.argv[2]

			wx.StaticText(self, label=_('Name'), pos=(25, 35))
			self.name = wx.TextCtrl(self, -1, size=(120, 32), pos=(20, 55))

			if self.con_type=='serial':
				if self.in_out=='in': wx.StaticBox(self, label=_(' Serial input '), size=(530, 90), pos=(10, 10))
				if self.in_out=='out': wx.StaticBox(self, label=_(' Serial output '), size=(530, 90), pos=(10, 10))
				self.SerDevLs = []
				self.SerialCheck('/dev/rfcomm')
				self.SerialCheck('/dev/ttyUSB')
				self.SerialCheck('/dev/ttyS')
				self.SerialCheck('/dev/ttyACM')
				self.SerialCheck('/dev/ttyAMA')
				wx.StaticText(self, label=_('Port'), pos=(155, 35))
				self.deviceComboBox = wx.ComboBox(self, choices=self.SerDevLs, style=wx.CB_DROPDOWN, size=(155, 32), pos=(150, 55))
				if self.SerDevLs : self.deviceComboBox.SetValue(self.SerDevLs[0])
				self.bauds = ['4800', '9600', '19200', '38400', '57600', '115200']
				wx.StaticText(self, label=_('Bauds'), pos=(320, 35))
				self.baudComboBox = wx.ComboBox(self, choices=self.bauds, style=wx.CB_READONLY, size=(90, 32), pos=(315, 55))
				self.baudComboBox.SetValue('4800')

			if self.con_type=='network':
				if self.in_out=='in': 
					wx.StaticBox(self, label=_(' Network input '), size=(530, 90), pos=(10, 10))
					self.gpsd =wx.Button(self, label=_('GPSD'), pos=(440, 55))
					self.Bind(wx.EVT_BUTTON, self.create_gpsd, self.gpsd)
				if self.in_out=='out': wx.StaticBox(self, label=_(' Network output '), size=(530, 90), pos=(10, 10))
				self.type = ['TCP', 'UDP']
				wx.StaticText(self, label=_('Type'), pos=(155, 35))
				self.typeComboBox = wx.ComboBox(self, choices=self.type, style=wx.CB_READONLY, size=(70, 32), pos=(150, 55))
				self.typeComboBox.SetValue('TCP')
				wx.StaticText(self, label=_('Address'), pos=(235, 35))
				self.address = wx.TextCtrl(self, -1, size=(120, 32), pos=(230, 55))
				wx.StaticText(self, label=_('Port'), pos=(365, 35))
				self.port = wx.TextCtrl(self, -1, size=(55, 32), pos=(360, 55))

			wx.StaticBox(self, label=_(' Filter '), size=(530, 195), pos=(10, 105))
			self.mode_filter = [_('none'), _('Accept only sentences:'), _('Ignore sentences:')]
			self.filter = wx.ComboBox(self, choices=self.mode_filter, style=wx.CB_READONLY, size=(220, 32), pos=(20, 130))
			self.filter.SetValue(self.mode_filter[0])
			wx.StaticText(self, label=_('Filtering'), pos=(25, 175))
			self.sentences = wx.TextCtrl(self, -1, style=wx.CB_READONLY, size=(400, 32), pos=(20, 195))
			self.sentences.SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_INACTIVECAPTION))
			self.delete =wx.Button(self, label=_('Delete'), pos=(440, 195))
			self.Bind(wx.EVT_BUTTON, self.delete_sentences, self.delete)
			wx.StaticText(self, label=_('Talker - Sentence'), pos=(25, 240))
			self.talker = wx.TextCtrl(self, -1, size=(35, 32), pos=(20, 260))
			wx.StaticText(self, label=_('-'), pos=(60, 265))
			self.sent = wx.TextCtrl(self, -1, size=(45, 32), pos=(70, 260))
			self.add_sent =wx.Button(self, label=_('Add sentence'), pos=(160, 260))
			self.Bind(wx.EVT_BUTTON, self.add_sentence, self.add_sent)

			self.sentences.SetValue(_('nothing'))
			self.talker.SetValue('**')
			self.sent.SetValue('***')

			self.ok =wx.Button(self, label=_('OK'), pos=(440, 310))
			self.Bind(wx.EVT_BUTTON, self.ok_conn, self.ok)
			self.cancel =wx.Button(self, label=_('Cancel'), pos=(330, 310))
			self.Bind(wx.EVT_BUTTON, self.cancel_conn, self.cancel)

			self.Centre()

		def ShowMessage(self, w_msg):
			wx.MessageBox(w_msg, 'Info', wx.OK | wx.ICON_INFORMATION)

		def SerialCheck(self,dev):
			num = 0
			for _ in range(99):
				s = dev + str(num)
				d = os.path.exists(s)
				if d == True:
					self.SerDevLs.append(s)      
				num = num + 1

		def delete_sentences(self,event):
			self.sentences.SetValue(_('nothing'))

		def add_sentence(self,event):
			talker=self.talker.GetValue()
			sent=self.sent.GetValue()

			if not re.match('^[*A-Z]{2}$', talker):
				self.ShowMessage(_('Talker must have 2 uppercase characters. The symbol * matches any character.'))
				return
			if not re.match('^[*A-Z]{3}$', sent):
				self.ShowMessage(_('Sentence must have 3 uppercase characters. The symbol * matches any character.'))
				return

			r_sentence=talker+sent
			if r_sentence=='*****': 
				self.ShowMessage(_('You must enter 2 uppercase characters for talker or 3 uppercase characters for sentence. The symbol * matches any character.'))
				return
			if r_sentence in self.sentences.GetValue(): 
				self.ShowMessage(_('This sentence already exists.'))
				return
			if self.sentences.GetValue()==_('nothing'):
				self.sentences.SetValue(r_sentence)
			else:
				self.sentences.SetValue(self.sentences.GetValue()+','+r_sentence)
		
		def create_gpsd(self,event):
			self.name.SetValue('gpsd')
			self.typeComboBox.SetValue('TCP')
			self.address.SetValue('127.0.0.1')
			self.port.SetValue('2947')

		def ok_conn(self,event):
			name= self.name.GetValue()
			name=name.replace(' ', '_')
			if not re.match('^[_0-9a-z]{1,13}$', name):
				self.ShowMessage(_('"Name" must be a string between 1 and 13 lowercase letters and/or numbers which is not used as name for another input/output.'))
				return

			if self.con_type=='serial':
				type_conn='Serial'
				if self.deviceComboBox.GetValue(): port_address=self.deviceComboBox.GetValue()
				else:
					self.ShowMessage(_('You must select a Port.'))
					return
				bauds_port=self.baudComboBox.GetValue()


			if self.con_type=='network':
				type_conn=self.typeComboBox.GetValue()
				if self.address.GetValue(): port_address=self.address.GetValue()
				else:
					self.ShowMessage(_('You must enter an Address.'))
					return
				if self.port.GetValue(): bauds_port=self.port.GetValue()
				else:
					self.ShowMessage(_('You must enter a Port.'))
					return
			
			if self.filter.GetValue()==_('none') and self.sentences.GetValue()!=_('nothing'):
				self.ShowMessage(_('You must select a Filter type.'))
				return

			filter_type='none'
			filtering='nothing'

			if self.filter.GetValue()==_('Accept only sentences:') and self.sentences.GetValue()!=_('nothing'):
				filter_type='accept'
				filtering=''
				r=self.sentences.GetValue()
				l=r.split(',')
				for index,item in enumerate(l):
					if index!=0: filtering+=':'
					filtering+='+'+item
				filtering+=':-all'
				

			if self.filter.GetValue()==_('Ignore sentences:') and self.sentences.GetValue()!=_('nothing'):
				filter_type='ignore'
				filtering=''
				r=self.sentences.GetValue()
				l=r.split(',')
				for index,item in enumerate(l):
					if index!=0: filtering+=':'
					filtering+='-'+item


			print  self.in_out+','+name+','+type_conn+','+port_address+','+bauds_port+','+filter_type+','+filtering+',1'
			self.Destroy()

		def cancel_conn(self,event):
			self.Destroy()
Example #26
0
class MainFrame(wx.Frame):
		
		def __init__(self):

			self.option=sys.argv[1]
			self.text_sms=sys.argv[2]
			self.text_sms=unicode(self.text_sms,'utf-8')
			self.phone=sys.argv[3]

			paths=Paths()
			self.currentpath=paths.currentpath

			self.conf=Conf()

			Language(self.conf.get('GENERAL','lang'))

			wx.Frame.__init__(self, None, title=_('Test SMS'), size=(500,260))

			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)

			self.CreateStatusBar()

			self.text=wx.StaticText(self, label=_('Error'), pos=(10, 10))

			self.output = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_DONTWRAP, size=(480,110), pos=(10,50))
			
			self.button_close =wx.Button(self, label=_('Close'), pos=(300, 170))
			self.Bind(wx.EVT_BUTTON, self.close, self.button_close)

			self.button_calculate =wx.Button(self, label=_('Start'), pos=(400, 170))
			self.Bind(wx.EVT_BUTTON, self.calculate, self.button_calculate)

			if self.option=='i': 
				self.text.SetLabel(_('Press start to check the settings and connect to the GSM device'))

			if self.option=='t':
				self.text.SetLabel(_('Press start to send the text "')+self.text_sms+_('"\nto the number "')+self.phone+'"')

			self.Centre()

		def calculate(self,e):
			self.output.SetValue('')
			output=''
			if self.option=='i': 
				self.SetStatusText(_('Connecting...'))
				try:
					output=subprocess.check_output(['gammu', 'identify'])
				except: output= _('Error opening device. Check settings.')	
			if self.option=='t':
				self.SetStatusText(_('Sending...'))
				try:
					sm = gammu.StateMachine()
					sm.ReadConfig()
					sm.Init()
					netinfo = sm.GetNetworkInfo()
					output+= 'Network name: %s' % netinfo['NetworkName']
					output+= '\nNetwork code: %s' % netinfo['NetworkCode']
					output+= '\nLAC: %s' % netinfo['LAC']
					output+= '\nCID: %s' % netinfo['CID']
					message = {
						'Text': self.text_sms, 
						'SMSC': {'Location': 1},
						'Number': self.phone,
					}
					sm.SendSMS(message)
					output+='\nSMS "'+self.text_sms+_('" sent succesfully to ')+self.phone
				except Exception,e: output= str(e)

			self.output.SetValue(output)
			self.SetStatusText(_('Finished'))

		def close(self,e):
			self.Destroy()
Example #27
0
		def __init__(self):

			self.conf=Conf()
			Language(self.conf.get('GENERAL','lang'))

			wx.Frame.__init__(self, None, title=_('Connection'), size=(550,385))
			
			self.SetFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
			
			self.icon = wx.Icon(currentpath+'/openplotter.ico', wx.BITMAP_TYPE_ICO)
			self.SetIcon(self.icon)

			self.in_out=sys.argv[1]
			self.con_type=sys.argv[2]

			wx.StaticText(self, label=_('Name'), pos=(25, 35))
			self.name = wx.TextCtrl(self, -1, size=(120, 32), pos=(20, 55))

			if self.con_type=='serial':
				if self.in_out=='in': wx.StaticBox(self, label=_(' Serial input '), size=(530, 90), pos=(10, 10))
				if self.in_out=='out': wx.StaticBox(self, label=_(' Serial output '), size=(530, 90), pos=(10, 10))
				self.SerDevLs = []
				self.SerialCheck('/dev/rfcomm')
				self.SerialCheck('/dev/ttyUSB')
				self.SerialCheck('/dev/ttyS')
				self.SerialCheck('/dev/ttyACM')
				self.SerialCheck('/dev/ttyAMA')
				wx.StaticText(self, label=_('Port'), pos=(155, 35))
				self.deviceComboBox = wx.ComboBox(self, choices=self.SerDevLs, style=wx.CB_DROPDOWN, size=(155, 32), pos=(150, 55))
				if self.SerDevLs : self.deviceComboBox.SetValue(self.SerDevLs[0])
				self.bauds = ['4800', '9600', '19200', '38400', '57600', '115200']
				wx.StaticText(self, label=_('Bauds'), pos=(320, 35))
				self.baudComboBox = wx.ComboBox(self, choices=self.bauds, style=wx.CB_READONLY, size=(90, 32), pos=(315, 55))
				self.baudComboBox.SetValue('4800')

			if self.con_type=='network':
				if self.in_out=='in': 
					wx.StaticBox(self, label=_(' Network input '), size=(530, 90), pos=(10, 10))
					self.gpsd =wx.Button(self, label=_('GPSD'), pos=(440, 55))
					self.Bind(wx.EVT_BUTTON, self.create_gpsd, self.gpsd)
				if self.in_out=='out': wx.StaticBox(self, label=_(' Network output '), size=(530, 90), pos=(10, 10))
				self.type = ['TCP', 'UDP']
				wx.StaticText(self, label=_('Type'), pos=(155, 35))
				self.typeComboBox = wx.ComboBox(self, choices=self.type, style=wx.CB_READONLY, size=(70, 32), pos=(150, 55))
				self.typeComboBox.SetValue('TCP')
				wx.StaticText(self, label=_('Address'), pos=(235, 35))
				self.address = wx.TextCtrl(self, -1, size=(120, 32), pos=(230, 55))
				wx.StaticText(self, label=_('Port'), pos=(365, 35))
				self.port = wx.TextCtrl(self, -1, size=(55, 32), pos=(360, 55))

			wx.StaticBox(self, label=_(' Filter '), size=(530, 195), pos=(10, 105))
			self.mode_filter = [_('none'), _('Accept only sentences:'), _('Ignore sentences:')]
			self.filter = wx.ComboBox(self, choices=self.mode_filter, style=wx.CB_READONLY, size=(220, 32), pos=(20, 130))
			self.filter.SetValue(self.mode_filter[0])
			wx.StaticText(self, label=_('Filtering'), pos=(25, 175))
			self.sentences = wx.TextCtrl(self, -1, style=wx.CB_READONLY, size=(400, 32), pos=(20, 195))
			self.sentences.SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_INACTIVECAPTION))
			self.delete =wx.Button(self, label=_('Delete'), pos=(440, 195))
			self.Bind(wx.EVT_BUTTON, self.delete_sentences, self.delete)
			wx.StaticText(self, label=_('Talker - Sentence'), pos=(25, 240))
			self.talker = wx.TextCtrl(self, -1, size=(35, 32), pos=(20, 260))
			wx.StaticText(self, label=_('-'), pos=(60, 265))
			self.sent = wx.TextCtrl(self, -1, size=(45, 32), pos=(70, 260))
			self.add_sent =wx.Button(self, label=_('Add sentence'), pos=(160, 260))
			self.Bind(wx.EVT_BUTTON, self.add_sentence, self.add_sent)

			self.sentences.SetValue(_('nothing'))
			self.talker.SetValue('**')
			self.sent.SetValue('***')

			self.ok =wx.Button(self, label=_('OK'), pos=(440, 310))
			self.Bind(wx.EVT_BUTTON, self.ok_conn, self.ok)
			self.cancel =wx.Button(self, label=_('Cancel'), pos=(330, 310))
			self.Bind(wx.EVT_BUTTON, self.cancel_conn, self.cancel)

			self.Centre()
Example #28
0
class MyFrame(wx.Frame):
    def __init__(self):
        self.ttimer = 40

        self.conf = Conf()
        self.home = self.conf.home
        self.currentpath = self.conf.get('GENERAL', 'op_folder')

        self.SK_settings = SK_settings(self.conf)

        baudrate = self.SK_settings.ngt1_baudrate
        can_device = self.SK_settings.ngt1_device
        if baudrate and can_device:
            try:
                self.ser = serial.Serial(can_device, baudrate, timeout=0.5)
            except:
                print 'failed to start N2K input diagnostic on ' + can_device
                sys.exit(0)
        else:
            sys.exit(0)

        Language(self.conf)

        list_N2K_txt = []
        self.list_N2K = []
        with open(self.currentpath + '/classes/N2K_PGN.csv') as f:
            list_N2K_txt = [x.strip('\n\r').split(',') for x in f.readlines()]

        for ii in list_N2K_txt:
            pgn = int(ii[0])
            self.list_N2K.append([pgn, ii[1]])

        self.Buffer = [0] * 500
        self.Zustand = 6
        self.list_iter = []

        wx.Frame.__init__(self,
                          None,
                          title='diagnostic N2K input',
                          size=(650, 435))
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        panel = wx.Panel(self, wx.ID_ANY)

        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.timer_act, self.timer)

        self.SetFont(
            wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL,
                    wx.FONTWEIGHT_NORMAL))

        self.icon = wx.Icon(self.currentpath + '/static/icons/openplotter.ico',
                            wx.BITMAP_TYPE_ICO)
        self.SetIcon(self.icon)

        self.list = wx.ListCtrl(panel,
                                -1,
                                style=wx.LC_REPORT | wx.SUNKEN_BORDER)
        self.list.InsertColumn(0, _('PGN'), wx.LIST_FORMAT_RIGHT, width=62)
        self.list.InsertColumn(1, _('SRC'), wx.LIST_FORMAT_RIGHT, width=38)
        self.list.InsertColumn(2, _('DST'), wx.LIST_FORMAT_RIGHT, width=38)
        self.list.InsertColumn(3, _('Name'), width=180)
        self.list.InsertColumn(4,
                               _('Interval'),
                               wx.LIST_FORMAT_RIGHT,
                               width=45)
        self.list.InsertColumn(5, _('Data'), width=350)

        sort_SRC = wx.Button(panel, label=_('Sort SRC'))
        sort_SRC.Bind(wx.EVT_BUTTON, self.on_sort_SRC)

        sort_PGN = wx.Button(panel, label=_('Sort PGN'))
        sort_PGN.Bind(wx.EVT_BUTTON, self.on_sort_PGN)

        hlistbox = wx.BoxSizer(wx.HORIZONTAL)
        hlistbox.Add(self.list, 1, wx.ALL | wx.EXPAND, 5)

        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(sort_SRC, 0, wx.RIGHT | wx.LEFT, 5)
        hbox.Add(sort_PGN, 0, wx.RIGHT | wx.LEFT, 5)

        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(hlistbox, 1, wx.ALL | wx.EXPAND, 0)
        vbox.Add(hbox, 0, wx.ALL | wx.EXPAND, 0)
        panel.SetSizer(vbox)

        self.CreateStatusBar()

        self.Show(True)

        self.status = ''
        self.data = []
        self.baudc = 0
        self.baud = 0

        self.timer.Start(self.ttimer)

    def timer_act(self, event):
        if self.ser:
            self.getCharfromSerial()

    def on_sort_PGN(self, e):
        self.timer.Stop()
        self.list_iter.sort()
        self.list.DeleteAllItems()
        self.init2()
        self.timer.Start(self.ttimer)

    def on_sort_SRC(self, e):
        self.timer.Stop()
        self.list.DeleteAllItems()

        list_new = []
        for i in sorted(self.list_iter, key=lambda item: (item[1], item[0])):
            list_new.append(i)
        self.list_iter = list_new
        self.init2()
        self.timer.Start(self.ttimer)

    def init2(self):
        index = 0
        for i in self.list_iter:
            self.list.InsertStringItem(index, str(i[0]))
            self.list.SetStringItem(index, 1, str(i[1]))
            self.list.SetStringItem(index, 2, str(i[2]))
            self.list.SetStringItem(index, 3, str(i[3]))
            self.list.SetStringItem(index, 4, str(i[4]))
            self.list.SetStringItem(index, 5, '')
            index += 1

    def OnClose(self, event):
        self.timer.Stop()
        self.Destroy()

    def getCharfromSerial(self):
        bytesToRead = self.ser.inWaiting()
        if bytesToRead > 0:
            buffer = self.ser.read(bytesToRead)
            for i in buffer:
                #sys.stdout.write(' '+hex(ord(i)))
                self.parse(ord(i))

    def parse(self, b):
        if self.Zustand == 6:  # zu Beginn auf 0x10 warten
            if b == 0x10:
                self.Zustand = 0x10
        elif self.Zustand == 0x10:
            if b == 0x10:  # 0x10 Schreiben wenn zweimal hintereinander
                self.Buffer[self.p] = b
                self.p += 1
                self.Zustand = 0
            elif b == 0x02:  # Anfang gefunden
                self.p = 0
                self.Zustand = 0
            elif b == 0x03:  # Ende gefunden
                if self.crcCheck():
                    #print "CRC"
                    self.output()
                self.p = 0
                self.Zustand = 6  # Auf Anfang zuruecksetzen
        elif self.Zustand == 0:
            if b == 0x10:
                self.Zustand = 0x10
            else:
                self.Buffer[self.p] = b
                self.p += 1

    def crcCheck(self):
        crc = 0
        i = 0
        while i < self.p:
            crc = (crc + self.Buffer[i]) & 255
            i += 1
        return (crc == 0)

    def output(self):
        if self.Buffer[0] == 0x93 and self.Buffer[1] == self.p - 3:
            nPriority = self.Buffer[2]
            lPGN = self.Buffer[
                3] + self.Buffer[4] * 256 + self.Buffer[5] * 256 * 256
            nDestAddr = self.Buffer[6]
            nSrcAddr = self.Buffer[7]
            length = self.Buffer[12]

            datap = ''
            data = 0
            for i in range(13, 13 + length):
                data = data + self.Buffer[i]
                datap += ' ' + ('0' + hex(self.Buffer[i])[2:])[-2:]

            #print lPGN, nSrcAddr, nDestAddr, datap

            exist = 0
            index = 0
            tt = time.time()
            for i in self.list_iter:
                if nSrcAddr == i[1]:
                    if lPGN == i[0]:
                        td = round(i[4] * 0.3 + 0.7 * (tt - i[5]), 1)
                        self.list_iter[index][4] = td
                        self.list_iter[index][5] = tt
                        self.list.SetStringItem(index, 4, str(td))
                        self.list.SetStringItem(index, 5, datap)
                        exist = 1
                index += 1
            if exist == 0:
                self.list.InsertStringItem(index, str(lPGN))
                self.list.SetStringItem(index, 1, str(nSrcAddr))
                self.list.SetStringItem(index, 2, str(nDestAddr))
                for ii in self.list_N2K:
                    if lPGN == ii[0]:
                        self.list.SetStringItem(index, 3, ii[1])
                self.list.SetStringItem(index, 4, 'X')
                self.list.SetStringItem(index, 5, datap)
                self.list_iter.append([
                    lPGN, nSrcAddr, nDestAddr,
                    self.list.GetItem(index, 3).GetText(), 0, tt
                ])
Example #29
0
class MyFrame(wx.Frame):
		
		def __init__(self, parent, title):

			paths=Paths()
			self.currentpath=paths.currentpath

			self.conf=Conf()

			Language(self.conf.get('GENERAL','lang'))

			wx.Frame.__init__(self, parent, title=title, size=(650,435))
			
			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)

			self.logger = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_DONTWRAP, size=(650,150), pos=(0,0))

			wx.StaticText(self, label=_('NMEA inspector'), pos=(525, 160))

			self.button_pause =wx.Button(self, label=_('Pause'), pos=(530, 190))
			self.Bind(wx.EVT_BUTTON, self.pause, self.button_pause)

			self.button_reset =wx.Button(self, label=_('Reset'), pos=(530, 230))
			self.Bind(wx.EVT_BUTTON, self.reset, self.button_reset)

			self.button_nmea =wx.Button(self, label=_('NMEA info'), pos=(530, 270))
			self.Bind(wx.EVT_BUTTON, self.nmea_info, self.button_nmea)

			self.list = wx.ListCtrl(self, -1, style=wx.LC_REPORT | wx.SUNKEN_BORDER, size=(500, 220), pos=(5, 155))
			self.list.InsertColumn(0, _('Type'), width=165)
			self.list.InsertColumn(1, _('Value'), width=130)
			self.list.InsertColumn(2, _('Source'), width=90)
			self.list.InsertColumn(3, _('NMEA'), width=50)
			self.list.InsertColumn(4, _('Age'), width=59)

			self.a=DataStream()

			index=0
			for i in self.a.DataList:
				data=eval('self.a.'+i+'[0]')
				self.list.InsertStringItem(index,data)
				index=index+1

			self.pause_all=0

			self.CreateStatusBar()

			self.Centre()

			self.Show(True)

			self.thread1=threading.Thread(target=self.parse_data)
			self.thread2=threading.Thread(target=self.refresh_loop)
			
			self.s2=''
			self.error=''
			self.frase_nmea_log=''
			self.data=[]
			self.read_conf=0

			if not self.thread1.isAlive(): self.thread1.start()
			if not self.thread2.isAlive(): self.thread2.start()

 		# thread 1
		def connect(self):
			try:
				self.s2 = socket.socket()
				self.s2.connect(("localhost", 10110))
				self.s2.settimeout(5)
			except socket.error, error_msg:
				self.error= _('Failed to connect with localhost:10110. Error: ')+ str(error_msg[0])+_(', trying to reconnect...')
				self.s2=''
				time.sleep(7)
			else: self.error=''
Example #30
0
	def __init__(self):
		self.conf = Conf()
		self.home = self.conf.home
		self.currentpath = self.conf.get('GENERAL', 'op_folder')
		Language(self.conf)
		style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER
		wx.Dialog.__init__(self, None, title=_('Generate N2K from Signal K'),style=style)
		self.Bind(wx.EVT_CLOSE, self.when_closed)
		self.SetInitialSize((720, 400))
		#self.SetAutoLayout(1)
		#self.SetupScrolling()

		self.icon = wx.Icon(self.currentpath + '/static/icons/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'],
			['127250','Heading','navigation.headingMagnetic'],
			['127257','Attitude','navigation.attitude.pitch, navigation.attitude.roll, navigation.attitude.yaw'],
			['127488','Engine_Rapid','propulsion.port.revolutions'],
			['127488_1','Engine_Rapid','propulsion.starboard.revolutions'],
			['127489','Engine','propulsion.port.oilTemperature, propulsion.port.temperature'],
			['127489_1','Engine','propulsion.starboard.oilTemperature, propulsion.starboard.temperature'],
			['127505','FluidLevel','tanks.fuel.standard.capacity, tanks.fuel.standard.currentLevel'],
			['127505_1','FluidLevel','tanks.liveWell.standard.capacity, tanks.liveWell.standard.currentLevel'],
			['127505_2','FluidLevel','tanks.wasteWater.standard.capacity, tanks.wasteWater.standard.currentLevel'],
			['127505_3','FluidLevel','tanks.blackWater.standard.capacity, tanks.blackWater.standard.currentLevel'],
			['127508','Battery_Status','electrical.batteries.service.voltage, electrical.batteries.service.current, electrical.batteries.service.temperature'],
			['128259','Speed','navigation.speedOverGround, navigation.speedThroughWater'],
			['128267','Depth','environment.depth.belowTransducer, environment.depth.surfaceToTransducer'],
			['128275','Distance_Log','navigation.log, navigation.logTrip'],
			['129025','Position_Rapid','navigation.position.latitude, navigation.position.longitude'],
			['129026','COG_SOG','navigation.courseOverGroundTrue, navigation.speedOverGround'],
			['130306_2','Wind Data','environment.wind.angleApparent, environment.wind.speedApparent'],
			['130306_3','Wind Data','environment.wind.angleTrueWater, environment.wind.speedTrue'],
			['130310','Environmental_Parameters','environment.outside.pressure, environment.outside.temperature, environment.water.temperature'],
			['130311','Environmental_Parameters','environment.outside.pressure, environment.inside.humidity, environment.water.temperature'],
			['130316','Temperature','environment.inside.refrigerator.temperature'],
			['130316_1','Temperature','propulsion.port.exhaustTemperature']
		]
		
		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=_('Apply changes'))
		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
Example #31
0
class MainFrame(wx.Frame):
    def __init__(self):

        self.conf = Conf()
        Language(self.conf.get("GENERAL", "lang"))

        wx.Frame.__init__(self, None, title=_("Connection"), size=(550, 385))

        self.SetFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))

        self.icon = wx.Icon(currentpath + "/openplotter.ico", wx.BITMAP_TYPE_ICO)
        self.SetIcon(self.icon)

        self.in_out = sys.argv[1]
        self.con_type = sys.argv[2]

        wx.StaticText(self, label=_("Name"), pos=(25, 35))
        self.name = wx.TextCtrl(self, -1, size=(120, 32), pos=(20, 55))

        if self.con_type == "serial":
            if self.in_out == "in":
                wx.StaticBox(self, label=_(" Serial input "), size=(530, 90), pos=(10, 10))
            if self.in_out == "out":
                wx.StaticBox(self, label=_(" Serial output "), size=(530, 90), pos=(10, 10))
            self.SerDevLs = []
            self.SerialCheck("/dev/rfcomm")
            self.SerialCheck("/dev/ttyUSB")
            self.SerialCheck("/dev/ttyS")
            self.SerialCheck("/dev/ttyACM")
            wx.StaticText(self, label=_("Port"), pos=(155, 35))
            self.deviceComboBox = wx.ComboBox(
                self, choices=self.SerDevLs, style=wx.CB_DROPDOWN, size=(155, 32), pos=(150, 55)
            )
            if self.SerDevLs:
                self.deviceComboBox.SetValue(self.SerDevLs[0])
            self.bauds = ["4800", "9600", "19200", "38400", "57600", "115200"]
            wx.StaticText(self, label=_("Bauds"), pos=(320, 35))
            self.baudComboBox = wx.ComboBox(
                self, choices=self.bauds, style=wx.CB_READONLY, size=(90, 32), pos=(315, 55)
            )
            self.baudComboBox.SetValue("4800")

        if self.con_type == "network":
            if self.in_out == "in":
                wx.StaticBox(self, label=_(" Network input "), size=(530, 90), pos=(10, 10))
                self.gpsd = wx.Button(self, label=_("GPSD"), pos=(440, 55))
                self.Bind(wx.EVT_BUTTON, self.create_gpsd, self.gpsd)
            if self.in_out == "out":
                wx.StaticBox(self, label=_(" Network output "), size=(530, 90), pos=(10, 10))
            self.type = ["TCP", "UDP"]
            wx.StaticText(self, label=_("Type"), pos=(155, 35))
            self.typeComboBox = wx.ComboBox(self, choices=self.type, style=wx.CB_READONLY, size=(70, 32), pos=(150, 55))
            self.typeComboBox.SetValue("TCP")
            wx.StaticText(self, label=_("Address"), pos=(235, 35))
            self.address = wx.TextCtrl(self, -1, size=(120, 32), pos=(230, 55))
            wx.StaticText(self, label=_("Port"), pos=(365, 35))
            self.port = wx.TextCtrl(self, -1, size=(55, 32), pos=(360, 55))

        wx.StaticBox(self, label=_(" Filter "), size=(530, 195), pos=(10, 105))
        self.mode_filter = [_("none"), _("Accept only sentences:"), _("Ignore sentences:")]
        self.filter = wx.ComboBox(self, choices=self.mode_filter, style=wx.CB_READONLY, size=(220, 32), pos=(20, 130))
        self.filter.SetValue(self.mode_filter[0])
        wx.StaticText(self, label=_("Filtering"), pos=(25, 175))
        self.sentences = wx.TextCtrl(self, -1, style=wx.CB_READONLY, size=(400, 32), pos=(20, 195))
        self.sentences.SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_INACTIVECAPTION))
        self.delete = wx.Button(self, label=_("Delete"), pos=(440, 195))
        self.Bind(wx.EVT_BUTTON, self.delete_sentences, self.delete)
        wx.StaticText(self, label=_("Talker - Sentence"), pos=(25, 240))
        self.talker = wx.TextCtrl(self, -1, size=(35, 32), pos=(20, 260))
        wx.StaticText(self, label=_("-"), pos=(60, 265))
        self.sent = wx.TextCtrl(self, -1, size=(45, 32), pos=(70, 260))
        self.add_sent = wx.Button(self, label=_("Add sentence"), pos=(160, 260))
        self.Bind(wx.EVT_BUTTON, self.add_sentence, self.add_sent)

        self.sentences.SetValue(_("nothing"))
        self.talker.SetValue("**")
        self.sent.SetValue("***")

        self.ok = wx.Button(self, label=_("OK"), pos=(440, 310))
        self.Bind(wx.EVT_BUTTON, self.ok_conn, self.ok)
        self.cancel = wx.Button(self, label=_("Cancel"), pos=(330, 310))
        self.Bind(wx.EVT_BUTTON, self.cancel_conn, self.cancel)

        self.Centre()

    def ShowMessage(self, w_msg):
        wx.MessageBox(w_msg, "Info", wx.OK | wx.ICON_INFORMATION)

    def SerialCheck(self, dev):
        num = 0
        for _ in range(99):
            s = dev + str(num)
            d = os.path.exists(s)
            if d == True:
                self.SerDevLs.append(s)
            num = num + 1

    def delete_sentences(self, event):
        self.sentences.SetValue(_("nothing"))

    def add_sentence(self, event):
        talker = self.talker.GetValue()
        sent = self.sent.GetValue()

        if not re.match("^[*A-Z]{2}$", talker):
            self.ShowMessage(_("Talker must have 2 uppercase characters. The symbol * matches any character."))
            return
        if not re.match("^[*A-Z]{3}$", sent):
            self.ShowMessage(_("Sentence must have 3 uppercase characters. The symbol * matches any character."))
            return

        r_sentence = talker + sent
        if r_sentence == "*****":
            self.ShowMessage(
                _(
                    "You must enter 2 uppercase characters for talker or 3 uppercase characters for sentence. The symbol * matches any character."
                )
            )
            return
        if r_sentence in self.sentences.GetValue():
            self.ShowMessage(_("This sentence already exists."))
            return
        if self.sentences.GetValue() == _("nothing"):
            self.sentences.SetValue(r_sentence)
        else:
            self.sentences.SetValue(self.sentences.GetValue() + "," + r_sentence)

    def create_gpsd(self, event):
        self.name.SetValue("gpsd")
        self.typeComboBox.SetValue("TCP")
        self.address.SetValue("localhost")
        self.port.SetValue("2947")

    def ok_conn(self, event):
        name = self.name.GetValue()
        name = name.replace(" ", "_")
        if not re.match("^[_0-9a-z]{1,13}$", name):
            self.ShowMessage(
                _(
                    '"Name" must be a string between 1 and 13 lowercase letters and/or numbers which is not used as name for another input/output.'
                )
            )
            return

        if self.con_type == "serial":
            type_conn = "Serial"
            if self.deviceComboBox.GetValue():
                port_address = self.deviceComboBox.GetValue()
            else:
                self.ShowMessage(_("You must select a Port."))
                return
            bauds_port = self.baudComboBox.GetValue()

        if self.con_type == "network":
            type_conn = self.typeComboBox.GetValue()
            if self.address.GetValue():
                port_address = self.address.GetValue()
            else:
                self.ShowMessage(_("You must enter an Address."))
                return
            if self.port.GetValue():
                bauds_port = self.port.GetValue()
            else:
                self.ShowMessage(_("You must enter a Port."))
                return

        if self.filter.GetValue() == _("none") and self.sentences.GetValue() != _("nothing"):
            self.ShowMessage(_("You must select a Filter type."))
            return

        filter_type = "none"
        filtering = "nothing"

        if self.filter.GetValue() == _("Accept only sentences:") and self.sentences.GetValue() != _("nothing"):
            filter_type = "accept"
            filtering = ""
            r = self.sentences.GetValue()
            l = r.split(",")
            for index, item in enumerate(l):
                if index != 0:
                    filtering += ":"
                filtering += "+" + item
            filtering += ":-all"

        if self.filter.GetValue() == _("Ignore sentences:") and self.sentences.GetValue() != _("nothing"):
            filter_type = "ignore"
            filtering = ""
            r = self.sentences.GetValue()
            l = r.split(",")
            for index, item in enumerate(l):
                if index != 0:
                    filtering += ":"
                filtering += "-" + item

        print self.in_out + "," + name + "," + type_conn + "," + port_address + "," + bauds_port + "," + filter_type + "," + filtering + ",1"
        self.Destroy()

    def cancel_conn(self, event):
        self.Destroy()
Example #32
0
# 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 <http://www.gnu.org/licenses/>.

import time, socket, threading
import RPi.GPIO as GPIO
from classes.datastream import DataStream
from classes.conf import Conf
from classes.language import Language
from classes.actions import Actions

conf=Conf()

Language(conf.get('GENERAL','lang'))

global trigger_actions
global triggers
trigger_actions=''
triggers=''
global sock_in
global error
sock_in=''
error=0
a=DataStream()
actions=Actions()
nodata=''
channel1=''
class MyFrame(wx.Frame):
    def __init__(self):
        self.SK_unit = ''
        self.SK_description = ''
        self.SK_unit_priv = 0
        self.SK_Faktor_priv = 1
        self.SK_Offset_priv = 0
        self.ws = None

        self.thread = threading._DummyThread

        self.private_unit_s = 1
        logging.basicConfig()
        self.buffer = []
        self.list_SK = []
        self.list_SK_unit = []
        self.sortCol = 0

        self.conf = Conf()
        self.home = self.conf.home
        self.currentpath = self.conf.get('GENERAL', 'op_folder')
        SK_ = SK_settings(self.conf)
        self.ws_name = SK_.ws + SK_.ip + ":" + str(
            SK_.aktport) + "/signalk/v1/stream?subscribe=self"

        Language(self.conf)

        wx.Frame.__init__(self,
                          None,
                          title='diagnostic Signal K input',
                          size=(770, 435))
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        panel = wx.Panel(self, wx.ID_ANY)

        self.ttimer = 100
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.timer_act, self.timer)

        self.SetFont(
            wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL,
                    wx.FONTWEIGHT_NORMAL))

        self.icon = wx.Icon(self.currentpath + '/static/icons/openplotter.ico',
                            wx.BITMAP_TYPE_ICO)
        self.SetIcon(self.icon)

        self.list = wx.ListCtrl(panel,
                                -1,
                                style=wx.LC_REPORT | wx.SUNKEN_BORDER)
        self.list.InsertColumn(0, _('SRC'), width=200)
        self.list.InsertColumn(1, _('Signal K'), width=310)
        self.list.InsertColumn(2, _('Value'), wx.LIST_FORMAT_RIGHT, width=190)
        self.list.InsertColumn(3, _('Unit'), width=45)
        self.list.InsertColumn(4,
                               _('Interval'),
                               wx.LIST_FORMAT_RIGHT,
                               width=55)
        self.list.InsertColumn(5, _('Status'), width=50)
        self.list.InsertColumn(6, _('Description'), width=500)
        self.list.InsertColumn(7, _('label'), width=100)
        self.list.InsertColumn(8, _('type'), width=90)
        self.list.InsertColumn(9, _('pgn'), width=70)
        self.list.InsertColumn(10, _('src'), width=50)
        self.list.InsertColumn(11, _('sentence'), width=50)
        self.list.InsertColumn(12, _('talker'), width=50)

        sort_SRC = wx.Button(panel, label=_('Sort SRC'))
        sort_SRC.Bind(wx.EVT_BUTTON, self.on_sort_SRC)

        sort_SK = wx.Button(panel, label=_('Sort SK'))
        sort_SK.Bind(wx.EVT_BUTTON, self.on_sort_SK)

        show_keys = wx.Button(panel, label=_('Show All SK keys'))
        show_keys.Bind(wx.EVT_BUTTON, self.on_show_keys)

        self.private_unit = wx.CheckBox(panel,
                                        label=_('private Unit'),
                                        pos=(360, 32))
        self.private_unit.Bind(wx.EVT_CHECKBOX, self.on_private_unit)
        self.private_unit.SetValue(self.private_unit_s)

        unit_setting = wx.Button(panel, label=_('Unit Setting'))
        unit_setting.Bind(wx.EVT_BUTTON, self.on_unit_setting)

        vbox = wx.BoxSizer(wx.VERTICAL)
        hlistbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hlistbox.Add(self.list, 1, wx.ALL | wx.EXPAND, 5)
        hbox.Add(sort_SRC, 0, wx.RIGHT | wx.LEFT, 5)
        hbox.Add(sort_SK, 0, wx.RIGHT | wx.LEFT, 5)
        hbox.Add(show_keys, 0, wx.RIGHT | wx.LEFT, 5)
        hbox.Add((0, 0), 1, wx.RIGHT | wx.LEFT, 5)
        hbox.Add(self.private_unit, 0, wx.RIGHT | wx.LEFT, 5)
        hbox.Add(unit_setting, 0, wx.RIGHT | wx.LEFT, 5)
        vbox.Add(hlistbox, 1, wx.ALL | wx.EXPAND, 0)
        vbox.Add(hbox, 0, wx.ALL | wx.EXPAND, 0)
        panel.SetSizer(vbox)

        self.CreateStatusBar()

        self.read()
        self.start()

        self.Show(True)

        self.status = ''
        self.data = []
        self.baudc = 0
        self.baud = 0

        self.timer.Start(self.ttimer)
        self.no_action = 0
        self.no_action_limit = 5000 / self.ttimer

    def timer_act(self, e):
        if len(self.buffer) > 0:
            self.no_action = 0
            for ii in self.buffer:
                if 0 <= ii[0] < self.list.GetItemCount():
                    self.list.SetStringItem(ii[0], ii[1], ii[2])
                else:
                    self.sorting()
            self.buffer = []
        else:
            self.no_action += 1
            if self.no_action > self.no_action_limit:
                if self.ws:
                    self.ws.close()
                self.start()
                self.no_action = 0

    def json_interval(self, time_old, time_new):
        sek_n = float(time_new[17:22])
        sek_o = float(time_old[17:22])
        if sek_n >= sek_o:
            dif = sek_n - sek_o
        else:
            dif = sek_n + 60 - sek_o
        return dif

    def read(self):
        self.list_SK_unit = []

        self.keys = GetKeys()
        data = self.keys.keys

        data_sk_unit_private = []
        if os.path.isfile(self.home + '/.openplotter/private_unit.json'):
            with open(self.home +
                      '/.openplotter/private_unit.json') as data_file:
                data_sk_unit_private = ujson.load(data_file)

        for i in data:
            self.list_SK_unit.append([str(i[0]), str(i[2]), '', str(i[1])])
        for j in data_sk_unit_private:
            for i in self.list_SK_unit:
                if j[0] == i[0]:
                    i[2] = j[2]
                    break

        self.list_SK_unit.sort(key=lambda tup: tup[0])
        self.list_SK_unit.sort(key=lambda tup: tup[1])

        self.data_sk_star3 = []
        self.data_sk_star4 = []
        self.data_sk_1 = []
        self.data_sk_2 = []
        self.data_sk_3 = []
        self.data_sk_4 = []
        self.data_sk_5 = []
        for i in self.list_SK_unit:
            j = i[0].split('.')
            if "*" in i[0]:
                if len(j) == 3:
                    self.data_sk_star3.append(i)
                elif len(j) == 4:
                    self.data_sk_star4.append(i)
            else:
                if len(j) == 3:
                    self.data_sk_3.append(i)
                elif len(j) == 4:
                    self.data_sk_4.append(i)
                elif len(j) == 1:
                    self.data_sk_1.append(i)
                elif len(j) == 2:
                    self.data_sk_2.append(i)
                elif len(j) == 5:
                    self.data_sk_5.append(i)

    def lookup_star(self, name):
        j = name.split('.')
        erg = []
        if len(j) == 3:
            for i in self.data_sk_3:
                if name == i[0]:
                    erg = i
                    break
        elif len(j) == 4:
            for i in self.data_sk_4:
                if name == i[0]:
                    erg = i
                    break
        elif len(j) == 1:
            for i in self.data_sk_1:
                if name == i[0]:
                    erg = i
                    break
        elif len(j) == 2:
            for i in self.data_sk_2:
                if name == i[0]:
                    erg = i
                    break
        elif len(j) == 5:
            for i in self.data_sk_5:
                if name == i[0]:
                    erg = i
                    break

        if erg == []:
            if len(j) == 3:
                for i in self.data_sk_star3:
                    if (j[0] + ".*." + j[2]) == i[0]:
                        erg = i
                        break
                    elif (j[0] + '.' + j[1] + '.*') == i[0]:
                        erg = i
                        break
            if len(j) == 4:
                for i in self.data_sk_star4:
                    if (j[0] + '.*.' + j[2] + '.' + j[3]) == i[0]:
                        erg = i
                        break
                    elif (j[0] + '.' + j[1] + '.*.' + j[3]) == i[0]:
                        erg = i
                        break

        self.SK_unit = ''
        self.SK_unit_priv = ''
        self.SK_description = ''
        if erg != []:
            self.SK_unit = erg[1]
            self.SK_description = erg[3]
            if erg[2] != '':
                self.SK_unit_priv = erg[2]
            else:
                self.SK_unit_priv = erg[1]
        else:
            print 'no unit for ', name

        self.SK_Faktor_priv = 1
        self.SK_Offset_priv = 0
        if self.SK_unit_priv != self.SK_unit:
            if self.SK_unit == 'Hz':
                if self.SK_unit_priv == 'RPM':
                    self.SK_Faktor_priv = 0.0166666666
            elif self.SK_unit == 'K':
                if self.SK_unit_priv == 'C':
                    self.SK_Offset_priv = -273.15
                elif self.SK_unit_priv == 'F':
                    self.SK_Faktor_priv = 1.8
                    self.SK_Offset_priv = -459.67
            elif self.SK_unit == 'J':
                if self.SK_unit_priv == 'Ah(12V)':
                    self.SK_Faktor_priv = 43200.
                if self.SK_unit_priv == 'Ah(24V)':
                    self.SK_Faktor_priv = 86400
            elif self.SK_unit == 'm':
                if self.SK_unit_priv == 'ft':
                    self.SK_Faktor_priv = 0.3048
                elif self.SK_unit_priv == 'nm':
                    self.SK_Faktor_priv = 1852
                elif self.SK_unit_priv == 'km':
                    self.SK_Faktor_priv = 1000
            elif self.SK_unit == 'm/s':
                if self.SK_unit_priv == 'kn':
                    self.SK_Faktor_priv = 0.514444444
                elif self.SK_unit_priv == 'kmh':
                    self.SK_Faktor_priv = 0, 277778
                elif self.SK_unit_priv == 'mph':
                    self.SK_Faktor_priv = 0.44704
            elif self.SK_unit == 'm3':
                if self.SK_unit_priv == 'dm3':
                    self.SK_Faktor_priv = 0.001
                elif self.SK_unit_priv == 'gal':
                    self.SK_Faktor_priv = 0.00378541
            elif self.SK_unit == 'm3/s':
                if self.SK_unit_priv == 'l/h':
                    self.SK_Faktor_priv = 2.777778E-7
                elif self.SK_unit_priv == 'gal/h':
                    self.SK_Faktor_priv = 0.0000010515
            elif self.SK_unit == 'Pa':
                if self.SK_unit_priv == 'hPa':
                    self.SK_Faktor_priv = 100
                elif self.SK_unit_priv == 'Bar':
                    self.SK_Faktor_priv = 100000
            elif self.SK_unit == 'rad' and self.SK_unit_priv == 'deg':
                self.SK_Faktor_priv = 0.0174533
            elif self.SK_unit == 's':
                if self.SK_unit_priv == 'h':
                    self.SK_Faktor_priv = 3600
                elif self.SK_unit_priv == 'd':
                    self.SK_Faktor_priv = 86400
                elif self.SK_unit_priv == 'y':
                    self.SK_Faktor_priv = 31536000
            elif self.SK_unit == 'ratio':
                if self.SK_unit_priv == '%':
                    self.SK_Faktor_priv = 0.01
        else:
            self.SK_Faktor_priv = 1
            self.SK_Offset_priv = 0

    def on_sort_SRC(self, e):
        self.sortCol = 0
        self.sorting()

    def on_sort_SK(self, e):
        self.sortCol = 1
        self.sorting()

    def on_show_keys(self, e):
        dlg = showKeys()
        res = dlg.ShowModal()
        dlg.Destroy()

    def sorting(self):
        self.list.DeleteAllItems()
        list_new = []
        for i in sorted(self.list_SK, key=lambda item: (item[self.sortCol])):
            list_new.append(i)
        self.list_SK = list_new
        self.init2()

    def init2(self):
        index = 0
        for i in self.list_SK:
            if type(i[2]) is float:
                pass
            elif type(i[2]) is str:
                pass
            else:
                i[2] = 0.0
            self.list.InsertStringItem(index, str(i[0]))
            self.list.SetStringItem(index, 1, str(i[1]))

            if not self.private_unit_s:
                if type(i[2]) is str:
                    self.buffer.append([index, 2, i[2]])
                else:
                    self.buffer.append([index, 2, str('%.3f' % i[2])])
                self.buffer.append([index, 3, i[3]])
            else:
                if type(i[2]) is str:
                    self.buffer.append([index, 2, i[2]])
                else:
                    i[9] = i[2] / i[10] + i[11]
                    self.buffer.append([index, 2, str('%.3f' % i[9])])
                self.buffer.append([index, 3, i[8]])
            self.list.SetStringItem(index, 4, str('%.1f' % i[4]))
            self.list.SetStringItem(index, 5, str(i[5]))
            self.list.SetStringItem(index, 6, str(i[6]))
            self.list.SetStringItem(index, 7, str(i[12]))
            self.list.SetStringItem(index, 8, str(i[13]))
            self.list.SetStringItem(index, 9, str(i[14]))
            self.list.SetStringItem(index, 10, str(i[15]))
            self.list.SetStringItem(index, 11, str(i[16]))
            self.list.SetStringItem(index, 12, str(i[17]))
            index += 1

    def on_unit_setting(self, e):
        subprocess.Popen(['python', self.currentpath + '/unit-private.py'])

    def OnClose(self, e):
        self.endlive = True

        if self.ws:
            self.ws.close()
        self.timer.Stop()
        self.Destroy()

    def on_message(self, ws, message):
        type = ''
        talker = ''
        sentence = ''
        src_ = ''
        pgn = ''
        label = ''
        src = ''
        type = ''
        value = ''

        if self.endlive:
            self.on_close(ws)
            self.ende = True
            return
            js_upb = ''
        #if True:
        try:
            js_upb = ujson.loads(message)
            if 'updates' not in js_upb:
                return
            js_up = js_upb['updates'][0]

            if 'source' in js_up.keys():
                source = js_up['source']
                label = source['label']
                if 'type' in source:
                    type = source['type']
                    if type == 'NMEA0183':
                        if 'talker' in source:
                            talker = source['talker']
                            src = label + '.' + talker
                            if 'sentence' in source:
                                sentence = source['sentence']
                                src = label + '.' + sentence
                    elif type == 'NMEA2000':
                        if 'src' in source:
                            src_ = source['src']
                            src = label + '.' + src_
                            if 'pgn' in source:
                                pgn = source['pgn']
                                src += '.' + str(pgn)
            if '$source' in js_up and src == '':
                src = js_up['$source']
            if 'timestamp' in js_up.keys():
                timestamp = js_up['timestamp']
            else:
                timestamp = '2000-01-01T00:00:00.000Z'
            values_ = js_up['values']
            for values in values_:
                path = values['path']
                value = values['value']
                src2 = src
                timestamp2 = timestamp
                if isinstance(value, dict):
                    if 'timestamp' in value: timestamp2 = value['timestamp']
                    if '$source' in value and src == '':
                        src = value['$source']
                    elif 'source' in value:
                        source = value['source']
                        label = source['label']
                        if 'type' in source:
                            type = source['type']
                            if type == 'NMEA0183':
                                if 'talker' in source:
                                    talker = source['talker']
                                    src = label + '.' + talker
                                    if 'sentence' in source:
                                        sentence = source['sentence']
                                        src = label + '.' + sentence
                            elif type == 'NMEA2000':
                                if 'src' in source:
                                    src_ = source['src']
                                    src = label + '.' + src_
                                    if 'pgn' in source:
                                        pgn = source['pgn']
                                        src += '.' + str(pgn)
                    for lvalue in value:
                        result = True
                        if lvalue in ['source', '$source', 'method']:
                            result = False
                        elif lvalue == 'timestamp':
                            if 'position' in path and 'RMC' in src2:
                                self.update_add(timestamp2,
                                                'navigation.datetime', src2,
                                                timestamp2, label, type, pgn,
                                                src_, sentence, talker)
                            result = False
                        if result:
                            path2 = path + '.' + lvalue
                            value2 = value[lvalue]
                            self.update_add(value2, path2, src2, timestamp2,
                                            label, type, pgn, src_, sentence,
                                            talker)

                else:
                    self.update_add(value, path, src, timestamp, label, type,
                                    pgn, src_, sentence, talker)

        except:
            print 'Error when parsing this sentence:'
            print js_upb

    def update_add(self, value, path, src, timestamp, label, type, pgn, src_,
                   sentence, talker):
        # SRC SignalK Value Unit Interval Status Description timestamp	private_Unit private_Value priv_Faktor priv_Offset label type pgn src_ sentence talker
        #  0    1      2     3      4        5        6          7           8             9           10          11		12	  13   14  15	  16	  17
        if isinstance(value, list): value = value[0]
        #if type(value) is list: value = value[0]

        if isinstance(value, float): pass
        elif isinstance(value, basestring): value = str(value)
        elif isinstance(value, int): value = float(value)
        elif value is None: value = 'None'
        else: value = 0.0

        index = 0
        exists = False
        for i in self.list_SK:
            if path == i[1] and i[0] == src:
                exists = True
                i[0] = src
                i[2] = value
                if i[4] == 0.0:
                    i[4] = self.json_interval(i[7], timestamp)
                else:
                    i[4] = i[4] * .6 + 0.4 * self.json_interval(
                        i[7], timestamp)
                i[7] = timestamp
                self.buffer.append([index, 0, i[0]])
                self.buffer.append([index, 4, str('%.2f' % i[4])])
                if isinstance(i[2], str):
                    #if type(i[2]) is str:
                    self.buffer.append([index, 2, i[2]])
                    self.buffer.append([index, 3, i[3]])
                    break
                elif isinstance(i[2], float):
                    #elif type(i[2]) is float:
                    pass
                else:
                    i[2] = 0.0
                if not self.private_unit_s:
                    self.buffer.append([index, 2, str('%.3f' % i[2])])
                    self.buffer.append([index, 3, i[3]])
                else:
                    i[9] = i[2] / i[10] + i[11]
                    self.buffer.append([index, 2, str('%.3f' % i[9])])
                    self.buffer.append([index, 3, i[8]])
                break
            index += 1
        if not exists:
            self.lookup_star(path)
            self.list_SK.append([
                src, path, value,
                str(self.SK_unit), 0.0, 1, self.SK_description, timestamp,
                str(self.SK_unit_priv), 0, self.SK_Faktor_priv,
                self.SK_Offset_priv, label, type,
                str(pgn), src_, sentence, talker
            ])
            self.buffer.append([-1, 0, ''])

    def on_private_unit(self, e):
        self.private_unit_s = self.private_unit.GetValue()

    def on_error(self, ws, error):
        print error

    def on_close(self, ws):
        ws.close()

    def on_open(self, ws):
        pass

    def run(self):
        self.endlive = False
        self.ende = False
        self.ws = websocket.WebSocketApp(
            self.ws_name,
            on_message=lambda ws, msg: self.on_message(ws, msg),
            on_error=lambda ws, err: self.on_error(ws, err),
            on_close=lambda ws: self.on_close(ws))
        self.ws.on_open = lambda ws: self.on_open(ws)
        self.ws.run_forever()
        self.ws = None

    def start(self):
        def run():
            self.run()

        self.thread = threading.Thread(target=run)
        self.thread.start()
Example #34
0
    def __init__(self):
        self.list_SK = []
        self.data_SK_unit_private = []
        self.SK_unit = ''
        self.SK_description = ''

        self.conf = Conf()
        self.home = self.conf.home
        self.currentpath = self.home + self.conf.get(
            'GENERAL', 'op_folder') + '/openplotter'

        Language(self.conf)

        logging.basicConfig()
        self.buffer = []
        self.sortCol = 0

        wx.Frame.__init__(self,
                          None,
                          title='diagnostic SignalK input',
                          size=(650, 435))
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        panel = wx.Panel(self, wx.ID_ANY)

        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)

        self.list = wx.ListCtrl(panel,
                                -1,
                                style=wx.LC_REPORT | wx.SUNKEN_BORDER)
        self.list.InsertColumn(0, 'SignalK', width=400)
        self.list.InsertColumn(1, _('SK Unit'), width=80)
        self.list.InsertColumn(2, _('Unit'), width=80)
        self.list.InsertColumn(3, _('Description'), width=500)

        self.sort_UnitSK = wx.Button(panel, label=_('Sort SK Unit'))
        self.sort_UnitSK.Bind(wx.EVT_BUTTON, self.on_sort_UnitSK)

        self.sort_Unit = wx.Button(panel, label=_('Sort Unit'))
        self.Bind(wx.EVT_BUTTON, self.on_sort_Unit, self.sort_Unit)

        self.sort_SK = wx.Button(panel, label=_('Sort SK'))
        self.sort_SK.Bind(wx.EVT_BUTTON, self.on_sort_SK)

        self.change_selected = wx.Button(panel, label=_('change selected'))
        self.change_selected.Bind(wx.EVT_BUTTON, self.on_change_selected)

        list_convert = [
            'Hz', 'Hz RPM', 'J', 'J Ah(12V)', 'J Ah(24V)', 'K', 'K C', 'K F',
            'm', 'm ft', 'm nm', 'm km', 'm/s', 'm/s kn', 'm/s kmh', 'm/s mph',
            'm3', 'm3 dm3', 'm3 gal', 'm3/s', 'm3/s l/h', 'm3/s gal/h', 'Pa',
            'Pa hPa', 'Pa Bar', 'rad', 'rad deg', 's', 's h', 's d', 's y',
            'ratio', 'ratio %'
        ]
        self.select_Unit_t = wx.StaticText(panel, label=_('convert'))
        self.select_Unit = wx.ComboBox(panel,
                                       choices=list_convert,
                                       style=wx.CB_READONLY,
                                       size=(150, 32))

        vbox = wx.BoxSizer(wx.VERTICAL)
        hlistbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hlistbox.Add(self.list, 1, wx.ALL | wx.EXPAND, 5)
        hbox.Add(self.sort_SK, 0, wx.RIGHT | wx.LEFT, 5)
        hbox.Add(self.sort_UnitSK, 0, wx.RIGHT | wx.LEFT, 5)
        hbox.Add(self.sort_Unit, 0, wx.RIGHT | wx.LEFT, 5)
        hbox.Add((0, 0), 1, wx.RIGHT | wx.LEFT, 5)
        hbox.Add(self.change_selected, 0, wx.RIGHT | wx.LEFT, 5)
        hbox.Add(self.select_Unit_t, 0, wx.LEFT | wx.TOP, 5)
        hbox.Add(self.select_Unit, 0, wx.RIGHT | wx.LEFT, 5)
        vbox.Add(hlistbox, 1, wx.ALL | wx.EXPAND, 0)
        vbox.Add(hbox, 0, wx.ALL | wx.EXPAND, 0)
        panel.SetSizer(vbox)

        self.CreateStatusBar()

        self.read()
        self.sorting()

        self.Show(True)
Example #35
0
home=paths.home
currentpath=paths.currentpath

device=''
ssid=''
passw=''

try:
	boot_conf = ConfigParser.SafeConfigParser()
	boot_conf.read('/boot/config.txt')
	device=boot_conf.get('OPENPLOTTER', 'device')
	ssid=boot_conf.get('OPENPLOTTER', 'ssid')
	passw=boot_conf.get('OPENPLOTTER', 'pass')
except Exception,e: print str(e)

conf=Conf()

if device and ssid and passw:
	conf.set('WIFI', 'enable', '1')
	conf.set('WIFI', 'device', device)
	conf.set('WIFI', 'ssid', ssid)
	conf.set('WIFI', 'password', passw)

delay=int(conf.get('STARTUP', 'delay'))

kplex=conf.get('STARTUP', 'kplex')
opencpn=conf.get('STARTUP', 'opencpn')
opencpn_no=conf.get('STARTUP', 'opencpn_no_opengl')
opencpn_fullscreen=conf.get('STARTUP', 'opencpn_fullscreen')
x11vnc=conf.get('STARTUP', 'x11vnc')
gps_time=conf.get('STARTUP', 'gps_time')
Example #36
0
boot_conf.read('/boot/config.txt')
try:
	device=boot_conf.get('OPENPLOTTER', 'device')
	ssid=boot_conf.get('OPENPLOTTER', 'ssid')
	passw=boot_conf.get('OPENPLOTTER', 'pass')
	hw_mode = boot_conf.get('OPENPLOTTER', 'hw_mode')
	channel = boot_conf.get('OPENPLOTTER', 'channel')
	wpa = boot_conf.get('OPENPLOTTER', 'wpa')
	boot_ap=1
except: boot_ap=0
try:
	share=boot_conf.get('OPENPLOTTER', 'share')
	boot_sh=1
except: boot_sh=0

conf=Conf()

if boot_ap==1:
	conf.set('WIFI', 'enable', '1')
	if device: conf.set('WIFI', 'device', device)
	else: conf.set('WIFI', 'device', 'wlan0')
	if ssid: conf.set('WIFI', 'ssid', ssid)
	else: conf.set('WIFI', 'ssid', 'OpenPlotter')
	if passw: conf.set('WIFI', 'password', passw)
	else: conf.set('WIFI', 'password', '12345678')
	if hw_mode: conf.set('WIFI', 'hw_mode', hw_mode)
	else: conf.set('WIFI', 'hw_mode', 'g')
	if channel: conf.set('WIFI', 'channel', channel)
	else: conf.set('WIFI', 'channel', '6')
	if wpa: conf.set('WIFI', 'wpa', wpa)
	else: conf.set('WIFI', 'wpa', '2')
Example #37
0
# 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 <http://www.gnu.org/licenses/>.

import serial
import socket
import sys

from classes.conf import Conf

conf = Conf()

activ = False
activ = conf.get('N2K', 'output') == '1'
if not activ:
    sys.exit(0)

try:
    ser = serial.Serial(conf.get('N2K', 'can_usb'), 115200, timeout=0.5)
except:
    print 'failed to start N2K output server on ' + conf.get('N2K', 'can_usb')
    sys.exit(0)

Quelle = '127.0.0.1'  # Adresse des eigenen Rechners
Port = 55560
Example #38
0
# 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 <http://www.gnu.org/licenses/>.

import sys, ConfigParser, os, socket, time, pynmea2
from w1thermsensor import W1ThermSensor
from classes.conf import Conf

conf=Conf()

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

eng_temp=''

tick=time.time()

while True:
	tick2=time.time()

	#GENERATE
	if tick2-tick > float(conf.get('STARTUP', 'nmea_rate_sen')):
		tick=time.time()

		# read DS18B20
Example #39
0
# along with Openplotter. If not, see <http://www.gnu.org/licenses/>.

import sys, subprocess, wx
from classes.conf import Conf
from classes.paths import Paths
from classes.language import Language

action=sys.argv[1]

#see actions.py
start_all_actions='18'

paths=Paths()
currentpath=paths.currentpath

conf=Conf()

Language(conf.get('GENERAL','lang'))

data=conf.get('ACTIONS', 'triggers')
triggers=data.split('||')
triggers.pop()
for index,item in enumerate(triggers):
	ii=item.split(',')
	triggers[index]=ii

data=conf.get('ACTIONS', 'actions')
trigger_actions=data.split('||')
trigger_actions.pop()
for index,item in enumerate(trigger_actions):
	ii=item.split(',')
Example #40
0
    def __init__(self):

        self.conf = Conf()
        Language(self.conf.get("GENERAL", "lang"))

        wx.Frame.__init__(self, None, title=_("Connection"), size=(550, 385))

        self.SetFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))

        self.icon = wx.Icon(currentpath + "/openplotter.ico", wx.BITMAP_TYPE_ICO)
        self.SetIcon(self.icon)

        self.in_out = sys.argv[1]
        self.con_type = sys.argv[2]

        wx.StaticText(self, label=_("Name"), pos=(25, 35))
        self.name = wx.TextCtrl(self, -1, size=(120, 32), pos=(20, 55))

        if self.con_type == "serial":
            if self.in_out == "in":
                wx.StaticBox(self, label=_(" Serial input "), size=(530, 90), pos=(10, 10))
            if self.in_out == "out":
                wx.StaticBox(self, label=_(" Serial output "), size=(530, 90), pos=(10, 10))
            self.SerDevLs = []
            self.SerialCheck("/dev/rfcomm")
            self.SerialCheck("/dev/ttyUSB")
            self.SerialCheck("/dev/ttyS")
            self.SerialCheck("/dev/ttyACM")
            wx.StaticText(self, label=_("Port"), pos=(155, 35))
            self.deviceComboBox = wx.ComboBox(
                self, choices=self.SerDevLs, style=wx.CB_DROPDOWN, size=(155, 32), pos=(150, 55)
            )
            if self.SerDevLs:
                self.deviceComboBox.SetValue(self.SerDevLs[0])
            self.bauds = ["4800", "9600", "19200", "38400", "57600", "115200"]
            wx.StaticText(self, label=_("Bauds"), pos=(320, 35))
            self.baudComboBox = wx.ComboBox(
                self, choices=self.bauds, style=wx.CB_READONLY, size=(90, 32), pos=(315, 55)
            )
            self.baudComboBox.SetValue("4800")

        if self.con_type == "network":
            if self.in_out == "in":
                wx.StaticBox(self, label=_(" Network input "), size=(530, 90), pos=(10, 10))
                self.gpsd = wx.Button(self, label=_("GPSD"), pos=(440, 55))
                self.Bind(wx.EVT_BUTTON, self.create_gpsd, self.gpsd)
            if self.in_out == "out":
                wx.StaticBox(self, label=_(" Network output "), size=(530, 90), pos=(10, 10))
            self.type = ["TCP", "UDP"]
            wx.StaticText(self, label=_("Type"), pos=(155, 35))
            self.typeComboBox = wx.ComboBox(self, choices=self.type, style=wx.CB_READONLY, size=(70, 32), pos=(150, 55))
            self.typeComboBox.SetValue("TCP")
            wx.StaticText(self, label=_("Address"), pos=(235, 35))
            self.address = wx.TextCtrl(self, -1, size=(120, 32), pos=(230, 55))
            wx.StaticText(self, label=_("Port"), pos=(365, 35))
            self.port = wx.TextCtrl(self, -1, size=(55, 32), pos=(360, 55))

        wx.StaticBox(self, label=_(" Filter "), size=(530, 195), pos=(10, 105))
        self.mode_filter = [_("none"), _("Accept only sentences:"), _("Ignore sentences:")]
        self.filter = wx.ComboBox(self, choices=self.mode_filter, style=wx.CB_READONLY, size=(220, 32), pos=(20, 130))
        self.filter.SetValue(self.mode_filter[0])
        wx.StaticText(self, label=_("Filtering"), pos=(25, 175))
        self.sentences = wx.TextCtrl(self, -1, style=wx.CB_READONLY, size=(400, 32), pos=(20, 195))
        self.sentences.SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_INACTIVECAPTION))
        self.delete = wx.Button(self, label=_("Delete"), pos=(440, 195))
        self.Bind(wx.EVT_BUTTON, self.delete_sentences, self.delete)
        wx.StaticText(self, label=_("Talker - Sentence"), pos=(25, 240))
        self.talker = wx.TextCtrl(self, -1, size=(35, 32), pos=(20, 260))
        wx.StaticText(self, label=_("-"), pos=(60, 265))
        self.sent = wx.TextCtrl(self, -1, size=(45, 32), pos=(70, 260))
        self.add_sent = wx.Button(self, label=_("Add sentence"), pos=(160, 260))
        self.Bind(wx.EVT_BUTTON, self.add_sentence, self.add_sent)

        self.sentences.SetValue(_("nothing"))
        self.talker.SetValue("**")
        self.sent.SetValue("***")

        self.ok = wx.Button(self, label=_("OK"), pos=(440, 310))
        self.Bind(wx.EVT_BUTTON, self.ok_conn, self.ok)
        self.cancel = wx.Button(self, label=_("Cancel"), pos=(330, 310))
        self.Bind(wx.EVT_BUTTON, self.cancel_conn, self.cancel)

        self.Centre()
Example #41
0
# 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 <http://www.gnu.org/licenses/>.

import time, socket, threading, datetime, geomag, pynmea2, math
from classes.datastream import DataStream
from classes.conf import Conf
from classes.language import Language

conf=Conf()

Language(conf.get('GENERAL','lang'))

global sock_in
global error
sock_in=''
error=0
a=DataStream(conf)
last_heading=''
heading_time=''

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

accuracy=float(conf.get('STARTUP', 'cal_accuracy'))
rate=float(conf.get('STARTUP', 'nmea_rate_cal'))
    def __init__(self):
        self.SK_unit = ''
        self.SK_description = ''
        self.SK_unit_priv = 0
        self.SK_Faktor_priv = 1
        self.SK_Offset_priv = 0
        self.ws = None

        self.thread = threading._DummyThread

        self.private_unit_s = 1
        logging.basicConfig()
        self.buffer = []
        self.list_SK = []
        self.list_SK_unit = []
        self.sortCol = 0

        self.conf = Conf()
        self.home = self.conf.home
        self.currentpath = self.conf.get('GENERAL', 'op_folder')
        SK_ = SK_settings(self.conf)
        self.ws_name = SK_.ws + SK_.ip + ":" + str(
            SK_.aktport) + "/signalk/v1/stream?subscribe=self"

        Language(self.conf)

        wx.Frame.__init__(self,
                          None,
                          title='diagnostic Signal K input',
                          size=(770, 435))
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        panel = wx.Panel(self, wx.ID_ANY)

        self.ttimer = 100
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.timer_act, self.timer)

        self.SetFont(
            wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL,
                    wx.FONTWEIGHT_NORMAL))

        self.icon = wx.Icon(self.currentpath + '/static/icons/openplotter.ico',
                            wx.BITMAP_TYPE_ICO)
        self.SetIcon(self.icon)

        self.list = wx.ListCtrl(panel,
                                -1,
                                style=wx.LC_REPORT | wx.SUNKEN_BORDER)
        self.list.InsertColumn(0, _('SRC'), width=200)
        self.list.InsertColumn(1, _('Signal K'), width=310)
        self.list.InsertColumn(2, _('Value'), wx.LIST_FORMAT_RIGHT, width=190)
        self.list.InsertColumn(3, _('Unit'), width=45)
        self.list.InsertColumn(4,
                               _('Interval'),
                               wx.LIST_FORMAT_RIGHT,
                               width=55)
        self.list.InsertColumn(5, _('Status'), width=50)
        self.list.InsertColumn(6, _('Description'), width=500)
        self.list.InsertColumn(7, _('label'), width=100)
        self.list.InsertColumn(8, _('type'), width=90)
        self.list.InsertColumn(9, _('pgn'), width=70)
        self.list.InsertColumn(10, _('src'), width=50)
        self.list.InsertColumn(11, _('sentence'), width=50)
        self.list.InsertColumn(12, _('talker'), width=50)

        sort_SRC = wx.Button(panel, label=_('Sort SRC'))
        sort_SRC.Bind(wx.EVT_BUTTON, self.on_sort_SRC)

        sort_SK = wx.Button(panel, label=_('Sort SK'))
        sort_SK.Bind(wx.EVT_BUTTON, self.on_sort_SK)

        show_keys = wx.Button(panel, label=_('Show All SK keys'))
        show_keys.Bind(wx.EVT_BUTTON, self.on_show_keys)

        self.private_unit = wx.CheckBox(panel,
                                        label=_('private Unit'),
                                        pos=(360, 32))
        self.private_unit.Bind(wx.EVT_CHECKBOX, self.on_private_unit)
        self.private_unit.SetValue(self.private_unit_s)

        unit_setting = wx.Button(panel, label=_('Unit Setting'))
        unit_setting.Bind(wx.EVT_BUTTON, self.on_unit_setting)

        vbox = wx.BoxSizer(wx.VERTICAL)
        hlistbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hlistbox.Add(self.list, 1, wx.ALL | wx.EXPAND, 5)
        hbox.Add(sort_SRC, 0, wx.RIGHT | wx.LEFT, 5)
        hbox.Add(sort_SK, 0, wx.RIGHT | wx.LEFT, 5)
        hbox.Add(show_keys, 0, wx.RIGHT | wx.LEFT, 5)
        hbox.Add((0, 0), 1, wx.RIGHT | wx.LEFT, 5)
        hbox.Add(self.private_unit, 0, wx.RIGHT | wx.LEFT, 5)
        hbox.Add(unit_setting, 0, wx.RIGHT | wx.LEFT, 5)
        vbox.Add(hlistbox, 1, wx.ALL | wx.EXPAND, 0)
        vbox.Add(hbox, 0, wx.ALL | wx.EXPAND, 0)
        panel.SetSizer(vbox)

        self.CreateStatusBar()

        self.read()
        self.start()

        self.Show(True)

        self.status = ''
        self.data = []
        self.baudc = 0
        self.baud = 0

        self.timer.Start(self.ttimer)
        self.no_action = 0
        self.no_action_limit = 5000 / self.ttimer
Example #43
0
class MyFrame(wx.Frame):
    def __init__(self):
        self.ttimer = 40
        self.conf = Conf()
        self.home = self.conf.home
        self.currentpath = self.home + self.conf.get(
            'GENERAL', 'op_folder') + '/openplotter'

        try:
            self.ser = serial.Serial(self.conf.get('N2K', 'can_usb'),
                                     115200,
                                     timeout=0.5)
        except:
            print 'failed to start N2K output setting on ' + self.conf.get(
                'N2K', 'can_usb')
            sys.exit(0)
        Language(self.conf)

        Buf_ = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0)
        self.Buffer = bytearray(Buf_)
        self.Zustand = 6
        self.buffer = 0
        self.PGN_list = []
        self.list_N2K_txt = []
        self.list_count = []
        self.p = 0

        wx.Frame.__init__(self, None, title="N2K setting", size=(650, 435))
        self.Bind(wx.EVT_CLOSE, self.OnClose)

        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.timer_act, self.timer)

        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)

        panel = wx.Panel(self, 100)
        wx.StaticText(panel,
                      wx.ID_ANY,
                      label="TX PGN",
                      style=wx.ALIGN_CENTER,
                      pos=(10, 5))
        self.list_N2K = CheckListCtrl(panel, 400, 260)
        self.list_N2K.SetBackgroundColour((230, 230, 230))
        self.list_N2K.SetPosition((10, 25))
        self.list_N2K.InsertColumn(0, _('PGN'), width=90)
        self.list_N2K.InsertColumn(1, _('info'), width=200)
        wx.StaticText(panel,
                      wx.ID_ANY,
                      label="enabled transmit PGN:",
                      style=wx.ALIGN_CENTER,
                      pos=(10, 300))
        self.printing = wx.StaticText(panel, size=(600, 70), pos=(10, 320))

        self.check_b = wx.Button(panel,
                                 label=_('check'),
                                 size=(70, 32),
                                 pos=(550, 20))
        self.Bind(wx.EVT_BUTTON, self.check, self.check_b)

        self.apply_b = wx.Button(panel,
                                 label=_('apply'),
                                 size=(70, 32),
                                 pos=(550, 60))
        self.Bind(wx.EVT_BUTTON, self.apply, self.apply_b)

        self.Centre()
        self.read_N2K()

        self.timer.Start(self.ttimer)

        self.check(0)

        self.Show(True)

    def check(self, e):
        self.Send_Command(1, 0x49, 0)
        time.sleep(0.2)
        self.read_stick_check()

    def apply(self, e):
        st = ''
        counter = 0
        for ii in self.list_N2K_txt:
            if self.list_N2K.IsChecked(counter):
                exist = 0
                for jj in self.PGN_list:
                    if ii[0] == str(jj):
                        exist = 1
                if exist == 0:
                    st += ii[0] + ' '
                    if len(self.PGN_list) < 36:
                        self.sendTX_PGN(int(ii[0]), 1)
                        self.PGN_list.append(ii[0])
                        time.sleep(0.2)

            counter += 1
        print 'new PGNs=', st

        st = ''
        for jj in self.PGN_list:
            counter = 0
            for ii in self.list_N2K_txt:
                exist = 0
                if ii[0] == str(jj):
                    if not self.list_N2K.IsChecked(counter):
                        exist = 1
                    if exist == 1:
                        st += ii[0] + ' '
                        self.sendTX_PGN(int(ii[0]), 0)
                        time.sleep(0.2)
                counter += 1
        print 'del PGNs=', st
        self.Send_Command(1, 0x01, 0)

    def sendTX_PGN(self, lPGN, add):
        if add:
            data_ = (0, 0, 0, 0, 1, 0xFE, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF,
                     0xFF)
        else:
            data_ = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
        data = bytearray(data_)
        data[0] = lPGN & 255
        data[1] = (lPGN >> 8) & 255
        data[2] = (lPGN >> 16) & 255

        self.Send_Command(14, 0x47, data)

    def Send_Command(self, length, command, arg):
        data_ = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
        data = bytearray(data_)

        data[0] = 0xa1  #command
        data[1] = length  #Actisense length
        data[2] = command
        i = 3
        while i < length + 2:
            data[i] = arg[i - 3]
            i += 1
        self.SendCommandtoSerial(data)

    def timer_act(self, e):
        self.getCharfromSerial()

    def OnClose(self, event):
        self.timer.Stop()
        self.Destroy()

    def SendCommandtoSerial(self, TXs):
        crc = 0
        #start = codecs.decode('1002', 'hex_codec')
        start = (0x10, 0x02)
        ende = codecs.decode('1003', 'hex_codec')
        ende = (0x10, 0x03)
        i = 0
        while i < TXs[1] + 2:
            crc += TXs[i]
            i += 1
        crc = (256 - crc) & 255
        TXs[TXs[1] + 2] = crc
        i = 0
        self.ser.write(chr(start[0]))
        self.ser.write(chr(start[1]))
        while i < TXs[1] + 3:
            self.ser.write(chr(TXs[i]))
            #print format(TXs[i], '02x')
            if TXs[i] == 0x10:
                self.ser.write(chr(TXs[i]))
            i += 1
        self.ser.write(chr(ende[0]))
        self.ser.write(chr(ende[1]))

    def getCharfromSerial(self):
        bytesToRead = self.ser.inWaiting()
        if bytesToRead > 0:
            buffer = self.ser.read(bytesToRead)
            for i in buffer:
                #sys.stdout.write(' '+hex(ord(i)))
                self.parse(ord(i))

    def parse(self, b):
        if self.Zustand == 6:  # zu Beginn auf 0x10 warten
            if b == 0x10:
                self.Zustand = 0x10
        elif self.Zustand == 0x10:
            if b == 0x10:  # 0x10 Schreiben wenn zweimal hintereinander
                self.Buffer[self.p] = b
                self.p += 1
                self.Zustand = 0
            elif b == 0x02:  # Anfang gefunden
                self.p = 0
                self.Zustand = 0
            elif b == 0x03:  # Ende gefunden
                if self.crcCheck():
                    #print "CRC"
                    self.output()
                self.p = 0
                self.Zustand = 6  # Auf Anfang zuruecksetzen
        elif self.Zustand == 0:
            if b == 0x10:
                self.Zustand = 0x10
            else:
                self.Buffer[self.p] = b
                self.p += 1

    def crcCheck(self):
        crc = 0
        i = 0
        while i < self.p:
            crc = (crc + self.Buffer[i]) & 255
            i += 1
        return (crc == 0)

    def output(self):
        k = 0
        if self.Buffer[0] == 0x93 and self.Buffer[1] == self.p - 3:
            #i=0
            #while i < 10:
            #	sys.stdout.write(' '+hex(self.Buffer[i]))
            #	i += 1
            #print ' '
            pass
        else:
            if self.Buffer[2] == 0x49 and self.Buffer[3] == 0x01:
                j = 0
                st = ''
                self.PGN_list = []
                while j < self.Buffer[14]:
                    i = j * 4
                    lPGN = self.Buffer[15 + i] + self.Buffer[
                        16 + i] * 256 + self.Buffer[17 + i] * 256 * 256
                    self.PGN_list.append(lPGN)
                    j += 1
                    st += str(lPGN) + ' '
                    if ((j) % 6) == 0 and j > 0:
                        st += '\n'
                self.printing.SetLabel(st)
                self.conf.set('N2K', 'pgn_output', st)

    def getCommandfromSerial(self, RXs):
        crc = 0
        start = (0x10, 0x02)
        ende = (0x10, 0x03)
        i = 0
        while i < RXs[1] + 2:
            crc += RXs[i]
            i += 1
        crc = (256 - crc) & 255
        RXs[RXs[1] + 2] = crc
        i = 0
        self.ser.write(chr(start[0]))
        self.ser.write(chr(start[1]))
        while i < RXs[1] + 3:
            self.ser.write(chr(RXs[i]))
            #print format(RXs[i], '02x')
            if RXs[i] == 0x10:
                self.ser.write(chr(RXs[i]))
            i += 1
        self.ser.write(chr(ende[0]))
        self.ser.write(chr(ende[1]))

    def read_N2K(self):
        if self.list_N2K.GetItemCount() < 3:
            while self.list_N2K.GetItemCount() > 3:
                self.list_N2K.DeleteItem(self.list_N2K.GetItemCount() - 1)

            self.list_N2K_txt = []
            with open(self.currentpath + '/classes/N2K_PGN.csv') as f:
                self.list_N2K_txt = [
                    x.strip('\n\r').split(',') for x in f.readlines()
                ]

            for ii in self.list_N2K_txt:
                pgn = int(ii[0])
                self.list_N2K.Append([pgn, ii[1]])

    def read_stick_check(self):
        counter = 0
        for ii in self.list_N2K_txt:
            for jj in self.PGN_list:
                if ii[0] == str(jj):
                    self.list_N2K.CheckItem(counter)
            counter += 1
Example #44
0
# 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 <http://www.gnu.org/licenses/>.

import time, socket, threading, datetime, geomag, pynmea2, math
import RPi.GPIO as GPIO
from classes.datastream import DataStream
from classes.conf import Conf
from classes.language import Language
from classes.actions import Actions

conf=Conf()

Language(conf.get('GENERAL','lang'))

global sock_in
global error
sock_in=''
error=0
a=DataStream()
actions=Actions()
nodata=''
global runSW1on
global runSW1off
global runSW2on
global runSW2off
global runSW3on
Example #45
0
    def __init__(self):
        self.ttimer = 40
        self.conf = Conf()
        self.home = self.conf.home
        self.currentpath = self.home + self.conf.get(
            'GENERAL', 'op_folder') + '/openplotter'

        try:
            self.ser = serial.Serial(self.conf.get('N2K', 'can_usb'),
                                     115200,
                                     timeout=0.5)
        except:
            print 'failed to start N2K output setting on ' + self.conf.get(
                'N2K', 'can_usb')
            sys.exit(0)
        Language(self.conf)

        Buf_ = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0)
        self.Buffer = bytearray(Buf_)
        self.Zustand = 6
        self.buffer = 0
        self.PGN_list = []
        self.list_N2K_txt = []
        self.list_count = []
        self.p = 0

        wx.Frame.__init__(self, None, title="N2K setting", size=(650, 435))
        self.Bind(wx.EVT_CLOSE, self.OnClose)

        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.timer_act, self.timer)

        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)

        panel = wx.Panel(self, 100)
        wx.StaticText(panel,
                      wx.ID_ANY,
                      label="TX PGN",
                      style=wx.ALIGN_CENTER,
                      pos=(10, 5))
        self.list_N2K = CheckListCtrl(panel, 400, 260)
        self.list_N2K.SetBackgroundColour((230, 230, 230))
        self.list_N2K.SetPosition((10, 25))
        self.list_N2K.InsertColumn(0, _('PGN'), width=90)
        self.list_N2K.InsertColumn(1, _('info'), width=200)
        wx.StaticText(panel,
                      wx.ID_ANY,
                      label="enabled transmit PGN:",
                      style=wx.ALIGN_CENTER,
                      pos=(10, 300))
        self.printing = wx.StaticText(panel, size=(600, 70), pos=(10, 320))

        self.check_b = wx.Button(panel,
                                 label=_('check'),
                                 size=(70, 32),
                                 pos=(550, 20))
        self.Bind(wx.EVT_BUTTON, self.check, self.check_b)

        self.apply_b = wx.Button(panel,
                                 label=_('apply'),
                                 size=(70, 32),
                                 pos=(550, 60))
        self.Bind(wx.EVT_BUTTON, self.apply, self.apply_b)

        self.Centre()
        self.read_N2K()

        self.timer.Start(self.ttimer)

        self.check(0)

        self.Show(True)
Example #46
0
					value = msg.payload
					value = value.replace('"', "'")
					SignalK='{"updates":[{"$source":"OPsensors.MQTT.'+msg.topic+'","values":[{"path":"'+path+'","value":"'+value+'"}]}]}\n'			
					sock.sendto(SignalK, ('127.0.0.1', 55557))
				if i[1] == 2: #signal k delta input
					SignalK = msg.payload		
					sock.sendto(SignalK, ('127.0.0.1', 55557))
	except Exception,e: print str(e)

def on_connect(client, userdata, flags, rc):
	try:
		for i in topics_list:
			client.subscribe(i[0], qos=0)
	except Exception,e: print str(e)

conf = Conf()

x=conf.get('MQTT', 'topics')
if x: topics_list=eval(x)
else: topics_list=[]

local_broker='127.0.0.1'
local_port='1883'
user=conf.get('MQTT', 'username')
passw=conf.get('MQTT', 'password')
broker=conf.get('MQTT', 'broker')
port=conf.get('MQTT', 'port')
client=''
client_local=''

if user and passw and topics_list:
Example #47
0
class MyFrame(wx.Frame):
    def __init__(self):
        self.SK_unit = ''
        self.SK_description = ''
        self.SK_unit_priv = 0
        self.SK_Faktor_priv = 1
        self.SK_Offset_priv = 0
        self.ws = None

        self.thread = threading._DummyThread

        self.private_unit_s = 1
        logging.basicConfig()
        self.buffer = []
        self.list_SK = []
        self.list_SK_unit = []
        self.sortCol = 0

        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='diagnostic SignalK input',
                          size=(670, 435))
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        panel = wx.Panel(self, wx.ID_ANY)

        self.ttimer = 100
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.timer_act, self.timer)

        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)

        self.list = wx.ListCtrl(panel,
                                -1,
                                style=wx.LC_REPORT | wx.SUNKEN_BORDER)
        self.list.InsertColumn(0, _('SRC'), width=245)
        self.list.InsertColumn(1, _('SignalK'), width=300)
        self.list.InsertColumn(2, _('Value'), wx.LIST_FORMAT_RIGHT, width=100)
        self.list.InsertColumn(3, _('Unit'), width=45)
        self.list.InsertColumn(4,
                               _('Interval'),
                               wx.LIST_FORMAT_RIGHT,
                               width=55)
        self.list.InsertColumn(5, _('Status'), width=50)
        self.list.InsertColumn(6, _('Description'), width=500)

        sort_SRC = wx.Button(panel, label=_('Sort SRC'))
        sort_SRC.Bind(wx.EVT_BUTTON, self.on_sort_SRC)

        sort_SK = wx.Button(panel, label=_('Sort SK'))
        sort_SK.Bind(wx.EVT_BUTTON, self.on_sort_SK)

        self.private_unit = wx.CheckBox(panel,
                                        label=_('private Unit'),
                                        pos=(360, 32))
        self.private_unit.Bind(wx.EVT_CHECKBOX, self.on_private_unit)
        self.private_unit.SetValue(self.private_unit_s)

        unit_setting = wx.Button(panel, label=_('Unit Setting'))
        unit_setting.Bind(wx.EVT_BUTTON, self.on_unit_setting)

        vbox = wx.BoxSizer(wx.VERTICAL)
        hlistbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hlistbox.Add(self.list, 1, wx.ALL | wx.EXPAND, 5)
        hbox.Add(sort_SRC, 0, wx.RIGHT | wx.LEFT, 5)
        hbox.Add(sort_SK, 0, wx.RIGHT | wx.LEFT, 5)
        hbox.Add((0, 0), 1, wx.RIGHT | wx.LEFT, 5)
        hbox.Add(self.private_unit, 0, wx.RIGHT | wx.LEFT, 5)
        hbox.Add(unit_setting, 0, wx.RIGHT | wx.LEFT, 5)
        vbox.Add(hlistbox, 1, wx.ALL | wx.EXPAND, 0)
        vbox.Add(hbox, 0, wx.ALL | wx.EXPAND, 0)
        panel.SetSizer(vbox)

        self.CreateStatusBar()

        self.read()
        self.start()

        self.Show(True)

        self.status = ''
        self.data = []
        self.baudc = 0
        self.baud = 0

        self.timer.Start(self.ttimer)
        self.no_action = 0
        self.no_action_limit = 5000 / self.ttimer

    def timer_act(self, e):
        if len(self.buffer) > 0:
            self.no_action = 0
            for ii in self.buffer:
                if 0 <= ii[0] < self.list.GetItemCount():
                    self.list.SetStringItem(ii[0], ii[1], ii[2])
                else:
                    self.sorting()
            self.buffer = []
        else:
            self.no_action += 1
            if self.no_action > self.no_action_limit:
                if self.ws:
                    self.ws.close()
                self.start()
                self.no_action = 0

    def json_interval(self, time_old, time_new):
        sek_n = float(time_new[17:22])
        sek_o = float(time_old[17:22])
        if sek_n >= sek_o:
            dif = sek_n - sek_o
        else:
            dif = sek_n + 60 - sek_o
        return dif

    def read(self):
        self.list_SK_unit = []

        try:
            with open(
                    self.home +
                    '/.config/signalk-server-node/node_modules/@signalk/signalk-schema/dist/keyswithmetadata.json'
            ) as data_file:
                data = json.load(data_file)
        except:
            #old signalk
            with open(
                    self.home +
                    '/.config/signalk-server-node/node_modules/@signalk/signalk-schema/src/keyswithmetadata.json'
            ) as data_file:
                data = json.load(data_file)

        data_sk_unit_private = []
        if os.path.isfile(self.home + '/.openplotter/private_unit.json'):
            with open(self.home +
                      '/.openplotter/private_unit.json') as data_file:
                data_sk_unit_private = json.load(data_file)

        for i in data:
            if 'units' in data[i].keys():
                if 'description' in data[i].keys():
                    ii = i.replace('/vessels/*/', '')
                    ii = ii.replace('RegExp', '*')
                    ii = ii.replace('/', '.')
                    self.list_SK_unit.append([
                        str(ii),
                        str(data[i]['units']), '',
                        str(data[i]['description'])
                    ])
                else:
                    self.list_SK_unit.append(
                        [str(ii), str(data[i]['units']), '', ''])
        for j in data_sk_unit_private:
            for i in self.list_SK_unit:
                if j[0] == i[0]:
                    i[2] = j[2]
                    break

        self.list_SK_unit.sort(key=lambda tup: tup[0])
        self.list_SK_unit.sort(key=lambda tup: tup[1])

    def lookup_star(self, name):
        skip = -1
        index = 0
        st = ''
        for i in name.split('.'):
            if index > -1:
                if skip == 0:
                    st += '.*'
                else:
                    if i in ['propulsion', 'sensors']:
                        skip = 1
                    elif i in ['electrical', 'registrations', 'tanks']:
                        skip = 2
                    st += '.' + i
            index += 1
            skip -= 1

        st = st[1:]
        self.SK_unit = ''
        self.SK_unit_priv = ''
        self.SK_description = ''
        for j in self.list_SK_unit:
            exist = False
            if j[0] == st:
                exist = True
                self.SK_unit = j[1]
                self.SK_description = j[3]
                if j[2] != '':
                    self.SK_unit_priv = j[2]
                else:
                    self.SK_unit_priv = j[1]
                break
        if not exist:
            print 'no unit for ', st

        self.SK_Faktor_priv = 1
        self.SK_Offset_priv = 0
        if self.SK_unit_priv != self.SK_unit:
            if self.SK_unit == 'Hz':
                if self.SK_unit_priv == 'RPM':
                    self.SK_Faktor_priv = 0.0166666666
            elif self.SK_unit == 'K':
                if self.SK_unit_priv == 'C':
                    self.SK_Offset_priv = -273.15
                elif self.SK_unit_priv == 'F':
                    self.SK_Faktor_priv = 1.8
                    self.SK_Offset_priv = -459.67
            elif self.SK_unit == 'J':
                if self.SK_unit_priv == 'Ah(12V)':
                    self.SK_Faktor_priv = 43200.
                if self.SK_unit_priv == 'Ah(24V)':
                    self.SK_Faktor_priv = 86400
            elif self.SK_unit == 'm':
                if self.SK_unit_priv == 'ft':
                    self.SK_Faktor_priv = 0.3048
                elif self.SK_unit_priv == 'nm':
                    self.SK_Faktor_priv = 1852
                elif self.SK_unit_priv == 'km':
                    self.SK_Faktor_priv = 1000
            elif self.SK_unit == 'm/s':
                if self.SK_unit_priv == 'kn':
                    self.SK_Faktor_priv = 0.514444444
                elif self.SK_unit_priv == 'kmh':
                    self.SK_Faktor_priv = 0, 277778
                elif self.SK_unit_priv == 'mph':
                    self.SK_Faktor_priv = 0.44704
            elif self.SK_unit == 'm3':
                if self.SK_unit_priv == 'l':
                    self.SK_Faktor_priv = 0.001
                elif self.SK_unit_priv == 'gal':
                    self.SK_Faktor_priv = 0.00378541
            elif self.SK_unit == 'm3/s':
                if self.SK_unit_priv == 'l/h':
                    self.SK_Faktor_priv = 2.777778E-7
                elif self.SK_unit_priv == 'gal/h':
                    self.SK_Faktor_priv = 0.0000010515
            elif self.SK_unit == 'Pa':
                if self.SK_unit_priv == 'hPa':
                    self.SK_Faktor_priv = 100
                elif self.SK_unit_priv == 'Bar':
                    self.SK_Faktor_priv = 100000
            elif self.SK_unit == 'rad' and self.SK_unit_priv == 'deg':
                self.SK_Faktor_priv = 0.0174533
            elif self.SK_unit == 's':
                if self.SK_unit_priv == 'h':
                    self.SK_Faktor_priv = 3600
                elif self.SK_unit_priv == 'd':
                    self.SK_Faktor_priv = 86400
                elif self.SK_unit_priv == 'y':
                    self.SK_Faktor_priv = 31536000
            elif self.SK_unit == 'ratio':
                if self.SK_unit_priv == '%':
                    self.SK_Faktor_priv = 0.01
        else:
            self.SK_Faktor_priv = 1
            self.SK_Offset_priv = 0

    def on_sort_SRC(self, e):
        self.sortCol = 0
        self.sorting()

    def on_sort_SK(self, e):
        self.sortCol = 1
        self.sorting()

    def sorting(self):
        self.list.DeleteAllItems()
        list_new = []
        for i in sorted(self.list_SK, key=lambda item: (item[self.sortCol])):
            list_new.append(i)
        self.list_SK = list_new
        self.init2()

    def init2(self):
        index = 0
        for i in self.list_SK:
            if type(i[2]) is float:
                pass
            elif type(i[2]) is str:
                pass
            else:
                i[2] = 0.0
            self.list.InsertStringItem(index, str(i[0]))
            self.list.SetStringItem(index, 1, str(i[1]))

            if not self.private_unit_s:
                if type(i[2]) is str:
                    self.buffer.append([index, 2, i[2]])
                else:
                    self.buffer.append([index, 2, str('%.3f' % i[2])])
                self.buffer.append([index, 3, i[3]])
            else:
                if type(i[2]) is str:
                    self.buffer.append([index, 2, i[2]])
                else:
                    i[9] = i[2] / i[10] + i[11]
                    self.buffer.append([index, 2, str('%.3f' % i[9])])
                self.buffer.append([index, 3, i[8]])
            self.list.SetStringItem(index, 4, str('%.1f' % i[4]))
            self.list.SetStringItem(index, 5, str(i[5]))
            self.list.SetStringItem(index, 6, str(i[6]))
            index += 1

    def on_unit_setting(self, e):
        subprocess.Popen(['python', self.currentpath + '/unit-private.py'])

    def OnClose(self, e):
        self.endlive = True
        qx = 0
        while not self.ende and qx < 50:
            time.sleep(0.1)
            qx += 1

        if self.ws:
            self.ws.close()
        self.timer.Stop()
        self.Destroy()

    def on_message(self, ws, message):
        if self.endlive:
            self.on_close(ws)
            self.ende = True
            return
        try:
            js_up = json.loads(message)['updates'][0]
        except:
            return

        label = ''
        src = ''
        if '$source' in js_up:
            src = js_up['$source']
        elif 'source' in js_up:
            label = js_up['source']['label']
            src = label
            if 'type' in js_up['source']:
                if js_up['source']['type'] == 'NMEA0183':
                    if 'talker' in js_up['source']:
                        src += '.' + js_up['source']['talker']
                    if 'sentence' in js_up['source']:
                        src += '.' + js_up['source']['sentence']
                elif js_up['source']['type'] == 'NMEA2000':
                    if 'src' in js_up['source']:
                        src += '.' + js_up['source']['src']
                    if 'pgn' in js_up['source']:
                        src += '.' + str(js_up['source']['pgn'])

        try:
            timestamp = js_up['timestamp']
        except:
            timestamp = '2000-01-01T00:00:00.000Z'

        values_ = js_up['values']
        for values in values_:
            path = values['path']
            value = values['value']
            src2 = src
            timestamp2 = timestamp
            if type(value) is dict:
                if 'timestamp' in value: timestamp2 = value['timestamp']

                if '$source' in value:
                    src2 = value['$source']
                elif 'source' in value:
                    src2 = label
                    if 'type' in value['source']:
                        if value['source']['type'] == 'NMEA0183':
                            if 'talker' in value['source']:
                                src2 += '.' + value['source']['talker']
                            if 'sentence' in value['source']:
                                src2 += '.' + value['source']['sentence']
                        elif value['source']['type'] == 'NMEA2000':
                            if 'src' in value['source']:
                                src2 += '.' + value['source']['src']
                            if 'pgn' in value['source']:
                                src2 += '.' + str(value['source']['pgn'])

                for lvalue in value:
                    result = True
                    if lvalue in ['source', '$source']:
                        result = False
                    elif lvalue == 'timestamp':
                        if 'position' in path and 'RMC' in src2:
                            path2 = 'navigation.datetime'
                            value2 = timestamp2
                            self.update_add(value2, path2, src2, timestamp2)
                        result = False
                    if result:
                        path2 = path + '.' + lvalue
                        value2 = value[lvalue]
                        self.update_add(value2, path2, src2, timestamp2)
            else:
                self.update_add(value, path, src, timestamp)

    def update_add(self, value, path, src, timestamp):
        # SRC SignalK Value Unit Interval Status Description timestamp	private_Unit private_Value priv_Faktor priv_Offset
        #  0    1      2     3      4        5        6          7           8             9           10          11
        if type(value) is list: value = value[0]

        if type(value) is float: pass
        elif type(value) is unicode: value = str(value)
        elif type(value) is int: value = float(value)
        else: value = 0.0

        index = 0
        exists = False
        for i in self.list_SK:
            if path == i[1] and i[0] == src:
                exists = True
                i[0] = src
                i[2] = value
                if i[4] == 0.0:
                    i[4] = self.json_interval(i[7], timestamp)
                else:
                    i[4] = i[4] * .8 + 0.2 * self.json_interval(
                        i[7], timestamp)
                i[7] = timestamp
                self.buffer.append([index, 0, i[0]])
                self.buffer.append([index, 4, str('%.2f' % i[4])])
                if type(i[2]) is str:
                    self.buffer.append([index, 2, i[2]])
                    self.buffer.append([index, 3, i[3]])
                    break
                elif type(i[2]) is float:
                    pass
                else:
                    i[2] = 0.0
                if not self.private_unit_s:
                    self.buffer.append([index, 2, str('%.3f' % i[2])])
                    self.buffer.append([index, 3, i[3]])
                else:
                    i[9] = i[2] / i[10] + i[11]
                    self.buffer.append([index, 2, str('%.3f' % i[9])])
                    self.buffer.append([index, 3, i[8]])
                break
            index += 1
        if not exists:
            self.lookup_star(path)
            self.list_SK.append([
                src, path, value,
                str(self.SK_unit), 0.0, 1, self.SK_description, timestamp,
                str(self.SK_unit_priv), 0, self.SK_Faktor_priv,
                self.SK_Offset_priv
            ])
            self.buffer.append([-1, 0, ''])

    def on_private_unit(self, e):
        self.private_unit_s = self.private_unit.GetValue()

    def on_error(self, ws, error):
        print error

    def on_close(self, ws):
        ws.close()

    def on_open(self, ws):
        pass

    def run(self):
        self.endlive = False
        self.ende = False
        self.ws = websocket.WebSocketApp(
            "ws://localhost:3000/signalk/v1/stream?subscribe=self",
            on_message=lambda ws, msg: self.on_message(ws, msg),
            on_error=lambda ws, err: self.on_error(ws, err),
            on_close=lambda ws: self.on_close(ws))
        self.ws.on_open = lambda ws: self.on_open(ws)
        self.ws.run_forever()
        self.ws = None

    def start(self):
        def run():
            self.run()

        self.thread = threading.Thread(target=run)
        self.thread.start()
Example #48
0
class MyFrame(wx.Frame):
		
		def __init__(self, parent):

			paths=Paths()
			self.currentpath=paths.currentpath

			self.conf=Conf()

			Language(self.conf.get('GENERAL','lang'))

			wx.Frame.__init__(self, parent, title="Inspector", size=(650,435))
			
			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)

			self.logger = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_DONTWRAP, size=(650,150), pos=(0,0))

			self.list = wx.ListCtrl(self, -1, style=wx.LC_REPORT | wx.SUNKEN_BORDER, size=(540, 220), pos=(5, 155))
			self.list.InsertColumn(0, _('Type'), width=205)
			self.list.InsertColumn(1, _('Value'), width=130)
			self.list.InsertColumn(2, _('Source'), width=90)
			self.list.InsertColumn(3, _('NMEA'), width=50)
			self.list.InsertColumn(4, _('Age'), width=59)

			self.button_pause =wx.Button(self, label=_('Pause'), pos=(555, 160))
			self.Bind(wx.EVT_BUTTON, self.pause, self.button_pause)

			self.button_reset =wx.Button(self, label=_('Reset'), pos=(555, 200))
			self.Bind(wx.EVT_BUTTON, self.reset, self.button_reset)

			self.button_nmea =wx.Button(self, label=_('NMEA info'), pos=(555, 240))
			self.Bind(wx.EVT_BUTTON, self.nmea_info, self.button_nmea)

			self.a=DataStream()

			index=0
			for i in self.a.DataList:
				data=eval('self.a.'+i+'[0]')
				self.list.InsertStringItem(index,data)
				index=index+1

			self.pause_all=0

			self.CreateStatusBar()

			self.Centre()

			self.Show(True)

			self.thread1=threading.Thread(target=self.parse_data)
			self.thread2=threading.Thread(target=self.refresh_loop)
			
			self.s2=''
			self.error=''
			self.frase_nmea_log=''
			self.data=[]
			self.read_conf=1
			GPIO.setmode(GPIO.BCM)
			GPIO.setwarnings(False)

			if not self.thread1.isAlive(): self.thread1.start()
			if not self.thread2.isAlive(): self.thread2.start()

		def check_switches(self):
			self.channel1=''
			self.channel2=''
			self.channel3=''
			self.channel4=''
			self.channel5=''
			self.channel6=''
			self.channel7=''
			self.channel8=''
			self.channel9=''
			self.channel10=''
			if self.conf.get('SWITCH1', 'enable')=='1':
				self.channel1=int(self.conf.get('SWITCH1', 'gpio'))
				pull_up_down=GPIO.PUD_DOWN
				if self.conf.get('SWITCH1', 'pull_up_down')=='Pull Up': pull_up_down=GPIO.PUD_UP
				GPIO.setup(self.channel1, GPIO.IN, pull_up_down=pull_up_down)
			if self.conf.get('SWITCH2', 'enable')=='1':
				self.channel2=int(self.conf.get('SWITCH2', 'gpio'))
				pull_up_down=GPIO.PUD_DOWN
				if self.conf.get('SWITCH2', 'pull_up_down')=='Pull Up': pull_up_down=GPIO.PUD_UP
				GPIO.setup(self.channel2, GPIO.IN, pull_up_down=pull_up_down)
			if self.conf.get('SWITCH3', 'enable')=='1':
				self.channel3=int(self.conf.get('SWITCH3', 'gpio'))
				pull_up_down=GPIO.PUD_DOWN
				if self.conf.get('SWITCH3', 'pull_up_down')=='Pull Up': pull_up_down=GPIO.PUD_UP
				GPIO.setup(self.channel3, GPIO.IN, pull_up_down=pull_up_down)
			if self.conf.get('SWITCH4', 'enable')=='1':
				self.channel4=int(self.conf.get('SWITCH4', 'gpio'))
				pull_up_down=GPIO.PUD_DOWN
				if self.conf.get('SWITCH4', 'pull_up_down')=='Pull Up': pull_up_down=GPIO.PUD_UP
				GPIO.setup(self.channel4, GPIO.IN, pull_up_down=pull_up_down)
			if self.conf.get('SWITCH5', 'enable')=='1':
				self.channel5=int(self.conf.get('SWITCH5', 'gpio'))
				pull_up_down=GPIO.PUD_DOWN
				if self.conf.get('SWITCH5', 'pull_up_down')=='Pull Up': pull_up_down=GPIO.PUD_UP
				GPIO.setup(self.channel5, GPIO.IN, pull_up_down=pull_up_down)
			if self.conf.get('SWITCH6', 'enable')=='1':
				self.channel6=int(self.conf.get('SWITCH6', 'gpio'))
				pull_up_down=GPIO.PUD_DOWN
				if self.conf.get('SWITCH6', 'pull_up_down')=='Pull Up': pull_up_down=GPIO.PUD_UP
				GPIO.setup(self.channel6, GPIO.IN, pull_up_down=pull_up_down)
			if self.conf.get('OUTPUT1', 'enable')=='1':
				self.channel7=int(self.conf.get('OUTPUT1', 'gpio'))
				GPIO.setup(self.channel7, GPIO.OUT)
			if self.conf.get('OUTPUT2', 'enable')=='1':
				self.channel8=int(self.conf.get('OUTPUT2', 'gpio'))
				GPIO.setup(self.channel8, GPIO.OUT)
			if self.conf.get('OUTPUT3', 'enable')=='1':
				self.channel9=int(self.conf.get('OUTPUT3', 'gpio'))
				GPIO.setup(self.channel9, GPIO.OUT)
			if self.conf.get('OUTPUT4', 'enable')=='1':
				self.channel10=int(self.conf.get('OUTPUT4', 'gpio'))
				GPIO.setup(self.channel10, GPIO.OUT)

 		# thread 1
		def connect(self):
			try:
				self.s2 = socket.socket()
				self.s2.connect(("localhost", 10110))
				self.s2.settimeout(5)
			except socket.error, error_msg:
				self.error= _('Failed to connect with localhost:10110. Error: ')+ str(error_msg[0])+_(', trying to reconnect...')
				self.s2=''
				time.sleep(7)
			else: self.error=''
# 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 <http://www.gnu.org/licenses/>.
import matplotlib.pyplot as plt
from classes.conf import Conf
from classes.language import Language

conf = Conf()
Language(conf)

data = conf.get('PYPILOT', 'deviation')
listsave = []
try:
	listsave = eval(data)
except:
	listsave = []

x=[]
y=[]
for ii in listsave:
	x.append(ii[1] - ii[0])
	y.append(ii[0])
Example #50
0
	Erg=''
	send=False
	for i in MCP:
		if i[0]==1:
			send=True
			XValue=read_adc(i[1])
			if i[4]==1:
				XValue = interpolread(i[1],XValue)
			Erg +='{"path": "'+i[2]+'","value":'+str(XValue)+'},'

	if send:
		SignalK +=Erg[0:-1]+']}]}\n'
		sock.sendto(SignalK, ('127.0.0.1', 55557))	


conf = Conf()
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
read_sensors = True

#init SPI MCP
rate_ana=0.25
MCP=[]
adjust_point=[]
SignalK=''
data=conf.get('SPI', 'mcp')
try:
	temp_list=eval(data)
except:temp_list=[]
analog_=False
for ii in temp_list:
	if '.*.' in ii[2]: ii[2]=ii[2].replace('*', ii[3])
Example #51
0
	global sock_in
	global error
	try:
		sock_in = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		sock_in.settimeout(5)
		sock_in.connect(('localhost', 10110))
	except socket.error, error_msg:
		error= _('Failed to connect with localhost:10110. Error: ')+ str(error_msg[0])
		print error
		sock_in=''
		time.sleep(7)
	else: error=0
#end thread1

# no loop
conf=Conf()

Language(conf.get('GENERAL','lang'))

global triggers
triggers=[]
global sock_in
global error
sock_in=''
error=0
a=DataStream(conf)
actions=Actions(conf)
nodata=''

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)