Skip to content

Commit

Permalink
added download files and fixed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
afwilkin committed Nov 25, 2023
1 parent 250e003 commit e51759b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 63 deletions.
2 changes: 0 additions & 2 deletions app/plot_app/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ <h1>
<div class="dropdown-menu">
<a class="dropdown-item" href="download?log={{ log_id }}">Log File</a>
<a class="dropdown-item" href="download?log={{ log_id }}&type=1" target="_blank">Parameters</a>
<a class="dropdown-item" href="download?log={{ log_id }}&type=4" target="_blank">Parameters (QGC)</a>
<a class="dropdown-item" href="download?log={{ log_id }}&type=3" target="_blank">Parameters (non-default)</a>
<a class="dropdown-item" href="download?log={{ log_id }}&type=5" target="_blank">Parameters (non-default - QGC)</a>
{% if has_position_data %}
<a class="dropdown-item" href="download?log={{ log_id }}&type=2" target="_blank">KML Track</a>
{% endif %}
Expand Down
81 changes: 20 additions & 61 deletions app/tornado_handlers/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,28 @@ def get_original_filename(default_value, new_file_suffix):
ulog = load_ulog_file(log_file_name)
param_keys = sorted(ulog.initial_parameters.keys())

self.set_header("Content-Type", "text/plain")
self.set_header('Content-Disposition', 'inline; filename=params.txt')
self.set_header('Content-Type', 'application/octet-stream')
self.set_header("Content-Description", "File Transfer")
self.set_header('Content-Disposition', 'attachment; filename=vehicle.params')

delimiter = ', '
delimiter = ' '
for param_key in param_keys:
self.write("1") #sysid
self.write(delimiter)
self.write("1") #compid
self.write(delimiter)
self.write(param_key)
self.write(delimiter)
self.write(str(ulog.initial_parameters[param_key]))

#if the value is an int write a 6, if not write a 9
if(type(ulog.initial_parameters[param_key]) == int):
self.write(delimiter)
self.write("6")
else:
self.write(delimiter)
self.write("9")

self.write('\n')

elif download_type == '2': # download the kml file
Expand Down Expand Up @@ -129,64 +143,9 @@ def kml_colors(flight_mode):
ulog = load_ulog_file(log_file_name)
param_keys = sorted(ulog.initial_parameters.keys())

self.set_header("Content-Type", "text/plain")
self.set_header('Content-Disposition', 'inline; filename=params.txt')
delimiter = ', '

# Use defaults from log if available
if ulog.has_default_parameters:
system_defaults = ulog.get_default_parameters(0)
airframe_defaults = ulog.get_default_parameters(1)
for param_key in param_keys:
try:
param_value = ulog.initial_parameters[param_key]
is_default = True
if param_key in airframe_defaults:
is_default = param_value == airframe_defaults[param_key]
elif param_key in system_defaults:
is_default = param_value == system_defaults[param_key]

if not is_default:
self.write(param_key)
self.write(delimiter)
self.write(str(param_value))
self.write('\n')
except:
pass

elif download_type == '4': # download QGC parameters
ulog = load_ulog_file(log_file_name)
param_keys = sorted(ulog.initial_parameters.keys())

self.set_header("Content-Type", "text/plain")
self.set_header('Content-Disposition', 'inline; filename=vehicle.params')

delimiter = ' '
for param_key in param_keys:
self.write("1")
self.write(delimiter)
self.write("1")
self.write(delimiter)
self.write(param_key)
self.write(delimiter)
self.write(str(ulog.initial_parameters[param_key]))

#if the value is an int write a 6, if not write a 9
if(type(ulog.initial_parameters[param_key]) == int):
self.write(delimiter)
self.write("6")
else:
self.write(delimiter)
self.write("9")

self.write('\n')

elif download_type == '5': # download non-default parameters for QGC
ulog = load_ulog_file(log_file_name)
param_keys = sorted(ulog.initial_parameters.keys())

self.set_header("Content-Type", "text/plain")
self.set_header('Content-Disposition', 'inline; filename=vehicle-nondefault.params')
self.set_header('Content-Type', 'application/octet-stream')
self.set_header("Content-Description", "File Transfer")
self.set_header('Content-Disposition', 'attachment; filename=non-default.params')
delimiter = ' '

# Use defaults from log if available
Expand Down

0 comments on commit e51759b

Please sign in to comment.