24 clnt = clnt_create (host, RCDAQ+servernumber, RCDAQ_VERS,
"tcp");
26 clnt_pcreateerror (host);
34 clnt_control(
clnt,CLSET_TIMEOUT , (
char *) &tv );
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;
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;
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;
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;
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;
88 std::cout << std::endl;
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;
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;
106 struct shortResult *
r;
107 struct deviceblock db;
113 char **arglist[NSTRINGPAR];
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;
131 char empty[2] = {
' ',0};
134 for ( i = 0; i < NSTRINGPAR; i++)
141 for ( i = optind+1; i < argc; i++)
146 if ( i == optind + 2)
148 if ( *argv[i] ==
'B' || *argv[i] ==
'b')
150 argv[
i] = (
char * )
"9";
152 else if ( *argv[i] ==
'D' || *argv[i] ==
'd')
154 argv[
i] = (
char *)
"1";
156 else if ( *argv[i] ==
'E' || *argv[i] ==
'e')
158 argv[
i] = (
char *)
"12";
160 else if ( *argv[i] ==
'S' || *argv[i] ==
's')
162 argv[
i] = (
char *)
"14";
166 *arglist[db.npar++] = argv[
i];
168 if ( db.npar >= NSTRINGPAR)
170 cout <<
"Too many parameters to handle for me" << endl;
175 r = r_create_device_1(&db,
clnt);
176 if (r == (shortResult *) NULL)
178 clnt_perror (
clnt,
"call failed");
180 if ( r->content) std::cout << r->str <<
std::flush;
188 struct shortResult *
r;
189 struct actionblock ab;
193 char tempSelection[1024];
200 int immediate_flag = 0;
207 while ((c = getopt(argc, argv,
"vlsi")) != EOF)
235 if ( getenv(
"RCDAQHOST") )
237 rcdaqhost = getenv(
"RCDAQHOST");
238 istringstream ss(rcdaqhost);
240 std::getline(ss, token,
':');
246 std::getline(ss, token,
':');
249 servernumber=std::stoi(token);
263 for ( i = 0; i< NIPAR; i++)
274 strcpy(command, argv[optind]);
276 if ( strcasecmp(command,
"help") == 0 )
281 else if ( strcasecmp(command,
"daq_sync") == 0)
286 r = r_action_1(&ab,
clnt);
287 if (r == (shortResult *) NULL)
289 clnt_perror (
clnt,
"call failed");
291 if (r->content) std::cout << r->str <<
std::flush;
295 else if ( strcasecmp(command,
"daq_begin") == 0)
308 if ( argc == optind + 2)
310 ab.ipar[0] =
get_value(argv[optind + 1]);
316 r = r_action_1 (&ab,
clnt);
317 if (r == (shortResult *) NULL)
319 clnt_perror (
clnt,
"call failed");
321 if (r->content) std::cout << r->str <<
std::flush;
326 else if ( strcasecmp(command,
"daq_end") == 0)
338 r = r_action_1(&ab,
clnt);
339 if (r == (shortResult *) NULL)
341 clnt_perror (
clnt,
"call failed");
343 if (r->content) std::cout << r->str <<
std::flush;
347 else if ( strcasecmp(command,
"daq_setfilerule") == 0)
349 if ( argc != optind + 2)
return -1;
352 ab.spar = argv[optind + 1];
353 r = r_action_1(&ab,
clnt);
354 if (r == (shortResult *) NULL)
356 clnt_perror (
clnt,
"call failed");
358 if (r->content) std::cout << r->str <<
std::flush;
362 else if ( strcasecmp(command,
"daq_setrunnumberfile") == 0)
364 if ( argc != optind + 2)
return -1;
367 ab.spar = argv[optind + 1];
370 if ( strcasecmp(argv[optind + 1],
"None") == 0) ab.ipar[0] = 1;
372 r = r_action_1(&ab,
clnt);
373 if (r == (shortResult *) NULL)
375 clnt_perror (
clnt,
"call failed");
377 if (r->content) std::cout << r->str <<
std::flush;
381 else if ( strcasecmp(command,
"daq_setrunnumberApp") == 0)
383 if ( argc != optind + 2)
return -1;
386 ab.spar = argv[optind + 1];
389 if ( strcasecmp(argv[optind + 1],
"None") == 0) ab.ipar[0] = 1;
391 r = r_action_1(&ab,
clnt);
392 if (r == (shortResult *) NULL)
394 clnt_perror (
clnt,
"call failed");
396 if (r->content) std::cout << r->str <<
std::flush;
401 else if ( strcasecmp(command,
"daq_set_runtype") == 0 || strcasecmp(command,
"daq_setruntype") == 0)
403 if ( argc != optind + 2)
return -1;
406 ab.spar = argv[optind + 1];
407 r = r_action_1(&ab,
clnt);
408 if (r == (shortResult *) NULL)
410 clnt_perror (
clnt,
"call failed");
412 if (r->content) std::cout << r->str <<
std::flush;
416 else if ( strcasecmp(command,
"daq_get_runtype") == 0)
420 ab.ipar[0] = long_flag;
422 r = r_action_1(&ab,
clnt);
423 if (r == (shortResult *) NULL)
425 clnt_perror (
clnt,
"call failed");
427 if (r->content) std::cout << r->str <<
std::flush;
431 else if ( strcasecmp(command,
"daq_define_runtype") == 0)
433 if ( argc != optind + 3)
return -1;
436 ab.spar = argv[optind + 1];
437 ab.spar2 = argv[optind + 2];
438 r = r_action_1(&ab,
clnt);
439 if (r == (shortResult *) NULL)
441 clnt_perror (
clnt,
"call failed");
443 if (r->content) std::cout << r->str <<
std::flush;
447 else if ( strcasecmp(command,
"daq_list_runtypes") == 0)
451 ab.ipar[0] = long_flag;
453 r = r_action_1(&ab,
clnt);
454 if (r == (shortResult *) NULL)
456 clnt_perror (
clnt,
"call failed");
458 if (r->content) std::cout << r->str <<
std::flush;
462 else if ( strcasecmp(command,
"daq_setname") == 0)
464 if ( argc != optind + 2)
return -1;
467 ab.spar = argv[optind + 1];
468 r = r_action_1(&ab,
clnt);
469 if (r == (shortResult *) NULL)
471 clnt_perror (
clnt,
"call failed");
473 if (r->content) std::cout << r->str <<
std::flush;
477 else if ( strcasecmp(command,
"daq_getname") == 0)
480 r = r_action_1(&ab,
clnt);
481 if (r == (shortResult *) NULL)
483 clnt_perror (
clnt,
"call failed");
485 if (r->content) std::cout << r->str <<
std::flush;
490 else if ( strcasecmp(command,
"daq_open") == 0)
494 r = r_action_1(&ab,
clnt);
495 if (r == (shortResult *) NULL)
497 clnt_perror (
clnt,
"call failed");
499 if (r->content) std::cout << r->str <<
std::flush;
503 else if ( strcasecmp(command,
"daq_set_server") == 0)
506 if ( argc < optind + 2)
return -1;
509 ab.spar = argv[optind + 1];
510 if ( argc == optind + 3)
512 ab.ipar[0] =
get_value(argv[optind + 2]);
518 r = r_action_1(&ab,
clnt);
519 if (r == (shortResult *) NULL)
521 clnt_perror (
clnt,
"call failed");
523 if (r->content) std::cout << r->str <<
std::flush;
526 else if ( strcasecmp(command,
"daq_close") == 0)
531 r = r_action_1(&ab,
clnt);
532 if (r == (shortResult *) NULL)
534 clnt_perror (
clnt,
"call failed");
536 if (r->content) std::cout << r->str <<
std::flush;
541 else if ( strcasecmp(command,
"daq_set_compression") == 0)
543 if ( argc < optind + 2)
return -1;
546 ab.ipar[0] =
get_value(argv[optind + 1]);
548 r = r_action_1(&ab,
clnt);
549 if (r == (shortResult *) NULL)
551 clnt_perror (
clnt,
"call failed");
553 if (r->content) std::cout << r->str <<
std::flush;
557 else if ( strcasecmp(command,
"daq_fake_trigger") == 0)
559 if ( argc < optind + 2)
return -1;
562 ab.ipar[0] =
get_value(argv[optind + 1]);
564 if ( argc > optind + 2)
566 ab.ipar[1] =
get_value(argv[optind + 1]);
569 r = r_action_1(&ab,
clnt);
570 if (r == (shortResult *) NULL)
572 clnt_perror (
clnt,
"call failed");
574 if (r->content) std::cout << r->str <<
std::flush;
578 else if ( strcasecmp(command,
"daq_list_readlist") == 0)
583 r = r_action_1(&ab,
clnt);
584 if (r == (shortResult *) NULL)
586 clnt_perror (
clnt,
"call failed");
588 if (r->content) std::cout << r->str <<
std::flush;
592 else if ( strcasecmp(command,
"daq_clear_readlist") == 0)
597 r = r_action_1(&ab,
clnt);
598 if (r == (shortResult *) NULL)
600 clnt_perror (
clnt,
"call failed");
602 if (r->content) std::cout << r->str <<
std::flush;
607 else if ( strcasecmp(command,
"daq_status") == 0)
612 ab.ipar[0] = long_flag;
614 r = r_action_1(&ab,
clnt);
615 if (r == (shortResult *) NULL)
617 clnt_perror (
clnt,
"call failed");
619 if (r->content) std::cout << r->str <<
std::flush;
623 else if ( strcasecmp(command,
"daq_set_maxevents") == 0)
625 if ( argc < optind + 2)
return -1;
628 ab.ipar[0] =
get_value(argv[optind + 1]);
630 r = r_action_1(&ab,
clnt);
631 if (r == (shortResult *) NULL)
633 clnt_perror (
clnt,
"call failed");
635 if (r->content) std::cout << r->str <<
std::flush;
639 else if ( strcasecmp(command,
"daq_set_maxvolume") == 0)
641 if ( argc < optind + 2)
return -1;
644 ab.ipar[0] =
get_value(argv[optind + 1]);
646 r = r_action_1(&ab,
clnt);
647 if (r == (shortResult *) NULL)
649 clnt_perror (
clnt,
"call failed");
651 if (r->content) std::cout << r->str <<
std::flush;
655 else if ( strcasecmp(command,
"daq_set_rolloverlimit") == 0)
657 if ( argc < optind + 2)
return -1;
660 ab.ipar[0] =
get_value(argv[optind + 1]);
662 r = r_action_1(&ab,
clnt);
663 if (r == (shortResult *) NULL)
665 clnt_perror (
clnt,
"call failed");
667 if (r->content) std::cout << r->str <<
std::flush;
671 else if ( strcasecmp(command,
"daq_set_maxbuffersize") == 0)
673 if ( argc < optind + 2)
return -1;
676 ab.ipar[0] =
get_value(argv[optind + 1]);
678 r = r_action_1(&ab,
clnt);
679 if (r == (shortResult *) NULL)
681 clnt_perror (
clnt,
"call failed");
683 if (r->content) std::cout << r->str <<
std::flush;
688 else if ( strcasecmp(command,
"daq_set_adaptivebuffering") == 0)
690 if ( argc < optind + 2)
return -1;
693 ab.ipar[0] =
get_value(argv[optind + 1]);
695 r = r_action_1(&ab,
clnt);
696 if (r == (shortResult *) NULL)
698 clnt_perror (
clnt,
"call failed");
700 if (r->content) std::cout << r->str <<
std::flush;
704 else if ( strcasecmp(command,
"daq_webcontrol") == 0)
708 if ( argc == optind + 2)
710 ab.ipar[0] =
get_value(argv[optind + 1]);
716 r = r_action_1 (&ab,
clnt);
717 if (r == (shortResult *) NULL)
719 clnt_perror (
clnt,
"call failed");
721 if (r->content) std::cout << r->str <<
std::flush;
725 else if ( strcasecmp(command,
"daq_get_lastfilename") == 0)
732 r = r_action_1 (&ab,
clnt);
733 if (r == (shortResult *) NULL)
735 clnt_perror (
clnt,
"call failed");
737 if (r->content) std::cout << r->str <<
std::flush;
741 else if ( strcasecmp(command,
"daq_get_last_event_number") == 0)
748 r = r_action_1 (&ab,
clnt);
749 if (r == (shortResult *) NULL)
751 clnt_perror (
clnt,
"call failed");
753 if (r->content) std::cout << r->str <<
std::flush;
757 else if ( strcasecmp(command,
"daq_set_eventformat") == 0)
759 if ( argc < optind + 2)
return -1;
762 ab.ipar[0] =
get_value(argv[optind + 1]);
764 r = r_action_1(&ab,
clnt);
765 if (r == (shortResult *) NULL)
767 clnt_perror (
clnt,
"call failed");
769 if (r->content) std::cout << r->str <<
std::flush;
773 else if ( strcasecmp(command,
"daq_set_runcontrolmode") == 0)
775 if ( argc < optind + 2)
return -1;
778 ab.ipar[0] =
get_value(argv[optind + 1]);
780 r = r_action_1(&ab,
clnt);
781 if (r == (shortResult *) NULL)
783 clnt_perror (
clnt,
"call failed");
785 if (r->content) std::cout << r->str <<
std::flush;
789 else if ( strcasecmp(command,
"daq_get_runcontrolmode") == 0)
794 r = r_action_1(&ab,
clnt);
795 if (r == (shortResult *) NULL)
797 clnt_perror (
clnt,
"call failed");
799 if (r->content) std::cout << r->str <<
std::flush;
803 #ifdef HAVE_MOSQUITTO_H
804 else if ( strcasecmp(command,
"daq_set_mqtt_host") == 0)
806 if ( argc < optind + 2)
return -1;
809 ab.spar = argv[optind + 1];
810 if ( argc == optind + 3)
812 ab.ipar[0] =
get_value(argv[optind + 2]);
818 r = r_action_1(&ab,
clnt);
819 if (r == (shortResult *) NULL)
821 clnt_perror (
clnt,
"call failed");
823 if (r->content) std::cout << r->str <<
std::flush;
827 else if ( strcasecmp(command,
"daq_get_mqtt_host") == 0)
831 r = r_action_1(&ab,
clnt);
832 if (r == (shortResult *) NULL)
834 clnt_perror (
clnt,
"call failed");
836 if (r->content) std::cout << r->str <<
std::flush;
842 else if ( strcasecmp(command,
"elog") == 0)
845 if ( argc != optind + 4)
return -1;
848 ab.spar = argv[optind + 1];
849 ab.ipar[0] =
get_value(argv[optind + 2]);
850 ab.spar2 = argv[optind +3];
852 r = r_action_1(&ab,
clnt);
853 if (r == (shortResult *) NULL)
855 clnt_perror (
clnt,
"call failed");
857 if (r->content) std::cout << r->str <<
std::flush;
862 else if ( strcasecmp(command,
"load") == 0)
865 if ( argc != optind + 2)
return -1;
868 ab.spar = argv[optind + 1];
870 r = r_action_1(&ab,
clnt);
871 if (r == (shortResult *) NULL)
873 clnt_perror (
clnt,
"call failed");
875 if (r->content) std::cout << r->str <<
std::flush;
881 else if ( strcasecmp(command,
"create_device") == 0)
886 else if ( strcasecmp(command,
"daq_shutdown") == 0)
889 r = r_shutdown_1(0,
clnt);
890 if (r == (shortResult *) NULL)
892 clnt_perror (
clnt,
"call failed");
897 if (r->content) std::cout << r->str <<
std::flush;
904 std::cout <<
"Unknown Command " << command << std::endl;