Skip to main content

Code Generators

The COSMOS Code Generators are built into the scripts openc3.sh and openc3.bat that are included in the COSMOS project (more about projects).

If you followed the Installation Guide you should already be inside a cloned openc3-project which is in your PATH (necessary for openc3.bat / openc3.sh to be resolved). To see all the available code generators type the following:

% openc3.sh cli generate
Unknown generator ''. Valid generators: plugin, target, microservice, widget, conversion,
limits_response, tool, tool_vue, tool_angular, tool_react, tool_svelte

If any of this gets confusing, contact us at support@openc3.com. We have training classes available!

Plugin Generator

The plugin generator creates the scaffolding for a new COSMOS Plugin. It requires a plugin name and will create a new directory called openc3-cosmos-<name>. For example:

% openc3.sh cli generate plugin
Usage: cli generate plugin <NAME>

% openc3.sh cli generate plugin GSE
Plugin openc3-cosmos-gse successfully generated!

This creates the following files:

NameDescription
.gitignoreTells git to ignore any node_modules directory (for tool development)
LICENSE.txtLicense for the plugin. COSMOS Plugins should be licensed in a manner compatible with the AGPLv3, unless they are designed only for use with COSMOS Enterprise Edition.
openc3-cosmos-gse.gemspecGemspec file which should be edited to add user specific information like description, authors, emails, homepage, etc. The name of this file is used in compiling the plugin contents into the final corresponding gem file: e.g. openc3-cosmos-gse-1.0.0.gem. COSMOS plugins should always begin with the openc3-cosmos prefix to make them easily identifiable in the Rubygems repository. The file is formatted as documented at: https://guides.rubygems.org/specification-reference/
plugin.txtCOSMOS specific file for Plugin creation. Learn more here.
RakefileRuby Rakefile configured to support building the plugin by running "openc3.sh cli rake build VERSION=X.X.X" where X.X.X is the plugin version number
README.mdMarkdown file used to document the plugin

While this structure is required, it is not very useful by itself. The plugin generator just creates the framework for other generators to use.

Target Generator

The target generator creates the scaffolding for a new COSMOS Target. It must operate inside an existing COSMOS plugin and requires a target name. For example:

openc3-cosmos-gse % openc3.sh cli generate target
Usage: cli generate target <NAME> (--ruby or --python)

openc3-cosmos-gse % openc3.sh cli generate target GSE
Target GSE successfully generated!

This creates the following files and directories:

NameDescription
targets/GSEContains the configuration for the GSE target. The target name is always defined in all caps. This is typically the default name of the target, but well-designed targets will allow themselves to be renamed at installation.
targets/GSE/cmd_tlmContains the command and telemetry definition files for the GSE target. These files capture the format of the commands that can be sent to the target, and the telemetry packets that are expected to be received by COSMOS from the target. Note that the files in this folder are processed in alphabetical order by default. That can matter if you reference a packet in another file (it must already have been defined).
targets/GSE/cmd_tlm/cmd.txtExample command configuration. Will need to be edited for the target specific commands.
targets/GSE/cmd_tlm/tlm.txtExample telemetry configuration. Will need to be edited for the target specific telemetry.
targets/GSE/libContains any custom code required by the target. Good examples of custom code are library files, custom interface classes and protocols.
targets/GSE/lib/gse.rbExample library file which can be expanded as the target is developed. COSMOS recommends building up library methods to avoid code duplication and ease reuse.
targets/GSE/proceduresThis folder contains target specific procedures and helper methods which exercise functionality of the target. These procedures should be kept simple and only use the command and telemetry definitions associated with this target. See the Scripting Guide for more information.
targets/GSE/procedures/procedure.rbProcedure with an example of sending a command and checking telemetry
targets/GSE/publicPut image files here for use in Telemetry Viewer Canvas Image widgets such as CANVASIMAGE and CANVASIMAGEVALUE
targets/GSE/screensContains telemetry screens for the target
targets/GSE/screens/status.txtExample screen to display telemetry values
targets/GSE/target.txtTarget configuration such as ignoring command and telemetry items and how to process the cmd/tlm files

It also updates the plugin.txt file to add the new target:

VARIABLE gse_target_name GSE

TARGET GSE <%= gse_target_name %>
INTERFACE <%= gse_target_name %>_INT tcpip_client_interface.rb host.docker.internal 8080 8081 10.0 nil BURST
  MAP_TARGET <%= gse_target_name %>

Microservice Generator

The microservice generator creates the scaffolding for a new COSMOS Microservice. It must operate inside an existing COSMOS plugin and requires a target name. For example:

openc3-cosmos-gse % openc3.sh cli generate microservice
Usage: cli generate microservice <NAME> (--ruby or --python)

openc3-cosmos-gse % openc3.sh cli generate microservice background
Microservice BACKGROUND successfully generated!

This creates the following files and directories:

NameDescription
microservices/BACKGROUNDContains the code and any necessary configuration for the BACKGROUND microservice. The name is always defined in all caps. This is typically the default name of the microservice, but well-designed microservices will allow themselves to be renamed at installation.
microservices/BACKGROUND/background.rbFully functional microservice which will run every minute and log a message. Edit to implement any custom logic that you want to run in the background. Potential uses are safety microservices which can check and autonomously respond to complex events and take action (NOTE: Simple actions might just require a Limits Response).

It also updates the plugin.txt file to add the new microservice:

MICROSERVICE BACKGROUND background-microservice
  CMD ruby background.rb

