Skip to content

Commit 7301d7d

Browse files
authored
Merge pull request #267 from NTIA/ActionRefactorActionsApp
Initialization and users app
2 parents 4e86cf8 + 7de7c4e commit 7301d7d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1182
-1140
lines changed

README.md

+182-18
Original file line numberDiff line numberDiff line change
@@ -309,18 +309,28 @@ settings in the environment file:
309309

310310
- ADDITIONAL_USER_NAMES: Comma separated list of additional admin usernames.
311311
- ADDITIONAL_USER_PASSWORD: Password for additional admin users.
312-
- ADMIN_NAME: Username for the admin user.
313312
- ADMIN_EMAIL: Email used to generate admin user. Change in production.
313+
- ADMIN_NAME: Username for the admin user.
314314
- ADMIN_PASSWORD: Password used to generate admin user. Change in production.
315315
- AUTHENTICATION: Authentication method used for scos-sensor. Supports `TOKEN` or
316316
`CERT`.
317-
- BASE_IMAGE: Base docker image used to build the API container.
317+
- BASE_IMAGE: Base docker image used to build the API container. These docker
318+
images, combined with any drivers found in the signal analyzer repos, are
319+
responsible for providing the operating system suitable for the chosen signal
320+
analyzer. Note, this should be updated when switching signal analyzers.
321+
By default, this is configured to
322+
use a version of `ghcr.io/ntia/scos-tekrsa/tekrsa_usb` to use a Tektronix
323+
signal analyzer.
318324
- CALLBACK_AUTHENTICATION: Sets how to authenticate to the callback URL. Supports
319325
`TOKEN` or `CERT`.
320326
- CALLBACK_SSL_VERIFICATION: Set to “true” in production environment. If false, the SSL
321327
certificate validation will be ignored when posting results to the callback URL.
322-
- CALLBACK_TIMEOUT: The timeout for the requests sent to the callback URL.
328+
- CALLBACK_TIMEOUT: The timeout for the posts sent to the callback URL when a scheduled
329+
action is completed.
323330
- DEBUG: Django debug mode. Set to False in production.
331+
- DEVICE_MODEL: Optional setting indicating the model of the signal analyzer. The
332+
TekRSASigan class will use this value to determine which action configs to load.
333+
See [scos-tekrsa](https://github.com/ntia/scos-tekrsa) for additional details.
324334
- DOCKER_TAG: Always set to “latest” to install newest version of docker containers.
325335
- DOMAINS: A space separated list of domain names. Used to generate [ALLOWED_HOSTS](
326336
<https://docs.djangoproject.com/en/3.0/ref/settings/#allowed-hosts>).
@@ -344,17 +354,36 @@ settings in the environment file:
344354
- POSTGRES_PASSWORD: Sets password for the Postgres database for the “postgres” user.
345355
Change in production. The env.template file sets to a randomly generated value.
346356
- REPO_ROOT: Root folder of the repository. Should be correctly set by default.
347-
- SCOS_SENSOR_GIT_TAG: The scos-sensor branch name.
357+
- SCOS_SENSOR_GIT_TAG: The scos-sensor branch name. This value may be used in action
358+
metadata to capture the version of the software that produced the sigmf archive.
348359
- SECRET_KEY: Used by Django to provide cryptographic signing. Change to a unique,
349360
unpredictable value. See
350361
<https://docs.djangoproject.com/en/3.0/ref/settings/#secret-key>. The env.template
351362
file sets to a randomly generated value.
363+
- SIGAN_CLASS: The name of the signal analyzer class to use. By default, this is
364+
set to `TekRSASigan` to use a Tektronix signal analyzer. This must be changed
365+
to switch to a different signal analyzer.
366+
- SIGAN_MODULE: The name of the python module that provides the signal analyzer
367+
implementation. This defaults to `scos_tekrsa.hardware.tekrsa_sigan` for the
368+
Tektronix signal analyzers. This must be changed to switch to a different
369+
signal analyzer.
370+
- SIGAN_POWER_CYCLE_STATES: Optional setting to provide the name of the control_state
371+
in the SIGAN_POWER_SWITCH that will power cycle the signal analyzer.
372+
- SIGAN_POWER_SWITCH: Optional setting used to indicate the name of a
373+
[WebRelay](https://github.com/NTIA/Preselector) that may be used to power cycle
374+
the signal analyzer if necessary. Note: specifics of power cycling behavior
375+
are implemented within the signal analyzer implementations or actions.
376+
- SSL_CA_PATH: Path to a CA certificate used to verify scos-sensor client
377+
certificate(s) when authentication is set to CERT.
352378
- SSL_CERT_PATH: Path to server SSL certificate. Replace the certificate in the
353379
scos-sensor repository with a valid certificate in production.
354380
- SSL_KEY_PATH: Path to server SSL private key. Use the private key for your valid
355381
certificate in production.
356-
- SSL_CA_PATH: Path to a CA certificate used to verify scos-sensor client
357-
certificate(s) when authentication is set to CERT.
382+
- USB_DEVICE: Optional string used to search for available USB devices. By default,
383+
this is set to Tektronix to see if the Tektronix signal analyzer is available. If
384+
the specified value is not found in the output of lsusb, scos-sensor will attempt
385+
to restart the api container. If switching to a different signal analyzer, this
386+
setting should be updated or removed.
358387

359388
### Sensor Definition File
360389

@@ -391,6 +420,106 @@ specific to the sensor you are using.
391420
}
392421
```
393422

423+
### Sensor Calibration File
424+
425+
By default, scos-sensor will use `configs/default_calibration.json` as the sensor
426+
calibration file. However, if`configs/sensor_calibration.json` or
427+
`configs/sigan_calibration.json` exist they will be used instead of the default
428+
calibration file. Sensor calibration files allow scos-sensor to apply a gain based
429+
on a laboratory calibration of the sensor and may also contain other useful
430+
metadata that characterizes the sensor performance. For additional
431+
information on the calibration data, see the
432+
[NTIA-Sensor SigMF Calibration Object](https://github.com/NTIA/sigmf-ns-ntia/blob/master/ntia-sensor.sigmf-ext.md#08-the-calibration-object).
433+
The default calibration file is shown below:
434+
435+
```json
436+
{
437+
"calibration_data":{
438+
"datetime": "1970-01-01T00:00:00.000000Z",
439+
"gain": 0,
440+
"noise_figure": null,
441+
"1db_compression_point": null,
442+
"enbw": null,
443+
"temperature": 26.85
444+
},
445+
"last_calibration_datetime": "1970-01-01T00:00:00.000000Z",
446+
"calibration_parameters": [],
447+
"clock_rate_lookup_by_sample_rate": [
448+
],
449+
"sensor_uid": "DEFAULT CALIBRATION",
450+
"calibration_reference": "noise source output"
451+
}
452+
```
453+
454+
The `calibration_parameters` key lists the parameters that will be used to obtain
455+
the calibration data. In the case of the default calibration, there are no
456+
`calibration_parameters` so the calibration data is found directly within the
457+
`calibration_data` element and by default scos-sensor will not apply any additional
458+
gain. Typically, a sensor would be calibrated at particular
459+
sensing parameters. The calibration data for specific parameters should be listed
460+
within the calibration_data object and accessed by the values of the settings
461+
listed in the calibration_parameters element. For example, the calibration below
462+
provides an example of a sensor calibrated at a sample rate of 14000000.0 samples
463+
per second at several frequencies with a signal analyzer reference level setting of -25.
464+
465+
```json
466+
{
467+
"last_calibration_datetime": "2023-10-23T14:39:13.682Z",
468+
"calibration_parameters": [
469+
"sample_rate",
470+
"frequency",
471+
"reference_level",
472+
"preamp_enable",
473+
"attenuation"
474+
],
475+
"clock_rate_lookup_by_sample_rate": [],
476+
"calibration_data": {
477+
"14000000.0": {
478+
"3545000000.0": {
479+
"-25": {
480+
"true": {
481+
"0": {
482+
"datetime": "2023-10-23T14:38:02.882Z",
483+
"gain": 30.09194805857024,
484+
"noise_figure": 4.741521295220736,
485+
"temperature": 15.6
486+
}
487+
}
488+
}
489+
},
490+
"3555000000.0": {
491+
"-25": {
492+
"true": {
493+
"0": {
494+
"datetime": "2023-10-23T14:38:08.022Z",
495+
"gain": 30.401008416406599,
496+
"noise_figure": 4.394893979804061,
497+
"temperature": 15.6
498+
}
499+
}
500+
}
501+
},
502+
"3565000000.0": {
503+
"-25": {
504+
"true": {
505+
"0": {
506+
"datetime": "2023-10-23T14:38:11.922Z",
507+
"gain": 30.848049817892105,
508+
"noise_figure": 4.0751785215495819,
509+
"temperature": 15.6
510+
}
511+
}
512+
}
513+
}
514+
}
515+
}
516+
}
517+
```
518+
519+
When an action is run with the above calibration, SCOS will expect the action to have
520+
a sample_rate, frequency, and reference_level specified in the action config. The values
521+
specified for these parameters will then be used to retrieve the calibration data.
522+
394523
## Security
395524

396525
This section covers authentication, permissions, and certificates used to access the
@@ -661,25 +790,60 @@ repository. The scos-actions repository is intended to be a dependency for every
661790
as it contains the actions base class and signals needed to interface with scos-sensor.
662791
These actions use a common but flexible signal analyzer interface that can be
663792
implemented for new types of hardware. This allows for action re-use by passing the
664-
signal analyzer interface implementation and the required hardware and measurement
665-
parameters to the constructor of these actions. Alternatively, custom actions that
666-
support unique hardware functionality can be added to the plugin.
793+
measurement parameters to the constructor of these actions and supplying the
794+
Sensor instance (including the signal analyzer) to the `__call__` method.
795+
Alternatively, custom actions that support unique hardware functionality can be
796+
added to the plugin.
667797

668-
The scos-actions repository can also be installed as a plugin which uses a mock signal
669-
analyzer.
670-
671-
scos-sensor uses the following convention to discover actions offered by plugins: if
798+
Scos-sensor uses the following convention to discover actions offered by plugins: if
672799
any Python package begins with "scos_", and contains a dictionary of actions at the
673800
Python path `package_name.discover.actions`, these actions will automatically be
674-
available for scheduling.
675-
676-
The scos-usrp plugin adds support for the Ettus B2xx line of signal analyzers.
677-
It can also be used as an example of a plugin which adds new hardware support and
678-
re-uses the common actions in scos-actions.
801+
available for scheduling. Similarly, plugins may offer new action types by including
802+
a dictionary of action classes at the Python path `package_name.discover.action_classes`.
803+
Scos-sensor will load all plugin actions and action classes prior to creating actions
804+
defined in yaml files in `configs/actions` directory. In this manner, a plugin may add new
805+
action types to scos-sensor and those new types may be instantiated/parameterized with yaml
806+
config files.
807+
808+
The [scos-usrp](https://github.com/ntia/scos-usrp) plugin adds support for the Ettus B2xx
809+
line of signal analyzers and [scos-tekrsa](https://github.com/ntia/scos-tekrsa) adss
810+
support for Tektronix RSA306, RSA306B, RSA503A,
811+
RSA507A, RSA513A, RSA518A, RSA603A, and RSA607A real-time spectrum analyzers.
812+
These repositories may also be used as examples of plugins which provide new hardware
813+
support and re-use the common actions in scos-actions.
679814

680815
For more information on adding actions and hardware support, see [scos-actions](
681816
<https://github.com/ntia/scos-actions#development>).
682817

818+
### Switching Signal Analyzers
819+
820+
Scos-sensor currently supports Ettus B2xx signal analyzers through
821+
the [scos-usrp](https://github.com/ntia/scos-usrp) plugin and
822+
Tektronix RSA306, RSA306B, RSA503A, RSA507A, RSA513A,
823+
RSA518A, RSA603A, and RSA607A real-time spectrum analyzers through
824+
the [scos-tekrsa](https://github.com/ntia/scos-tekrsa) plugin. To
825+
configure scos-sensor for the desired signal analyzer review the
826+
instructions in the plugin repository. Generally,
827+
switching signal analyzers involves updating the `BASE_IMAGE`
828+
setting, updating the requirements, and updating the `SIGAN_MODULE`,
829+
`SIGAN_CLASS`, and `USB_DEVICE` settings. To identify the
830+
`BASE_IMAGE`, go to the preferred plugin repository and find
831+
the latest docker image. For example, see
832+
[scos-tekrsa base images](https://github.com/NTIA/scos-tekrsa/pkgs/container/scos-tekrsa%2Ftekrsa_usb)
833+
or
834+
[scos-usrp base images](https://github.com/NTIA/scos-usrp/pkgs/container/scos-usrp%2Fscos_usrp_uhd).
835+
Update the `BASE_IMAGE` setting in env file to the desired base image.
836+
Then update the `SIGAN_MODULE` and `SIGAN_CLASS` settings with
837+
the appropriate Python module and class that provide
838+
an implementation of the `SignalAnalyzerInterface`
839+
(you will have to look in the plugin repo to identify the correct module and class). Finally,
840+
update the requirements with the selected plugin repo.
841+
See [Requirements and Configuration](https://github.com/NTIA/scos-sensor?tab=readme-ov-file#requirements-and-configuration)
842+
and [Using pip-tools](https://github.com/NTIA/scos-sensor?tab=readme-ov-file#using-pip-tools)
843+
for additional information. Be sure to re-source the environment file, update the
844+
requirements files, and prune any existing containers
845+
before rebuilding scos-sensor.
846+
683847
## Preselector Support
684848

685849
Scos-sensor can be configured to support

configs/actions/readme.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Actions
2+
3+
Add yaml configs for actions in this directory to create additional actions.

configs/default_calibration.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"calibration_data":{
3+
"datetime": "1970-01-01T00:00:00.000000Z",
4+
"gain": 0,
5+
"noise_figure": 0.0,
6+
"1db_compression_point": null,
7+
"enbw": null,
8+
"temperature": 26.85
9+
},
10+
"last_calibration_datetime": "1970-01-01T00:00:00.000000Z",
11+
"calibration_parameters": [],
12+
"clock_rate_lookup_by_sample_rate": [
13+
],
14+
"sensor_uid": "DEFAULT CALIBRATION",
15+
"calibration_reference": "noise source output"
16+
}

docker-compose.yml

+4
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@ services:
5959
- POSTGRES_PASSWORD
6060
- SCOS_SENSOR_GIT_TAG
6161
- SECRET_KEY
62+
- SIGAN_MODULE
63+
- SIGAN_CLASS
6264
- SIGAN_POWER_SWITCH
6365
- SIGAN_POWER_CYCLE_STATES
66+
- RUNNING_MIGRATIONS
67+
- USB_DEVICE
6468
expose:
6569
- '8000'
6670
volumes:

docker/Dockerfile-api

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ RUN apt-get update -q && \
66
apt-get install -qy --no-install-recommends \
77
libusb-1.0-0 libpython3.8 \
88
git smartmontools \
9-
python3-pip python3.8 python3.8-dev && \
9+
python3-pip python3.8 python3.8-dev usbutils && \
1010
apt-get clean && rm -rf /var/lib/apt/lists/*
1111

1212
ENV PYTHONUNBUFFERED 1
@@ -27,9 +27,6 @@ COPY ./gunicorn /gunicorn
2727
RUN mkdir -p /entrypoints
2828
COPY ./entrypoints/api_entrypoint.sh /entrypoints
2929

30-
RUN mkdir -p /scripts
31-
COPY ./scripts/create_superuser.py /scripts
32-
3330
RUN chmod +x /entrypoints/api_entrypoint.sh
3431

3532
COPY ./configs /configs

entrypoints/api_entrypoint.sh

+3-9
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,11 @@ function cleanup_demodb {
1010

1111
trap cleanup_demodb SIGTERM
1212
trap cleanup_demodb SIGINT
13-
# This is done to avoid loading actions and connecting to the sigan when migrations are applied and when
14-
# the super user is created.
15-
cp sensor/migration_settings.py sensor/settings.py
13+
RUNNING_MIGRATIONS="True"
14+
export RUNNING_MIGRATIONS
1615
echo "Starting Migrations"
1716
python3.8 manage.py migrate
18-
19-
20-
echo "Creating superuser (if managed)"
21-
python3.8 /scripts/create_superuser.py
22-
cp sensor/runtime_settings.py sensor/settings.py
23-
17+
RUNNING_MIGRATIONS="False"
2418
echo "Starting Gunicorn"
2519
exec gunicorn sensor.wsgi -c ../gunicorn/config.py &
2620
wait

0 commit comments

Comments
 (0)