COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
queen.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 queen.cpp:

Functions

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

Variables

static Agentagent
 
string node_name = "queen"
 
string agent_name = "elizabeth"
 
string node_agent_name = "["+node_name+":"+agent_name+"]"
 
bool once = true
 
string tel_message = "THIS IS THE QUEEN CALLING"
 

Function Documentation

int32_t are_you_out_there ( string &  request,
string &  response,
Agent cdata 
)
139 {
140  response = "Yes! I am the one they call " + node_agent_name + ".";
141  return 0;
142 }
string node_agent_name
Definition: queen.cpp:46
int32_t req_pass_message ( string &  request,
string &  response,
Agent  
)
145  {
146  cout<<"\tincoming request = <"<<request<<">"<<endl;
147 
148  // remove function call and space
149  request.erase(0,13);
150 
151  // read in mjdtime
152  string timemjd = request;
153 
154  int charidx = rand() % timemjd.size();
155  char newchar = rand() % 26 + 65;
156  timemjd[charidx] = newchar;
157  tel_message = timemjd;
158 
159  cout << "\tmessage: " << tel_message << endl;
160 
161  once = true;
162 
163  return 0;
164 }
string tel_message
Definition: queen.cpp:49
bool once
Definition: queen.cpp:48
int main ( int  argc,
char **  argv 
)
52 {
53  // construct agent
54  cout << node_agent_name << " starting..."<<endl;
55  agent = new Agent(node_name, agent_name, 1.);
56 
57  // exit with error if unable to start agent
58  if(agent->last_error() < 0) {
59  cerr<<"error: unable to start "<<node_agent_name
60  <<" ("<<agent->last_error()<<") "
62  exit(1);
63  } else {
64  cout << node_agent_name << " started."<<endl;
65  }
66 
67  // add custom request functions for this agent
68  agent->add_request("are_you_out_there", are_you_out_there, "\n\t\trequest to determine if specific agent exists");
69  agent->add_request("pass_message", req_pass_message, "\n\t\trequest to pass message");
70 
71  // cosmosstruc
72  cosmosstruc* c = agent->cinfo;
73 
74  // set the orbital elements (psuedo ISS orbit)
75  c->a = 6738000; // 6738 km
76  c->e = 0.0001640; // no units!
77  c->i = 51.6407 * (M_PI/180.0); // radians
78  c->O = 126.7653 * (M_PI/180.0); // radians
79  c->w = 163.1572 * (M_PI/180.0); // radians
80  c->tau = 0.00; // seconds since periasis
81 
82  // n = mean angular motion (rad/s) [ used to find a in TLEs ]
83  c->n = pow( (c->mu / pow(c->a,3.0) ), (0.5) );
84  // T = period of orbit (seconds)
85  c->T = ( 2.0 * M_PI ) / c->n;
86 
87  cout<<"\tPeriod in seconds = "<<setprecision(numeric_limits<double>::digits10)<<c->T<<endl;
88  cout<<"\tRevolutions / day = "<<setprecision(numeric_limits<double>::digits10)<<86400.0/c->T<<endl;
89 
90  string workernames[3] = {"albeert", "beeber", "corbee"};
91 
92  // agent loop
93  while (agent->running()) {
94 
95  cout<<node_agent_name<<" running..."<<endl;
96 
97  // see if you can locate each of the daughters
98  string request = "are_you_out_there";
99  string response = "";
100 
101  // stringify the current time
102  double t = currentmjd();
103  stringstream sss;
104  sss<<setprecision(numeric_limits<double>::digits10)<<t;
105  string time = sss.str();
106 
107  // calculate position of Mothership
108  //double mother_x = 0.0, mother_y = 0.0, mother_z = 0.0;
109  if(once) {
110  int workernum = rand() % (sizeof(workernames)/sizeof(*workernames));
111  string worker = "worker_0" + to_string(workernum+1);
112  agent->send_request(agent->find_agent(worker, workernames[workernum], 2.), request, response, 2.);
113  if(response.size()) {
114  string s = "\t[" + worker + ":" + workernames[workernum] + "]";
115  cout<<left<<setw(40)<< s <<setw(16)<<"\033[1;32mFOUND\033[0m"<<endl;
116  response.clear();
117  agent->send_request(agent->find_agent(worker, workernames[workernum], 2.), "pass_message " + tel_message, response, 2);
118  // ask for their location
119  //agent->send_request(agent->find_agent("daughter_01", "allison", 2.), "get_position " + time, response, 2.);
120  cout<<response<<endl;
121  response.clear();
122  once = false;
123  } else {
124  string s = "\t[" + worker + ":" + workernames[workernum] + "]";
125  cout<<left<<setw(40) << s <<"\033[1;31mNOT FOUND\033[0m"<<endl;
126  }
127  }
128 
129  // Sleep for 5 sec
130  COSMOS_SLEEP(5.);
131  }
132  return 0;
133 }
int32_t send_request(beatstruc cbeat, string request, string &output, float waitsec=5.)
Send a request over AGENT.
Definition: agentclass.cpp:424
static Agent * agent
Definition: queen.cpp:43
string to_string(char *value)
Definition: stringlib.cpp:220
string agent_name
Definition: queen.cpp:45
double O
Definition: jsondef.h:4336
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
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
Definition: agentclass.h:139
string tel_message
Definition: queen.cpp:49
int32_t are_you_out_there(string &request, string &response, Agent *cdata)
Definition: queen.cpp:138
bool once
Definition: queen.cpp:48
double mu
Definition: jsondef.h:4350
double currentmjd(double offset)
Current UTC in Modified Julian Days.
Definition: timelib.cpp:65
string node_agent_name
Definition: queen.cpp:46
int32_t last_error()
Definition: agentclass.cpp:414
string node_name
Definition: queen.cpp:44
double T
Definition: jsondef.h:4356
double w
Definition: jsondef.h:4338
beatstruc find_agent(string node, string agent, double waitsec=0.)
Find agent.
Definition: agentclass.cpp:559
cosmosstruc * cinfo
Definition: agentclass.h:346
double n
Definition: jsondef.h:4353
int32_t req_pass_message(string &request, string &response, Agent *)
Definition: queen.cpp:145
Definition: jsondef.h:4199
double a
Definition: jsondef.h:4320
double tau
Definition: jsondef.h:4340
double i
Definition: jsondef.h:4334
double e
Definition: jsondef.h:4322

Variable Documentation

Agent* agent
static
string node_name = "queen"
string agent_name = "elizabeth"
string node_agent_name = "["+node_name+":"+agent_name+"]"
bool once = true
string tel_message = "THIS IS THE QUEEN CALLING"