DABC (Data Acquisition Backbone Core)  2.9.9
mbscmd.cxx
Go to the documentation of this file.
1 // $Id: mbsprint.cxx 2226 2014-04-04 07:32:45Z linev $
2 
3 /************************************************************
4  * The Data Acquisition Backbone Core (DABC) *
5  ************************************************************
6  * Copyright (C) 2009 - *
7  * GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
8  * Planckstr. 1, 64291 Darmstadt, Germany *
9  * Contact: http://dabc.gsi.de *
10  ************************************************************
11  * This software can be used under the GPL license *
12  * agreements as stated in LICENSE.txt file *
13  * which is part of the distribution. *
14  ************************************************************/
15 
16 #include <cstdio>
17 #include <cstring>
18 #include <ctime>
19 #include <vector>
20 
21 #include "mbs/api.h"
22 
23 int usage(const char* errstr = 0)
24 {
25  if (errstr!=0) printf("Error: %s\n\n", errstr);
26 
27  printf("Utility for execute commands on remote MBS node\n");
28  printf(" mbscmd nodename [args] -cmd cmd1 [-cmd cmd2] [-cmd cmd3] ...\n");
29  printf("Arguments:\n");
30  printf(" -logport number - port number of log channel (-1 - off, default 6007)\n");
31  printf(" -cmdport number - port number of command channel (-1 - off, default 6019)\n");
32  printf(" -prompter - connect to MBS prompter (same as -cmdport 6006)\n");
33  printf(" -stat - enable reading of status record from port 6008 (default off)\n");
34  printf(" -cmd mbs_command - MBS command to execute (can be any number)\n");
35  printf(" -tmout time - timeout for command execution (default 5 sec)\n");
36  printf(" -wait time - wait time at the end of utility (default 1 sec)\n");
37 
38  return errstr ? 1 : 0;
39 }
40 
41 
42 int main(int argc, char* argv[])
43 {
44  if (argc<2) return usage();
45 
46  int logport(6007), cmdport(6019), statport(0);
47  double tmout(5.), waittm(1.);
48 
49  std::vector<std::string> cmds;
50 
51  int n = 1;
52  while (++n<argc) {
53  if (strcmp(argv[n],"-prompter")==0) { cmdport = 6006; } else
54  if (strcmp(argv[n],"-stat")==0) { statport = 6008; } else
55  if ((strcmp(argv[n],"-logport")==0) && (n+1<argc)) { dabc::str_to_int(argv[++n], &logport); } else
56  if ((strcmp(argv[n],"-cmdport")==0) && (n+1<argc)) { dabc::str_to_int(argv[++n], &cmdport); } else
57  if ((strcmp(argv[n],"-tmout")==0) && (n+1<argc)) { dabc::str_to_double(argv[++n], &tmout); } else
58  if ((strcmp(argv[n],"-wait")==0) && (n+1<argc)) { dabc::str_to_double(argv[++n], &waittm); } else
59  if ((strcmp(argv[n],"-cmd")==0) && (n+1<argc)) { cmds.push_back(argv[++n]); } else
60  usage("Unknown option");
61  }
62 
63  mbs::MonitorHandle ref = mbs::MonitorHandle::Connect(argv[1], cmdport, logport, statport);
64 
66 
67  //ref.MbsCmd("sta logrem");
68 
69  for (unsigned n=0;n<cmds.size();n++)
70  ref.MbsCmd(cmds[n], tmout);
71 
72  dabc::Sleep(waittm);
73 
74  ref.Disconnect();
75 
76  return 0;
77 }
bool Disconnect()
Release connection to the MBS node.
Definition: api.cxx:248
static MonitorHandle Connect(const std::string &mbsnode, int cmdport=6019, int logport=6007, int statport=6008)
Connect with MBS node.
Definition: api.cxx:218
bool MbsCmd(const std::string &cmd, double tmout=5.)
Execute MBS command.
Definition: api.cxx:268
int main(int argc, char *argv[])
Definition: mbscmd.cxx:42
int usage(const char *errstr=0)
Definition: mbscmd.cxx:23
void Sleep(double tm)
Definition: timing.cxx:129
void SetDebugLevel(int level=0)
Definition: logging.cxx:468
bool str_to_double(const char *val, double *res)
Convert string to double value.
Definition: string.cxx:216
bool str_to_int(const char *val, int *res)
Convert string to integer value.
Definition: string.cxx:142