Example #1
0
    def __global_fix(self, data):
        if data[6] in ['1', '2']:
            lat = self.__coord(data[2], data[3])
            lon = self.__coord(data[4], data[5])

            event = Event(Events.GPS_LOC, loc=(lat, lon))
            post_event(self._eventHandler, event)
Example #2
0
    def __global_fix(self, data):
        if data[6] in ['1', '2']:
            lat = self.__coord(data[2], data[3])
            lon = self.__coord(data[4], data[5])

            event = Event(Events.GPS_LOC, loc=(lat, lon))
            post_event(self._eventHandler, event)
Example #3
0
    def __on_enable(self, _event):
        enabled = self._checkEnable.IsChecked()
        self.set_enabled(enabled)
        timestamp = time.time()
        if self._isRecording and self._enabled:
            self.start_period(timestamp)
        elif self._isRecording and not self._enabled:
            self.end_period(timestamp)

        event = Event(Events.CHANGED)
        post_event(self._eventHandler, event)
Example #4
0
    def __on_enable(self, _event):
        enabled = self._checkEnable.IsChecked()
        self.set_enabled(enabled)
        timestamp = time.time()
        if self._isRecording and self._enabled:
            self.start_period(timestamp)
        elif self._isRecording and not self._enabled:
            self.end_period(timestamp)

        event = Event(Events.CHANGED)
        post_event(self._eventHandler, event)
Example #5
0
    def __capture(self, data, _sdr):
        timestamp = time.time()
        dst = ctypes.byref(self._capture, 0)
        ctypes.memmove(dst, data, len(data))

        iq = self.__stream_to_complex(self._capture)
        l, f = psd(iq, BINS, SAMPLE_RATE, scale_by_freq=False)
        f /= 1e6
        f += self._freq

        event = Event(Events.SCAN_DATA, timestamp=timestamp, l=l, f=f)
        post_event(self._eventHandler, event)
Example #6
0
    def __on_colour(self, _event):
        colourData = wx.ColourData()
        colourData.SetChooseFull(True)
        colourData.SetColour([level * 255 for level in self._colour])
        for i in range(len(self._colours)):
            colour = [level * 255 for level in self._colours[i]]
            colourData.SetCustomColour(i, colour)

        dlg = CubeColourDialog(self, colourData)
        if dlg.ShowModal() == wx.ID_OK:
            colour = dlg.GetColourData().GetColour()
            colour = [level / 255. for level in colour]
            self.set_colour(colour)
            event = Event(Events.CHANGED)
            post_event(self._eventHandler, event)
Example #7
0
    def __on_colour(self, _event):
        colourData = wx.ColourData()
        colourData.SetChooseFull(True)
        colourData.SetColour([level * 255 for level in self._colour])
        for i in range(len(self._colours)):
            colour = [level * 255 for level in self._colours[i]]
            colourData.SetCustomColour(i, colour)

        dlg = CubeColourDialog(self, colourData)
        if dlg.ShowModal() == wx.ID_OK:
            colour = dlg.GetColourData().GetColour()
            colour = [level / 255. for level in colour]
            self.set_colour(colour)
            event = Event(Events.CHANGED)
            post_event(self._eventHandler, event)
Example #8
0
    def __send(self, uri, data):
        req = urllib2.Request(uri)
        req.add_header('Content-Type', 'application/json')

        event = None
        try:
            urllib2.urlopen(req, data)
        except ValueError as error:
            event = Event(Events.PUSH_ERROR, msg=error.message)
        except URLError as error:
            event = Event(Events.PUSH_ERROR, msg=error.reason.strerror)

        if event is not None:
            self._failed.append(data)
            post_event(self._handler, event)
Example #9
0
    def __capture(self, data, _sdr):
        timestamp = time.time()
        dst = ctypes.byref(self._capture, 0)
        ctypes.memmove(dst, data, len(data))

        iq = self.__stream_to_complex(self._capture)
        l, f = psd(iq,
                   BINS,
                   SAMPLE_RATE,
                   scale_by_freq=False,
                   noverlap=-SAMPLES / 64)
        f /= 1e6
        f += self._freq

        event = Event(Events.SCAN_DATA, timestamp=timestamp, l=l, f=f)
        post_event(self._eventHandler, event)
