Add notes module - #1717
Merged
Merged
Conversation
There was no way to take a single item back out of a submenu once added. MPMenuSubMenu.remove() only works on the submenu you already hold, and nothing walks a menu path to reach it, so a module that adds an item with console menu add had no way to tidy up after itself on unload. Add remove_from_submenu() alongside add_to_submenu() on both MPMenuTop and MPMenuSubMenu, and a console menu remove command using it. Separators have no name, so the item match reads the attribute defensively.
Lets an operator flying with --aircraft keep notes about a flight, stored beside the logs at AIRCRAFTNAME/logs/DATE/notes.txt. There is one file per aircraft per day, so a day of several flights, or one flown with --mission, shares the one file. A Notes item is added to the console's MAVProxy menu, which opens a window with a collapsible section per date, latest first. The current date is expanded and editable and saves as you type; earlier dates that have notes can be expanded and read but not edited, and are only read from disk when first opened. An Insert time button, and ctrl-T, stamp the time at the cursor for an in flight entry. The path is built from aircraft_dir rather than by walking up from logdir, as logdir is the flight subdirectory and sits one level deeper again with --mission. Only real dates earlier than today are offered as history. Saving is done in the GUI child process, which is the only place holding the text. A write goes to a temporary file of our own and is then renamed, with the directory synced, so a crash cannot truncate the notes and two MAVProxy instances cannot write through the same temporary file. An empty file is never created, as that would make the date look like one that has notes. Content we did not write is copied to notes.txt.bak before being replaced. That covers the file changing under us, appearing while the window is open, and being unreadable or not valid UTF-8, in which case the bytes are kept as they are. A copy that cannot be made fails the save rather than going ahead without it. Note that two MAVProxy instances saving the same notes in the same instant can still race, as the check and the rename are not one operation. A failed write is reported in the window and retried. If it is still failing as the window closes, the first close is refused with the reason shown, and closing again writes the notes beside the file, or into the .mavproxy directory, or prints them, under a name of this process so a rescue copy never lands on another. The menu item is added from idle_task, as the console may be loaded and unloaded at any time, and goes in with add_to_submenu: adding a submenu of the same name would replace the existing MAVProxy menu items. The command is removed on unload, as MAVProxy leaves commands registered otherwise. Each side closes the pipe end it does not use, so the window notices MAVProxy going away and shuts down saving as it goes. Closing waits for the window to finish writing rather than killing it while it may still hold unsaved notes.
Flight notes are stored per aircraft and per date, so the module has nowhere to put them without --aircraft, and they are state, so are not wanted with --no-state. Load it just after aircraft_dir is worked out, which is also after the console has loaded so the Notes menu item appears straight away.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This allow you to collect notes in flight ready for next flight. Added as I wanted to keep notes together with logs and be able to quickly refer to past flight notes while flyin

Appears in MAVProxy menu when --aircraft is used