Skip to content

Commit

Permalink
Merge pull request #291 from projecthorus/testing
Browse files Browse the repository at this point in the history
v1.3.2 release
  • Loading branch information
darksidelemm authored Jul 24, 2020
2 parents 97f165d + 17f28af commit 72cb7de
Show file tree
Hide file tree
Showing 41 changed files with 3,983 additions and 1,678 deletions.
53 changes: 41 additions & 12 deletions auto_rx/auto_rx.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
exporter_objects = [] # This list will hold references to each exporter instance that is created.
exporter_functions = [] # This list will hold references to the exporter add functions, which will be passed onto the decoders.

# Separate reference to the e-mail exporter, as we may want to use this for error notifications.
email_exporter = None

# GPSDAdaptor Instance, if used.
gpsd_adaptor = None
Expand All @@ -81,7 +83,8 @@ def allocate_sdr(check_only = False, task_description = ""):
(str): The device index/serial number of the free/allocated SDR, if one is free, else None.
"""

for _idx in autorx.sdr_list.keys():

for _idx in sorted(autorx.sdr_list.keys()):
if autorx.sdr_list[_idx]['in_use'] == False:
# Found a free SDR!
if check_only:
Expand All @@ -90,7 +93,7 @@ def allocate_sdr(check_only = False, task_description = ""):
else:
# Otherwise, set the SDR as in-use.
autorx.sdr_list[_idx]['in_use'] = True
logging.info("SDR #%s has been allocated to %s." % (str(_idx), task_description))
logging.info("Task Manager - SDR #%s has been allocated to %s." % (str(_idx), task_description))

return _idx

Expand Down Expand Up @@ -323,6 +326,7 @@ def handle_scan_results():

def clean_task_list():
""" Check the task list to see if any tasks have stopped running. If so, release the associated SDR """
global email_exporter

for _key in autorx.task_list.copy().keys():
# Attempt to get the state of the task
Expand All @@ -337,19 +341,29 @@ def clean_task_list():
if _running == False:
# This task has stopped.
# Check the exit state of the task for any abnormalities:
if _exit_state == "Encrypted":
# This task was a decoder, and it has encountered an encrypted sonde.
if (_exit_state == "Encrypted") or (_exit_state == "TempBlock"):
# This task was a decoder, and it has encountered an encrypted sonde, or one too far away.
logging.info("Task Manager - Adding temporary block for frequency %.3f MHz" % (_key/1e6))
# Add the sonde's frequency to the global temporary block-list
temporary_block_list[_key] = time.time()
# If there is a scanner currently running, add it to the scanners internal block list.
if 'SCAN' in autorx.task_list:
autorx.task_list['SCAN']['task'].add_temporary_block(_key)

if (_exit_state == "FAILED SDR"):
# The SDR was not able to be recovered after many attempts.
# Remove it from the SDR list and flag an error.
autorx.sdr_list.pop(_task_sdr)
logging.error("Task Manager - Removed SDR %s from SDR list due to repeated failures." % (str(_task_sdr)))

if email_exporter:
# TODO: Send e-mail notification.
pass

# Release its associated SDR.
autorx.sdr_list[_task_sdr]['in_use'] = False
autorx.sdr_list[_task_sdr]['task'] = None
else:
# Release its associated SDR.
autorx.sdr_list[_task_sdr]['in_use'] = False
autorx.sdr_list[_task_sdr]['task'] = None

# Pop the task from the task list.
autorx.task_list.pop(_key)
Expand Down Expand Up @@ -435,7 +449,16 @@ def telemetry_filter(telemetry):
if _info['straight_distance'] > config['max_radius_km']*1000:
_radius_breach = _info['straight_distance']/1000.0 - config['max_radius_km']
logging.warning("Sonde %s position breached radius cap by %.1f km." % (telemetry['id'], _radius_breach))
return False

if config['radius_temporary_block']:
logging.warning("Blocking for %d minutes." % config['temporary_block_time'])
return "TempBlock"
else:
return False

if (_info['straight_distance'] < config['min_radius_km']*1000) and config['radius_temporary_block']:
logging.warning("Sonde %s within minimum radius limit (%.1f km). Blocking for %d minutes." % (telemetry['id'], config['min_radius_km'], config['temporary_block_time']))
return "TempBlock"

# Payload Serial Number Checks
_serial = telemetry['id']
Expand All @@ -459,8 +482,8 @@ def telemetry_filter(telemetry):
meisei_callsign_valid = False

# If Vaisala or DFMs, check the callsigns are valid. If M10, iMet or LMS6, just pass it through.
if vaisala_callsign_valid or dfm_callsign_valid or meisei_callsign_valid or ('M10' in telemetry['type']) or ('MK2LMS' in telemetry['type']) or ('LMS6' in telemetry['type']) or ('iMet' in telemetry['type']) or ('UDP' in telemetry['type']):
return True
if vaisala_callsign_valid or dfm_callsign_valid or meisei_callsign_valid or ('M10' in telemetry['type']) or ('M20' in telemetry['type']) or ('LMS' in telemetry['type']) or ('IMET' in telemetry['type']):
return "OK"
else:
_id_msg = "Payload ID %s is invalid." % telemetry['id']
# Add in a note about DFM sondes and their oddness...
Expand Down Expand Up @@ -493,7 +516,7 @@ def station_position_update(position):

def main():
""" Main Loop """
global config, exporter_objects, exporter_functions, logging_level, rs92_ephemeris, gpsd_adaptor
global config, exporter_objects, exporter_functions, logging_level, rs92_ephemeris, gpsd_adaptor, email_exporter

# Command line arguments.
parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -604,7 +627,8 @@ def main():
mail_to = config['email_to'],
mail_subject = config['email_subject'],
station_position = (config['station_lat'], config['station_lon'], config['station_alt'])
)
)
email_exporter = _email_notification

exporter_objects.append(_email_notification)
exporter_functions.append(_email_notification.add)
Expand Down Expand Up @@ -732,6 +756,11 @@ def main():
# Sleep a little bit.
time.sleep(2)

if len(autorx.sdr_list) == 0:
# No Functioning SDRs!
logging.critical("Task Manager - No SDRs available! Cannot continue...")
raise IOError("No SDRs available!")

# Allow a timeout after a set time, for users who wish to run auto_rx
# within a cronjob.
if (_timeout > 0) and ((time.time()-_start_time) > _timeout):
Expand Down
2 changes: 1 addition & 1 deletion auto_rx/autorx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# MINOR - New sonde type support, other fairly big changes that may result in telemetry or config file incompatability issus.
# PATCH - Small changes, or minor feature additions.

__version__ = "1.3.1"
__version__ = "1.3.2"


# Global Variables
Expand Down
5 changes: 3 additions & 2 deletions auto_rx/autorx/aprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ def telemetry_to_aprs_position(sonde_data, object_name="<id>", aprs_comment="BOM
# Use the generated id same as dxlAPRS
_object_name = sonde_data['aprsid']

elif 'iMet' in sonde_data['type']:
elif 'IMET' in sonde_data['type']:
# Use the last 5 characters of the unique ID we have generated.
_object_name = "IMET" + sonde_data['id'][-5:]

elif ('MK2LMS' in sonde_data['type']) or ('LMS6' in sonde_data['type']):
elif 'LMS' in sonde_data['type']:
# Use the last 5 hex digits of the sonde ID.
_id_suffix = int(sonde_data['id'].split('-')[1])
_id_hex = hex(_id_suffix).upper()
Expand All @@ -83,6 +83,7 @@ def telemetry_to_aprs_position(sonde_data, object_name="<id>", aprs_comment="BOM
# New Sonde types will be added in here.
else:
# Unknown sonde type, don't know how to handle this yet.
logging.error('No APRS ID conversion available for sonde type: %s' % sonde_data['type'])
return (None, None)
else:
_object_name = object_name
Expand Down
24 changes: 17 additions & 7 deletions auto_rx/autorx/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def read_auto_rx_config(filename, no_sdr_test=False):
# Position Filter Settings
'max_altitude' : 50000,
'max_radius_km' : 1000,
'min_radius_km' : 0,
'radius_temporary_block': False,
# Habitat Settings
'habitat_enabled': False,
'habitat_upload_rate': 30,
Expand Down Expand Up @@ -279,13 +281,14 @@ def read_auto_rx_config(filename, no_sdr_test=False):
auto_rx_config['temporary_block_time'] = config.getint('advanced', 'temporary_block_time')

# New demod tweaks - Added 2019-04-23
# Default to all experimental decoders off.
# Default to all experimental decoders on.
auto_rx_config['experimental_decoders'] = {
'RS41': False,
'RS92': False,
'DFM': False,
'M10': False,
'iMet': False,
'RS41': True,
'RS92': True,
'DFM': True,
'M10': True,
'M20': True,
'IMET': False,
'LMS6': True,
'MK2LMS': False,
'MEISEI': False,
Expand All @@ -309,7 +312,14 @@ def read_auto_rx_config(filename, no_sdr_test=False):
auto_rx_config['web_control'] = False
auto_rx_config['ngp_tweak'] = False
auto_rx_config['gpsd_enabled'] = False


try:
auto_rx_config['min_radius_km'] = config.getint('filtering', 'min_radius_km')
auto_rx_config['radius_temporary_block'] = config.getboolean('filtering', 'radius_temporary_block')
except:
logging.warning("Config - Did not find minimum radius filter setting, using default (0km).")
auto_rx_config['min_radius_km'] = 0
auto_rx_config['radius_temporary_block'] = False

# If we are being called as part of a unit test, just return the config now.
if no_sdr_test:
Expand Down
Loading

0 comments on commit 72cb7de

Please sign in to comment.