179 #define AGENT_MULTIPLE true 180 #define AGENT_SINGLE false 182 #define AGENT_BLOCKING SOCKET_BLOCKING 184 #define AGENT_NONBLOCKING SOCKET_NONBLOCKING 186 #define AGENT_TALK SOCKET_TALK 188 #define AGENT_LISTEN SOCKET_LISTEN 190 #define AGENT_COMMUNICATE SOCKET_COMMUNICATE 192 #define AGENT_JABBER SOCKET_JABBER 196 #define AGENTBASE 10020 197 #define AGENTSENDPORT 10020 199 #define AGENTRECVPORT 10021 201 #define AGENTMCAST "225.1.1.1" 203 #define AGENTMAXLIST 500 205 #define AGENTMAXHEARTBEAT 200 207 #define AGENTRCVTIMEO 100000 209 #define AGENT_HEARTBEAT_PERIOD_MIN 0.01 213 #define MESSAGE_RING_SIZE 100 247 #define MAXARGCOUNT 100 344 void log(
string log_entry);
345 bool setSoh(
string sohFields);
423 static int32_t
req_echo(
string &request,
string &response,
Agent *agent);
424 static int32_t
req_help(
string &request,
string &response,
Agent *agent);
427 static int32_t
req_idle(
string &request,
string &response,
Agent *agent);
428 static int32_t
req_init(
string &request,
string &response,
Agent *agent);
429 static int32_t
req_monitor(
string &request,
string &response,
Agent *agent);
430 static int32_t
req_reset(
string &request,
string &response,
Agent *agent);
431 static int32_t
req_run(
string &request,
string &response,
Agent *agent);
432 static int32_t
req_status(
string &request,
string &response,
Agent *agent);
453 static int32_t
req_postsoh(
string &request,
string &response,
Agent *agent);
454 static int32_t
req_utc(
string &request,
string &response,
Agent *agent);
455 static int32_t
req_soh(
string &,
string &response,
Agent *agent);
462 #endif // COSMOSAGENT_H static string port
Definition: add_radio.cpp:16
static int32_t req_run(string &request, string &response, Agent *agent)
Built-in Set state to Run request.
Definition: agentclass.cpp:977
static int32_t req_help_json(string &request, string &response, Agent *agent)
Built-in Help request.
Definition: agentclass.cpp:900
Definition: agentclass.cpp:54
uint16_t debug_level
Flag for level of debugging, keep it public so that it can be controlled from the outside...
Definition: agentclass.h:362
int json_map_agentstruc(agentstruc **agent)
external_request_function efunction
Pointer to function to call with request string as argument and returning any error.
Definition: agentclass.h:407
int32_t finish_active_loop()
Definition: agentclass.cpp:355
string token
Character token for request.
Definition: agentclass.h:405
bool multiflag
Definition: agentclass.h:377
size_t message_tail
Last message rad in message ring buffer.
Definition: agentclass.h:359
FILE * get_debug_fd(double mjd=0.)
Definition: agentclass.cpp:2645
AgentMessage
Type of Agent Message. Types > 127 are binary.
Definition: agentclass.h:216
static int32_t req_get_position(string &request, string &response, Agent *agent)
Definition: agentclass.cpp:1253
string version
Definition: agentclass.h:381
double(* agent_time_producer)()
Function in which we generate our time, for the mjd request.
Definition: agentclass.h:398
beatstruc beat
Definition: agentclass.h:268
void get_ip_list(uint16_t port)
FILE * debug_fd
Definition: agentclass.h:379
Agent socket using Unicast UDP.
vector< uint8_t > bdata
Definition: agentclass.h:275
static int32_t req_utc(string &request, string &response, Agent *agent)
Definition: agentclass.cpp:1556
static double delta
Definition: agent_exec-2-0.cpp:141
static int32_t req_listnames(string &request, string &response, Agent *agent)
Built-in List Name Space Names request.
Definition: agentclass.cpp:1375
Definition: jsondef.h:923
uint16_t bsize
Definition: netperf_listen.cpp:71
int32_t receiveAll(uint8_t address, string &message)
string nodeName
Definition: agentclass.h:367
COSMOS SLIP support include file.
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
static int32_t req_facesjson(string &request, string &response, Agent *agent)
Built-in Return Face JSON request.
Definition: agentclass.cpp:1445
Where
Definition: agentclass.h:240
#define AGENTMAXLIST
Maximum AGENT server list count.
Definition: agentclass.h:204
int16_t count
Number of heartbeats in list.
Definition: agentclass.h:259
static int32_t req_jsondump(string &, string &response, Agent *agent)
Definition: agentclass.cpp:1576
static int32_t req_utcstartjson(string &request, string &response, Agent *agent)
Built-in Return UTC Start Time JSON request.
Definition: agentclass.cpp:1417
static int32_t req_piecesjson(string &request, string &response, Agent *agent)
Built-in Return Pieces JSON request.
Definition: agentclass.cpp:1431
static int32_t req_get_value(string &request, string &response, Agent *agent)
Definition: agentclass.cpp:1123
string hbjstring
Definition: agentclass.h:385
string metaHeader
Definition: agentclass.h:342
int32_t unsubscribe()
Close COSMOS subscription channel.
Definition: agentclass.cpp:2251
vector< socket_channel > find_addresses(NetworkType ntype)
Discover interfaces.
Definition: agentclass.cpp:1917
bool logTime
Definition: agentclass.h:383
int32_t wait(State state=State::RUN, double waitsec=10.)
Definition: agentclass.cpp:398
string output
Definition: agent-2-0.cpp:56
int32_t post_soh()
Definition: agentclass.cpp:2194
int32_t process_request(string &bufferin, string &bufferout)
Definition: agentclass.cpp:743
int32_t poll(messstruc &mess, AgentMessage type, float waitsec=1.)
Listen for message.
Definition: agentclass.cpp:2264
static int32_t req_nodejson(string &request, string &response, Agent *agent)
Built-in Return Node JSON request.
Definition: agentclass.cpp:1389
int32_t set_sohstring(string list)
Set Limited SOH string.
Definition: agentclass.cpp:641
static double epsilon
Definition: agent_exec-2-0.cpp:140
double timeoutSec
Definition: agentclass.h:382
string description
Definition: agentclass.h:409
double activeTimeout
Definition: agentclass.h:375
static int32_t req_status(string &request, string &response, Agent *agent)
Built-in Status request.
Definition: agentclass.cpp:1064
static int32_t req_fullsoh(string &, string &response, Agent *agent)
Definition: agentclass.cpp:1569
mutex process_mutex
mutex to protect process_request
Definition: agentclass.h:395
Definition: agentclass.h:256
string adata
Definition: agentclass.h:276
size_t message_head
Last message placed in message ring buffer.
Definition: agentclass.h:357
string node_name
Definition: agent_001.cpp:46
int32_t send(uint8_t address, string message)
static int32_t req_statejson(string &request, string &response, Agent *agent)
Built-in Return State Vector JSON request.
Definition: agentclass.cpp:1403
thread cthread
Handle for request thread.
Definition: agentclass.h:387
int32_t close_debug_fd()
Definition: agentclass.cpp:2692
static int32_t req_get_time(string &request, string &response, Agent *agent)
Definition: agentclass.cpp:1148
uint16_t running()
Check if we're supposed to be running.
Definition: agentclass.cpp:391
static int32_t req_setvalue(string &request, string &response, Agent *agent)
Built-in Set Internal Value request.
Definition: agentclass.cpp:1345
static int32_t req_reset(string &request, string &response, Agent *agent)
Built-in Set state to Reset request.
Definition: agentclass.cpp:1033
int32_t start()
Start Agent Request and Heartbeat loops.
Definition: agentclass.cpp:337
int32_t get_agent_time(double &agent_time, double &epsilon, double &delta, string agent, string node="any", double wait_sec=2.)
Definition: agentclass.cpp:2711
int32_t receive(uint8_t address, string &message)
int32_t get_agent(string node, string agent, double waitsec, beatstruc &cbeat)
Get specific server.
Definition: agentclass.cpp:513
int32_t post(messstruc mess)
Post a Cosmos::Agent::messstruc.
Definition: agentclass.cpp:2074
static int32_t req_debug_level(string &request, string &response, Agent *agent)
Definition: agentclass.cpp:1090
static int32_t req_getvalue(string &request, string &response, Agent *agent)
Built-in Get Internal Value request.
Definition: agentclass.cpp:1105
char address[]
Definition: netperf_listen.cpp:69
int32_t publish(NetworkType type, uint16_t port)
Open COSMOS output channel.
Definition: agentclass.cpp:1588
Definition: devicecpu.h:239
Definition: agentclass.h:264
int32_t check_agent(string node, string agent, double waitsec)
Check agent.
Definition: agentclass.cpp:546
int32_t resizering(size_t newsize)
Definition: agentclass.cpp:2454
int32_t unpublish()
Close COSMOS output channel.
Definition: agentclass.cpp:2205
char * parse_request(char *input)
static char buffer[255]
Definition: propagator_simple.cpp:60
string getAgent()
Definition: agentclass.cpp:2609
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
static Agent * agent
ensure the Agent constructor creates only one instance per process
Definition: agent_001.cpp:45
int32_t set_fullsohstring(string list)
Set Full SOH string.
Definition: agentclass.cpp:654
static int32_t req_soh(string &, string &response, Agent *agent)
Definition: agentclass.cpp:1562
int32_t parsering(AgentMessage type=Agent::AgentMessage::ALL, float waitsec=1., Where where=Where::HEAD, string proc="", string node="")
Parse next message from ring.
Definition: agentclass.cpp:2428
uint8_t message[300]
Definition: kpc9612p_send.cpp:36
bool setSoh(string sohFields)
int waitsec
Definition: agent_add_soh.cpp:56
static int32_t req_monitor(string &request, string &response, Agent *agent)
Built-in Set state to Monitor request.
Definition: agentclass.cpp:1019
Definition: agentclass.h:139
JSON Support definitions.
uint32_t bufferSize
Definition: agentclass.h:376
Headers and definitions common to all COSMOS.
uint16_t jlength
Definition: agentclass.h:267
NetworkType
Definition: socketlib.h:63
Socket Support header file.
void heartbeat_loop()
Heartbeat Loop.
Definition: agentclass.cpp:671
static int32_t req_devspecjson(string &request, string &response, Agent *agent)
Built-in Return devspec JSON request.
Definition: agentclass.cpp:1487
Agent(const string &node_name="", const string &agent_name="", double bprd=0., uint32_t bsize=AGENTMAXBUFFER, bool mflag=false, int32_t portnum=0, NetworkType ntype=NetworkType::UDP, uint16_t dlevel=1)
Definition: agentclass.cpp:78
static int32_t req_echo(string &request, string &response, Agent *agent)
Built-in Echo request.
Definition: agentclass.cpp:880
int32_t shutdown()
Shutdown agent gracefully.
Definition: agentclass.cpp:366
void log(string log_entry)
DeviceCpu deviceCpu_
Definition: agentclass.h:420
vector< beatstruc > slist
Definition: agentclass.h:369
Storage for messages.
Definition: agentclass.h:272
vector< jsonentry * > fullsohtable
Definition: agentclass.h:157
double mjd
Definition: udp_send.cpp:41
timelib include file A library providing functions for handling various types of time.
int32_t portNumber
Definition: agentclass.h:378
static int32_t req_idle(string &request, string &response, Agent *agent)
Built-in Set state to Idle request.
Definition: agentclass.cpp:1005
#define MESSAGE_RING_SIZE
Default size of message ring buffer.
Definition: agentclass.h:213
int32_t set_agent_time_producer(double(*source)())
Definition: agentclass.cpp:2704
thread mthread
Handle for message thread.
Definition: agentclass.h:391
double currentmjd(double offset)
Current UTC in Modified Julian Days.
Definition: timelib.cpp:65
int32_t post_beat()
Definition: agentclass.cpp:2178
Elapsed Time header file.
~Agent()
Definition: agentclass.cpp:269
Agent control structure.
Definition: jsondef.h:1006
int32_t last_error()
Definition: agentclass.cpp:414
int32_t clearring()
Definition: agentclass.cpp:2466
pollstruc meta
Definition: agentclass.h:274
string jdata
Definition: agentclass.h:277
Do minimal necessary to run.
beatstruc find_agent(string node, string agent, double waitsec=0.)
Find agent.
Definition: agentclass.cpp:559
string agent_name
Definition: agent_001.cpp:47
AgentMessage type
Definition: agentclass.h:266
int32_t error_value
Last error.
Definition: agentclass.h:393
Definition: jsondef.h:724
NetworkType networkType
Definition: agentclass.h:374
NetworkType ntype
Definition: agent_node.cpp:50
static int32_t req_init(string &request, string &response, Agent *agent)
Built-in Set state to Init request.
Definition: agentclass.cpp:991
thread hthread
Handle for heartbeat thread.
Definition: agentclass.h:389
static string source
Definition: ax25_recv.cpp:42
deque< messstruc > message_queue
Ring buffer for incoming messages.
Definition: agentclass.h:355
void message_loop()
Definition: agentclass.cpp:806
cosmosstruc * get_cosmosstruc()
Return Agent cosmosstruc.
Definition: agentclass.cpp:664
static int32_t req_heartbeat(string &request, string &response, Agent *agent)
Built-in Send Heartbeat request.
Definition: agentclass.cpp:1539
vector< request_entry > reqs
Definition: agentclass.h:412
stringlib include file A library providing functions for handling various types of string...
static int32_t req_set_value(string &request, string &response, Agent *agent)
Definition: agentclass.cpp:1352
int32_t start_active_loop()
Definition: agentclass.cpp:347
int32_t send_request_jsonnode(beatstruc cbeat, jsonnode &jnode, float waitsec=5.)
Send request for Node JSON.
Definition: agentclass.cpp:477
static beatstruc cbeat
Definition: agent_file.cpp:92
cosmosstruc * cinfo
Definition: agentclass.h:346
void get_ip(char *buffer, size_t buflen)
pollstruc metaRx
Definition: agentclass.h:341
#define AGENTMAXBUFFER
Maximum AGENT transfer buffer size.
Definition: jsondef.h:438
static int32_t req_forward(string &request, string &response, Agent *agent)
Built-in Forward request.
Definition: agentclass.cpp:856
static int32_t req_vertexsjson(string &request, string &response, Agent *agent)
Built-in Return Vertex JSON request.
Definition: agentclass.cpp:1459
static int32_t req_portsjson(string &request, string &response, Agent *agent)
Built-in Return Ports JSON request.
Definition: agentclass.cpp:1501
vector< beatstruc > agent_list
List of active agents.
Definition: agentclass.h:349
int32_t(* external_request_function)(string &request_string, string &output_string, Agent *agent)
Definition: agentclass.h:282
vector< jsonentry * > sohtable
State of Health element vector.
Definition: agentclass.h:156
static int32_t req_help(string &request, string &response, Agent *agent)
Definition: agentclass.cpp:947
string debug_pathName
Definition: agentclass.h:380
static string node
Definition: agent_monitor.cpp:126
Definition: jsondef.h:4199
Definition: agentclass.h:402
vector< jsonnode > node_list
List of active Nodes.
Definition: agentclass.h:351
double timeStart
Definition: agentclass.h:384
Inertial Measurement Unit.
Definition: jsondef.h:496
int32_t getJson(string node, jsonnode &jnode)
Definition: agentclass.cpp:2612
string synopsis
Definition: agentclass.h:408
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
vector< beatstruc > find_agents(double waitsec=0.)
Find single server.
Definition: agentclass.cpp:605
static int32_t req_targetsjson(string &request, string &response, Agent *agent)
Built-in Return Target JSON request.
Definition: agentclass.cpp:1520
string agentName
Definition: agentclass.h:368
static int32_t req_devgenjson(string &request, string &response, Agent *agent)
Built-in Return devgen JSON request.
Definition: agentclass.cpp:1473
void request_loop() noexcept
Request Loop.
Definition: agentclass.cpp:722
int32_t subscribe(NetworkType type, const char *address, uint16_t port)
Open COSMOS channel for polling with 100 usec timeout.
Definition: agentclass.cpp:2242
State
Definition: agentclass.h:159
static int32_t req_shutdown(string &request, string &response, Agent *agent)
Built-in Set state to Shutdown request.
Definition: agentclass.cpp:1047
static int32_t req_get_position_data(string &request, string &response, Agent *agent)
Definition: agentclass.cpp:1156
static int32_t req_postsoh(string &request, string &response, Agent *agent)
Definition: agentclass.cpp:1548