Skip to content

Commit

Permalink
IMPROVEMENT: More upload/download renaming
Browse files Browse the repository at this point in the history
Improve the title
  • Loading branch information
amilcarlucas committed May 14, 2024
1 parent 616e4fe commit 12946d3
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 64 deletions.
2 changes: 1 addition & 1 deletion MethodicConfigurator/ardupilot_methodic_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def argument_parser():
'its current value on the flight controller, its new value from the selected '
'intermediate parameter file, and an "Upload" checkbox. The GUI includes "Upload '
'selected params to FC" and "Skip" buttons at the bottom. '
'When "Upload Selected to FC" is clicked, it writes the selected parameters to the '
'When "Upload Selected to FC" is clicked, it uploads the selected parameters to the '
'flight controller. '
'When "Skip" is pressed, it skips to the next intermediate parameter file. '
'The process gets repeated for each intermediate parameter file.')
Expand Down
40 changes: 20 additions & 20 deletions MethodicConfigurator/backend_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def zip_files(self, files_to_zip: List[Tuple[bool, str]]):

# Check for and add specific files if they exist
specific_files = ["00_default.param", "apm.pdef.xml", self.configuration_steps_filename,
"vehicle_components.json", "vehicle.jpg", "last_written_filename.txt",
"vehicle_components.json", "vehicle.jpg", "last_uploaded_filename.txt",
"tempcal_gyro.png", "tempcal_acc.png"]
for file_name in specific_files:
file_path = os_path.join(self.vehicle_dir, file_name)
Expand Down Expand Up @@ -555,19 +555,19 @@ def get_recently_used_dirs():

return template_dir, new_base_dir, vehicle_dir

def write_last_written_filename(self, current_file: str):
def write_last_uploaded_filename(self, current_file: str):
try:
with open(os_path.join(self.vehicle_dir, 'last_written_filename.txt'), 'w', encoding='utf-8') as file:
with open(os_path.join(self.vehicle_dir, 'last_uploaded_filename.txt'), 'w', encoding='utf-8') as file:
file.write(current_file)
except Exception as e: # pylint: disable=broad-except
logging_error("Error writing last written filename: %s", e)
logging_error("Error writing last uploaded filename: %s", e)

def __read_last_written_filename(self) -> str:
def __read_last_uploaded_filename(self) -> str:
try:
with open(os_path.join(self.vehicle_dir, 'last_written_filename.txt'), 'r', encoding='utf-8') as file:
with open(os_path.join(self.vehicle_dir, 'last_uploaded_filename.txt'), 'r', encoding='utf-8') as file:
return file.read().strip()
except Exception as e: # pylint: disable=broad-except
logging_error("Error reading last written filename: %s", e)
logging_error("Error reading last uploaded filename: %s", e)
return ""

def get_start_file(self, explicit_index: int):
Expand All @@ -586,25 +586,25 @@ def get_start_file(self, explicit_index: int):
explicit_index, files[start_file_index])
return files[start_file_index]

last_written_filename = self.__read_last_written_filename()
if last_written_filename:
logging_info("Last written file was %s.", last_written_filename)
last_uploaded_filename = self.__read_last_uploaded_filename()
if last_uploaded_filename:
logging_info("Last uploaded file was %s.", last_uploaded_filename)
else:
logging_info("No last written file found. Starting with the first file.")
logging_info("No last uploaded file found. Starting with the first file.")
return files[0]

if last_written_filename not in files:
# Handle the case where last_written_filename is not found in the list
logging_warning("Last written file not found in the list of files. Starting with the first file.")
if last_uploaded_filename not in files:
# Handle the case where last_uploaded_filename is not found in the list
logging_warning("Last uploaded file not found in the list of files. Starting with the first file.")
return files[0]

# Find the index of last_written_filename in files
last_written_index = files.index(last_written_filename)
# Check if there is a file following last_written_filename
start_file_index = last_written_index + 1
# Find the index of last_uploaded_filename in files
last_uploaded_index = files.index(last_uploaded_filename)
# Check if there is a file following last_uploaded_filename
start_file_index = last_uploaded_index + 1
if start_file_index >= len(files):
# Handle the case where last_written_filename is the last file in the list
logging_warning("Last written file is the last file in the list. Starting from there.")
# Handle the case where last_uploaded_filename is the last file in the list
logging_warning("Last uploaded file is the last file in the list. Starting from there.")
start_file_index = len(files) - 1
return files[start_file_index]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def fc_autoconnect(self):
self.connection_selection_widgets.reconnect()

