def get_data(self): for scanner in self.scanners: if scanner.file_reader.sample_queue.empty(): continue current_cf = self.bands[0][0] count = scanner.sample_count while not scanner.file_reader.sample_queue.empty(): ts, xydata = scanner.file_reader.sample_queue.get() if self.dump_to_file: cPickle.dump((scanner.idx, ts, xydata), self.dump_file) for (tsf, freq_cf, noise, rssi, pwr) in SpectrumFileReader.decode(xydata): print('centre frequency: {}'.format( scanner.freq_to_chan(int(freq_cf)))) sc_pwr = [] if count < scanner.sample_count and current_cf == freq_cf: for freq_sc, sigval in sorted(pwr.items()): sc_pwr.append(sigval) s = pd.Series(sc_pwr, index=df.columns) df = df.append(s, ignore_index=True) else: count = scanner.sample_count for freq_sc, sigval in sorted(pwr.items()): sc_pwr.append(sigval) df = pd.DataFrame(sc_pwr).T count -= 1 current_cf = freq_cf self.write_data("./spectral_data/" + str(current_cf) + ".csv", df)
def update_data(self, w, frame_clock, user_data): time = frame_clock.get_frame_time() if time - self.lastframe > 1000: self.lastframe = time else: return True hmp = self.heatmap mpf = self.max_per_freq for scanner in self.scanners: if scanner.file_reader.sample_queue.empty(): continue ts, xydata = scanner.file_reader.sample_queue.get() if self.dump_to_file: cPickle.dump((scanner.idx, ts, xydata), self.dump_file) if not self.ui_update: continue for (tsf, freq_cf, noise, rssi, pwr) in SpectrumFileReader.decode(xydata): if scanner.mode.value == 1 and freq_cf < self.last_x: # chanscan # we wrapped the scan... self.hmp_gen += 1 self.mpf_gen += 1 if scanner.mode.value == 2: # background if self.bg_sample_count == self.bg_sample_count_limit: self.bg_sample_count = 0 self.hmp_gen += 1 self.mpf_gen += 1 self.bg_sample_count += 1 for freq_sc, sigval in pwr.iteritems(): if freq_sc not in hmp or self.hmp_gen_tbl.get(freq_sc, 0) < self.hmp_gen: hmp[freq_sc] = {} self.hmp_gen_tbl[freq_sc] = self.hmp_gen arr = hmp[freq_sc] mody = ceil(sigval*2.0)/2.0 arr.setdefault(mody, 0) arr[mody] += 1.0 mpf.setdefault(freq_sc, 0) if sigval > mpf[freq_sc] or self.mpf_gen_tbl.get(freq_sc, 0) < self.mpf_gen: mpf[freq_sc] = sigval self.mpf_gen_tbl[freq_sc] = self.mpf_gen self.last_x = freq_cf if not self.ui_update: return True self.heatmap = hmp self.max_per_freq = mpf w.queue_draw() return True
def process(fn): print "processing '%s':" % fn f = open(fn, 'r') while True: try: device_id, ts, sample_data = cPickle.load(f) for tsf, freq, noise, rssi, pwrs in SpectrumFileReader.decode(sample_data): print device_id, ts, tsf, freq, noise, rssi for carrier_freq, pwr_level in pwrs.iteritems(): print carrier_freq, pwr_level except EOFError: break
def __init__(self, ifaces): self.color_map = self.gen_pallete() self.scanners = [] idx = 0 for iface in ifaces: scanner = Scanner(iface, idx=idx) scanner.mode_chanscan() fn = '%s/spectral_scan0' % scanner.get_debugfs_dir() reader = SpectrumFileReader(fn) scanner.file_reader = reader self.scanners.append(scanner) idx += 1 self.dev_idx = 0 # id of currently selected device if not os.path.exists("./spectral_data"): os.mkdir("./spectral_data") self.dump_to_file = False self.dump_file = None self.ui_update = True self.bg_sample_count = 0 self.bg_sample_count_limit = 500
def __init__(self, ifaces): self.scanners = [] idx = 0 for iface in ifaces: scanner = Scanner(iface, idx=idx) scanner.mode_chanscan() fn = '%s/spectral_scan0' % scanner.get_debugfs_dir() reader = SpectrumFileReader(fn) scanner.file_reader = reader self.scanners.append(scanner) idx += 1 self.dev_idx = 0 if not os.path.exists("./spectral_data"): os.mkdir("./spectral_data") # self.ctl_file = '%s/spectral_scan_ctl' % self.debugfs_dir self.set_band(self.band_idx) self.dump_to_file = False self.dump_file = None self.bg_sample_count = 0 self.bg_sample_count_limit = 500
def update_data(self, w, frame_clock, user_data): time = frame_clock.get_frame_time() if time - self.lastframe > 1000: self.lastframe = time else: return True hmp = self.heatmap mpf = self.max_per_freq for scanner in self.scanners: if scanner.file_reader.sample_queue.empty(): continue ts, xydata = scanner.file_reader.sample_queue.get() if self.dump_to_file: cPickle.dump((scanner.idx, ts, xydata), self.dump_file) if not self.ui_update: continue for (tsf, freq_cf, noise, rssi, pwr) in SpectrumFileReader.decode(xydata): if scanner.mode.value == 1 and freq_cf < self.last_x: # chanscan # we wrapped the scan... self.hmp_gen += 1 self.mpf_gen += 1 if scanner.mode.value == 2: # background if self.bg_sample_count == self.bg_sample_count_limit: self.bg_sample_count = 0 self.hmp_gen += 1 self.mpf_gen += 1 self.bg_sample_count += 1 for freq_sc, sigval in pwr.iteritems(): if freq_sc not in hmp or self.hmp_gen_tbl.get( freq_sc, 0) < self.hmp_gen: hmp[freq_sc] = {} self.hmp_gen_tbl[freq_sc] = self.hmp_gen arr = hmp[freq_sc] mody = ceil(sigval * 2.0) / 2.0 arr.setdefault(mody, 0) arr[mody] += 1.0 mpf.setdefault(freq_sc, 0) if sigval > mpf[freq_sc] or self.mpf_gen_tbl.get( freq_sc, 0) < self.mpf_gen: mpf[freq_sc] = sigval self.mpf_gen_tbl[freq_sc] = self.mpf_gen self.last_x = freq_cf if not self.ui_update: return True self.heatmap = hmp self.max_per_freq = mpf w.queue_draw() return True
def __init__(self, iface): self.scanner = Scanner(iface) fn = '%s/spectral_scan0' % self.scanner.get_debugfs_dir() self.file_reader = SpectrumFileReader(fn) self.interface = iface
class AthBenchmark(object): def __init__(self, iface): self.scanner = Scanner(iface) fn = '%s/spectral_scan0' % self.scanner.get_debugfs_dir() self.file_reader = SpectrumFileReader(fn) self.interface = iface def get_samples(self, duration): sps = 0 end = datetime.now() + timedelta(seconds=duration) while datetime.now() < end: try: ts, samples = self.file_reader.sample_queue.get(timeout=0.1) except Queue.Empty: continue sps += len(samples) / (17 + 56) # (header + payload in HT20) print "total: %d sps" % sps sps /= float(duration) return sps # count samples in chanscan def benchmark_chanscan(self, duration=5, samplecount=8): print "\nrun benchmark chanscan with samplecount=%d, duration=%d " % (samplecount, duration) self.scanner.cmd_set_samplecount(samplecount) self.scanner.mode_chanscan() self.scanner.start() sps = self.get_samples(duration=duration) self.scanner.stop() self.file_reader.flush() print "%.2f sps, chanscan" % sps return sps # count samples in bg mode (w/o) load def benchmark_background(self, duration=5): print "\nrun benchmark background with duration=%d " % duration self.scanner.mode_noninvasive_background() self.scanner.dev_add_monitor() self.scanner.start() sps = self.get_samples(duration=duration) self.scanner.stop() self.file_reader.flush() print "%.2f sps, background scan " % sps return sps def benchmark_manual(self, samplecount=127): print "\nrun benchmark manual with samplecount=%d " % samplecount self.scanner.mode_manual() self.scanner.cmd_manual() self.scanner.cmd_set_samplecount(samplecount) self.scanner.dev_add_monitor() self.scanner.cmd_trigger() sps = 0 reread = 3 while reread: try: ts, samples = self.file_reader.sample_queue.get(timeout=0.1) sps += len(samples) / (17 + 56) # (header + payload in HT20) except Queue.Empty: pass reread -= 1 self.scanner.stop() self.file_reader.flush() print "got %d samples in manual mode" % sps return sps def main(self): samplecount = [1, 10, 50, 100, 150, 200, 255] for sc in samplecount: sps = self.benchmark_chanscan( duration=5, samplecount=sc) print "sps / samplecount: %.2f" % (sps / sc) time.sleep(0.2) self.benchmark_background(duration=5) time.sleep(0.2) self.benchmark_manual(samplecount=127) time.sleep(0.2) self.cleanup() def cleanup(self): # self.scanner.stop() self.file_reader.stop()
class AthBenchmark(object): def __init__(self, iface): self.scanner = Scanner(iface) fn = '%s/spectral_scan0' % self.scanner.get_debugfs_dir() self.file_reader = SpectrumFileReader(fn) self.interface = iface def get_samples(self, duration): sps = 0 end = datetime.now() + timedelta(seconds=duration) while datetime.now() < end: try: ts, samples = self.file_reader.sample_queue.get(timeout=0.1) except Queue.Empty: continue sps += len(samples) / (17 + 56) # (header + payload in HT20) print "total: %d sps" % sps sps /= float(duration) return sps # count samples in chanscan def benchmark_chanscan(self, duration=5, samplecount=8): print "\nrun benchmark chanscan with samplecount=%d, duration=%d " % ( samplecount, duration) self.scanner.cmd_set_samplecount(samplecount) self.scanner.mode_chanscan() self.scanner.start() sps = self.get_samples(duration=duration) self.scanner.stop() self.file_reader.flush() print "%.2f sps, chanscan" % sps return sps # count samples in bg mode (w/o) load def benchmark_background(self, duration=5): print "\nrun benchmark background with duration=%d " % duration self.scanner.mode_noninvasive_background() self.scanner.dev_add_monitor() self.scanner.start() sps = self.get_samples(duration=duration) self.scanner.stop() self.file_reader.flush() print "%.2f sps, background scan " % sps return sps def benchmark_manual(self, samplecount=127): print "\nrun benchmark manual with samplecount=%d " % samplecount self.scanner.mode_manual() self.scanner.cmd_manual() self.scanner.cmd_set_samplecount(samplecount) self.scanner.dev_add_monitor() self.scanner.cmd_trigger() sps = 0 reread = 3 while reread: try: ts, samples = self.file_reader.sample_queue.get(timeout=0.1) sps += len(samples) / (17 + 56) # (header + payload in HT20) except Queue.Empty: pass reread -= 1 self.scanner.stop() self.file_reader.flush() print "got %d samples in manual mode" % sps return sps def main(self): samplecount = [1, 10, 50, 100, 150, 200, 255] for sc in samplecount: sps = self.benchmark_chanscan(duration=5, samplecount=sc) print "sps / samplecount: %.2f" % (sps / sc) time.sleep(0.2) self.benchmark_background(duration=5) time.sleep(0.2) self.benchmark_manual(samplecount=127) time.sleep(0.2) self.cleanup() def cleanup(self): # self.scanner.stop() self.file_reader.stop()