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

Functions

int main (int, char **)
 agent_005 is a test agent that demonstrates the interconnectivity with another agent, namely agent_002, through the use of agent requests. This agent will send a request to agent_002 and will print the response that agent_002 provides. More...
 

Variables

static Agentagent
 

Function Documentation

int main ( int  ,
char **   
)

agent_005 is a test agent that demonstrates the interconnectivity with another agent, namely agent_002, through the use of agent requests. This agent will send a request to agent_002 and will print the response that agent_002 provides.

Parameters
argcNumber of arguments provided
argvThe arguments provided
Returns
int
50 {
51  cout << "Starting agent_005" << endl;
52 
53  // Initialize agent parameters; its name, node and communicating agent
54  string agentname = "005"; // Forward facing name of the agent
55  string nodename = "cubesat1"; // The node that the agent will run on
56  string agent002 = "002"; // The name of the agent this agent will speak to
57 
58  // Construct agent with above parameters
59  agent = new Agent(nodename, agentname);
60 
61  // Exit if error is found
62  if (agent->last_error() < 0)
63  {
64  cout << "unable to start agent_exec (" << agent->last_error() << ") " << cosmos_error_string(agent->last_error()) << endl;
65  exit(1);
66  }
67 
68  beatstruc beat_agent_002 = agent->find_agent(nodename, agent002, 2.);
69 
70  string requestString = "request_hello"; // The name of agent_002's request
71  std::string response; // Variable to store agent_002's response
72 
73  // Start executing the agent
74  while (agent->running())
75  {
76  // Initiate request from agent_002
77  agent->send_request(beat_agent_002, requestString, response, 2.);
78 
79  // Check for response from agent_002
80  if (response.size() > 1) {
81  // The case if agent_002 is on and successfully receives the request
82  cout << "Received from agent_002: " << response.size() << " bytes : " << response << endl;
83 
84  // Clear the response for next time
85  response.clear();
86  }
87  else
88  {
89  // The case if agent_002 is not running
90  cout << "What happened to agent_002? Let's try to find it..." << endl;
91 
92  beat_agent_002.node[0] = '\0'; // reset
93  beat_agent_002 = agent->find_agent(nodename, agent002, 2.);
94 
95  cout << "Beat agent_002 node: " << beat_agent_002.utc << endl;
96  }
97 
98  // Sleep for 1 sec
99  COSMOS_SLEEP(1.);
100  }
101 
102  return 0;
103 }
Definition: jsondef.h:923
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: agent_005.cpp:40
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
char node[40+1]
Definition: jsondef.h:928
string agentname
Definition: agent_add_soh.cpp:53
Definition: agentclass.h:139
string nodename
Definition: agent_add_soh.cpp:54
int32_t last_error()
Definition: agentclass.cpp:414
beatstruc find_agent(string node, string agent, double waitsec=0.)
Find agent.
Definition: agentclass.cpp:559
double utc
Definition: jsondef.h:926
beatstruc beat_agent_002
Definition: agent_add_soh.cpp:60

Variable Documentation

Agent* agent
static