Skip to content

Commit 6b41562

Browse files
committed
feat(compare and upload): After upload, refresh FC parameter values in parameter tables
1 parent 1231f9e commit 6b41562

3 files changed

Lines changed: 58 additions & 5 deletions

File tree

ARCHITECTURE_parameter_upload.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ configuration step, write to the selected file, or ask whether temporary edits s
5656
Upload checkbox is not selected. Close the modal after a successful upload without advancing the
5757
AMC configuration step.
5858

59+
7. **Post-upload synchronization**:
60+
- After a successful upload and verification download, update the FC-value snapshot in each
61+
external `ArduPilotParameter` object from the refreshed `fc_parameters` cache.
62+
- Refresh the underlying parameter table whenever the compare-and-upload window closes so it
63+
reflects the latest FC parameter values.
64+
5965
### Non-Functional Requirements
6066

6167
- Avoid duplicating parameter table rendering and upload orchestration.
@@ -120,6 +126,8 @@ filesystem state.
120126
- Apply the changed-only filter.
121127
- Obtain the checked upload payload from the table.
122128
- Run upload precondition checks and delegate to the parent upload workflow.
129+
- Synchronize external FC-value snapshots after successful upload verification.
130+
- Refresh the parent parameter table when the modal closes.
123131
- Close without invoking project navigation or save operations.
124132

125133
The modal upload button does not duplicate the entry-point connection-state gate. The upload
@@ -218,8 +226,9 @@ Each external parameter has four relevant pieces of state:
218226
| Manual selection | `ParameterTableOptions.manually_editable_parameters` | Modal lifetime | No |
219227

220228
The FC value and parameter metadata in each external parameter object are snapshots supplied when
221-
the object is created. The shared upload workflow refreshes its FC parameter cache for verification;
222-
it does not convert the modal's original comparison values into project state.
229+
the object is created. After a successful external upload and verification download, the modal
230+
updates those FC-value snapshots from the refreshed cache before closing. Closing the modal also
231+
repopulates the underlying parameter table so it displays the latest FC values.
223232

224233
## Detailed Workflows
225234

@@ -269,8 +278,10 @@ forced and derived parameters in AMC-managed configuration steps.
269278
6. Reset-required parameters, reconnection, remaining uploads, re-download, and validation follow
270279
the normal parameter editor rules.
271280
7. The user reviews the differences and may edit values temporarily before pressing `Upload selected params to the FC`.
272-
8. On success the modal closes.
273-
9. The current AMC configuration step is not saved, skipped, or advanced; no tuning report or
281+
8. On success the modal updates the external parameters' FC-value snapshots from the verified
282+
download and closes.
283+
9. Closing the modal repopulates the underlying AMC parameter table with the latest FC values.
284+
10. The current AMC configuration step is not saved, skipped, or advanced; no tuning report or
274285
FC-difference export is written.
275286

276287
## Data Integrity Invariants
@@ -326,6 +337,8 @@ The following invariants define the boundary between external upload and project
326337
- Verify external-only names do not access `current_step_parameters`.
327338
- Verify only Upload-checked parameters enter the payload.
328339
- Verify the modal delegates to the shared upload workflow and never advances the project.
340+
- Verify successful uploads update external FC-value snapshots from the verified download.
341+
- Verify closing the modal refreshes the underlying parameter table.
329342
- Verify a failed model upload leaves the modal open.
330343
- Verify Manual toggles update only the affected row rather than rebuilding the static table.
331344
- Verify file-selection and parse-error orchestration.

ardupilot_methodic_configurator/frontend_tkinter_parameter_compare_and_upload.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,16 @@ def upload_parameters(self) -> None:
143143
if not self.parent.parameter_editor.ensure_upload_preconditions(dict(selected_params), self.parent.ui.show_warning):
144144
return
145145
if self.parent.upload_external_params(selected_params):
146+
self._update_fc_values_from_parent()
146147
self.close()
147148

149+
def _update_fc_values_from_parent(self) -> None:
150+
"""Update the external parameter snapshot after a verified FC upload."""
151+
fc_parameters = self.parent.parameter_editor.fc_parameters
152+
for param_name, parameter in self.parameters.items():
153+
if param_name in fc_parameters:
154+
parameter.set_fc_value(fc_parameters[param_name])
155+
148156
def reset_all_parameters_to_default(self) -> None:
149157
"""Confirm and reset all flight-controller parameters to their factory defaults."""
150158
if (
@@ -160,7 +168,8 @@ def reset_all_parameters_to_default(self) -> None:
160168
self.close()
161169

162170
def close(self) -> None:
163-
"""Close the modal window."""
171+
"""Close the modal window and refresh the underlying parameter table."""
164172
if sys_platform != "darwin":
165173
self.root.grab_release()
166174
self.root.destroy()
175+
self.parent.repopulate_parameter_table()

tests/test_frontend_tkinter_parameter_compare_and_upload.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from unittest.mock import MagicMock, call, patch
1616

17+
from ardupilot_methodic_configurator.data_model_ardupilot_parameter import ArduPilotParameter
1718
from ardupilot_methodic_configurator.data_model_par_dict import Par, ParDict
1819
from ardupilot_methodic_configurator.frontend_tkinter_parameter_compare_and_upload import ParameterFileUploadWindow
1920
from ardupilot_methodic_configurator.frontend_tkinter_parameter_editor import ParameterEditorWindow
@@ -384,6 +385,36 @@ def test_upload_uses_external_parameters_without_advancing_project() -> None:
384385
window.parent.on_skip_click.assert_not_called()
385386

386387

388+
def test_successful_external_upload_updates_fc_values_before_closing() -> None:
389+
"""Refresh a real external parameter's FC-value snapshot after upload verification."""
390+
window = _window_without_tk()
391+
parameter = ArduPilotParameter("ROLL_P", Par(0.2), fc_value=0.1)
392+
window.parameters = {"ROLL_P": parameter}
393+
window.parent.parameter_editor.fc_parameters = {"ROLL_P": 0.2}
394+
selected_params = ParDict({"ROLL_P": Par(0.2)})
395+
window.table.get_upload_selected_params.return_value = selected_params
396+
window.parent.parameter_editor.ensure_upload_preconditions.return_value = True
397+
window.parent.upload_external_params.return_value = True
398+
window.close = MagicMock()
399+
400+
window.upload_parameters()
401+
402+
assert parameter.fc_value_as_string == "0.2"
403+
assert not parameter.is_different_from_fc
404+
window.close.assert_called_once_with()
405+
406+
407+
def test_closing_external_upload_window_refreshes_parent_table() -> None:
408+
"""Refresh the normal parameter table after the modal is closed."""
409+
window = _window_without_tk()
410+
window.root = MagicMock()
411+
412+
window.close()
413+
414+
window.root.destroy.assert_called_once_with()
415+
window.parent.repopulate_parameter_table.assert_called_once_with()
416+
417+
387418
def test_failed_external_upload_keeps_modal_open() -> None:
388419
"""
389420
Keep the external modal open after a failed upload.

0 commit comments

Comments
 (0)