Skip to content

Commit

Permalink
Merge pull request #962 from anarkiwi/timeout
Browse files Browse the repository at this point in the history
implement sample duration for rssi.
  • Loading branch information
anarkiwi authored Nov 10, 2023
2 parents 8783066 + 7882c03 commit dd4e52e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 8 additions & 1 deletion gamutrf/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,12 @@ def report_rssi(self, record_args, reported_rssi, reported_time):

def process_rssi(self, record_args, sock):
last_rssi_time = 0
duration = 0
if record_args["sample_count"]:
duration = float(record_args["sample_count"]) / float(
record_args["sample_rate"]
)
start_time = time.time()
while self.q.empty():
rssi_raw, _ = sock.recvfrom(FLOAT_SIZE)
rssi = struct.unpack("f", rssi_raw)[0]
Expand All @@ -328,6 +334,8 @@ def process_rssi(self, record_args, sock):
if rssi > MAX_RSSI:
continue
now = time.time()
if duration and now - start_time > duration:
break
now_diff = now - last_rssi_time
if now_diff < self.arguments.rssi_interval:
continue
Expand All @@ -349,7 +357,6 @@ def serve_rssi(self, record_args):
else:
center_freq = int(record_args["center_freq"])
try:
# TODO: enable duration
rssi_server = BirdsEyeRSSI(
self.arguments,
record_args["sample_rate"],
Expand Down
9 changes: 5 additions & 4 deletions tests/test_birdseye_rssi.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,21 @@ def test_birdseye_smoke(self):
tb.wait()

def verify_birdseye_stream(self, gamutdir, freq):
sample_rate = 1000000
duration = 10
sample_count = duration * sample_rate
for _ in range(15):
try:
response = requests.get(
f"http://localhost:8000/v1/rssi/{int(freq)}/1000000/1000000"
f"http://localhost:8000/v1/rssi/{int(freq)}/{sample_count}/{sample_rate}"
)
self.assertEqual(200, response.status_code, response)
break
except requests.exceptions.ConnectionError:
time.sleep(1)
mqtt_logs = None
line_json = None
for _ in range(30):
for _ in range(duration):
self.assertTrue(os.path.exists(gamutdir))
mqtt_logs = glob.glob(os.path.join(gamutdir, "mqtt-rssi-*log"))
for log_name in mqtt_logs:
Expand Down Expand Up @@ -72,8 +75,6 @@ def test_birdseye_endtoend_rssi(self):
container = client.containers.run(
test_tag,
command=[
"timeout",
"60s",
"gamutrf-worker",
"--rssi_threshold=-100",
f"--sdr=file:{testraw}",
Expand Down

0 comments on commit dd4e52e

Please sign in to comment.