COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
worker_03.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 worker_03.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
 ensure the Agent constructor creates only one instance per process More...
 
string node_name = "worker_03"
 
string agent_name = "corbee"
 
string node_agent_name = "["+node_name+":"+agent_name+"]"
 
bool once = false
 
string tel_message = "EMPTY"
 

Function Documentation

int32_t are_you_out_there ( string &  request,
string &  response,
Agent cdata 
)
124 {
125  // Send response back to the agent who made the request
126  response = "Yes! I am the one they call " + node_agent_name + ".";
127  return 0;
128 }
string node_agent_name
Definition: worker_03.cpp:46
int32_t req_pass_message ( string &  request,
string &  response,
Agent  
)
131  {
132  cout<<"\tincoming request = <"<<request<<">"<<endl;
133 
134  // remove function call and space
135  request.erase(0,13);
136 
137  // read in mjdtime
138  string timemjd = request;
139 
140  int charidx = rand() % timemjd.size();
141  char newchar = rand() % 26 + 65;
142  timemjd[charidx] = newchar;
143  tel_message = timemjd;
144 
145  cout << "\tmessage: " << tel_message << endl;
146 
147  once = true;
148 
149  return 0;
150 }
string tel_message
Definition: worker_03.cpp:49
bool once
Definition: worker_03.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  cout<<"error: unable to start "<<node_agent_name<<" ("<<agent->last_error()<<") "<<cosmos_error_string(agent->last_error())<<endl;
60  exit(1);
61  } else {
62  cout << node_agent_name << " started."<<endl;
63  }
64 
65  // add custom request functions for this agent
66  agent->add_request("are_you_out_there", are_you_out_there, "\n\t\trequest to support the reporting of existence");
67  agent->add_request("pass_message", req_pass_message, "\n\t\trequest to pass message");
68 
69  cosmosstruc* c = agent->cinfo;
70  // set the orbital elements (psuedo ISS orbit)
71  c->a = 6738000; // 6738 km
72  c->e = 0.0001640; // no units!
73  c->i = 51.6407 * (M_PI/180.0); // radians
74  c->O = 126.7653 * (M_PI/180.0); // radians
75  c->w = 163.1572 * (M_PI/180.0); // radians
76  c->tau = 1.0;
77 
78  // n = mean angular motion (rad/s) [ used to find a in TLEs ]
79  c->n = pow( (c->mu / pow(c->a,3.0) ), (0.5) );
80  // T = period of orbit (seconds)
81  c->T = ( 2.0 * M_PI ) / c->n;
82 
83  string request = "are_you_out_there";
84  string response = "";
85  string workernames[3] = {"albeert", "beeber", "elizabeth"};
86 
87  while (agent->running()) {
88 
89  cout<<node_agent_name<<" running..."<<endl;
90 
91  // see if you can locate the mothership
92  // see if you can locate each of the other daughters
93  if(once) {
94  int workernum = rand() % (sizeof(workernames)/sizeof(*workernames));
95  string worker = "worker_0" + to_string(workernum+1);
96  if(workernum == 2) {
97  worker = "queen";
98  }
99  agent->send_request(agent->find_agent(worker, workernames[workernum], 2.), request, response, 2.);
100  if(response.size()) {
101  string s = "\t[" + worker + ":" + workernames[workernum] + "]";
102  cout<<left<<setw(40)<< s <<setw(16)<<"\033[1;32mFOUND\033[0m"<<endl;
103  response.clear();
104  agent->send_request(agent->find_agent(worker, workernames[workernum], 2.), "pass_message " + tel_message, response, 2);
105  // ask for their location
106  //agent->send_request(agent->find_agent("daughter_01", "allison", 2.), "get_position " + time, response, 2.);
107  cout<<response<<endl;
108  response.clear();
109  once = false;
110  } else {
111  string s = "\t[" + worker + ":" + workernames[workernum] + "]";
112  cout<<left<<setw(40) << s <<"\033[1;31mNOT FOUND\033[0m"<<endl;
113  }
114  }
115  // Sleep for 5 sec
116  COSMOS_SLEEP(5.);
117  }
118  return 0;
119 }
string tel_message
Definition: worker_03.cpp:49
int32_t send_request(beatstruc cbeat, string request, string &output, float waitsec=5.)
Send a request over AGENT.
Definition: agentclass.cpp:424
string agent_name
Definition: worker_03.cpp:45
string node_agent_name
Definition: worker_03.cpp:46
string to_string(char *value)
Definition: stringlib.cpp:220
static Agent * agent
ensure the Agent constructor creates only one instance per process
Definition: worker_03.cpp:43
double O
Definition: jsondef.h:4336
string node_name
Definition: worker_03.cpp:44
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 are_you_out_there(string &request, string &response, Agent *cdata)
Definition: worker_03.cpp:123
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
bool once
Definition: worker_03.cpp:48
Definition: agentclass.h:139
double mu
Definition: jsondef.h:4350
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
int32_t req_pass_message(string &request, string &response, Agent *)
Definition: worker_03.cpp:131
cosmosstruc * cinfo
Definition: agentclass.h:346
double n
Definition: jsondef.h:4353
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

ensure the Agent constructor creates only one instance per process

string node_name = "worker_03"
string agent_name = "corbee"
string node_agent_name = "["+node_name+":"+agent_name+"]"
bool once = false
string tel_message = "EMPTY"