F´ Flight Software - C/C++ Documentation
devel
A framework for building embedded system applications to NASA flight quality standards.
|
This guide will walk through the process of developing GDS plugins. GDS plugins allow users to add functionality to the GDS in several ways. These include:
This guide will walk through the development of a framing
selection plugin to see the basic development of a plugin. Then the guide will walk you through the development of a start-up application functionality plugin, which will also discuss taking arguments to plugins. Finally the guide will close with a discussion of testing and distributing your plugins.
Examples covered here are available at: https://github.com/fprime-community/fprime-gds-plugin-examples
GDS plugins are built on top of the pluggy. This means that each implementor of a GDS plugin must define a function for behavior and mark that function with an implementation decorator. GDS plugins all define a registration function, which returns an implementation class for the given plugin category.
The GDS defines several categories of plugins that the user may implement. These categories and the plugin type of each category is summarized in the table below.
Category | Type | Description | Implementation Base Class |
---|---|---|---|
framing | Selection | Implement a framer/deframer pair to handle serialized data | FramerDeframer |
communication | Selection | Implement a communication adapter for flight software communication | BaseAdapter |
gds-app | Functionality | Implement a new GDS application isolated to a separate process | GdsApp |
gds-function | Functionality | (Advanced) Implement new GDS functionality with control over the process | GdsFunction |
Plugins should define a function called register_<category>_plugin
that return a concrete subclass of the category's implementation base class from the above table. These concrete classes may additionally define get_arguments
, get_name
, and check_arguments
functions used by the plugin system to provide and validate arguments from the CLI.
This guide will walk through the development of a framing plugin and compare that to a gds-app plugin.
The first step in developing a framing plugin is to determine the function that must be implemented and the class that must be derived to develop the plugin. For the case of a framing
plugin, the register_framing_plugin
function must be defined to return a concrete subclass of FramerDeframer
. This information was found in the above table.
GDS plugins define a class that inherits from the implementation base class and implements all virtual functions. These classes also define a properly decorated class method for the registration function, and may define the other class methods used for CLI interaction.
A basic framing plugin skeleton would thus look like: **src/my_plugin.py
:**
Each plugin implementation base class (e.g. FramerDeframer
) has a set of virtual methods that plugin implementors must implement in order to support the plugin implementation. These functions are marked as @abc.abstractmethod
and can be found in the virtual class definition.
FramerDeframer virtual functions consist of a frame
and deframe
method. Below the frame function adds the bytes MY-PLUGIN
to the start of each frame and strip the same bytes off the start of each frame. This is a trivial example of a start word.
**src/my_plugin.py
:**
This is the basic implementation of a no-argument framing plugin. The above plugin tracks a single start MY-PLUGIN
string and deframes that as a packet. Next, this guide will cover how to integrate this plugin via python packaging. Following that, plugin arguments will be covered.
You may now continue to read about "Application Plugins" that show the other type of plugin available for the fprime-gds
. This section also covers how arguments to plugins work. Otherwise, jump to the Packaging and Testing Plugins section to begin testing your plugin!
Unlike the example framing
plugin, application plugins run in addition to the GDS. These plugins can be used to start new services that connect to the larger GDS network. Application plugins will be used to show how to solicit arguments from the command line.
Our plugin ill run python to print a message supplied via arguments. This is the equivalent to running the following command line:
Here is the basic structure for a gds-app
plugin. It prints "Hello World". gds-app plugins must implement the function get_process_invocation
that returns command line arguments to be run as a separate process using the subprocess
module.
**src/my_app.py
:**
Plugins can source arguments from the command line. Although, all types of plugins can source arguments using the pattern described here, you will see them shown with our application plugin.
It is time to add in plugin arguments. This plugin will take one argument --message
and will inject this message into the printed message. To do this we return the argument using the get_arguments
class method. Add this to your plugin MyApp
class:
get_arguments
is a class method that returns a dictionary whose keys are tuples containing the flags, and whose value is a dictionary of keyword arguments passed to argparse.add_argument
.
Arguments are supplied to the plugin at instantiation via keyword arguments. Add the following to your MyApp
class.
Change the get_process_invocation
to use the new member variable.
Finally, security-minded developers will notice there is an injection vulnerability above. This can be check using the check_arguments
class method. This method should raise a ValueError
or TypeError
when an argument value is malformed. Add this function to MyApp
fix the injection:
Now our plugin may be run. The GDS will automatically solicit the message argument as seen should the user run
The complete plugin would look like:
**src/my_app.py
:**
Plugins are supplied as python packages with an entrypoint used to load the plugin. In the root of the package a basic python package will need to be configured. This consists of two files: pyproject.toml representing the package, and setup.py for backwards compatibility.
The project structure should look like:
A sample pyproject.toml file would look like:
A sample setup.py
would look like:
We can add our application plugin with the following additional line in the project.entry-points.fprime_gds
section:
Once these files have been written, the plugin can be installed locally for testing with the following command:
Users must be in the same virtual environment that the
fprime-gds
package has been installed into-e
allows local changes to take effect without a reinstall
The first step in testing a plugin is to run fprime-gds --help
. This should show arguments associated with your plugin. The plugins implemented here would produce the following output:
Syntax errors, indentation errors, and other exceptions can arise during this step. Resolving these errors will allow the help message to display properly.
To test selection plugins, select them during a normal GDS run:
Remember to supply any arguments needed for your plugin!
Application plugins run automatically at start-up. To test these plugins, just supply any desired arguments:
Plugins are implemented as python packages. Thus plugins may be distributed in the following ways:
pip install .
as shown abovepip install /path/to/wheel
A tutorial on python packaging including building wheels and uploading them to PyPI is available from packaging.python.org: https://packaging.python.org/en/latest/tutorials/packaging-projects/
This guide has covered how to develop GDS plugins, their design, and selection vs functionality plugins. You should now be capable of writing plugins and handling arguments.