From e2c0181d92c9a7dd2cb382e2459210eda722a2c9 Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Thu, 23 Feb 2012 14:28:09 +0000 Subject: [PATCH] Universal client for both slsDetector and multiSlsDetector, depending on the syntax git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@393 951219d9-93cf-4727-9268-0efd64621fa3 --- .../slsDetectorClient/Makefile | 127 +++-------------- .../slsDetectorClient/sls_detector_client.cpp | 132 +++++++++++------- 2 files changed, 101 insertions(+), 158 deletions(-) diff --git a/slsDetectorSoftware/slsDetectorClient/Makefile b/slsDetectorSoftware/slsDetectorClient/Makefile index 1588a5c66..3eda2c3db 100644 --- a/slsDetectorSoftware/slsDetectorClient/Makefile +++ b/slsDetectorSoftware/slsDetectorClient/Makefile @@ -1,137 +1,50 @@ CFLAGS= -DC_ONLY -#FLAGS=-DVERBOSE -INCLUDES= -I../slsDetectorSoftware/commonFiles -I../slsDetectorSoftware/slsDetector -I ../slsDetectorSoftware/MySocketTCP -I../slsDetectorSoftware/usersFunctions -#-I../slsDetectorSoftware/mythenDetector -I../slsDetectorSoftware/gotthardDetector +FLAGS=-DVERBOSE +INCLUDES= -I../slsDetectorSoftware/commonFiles -I../slsDetectorSoftware/slsDetector -I ../slsDetectorSoftware/MySocketTCP -I../slsDetectorSoftware/mythenDetector -I../slsDetectorSoftware/gotthardDetector -I../slsDetectorSoftware/usersFunctions -I../slsDetectorSoftware/multiSlsDetector #LIBS=-L../TMythenDetector/bin/ -L$(QTDIR)/lib -LIBS= -L$(QTDIR)/lib -L../slsDetectorSoftware/ -LDFLAG=-lSlsDetector -lpthread - -MYTHEN = mythen_put mythen_get mythen_acquire -PICASSO = picasso_put picasso_get picasso_acquire -GOTTHARD = gotthard_put gotthard_get gotthard_acquire +LIBS= -L../slsDetectorSoftware/ +LDFLAG= -lSlsDetector -lpthread BIN=bin -SRC_CLNT=sls_detector_client.cpp +SRC_CLNT=multi_sls_detector_client.cpp -gotthard: lib $(GOTTHARD) -mythen: lib $(MYTHEN) -picasso: lib $(PICASSO) +all: lib sls_detector_put sls_detector_get sls_detector_acquire sls_detector_help lib: -# cd ../TMythenDetector && $(MAKE) cd ../slsDetectorSoftware && $(MAKE) lib -all: mythen gotthard picasso - - -mythen_put: $(SRC_CLNT) +sls_detector_put: $(SRC_CLNT) mkdir -p $(BIN) - $(CXX) -static -o $(BIN)/mythen_put $(SRC_CLNT) $(FLAGS) -lpthread $(INCLUDES) -DPUT -DMYTHEN_DET $(LIBS) $(LDFLAG) + $(CXX) -static -o $(BIN)/sls_detector_put $(SRC_CLNT) $(FLAGS) -lpthread $(INCLUDES) -DPUT $(LIBS) $(LDFLAG) -mythen_get: $(SRC_CLNT) +sls_detector_get: $(SRC_CLNT) mkdir -p $(BIN) - $(CXX) -static -o $(BIN)/mythen_get $(SRC_CLNT) $(FLAGS) -lpthread $(INCLUDES) -DGET -DMYTHEN_DET $(LIBS) $(LDFLAG) + $(CXX) -static -o $(BIN)/sls_detector_get $(SRC_CLNT) $(FLAGS) -lpthread $(INCLUDES) -DGET $(LIBS) $(LDFLAG) -mythen_acquire: $(SRC_CLNT) +sls_detector_acquire: $(SRC_CLNT) mkdir -p $(BIN) - $(CXX) -static -o $(BIN)/mythen_acquire $(SRC_CLNT) $(FLAGS) -lpthread $(INCLUDES) -DREADOUT -DMYTHEN_DET $(LIBS) $(LDFLAG) + $(CXX) -static -o $(BIN)/sls_detector_acquire $(SRC_CLNT) $(FLAGS) -lpthread $(INCLUDES) -DREADOUT $(LIBS) $(LDFLAG) - -mythen_clean: - rm -rf $(BIN)/$(MYTHEN) - - - - - - - - - -gotthard_put: $(SRC_CLNT) +sls_detector_help: $(SRC_CLNT) mkdir -p $(BIN) - $(CXX) -static -o $(BIN)/gotthard_put $(SRC_CLNT) $(FLAGS) -lpthread $(INCLUDES) -DPUT -DGOTTHARD_DET $(LIBS) $(LDFLAG) - -gotthard_get: $(SRC_CLNT) - mkdir -p $(BIN) - $(CXX) -static -o $(BIN)/gotthard_get $(SRC_CLNT) $(FLAGS) -lpthread $(INCLUDES) -DGET -DGOTTHARD_DET $(LIBS) $(LDFLAG) - -gotthard_acquire: $(SRC_CLNT) - mkdir -p $(BIN) - $(CXX) -static -o $(BIN)/gotthard_acquire $(SRC_CLNT) $(FLAGS) -lpthread $(INCLUDES) -DREADOUT -DGOTTHARD_DET $(LIBS) $(LDFLAG) + $(CXX) -static -o $(BIN)/sls_detector_help $(SRC_CLNT) $(FLAGS) -lpthread $(INCLUDES) -DHELP $(LIBS) $(LDFLAG) - -gotthard_clean: - rm -rf $(BIN)/$(GOTTHARD) +clean: + rm -rf $(BIN)/sls_detector_put sls_detector_get sls_detector_acquire sls_detector_help - - - - -picasso_put: $(SRC_CLNT) - mkdir -p $(BIN) - $(CXX) -static -o $(BIN)/picasso_put $(SRC_CLNT) $(FLAGS) -lpthread $(INCLUDES) -DPUT -DPICASSOD -DMYTHEN_DET $(LIBS) $(LDFLAG) - -picasso_get: $(SRC_CLNT) - mkdir -p $(BIN) - $(CXX) -static -o $(BIN)/picasso_get $(SRC_CLNT) $(FLAGS) -lpthread $(INCLUDES) -DGET -DPICASSOD -DMYTHEN_DET $(LIBS) $(LDFLAG) - -picasso_acquire: $(SRC_CLNT) - mkdir -p $(BIN) - $(CXX) -static -o $(BIN)/picasso_acquire $(SRC_CLNT) $(FLAGS) -lpthread $(INCLUDES) -DREADOUT -DGET -DPICASSOD -DMYTHEN_DET $(LIBS) $(LDFLAG) - - - -picasso_clean: - rm -rf $(BIN)/$(PICASSO) - - - - - - - - - - - - - -clean: picasso_clean mythen_clean gotthard_clean - - -install_mythen: mythen +install_sls_detector: all $(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR)) - cp -P $(BIN)/mythen_put $(DESTDIR) - cp -P $(BIN)/mythen_get $(DESTDIR) - cp -P $(BIN)/mythen_acquire $(DESTDIR) - -install_gotthard: gotthard - $(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR)) - cp -P $(BIN)/gotthard_put $(DESTDIR) - cp -P $(BIN)/gotthard_get $(DESTDIR) - cp -P $(BIN)/gotthard_acquire $(DESTDIR) - -install_picasso: picasso - $(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR)) - cp -P $(BIN)/picassoPut $(DESTDIR) - cp -P $(BIN)/picassoGet $(DESTDIR) - cp -P $(BIN)/picassoData $(DESTDIR) - -install_doc: - $(shell test -d $(DESTDIR) || mkdir -p $(DESTDIR)) - cp -P docs/* $(DESTDIR) - -install: install_mythen install_picasso install_gotthard - + cp -P $(BIN)/sls_detector_put $(DESTDIR) + cp -P $(BIN)/sls_detector_get $(DESTDIR) + cp -P $(BIN)/sls_detector_acquire $(DESTDIR) diff --git a/slsDetectorSoftware/slsDetectorClient/sls_detector_client.cpp b/slsDetectorSoftware/slsDetectorClient/sls_detector_client.cpp index 2942e7af4..9dcf2a6d6 100644 --- a/slsDetectorSoftware/slsDetectorClient/sls_detector_client.cpp +++ b/slsDetectorSoftware/slsDetectorClient/sls_detector_client.cpp @@ -1,6 +1,8 @@ #include #include + +#include "multiSlsDetector.h" #include "slsDetector.h" @@ -12,12 +14,13 @@ int main(int argc, char *argv[]) { - int id=0; + int id=-1, iv=0; char *c; string answer; + char cmd[100]; int action; - slsDetector *myDetector; - + slsDetectorCommand *myDetector; + #ifdef READOUT @@ -26,63 +29,90 @@ int main(int argc, char *argv[]) action=PUT_ACTION; #elif GET action=GET_ACTION; -#endif +#elif HELP + action=HELP_ACTION; +#endif + + if (argc>1){ - detectorType t; - -#ifdef MYTHEN_DET -#ifndef PICASSOD - t=MYTHEN; -#else - t=PICASSO; -#endif; -#elif GOTTHARD_DET - t=GOTTHARD; -#else - t=GENERIC; + iv=sscanf(argv[1],"%d%s",&id, cmd); + if (id>=0) { + if (iv==2) { + if (cmd[0]=='-') { +#ifdef VERBOSE + cout << "Using multiSlsDetector id=" << id << endl; #endif - - - - - if (argc>1 && sscanf(argv[1],"%d",&id)){ - - - myDetector=new slsDetector(t,id); - - - } else { - cout << "Wrong usage - should be: "<< argv[0] << " id"; - cout << "(:channel arg)" << endl; - - cout << slsDetector::helpLine(argc-1, argv+1, action); - - cout << endl; - return -1; + myDetector=new multiSlsDetector(id); + argv[1]=cmd+1; + } else if (cmd[0]==':') { +#ifdef VERBOSE + cout << "Using slsDetector id=" << id << endl; +#endif + myDetector=new slsDetector(id); + argv[1]=cmd+1; + } else { + cout << "Wrong syntax: no channels starts with integer number "<helpLine(argc-1, argv, action); cout << endl; return -1; +#endif + +#ifdef PUT + if (argc<3) { + cout << "Wrong usage - should be: "<< argv[0] << "[id:/id-]channel arg" << endl; + cout << myDetector->helpLine(argc-1, argv+1, action); + cout << endl; + return -1; + } +#endif +#ifdef VERBOSE + cout << "Using default multiSlsDetector" << id << endl; +#endif + myDetector=new multiSlsDetector(); + answer=myDetector->executeLine(argc-1, argv, action); + cout << answer<< endl; + return 0; } + + +#ifdef PUT + if (argc<3) { + cout << "Wrong usage - should be: "<< argv[0] <<" " << argv[1]<< " arg" << endl; + cout << myDetector->helpLine(argc-1, argv+1, action); + cout << endl; + return -1; + } #endif - if ((c=strchr(argv[1],':'))) - argv[1]=c+1; -#endif - answer=myDetector->executeLine(argc-1, argv+1, action); -#ifndef READOUT - cout << s << " " << answer<< endl; -#endif + + + if (argc<2) { + answer=myDetector->executeLine(argc-1, argv, action); + } else { + answer=myDetector->executeLine(argc-1, argv+1, action); + } + cout << answer<< endl; + return 0; }