COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
alias.cpp File Reference

Example to demonstrate use of cosmos namespace aliases Follow this tutorial for more information tutorial-alias. More...

#include <iostream>
#include "agent/agent.h"
#include "jsonlib.h"
Include dependency graph for alias.cpp:

Functions

int main ()
 Example to demonstrate use of cosmos namespace aliases by creating an alias to an equation that converts degrees Kelvin to degrees Celcius. More...
 

Variables

cosmosstruccdata
 

Detailed Description

Example to demonstrate use of cosmos namespace aliases Follow this tutorial for more information tutorial-alias.

Function Documentation

int main ( )

Example to demonstrate use of cosmos namespace aliases by creating an alias to an equation that converts degrees Kelvin to degrees Celcius.

define the node name (it must be installed in COSMOS/nodes

20 {
21  cout << "Example for COSMOS Namespace Equations" << endl;
22 
24  string nodename = "cubesat1";
25 
26  // Establish the agent inside the given node
27  if (!(cdata = agent_setup_client(NetworkType::UDP, nodename, 10000)))
28  {
29  cout << "agent_setup_client failed (error <" << AGENT_ERROR_JSON_CREATE << ">)"<<endl;
31  } else {
32  cout << "agent setup client ... OK" << endl;
33  }
34 
35  // define the equation using the COSMOS namespace
36  // in this case we are setting an equation to convert the temperature
37  // for imu 0 (device_imu_temp_000) from Kelvin (the standart temperature unit in COSMOS)
38  // to degree Celcius
39  string equation = "(\"device_imu_temp_000\" - 273.15)";
40 
41  // get the equation handle for later use
42  jsonhandle eqhandle;
43 
44  // map/connect the equation to the handle
45  json_equation_map(equation,cdata,&eqhandle);
46 
47  // set initial IMU temperature in Kelvin
48  cdata->devspec.imu[0]->gen.temp = 0;
49 
50  // loop to demonstrate how to change values on the cdata structure
51  // and get the values from the equation and alias mechanisms
52 
53  while(cdata->devspec.imu[0]->gen.temp <= 300) {
54 
55  cout << "temperature value set [K] : " << cdata->devspec.imu[0]->gen.temp << endl;
56 
57  // using the equation handle get the result of the equation
58  double temp = json_equation(&eqhandle, cdata);
59  cout << "temperature value from handle [C] : " << temp << endl;
60 
61  // change temperature value for demo only
62  // set temp in Kelvin
63  cdata->devspec.imu[0]->gen.temp += 1;
64 
65  cout << endl;
66  };
67 
68  return 0;
69 
70 }
Agent socket using Unicast UDP.
vector< uint16_t > imu
Definition: jsondef.h:3904
double json_equation(const char *&ptr, cosmosstruc *cinfo)
Return the results of a JSON equation.
Definition: jsonlib.cpp:4294
int32_t json_equation_map(string equation, cosmosstruc *cinfo, jsonhandle *handle)
Get hash and index in JSON Equation map.
Definition: jsonlib.cpp:10609
JSON handle.
Definition: jsondef.h:791
string nodename
Definition: agent_add_soh.cpp:54
#define AGENT_ERROR_JSON_CREATE
Definition: cosmos-errno.h:105
devspecstruc devspec
Structure for devices (components) special data in node, by type.
Definition: jsondef.h:4241
cosmosstruc * cdata
Definition: alias.cpp:13

Variable Documentation

cosmosstruc* cdata