Skip to content

Commit

Permalink
Merge pull request #7 from NTIA/scos-sensor
Browse files Browse the repository at this point in the history
Support X410 sensor format and allow for instantiation from just sensor definition json.
  • Loading branch information
dboulware authored Jun 14, 2022
2 parents ee275a6 + cdbe036 commit ee86931
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 13 deletions.
5 changes: 1 addition & 4 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@
"noise_diode_on" : "1State=1,2State=1,3State=0,4State=0",
"noise_diode_off" : "1State=1,2State=0,3State=0,4State=0",
"antenna" : "1State=0,2State=0,3State=0,4State=0"
}



}
28 changes: 22 additions & 6 deletions src/its_preselector/preselector.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,44 @@ def __init__(self, sigmf, config):
self.preselector_spec = []
self.config = config
try:
self.__set_filters(sigmf['global']['ntia-sensor:sensor']['preselector']['filters'])
if 'global' in sigmf:
self.__set_filters(sigmf['global']['ntia-sensor:sensor']['preselector']['filters'])
else:
self.__set_filters(sigmf['preselector']['filters'])
except KeyError:
pass

try:
self.__set_amplifiers(sigmf['global']['ntia-sensor:sensor']['preselector']['amplifiers'])
if 'global' in sigmf:
self.__set_amplifiers(sigmf['global']['ntia-sensor:sensor']['preselector']['amplifiers'])
else:
self.__set_amplifiers(sigmf['preselector']['amplifiers'])
except KeyError:
pass

try:
self.__get_rf_paths(sigmf['global']['ntia-sensor:sensor']['preselector']['rf_paths'])
if 'global' in sigmf:
self.__get_rf_paths(sigmf['global']['ntia-sensor:sensor']['preselector']['rf_paths'])
else:
self.__get_rf_paths(sigmf['preselector']['rf_paths'])
except KeyError:
pass

try:
self.__set_cal_sources(sigmf['global']['ntia-sensor:sensor']['preselector']['cal_sources'])
if 'global' in sigmf:
self.__set_cal_sources(sigmf['global']['ntia-sensor:sensor']['preselector']['cal_sources'])
else:
self.__set_cal_sources(sigmf['preselector']['cal_sources'])
except KeyError:
pass

try:
self.preselector_spec = HardwareSpec(
sigmf['global']['ntia-sensor:sensor']['preselector']['preselector_spec'])
if 'global' in sigmf:
self.preselector_spec = HardwareSpec(
sigmf['global']['ntia-sensor:sensor']['preselector']['preselector_spec'])
else:
self.preselector_spec = HardwareSpec(
sigmf['preselector']['preselector_spec'])
except KeyError:
pass

Expand Down
105 changes: 105 additions & 0 deletions src/its_preselector/test/sensor_definition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
"id":"11.11.11.111",
"sensor_spec":{
"id":"Default",
"model":"Default",
"version":"vD.f.t",
"description":"Default"

},
"antenna":{
"antenna_spec":{
"model":"Default",
"description":"Default"

},
"type":"Default",
"frequency_low":0.0,
"frequency_high":9999999.0,
"gain":99.0,
"polarization":"Default",
"horizontal_beam_width":360.0,
"vertical_beam_width":90.0,
"voltage_standing_wave_ratio":9.9,
"steerable":false

},
"preselector":{
"cal_sources":[
{
"cal_source_spec":{
"description":"Default"

},
"enr":14.53

}

],
"filters":[
{
"filter_spec":{
"id":"default",
"model":"default",
"supplemental_information":"default"

},
"frequency_low_passband":9999999.0,
"frequency_high_passband":9.9999999E7,
"frequency_low_stopband":999999.0,
"frequency_high_stopband":9.99999999E8

}

],
"amplifiers":[
{
"amplifier_spec":{


}

}

],
"rf_paths":[
{
"name":"default",
"filter_id":"default"

}

]

},
"signal_analyzer":{
"sigan_spec":{
"id":"Default",
"model":"Default",
"supplemental_information":"Default"

},
"frequency_low":9999999999.0,
"frequency_high":0.0,
"noise_figure":99.0,
"a2d_bits":99

},
"computer_spec":{
"id":"default",
"description":"Default"

},
"location":{
"x":-199.0,
"y":99.0,
"z":9999.0,
"speed":0.0,
"description":"default"

},
"environment":{
"category":"Default"

}
}
6 changes: 6 additions & 0 deletions src/its_preselector/test/test_preselector.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def setUpClass(cls):
null_def = json.load(null_file)
null_file.close()
cls.empty_preselector = WebRelayPreselector(null_def, {})
with open('sensor_definition.json', 'r') as f:
sensor_def = json.load(f)
cls.scos_preselector = WebRelayPreselector(sensor_def, {})

def test_valid_preselector(self):
self.assertIsNotNone(self.preselector)
Expand Down Expand Up @@ -64,6 +67,9 @@ def test_get_amplifier_noise_figure(self):
def test_empty_get_amplifier_noise_figure(self):
self.assertIsNone(self.empty_preselector.get_amplifier_noise_figure(0))

def test_scos_calibration_sources(self):
self.assertEqual(1, len(self.scos_preselector.cal_sources))


if __name__ == '__main__':
unittest.main()
14 changes: 11 additions & 3 deletions src/its_preselector/web_relay_preselector.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@ def set_state(self, i):
raise Exception("RF path " + key + " configuration does not exist.")

def get_sensor_value(self, sensor_num):
sensor_num_string = str(sensor_num)
response = requests.get(self.base_url + '?sensor' + sensor_num_string)
sensor_num_string = str(sensor_num)
response = requests.get(self.base_url)
#Check for X310 xml format first.
sensor_tag = 'sensor' + sensor_num_string
root = ET.fromstring(response.text)
sensor = root.find(sensor_tag)
return sensor.text
if sensor is None:
#Didn't find X310 format sensor so check for X410 format.
sensor_tag = 'oneWireSensor' + sensor_num_string
sensor = root.find(sensor_tag)
if sensor is None:
return None
else:
return sensor.text

def healthy(self):
try:
Expand Down

0 comments on commit ee86931

Please sign in to comment.