Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rcdaq_client.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file rcdaq_client.cc
1 
2 
3 #include <iostream>
4 #include <iomanip>
5 #include <getopt.h>
6 
7 #include <sstream>
8 #include "parseargument.h"
9 #include "rcdaq_rpc.h"
10 #include "rcdaq_actions.h"
11 
12 using namespace std;
13 
14 CLIENT *clnt;
15 
16 //result *ra;
17 int verbose_flag = 0;
18 
19 void
20 rcdaq_client_Init(const char *host, const int servernumber)
21 {
22 
23 
24  clnt = clnt_create (host, RCDAQ+servernumber, RCDAQ_VERS, "tcp");
25  if (clnt == NULL) {
26  clnt_pcreateerror (host);
27  exit (1);
28  }
29 
30  struct timeval tv;
31  tv.tv_sec = 1000;
32  tv.tv_usec = 0;
33 
34  clnt_control(clnt,CLSET_TIMEOUT , (char *) &tv );
35 
36 
37 
38 }
39 
40 void showHelp()
41 {
42  std::cout << " help show this help text" << std::endl;
43  std::cout << " daq_status [-s] [-l] display status [short] [long]" << std::endl;
44  std::cout << " daq_open enable logging" << std::endl;
45  std::cout << " daq_set_server hostname [port] choose logging to a SFS server, or \"None\" to choose local file" << std::endl;
46  std::cout << " daq_begin [run-number] start taking data for run-number, or auto-increment" << std::endl;
47  std::cout << " daq_end end the run " << std::endl;
48  std::cout << " daq_close disable logging" << std::endl;
49  std::cout << " daq_setfilerule file-rule set the file rule default rcdaq-%08d-%04d.evt" << std::endl;
50  std::cout << std::endl;
51  std::cout << " daq_list_readlist display the current readout list" << std::endl;
52  std::cout << " daq_clear_readlist clear the current readout list " << std::endl;
53  std::cout << std::endl;
54  std::cout << " daq_define_runtype type file-rule define a run type, such as \"calibration\"" << std::endl;
55  std::cout << " daq_set_runtype type activate a predefined run type" << std::endl;
56  std::cout << " daq_get_runtype [-l] list the active runtype (if any)" << std::endl;
57  std::cout << " daq_list_runtypes [-s] list defined run types" << std::endl;
58  std::cout << " daq_get_lastfilename return the last file name written, if any" << std::endl;
59  std::cout << " daq_get_last_event_number return the last event number from the previous run" << std::endl;
60  std::cout << std::endl;
61 
62  std::cout << " daq_set_maxevents nevt set automatic end at so many events" << std::endl;
63  std::cout << " daq_set_maxvolume n_MB set automatic end at n_MB MegaByte" << std::endl;
64  std::cout << " daq_set_rolloverlimit n_GB set file rollover limit at n_BG GigaByte" << std::endl;
65  std::cout << " daq_set_eventformat n dynamically switch from standard (0) to legacy header format (1)" << std::endl;
66  std::cout << " daq_set_compression n enable (1) or disable(0) the file compression" << std::endl;
67  std::cout << std::endl;
68 
69  std::cout << " load shared_library_name load a \"plugin\" shared library" << std::endl;
70  std::cout << " create_device [device-specific parameters] " << std::endl;
71  std::cout << std::endl;
72 
73  std::cout << " daq_setname <string> define an identifying string for this RCDAQ instance" << std::endl;
74  std::cout << " daq_setrunnumberfile file define a file to maintain the current run number, \"None\" to reset" << std::endl;
75  std::cout << " daq_setrunnumberApp file define an App that dispenses run numbers, \"None\" to reset" << std::endl;
76  std::cout << " daq_set_maxbuffersize n_KB adjust the size of buffers written to n KB" << std::endl;
77  std::cout << " daq_set_adaptivebuffering seconds enable adaptive buffering at n seconds (0 = off)" << std::endl;
78  std::cout << std::endl;
79 
80  std::cout << " daq_webcontrol <port number> restart web controls on a new port (default 8080)" << std::endl;
81  std::cout << std::endl;
82 #ifdef HAVE_MOSQUITTO_H
83  std::cout << " daq_set_mqtt_host <host> [port] set up the MQTT host/port for the DB interaction, or \"none\" to remove" << std::endl;
84  std::cout << " daq_get_mqtt_host <host> [port] retrieve the MQTT host/port for the DB interaction" << std::endl;
85 #endif
86  // std::cout << " daq_open_sqlstream <string> open a stream to issue SQL commands" << std::endl;
87  // std::cout << " daq_close_sqlstream close a SQL stream" << std::endl;
88  std::cout << std::endl;
89 
90  std::cout << " daq_set_runcontrolmode n switch to Run Control Mode (1=on, 0=off)" << std::endl;
91  std::cout << " daq_get_runcontrolmode get the current Run Control Mode setting" << std::endl;
92  std::cout << std::endl;
93 
94  std::cout << " elog elog-server port specify coordinates for an Elog server" << std::endl;
95  std::cout << std::endl;
96  std::cout << " daq_shutdown terminate the rcdaq backend" << std::endl;
97  exit(0);
98 }
99 
100 
101 
102 int handle_device( int argc, char **argv, const int optind)
103 {
104 
105 
106  struct shortResult *r;
107  struct deviceblock db;
108 
109 
110  // this construct is here because RPC doesn't support
111  // 2-dim arrays (at least AFAIK). It saves a lot of if's
112  // and else's:
113  char **arglist[NSTRINGPAR];
114 
115 
116  arglist[0] = &db.argv0;
117  arglist[1] = &db.argv1;
118  arglist[2] = &db.argv2;
119  arglist[3] = &db.argv3;
120  arglist[4] = &db.argv4;
121  arglist[5] = &db.argv5;
122  arglist[6] = &db.argv6;
123  arglist[7] = &db.argv7;
124  arglist[8] = &db.argv8;
125  arglist[9] = &db.argv9;
126  arglist[10] = &db.argv10;
127  arglist[11] = &db.argv11;
128  arglist[12] = &db.argv12;
129  arglist[13] = &db.argv13;
130 
131  char empty[2] = {' ',0};
132 
133  int i;
134  for ( i = 0; i < NSTRINGPAR; i++)
135  {
136  *arglist[i] = empty;
137  }
138 
139  db.npar=0;
140 
141  for ( i = optind+1; i < argc; i++)
142  {
143 
144  // this is only the case here - the event type
145  // if it's "B, D, S, or E", we replace with the begin- data- scaler- endrun event
146  if ( i == optind + 2)
147  {
148  if ( *argv[i] == 'B' || *argv[i] == 'b')
149  {
150  argv[i] = (char * ) "9"; // begin-run;
151  }
152  else if ( *argv[i] == 'D' || *argv[i] == 'd')
153  {
154  argv[i] = (char *) "1"; // data event
155  }
156  else if ( *argv[i] == 'E' || *argv[i] == 'e')
157  {
158  argv[i] = (char *) "12"; // end-run
159  }
160  else if ( *argv[i] == 'S' || *argv[i] == 's')
161  {
162  argv[i] = (char *) "14"; // scaler event
163  }
164  }
165 
166  *arglist[db.npar++] = argv[i];
167 
168  if ( db.npar >= NSTRINGPAR)
169  {
170  cout << "Too many parameters to handle for me" << endl;
171  break;
172  }
173  }
174 
175  r = r_create_device_1(&db, clnt);
176  if (r == (shortResult *) NULL)
177  {
178  clnt_perror (clnt, "call failed");
179  }
180  if ( r->content) std::cout << r->str << std::flush;
181 
182  return r->status;
183 }
184 
185 
186 int command_execute( int argc, char **argv)
187 {
188  struct shortResult *r;
189  struct actionblock ab;
190 
191  if ( argc <= 1 ) showHelp();
192 
193  char tempSelection[1024];
194 
195  char command[512];
196 
197  // the log and short flags are for qualifying the
198  // status output
199  int long_flag = 1;
200  int immediate_flag = 0; // only used for daq_end so far
201 
202  int c;
203 
204  optind = 0; // tell getopt to start over
205  int servernumber=0;
206 
207  while ((c = getopt(argc, argv, "vlsi")) != EOF)
208  {
209  switch (c)
210  {
211 
212  case 'v': // set the verbose flag
213  verbose_flag++;
214  break;
215 
216  case 'l': // set the long flag; we can step up the verbosity with multiple -l's
217  long_flag++;
218  break;
219 
220  case 's': // set the short flag (0) (note that long_flag is pre-set to 1 for "normal")
221  long_flag=0;
222  break;
223 
224  case 'i': // set the "immediate" flag; onoy used in daq_end to request an asynchronous end
225  immediate_flag=1;
226  break;
227 
228  }
229  }
230 
231 
232  std::string rcdaqhost;
233  std::string host = "localhost";
234 
235  if ( getenv("RCDAQHOST") )
236  {
237  rcdaqhost = getenv("RCDAQHOST");
238  istringstream ss(rcdaqhost);
239  string token;
240  std::getline(ss, token, ':');
241  if ( token.size())
242  {
243  host = token;
244  }
245 
246  std::getline(ss, token, ':');
247  if ( token.size())
248  {
249  servernumber=std::stoi(token);
250  }
251  }
252 
253  // std::cout << "hoat " << host << " Server number is " << servernumber << std::endl;
254 
255 
256  rcdaq_client_Init (host.c_str(),servernumber);
257 
258  ab.action = 0;
259  ab.value = 0;
260  ab.spare = 0;
261 
262  int i;
263  for ( i = 0; i< NIPAR; i++)
264  {
265  ab.ipar[i] = 0;
266  }
267 
268  char space[] = " ";
269  ab.spar = space;
270  ab.spar2 = space;
271 
272  int convertstatus;
273 
274  strcpy(command, argv[optind]);
275 
276  if ( strcasecmp(command,"help") == 0 )
277  {
278  showHelp();
279  }
280 
281  else if ( strcasecmp(command,"daq_sync") == 0)
282  {
283 
284  ab.action = DAQ_SYNC;
285 
286  r = r_action_1(&ab, clnt);
287  if (r == (shortResult *) NULL)
288  {
289  clnt_perror (clnt, "call failed");
290  }
291  if (r->content) std::cout << r->str << std::flush;
292 
293  }
294 
295  else if ( strcasecmp(command,"daq_begin") == 0)
296  {
297 
298  if (immediate_flag)
299  {
300  ab.action = DAQ_BEGIN_IMMEDIATE;
301  }
302  else
303  {
304  ab.action = DAQ_BEGIN;
305 
306  }
307 
308  if ( argc == optind + 2)
309  {
310  ab.ipar[0] = get_value(argv[optind + 1]);
311  }
312  else
313  {
314  ab.ipar[0] = 0;
315  }
316  r = r_action_1 (&ab, clnt);
317  if (r == (shortResult *) NULL)
318  {
319  clnt_perror (clnt, "call failed");
320  }
321  if (r->content) std::cout << r->str << std::flush;
322 
323  }
324 
325 
326  else if ( strcasecmp(command,"daq_end") == 0)
327  {
328 
329  if (immediate_flag)
330  {
331  ab.action = DAQ_END_IMMEDIATE;
332  }
333  else
334  {
335  ab.action = DAQ_END;
336  }
337 
338  r = r_action_1(&ab, clnt);
339  if (r == (shortResult *) NULL)
340  {
341  clnt_perror (clnt, "call failed");
342  }
343  if (r->content) std::cout << r->str << std::flush;
344 
345  }
346 
347  else if ( strcasecmp(command,"daq_setfilerule") == 0)
348  {
349  if ( argc != optind + 2) return -1;
350 
351  ab.action = DAQ_SETFILERULE;
352  ab.spar = argv[optind + 1];
353  r = r_action_1(&ab, clnt);
354  if (r == (shortResult *) NULL)
355  {
356  clnt_perror (clnt, "call failed");
357  }
358  if (r->content) std::cout << r->str << std::flush;
359 
360  }
361 
362  else if ( strcasecmp(command,"daq_setrunnumberfile") == 0)
363  {
364  if ( argc != optind + 2) return -1;
365 
366  ab.action = DAQ_RUNNUMBERFILE;
367  ab.spar = argv[optind + 1];
368 
369  // if we set "none", unset the app
370  if ( strcasecmp(argv[optind + 1],"None") == 0) ab.ipar[0] = 1;
371 
372  r = r_action_1(&ab, clnt);
373  if (r == (shortResult *) NULL)
374  {
375  clnt_perror (clnt, "call failed");
376  }
377  if (r->content) std::cout << r->str << std::flush;
378 
379  }
380 
381  else if ( strcasecmp(command,"daq_setrunnumberApp") == 0)
382  {
383  if ( argc != optind + 2) return -1;
384 
385  ab.action = DAQ_SETRUNNUMBERAPP;
386  ab.spar = argv[optind + 1];
387 
388  // if we set "none", unset the app
389  if ( strcasecmp(argv[optind + 1],"None") == 0) ab.ipar[0] = 1;
390 
391  r = r_action_1(&ab, clnt);
392  if (r == (shortResult *) NULL)
393  {
394  clnt_perror (clnt, "call failed");
395  }
396  if (r->content) std::cout << r->str << std::flush;
397 
398  }
399 
400  // the 2nd half is not to break scripts that may use the older name
401  else if ( strcasecmp(command,"daq_set_runtype") == 0 || strcasecmp(command,"daq_setruntype") == 0)
402  {
403  if ( argc != optind + 2) return -1;
404 
405  ab.action = DAQ_SETRUNTYPE;
406  ab.spar = argv[optind + 1];
407  r = r_action_1(&ab, clnt);
408  if (r == (shortResult *) NULL)
409  {
410  clnt_perror (clnt, "call failed");
411  }
412  if (r->content) std::cout << r->str << std::flush;
413 
414  }
415 
416  else if ( strcasecmp(command,"daq_get_runtype") == 0)
417  {
418 
419  ab.action = DAQ_GETRUNTYPE;
420  ab.ipar[0] = long_flag;
421 
422  r = r_action_1(&ab, clnt);
423  if (r == (shortResult *) NULL)
424  {
425  clnt_perror (clnt, "call failed");
426  }
427  if (r->content) std::cout << r->str << std::flush;
428 
429  }
430 
431  else if ( strcasecmp(command,"daq_define_runtype") == 0)
432  {
433  if ( argc != optind + 3) return -1;
434 
435  ab.action = DAQ_DEFINERUNTYPE;
436  ab.spar = argv[optind + 1];
437  ab.spar2 = argv[optind + 2];
438  r = r_action_1(&ab, clnt);
439  if (r == (shortResult *) NULL)
440  {
441  clnt_perror (clnt, "call failed");
442  }
443  if (r->content) std::cout << r->str << std::flush;
444 
445  }
446 
447  else if ( strcasecmp(command,"daq_list_runtypes") == 0)
448  {
449 
450  ab.action = DAQ_LISTRUNTYPES;
451  ab.ipar[0] = long_flag;
452 
453  r = r_action_1(&ab, clnt);
454  if (r == (shortResult *) NULL)
455  {
456  clnt_perror (clnt, "call failed");
457  }
458  if (r->content) std::cout << r->str << std::flush;
459 
460  }
461 
462  else if ( strcasecmp(command,"daq_setname") == 0)
463  {
464  if ( argc != optind + 2) return -1;
465 
466  ab.action = DAQ_SETNAME;
467  ab.spar = argv[optind + 1];
468  r = r_action_1(&ab, clnt);
469  if (r == (shortResult *) NULL)
470  {
471  clnt_perror (clnt, "call failed");
472  }
473  if (r->content) std::cout << r->str << std::flush;
474 
475  }
476 
477  else if ( strcasecmp(command,"daq_getname") == 0)
478  {
479  ab.action = DAQ_GETNAME;
480  r = r_action_1(&ab, clnt);
481  if (r == (shortResult *) NULL)
482  {
483  clnt_perror (clnt, "call failed");
484  }
485  if (r->content) std::cout << r->str << std::flush;
486 
487  }
488 
489 
490  else if ( strcasecmp(command,"daq_open") == 0)
491  {
492 
493  ab.action = DAQ_OPEN;
494  r = r_action_1(&ab, clnt);
495  if (r == (shortResult *) NULL)
496  {
497  clnt_perror (clnt, "call failed");
498  }
499  if (r->content) std::cout << r->str << std::flush;
500 
501  }
502 
503  else if ( strcasecmp(command,"daq_set_server") == 0)
504  {
505 
506  if ( argc < optind + 2) return -1;
507 
508  ab.action = DAQ_SET_SERVER;
509  ab.spar = argv[optind + 1];
510  if ( argc == optind + 3)
511  {
512  ab.ipar[0] = get_value(argv[optind + 2]);
513  }
514  else
515  {
516  ab.ipar[0] = 0;
517  }
518  r = r_action_1(&ab, clnt);
519  if (r == (shortResult *) NULL)
520  {
521  clnt_perror (clnt, "call failed");
522  }
523  if (r->content) std::cout << r->str << std::flush;
524  }
525 
526  else if ( strcasecmp(command,"daq_close") == 0)
527  {
528 
529  ab.action = DAQ_CLOSE;
530 
531  r = r_action_1(&ab, clnt);
532  if (r == (shortResult *) NULL)
533  {
534  clnt_perror (clnt, "call failed");
535  }
536  if (r->content) std::cout << r->str << std::flush;
537 
538  }
539 
540 
541  else if ( strcasecmp(command,"daq_set_compression") == 0)
542  {
543  if ( argc < optind + 2) return -1;
544 
545  ab.action = DAQ_SET_COMPRESSION;
546  ab.ipar[0] = get_value(argv[optind + 1]);
547 
548  r = r_action_1(&ab, clnt);
549  if (r == (shortResult *) NULL)
550  {
551  clnt_perror (clnt, "call failed");
552  }
553  if (r->content) std::cout << r->str << std::flush;
554 
555  }
556 
557  else if ( strcasecmp(command,"daq_fake_trigger") == 0)
558  {
559  if ( argc < optind + 2) return -1;
560 
561  ab.action = DAQ_FAKETRIGGER;
562  ab.ipar[0] = get_value(argv[optind + 1]);
563  // see if we have a 2nd parameter
564  if ( argc > optind + 2)
565  {
566  ab.ipar[1] = get_value(argv[optind + 1]);
567  }
568 
569  r = r_action_1(&ab, clnt);
570  if (r == (shortResult *) NULL)
571  {
572  clnt_perror (clnt, "call failed");
573  }
574  if (r->content) std::cout << r->str << std::flush;
575 
576  }
577 
578  else if ( strcasecmp(command,"daq_list_readlist") == 0)
579  {
580 
581  ab.action = DAQ_LISTREADLIST;
582 
583  r = r_action_1(&ab, clnt);
584  if (r == (shortResult *) NULL)
585  {
586  clnt_perror (clnt, "call failed");
587  }
588  if (r->content) std::cout << r->str << std::flush;
589 
590  }
591 
592  else if ( strcasecmp(command,"daq_clear_readlist") == 0)
593  {
594 
595  ab.action = DAQ_CLEARREADLIST;
596 
597  r = r_action_1(&ab, clnt);
598  if (r == (shortResult *) NULL)
599  {
600  clnt_perror (clnt, "call failed");
601  }
602  if (r->content) std::cout << r->str << std::flush;
603 
604  }
605 
606 
607  else if ( strcasecmp(command,"daq_status") == 0)
608  {
609 
610  ab.action = DAQ_STATUS;
611 
612  ab.ipar[0] = long_flag;
613 
614  r = r_action_1(&ab, clnt);
615  if (r == (shortResult *) NULL)
616  {
617  clnt_perror (clnt, "call failed");
618  }
619  if (r->content) std::cout << r->str << std::flush;
620 
621  }
622 
623  else if ( strcasecmp(command,"daq_set_maxevents") == 0)
624  {
625  if ( argc < optind + 2) return -1;
626 
627  ab.action = DAQ_SETMAXEVENTS;
628  ab.ipar[0] = get_value(argv[optind + 1]);
629 
630  r = r_action_1(&ab, clnt);
631  if (r == (shortResult *) NULL)
632  {
633  clnt_perror (clnt, "call failed");
634  }
635  if (r->content) std::cout << r->str << std::flush;
636 
637  }
638 
639  else if ( strcasecmp(command,"daq_set_maxvolume") == 0)
640  {
641  if ( argc < optind + 2) return -1;
642 
643  ab.action = DAQ_SETMAXVOLUME;
644  ab.ipar[0] = get_value(argv[optind + 1]);
645 
646  r = r_action_1(&ab, clnt);
647  if (r == (shortResult *) NULL)
648  {
649  clnt_perror (clnt, "call failed");
650  }
651  if (r->content) std::cout << r->str << std::flush;
652 
653  }
654 
655  else if ( strcasecmp(command,"daq_set_rolloverlimit") == 0)
656  {
657  if ( argc < optind + 2) return -1;
658 
659  ab.action = DAQ_ROLLOVERLIMIT;
660  ab.ipar[0] = get_value(argv[optind + 1]);
661 
662  r = r_action_1(&ab, clnt);
663  if (r == (shortResult *) NULL)
664  {
665  clnt_perror (clnt, "call failed");
666  }
667  if (r->content) std::cout << r->str << std::flush;
668 
669  }
670 
671  else if ( strcasecmp(command,"daq_set_maxbuffersize") == 0)
672  {
673  if ( argc < optind + 2) return -1;
674 
675  ab.action = DAQ_SETMAXBUFFERSIZE;
676  ab.ipar[0] = get_value(argv[optind + 1]);
677 
678  r = r_action_1(&ab, clnt);
679  if (r == (shortResult *) NULL)
680  {
681  clnt_perror (clnt, "call failed");
682  }
683  if (r->content) std::cout << r->str << std::flush;
684 
685  }
686 
687 
688  else if ( strcasecmp(command,"daq_set_adaptivebuffering") == 0)
689  {
690  if ( argc < optind + 2) return -1;
691 
692  ab.action = DAQ_SETADAPTIVEBUFFER;
693  ab.ipar[0] = get_value(argv[optind + 1]);
694 
695  r = r_action_1(&ab, clnt);
696  if (r == (shortResult *) NULL)
697  {
698  clnt_perror (clnt, "call failed");
699  }
700  if (r->content) std::cout << r->str << std::flush;
701 
702  }
703 
704  else if ( strcasecmp(command,"daq_webcontrol") == 0)
705  {
706 
707  ab.action = DAQ_WEBCONTROL;
708  if ( argc == optind + 2)
709  {
710  ab.ipar[0] = get_value(argv[optind + 1]);
711  }
712  else
713  {
714  ab.ipar[0] = 0;
715  }
716  r = r_action_1 (&ab, clnt);
717  if (r == (shortResult *) NULL)
718  {
719  clnt_perror (clnt, "call failed");
720  }
721  if (r->content) std::cout << r->str << std::flush;
722 
723  }
724 
725  else if ( strcasecmp(command,"daq_get_lastfilename") == 0)
726  {
727 
728  ab.action = DAQ_GETLASTFILENAME;
729 
730  ab.ipar[0] = 0;
731 
732  r = r_action_1 (&ab, clnt);
733  if (r == (shortResult *) NULL)
734  {
735  clnt_perror (clnt, "call failed");
736  }
737  if (r->content) std::cout << r->str << std::flush;
738 
739  }
740 
741  else if ( strcasecmp(command,"daq_get_last_event_number") == 0)
742  {
743 
744  ab.action = DAQ_GETLASTEVENTNUMBER;
745 
746  ab.ipar[0] = 0;
747 
748  r = r_action_1 (&ab, clnt);
749  if (r == (shortResult *) NULL)
750  {
751  clnt_perror (clnt, "call failed");
752  }
753  if (r->content) std::cout << r->str << std::flush;
754 
755  }
756 
757  else if ( strcasecmp(command,"daq_set_eventformat") == 0)
758  {
759  if ( argc < optind + 2) return -1;
760 
761  ab.action = DAQ_SETEVENTFORMAT;
762  ab.ipar[0] = get_value(argv[optind + 1]);
763 
764  r = r_action_1(&ab, clnt);
765  if (r == (shortResult *) NULL)
766  {
767  clnt_perror (clnt, "call failed");
768  }
769  if (r->content) std::cout << r->str << std::flush;
770 
771  }
772 
773  else if ( strcasecmp(command,"daq_set_runcontrolmode") == 0)
774  {
775  if ( argc < optind + 2) return -1;
776 
777  ab.action = DAQ_SET_RUNCONTROLMODE;
778  ab.ipar[0] = get_value(argv[optind + 1]);
779 
780  r = r_action_1(&ab, clnt);
781  if (r == (shortResult *) NULL)
782  {
783  clnt_perror (clnt, "call failed");
784  }
785  if (r->content) std::cout << r->str << std::flush;
786 
787  }
788 
789  else if ( strcasecmp(command,"daq_get_runcontrolmode") == 0)
790  {
791 
792  ab.action = DAQ_GET_RUNCONTROLMODE;
793 
794  r = r_action_1(&ab, clnt);
795  if (r == (shortResult *) NULL)
796  {
797  clnt_perror (clnt, "call failed");
798  }
799  if (r->content) std::cout << r->str << std::flush;
800 
801  }
802 
803 #ifdef HAVE_MOSQUITTO_H
804  else if ( strcasecmp(command, "daq_set_mqtt_host") == 0)
805  {
806  if ( argc < optind + 2) return -1;
807 
808  ab.action = DAQ_SET_MQTT_HOST;
809  ab.spar = argv[optind + 1];
810  if ( argc == optind + 3)
811  {
812  ab.ipar[0] = get_value(argv[optind + 2]);
813  }
814  else
815  {
816  ab.ipar[0] = 1883;
817  }
818  r = r_action_1(&ab, clnt);
819  if (r == (shortResult *) NULL)
820  {
821  clnt_perror (clnt, "call failed");
822  }
823  if (r->content) std::cout << r->str << std::flush;
824 
825  }
826 
827  else if ( strcasecmp(command, "daq_get_mqtt_host") == 0)
828  {
829  ab.action = DAQ_GET_MQTT_HOST;
830 
831  r = r_action_1(&ab, clnt);
832  if (r == (shortResult *) NULL)
833  {
834  clnt_perror (clnt, "call failed");
835  }
836  if (r->content) std::cout << r->str << std::flush;
837 
838  }
839 #endif
840 
841 
842  else if ( strcasecmp(command,"elog") == 0)
843  {
844 
845  if ( argc != optind + 4) return -1;
846 
847  ab.action = DAQ_ELOG;
848  ab.spar = argv[optind + 1];
849  ab.ipar[0] = get_value(argv[optind + 2]);
850  ab.spar2 = argv[optind +3];
851 
852  r = r_action_1(&ab, clnt);
853  if (r == (shortResult *) NULL)
854  {
855  clnt_perror (clnt, "call failed");
856  }
857  if (r->content) std::cout << r->str << std::flush;
858 
859  }
860 
861 
862  else if ( strcasecmp(command,"load") == 0)
863  {
864 
865  if ( argc != optind + 2) return -1;
866 
867  ab.action = DAQ_LOAD;
868  ab.spar = argv[optind + 1];
869 
870  r = r_action_1(&ab, clnt);
871  if (r == (shortResult *) NULL)
872  {
873  clnt_perror (clnt, "call failed");
874  }
875  if (r->content) std::cout << r->str << std::flush;
876 
877  }
878 
879 
880 
881  else if ( strcasecmp(command,"create_device") == 0)
882  {
883  return handle_device ( argc, argv, optind);
884  }
885 
886  else if ( strcasecmp(command,"daq_shutdown") == 0)
887  {
888 
889  r = r_shutdown_1(0,clnt);
890  if (r == (shortResult *) NULL)
891  {
892  clnt_perror (clnt, "call failed");
893  return 0;
894  }
895  else
896  {
897  if (r->content) std::cout << r->str << std::flush;
898  }
899  }
900 
901 
902  else
903  {
904  std::cout << "Unknown Command " << command << std::endl;
905  return 0;
906  }
907 
908  return r->status;
909 }
910 
911 
912 int
913 main (int argc, char *argv[])
914 {
915 
916 
917  int status = command_execute( argc, argv);
918  clnt_destroy (clnt);
919 
920  if ( status)
921  {
922  return 1;
923  }
924 
925 
926  return 0;
927 }