Example #10
0
 def __read(self):
     for resp in self.__serial_read():
         nmea = resp.split('*')
         if len(nmea) == 2:
             data = nmea[0].split(',')
             if data[0] in ['GPGGA', 'GPGSV']:
                 checksum = self.__checksum(nmea[0])
                 if checksum == nmea[1]:
                     if data[0] == 'GPGGA':
                         self.__global_fix(data)
                     elif data[0] == 'GPGSV':
                         self.__sats(data)
                 else:
                     warn = 'Invalid checksum for {} sentence'.format(data[0])
                     event = Event(Events.GPS_WARN, msg=warn)
                     post_event(self._eventHandler, event)
Example #11
0
 def __read(self):
     for resp in self.__serial_read():
         nmea = resp.split('*')
         if len(nmea) == 2:
             data = nmea[0].split(',')
             if data[0] in ['GPGGA', 'GPGSV']:
                 checksum = self.__checksum(nmea[0])
                 if checksum == nmea[1]:
                     if data[0] == 'GPGGA':
                         self.__global_fix(data)
                     elif data[0] == 'GPGSV':
                         self.__sats(data)
                 else:
                     warn = 'Invalid checksum for {} sentence'.format(
                         data[0])
                     event = Event(Events.GPS_WARN, msg=warn)
                     post_event(self._eventHandler, event)
Example #12
0
    def __init__(self, eventHandler, freq, gain):
        threading.Thread.__init__(self)
        self.name = "Receive"
        self.daemon = True

        self._cancel = False
        self._freq = freq
        self._gain = gain
        self._eventHandler = eventHandler
        self._sdr = None
        self._capture = (ctypes.c_ubyte * SAMPLES)()

        devices = rtlsdr.librtlsdr.rtlsdr_get_device_count()
        if devices == 0:
            event = Event(Events.SCAN_ERROR, msg="No device found")
            post_event(eventHandler, event)
        else:
            self.start()
Example #13
0
    def __init__(self, eventHandler):
        threading.Thread.__init__(self)
        self.name = 'Server'
        self._eventHandler = eventHandler

        self._client = None
        self._server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self._server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

        try:
            self._server.bind(('', PORT))
            self._server.listen(5)
        except socket.error:
            event = Event(Events.SCAN_ERROR, msg='Could not start server')
            post_event(eventHandler, event)
            return

        self._cancel = False
        self.start()
Example #14
0
    def __init__(self, eventHandler, freq, gain, cal):
        threading.Thread.__init__(self)
        self.name = 'Receive'
        self.daemon = True

        self._cancel = False
        self._freq = freq
        self._gain = gain
        self._cal = cal
        self._eventHandler = eventHandler
        self._sdr = None
        self._capture = (ctypes.c_ubyte * SAMPLES)()

        devices = rtlsdr.librtlsdr.rtlsdr_get_device_count()
        if devices == 0:
            event = Event(Events.SCAN_ERROR, msg='No device found')
            post_event(eventHandler, event)
        else:
            self.start()
Example #15
0
    def __init__(self, eventHandler):
        threading.Thread.__init__(self)
        self.name = 'Server'
        self.daemon = True
        self._eventHandler = eventHandler

        self._client = None
        self._server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self._server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

        try:
            self._server.bind(('', PORT))
            self._server.listen(5)
        except socket.error:
            event = Event(Events.SCAN_ERROR, msg='Could not start server')
            post_event(eventHandler, event)
            return

        self._cancel = False
        self.start()
Example #16
0
    def set_level(self, level, timestamp, location):
        threshold = self.get_dynamic_threshold()
        self._meterLevel.set_threshold(threshold, False)
        self._meterLevel.set_noise(self._noise)
        self._meterLevel.set_level(level)

        signal = None
        if self._isRecording:
            signal = Monitor.set_level(self, level, timestamp, location)
            if signal is not None:
                self.__set_records()

        if level >= threshold and self._isLow:
            self._isLow = False
            if self._alert:
                event = Event(Events.MON_ALERT)
                post_event(self._eventHandler, event)
        elif level < threshold:
            self._isLow = True

        return signal
Example #17
0
    def set_level(self, level, timestamp, location):
        threshold = self.get_dynamic_threshold()
        self._meterLevel.set_threshold(threshold, False)
        self._meterLevel.set_noise(self._noise)
        self._meterLevel.set_level(level)

        signal = None
        if self._isRecording:
            signal = Monitor.set_level(self, level, timestamp, location)
            if signal is not None:
                self.__set_records()

        if level >= threshold and self._isLow:
            self._isLow = False
            if self._alert:
                event = Event(Events.MON_ALERT)
                post_event(self._eventHandler, event)
        elif level < threshold:
            self._isLow = True

        return signal
