From ceeccd90f648b4f673d2633df4cb7dafc1bbf5b4 Mon Sep 17 00:00:00 2001 From: Arturs Artamonovs Date: Sun, 26 Mar 2023 14:08:10 +0100 Subject: Update waterfall --- airspyhf/airspyhf.py | 2 +- airspyhf_waterfall.py | 95 ++++++++++++++++++++++++++++++++------------------- 2 files changed, 60 insertions(+), 37 deletions(-) mode change 100644 => 100755 airspyhf_waterfall.py diff --git a/airspyhf/airspyhf.py b/airspyhf/airspyhf.py index 5a26fa3..74e2e1d 100644 --- a/airspyhf/airspyhf.py +++ b/airspyhf/airspyhf.py @@ -98,7 +98,7 @@ class AirSpyHF: ret = libairspyhf.airspyhf_set_hf_lna(self.dev_p, flag) return ret - def set_frequency(self,freq:int): + def set_frequency(self, freq:int): if not self.initalized: print("airspy not initalized") return -1 diff --git a/airspyhf_waterfall.py b/airspyhf_waterfall.py old mode 100644 new mode 100755 index fc1de56..f51935e --- a/airspyhf_waterfall.py +++ b/airspyhf_waterfall.py @@ -1,3 +1,5 @@ +#!/usr/bin/python3 + import os import sys import math @@ -14,15 +16,15 @@ import pygame from pygame import gfxdraw CENTER_FREQ = 101000000 -SAMPLE_RATE = 196e3 +SAMPLE_RATE = 912e3 SAMPLE_NUM = 2048 SCREEN_X = 1025 SCREEN_Y = 320 -MOVE_STEP = int(SAMPLE_RATE/2) +MOVE_STEP = int(SAMPLE_RATE/8) -sample_buf_lock = threading.Lock() +sample_lock = threading.Lock() # init AIRSPY and if no then go out airspy = airspyhf.AirSpyHF() @@ -31,7 +33,7 @@ if airspy.open(device_index=0) == -1: sys.exit(1) # config rtlsdr device -airspy.set_samplerate(SAMPLE_RATE) +airspy.set_samplerate(int(SAMPLE_RATE)) airspy.set_frequency(CENTER_FREQ) airspy.set_hf_agc(1) airspy.set_hf_agc_threshold(0) @@ -46,6 +48,8 @@ def iq_abs(c): def color_normalise(point): ret = (255, 0, 0) # blue + if point < 0.0: + point = 0.0 if (point < 0.3): ret = (0, 0, int(point * 255 * 3.3)) # yello @@ -57,15 +61,35 @@ def color_normalise(point): else: # print "Color Error ", point pass + print(ret) return ret def color_mapping(x): "assumes -50 to 0 range, returns color" - r = int((x + 70) * 255 // 70) - r = max(0, r) - r = min(255, r) - return (r, r, 100) + + #r = math.fabs(int(x)) + #if r > 255: + # r = 255 + #print("+",r) + r = int((x + 120) * 255 // 30) + #r = max(0, r) + #r = min(255, r) + if r > 255: + r = 255 + if r < 0: + r = 0 + res = (r, r, r) + #avg3 = avg(r)/3 + #if avg3 < 0.3: + # res = (0, 0, int(avg3 * 255 * 3.3)) + + print(res) + return res + #r = 255-r + #print((int(r), int(r), 100)) + #return (int(r), int(r), 100) + # def draw_Hz( surface, x, y, hz ): @@ -83,11 +107,8 @@ screen = pygame.display.set_mode((SCREEN_X, SCREEN_Y)) sample_buffer = [] def read_samples(transfer): global sample_buffer + #print("callback") - #if sample_buf_lock.locked(): - # print("Buffer locked") - # return 0 - #sample_buf_lock.acquire() #print("Python call back") t = transfer.contents bytes_to_write = t.sample_count * 4 * 2 @@ -95,6 +116,8 @@ def read_samples(transfer): rx_buffer = t.samples #print(f"{bytes_to_write} bytes receieved") #sample_buffer.append(rx_buffer) + if len(sample_buffer) > SAMPLE_NUM: + return 0 for i in range(0,t.sample_count): d_re = t.samples[i].re d_im = t.samples[i].im @@ -104,22 +127,21 @@ def read_samples(transfer): #data = struct.pack("