From a2e1f674d753be17d01a48d25fdf334826bd7056 Mon Sep 17 00:00:00 2001 From: f4exb Date: Mon, 19 Mar 2018 02:19:36 +0100 Subject: [PATCH] Web API: NFM scanner Python script example (1) --- swagger/sdrangel/examples/Readme.md | 96 ++++++++++++++- swagger/sdrangel/examples/nfm_scanner.py | 143 +++++++++++++++++++++++ 2 files changed, 238 insertions(+), 1 deletion(-) create mode 100644 swagger/sdrangel/examples/nfm_scanner.py diff --git a/swagger/sdrangel/examples/Readme.md b/swagger/sdrangel/examples/Readme.md index e50d1dd92..d367e37e5 100644 --- a/swagger/sdrangel/examples/Readme.md +++ b/swagger/sdrangel/examples/Readme.md @@ -64,6 +64,12 @@ It uses the following APIs: - URI: `/sdrangel/deviceset/{deviceSetIndex}/device/run` - HTTP method: `POST` +

nfm_scanner.py

+ +Simple NFM scanner with multiple equally spaced NFM channels. Stops whenever any of the channels squelch opens. + +Requires numpy +

nfm_test.py

Example of creating NFM channels (demodulator and modulator) and changing the settings @@ -125,6 +131,53 @@ It uses the following APIs: - URI: `/sdrangel/deviceset/{deviceSetIndex}/device/settings` - HTTP method: `PATCH` +

rx_test.py

+ +Sets specified Rx in existing source device set or create a new source device set with this Rx. Adds an NFM demodulator channel. + +It uses the following APIs: + + - Create a new device set: + - Operation ID: `devicesetPost` + - URI: `/sdrangel/deviceset` + - HTTP method: `POST` + - Get information on a device set: + - Operation ID: `devicesetGet` + - URI: `/sdrangel/deviceset/{deviceSetIndex}` + - HTTP method: `GET` + - To select a device in a device set: + - Operation ID: `devicesetDevicePut` + - URI: `/sdrangel/deviceset/{deviceSetIndex}/device` + - HTTP method: `PUT` + - To get the settings of a device: + - OperationID: `devicesetDeviceSettingsGet` + - URI: `/sdrangel/deviceset/{deviceSetIndex}/device/settings` + - HTTP method: `GET` + - To change the settings of a device: + - OperationID: `devicesetDeviceSettingsPatch` + - URI: `/sdrangel/deviceset/{deviceSetIndex}/device/settings` + - HTTP method: `PATCH` + - To create a new channel: + - Operation ID: `devicesetChannelPost` + - URI: `/sdrangel/deviceset/{deviceSetIndex}/channel` + - HTTP method: `POST` + - To get the settings of a channel: + - OperationID: `devicesetChannelSettingsGet` + - URI: `/sdrangel/deviceset/{deviceSetIndex}/channel/{channelIndex}/settings` + - HTTP method: `GET` + - To change the settings of a channel: + - OperationID: `devicesetChannelSettingsPatch` + - URI: `/sdrangel/deviceset/{deviceSetIndex}/channel/{channelIndex}/settings` + - HTTP method: `PATCH` + - Start a device streaming + - OperationID: `devicesetDeviceRunPost` + - URI: `/sdrangel/deviceset/{deviceSetIndex}/device/run` + - HTTP method: `POST` + +

rx_tx_test.py

+ +Combines `rx_test` and `tx_test` to create a pair of source and sink device sets. The APIs used are the same as in `rx_test` or `tx_test`. +

start_stop.py

Starts or stops a device in the specified device set @@ -155,4 +208,45 @@ It uses this API: - URI: `/sdrangel` - HTTP method: `DELETE` - \ No newline at end of file +

tx_test.py

+ +Sets specified Tx in existing sink device set or create a new sink device set with this Tx. Adds an NFM modulator channel. + +It uses the following APIs: + + - Create a new device set: + - Operation ID: `devicesetPost` + - URI: `/sdrangel/deviceset` + - HTTP method: `POST` + - Get information on a device set: + - Operation ID: `devicesetGet` + - URI: `/sdrangel/deviceset/{deviceSetIndex}` + - HTTP method: `GET` + - To select a device in a device set: + - Operation ID: `devicesetDevicePut` + - URI: `/sdrangel/deviceset/{deviceSetIndex}/device` + - HTTP method: `PUT` + - To get the settings of a device: + - OperationID: `devicesetDeviceSettingsGet` + - URI: `/sdrangel/deviceset/{deviceSetIndex}/device/settings` + - HTTP method: `GET` + - To change the settings of a device: + - OperationID: `devicesetDeviceSettingsPatch` + - URI: `/sdrangel/deviceset/{deviceSetIndex}/device/settings` + - HTTP method: `PATCH` + - To create a new channel: + - Operation ID: `devicesetChannelPost` + - URI: `/sdrangel/deviceset/{deviceSetIndex}/channel` + - HTTP method: `POST` + - To get the settings of a channel: + - OperationID: `devicesetChannelSettingsGet` + - URI: `/sdrangel/deviceset/{deviceSetIndex}/channel/{channelIndex}/settings` + - HTTP method: `GET` + - To change the settings of a channel: + - OperationID: `devicesetChannelSettingsPatch` + - URI: `/sdrangel/deviceset/{deviceSetIndex}/channel/{channelIndex}/settings` + - HTTP method: `PATCH` + - Start a device streaming + - OperationID: `devicesetDeviceRunPost` + - URI: `/sdrangel/deviceset/{deviceSetIndex}/device/run` + - HTTP method: `POST` diff --git a/swagger/sdrangel/examples/nfm_scanner.py b/swagger/sdrangel/examples/nfm_scanner.py new file mode 100644 index 000000000..fe90c0a9b --- /dev/null +++ b/swagger/sdrangel/examples/nfm_scanner.py @@ -0,0 +1,143 @@ +#!/usr/bin/env python + +import requests, json, traceback, sys +from optparse import OptionParser +import time +import numpy as np + +base_url = "http://127.0.0.1:8091/sdrangel" +deviceset_url = "" + +requests_methods = { + "GET": requests.get, + "PATCH": requests.patch, + "POST": requests.post, + "PUT": requests.put, + "DELETE": requests.delete +} + +class ScanControl: + def __init__(self, num_channels, channel_step, start_freq, stop_freq, log2_decim): + self.channel_shifts = [] + if num_channels < 2: + self.channel_shifts = [0] + limit = 0 + else: + limit = ((num_channels-1)*channel_step) / 2 + self.channel_shifts = list(np.linspace(-limit, limit, num_channels)) + self.device_start_freq = start_freq + limit + self.device_stop_freq = stop_freq - limit + self.device_step_freq = 2*limit + channel_step + self.device_sample_rate = (2*limit + channel_step)*(1<> sys.stderr, tb + + +if __name__ == "__main__": + main() +