85     if (agent->
cinfo == 
nullptr)
    97             printf(
"Usage: agent [ list | dump [soh, beat, ###] | node_name agent_name \"request [ arguments ]\" ]\n");
   109         if (!strcmp(argv[1],
"dump"))
   111             double lmjd = 0., dmjd;
   128                 if (channel == 
"soh")
   130                     cnum = Agent::AgentMessage::SOH;
   132                 else if (channel == 
"beat")
   134                     cnum = Agent::AgentMessage::BEAT;
   136                 else if (channel == 
"request")
   138                     cnum = Agent::AgentMessage::REQUEST;
   140                 else if (channel == 
"response")
   142                     cnum = Agent::AgentMessage::RESPONSE;
   151                 cnum = Agent::AgentMessage::ALL;
   158                 if ((iretn=agent->
readring(message, cnum, 1., Agent::Where::TAIL)) > 0)
   163                     if (!channel.empty() && cnum != pretn)
   180                     case Agent::AgentMessage::SOH:
   183                     case Agent::AgentMessage::BEAT:
   186                     case Agent::AgentMessage::REQUEST:
   189                     case Agent::AgentMessage::RESPONSE:
   190                         printf(
"[RESPONSE]");
   193                         printf(
"[%d]",pretn);
   198                     printf(
"%s\n",message.
jdata.c_str());
   199                     if (pretn < Agent::AgentMessage::BINARY)
   201                         if (!channel.empty())
   203                             printf(
"%s\n",message.
adata.c_str());
   207                     if ((channel==
"info") && pretn == Agent::AgentMessage::TRACK)
   230                                     dmjd = 86400.*(agent->
cinfo->
agent[0].beat.utc-lmjd);
   233                                 printf(
"%.15g %.4g\n",loc.
utc,dmjd);
   243         else if (!strcmp(argv[1],
"list"))
   245             size_t agent_count = 0;
   247             agent->
post(Agent::AgentMessage::REQUEST, 
"heartbeat");
   253                     for (
size_t i=agent_count; i<agent->
agent_list.size(); ++
i)
   257                         printf(
"[%lu] %.15g %s %s %s %hu %u\n",i,cbeat.
utc,cbeat.
node,cbeat.
proc,cbeat.
addr,cbeat.
port,cbeat.
bsz);
   258                         printf(
"\t%s\n",
output.c_str());
   269         else if (!strcmp(argv[1],
"list_json"))
   271             size_t agent_count = 0;
   273             agent->
