COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
agent_generic_device_test.cpp File Reference
#include "configCosmos.h"
#include "elapsedtime.h"
#include "timeutils.hpp"
#include "agentlib.h"
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
Include dependency graph for agent_generic_device_test.cpp:

Functions

int agentloop ()
 
int generic_node_test (int telem_num, string type)
 
int set_zeros (int telem_num, string type)
 
int main (int argc, char *argv[])
 

Variables

Agent agent
 
string agentname = "generic_device_test"
 
string nodename = "telem"
 
string agent_neighbor = "generic_device_neighbor"
 
uint32_t itemp = 0
 
beatstruc beat_agent_neighbour
 

Function Documentation

int agentloop ( )
80 {
81  cout << "agent " << agentname << " ...online " << endl;
82 
83  //int telem_num = 0;
84 
85  // reset telemetry streams
86  set_zeros(0, "vuint8");
87  set_zeros(1, "vint8");
88  set_zeros(2, "vuint16");
89  set_zeros(3, "vint16");
90  set_zeros(4, "vuint32");
91  set_zeros(5, "vint32");
92  set_zeros(6, "vfloat");
93  set_zeros(7, "vdouble");
94  set_zeros(8, "vstring");
95 
96 
97  // Start executing the agent
98  while(agent.isRunning())
99  {
100 
101  cout << "-------------------" << endl;
102 
103  generic_node_test(0,"vuint8"); // test telemetry stream with uint8
104  generic_node_test(1,"vint8"); // test telemetry stream with int8
105  generic_node_test(2,"vuint16"); // test telemetry stream with uint16
106  generic_node_test(3,"vint16"); // test telemetry stream with int16
107  generic_node_test(4,"vuint32"); // test telemetry stream with uint32
108  generic_node_test(5,"vint32"); // test telemetry stream with int32
109  generic_node_test(6,"vfloat"); // test telemetry stream with float
110  generic_node_test(7,"vdouble"); // test telemetry stream with double
111  generic_node_test(8,"vstring"); // test telemetry stream with string
112 
113  COSMOS_SLEEP(0.05);
114 
115  }
116  return (0);
117 
118 }
string agentname
Definition: agent_generic_device_test.cpp:49
Agent agent
Definition: agent_generic_device_test.cpp:48
int set_zeros(int telem_num, string type)
Definition: agent_generic_device_test.cpp:275
int generic_node_test(int telem_num, string type)
Definition: agent_generic_device_test.cpp:122
int generic_node_test ( int  telem_num,
string  type 
)
122  {
123  string request;
124  string response;
125  //char response_c_str[300];
126  int iretn;
127 
128  // convert device number to string: 2 -> "002"
129  ostringstream dev_number_string;
130  dev_number_string << setw(3) << setfill('0') << telem_num;
131 
132  // command ex.: getvalue {\"device_telem_vuint16_002\"}
133  request = "getvalue {\"device_telem_" + type + "_" + dev_number_string.str() + "\"}";
134 
135  // makes a request to agent get
136  iretn = agent.sendRequest(beat_agent_neighbour, request, response);
137 
138  //cout << "return:" << iretn << endl;
139 
140  // response = string(response_c_str);
141  json_parse(response,agent.cdata);
142 
143  string value_str; //value_str_rep
144 
145  if (type == "vuint8"){
146  uint8_t value = agent.cdata->devspec.telem[telem_num]->vuint8;
147  value_str = to_string((int)value);
148  // value_str_rep = string(cdata->devspec.telem[telem_num]->vstring);
149  }
150 
151  if (type == "vint8"){
152  int8_t value= agent.cdata->devspec.telem[telem_num]->vint8;
153  value_str = to_string((int)value);
154  // value_str_rep = string(agent.cdata->devspec.telem[telem_num]->vstring);
155  }
156 
157  if (type == "vuint16"){
158  uint16_t value= agent.cdata->devspec.telem[telem_num]->vuint16;
159  value_str = to_string(value);
160  // value_str_rep = string(agent.cdata->devspec.telem[telem_num]->vstring);
161  }
162 
163  if (type == "vint16"){
164  int16_t value= agent.cdata->devspec.telem[telem_num]->vint16;
165  value_str = to_string(value);
166  // value_str_rep = string(agent.cdata->devspec.telem[telem_num]->vstring);
167  }
168 
169  if (type == "vuint32"){
170  uint32_t value= agent.cdata->devspec.telem[telem_num]->vuint32;
171  value_str = to_string(value);
172  // value_str_rep = string(agent.cdata->devspec.telem[telem_num]->vstring);
173  }
174 
175  if (type == "vint32"){
176  int32_t value= agent.cdata->devspec.telem[telem_num]->vint32;
177  value_str = to_string(value);
178  // value_str_rep = string(agent.cdata->devspec.telem[telem_num]->vstring);
179  }
180 
181  if (type == "vfloat"){
182  float value= agent.cdata->devspec.telem[telem_num]->vfloat;
183  value_str = to_string(value);
184  // value_str_rep = string(agent.cdata->devspec.telem[telem_num]->vstring);
185  }
186 
187  if (type == "vdouble"){
188  double value= agent.cdata->devspec.telem[telem_num]->vdouble;
189  value_str = to_string(value);
190  // value_str_rep = string(agent.cdata->devspec.telem[telem_num]->vstring);
191  }
192 
193  if (type == "vstring"){
194  value_str = string(agent.cdata->devspec.telem[telem_num]->vstring);
195  // value_str_rep = value_str;
196  }
197 
198  if ( response.size() > 1){
199 
200  // print status
201  cout << "rx telem stream #" << telem_num
202  << " (" << type << ") \t : " << value_str << endl; //" str (" << value_str_rep << ")" << endl;
203 
204  // just increment the value by 1
205 
206  if (type == "vuint8"){
207  agent.cdata->devspec.telem[telem_num]->vuint8 ++;
208  value_str = to_string(agent.cdata->devspec.telem[telem_num]->vuint8);
209  }
210 
211  if (type == "vint8"){
212  agent.cdata->devspec.telem[telem_num]->vint8 ++;
213  value_str = to_string(agent.cdata->devspec.telem[telem_num]->vint8);
214  }
215 
216  if (type == "vuint16"){
217  agent.cdata->devspec.telem[telem_num]->vuint16 ++;
218  value_str = to_string(agent.cdata->devspec.telem[telem_num]->vuint16);
219  }
220 
221  if (type == "vint16"){
222  agent.cdata->devspec.telem[telem_num]->vint16 ++;
223  value_str = to_string(agent.cdata->devspec.telem[telem_num]->vint16);
224  }
225 
226  if (type == "vuint32"){
227  agent.cdata->devspec.telem[telem_num]->vuint32 ++;
228  value_str = to_string(agent.cdata->devspec.telem[telem_num]->vuint32);
229  }
230 
231  if (type == "vint32"){
232  agent.cdata->devspec.telem[telem_num]->vint32 ++;
233  value_str = to_string(agent.cdata->devspec.telem[telem_num]->vint32);
234  }
235 
236  if (type == "vfloat"){
237  agent.cdata->devspec.telem[telem_num]->vfloat += 0.1;
238  value_str = to_string(agent.cdata->devspec.telem[telem_num]->vfloat);
239  }
240 
241  if (type == "vdouble"){
242  agent.cdata->devspec.telem[telem_num]->vdouble += 0.1;
243  value_str = to_string(agent.cdata->devspec.telem[telem_num]->vdouble);
244  }
245 
246  if (type == "vstring"){
247  //agent.cdata->devspec.telem[telem_num]->vstring = "asd";
248  //value_str = to_string(agent.cdata->devspec.telem[telem_num]->vuint8);
249  //itemp = atol(value_str.c_str());
250  ++itemp;
251  sprintf(agent.cdata->devspec.telem[telem_num]->vstring, "\"str%u\"", itemp);
252  value_str = string(agent.cdata->devspec.telem[telem_num]->vstring);
253  }
254 
255 
256  // now send the new value to the neighbour agent
257  // command ex.: setvalue {\"device_telem_vuint16_002\"}
258  request = "setvalue {\"device_telem_"+type+"_"
259  + dev_number_string.str() + "\":"
260  + value_str
261  + "}";
262 
263  // makes a request to agent get
264  iretn = agent.sendRequest(beat_agent_neighbour, request, response);
265 
266  //cout << "Received from agent_neighbour: " << response.size() << " bytes : " << response << endl;
267  response = "";
268  }
269 
270  return iretn;
271 }
int32_t json_parse(string jstring, cosmosstruc *cinfo)
Parse JSON using Name Space.
Definition: jsonlib.cpp:4799
string to_string(char *value)
Definition: stringlib.cpp:220
int iretn
Definition: rw_test.cpp:37
uint32_t itemp
Definition: agent_generic_device_test.cpp:52
beatstruc beat_agent_neighbour
Definition: agent_generic_device_test.cpp:53
Agent agent
Definition: agent_generic_device_test.cpp:48
int set_zeros ( int  telem_num,
string  type 
)
275  {
276  string request;
277  string response;
278  //char response_c_str[300];
279  int iretn;
280 
281  // convert device number to string: 2 -> "002"
282  ostringstream dev_number_string;
283  dev_number_string << setw(3) << setfill('0') << telem_num;
284 
285 
286  if (type == "vstring"){
287  request = "setvalue {\"device_telem_"+type+"_"
288  + dev_number_string.str() + "\":"
289  + "\"str0\""
290  + "}";
291  } else {
292  // now send the new value to the neighbour agent
293  // command ex.: setvalue {\"device_telem_vuint16_002\"}
294  request = "setvalue {\"device_telem_"+type+"_"
295  + dev_number_string.str() + "\":"
296  + to_string(0)
297  + "}";
298  }
299 
300  // makes a request to agent get
301  iretn = agent.sendRequest(beat_agent_neighbour, request, response);
302 
303  return iretn;
304 }
string to_string(char *value)
Definition: stringlib.cpp:220
int iretn
Definition: rw_test.cpp:37
beatstruc beat_agent_neighbour
Definition: agent_generic_device_test.cpp:53
Agent agent
Definition: agent_generic_device_test.cpp:48
int main ( int  argc,
char *  argv[] 
)
56 {
57 
58  agent.setupServer(nodename, agentname);
59 
61 
62  //beat_agent_neighbour = agent_find_server(cdata, nodename, agent_neighbor, 5.);
63 
64  if (beat_agent_neighbour.utc > 0){
65  cout << "beat agent_neighbour node: " << beat_agent_neighbour.node << endl;
66  } else {
67  cout << "could not find " << agent_neighbor << endl;
68  exit (0);
69  }
70 
71  // Start agent thread
72  agentloop();
73 
74  //agent.shutdown();
75 
76  return 0;
77 }
string agentname
Definition: agent_generic_device_test.cpp:49
string agent_neighbor
Definition: agent_generic_device_test.cpp:51
int agentloop()
Definition: agent_generic_device_test.cpp:79
char node[40+1]
Definition: jsondef.h:928
beatstruc beat_agent_neighbour
Definition: agent_generic_device_test.cpp:53
Agent agent
Definition: agent_generic_device_test.cpp:48
double utc
Definition: jsondef.h:926
string nodename
Definition: agent_generic_device_test.cpp:50

Variable Documentation

Agent agent
string agentname = "generic_device_test"
string nodename = "telem"
string agent_neighbor = "generic_device_neighbor"
uint32_t itemp = 0
beatstruc beat_agent_neighbour