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

Functions

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

Variables

static Agentagent
 
string node_name = "mothership"
 
string agent_name = "mother"
 
string node_agent_name = "["+node_name+":"+agent_name+"]"
 

Function Documentation

int32_t are_you_out_there ( string &  request,
string &  response,
Agent cdata 
)
193 {
194  response = "Yes! I am the one they call " + node_agent_name + ".";
195  return 0;
196 }
string node_agent_name
Definition: mothership.cpp:45
int main ( int  argc,
char **  argv 
)
49 {
50  // construct agent
51  cout << node_agent_name << " starting..."<<endl;
52  agent = new Agent(node_name, agent_name, 1.);
53 
54  // exit with error if unable to start agent
55  if(agent->last_error() < 0) {
56  cerr<<"error: unable to start "<<node_agent_name
57  <<" ("<<agent->last_error()<<") "
59  exit(1);
60  } else {
61  cout << node_agent_name << " started."<<endl;
62  }
63 
64  // add custom request functions for this agent
65  agent->add_request("are_you_out_there", are_you_out_there, "\n\t\trequest to determine if specific agent exists");
66 
67  cosmosstruc* c = agent->cinfo;
68 
69  // set the orbital elements (psuedo ISS orbit)
70  c->a = 6738000; // 6738 km
71  c->e = 0.0001640; // no units!
72  c->i = 51.6407 * (M_PI/180.0); // radians
73  c->O = 126.7653 * (M_PI/180.0); // radians
74  c->w = 163.1572 * (M_PI/180.0); // radians
75  c->tau = 0.00; // seconds since periasis
76 
77  // n = mean angular motion (rad/s) [ used to find a in TLEs ]
78  c->n = pow( (c->mu / pow(c->a,3.0) ), (0.5) );
79  // T = period of orbit (seconds)
80  c->T = ( 2.0 * M_PI ) / c->n;
81 
82  cout<<"\tPeriod in seconds = "<<setprecision(numeric_limits<double>::digits10)<<c->T<<endl;
83  cout<<"\tRevolutions / day = "<<setprecision(numeric_limits<double>::digits10)<<86400.0/c->T<<endl;
84 
85 
86  // agent loop
87  while (agent->running()) {
88 
89  cout<<node_agent_name<<" running..."<<endl;
90 
91  // see if you can locate each of the daughters
92  string request = "are_you_out_there";
93  string response = "";
94 
95  // stringify the current time
96  double t = currentmjd();
97  stringstream sss;
98  sss<<setprecision(numeric_limits<double>::digits10)<<t;
99  string time = sss.str();
100 
101  // calculate position of Mothership
102  //double mother_x = 0.0, mother_y = 0.0, mother_z = 0.0;
103 
104 
105  agent->send_request(agent->find_agent("daughter_01", "allison", 2.), request, response, 2.);
106  if(response.size()) {
107  cout<<left<<setw(40)<<"\t[daughter_01:allison]"<<setw(16)<<"\033[1;32mFOUND\033[0m";
108  response.clear();
109 
110 
111  // (see how long to send/receive requests)
112  //double tx_time = currentmjd();
113  //agent->send_request(agent->find_agent("daughter_01", "allison", 2.), "get_time", response, 2.);
114  //double rx_time = currentmjd();
115  //cout<<"get_time = "<<response<<endl;
116  //stringstream ss;
117  //ss<<response;
118  //double go_time;
119  //ss>>go_time;
120  //cout<<"\t\trequest time = <"<<setprecision(numeric_limits<double>::digits10)<<go_time-tx_time<<">"<<endl;
121  //cout<<"\t\treceive time = <"<<setprecision(numeric_limits<double>::digits10)<<rx_time-go_time<<">"<<endl;
122 
123  //cout<<setprecision(numeric_limits<double>::digits10)<<"time = "<<tx_time<<endl;
124  //cout<<setprecision(numeric_limits<double>::digits10)<<"time = "<<go_time<<endl;
125  //cout<<setprecision(numeric_limits<double>::digits10)<<"time = "<<rx_time<<endl;
126 
127 
128  // ask for their location
129  agent->send_request(agent->find_agent("daughter_01", "allison", 2.), "get_position " + time, response, 2.);
130  cout<<"\n"<<response<<endl;
131 
132  // de-stringify location data
133  //stringstream ss;
134  //string junk;
135  //double x_coord = 0.0;
136  //double y_coord = 0.0;
137  //double z_coord = 0.0;
138  //ss<<response;
139  //ss>>junk>>junk>>junk>>junk>>junk>>junk>>x_coord>>y_coord>>z_coord;
140  //ss>>x_coord>>y_coord>>z_coord;
141 
142 
143  } else {
144  cout<<left<<setw(40)<<"\t[daughter_01:allison]"<<"\033[1;31mNOT FOUND\033[0m"<<endl;
145  }
146 
147  response.clear();
148  agent->send_request(agent->find_agent("daughter_02", "becky", 2.), request, response, 2.);
149  if(response.size()) {
150  cout<<left<<setw(40)<<"\t[daughter_02:becky]"<<setw(16)<<"\033[1;32mFOUND\033[0m";
151  // ask for their location
152  response.clear();
153  agent->send_request(agent->find_agent("daughter_02", "becky", 2.), "get_position " + time, response, 2.);
154  cout<<"\n"<<response<<endl;
155  } else {
156  cout<<left<<setw(40)<<"\t[daughter_02:becky]"<<"\033[1;31mNOT FOUND\033[0m"<<endl;
157  }
158 
159  response.clear();
160  agent->send_request(agent->find_agent("daughter_03", "cecilia", 2.), request, response, 2.);
161  if(response.size()) {
162  cout<<left<<setw(40)<<"\t[daughter_03:cecilia]"<<setw(16)<<"\033[1;32mFOUND\033[0m";
163  // ask for their location
164  response.clear();
165  agent->send_request(agent->find_agent("daughter_03", "cecilia", 2.), "get_position " + time, response, 2.);
166  cout<<"\n"<<response<<endl;
167  } else {
168  cout<<left<<setw(40)<<"\t[daughter_03:cecilia]"<<"\033[1;31mNOT FOUND\033[0m"<<endl;
169  }
170 
171  response.clear();
172  agent->send_request(agent->find_agent("daughter_04", "delilah", 2.), request, response, 2.);
173  if(response.size()) {
174  cout<<left<<setw(40)<<"\t[daughter_04:deliliah]"<<setw(16)<<"\033[1;32mFOUND\033[0m";
175  // ask for their location
176  response.clear();
177  agent->send_request(agent->find_agent("daughter_04", "delilah", 2.), "get_position " + time, response, 2.);
178  cout<<"\n"<<response<<endl;
179  } else {
180  cout<<left<<setw(40)<<"\t[daughter_04:deliliah]"<<"\033[1;31mNOT FOUND\033[0m"<<endl;
181  }
182 
183  // Sleep for 5 sec
184  COSMOS_SLEEP(5.);
185  }
186  return 0;
187 }
int32_t send_request(beatstruc cbeat, string request, string &output, float waitsec=5.)
Send a request over AGENT.
Definition: agentclass.cpp:424
double O
Definition: jsondef.h:4336
string node_agent_name
Definition: mothership.cpp:45
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
string node_name
Definition: mothership.cpp:43
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
double mu
Definition: jsondef.h:4350
double currentmjd(double offset)
Current UTC in Modified Julian Days.
Definition: timelib.cpp:65
int32_t last_error()
Definition: agentclass.cpp:414
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
string agent_name
Definition: mothership.cpp:44
static Agent * agent
Definition: mothership.cpp:42
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
int32_t are_you_out_there(string &request, string &response, Agent *cdata)
Definition: mothership.cpp:192

Variable Documentation

Agent* agent
static
string node_name = "mothership"
string agent_name = "mother"
string node_agent_name = "["+node_name+":"+agent_name+"]"