COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
agent_scoot.cpp File Reference
#include "support/configCosmos.h"
#include "support/elapsedtime.h"
#include "support/timeutils.h"
#include "agent/agentclass.h"
#include <iostream>
#include <string>
Include dependency graph for agent_scoot.cpp:

Functions

int32_t sample_agent_request_function (string &request, string &response, Agent *cdata)
 
int main (int argc, char **argv)
 

Variables

static uint64_t request_counter = 10000
 
static Agentagent
 ensure the Agent constructor creates only one instance per process More...
 
string node_name = "sat_001"
 
string agent_name = "agent_scoot"
 
string node_agent_name = "["+node_name+":"+agent_name+"]"
 

Function Documentation

int32_t sample_agent_request_function ( string &  request,
string &  response,
Agent cdata 
)
125 {
126  // Send response back to agent_002
127  response = "I am the one they call [sat_001:agent_scoot]";
128  cout << "[" << node_name << ":" << agent_name << "]"<<" received <"<<request.c_str()<<"> request!"<<endl;
129  cout << "[" << node_name << ":" << agent_name << "] transmit <"<<request.c_str()<<"> response:\n TX: \"" << response << "\" ("<<response.size()<<" bytes)"<<endl;
130 
131  // Increment counter of how many requests were run
132  request_counter--;
133 
134  return 0;
135 }
string agent_name
Definition: agent_scoot.cpp:47
string node_name
Definition: agent_scoot.cpp:46
static uint64_t request_counter
Definition: agent_scoot.cpp:41
int main ( int  argc,
char **  argv 
)
51 {
52  // construct agent
53  cout << node_agent_name << " starting..."<<endl;
54  agent = new Agent(node_name, agent_name, 1.);
55 
56  // exit with error if unable to start agent
57  if(agent->last_error() < 0) {
58  cout<<"error: unable to start "<<node_agent_name<<" ("<<agent->last_error()<<") "<<cosmos_error_string(agent->last_error())<<endl;
59  exit(1);
60  } else {
61  cout << node_agent_name << " started."<<endl;
62  }
63 
64  // add custom request functions for this agent
65  string request_name = "identify_yourself";
66  agent->add_request(request_name, sample_agent_request_function, "\n\t\trequest to support the reporting of identification");
67 
68  // try to locate a specific agent (agent_002)
69  string agent_target = "agent_002"; // The name of the agent this agent will send requests to
70  beatstruc agent_target_heartbeat = agent->find_agent(node_name, agent_target, 2.);
71  //cout<<"["<<node_name<<":"<<agent_name<<"] looking for ["<<node_name<<":"<<agent_target<<"]..."<<endl;
72 
73  if(agent->debug_level>1) {
74  cout<<"A agent "<<agent_target<<" beatstruc:"<<endl;
75  cout<<agent_target_heartbeat;
76  }
77 
78  string response; // Variable to store agent_002's response
79 
80  // Start executing the agent
81  //auto test = agent->cinfo->get_json<vector<vector<unitstruc>>>("unit");
82  //agent->cinfo->set_value<string>("unit[35][1].name", "NAME");
83  //agent->cinfo->set_json(test);
84  //cout<<"<vector<vector<unitstruc>>> = <"<<agent->cinfo->get_json_pretty<vector<vector<unitstruc>>>("unit")<<">"<<endl;
85 
86  vector<vector<uint16_t>> vvuint16 {{1},{1,2},{1,2,3},{1,2,3,4},{1,2,3,4,5}};
87  agent->cinfo->add_name("vvuint16", &vvuint16, "vector<vector<uint16_t>>");
88  agent->cinfo->add_name("vvuint16[4][4]", &vvuint16[4][4], "int16_t");
89  auto j_vvuint16 = agent->cinfo->get_json("vvuint16");
90  agent->cinfo->set_value<uint16_t>("vvuint16[4][4]", 9);
91  agent->cinfo->set_json(j_vvuint16);
92  cout<<"<vector<vector<uint16_t>>> = <"<<agent->cinfo->get_json_pretty<vector<vector<uint16_t>>>("vvuint16")<<">"<<endl;
93 
94  uint32_t t_uint32 = 1;
95  agent->cinfo->add_name("t_uint32", &t_uint32, "uint32_t");
96  auto j_t_uint32 = agent->cinfo->get_json("t_uint32"); // SCOTTNOTE: error if type is uint32_t, should fix get_json and get_json_pretty
97  agent->cinfo->set_value<uint32_t>("t_uint32", 99);
98  agent->cinfo->set_json(j_t_uint32);
99  cout<<"uint32_t> = <"<<agent->cinfo->get_json_pretty<int>("t_uint32")<<">"<<endl;
100 
101  auto arptrtest = agent->cinfo->get_pointer<double*>("node.loc.pos.icrf.s.col");
102  cout<<"double* = "<<arptrtest<<endl;
103  cout<<"actual* = "<<&agent->cinfo->node.loc.pos.icrf.s.col<<endl;
104 
105  auto charptest = agent->cinfo->get_pointer<char[41]>("node.name");
106  cout<<"char * = "<<charptest<<endl;
107  cout<<"actual* = "<<&agent->cinfo->node.name<<endl;
108  if(charptest == &agent->cinfo->node.name) {
109  cout<<"char* == actual*"<<endl;
110  }
111 
112  //auto a = agent->cinfo->get_value("")
113 
114 
115  while (agent->running()) {
116 
117  cout<<"["<<node_name<<":"<<agent_name<<"] running..."<<endl;
118  // Sleep for 5 sec
119  COSMOS_SLEEP(5.);
120  }
121  return 0;
122 }
uint16_t debug_level
Flag for level of debugging, keep it public so that it can be controlled from the outside...
Definition: agentclass.h:362
string get_json(const string &s)
Gets a JSON-formatted string of the data associated with the provided name in Namespace 2...
Definition: jsondef.h:7281
string agent_name
Definition: agent_scoot.cpp:47
void add_name(const string &s, void *v, string t)
Adds a name, memory location, and datatype to Namespace 2.0.
Definition: jsondef.h:4611
string get_json_pretty(const string &s)
Definition: jsondef.h:7589
Definition: jsondef.h:923
string node_agent_name
Definition: agent_scoot.cpp:48
int32_t sample_agent_request_function(string &request, string &response, Agent *cdata)
Definition: agent_scoot.cpp:124
T * get_pointer(const string &s) const
Gets the pointer to the memory address associated with the provided name in Namespace 2...
Definition: jsondef.h:6779
nodestruc node
Structure for summary information in node.
Definition: jsondef.h:4220
string cosmos_error_string(int32_t cosmos_errno)
Definition: cosmos-errno.cpp:45
uint16_t running()
Check if we&#39;re supposed to be running.
Definition: agentclass.cpp:391
rvector s
Location.
Definition: convertdef.h:163
static Agent * agent
ensure the Agent constructor creates only one instance per process
Definition: agent_scoot.cpp:45
int32_t add_request(string token, external_request_function function, string synopsis="", string description="")
Add internal request to Agent request list with description and synopsis.
Definition: agentclass.cpp:312
char name[40+1]
Node Name.
Definition: jsondef.h:3556
Definition: agentclass.h:139
string node_name
Definition: agent_scoot.cpp:46
locstruc loc
Location structure.
Definition: jsondef.h:3596
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
int32_t last_error()
Definition: agentclass.cpp:414
beatstruc find_agent(string node, string agent, double waitsec=0.)
Find agent.
Definition: agentclass.cpp:559
void set_json(const string &json)
Sets the data in Namespace 2.0 with a JSON-formatted string.
Definition: jsondef.h:6822
double col[3]
Definition: vector.h:55
cosmosstruc * cinfo
Definition: agentclass.h:346
void set_value(const string &s, const T &value) const
Sets the value of the data associated with the provided name in Namespace 2.0.
Definition: jsondef.h:6808
cartpos icrf
Definition: convertdef.h:736

Variable Documentation

uint64_t request_counter = 10000
static
Agent* agent
static

ensure the Agent constructor creates only one instance per process

string node_name = "sat_001"
string agent_name = "agent_scoot"
string node_agent_name = "["+node_name+":"+agent_name+"]"