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

Functions

int main (int, char **)
 agent_008 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_008 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
51 {
52  cout << "Starting agent_001" << endl;
53 
54  // Initialize agent parameters; its name, node and communicating agent
55  string agentname = "008"; // Forward facing name of the agent
56  string nodename = "cubesat1"; // The node that the agent will run on
57  string agent004 = "004"; // The name of the agent this agent will speak to
58 
59  // Construct agent with above parameters
60  agent = new Agent(nodename, agentname);
61 
62  // Exit if error is found
63  if (agent->last_error() < 0)
64  {
65  cout << "unable to start agent_exec (" << agent->last_error() << ") " << cosmos_error_string(agent->last_error()) << endl;
66  exit(1);
67  }
68 
69  beatstruc beat_agent_004 = agent->find_agent(nodename, agent004, 2.);
70 
71  string requestString = "request_hello"; // The name of agent_002's request
72  std::string response; // Variable to store agent_002's response
73 
74  // Start executing the agent
75  while(agent->running())
76  {
77  // Initiate request from agent_002
78  agent->send_request(beat_agent_004, requestString, response, 2.);
79 
80  // Check for response from agent_002
81  if (response.size() > 1) {
82  // The case if agent_002 is on and successfully receives the request
83  cout << "Received from agent_004: " << response.size() << " bytes : " << response << endl;
84 
85  // Clear the response for next time
86  response.clear();
87  }
88  else
89  {
90  // The case if agent_002 is not running
91  cout << "What happened to agent_004? Let's try to find it..." << endl;
92 
93  beat_agent_004.node[0] = '\0'; // reset
94  beat_agent_004 = agent->find_agent(nodename, agent004, 2.);
95 
96  cout << "beat agent_004 node: " << beat_agent_004.utc << endl;
97  }
98 
99  // Sleep for 1 sec
100  COSMOS_SLEEP(1.);
101  }
102 
103  return 0;
104 }
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
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
static Agent * agent
Definition: agent_008.cpp:41
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

Variable Documentation

Agent* agent
static