Conversion Generator

The conversion generator creates the scaffolding for a new COSMOS Conversion. It must operate inside an existing COSMOS plugin and requires both a target name and conversion name. For example:

openc3-cosmos-gse % openc3.sh cli generate conversion
Usage: cli generate conversion <TARGET> <NAME> (--ruby or --python)

openc3-cosmos-gse % openc3.sh cli generate limits_response GSE double
Conversion targets/GSE/lib/double_conversion.rb successfully generated!
To use the conversion add the following to a telemetry item:
  READ_CONVERSION double_conversion.rb

This creates the following files and directories:

NameDescription
targets/GSE/lib/double_conversion.rbFully functional Conversion which has an example implementation of the call() method to convert any existing COSMOS values.

As the generator states, to use this conversion code you must add it to a telemetry item. For example:

TELEMETRY GSE STATUS BIG_ENDIAN "Telemetry description"
  # Keyword      Name  BitSize Type   ID Description
  APPEND_ID_ITEM ID    16      INT    1  "Identifier"
  APPEND_ITEM    VALUE 32      FLOAT     "Value"
    READ_CONVERSION double_conversion.rb
  APPEND_ITEM    BOOL  8       UINT      "Boolean"
    STATE FALSE 0
    STATE TRUE 1
  APPEND_ITEM    LABEL 0       STRING    "The label to apply"

Limits Response Generator

The limits_response generator creates the scaffolding for a new COSMOS Limits Response. It must operate inside an existing COSMOS plugin and requires both a target name and limits response name. For example:

openc3-cosmos-gse % openc3.sh cli generate limits_response
Usage: cli generate limits_response <TARGET> <NAME> (--ruby or --python)

openc3-cosmos-gse % openc3.sh cli generate limits_response GSE safe
Limits response targets/GSE/lib/safe_limits_response.rb successfully generated!
To use the limits response add the following to a telemetry item:
  LIMITS_RESPONSE safe_limits_response.rb

This creates the following files and directories:

NameDescription
targets/GSE/lib/safe_limits_response.rbFully functional Limits Response which has an example implementation of the call() method and taking action based on the current limits state of the particular item

As the generator states, to use this limits code you must add it to a telemetry item which has limits defined. In the generated GSE target, none of the items have limits defined so you first need to add limits and then add the response.

TELEMETRY GSE STATUS BIG_ENDIAN "Telemetry description"
  # Keyword      Name  BitSize Type   ID Description
  APPEND_ID_ITEM ID    16      INT    1  "Identifier"
  APPEND_ITEM    VALUE 32      FLOAT     "Value"
    LIMITS DEFAULT 1 ENABLED -80.0 -70.0 60.0 80.0 -20.0 20.0
    LIMITS_RESPONSE safe_limits_response.rb
  APPEND_ITEM    BOOL  8       UINT      "Boolean"
    STATE FALSE 0
    STATE TRUE 1
  APPEND_ITEM    LABEL 0       STRING    "The label to apply"

Widget Generator

The conversion generator creates the scaffolding for a new COSMOS Widget for use in Telemetry Viewer Screens. For more information see the Custom Widget guide. It must operate inside an existing COSMOS plugin and requires a widget name. For example:

openc3-cosmos-gse % openc3.sh cli generate widget
Usage: cli generate widget <SuperdataWidget>

openc3-cosmos-gse % openc3.sh cli generate widget HelloworldWidget
Widget HelloworldWidget successfully generated!
Please be sure HelloworldWidget does not overlap an existing widget: https://docs.openc3.com/docs/configuration/telemetry-screens

This creates the following files and directories:

NameDescription
src/HelloworldWidget.vueFully functional widget which displays a simple value. This can be expanded using existing COSMOS Vue.js code to create any data visualization imaginable.

It also updates the plugin.txt file to add the new widget:

WIDGET Helloworld

Tool Generator

The tool generator creates the scaffolding for a new COSMOS Tool. It's It must operate inside an existing COSMOS plugin and requires a tool name. Developing a custom tool requires intensive knowledge of a Javascript framework such as Vue.js, Angular, React, or Svelt. Since all the COSMOS tools are built in Vue.js, that is the recommended framework for new tool development. For additional help on frontend development, see Running a Frontend Application.

openc3-cosmos-gse % openc3.sh cli generate tool
Usage: cli generate tool 'Tool Name'

openc3-cosmos-gse % openc3.sh cli generate widget DataVis
Tool datavis successfully generated!
Please be sure datavis does not conflict with any other tools

This creates the following files and directories:

NameDescription
src/App.vueBasic Vue template to render the application.
src/main.jsEntry point for the new tool which loads Vue, Vuetify, and other libraries.
src/router.jsVue component router.
src/tools/datavisContains all the files necessary to serve a web-based tool named datavis. The name is always defined in all lowercase. Due to technical limitations, the toolname must be unique and cannot be renamed at installation.
src/tools/datavis/datavis.vueFully functional tool which displays a simple button. This can be expanded using existing COSMOS Vue.js code to create any tool imaginable.
package.jsonBuild and dependency definition file. Used by npm or yarn to build the tool.
vue.config.jsVue configuration file used to serve the application in development and build the application.
<dotfiles>Various dotfiles which help configure formatters and tools for Javascript frontend developemnt

It also updates the plugin.txt file to add the new tool. The icon can be changed to any of the material design icons found here.

TOOL datavis "DataVis"
  INLINE_URL js/app.js
  ICON mdi-file-cad-box