diff --git a/README.md b/README.md index b2a3785f..0bc5eee3 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,11 @@ For example, make a recording with a sample rate of 20.48e6, for 2 seconds (4096 $ wget -nv -O- localhost:8000/v1/record/100000000/409600000/20480000 ``` -If the worker is started with `--rssi`, that same ```record``` call will cause the worker to publish RSSI values instead of recording (the duration argument must be present, but is not used). +To stream RSSI values instead, call (note that the duration argument must be present, but is not currently used): + +``` +$ wget -nv -O- localhost:8000/v1/rssi/100000000/409600000/20480000 +``` ## Working with worker I/Q recordings diff --git a/gamutrf/sigfinder.py b/gamutrf/sigfinder.py index a50ed6f5..c0a7d33d 100644 --- a/gamutrf/sigfinder.py +++ b/gamutrf/sigfinder.py @@ -81,7 +81,8 @@ def on_post(self, req, resp): signal_hz = int(int(req.media["frequency"]) * 1e6) record_bps = int(int(req.media["bandwidth"]) * MB) record_samples = int(record_bps * int(req.media["duration"])) - recorder_args = f"record/{signal_hz}/{record_samples}/{record_bps}" + action = req.media["action"] + recorder_args = f"{action}/{signal_hz}/{record_samples}/{record_bps}" timeout = int(req.media["duration"]) response = None if int(req.media["repeat"]) == -1: diff --git a/gamutrf/worker.py b/gamutrf/worker.py index a6ab9b46..0f3a135c 100644 --- a/gamutrf/worker.py +++ b/gamutrf/worker.py @@ -138,13 +138,6 @@ def argument_parser(): action=argparse.BooleanOptionalAction, help="add sigmf meta file", ) - parser.add_argument( - "--rssi", - dest="enable_rssi", - default=False, - action=argparse.BooleanOptionalAction, - help="get RSSI values", - ) parser.add_argument( "--use_external_gps", dest="use_external_gps", @@ -206,11 +199,12 @@ def on_get(self, _req, resp): resp.status = falcon.HTTP_200 -class Record: +class Action: def __init__(self, arguments, q, sdr_recorder): self.arguments = arguments self.q = q self.sdr_recorder = sdr_recorder + self.action = None def on_get(self, _req, resp, center_freq, sample_count, sample_rate): # TODO check if chosen SDR can do the supplied sample_count @@ -228,6 +222,7 @@ def on_get(self, _req, resp, center_freq, sample_count, sample_rate): if status is None: self.q.put( { + "action": self.action, "center_freq": int(center_freq), "sample_count": int(sample_count), "sample_rate": int(sample_rate), @@ -239,6 +234,18 @@ def on_get(self, _req, resp, center_freq, sample_count, sample_rate): resp.text = json.dumps({"status": status}) +class Record(Action): + def __init__(self, arguments, q, sdr_recorder): + super().__init__(arguments, q, sdr_recorder) + self.action = "record" + + +class Rssi(Action): + def __init__(self, arguments, q, sdr_recorder): + super().__init__(arguments, q, sdr_recorder) + self.action = "record" + + class API: def __init__(self, arguments): self.arguments = arguments @@ -267,10 +274,14 @@ def run_recorder(self, record_func): logging.info("run recorder") while True: logging.info("awaiting request") - if self.arguments.enable_rssi: - self.serve_rssi() + action_args = self.q.get() + action = action_args["action"] + if action == "record": + self.serve_recording(record_func, action_args) + elif action == "rssi": + self.serve_rssi(action_args) else: - self.serve_recording(record_func) + logging.error("no such action: %s", action) def record(self, center_freq, sample_count, sample_rate=20e6): return self.sdr_recorder.run_recording( @@ -286,8 +297,7 @@ def record(self, center_freq, sample_count, sample_rate=20e6): self.arguments.antenna, ) - def serve_recording(self, record_func): - record_args = self.q.get() + def serve_recording(self, record_func, record_args): logging.info(f"got a request: {record_args}") record_status = record_func(**record_args) if record_status == -1: @@ -330,8 +340,7 @@ def proxy_rssi(self, rssi_addr, record_args): sock.bind((rssi_addr, RSSI_UDP_PORT)) # nosec self.process_rssi(record_args, sock) - def serve_rssi(self): - record_args = self.q.get() + def serve_rssi(self, record_args): logging.info(f"got request {record_args}") if self.arguments.rssi_external: logging.info("proxying external RSSI") @@ -340,6 +349,7 @@ def serve_rssi(self): else: center_freq = int(record_args["center_freq"]) try: + # TODO: enable duration rssi_server = BirdsEyeRSSI( self.arguments, record_args["sample_rate"], @@ -361,7 +371,12 @@ def serve_rssi(self): @staticmethod def paths(): - return ["", "/info", "/record/{center_freq}/{sample_count}/{sample_rate}"] + return [ + "", + "/info", + "/record/{center_freq}/{sample_count}/{sample_rate}", + "/rssi/{center_freq}/{sample_count}/{sample_rate}", + ] @staticmethod def version(): @@ -372,7 +387,8 @@ def routes(self): endpoints = Endpoints() info = Info(self.arguments) record = Record(self.arguments, self.q, self.sdr_recorder) - funcs = [endpoints, info, record] + rssi = Rssi(self.arguments, self.q, self.sdr_recorder) + funcs = [endpoints, info, record, rssi] return dict(zip(p, funcs)) def run(self): diff --git a/templates/scanner_form.html b/templates/scanner_form.html index 05c3a4d3..c7d10ca7 100644 --- a/templates/scanner_form.html +++ b/templates/scanner_form.html @@ -5,6 +5,7 @@ {% endfor %}

Make a request to record below:

Worker IP or name

+

Action (e.g. record, rssi

Frequency

Bandwidth in Mhz (20 max)

Duration in seconds

diff --git a/tests/test_api.py b/tests/test_api.py index 32826518..04c8385b 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -52,14 +52,12 @@ def test_report_rssi(): def test_serve_recording(): app = worker.API(FakeArgs()) - app.q.put({"center_freq": 1e6, "sample_count": 1e6}) - app.serve_recording(app.record) + app.serve_recording(app.record, {"center_freq": 1e6, "sample_count": 1e6}) def test_serve_rssi(): app = worker.API(FakeArgs()) - app.q.put({"center_freq": 1e6, "sample_count": 1e6, "sample_rate": 1e6}) - app.serve_rssi() + app.serve_rssi({"center_freq": 1e6, "sample_count": 1e6, "sample_rate": 1e6}) def test_argument_parse(): diff --git a/tests/test_birdseye_rssi.py b/tests/test_birdseye_rssi.py index b4c1a71d..510b694b 100644 --- a/tests/test_birdseye_rssi.py +++ b/tests/test_birdseye_rssi.py @@ -34,7 +34,7 @@ def verify_birdseye_stream(self, gamutdir, freq): for _ in range(15): try: response = requests.get( - f"http://localhost:8000/v1/record/{int(freq)}/1000000/1000000" + f"http://localhost:8000/v1/rssi/{int(freq)}/1000000/1000000" ) self.assertEqual(200, response.status_code, response) break @@ -76,7 +76,6 @@ def test_birdseye_endtoend_rssi(self): "60s", "gamutrf-worker", "--rssi_threshold=-100", - "--rssi", f"--sdr=file:{testraw}", ], ports={"8000/tcp": 8000}, diff --git a/worker.yml b/worker.yml index 358f44d9..a0ccaa4d 100644 --- a/worker.yml +++ b/worker.yml @@ -34,7 +34,6 @@ services: - --rxb=62914560 - '--gain=${GAIN}' - --qsize=5 - #- --rssi #- --rssi_threshold=-110 #- --rssi_throttle=10 #- --use_external_gps