71 if (agent->
cinfo ==
nullptr)
83 printf(
"Usage: agent [ list | dump [soh, beat, ###] | node_name agent_name \"request [ arguments ]\" ]\n");
92 if (!strcmp(argv[1],
"dump"))
94 double lmjd = 0., dmjd;
111 if (channel ==
"soh")
113 message_type = Agent::AgentMessage::SOH;
115 else if (channel ==
"beat")
117 message_type = Agent::AgentMessage::BEAT;
119 else if (channel ==
"request")
121 message_type = Agent::AgentMessage::REQUEST;
123 else if (channel ==
"response")
125 message_type = Agent::AgentMessage::RESPONSE;
134 message_type = Agent::AgentMessage::ALL;
141 if ((iretn=agent->
readring(message, message_type, 1., Agent::Where::TAIL)) > 0)
146 if (!channel.empty() && message_type != message_type_read)
161 switch (message_type_read)
163 case Agent::AgentMessage::SOH:
166 case Agent::AgentMessage::BEAT:
169 case Agent::AgentMessage::REQUEST:
172 case Agent::AgentMessage::RESPONSE:
173 printf(
"[RESPONSE]");
176 printf(
"[%d]",message_type_read);
181 printf(
"%s\n",message.
jdata.c_str());
182 if (message_type_read < Agent::AgentMessage::BINARY)
184 if (!channel.empty())
186 printf(
"%s\n",message.
adata.c_str());
190 if ((channel==
"info") && message_type_read == Agent::AgentMessage::TRACK)
210 dmjd = 86400.*(agent->
cinfo->
agent[0].beat.utc-lmjd);
213 printf(
"%.15g %.4g\n",loc.
utc,dmjd);
223 else if (!strcmp(argv[1],
"list"))
225 size_t agent_count = 0;
227 agent->
post(Agent::AgentMessage::REQUEST,
"heartbeat");
231 for (
size_t i=agent_count; i<agent->
agent_list.size(); ++
i) {
237 printf(
"[%lu] %.15g %s %s %s %hu %u\n",i,cbeat.
utc,cbeat.
node,cbeat.
proc,cbeat.
addr,cbeat.
port,cbeat.
bsz);
238 printf(
"\t%s\n",
output.c_str());
247 }
else if (!strcmp(argv[1],
"list_json")) {
248 size_t agent_count = 0;
250 agent->
post(Agent::AgentMessage::REQUEST,
"heartbeat");
252 printf(
"{\"agent_list\":[");
255 for (
size_t i=agent_count; i<agent->
agent_list.size(); ++
i) {
263 printf(
"{\"agent_proc\": \"%s\", ", cbeat.
proc);
264 printf(
"\"agent_utc\": %.15g, ", cbeat.
utc);
265 printf(
"\"agent_node\": \"%s\", ", cbeat.
node);
266 printf(
"\"agent_addr\": \"%s\", ", cbeat.
addr);
267 printf(
"\"agent_port\": %hu, ", cbeat.
port);
268 printf(
"\"agent_bsz\": %u, ", cbeat.
bsz);
271 if((status_pos=
output.find(
"[OK]") )!= string::npos){
273 if(status_pos - 1 >= 0 &&
output.at(status_pos - 1) ==
'}'){
274 printf(
"\"output\": %s,",
output.substr(0, status_pos).c_str());
276 printf(
"\"output\": %s,",
output.c_str());
279 printf(
"\"output\": \"%s\",",
output.substr(status_pos ).c_str());
281 printf(
"\"status\": \"OK\"}");
282 }
else if((status_pos =
output.find(
"[NOK]") )!= string::npos){
283 printf(
"\"status\": \"NOK\"}");
285 printf(
"\"output\": %s }",
output.c_str());
300 if (!strcmp(argv[1],
"dump")) {
301 double lmjd = 0., dmjd;
311 if (channel ==
"soh") {
312 message_type = Agent::AgentMessage::SOH;
314 if (channel ==
"beat") {
315 message_type = Agent::AgentMessage::BEAT;
322 message_type = Agent::AgentMessage::ALL;
328 if ((iretn=agent->
readring(message, Agent::AgentMessage::ALL, 1., Agent::Where::TAIL)) > 0) {
331 if (!channel.empty() && message_type != message_type_read) {
continue; }
334 if (message_type_read < Agent::AgentMessage::BINARY)
346 switch (message_type_read) {
347 case Agent::AgentMessage::SOH:
350 case Agent::AgentMessage::BEAT:
353 case Agent::AgentMessage::REQUEST:
356 case Agent::AgentMessage::RESPONSE:
357 printf(
"[RESPONSE]");
360 printf(
"[%d]",message_type_read);
366 if (message_type_read < Agent::AgentMessage::BINARY && !channel.empty()) {
367 printf(
"%s\n",message.
adata.c_str());
370 if ((channel==
"info") && message_type_read == Agent::AgentMessage::TRACK) {
388 dmjd = 86400.*(agent->
cinfo->
agent[0].beat.utc-lmjd);
391 printf(
"%.15g %.4g\n",loc.
utc,dmjd);
407 printf(
"%s [%d]\n",
output.c_str(), nbytes);
413 for (
size_t i=0; i<(size_t)argc-4; ++
i)
416 request += argv[i+4];
424 if((status_pos=
output.find(
"[OK]") )!= string::npos){
426 if(status_pos - 1 >= 0 &&
output.at(status_pos - 1) ==
'}'){
427 printf(
"\"output\": %s,",
output.substr(0, status_pos).c_str());
429 printf(
"\"output\": %s,",
output.c_str());
432 printf(
"\"output\": \"%s\",",
output.substr(0,status_pos ).c_str());
434 printf(
"\"status\": \"OK\"}\n");
435 }
else if((status_pos =
output.find(
"[NOK]") )!= string::npos){
436 printf(
"\"status\": \"NOK\"}\n");
438 printf(
"\"output\": %s }\n",
output.c_str());
443 fprintf(stderr,
"node-agent pair [%s:%s] not found\n",argv[1],argv[2]);
444 printf(
"{\"error\": \"node-agent pair [%s:%s] not found\" }\n",argv[1],argv[2]);
447 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
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
string output
Definition: agent-2-0.cpp:56
devicestruc
Definition: jsondef.h:150
ElapsedTime et
Definition: agent_cpu_device_test.cpp:51
const int SERVER_WAIT_TIME
Definition: agent-2-0.cpp:54
string adata
Definition: agentclass.h:276
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
string node_name
Definition: agent-2-0.cpp:57
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
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
const int REQUEST_WAIT_TIME
Definition: agent-2-0.cpp:53
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
string agent_name
Definition: agent-2-0.cpp:58
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
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
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
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