def skip_fc_connection(self, flight_controller: FlightController):
logging_warning("Will proceed without FC connection. FC parameters will not be read nor written")
logging_warning("Will proceed without FC connection. FC parameters will not be downloaded nor uploaded")
logging_warning("Only the intermediate '.param' files on the PC disk will be edited")
flight_controller.disconnect()
self.root.destroy()
Expand Down
6 changes: 4 additions & 2 deletions MethodicConfigurator/frontend_tkinter_directory_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def __init__(self, parent, parent_frame, initialdir: str, label_text: str, # py
command=self.on_select_directory, width=2)
directory_selection_button.pack(side=tk.RIGHT, anchor=tk.NW)
show_tooltip(directory_selection_button, button_tooltip)
else:
self.directory_entry.xview_moveto(1.0)

def on_select_directory(self):
# Open the directory selection dialog
Expand Down Expand Up @@ -138,9 +140,9 @@ def __init__(self, parent: tk, parent_frame: tk.Frame, # pylint: disable=too-ma
super().__init__(parent, parent_frame, initial_dir, "Vehicle directory:",
False,
"Vehicle-specific directory containing the intermediate\n"
"parameter files to be written to the flight controller",
"parameter files to be uploaded to the flight controller",
"Select the vehicle-specific directory containing the\n"
"intermediate parameter files to be written to the flight controller" \
"intermediate parameter files to be uploaded to the flight controller" \
if destroy_parent_on_open else '')
self.local_filesystem = local_filesystem
self.destroy_parent_on_open = destroy_parent_on_open
Expand Down
53 changes: 27 additions & 26 deletions MethodicConfigurator/frontend_tkinter_parameter_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ def __init__(self, current_file: str, flight_controller: FlightController,
self.param_download_progress_window = None
self.tempcal_imu_progress_window = None

self.root.title("Amilcar Lucas's - ArduPilot methodic configurator - " + version + " - Parameter editor")
self.root.geometry("880x500") # Set the window width
self.root.title("Amilcar Lucas's - ArduPilot methodic configurator - " + version + \
" - Parameter file editor and uploader")
self.root.geometry("900x500") # Set the window width

# Bind the close_connection_and_quit function to the window close event
self.root.protocol("WM_DELETE_WINDOW", self.close_connection_and_quit)
Expand Down Expand Up @@ -226,7 +227,7 @@ def __create_conf_widgets(self, version: str):
self.current_file,
"Select the intermediate parameter file from the list of available "
"files in the selected vehicle directory\nIt will automatically "
"advance to the next file once the current file is written to the "
"advance to the next file once the current file is uploaded to the "
"fight controller",
state='readonly', width=45)
self.file_selection_combobox.bind("<<ComboboxSelected>>", self.on_param_file_combobox_change)
Expand Down Expand Up @@ -264,7 +265,7 @@ def __create_parameter_area_widgets(self):
variable=self.show_only_differences,
command=self.on_show_only_changed_checkbox_change)
only_changed_checkbox.pack(side=tk.TOP, anchor=tk.NW)
show_tooltip(only_changed_checkbox, "Toggle to show only parameters that will change if/when written to the flight "
show_tooltip(only_changed_checkbox, "Toggle to show only parameters that will change if/when uploaded to the flight "
"controller")

annotate_params_checkbox = ttk.Checkbutton(checkboxes_frame, text="Annotate docs into .param files",
Expand All @@ -275,11 +276,11 @@ def __create_parameter_area_widgets(self):
"parameter files\n"
"The files will be bigger, but all the existing parameter documentation will be included inside")

# Create write button
write_selected_button = tk.Button(buttons_frame, text="Upload selected params to FC, and advance to next param file",
command=self.on_upload_selected_click)
write_selected_button.pack(side=tk.LEFT, padx=(8, 8)) # Add padding on both sides of the write selected button
show_tooltip(write_selected_button, "Upload selected parameters to the flight controller and advance to the next "
# Create upload button
upload_selected_button = tk.Button(buttons_frame, text="Upload selected params to FC, and advance to next param file",
command=self.on_upload_selected_click)
upload_selected_button.pack(side=tk.LEFT, padx=(8, 8)) # Add padding on both sides of the upload selected button
show_tooltip(upload_selected_button, "Upload selected parameters to the flight controller and advance to the next "
"intermediate parameter file\nIf changes have been made to the current file it will ask if you want "
"to save them\nIt will reset the FC if necessary, re-download all parameters and validate their value")

Expand Down Expand Up @@ -439,20 +440,20 @@ def on_upload_selected_click(self):
self.parameter_editor_table.generate_edit_widgets_focus_out()

self.write_changes_to_intermediate_parameter_file()
selected_params = self.parameter_editor_table.get_write_selected_params(self.current_file)
selected_params = self.parameter_editor_table.get_upload_selected_params(self.current_file)
if selected_params:
if hasattr(self.flight_controller, 'fc_parameters') and self.flight_controller.fc_parameters:
self.upload_selected_params(selected_params)
else:
logging_warning("No parameters were yet read from the flight controller, will not write any parameter")
messagebox.showwarning("Will not write any parameter", "No flight controller connection")
logging_warning("No parameters were yet downloaded from the flight controller, will not upload any parameter")
messagebox.showwarning("Will not upload any parameter", "No flight controller connection")
else:
logging_warning("No parameter was selected for write, will not write any parameter")
messagebox.showwarning("Will not write any parameter", "No parameter was selected for write")
logging_warning("No parameter was selected for upload, will not upload any parameter")
messagebox.showwarning("Will not upload any parameter", "No parameter was selected for upload")
# Delete the parameter table and create a new one with the next file if available
self.on_skip_click(force_focus_out_event=False)

# This function can recurse multiple times if there is a write error
# This function can recurse multiple times if there is an upload error
def upload_selected_params(self, selected_params):
logging_info("Uploading %d selected %s parameters to flight controller...", len(selected_params), self.current_file)

Expand All @@ -476,27 +477,27 @@ def upload_selected_params(self, selected_params):
logging_info("Re-download all parameters from the flight controller")

# Validate that the read parameters are the same as the ones in the current_file
param_write_error = []
param_upload_error = []
for param_name, param in selected_params.items():
if param_name in self.flight_controller.fc_parameters and \
param is not None and \
not is_within_tolerance(self.flight_controller.fc_parameters[param_name], float(param.value)):
logging_error("Parameter %s write to the flight controller failed. Expected: %f, Actual: %f",
logging_error("Parameter %s upload to the flight controller failed. Expected: %f, Actual: %f",
param_name, param.value, self.flight_controller.fc_parameters[param_name])
param_write_error.append(param_name)
param_upload_error.append(param_name)
if param_name not in self.flight_controller.fc_parameters:
logging_error("Parameter %s write to the flight controller failed. Expected: %f, Actual: N/A",
logging_error("Parameter %s upload to the flight controller failed. Expected: %f, Actual: N/A",
param_name, param.value)
param_write_error.append(param_name)
param_upload_error.append(param_name)

if param_write_error:
if messagebox.askretrycancel("Parameter write error",
"Failed to write the following parameters to the flight controller:\n"
f"{(', ').join(param_write_error)}"):
if param_upload_error:
if messagebox.askretrycancel("Parameter upload error",
"Failed to upload the following parameters to the flight controller:\n"
f"{(', ').join(param_upload_error)}"):
self.upload_selected_params(selected_params)
else:
logging_info("All parameters written to the flight controller successfully")
self.local_filesystem.write_last_written_filename(self.current_file)
logging_info("All parameters uploaded to the flight controller successfully")
self.local_filesystem.write_last_uploaded_filename(self.current_file)

def on_skip_click(self, _event=None, force_focus_out_event=True):
if force_focus_out_event:
Expand Down
Loading

0 comments on commit 12946d3

Please sign in to comment.