def __nmea_read(self): if self.device.type == DeviceGPS.NMEA_SERIAL: comm = self.__serial_read() else: comm = self.__tcp_read() for resp in comm: resp = resp.replace('\n', '') resp = resp.replace('\r', '') resp = resp[1::] resp = resp.split('*') if len(resp) == 2: checksum = self.__nmea_checksum(resp[0]) if checksum == resp[1]: data = resp[0].split(',') if data[0] == 'GPGGA': if data[6] in ['1', '2']: lat = self.__nmea_coord(data[2], data[3]) lon = self.__nmea_coord(data[4], data[5]) try: alt = float(data[9]) except ValueError: alt = None post_event(self.notify, EventThread(Event.LOC, 0, (lat, lon, alt))) else: error = 'Invalid checksum {0}, should be {1}'.format(resp[1], checksum) post_event(self.notify, EventThread(Event.LOC_WARN, 0, error))
def __tcp_read(self, isGpsd=False): buf = '' data = True while data and not self._cancel: reads, writes, errors = select.select([self._comm], [self._comm], [self._comm], 0.1) for read in reads: data = read.recv(64) buf += data while buf.find('\n') != -1: line, buf = buf.split('\n', 1) if not isGpsd: pos = line.find('$') if pos != -1 and pos + 1 < len(line): yield line[pos + 1:].rstrip('\r\n') else: yield line if self._raw: line = limit_to_ascii(line) post_event(self._notify, EventThread(Event.LOC_RAW, 0, line)) for write in writes: if self._send is not None: write.sendall(self._send) self._send = None for _error in errors: post_event(self._notify, EventThread(Event.LOC_ERR, 0, 'Connection dropped')) return
def run(self): conn = True if self._device.type in [DeviceGPS.NMEA_SERIAL, DeviceGPS.NMEA_TCP]: if not self.__nmea_open(): self.__nmea_close() conn = False else: if not self.__gpsd_open(): conn = False if conn: if self._device.type in [DeviceGPS.NMEA_SERIAL, DeviceGPS.NMEA_TCP]: self.__nmea_read() elif self._device.type == DeviceGPS.GPSD: self.__gpsd_read() elif self._device.type == DeviceGPS.GPSD_OLD: self.__gpsd_old_read() if self._device.type in [DeviceGPS.NMEA_SERIAL, DeviceGPS.NMEA_TCP]: self.__nmea_close() else: self.__gpsd_close() if self._raw: post_event(self._notify, EventThread(Event.LOC_RAW, 0, 'Stopped'))
def __gpsd_sats(self, satData): sats = {} for sat in satData: sats[sat['PRN']] = [sat['ss'], sat['used']] post_event(self.notify, EventThread(Event.LOC_SAT, None, sats))
def __gpsd_open(self): try: self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.socket.settimeout(5) self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) url = urlparse('//' + self.device.resource) if url.hostname is not None: host = url.hostname else: host = 'localhost' if url.port is not None: port = url.port else: port = 2947 self.socket.connect((host, port)) if self.device.type == DeviceGPS.GPSD: self.socket.sendall('?WATCH={"enable": true,"json": true}') else: self.socket.sendall('w') except IOError as error: post_event(self.notify, EventThread(Event.LOC_WARN, 0, error)) self.socket.close() return False return True
def __nmea_parse(self): while not self.cancel: resp = self.serial.readline() if self.raw: post_event(self.notify, EventThread(Event.LOC_RAW, 0, resp)) resp = resp.replace('\n', '') resp = resp.replace('\r', '') resp = resp[1::] resp = resp.split('*') if len(resp) == 2: checksum = self.__nmea_checksum(resp[0]) if checksum == resp[1]: data = resp[0].split(',') if data[0] == 'GPGGA': if data[6] in ['1', '2']: lat = self.__nmea_coord(data[2], data[3]) lon = self.__nmea_coord(data[4], data[5]) try: alt = float(data[9]) except ValueError: alt = None post_event(self.notify, EventThread(Event.LOC, 0, (lat, lon, alt)))
def update_spectrum(notify, lock, start, stop, freqCentre, data, offset, spectrum, average, alertLevel=None): with lock: updated = False if average: timeStamp = 0 else: timeStamp = data[0] scan = data[1] upperStart = freqCentre + offset upperEnd = freqCentre + offset + BANDWIDTH / 2 lowerStart = freqCentre - offset - BANDWIDTH / 2 lowerEnd = freqCentre - offset if not timeStamp in spectrum: spectrum[timeStamp] = {} for freq in scan: if start <= freq < stop: power = 10 * math.log10(scan[freq]) if upperStart <= freq * 1e6 <= upperEnd or \ lowerStart <= freq * 1e6 <= lowerEnd: if freq in spectrum[timeStamp]: spectrum[timeStamp][freq] = \ (spectrum[timeStamp][freq] + power) / 2 if alertLevel is not None and \ spectrum[timeStamp][freq] > alertLevel: post_event(notify, EventThreadStatus(Event.LEVEL)) updated = True else: spectrum[timeStamp][freq] = power updated = True post_event(notify, EventThreadStatus(Event.UPDATED, None, updated))
def __rtl_setup(self): if self.sdr is not None: return tuner = 0 if self.isDevice: try: self.sdr = rtlsdr.RtlSdr(self.indexRtl) self.sdr.set_sample_rate(SAMPLE_RATE) self.sdr.set_manual_gain_enabled(1) self.sdr.set_gain(self.gain) tuner = self.sdr.get_tuner_type() except IOError as error: post_event(self.notify, EventThread(Event.ERROR, 0, error.message)) else: try: self.sdr = rtltcp.RtlTcp(self.server, self.port, self.notify) self.sdr.set_sample_rate(SAMPLE_RATE) self.sdr.set_manual_gain_enabled(1) self.sdr.set_gain(self.gain) tuner = self.sdr.get_tuner_type() except IOError as error: post_event(self.notify, EventThread(Event.ERROR, 0, error)) return tuner
def run(self): conn = True if self._device.type in [DeviceGPS.NMEA_SERIAL, DeviceGPS.NMEA_TCP]: if not self.__nmea_open(): self.__nmea_close() conn = False else: if not self.__gpsd_open(): conn = False if conn: if self._device.type in [ DeviceGPS.NMEA_SERIAL, DeviceGPS.NMEA_TCP ]: self.__nmea_read() elif self._device.type == DeviceGPS.GPSD: self.__gpsd_read() elif self._device.type == DeviceGPS.GPSD_OLD: self.__gpsd_old_read() if self._device.type in [ DeviceGPS.NMEA_SERIAL, DeviceGPS.NMEA_TCP ]: self.__nmea_close() else: self.__gpsd_close() if self._raw: post_event(self._notify, EventThread(Event.LOC_RAW, 0, 'Stopped'))
def __serial_read(self): data = True while data and not self.cancel: data = self.comm.readline() yield data if self.raw: post_event(self.notify, EventThread(Event.LOC_RAW, 0, data)) return
def rtl_scan(self, freq): self.sdr.set_center_freq(freq + self.lo) try: capture = self.sdr.read_samples(self.samples) except MemoryError as error: post_event(self.notify, EventThread(Event.ERROR, 0, error)) capture = [] return capture
def __serial_read(self): data = True while data and not self.cancel: data = self.comm.readline() yield data if self.raw: data = limit_to_ascii(data) post_event(self.notify, EventThread(Event.LOC_RAW, 0, data)) return
def run(self): try: while not self.cancel: if self.readLen > 0: self.__read_stream() else: self.__skip_stream() except socket.error as error: post_event(self.notify, EventThread(Event.ERROR, 0, error)) finally: self.socket.close() self.__do_notify()
def update_spectrum(notify, lock, start, stop, data, offset, spectrum, average, alertLevel=None): with lock: updated = False if average: if len(spectrum) > 0: timeStamp = min(spectrum) else: timeStamp = data[0] else: timeStamp = data[0] freqCentre = data[1] scan = data[2] upperStart = freqCentre + offset upperEnd = freqCentre + offset + BANDWIDTH / 2 lowerStart = freqCentre - offset - BANDWIDTH / 2 lowerEnd = freqCentre - offset if timeStamp not in spectrum: spectrum[timeStamp] = OrderedDict() for freq in scan: if start <= freq < stop: power = 10 * math.log10(scan[freq]) if upperStart <= freq * 1e6 <= upperEnd or \ lowerStart <= freq * 1e6 <= lowerEnd: if freq in spectrum[timeStamp]: spectrum[timeStamp][freq] = \ (spectrum[timeStamp][freq] + power) / 2 if alertLevel is not None and ( spectrum[timeStamp][freq] > alertLevel): post_event(notify, EventThread(Event.LEVEL)) updated = True else: spectrum[timeStamp][freq] = power updated = True if updated: spectrum[timeStamp] = OrderedDict( sorted(spectrum[timeStamp].items())) post_event(notify, EventThread(Event.UPDATED, None, updated))
def __serial_connect(self): self._timeout = Timeout(self.__serial_timeout) if self._raw: text = 'Opening "{}"'.format(self._device.resource) post_event(self._notify, EventThread(Event.LOC_RAW, 0, text)) try: self._comm = serial.Serial(self._device.resource, baudrate=self._device.baud, bytesize=self._device.bytes, parity=self._device.parity, stopbits=self._device.stops, xonxoff=self._device.soft, timeout=0) except SerialException as error: post_event(self._notify, EventThread(Event.LOC_ERR, 0, error.message)) return False except OSError as error: post_event(self._notify, EventThread(Event.LOC_ERR, 0, error)) return False except ValueError as error: post_event(self._notify, EventThread(Event.LOC_ERR, 0, error)) return False return True
def __nmea_open(self): try: self.serial = serial.Serial(self.device.resource, baudrate=self.device.baud, bytesize=self.device.bytes, parity=self.device.parity, stopbits=self.device.stops, xonxoff=self.device.soft, timeout=1) except SerialException as error: post_event(self.notify, EventThread(Event.LOC_WARN, 0, error.message)) return False return True
def __gpsd_open(self): self.__tcp_connect(2947) try: if self._device.type == DeviceGPS.GPSD: self._send = '?WATCH={"enable": true,"json": true}' else: self._send = 'w' except IOError as error: post_event(self._notify, EventThread(Event.LOC_ERR, 0, error)) self._comm.close() return False return True
def __gpsd_old_read(self): for resp in self.__tcp_read(): data = resp.split(' ') if len(data) == 15 and data[0] == 'GPSD,O=GGA': try: lat = float(data[4]) lon = float(data[3]) except ValueError: return try: alt = float(data[5]) except ValueError: alt = None post_event(self.notify, EventThread(Event.LOC, 0, (lat, lon, alt)))
def __gpsd_open(self): self.__tcp_connect(2947) try: if self.device.type == DeviceGPS.GPSD: self.comm.sendall('?WATCH={"enable": true,"json": true}') else: self.comm.sendall('w') except IOError as error: post_event(self.notify, EventThread(Event.LOC_WARN, 0, error)) self.comm.close() return False return True
def run(self): spectrum = {} timeStamp = self.scan[0] samples = self.scan[1] pos = WINFUNC[::2].index(self.winFunc) function = WINFUNC[1::2][pos] powers, freqs = matplotlib.mlab.psd(samples, NFFT=self.nfft, Fs=SAMPLE_RATE / 1e6, window=function(self.nfft)) for freqPsd, pwr in itertools.izip(freqs, powers): xr = freqPsd + (self.freq / 1e6) xr = xr + (xr * self.cal / 1e6) spectrum[xr] = pwr post_event(self.notify, EventThread(Event.PROCESSED, (timeStamp, self.freq, spectrum)))
def __serial_connect(self): if self.raw: text = 'Opening "{0}"'.format(self.device.resource) post_event(self.notify, EventThread(Event.LOC_RAW, 0, text)) try: self.comm = serial.Serial(self.device.resource, baudrate=self.device.baud, bytesize=self.device.bytes, parity=self.device.parity, stopbits=self.device.stops, xonxoff=self.device.soft, timeout=1) except SerialException as error: post_event(self.notify, EventThread(Event.LOC_WARN, 0, error.message)) return False return True
def __gpsd_read(self): for resp in self.__tcp_read(): data = json.loads(resp) if data['class'] == 'TPV': if data['mode'] in [2, 3]: try: lat = data['lat'] lon = data['lon'] except KeyError: return try: alt = data['alt'] except KeyError: alt = None post_event(self.notify, EventThread(Event.LOC, 0, (lat, lon, alt)))
def __tcp_read(self): buf = '' data = True while data and not self.cancel: try: data = self.comm.recv(1024) except socket.timeout as error: post_event(self.notify, EventThread(Event.LOC_WARN, 0, error)) return buf += data while buf.find('\n') != -1: line, buf = buf.split('\n', 1) yield line if self.raw: post_event(self.notify, EventThread(Event.LOC_RAW, 0, line)) return
def __tcp_read(self): buf = '' data = True while data and not self.cancel: try: data = self.comm.recv(1024) except socket.timeout as error: post_event(self.notify, EventThread(Event.LOC_ERR, 0, error)) return buf += data while buf.find('\n') != -1: line, buf = buf.split('\n', 1) yield line if self.raw: line = limit_to_ascii(line) post_event(self.notify, EventThread(Event.LOC_RAW, 0, line)) return
def run(self): spectrum = {} timeStamp = self.scan[0] samples = self.scan[1] pos = WINFUNC[::2].index(self.winFunc) function = WINFUNC[1::2][pos] powers, freqs = matplotlib.mlab.psd(samples, NFFT=self.nfft, Fs=SAMPLE_RATE / 1e6, window=function(self.nfft)) for freqPsd, pwr in itertools.izip(freqs, powers): xr = freqPsd + (self.freq / 1e6) xr = xr + (xr * self.cal / 1e6) spectrum[xr] = pwr post_event( self.notify, EventThread(Event.PROCESSED, (timeStamp, self.freq, spectrum)))
def update_spectrum(notify, lock, start, stop, data, offset, spectrum, average, alertLevel=None): with lock: updated = False if average: if len(spectrum) > 0: timeStamp = min(spectrum) else: timeStamp = data[0] else: timeStamp = data[0] freqCentre = data[1] scan = data[2] upperStart = freqCentre + offset upperEnd = freqCentre + offset + BANDWIDTH / 2 lowerStart = freqCentre - offset - BANDWIDTH / 2 lowerEnd = freqCentre - offset if timeStamp not in spectrum: spectrum[timeStamp] = OrderedDict() for freq in scan: if start <= freq < stop: power = 10 * math.log10(scan[freq]) if upperStart <= freq * 1e6 <= upperEnd or \ lowerStart <= freq * 1e6 <= lowerEnd: if freq in spectrum[timeStamp]: spectrum[timeStamp][freq] = \ (spectrum[timeStamp][freq] + power) / 2 if alertLevel is not None and (spectrum[timeStamp][freq] > alertLevel): post_event(notify, EventThread(Event.LEVEL)) updated = True else: spectrum[timeStamp][freq] = power updated = True if updated: spectrum[timeStamp] = OrderedDict(sorted(spectrum[timeStamp].items())) post_event(notify, EventThread(Event.UPDATED, None, updated))
def __tcp_connect(self, defaultPort): self._comm = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._comm.settimeout(5) self._comm.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) url = urlparse('//' + self._device.resource) if url.hostname is not None: host = url.hostname else: host = 'localhost' if url.port is not None: port = url.port else: port = defaultPort if self._raw: text = 'Opening "{}"'.format(self._device.resource) post_event(self._notify, EventThread(Event.LOC_RAW, 0, text)) try: self._comm.connect((host, port)) except socket.error as error: post_event(self._notify, EventThread(Event.LOC_ERR, 0, error))
def __init__(self, notify, settings, device, samples, isCal): threading.Thread.__init__(self) self.name = 'ThreadScan' self.notify = notify self.fstart = settings.start * 1e6 self.fstop = settings.stop * 1e6 self.samples = samples self.isCal = isCal self.index = settings.index self.isDevice = settings.devices[device].isDevice self.server = settings.devices[device].server self.port = settings.devices[device].port self.gain = settings.devices[device].gain self.lo = settings.devices[device].lo * 1e6 self.offset = settings.devices[device].offset self.cancel = False post_event(self.notify, EventThreadStatus(Event.STARTING)) steps = ((self.f_stop() - self.f_start()) / self.f_step()) + 1 post_event(self.notify, EventThreadStatus(Event.STEPS, steps)) self.start()
def __tcp_read(self): buf = '' data = True while data and not self._cancel: try: data = self._comm.recv(1024) except socket.timeout as error: post_event(self._notify, EventThread(Event.LOC_ERR, 0, error)) return buf += data while buf.find('\n') != -1: line, buf = buf.split('\n', 1) pos = line.find('$') if pos != -1 and pos + 1 < len(line): yield line[pos + 1:] if self._raw: line = limit_to_ascii(line) post_event(self._notify, EventThread(Event.LOC_RAW, 0, line)) return
def __tcp_connect(self, defaultPort): self.comm = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.comm.settimeout(5) self.comm.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) url = urlparse('//' + self.device.resource) if url.hostname is not None: host = url.hostname else: host = 'localhost' if url.port is not None: port = url.port else: port = defaultPort if self.raw: text = 'Opening "{0}"'.format(self.device.resource) post_event(self.notify, EventThread(Event.LOC_RAW, 0, text)) try: self.comm.connect((host, port)) except socket.error as error: post_event(self.notify, EventThread(Event.LOC_WARN, 0, error))
def rtl_setup(self): sdr = None if self.isDevice: try: sdr = rtlsdr.RtlSdr(self.index) sdr.set_sample_rate(SAMPLE_RATE) sdr.set_gain(self.gain) except IOError as error: post_event(self.notify, EventThreadStatus(Event.ERROR, 0, error.message)) else: try: sdr = rtltcp.RtlTcp(self.server, self.port) sdr.set_sample_rate(SAMPLE_RATE) sdr.set_gain(self.gain) except IOError as error: post_event(self.notify, EventThreadStatus(Event.ERROR, 0, error)) return sdr
def __serial_connect(self): if self.raw: text = 'Opening "{}"'.format(self.device.resource) post_event(self.notify, EventThread(Event.LOC_RAW, 0, text)) try: self.comm = serial.Serial(self.device.resource, baudrate=self.device.baud, bytesize=self.device.bytes, parity=self.device.parity, stopbits=self.device.stops, xonxoff=self.device.soft, timeout=1) buff = io.BufferedReader(self.comm, 1) self.commIo = io.TextIOWrapper(buff, newline='\r', line_buffering=True) except SerialException as error: post_event(self.notify, EventThread(Event.LOC_ERR, 0, error.message)) return False except OSError as error: post_event(self.notify, EventThread(Event.LOC_ERR, 0, error)) return False return True
def __nmea_read(self): if self._device.type == DeviceGPS.NMEA_SERIAL: comm = self.__serial_read() else: comm = self.__tcp_read() for resp in comm: nmea = resp.split('*') if len(nmea) == 2: data = nmea[0].split(',') if data[0] in ['GPGGA', 'GPGSV']: checksum = self.__nmea_checksum(nmea[0]) if checksum == nmea[1]: if data[0] == 'GPGGA': self.__nmea_global_fix(data) elif data[0] == 'GPGSV': self.__nmea_sats(data) else: error = 'Invalid checksum {}, should be {}'.format(resp[1], checksum) post_event(self._notify, EventThread(Event.LOC_WARN, 0, error))
def __nmea_read(self): if self._device.type == DeviceGPS.NMEA_SERIAL: comm = self.__serial_read() else: comm = self.__tcp_read() for resp in comm: nmea = resp.split('*') if len(nmea) == 2: data = nmea[0].split(',') if data[0] in ['GPGGA', 'GPGSV']: checksum = self.__nmea_checksum(nmea[0]) if checksum == nmea[1]: if data[0] == 'GPGGA': self.__nmea_global_fix(data) elif data[0] == 'GPGSV': self.__nmea_sats(data) else: error = 'Invalid checksum {}, should be {}'.format( resp[1], checksum) post_event(self._notify, EventThread(Event.LOC_WARN, 0, error))
def __init__(self, notify, sdr, settings, device, samples, isCal): threading.Thread.__init__(self) self.name = 'Scan' self.notify = notify self.sdr = sdr self.fstart = settings.start * 1e6 self.fstop = settings.stop * 1e6 self.samples = int(samples) self.isCal = isCal self.indexRtl = settings.indexRtl self.isDevice = settings.devicesRtl[device].isDevice self.server = settings.devicesRtl[device].server self.port = settings.devicesRtl[device].port self.gain = settings.devicesRtl[device].gain self.lo = settings.devicesRtl[device].lo * 1e6 self.offset = settings.devicesRtl[device].offset self.cancel = False post_event(self.notify, EventThread(Event.STARTING)) steps = int((self.__f_stop() - self.__f_start()) / self.__f_step()) post_event(self.notify, EventThread(Event.STEPS, steps)) self.start()
def __init__(self, notify, queue, sdr, settings, device, samples, isCal): threading.Thread.__init__(self) self.name = 'Scan' self.notify = notify self.queue = queue self.sdr = sdr self.fstart = settings.start * 1e6 self.fstop = settings.stop * 1e6 self.samples = int(samples) self.isCal = isCal self.indexRtl = settings.indexRtl self.isDevice = settings.devicesRtl[device].isDevice self.server = settings.devicesRtl[device].server self.port = settings.devicesRtl[device].port self.gain = settings.devicesRtl[device].gain self.lo = settings.devicesRtl[device].lo * 1e6 self.offset = settings.devicesRtl[device].offset self.cancel = False post_event(self.notify, EventThread(Event.STARTING)) steps = int((self.__f_stop() - self.__f_start()) / self.__f_step()) post_event(self.notify, EventThread(Event.STEPS, steps)) self.start()
def __serial_read(self): isSentence = False sentence = '' while not self._cancel: data = self._comm.read(1) if data: self._timeout.reset() if data == '$': isSentence = True continue if data == '\r' or data == '\n': isSentence = False if sentence: yield sentence if self._raw: line = limit_to_ascii(sentence) post_event(self._notify, EventThread(Event.LOC_RAW, 0, line)) sentence = '' if isSentence: sentence += data else: time.sleep(0.1)
def __nmea_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, used] if message == messages and len(self._sats) == viewed: post_event(self._notify, EventThread(Event.LOC_SAT, None, self._sats))
def __nmea_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, used] if message == messages and len(self.sats) == viewed: post_event(self.notify, EventThread(Event.LOC_SAT, None, self.sats))
def __nmea_read(self): if self.device.type == DeviceGPS.NMEA_SERIAL: comm = self.__serial_read() else: comm = self.__tcp_read() for resp in comm: resp = resp.replace('\n', '') resp = resp.replace('\r', '') resp = resp[1::] resp = resp.split('*') if len(resp) == 2: checksum = self.__nmea_checksum(resp[0]) if checksum == resp[1]: data = resp[0].split(',') if data[0] == 'GPGGA': self.__nmea_global_fix(data) elif data[0] == 'GPGSV': self.__nmea_sats(data) else: error = 'Invalid checksum {}, should be {}'.format(resp[1], checksum) post_event(self.notify, EventThread(Event.LOC_WARN, 0, error))
def __nmea_read(self): if self.device.type == DeviceGPS.NMEA_SERIAL: comm = self.__serial_read() else: comm = self.__tcp_read() for resp in comm: resp = resp.replace('\n', '') resp = resp.replace('\r', '') resp = resp[1::] resp = resp.split('*') if len(resp) == 2: checksum = self.__nmea_checksum(resp[0]) if checksum == resp[1]: data = resp[0].split(',') if data[0] == 'GPGGA': self.__nmea_global_fix(data) elif data[0] == 'GPGSV': self.__nmea_sats(data) else: error = 'Invalid checksum {}, should be {}'.format( resp[1], checksum) post_event(self.notify, EventThread(Event.LOC_WARN, 0, error))
def __update_check(self): local = get_version_timestamp(True) try: remote = get_version_timestamp_repo() except IOError: post_event(self, EventThread(Event.VER_UPDFAIL)) return if remote > local: post_event(self, EventThread(Event.VER_UPD, local, remote)) else: post_event(self, EventThread(Event.VER_NOUPD))
def redraw_plot(self): if self.figure is not None: post_event(self.notify, EventThread(Event.DRAW))
def run(self): tuner = self.__rtl_setup() if self.sdr is None: return post_event(self.notify, EventThread(Event.INFO, None, tuner)) freq = self.__f_start() timeStamp = math.floor(time.time()) while freq <= self.__f_stop(): if self.cancel: post_event(self.notify, EventThread(Event.STOPPED)) self.rtl_close() return try: scan = self.rtl_scan(freq) if len(scan): post_event( self.notify, EventThread(Event.DATA, freq, (timeStamp, scan))) except IOError: if self.sdr is not None: self.rtl_close() self.__rtl_setup() except (TypeError, AttributeError) as error: if self.notify: post_event(self.notify, EventThread(Event.ERROR, 0, error.message)) return except WindowsError: if self.sdr is not None: self.rtl_close() freq += self.__f_step() post_event(self.notify, EventThread(Event.FINISHED, 0, None)) if self.isCal: post_event(self.notify, EventThread(Event.CAL))
def __on_process_done(self, data): timeStamp, freq, scan = data post_event(self.queueNotify, EventThread(Event.PROCESSED, freq, (timeStamp, scan)))
def __post_location(self, lat, lon, alt): utc = time.time() post_event(self._notify, EventThread(Event.LOC, 0, [lat, lon, alt, utc]))
def run(self): tuner = self.__rtl_setup() if self.sdr is None: return post_event(self.notify, EventThread(Event.INFO, None, tuner)) freq = self.__f_start() timeStamp = math.floor(time.time()) while freq <= self.__f_stop(): if self.cancel: post_event(self.notify, EventThread(Event.STOPPED)) self.rtl_close() return try: scan = self.rtl_scan(freq) if len(scan): self.queue.put([freq, (timeStamp, scan)]) post_event(self.notify, EventThread(Event.DATA)) else: post_event( self.notify, EventThread(Event.ERROR, 0, 'No samples returned')) return except (AttributeError, MemoryError, TypeError) as error: post_event(self.notify, EventThread(Event.ERROR, 0, error.message)) return except (IOError, OSError) as error: if self.sdr is not None: self.rtl_close() post_event(self.notify, EventThread(Event.ERROR, 0, error.message)) return freq += self.__f_step() post_event(self.notify, EventThread(Event.FINISHED, 0, None)) if self.isCal: post_event(self.notify, EventThread(Event.CAL))
def __serial_timeout(self): self.stop() post_event(self._notify, EventThread(Event.LOC_ERR, 0, 'GPS timed out'))
def redraw_plot(self): post_event(self.notify, EventThread(Event.DRAW))
def _post_event(): threading.Timer(event_interval, _post_event).start() post_event(dataset_id, version, event_poster)