post(Agent::AgentMessage::REQUEST, 
"heartbeat");
   275             printf(
"{\"agent_list\":[");
   281                     for (
size_t i=agent_count; i<agent->
agent_list.size(); ++
i)
   286                         printf(
"{\"agent_proc\": \"%s\", ", cbeat.
proc);
   287                         printf(
"\"agent_utc\": %.15g, ", cbeat.
utc);
   288                         printf(
"\"agent_node\": \"%s\", ", cbeat.
node);
   289                         printf(
"\"agent_addr\": \"%s\", ", cbeat.
addr);
   290                         printf(
"\"agent_port\": %hu, ", cbeat.
port);
   291                         printf(
"\"agent_bsz\": %u, ", cbeat.
bsz);
   294                         if((status_pos= 
output.find(
"[OK]")  )!= string::npos){
   296                                 if(status_pos - 1 >= 0 && 
output.at(status_pos - 1) == 
'}'){
   297                                     printf(
"\"output\": %s,", 
output.substr(0, status_pos).c_str());
   299                                     printf(
"\"output\": %s,", 
output.c_str());
   302                                 printf(
"\"output\": \"%s\",", 
output.substr(status_pos ).c_str());
   304                             printf(
"\"status\": \"OK\"}");
   305                         } 
else if((status_pos = 
output.find(
"[NOK]") )!= string::npos){
   306                             printf(
"\"status\": \"NOK\"}");
   308                              printf(
"\"output\": %s }", 
output.c_str());
   324         if (!strcmp(argv[1],
"dump"))
   326             double lmjd = 0., dmjd;
   337                 if (channel == 
"soh")
   339                     cnum = Agent::AgentMessage::SOH;
   343                     if (channel == 
"beat")
   345                         cnum = Agent::AgentMessage::BEAT;
   356                 cnum = Agent::AgentMessage::ALL;
   362                 if ((iretn=agent->
readring(message, Agent::AgentMessage::ALL, 1., Agent::Where::TAIL)) > 0)
   366                     if (!channel.empty() && cnum != pretn)
   372                     if (pretn < Agent::AgentMessage::BINARY)
   386                     case Agent::AgentMessage::SOH:
   389                     case Agent::AgentMessage::BEAT:
   392                     case Agent::AgentMessage::REQUEST:
   395                     case Agent::AgentMessage::RESPONSE:
   396                         printf(
"[RESPONSE]");
   399                         printf(
"[%d]",pretn);
   405                     if (pretn < Agent::AgentMessage::BINARY && !channel.empty())
   407                         printf(
"%s\n",message.
adata.c_str());
   410                     if ((channel==
"info") && pretn == Agent::AgentMessage::TRACK)
   433                                     dmjd = 86400.*(agent->
cinfo->
agent[0].beat.utc-lmjd);
   436                                 printf(
"%.15g %.4g\n",loc.
utc,dmjd);
   456                 printf(
"%s [%d]\n", 
output.c_str(), nbytes);
   462                 for (
size_t i=0; i<(size_t)argc-4; ++
i)
   465                     request += argv[i+4];
   473                 if((status_pos= 
output.find(
"[OK]")  )!= string::npos){
   475                         if(status_pos - 1 >= 0 && 
output.at(status_pos - 1) == 
'}'){
   476                             printf(
"\"output\": %s,", 
output.substr(0, status_pos).c_str());
   478                             printf(
"\"output\": %s,", 
output.c_str());
   481                         printf(
"\"output\": \"%s\",", 
output.substr(0,status_pos ).c_str());
   483                     printf(
"\"status\": \"OK\"}\n");
   484                 } 
else if((status_pos = 
output.find(
"[NOK]") )!= string::npos){
   485                     printf(
"\"status\": \"NOK\"}\n");
   487                      printf(
"\"output\": %s }\n", 
output.c_str());
   494                 fprintf(stderr,
"node-agent pair [%s:%s] not found\n",argv[1],argv[2]);
   495                 printf(
"{\"error\": \"node-agent pair [%s:%s] not found\" }\n",argv[1],argv[2]);
   498                 printf(
"Error: %d\n", nbytes);
 uint16_t imu_cnt
Definition: jsondef.h:3871
FILE * get_debug_fd(double mjd=0.)
Definition: agentclass.cpp:2645
AgentMessage
Type of Agent Message. Types > 127 are binary. 
Definition: agentclass.h:216
beatstruc beat
Definition: agentclass.h:268
vector< uint8_t > bdata
Definition: agentclass.h:275
Definition: jsondef.h:923
int i
Definition: rw_test.cpp:37
int32_t json_parse(string jstring, cosmosstruc *cinfo)
Parse JSON using Name Space. 
Definition: jsonlib.cpp:4799
int32_t send_request(beatstruc cbeat, string request, string &output, float waitsec=5.)
Send a request over AGENT. 
Definition: agentclass.cpp:424
string getNode()
Listen for heartbeat. 
Definition: agentclass.cpp:2607
string node_name
Definition: agent.cpp:70
uint32_t bsz
Transfer buffer size. 
Definition: jsondef.h:938
char addr[18]
Protocol Address. 
Definition: jsondef.h:934
float battlev
Definition: jsondef.h:3431
int iretn
Definition: rw_test.cpp:37
int32_t json_clear_cosmosstruc(int32_t type, cosmosstruc *cinfo)
Clear global data structure. 
Definition: jsonlib.cpp:6268
double utc
Master time for location, in Modified Julian Day. 
Definition: convertdef.h:879
devicestruc 
Definition: jsondef.h:150
ElapsedTime et
Definition: agent_cpu_device_test.cpp:51
string adata
Definition: agentclass.h:276
vector< string > data_list_nodes()
Get list of Nodes, directly. 
Definition: datalib.cpp:583
nodestruc node
Structure for summary information in node. 
Definition: jsondef.h:4220
string cosmos_error_string(int32_t cosmos_errno)
Definition: cosmos-errno.cpp:45
int32_t get_agent(string node, string agent, double waitsec, beatstruc &cbeat)
Get specific server. 
Definition: agentclass.cpp:513
rvector s
Location. 
Definition: convertdef.h:163
int32_t post(messstruc mess)
Post a Cosmos::Agent::messstruc. 
Definition: agentclass.cpp:2074
char proc[40+1]
Heartbeat Agent Name. 
Definition: jsondef.h:930
char node[40+1]
Definition: jsondef.h:928
string getAgent()
Definition: agentclass.cpp:2609
static Agent * agent
ensure the Agent constructor creates only one instance per process 
Definition: agent_001.cpp:45
string output
Definition: agent.cpp:69
double utc
Definition: convertdef.h:735
uint8_t message[300]
Definition: kpc9612p_send.cpp:36
char name[40+1]
Node Name. 
Definition: jsondef.h:3556
uint16_t port
AGENT port. 
Definition: jsondef.h:936
Definition: agentclass.h:139
uint16_t jlength
Definition: agentclass.h:267
locstruc loc
Location structure. 
Definition: jsondef.h:3596
#define DEGOF(rad)
Degrees of a Radian value. 
Definition: math/constants.h:33
int32_t pos_eci(locstruc *loc)
Set ECI position. 
Definition: convertlib.cpp:258
double h
Height in meters. 
Definition: vector.h:229
Storage for messages. 
Definition: agentclass.h:272
nodestruc 
Definition: jsondef.h:146
double lon
Longitude in radians. 
Definition: vector.h:227
double data_ctime(string path)
Definition: datalib.cpp:1910
float powuse
Definition: jsondef.h:3433
const int REQUEST_WAIT_TIME
Definition: agent.cpp:53
Definition: elapsedtime.h:62
double currentmjd(double offset)
Current UTC in Modified Julian Days. 
Definition: timelib.cpp:65
posstruc pos
posstruc for this time. 
Definition: convertdef.h:881
gvector s
Position vector. 
Definition: convertdef.h:263
double lat
Latitude in radians. 
Definition: vector.h:225
pollstruc meta
Definition: agentclass.h:274
string jdata
Definition: agentclass.h:277
const int SERVER_WAIT_TIME
Definition: agent.cpp:54
string utc2iso8601(double utc)
ISO 8601 version of time. 
Definition: timelib.cpp:1286
vector< agentstruc > agent
Single entry vector for agent information. 
Definition: jsondef.h:4247
double utc
Definition: jsondef.h:926
static beatstruc cbeat
Definition: agent_file.cpp:92
cosmosstruc * cinfo
Definition: agentclass.h:346
vector< beatstruc > agent_list
List of active agents. 
Definition: agentclass.h:349
geoidpos geod
Definition: convertdef.h:741
string agent_name
Definition: agent.cpp:71
devspecstruc devspec
Structure for devices (components) special data in node, by type. 
Definition: jsondef.h:4241
double split()
ElapsedTime::split, gets the current elapsed time since the start() 
Definition: elapsedtime.cpp:234
string mjd2iso8601(double mjd)
Definition: timelib.cpp:1316
cartpos icrf
Definition: convertdef.h:736
Inertial Measurement Unit. 
Definition: jsondef.h:496
Definition: convertdef.h:876
physicsstruc phys
Definition: jsondef.h:3597
int32_t readring(messstruc &message, AgentMessage type=Agent::AgentMessage::ALL, float waitsec=1., Where where=Where::TAIL, string proc="", string node="")
Check Ring for message. 
Definition: agentclass.cpp:2395
float powgen
Definition: jsondef.h:3432
#define NODE_ERROR_NODE
Definition: cosmos-errno.h:143