docs/assets/js/a9987364.841623dc.js
"use strict";(self.webpackChunkdocs_openc3_com=self.webpackChunkdocs_openc3_com||[]).push([[6830],{2653:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>s,default:()=>h,frontMatter:()=>o,metadata:()=>r,toc:()=>c});var i=n(4848),a=n(8453);const o={sidebar_position:2,title:"Getting Started"},s=void 0,r={id:"getting-started/gettingstarted",title:"Getting Started",description:"Welcome to the OpenC3 COSMOS system... Let's get started! This guide is a high level overview that will help with setting up your first COSMOS project.",source:"@site/docs/getting-started/gettingstarted.md",sourceDirName:"getting-started",slug:"/getting-started/gettingstarted",permalink:"/docs/getting-started/gettingstarted",draft:!1,unlisted:!1,editUrl:"https://github.com/OpenC3/cosmos/tree/main/docs.openc3.com/docs/getting-started/gettingstarted.md",tags:[],version:"current",sidebarPosition:2,frontMatter:{sidebar_position:2,title:"Getting Started"},sidebar:"defaultSidebar",previous:{title:"Installation",permalink:"/docs/getting-started/installation"},next:{title:"Code Generators",permalink:"/docs/getting-started/generators"}},l={},c=[{value:"Interfacing with Your Hardware",id:"interfacing-with-your-hardware",level:2},{value:"Building Your Plugin",id:"building-your-plugin",level:2}];function d(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",ol:"ol",p:"p",pre:"pre",ul:"ul",...(0,a.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.p,{children:"Welcome to the OpenC3 COSMOS system... Let's get started! This guide is a high level overview that will help with setting up your first COSMOS project."}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["Get COSMOS Installed onto your computer by following the ",(0,i.jsx)(t.a,{href:"/docs/getting-started/installation",children:"Installation Guide"}),".","\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsx)(t.li,{children:"You should now have COSMOS installed and a Demo project available that we can make changes to."}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(t.li,{children:["Browse to ",(0,i.jsx)(t.a,{href:"http://localhost:2900",children:"http://localhost:2900"}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsx)(t.li,{children:'The COSMOS Command and Telemetry Server will appear. This tool provides real-time information about each "target" in the system. Targets are external systems that receive commands and generate telemetry, often over ethernet or serial connections.'}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(t.li,{children:["Experiment with other COSMOS tools. This is a DEMO environment so you can't break anything. Some things to try:","\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsx)(t.li,{children:"Use Command Sender to send individual commands."}),"\n",(0,i.jsx)(t.li,{children:"Use Limits Monitor to watch for telemetry limits violations"}),"\n",(0,i.jsx)(t.li,{children:"Run some of the example scripts in Script Runner and Test Runner"}),"\n",(0,i.jsx)(t.li,{children:"View individual Telemetry packets in Packet Viewer"}),"\n",(0,i.jsx)(t.li,{children:"View detailed telemetry displays in Telemetry Viewer"}),"\n",(0,i.jsx)(t.li,{children:"Graph some data in Telemetry Grapher"}),"\n",(0,i.jsx)(t.li,{children:"View log type data in Data Viewer"}),"\n",(0,i.jsx)(t.li,{children:"Process log data with Data Extractor"}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(t.admonition,{title:"Browser Version Issue",type:"info",children:[(0,i.jsxs)(t.p,{children:["When you try to load the page and it fails to load, check with the built-in web development tools / DevTools. We have seen some strange things with version of browsers. You can build to a version of browser if you need to by reading about the ",(0,i.jsx)(t.a,{href:"https://github.com/browserslist/browserslist",children:"browserslist"}),". A typical failure results in:"]}),(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"unexpected token ||=\n"})}),(0,i.jsxs)(t.p,{children:["To fix this make sure your browsers is compliant with the current settings in the ",(0,i.jsx)(t.a,{href:"https://github.com/OpenC3/cosmos/blob/main/openc3-cosmos-init/plugins/openc3-tool-base/.browserslistrc",children:".browserlistrc"})," file. You can change this and rebuild the image. Note: This can cause build speeds to increase or decrease."]})]}),"\n",(0,i.jsx)(t.h2,{id:"interfacing-with-your-hardware",children:"Interfacing with Your Hardware"}),"\n",(0,i.jsx)(t.p,{children:"Playing with the COSMOS Demo is fun and all, but now you want to talk to your own real hardware? Let's do it!"}),"\n",(0,i.jsx)(t.admonition,{title:"Install and Platform",type:"info",children:(0,i.jsx)(t.p,{children:"This guide assumes we're on Windows and COSMOS is installed in C:\\COSMOS. Adjust scripts and paths as necessary to match your platform and COSMOS installation directory."})}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsx)(t.p,{children:"Before creating your own configuration you should uninstall the COSMOS Demo so you're working with a clean COSMOS system. Click the Admin button and the PLUGINS tab. Then click the Trash can icon next to openc3-cosmos-demo to delete it. When you go back to the Command and Telemetry Server you should have a blank table with no interfaces."}),"\n"]}),"\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsxs)(t.p,{children:["If you followed the ",(0,i.jsx)(t.a,{href:"/docs/getting-started/installation",children:"Installation Guide"})," you should already be inside a cloned ",(0,i.jsx)(t.a,{href:"https://github.com/OpenC3/cosmos-project",children:"openc3-project"})," which is in your PATH (necessary for openc3.bat / openc3.sh to be resolved). Inside this project it's recommended to edit the README.md (",(0,i.jsx)(t.a,{href:"https://www.markdownguide.org/",children:"Markdown"}),") to describe your program / project."]}),"\n"]}),"\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsx)(t.p,{children:"Now we need to create a plugin. Plugins are how we add targets and microservices to COSMOS. Our plugin will contain a single target which contains all the information defining the packets (command and telemetry) that are needed to communicate with the target. Use the COSMOS plugin generator to create the correct structure:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-batch",children:"C:\\openc3-project> openc3.bat cli generate plugin BOB\n"})}),"\n",(0,i.jsxs)(t.p,{children:['This should create a new directory called "openc3-cosmos-bob" with a bunch of files in it. The full description of all the files is explained by the ',(0,i.jsx)(t.a,{href:"/docs/configuration/plugins#plugin-directory-structure",children:"Plugin Structure"})," page."]}),"\n"]}),"\n"]}),"\n",(0,i.jsx)(t.admonition,{title:"Run as the Root user",type:"info",children:(0,i.jsxs)(t.p,{children:["The cli runs as the default COSMOS container user which is the recommended practice. If you're having issues running as that user you can run as the root user (effectively ",(0,i.jsx)(t.code,{children:"docker run --user=root"})," ) by running ",(0,i.jsx)(t.code,{children:"cliroot"})," instead of ",(0,i.jsx)(t.code,{children:"cli"})," in any of the examples."]})}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsxs)(t.p,{children:["Starting with ",(0,i.jsx)(t.a,{href:"https://openc3.com/news/2023/02/23/openc3-cosmos-5-5-0-released/",children:"COSMOS v5.5.0"}),", the plugin generator creates just the plugin framework (previously it would also create a target). From within the newly created plugin directory, we generate a target."]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-batch",children:"C:\\openc3-project> cd openc3-cosmos-bob\nopenc3-cosmos-bob> openc3.bat cli generate target BOB\n"})}),"\n"]}),"\n"]}),"\n",(0,i.jsx)(t.admonition,{title:"Generators",type:"info",children:(0,i.jsxs)(t.p,{children:["There are a number of generators available. Run ",(0,i.jsx)(t.code,{children:"openc3.bat cli generate"})," to see all the available options."]})}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsx)(t.p,{children:"The target generator creates a single target named BOB. Best practice is to create a single target per plugin to make it easier to share targets and upgrade them individually. Lets see what the target generator created for us. Open the openc3-cosmos-bob/targets/BOB/cmd_tlm/cmd.txt:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ruby",children:'COMMAND BOB EXAMPLE BIG_ENDIAN "Packet description"\n # Keyword Name BitSize Type Min Max Default Description\n APPEND_ID_PARAMETER ID 16 INT 1 1 1 "Identifier"\n APPEND_PARAMETER VALUE 32 FLOAT 0 10.5 2.5 "Value"\n APPEND_PARAMETER BOOL 8 UINT MIN MAX 0 "Boolean"\n STATE FALSE 0\n STATE TRUE 1\n APPEND_PARAMETER LABEL 0 STRING "OpenC3" "The label to apply"\n'})}),"\n",(0,i.jsx)(t.p,{children:"What does this all mean?"}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsx)(t.li,{children:"We created a COMMAND for target BOB named EXAMPLE."}),"\n",(0,i.jsx)(t.li,{children:'The command is made up of BIG_ENDIAN parameters and is described by "Packet description". Here we are using the append flavor of defining parameters which stacks them back to back as it builds up the packet and you don\'t have to worry about defining the bit offset into the packet.'}),"\n",(0,i.jsx)(t.li,{children:'First we APPEND_ID_PARAMETER a parameter that is used to identify the packet called ID that is an 16-bit signed integer (INT) with a minimum value of 1, a maximum value of 1, and a default value of 1, that is described as the "Identifier".'}),"\n",(0,i.jsx)(t.li,{children:"Next we APPEND_PARAMETER a parameter called VALUE that is a 32-bit float (FLOAT) that has a minimum value of 0, a maximum value of 10.5, and a default value of 2.5."}),"\n",(0,i.jsx)(t.li,{children:"Then we APPEND_PARAMETER a third parameter called BOOL which is a 8-bit unsigned integer (UINT) with a minimum value of MIN (meaning the smallest value a UINT supports, e.g 0), a maximum value of MAX (largest value a UINT supports, e.g. 255), and a default value of 0. BOOL has two states which are just a fancy way of giving meaning to the integer values 0 and 1. The STATE FALSE has a value of 0 and the STATE TRUE has a value of 1."}),"\n",(0,i.jsx)(t.li,{children:"Finally we APPEND_PARAMETER called LABEL which is a 0-bit (meaning it takes up all the remaining space in the packet) string (STRING) with a default value of \"OpenC3\". Strings don't have minimum or maximum values as that doesn't make sense for STRING types."}),"\n"]}),"\n",(0,i.jsxs)(t.p,{children:["Check out the full ",(0,i.jsx)(t.a,{href:"/docs/configuration/command",children:"Command"})," documentation for more."]}),"\n"]}),"\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsx)(t.p,{children:"Now open the openc3-cosmos-bob/targets/BOB/cmd_tlm/tlm.txt:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ruby",children:'TELEMETRY BOB STATUS BIG_ENDIAN "Telemetry description"\n # Keyword Name BitSize Type ID Description\n APPEND_ID_ITEM ID 16 INT 1 "Identifier"\n APPEND_ITEM VALUE 32 FLOAT "Value"\n APPEND_ITEM BOOL 8 UINT "Boolean"\n STATE FALSE 0\n STATE TRUE 1\n APPEND_ITEM LABEL 0 STRING "The label to apply"\n'})}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsx)(t.li,{children:'This time we created a TELEMETRY packet for target BOB called STATUS that contains BIG_ENDIAN items and is described as "Telemetry description".'}),"\n",(0,i.jsx)(t.li,{children:'We start by defininig an ID_ITEM called ID that is a 16-bit signed integer (INT) with an id value of 1 and described as "Identifier". Id items are used to take unidentified blobs of bytes and determine which packet they are. In this case if a blob comes in with a value of 1, at bit offset 0 (since we APPEND this item first), interpreted as a 16-bit integer, then this packet will be "identified" as STATUS. Note the first packet defined without any ID_ITEMS is a "catch-all" packet that matches all incoming data (even if the data lengths don\'t match).'}),"\n",(0,i.jsx)(t.li,{children:"Next we define three items similar to the command definition above."}),"\n"]}),"\n",(0,i.jsxs)(t.p,{children:["Check out the full ",(0,i.jsx)(t.a,{href:"/docs/configuration/telemetry",children:"Telemetry"})," documentation for more."]}),"\n"]}),"\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsxs)(t.p,{children:["COSMOS has defined an example command and telemetry packet for our target. Most targets will obviously have more than one command and telemetry packet. To add more simply create additional COMMAND and TELEMETRY lines in your text files. Actual packets should match the structure of your command and telemetry. Be sure to add at least one unique ",(0,i.jsx)(t.a,{href:"/docs/configuration/command#id_parameter",children:"ID_PARAMETER"})," and ",(0,i.jsx)(t.a,{href:"/docs/configuration/telemetry#id_item",children:"ID_ITEM"})," so your packets can be distinguished from each other."]}),"\n"]}),"\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsx)(t.p,{children:"Now we need to tell COSMOS how to connect to our BOB target. Open the openc3-cosmos-bob/plugin.txt file:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ruby",children:"# Set VARIABLEs here to allow variation in your plugin\n# See [Plugins](../configuration/plugins.md) for more information\nVARIABLE bob_target_name BOB\n\n# Modify this according to your actual target connection\n# See [Interfaces](../configuration/interfaces.md) for more information\nTARGET BOB <%= bob_target_name %>\nINTERFACE <%= bob_target_name %>_INT tcpip_client_interface.rb host.docker.internal 8080 8081 10.0 nil BURST\n MAP_TARGET <%= bob_target_name %>\n"})}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsx)(t.li,{children:'This configures the plugin with a VARIABLE called bob_target_name with a default of "BOB". When you install this plugin you will have the option to change the name of this target to something other than "BOB". This is useful to avoid name conflicts and allows you to have multiple copies of the BOB target in your COSMOS system.'}),"\n",(0,i.jsx)(t.li,{children:"The TARGET line declares the new BOB target using the name from the variable. The <%= %> syntax is called ERB (embedded Ruby) and allows us to put variables into our text files, in this case referencing our bob_target_name."}),"\n",(0,i.jsxs)(t.li,{children:["The last line declares a new INTERFACE called (by default) BOB_INT that will connect as a TCP/IP client using the code in tcpip_client_interface.rb to address host.docker.internal (This adds an /etc/hosts entry to the correct IP address for the host's gateway) using port 8080 for writing and 8081 for reading. It also has a write timeout of 10 seconds and reads will never timeout (nil). The TCP/IP stream will be interpreted using the COSMOS ",(0,i.jsx)(t.a,{href:"/docs/configuration/protocols#burst-protocol",children:"BURST"})," protocol which means it will read as much data as it can from the interface. For all the details on how to configure COSMOS interfaces please see the ",(0,i.jsx)(t.a,{href:"/docs/configuration/interfaces",children:"Interface Guide"}),". The MAP_TARGET line tells COSMOS that it will receive telemetry from and send commands to the BOB target using the BOB_INT interface."]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,i.jsx)(t.admonition,{title:"Variables Support Reusability",type:"note",children:(0,i.jsx)(t.p,{children:"In a plugin that you plan to reuse you should make things like hostnames and ports variables"})}),"\n",(0,i.jsx)(t.h2,{id:"building-your-plugin",children:"Building Your Plugin"}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsx)(t.p,{children:"Now we need to build our plugin and upload it to COSMOS."}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-batch",children:"C:\\cosmos-project> cd openc3-cosmos-bob\nC:\\cosmos-project\\openc3-cosmos-bob> ..\\openc3.bat cli rake build VERSION=1.0.0\n Successfully built RubyGem\n Name: openc3-cosmos-bob\n Version: 1.0.0.20210618174517\n File: openc3-cosmos-bob-1.0.0.20210618174517.gem\n"})}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsxs)(t.li,{children:["Note that the VERSION is required to specify the version to build. We recommend ",(0,i.jsx)(t.a,{href:"https://semver.org/",children:"semantic versioning"})," when building your plugin so people using your plugin (including you) know when there are breaking changes."]}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsx)(t.p,{children:"Once our plugin is built we need to upload it to COSMOS. Go back to the Admin page and click the Plugins Tab. Click on \"Click to install plugin\" and select the openc3-cosmos-bob-1.0.0.20210618174517.gem file. Then click Upload. Go back to the CmdTlmServer and you should see the plugin being deployed at which point the BOB_INT interface should appear and try to connect. Go ahead and click 'Cancel' because unless you really have something listening on port 8080 this will never connect. At this point you can explore the other CmdTlmServer tabs and other tools to see your newly defined BOB target."}),"\n"]}),"\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsx)(t.p,{children:'Let\'s modify our BOB target and then update the copy in COSMOS. If you open Command Sender in COSMOS to BOB EXAMPLE you should see the VALUE parameter has value 2.5. Open the openc3-cosmos-bob/targets/BOB/cmd_tlm/cmd.txt and change the Default value for VALUE to 5 and the description to "New Value".'}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-ruby",children:'COMMAND BOB EXAMPLE BIG_ENDIAN "Packet description"\n # Keyword Name BitSize Type Min Max Default Description\n APPEND_ID_PARAMETER ID 16 INT 1 1 1 "Identifier"\n APPEND_PARAMETER VALUE 32 FLOAT 0 10.5 5 "New Value"\n APPEND_PARAMETER BOOL 8 UINT MIN MAX 0 "Boolean"\n STATE FALSE 0\n STATE TRUE 1\n APPEND_PARAMETER LABEL 0 STRING "OpenC3" "The label to apply"\n'})}),"\n"]}),"\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsx)(t.p,{children:"Rebuild the plugin with a new VERSION number. Since we didn't make any breaking changes we simply bump the patch release number:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-batch",children:"C:\\cosmos-project\\openc3-cosmos-bob> ..\\openc3.bat cli rake build VERSION=1.0.1\n Successfully built RubyGem\n Name: openc3-cosmos-bob\n Version: 1.0.1.20210618202504\n File: openc3-cosmos-bob-1.0.1.20210618202504.gem\n"})}),"\n"]}),"\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsx)(t.p,{children:'Go back to the Admin page and click the Plugins Tab. This time click the clock icon next to openc3-cosmos-bob-1.0.0 to Upgrade the plugin. Browse to the newly built plugin gem and select it. This will re-prompt for the plugin variables (bob_target_name) so don\'t change the name and just click OK. You should see a message about the plugin being installed at which point the plugins list will change to openc3-cosmos-bob-1.0.1.20210618202504.gem. Go back to Command Sender and you should see the new Default value for VALUE is 5 and the description is "New Value". We have upgraded our plugin!'}),"\n"]}),"\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsxs)(t.p,{children:["At this point you can create a new plugin named after your real target and start modifying the interface and command and telemetry definitions to enable COSMOS to connect to and drive your target. If you run into trouble look for solutions on our ",(0,i.jsx)(t.a,{href:"https://github.com/OpenC3/cosmos/issues",children:"Github Issues"})," page. If you would like to enquire about support contracts or professional COSMOS development please contact us at ",(0,i.jsx)(t.a,{href:"mailto:support@openc3.com",children:"support@openc3.com"}),"."]}),"\n"]}),"\n"]})]})}function h(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>s,x:()=>r});var i=n(6540);const a={},o=i.createContext(a);function s(e){const t=i.useContext(o);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:s(e.components),i.createElement(o.Provider,{value:t},e.children)}}}]);