diff --git a/scripts/_input_protection_disable.py b/scripts/_input_protection_disable.py new file mode 100644 index 00000000..18e62953 --- /dev/null +++ b/scripts/_input_protection_disable.py @@ -0,0 +1,25 @@ +import json +from its_preselector.controlbyweb_web_relay import ControlByWebWebRelay +from its_preselector.web_relay_preselector import WebRelayPreselector + +sensor_definition_file = "/opt/scos-sensor/configs/sensor_definition.json" +preselector_json_file = "/opt/scos-sensor/configs/preselector_config.json" +spu_relay_json_file = "/opt/scos-sensor/configs/switches/x410_config.json" + +# Load Preselector +with open(sensor_definition_file, "r") as f: + sensor_definition_json = json.load(f) +with open(preselector_json_file, "r") as f: + preselector_json = json.load(f) +preselector = WebRelayPreselector(sensor_definition_json, preselector_json) + +# Load SPU Relay +with open(spu_relay_json_file, "r") as f: + spu_json = json.load(f) +spu_relay = ControlByWebWebRelay(spu_json) + +# Enable Preselector Power +spu_relay.set_state("power_on_preselector") + +# Set Preselector to Antenna State +preselector.set_state("antenna") diff --git a/scripts/_input_protection_enable.py b/scripts/_input_protection_enable.py new file mode 100644 index 00000000..613661f6 --- /dev/null +++ b/scripts/_input_protection_enable.py @@ -0,0 +1,25 @@ +import json +from its_preselector.controlbyweb_web_relay import ControlByWebWebRelay +from its_preselector.web_relay_preselector import WebRelayPreselector + +sensor_definition_file = "/opt/scos-sensor/configs/sensor_definition.json" +preselector_json_file = "/opt/scos-sensor/configs/preselector_config.json" +spu_relay_json_file = "/opt/scos-sensor/configs/switches/x410_config.json" + +# Load Preselector +with open(sensor_definition_file, "r") as f: + sensor_definition_json = json.load(f) +with open(preselector_json_file, "r") as f: + preselector_json = json.load(f) +preselector = WebRelayPreselector(sensor_definition_json, preselector_json) + +# Load SPU Relay +with open(spu_relay_json_file, "r") as f: + spu_json = json.load(f) +spu_relay = ControlByWebWebRelay(spu_json) + +# Set Preselector to Noise Diode Off State +preselector.set_state("noise_diode_off") + +# Disable Preselector Power +spu_relay.set_state("power_off_preselector") diff --git a/scripts/input_protection.sh b/scripts/input_protection.sh new file mode 100644 index 00000000..d12e7349 --- /dev/null +++ b/scripts/input_protection.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Usage: +# - Activate a Python environment with the its_preselector +# package installed +# - Run this script with start and stop times for input +# protection specified as command line arguments. + +# Example: Enable input protection from 10:00 to 12:00 +# > sudo bash +# > cd /opt/scos-sensor +# > venv/bin/activate +# > pip install git+https://github.com/NTIA/Preselector +# > bash scripts/input_protection.sh 10:00 12:00 + +# This script sets the preselector state to "noise_diode_off" +# then powers off the preselector, at START_TIME +# Then, at STOP_TIME, the preselector is powered on and set to +# the "antenna" state. + + +START_TIME=$1 +STOP_TIME=$2 + +SCRIPT_DIR=$(dirname "$0") + +echo "python3 $SCRIPT_DIR/_input_protection_enable.py" | at $START_TIME + +echo "python3 $SCRIPT_DIR/_input_protection_disable.py" | at $STOP_TIME \ No newline at end of file