Example #18
0
    def __sats(self, data):
        message = int(data[1])
        messages = int(data[1])
        viewed = int(data[3])

        if message == 1:
            self._sats.clear()

        blocks = (len(data) - 4) / 4
        for i in range(0, blocks):
            sat = int(data[4 + i * 4])
            level = data[7 + i * 4]
            used = True
            if level == '':
                level = None
                used = False
            else:
                level = int(level)
            self._sats[sat] = {'Level': level, 'Used': used}

        if message == messages and len(self._sats) == viewed:
            event = Event(Events.GPS_SATS, sats=self._sats)
            post_event(self._eventHandler, event)
Example #19
0
    def __sats(self, data):
        message = int(data[1])
        messages = int(data[1])
        viewed = int(data[3])

        if message == 1:
            self._sats.clear()

        blocks = (len(data) - 4) / 4
        for i in range(0, blocks):
            sat = int(data[4 + i * 4])
            level = data[7 + i * 4]
            used = True
            if level == '':
                level = None
                used = False
            else:
                level = int(level)
            self._sats[sat] = {'Level': level,
                               'Used': used}

        if message == messages and len(self._sats) == viewed:
            event = Event(Events.GPS_SATS, sats=self._sats)
            post_event(self._eventHandler, event)
Example #20
0
    def run(self):
        try:
            self.__open()
            self.__read()
        except SerialException as error:
            event = Event(Events.GPS_ERROR, msg=error.message)
            post_event(self._eventHandler, event)
        except OSError as error:
            event = Event(Events.GPS_ERROR, msg=error)
            post_event(self._eventHandler, event)
        except ValueError as error:
            event = Event(Events.GPS_ERROR, msg=error)
            post_event(self._eventHandler, event)

        self.__close()
Example #21
0
    def run(self):
        try:
            self.__open()
            self.__read()
        except SerialException as error:
            event = Event(Events.GPS_ERROR, msg=error.message)
            post_event(self._eventHandler, event)
        except OSError as error:
            event = Event(Events.GPS_ERROR, msg=error)
            post_event(self._eventHandler, event)
        except ValueError as error:
            event = Event(Events.GPS_ERROR, msg=error)
            post_event(self._eventHandler, event)

        self.__close()
Example #22
0
    def __on_threshold(self, _event):
        self._threshold = self._sliderThreshold.GetValue()
        self._meterLevel.set_threshold(self.get_dynamic_threshold())

        event = Event(Events.CHANGED)
        post_event(self._eventHandler, event)
Example #23
0
 def __on_change(self, _event=None):
     event = Event(Events.CHANGED)
     post_event(self._parent, event)
Example #24
0
 def __timeout(self):
     self.stop()
     event = Event(Events.GPS_TIMEOUT, msg='GPS timeout')
     post_event(self._eventHandler, event)
Example #25
0
    def __on_alert(self, _event):
        self._alert = self._checkAlert.IsChecked()

        event = Event(Events.CHANGED)
        post_event(self._eventHandler, event)
Example #26
0
    def __on_dynamic(self, _event=None):
        self.set_dynamic(self._checkDynamic.IsChecked())

        event = Event(Events.CHANGED)
        post_event(self._eventHandler, event)
Example #27
0
    def __on_freq(self, event):
        self._freq = float(event.GetString())

        event = Event(Events.CHANGED)
        post_event(self._eventHandler, event)
Example #28
0
    def __on_threshold(self, _event):
        self._threshold = self._sliderThreshold.GetValue()
        self._meterLevel.set_threshold(self.get_dynamic_threshold())

        event = Event(Events.CHANGED)
        post_event(self._eventHandler, event)
Example #29
0
    def __on_alert(self, _event):
        self._alert = self._checkAlert.IsChecked()

        event = Event(Events.CHANGED)
        post_event(self._eventHandler, event)
Example #30
0
    def __on_dynamic(self, _event=None):
        self.set_dynamic(self._checkDynamic.IsChecked())

        event = Event(Events.CHANGED)
        post_event(self._eventHandler, event)
Example #31
0
    def __on_freq(self, event):
        self._freq = float(event.GetString())

        event = Event(Events.CHANGED)
        post_event(self._eventHandler, event)
Example #32
0
 def __timeout(self):
     self.stop()
     event = Event(Events.GPS_TIMEOUT, msg='GPS timeout')
     post_event(self._eventHandler, event)
Example #33
0
 def __on_change(self, _event=None):
     event = Event(Events.CHANGED)
     post_event(self._parent, event)