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()
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)
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)
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)
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)
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)
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)
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()
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()
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
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)
def __timeout(self): self.stop() event = Event(Events.GPS_TIMEOUT, msg='GPS timeout') post_event(self._eventHandler, event)
def __on_alert(self, _event): self._alert = self._checkAlert.IsChecked() event = Event(Events.CHANGED) post_event(self._eventHandler, event)
def __on_dynamic(self, _event=None): self.set_dynamic(self._checkDynamic.IsChecked()) event = Event(Events.CHANGED) post_event(self._eventHandler, event)
def __on_freq(self, event): self._freq = float(event.GetString()) event = Event(Events.CHANGED) post_event(self._eventHandler, event)
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)
def __on_change(self, _event=None): event = Event(Events.CHANGED) post_event(self._parent, event)