Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Eshco93 authored Apr 22, 2023
1 parent 0ca76fd commit 7cb98f0
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 19 deletions.
3 changes: 3 additions & 0 deletions SondeHubUploader/SondeHubUploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def __init__(self, args):
self.last_station_upload = 0
# Stores the last time telemetry was uploaded
self.last_telemetry_upload = 0

# Disable upload for all radiosondes that were not enabled
self.utils.disable_radiosondes(self, self.sonde)

# Create a thread for receiving packages
self.receive_thread = threading.Thread(target=self.threads.receive, args=(self,))
Expand Down
1 change: 1 addition & 0 deletions SondeHubUploader/handleData.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ def reformat_telemetry(self, unified_telemetry):
# ref_datetime and ref_position can be transferred directly
reformatted_telemetry['ref_datetime'] = self.shuConfig.radiosonde[name]['sondehub_time_reference']
reformatted_telemetry['ref_position'] = self.shuConfig.radiosonde[name]['sondehub_position_reference']
# Break out of for-loop after the first match because only a single match is expected
break

# Thirdly, mandatory non-radiosonde-specific reformatted telemetry parameters are added
Expand Down
26 changes: 17 additions & 9 deletions SondeHubUploader/shuConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

# Software definitions
software_name = 'dxlAPRS-SHUE'
software_version = '1.1.0'
software_version = '1.1.1'

# Status code definitions
status_code_ok = 200
Expand Down Expand Up @@ -946,7 +946,8 @@
'altitude_precision': 5,
'radiosonde_time_reference': 'GPS',
'sondehub_time_reference': 'GPS',
'sondehub_position_reference': 'GPS'
'sondehub_position_reference': 'GPS',
'enabled': True
},
'RS92':
{
Expand All @@ -958,7 +959,8 @@
'altitude_precision': 5,
'radiosonde_time_reference': 'GPS',
'sondehub_time_reference': 'GPS',
'sondehub_position_reference': 'GPS'
'sondehub_position_reference': 'GPS',
'enabled': True
},
'DFM':
{
Expand All @@ -970,7 +972,8 @@
'altitude_precision': 2,
'radiosonde_time_reference': 'UTC',
'sondehub_time_reference': 'UTC',
'sondehub_position_reference': 'GPS'
'sondehub_position_reference': 'GPS',
'enabled': True
},
'iMET':
{
Expand All @@ -982,7 +985,8 @@
'altitude_precision': 0,
'radiosonde_time_reference': 'GPS',
'sondehub_time_reference': 'GPS',
'sondehub_position_reference': 'MSI'
'sondehub_position_reference': 'MSI',
'enabled': True
},
'M10':
{
Expand All @@ -994,7 +998,8 @@
'altitude_precision': 2,
'radiosonde_time_reference': 'GPS',
'sondehub_time_reference': 'UTC',
'sondehub_position_reference': 'GPS'
'sondehub_position_reference': 'GPS',
'enabled': True
},
'M20':
{
Expand All @@ -1006,7 +1011,8 @@
'altitude_precision': 2,
'radiosonde_time_reference': 'GPS',
'sondehub_time_reference': 'GPS',
'sondehub_position_reference': 'GPS'
'sondehub_position_reference': 'GPS',
'enabled': True
},
'MRZ':
{
Expand All @@ -1018,7 +1024,8 @@
'altitude_precision': 5,
'radiosonde_time_reference': 'UTC',
'sondehub_time_reference': 'UTC',
'sondehub_position_reference': 'GPS'
'sondehub_position_reference': 'GPS',
'enabled': True
},
'MEISEI':
{
Expand All @@ -1030,6 +1037,7 @@
'altitude_precision': 1,
'radiosonde_time_reference': 'UTC',
'sondehub_time_reference': 'UTC',
'sondehub_position_reference': 'GPS'
'sondehub_position_reference': 'GPS',
'enabled': True
}
}
11 changes: 9 additions & 2 deletions SondeHubUploader/telemetryChecks.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,15 @@ def check_time_plausibility(time, difference_seconds):
lower_threshold = (datetime.datetime.utcnow() - datetime.timedelta(seconds=difference_seconds)).time()
upper_threshold = (datetime.datetime.utcnow() + datetime.timedelta(seconds=difference_seconds)).time()

if lower_threshold <= time <= upper_threshold:
return True
# Check whether a rollover exists within the range
if lower_threshold < upper_threshold:
# When no rollover exists, the time must be within the range
if lower_threshold <= time <= upper_threshold:
return True
else:
# If a rollover exists, the time must be greater than the lower threshold or smaller than the upper threshold
if time > lower_threshold or time < upper_threshold:
return True
return False


Expand Down
25 changes: 18 additions & 7 deletions SondeHubUploader/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def process_input_queue(self):
if self.writeo:
self.writeData.write_raw_data(self, package)
# Mode is set to JSON or package was determined to be JSON
if (self.mode == 0 or self.mode == 1) and self.utils.check_json(self, package):
if (self.mode == 0 or self.mode == 1) and self.utils.check_json(package):
# Package is valid JSON
valid = True
self.loggerObj.debug('Package is JSON')
Expand Down Expand Up @@ -90,12 +90,23 @@ def process_input_queue(self):
# Optionally write the reformatted telemetry
if self.writer:
self.writeData.write_reformatted_telemetry(self, reformatted_telemetry)
# Store the reformatted telemetry to the upload queue
try:
self.upload_queue.put(reformatted_telemetry, False)
self.loggerObj.debug('Reformatted telemetry put in queue (Serial: %s)', reformatted_telemetry['serial'])
except queue.Full:
self.loggerObj.warning('Upload queue full')
# Go through all possible radiosonde types
for name in self.shuConfig.radiosonde:
# The radiosonde type is compared
if unified_telemetry['type'].startswith(name):
# Check whether uploading for this radiosonde is enabled
if self.shuConfig.radiosonde[name]['enabled']:
self.loggerObj.debug('Uploading for radiosonde type %s is enabled', name)
# Store the reformatted telemetry to the upload queue
try:
self.upload_queue.put(reformatted_telemetry, False)
self.loggerObj.debug('Reformatted telemetry put in queue (Serial: %s)', reformatted_telemetry['serial'])
except queue.Full:
self.loggerObj.warning('Upload queue full')
else:
self.loggerObj.warning('Uploading for radiosonde type %s is disabled', name)
# Break out of for-loop after the first match because only a single match is expected
break
else:
self.loggerObj.error('Mandatory data check failed (Serial: %s)', unified_telemetry['serial'] if 'serial' in unified_telemetry else 'N/A')

Expand Down
13 changes: 12 additions & 1 deletion SondeHubUploader/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,19 @@
import hashlib


# Disable upload for all radiosondes that were not enabled
def disable_radiosondes(self, enabled_radiosondes):
# Go through all possible radiosonde types
for name in self.shuConfig.radiosonde:
# Check whether the name of the radiosonde is within the list of enabled radiosondes
if name not in enabled_radiosondes.split(','):
# Disable uploading for a radiosonde that is not within the list of enabled radiosondes
self.shuConfig.radiosonde[name]['enabled'] = False
return False


# Check whether data is valid JSON data
def check_json(self, data):
def check_json(data):
# Checking whether JSON data is valid is relatively easy by just trying to decode it
try:
json.loads(data.decode())
Expand Down

0 comments on commit 7cb98f0

Please sign in to comment.