diff --git a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h index 3e996ae5e..88804c730 100644 --- a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h @@ -5,7 +5,8 @@ All set functions with argument -1 work as get, when possible */ - + #ifndef SLS_DETECTOR_FUNCS_H +#define SLS_DETECTOR_FUNCS_H enum { @@ -102,11 +103,15 @@ enum { F_READ_COUNTER_BLOCK, /**< reads the counter block memory for gotthard */ - F_RESET_COUNTER_BLOCK /**< resets the counter block memory for gotthard */ + F_RESET_COUNTER_BLOCK, /**< resets the counter block memory for gotthard */ + + F_SETUP_RECEIVER, /**< sets up receiver with parameters */ + + F_START_RECEIVER/**< starts/stops the receiver and returns status */ /* Always append functions hereafter!!! */ }; - +#endif SLS_DETECTOR_FUNCS_H /** @endinternal */ diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index daa75c80f..037d53275 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -3551,3 +3551,40 @@ int multiSlsDetector::readDataFile(string fname, int *data) { return iline; } + + + + +string multiSlsDetector::setupReceiver(string fileName) { + cout<<"File Name:"<numberOfDetectors; idet++) { + if (detectors[idet]) { + retval=detectors[idet]->setupReceiver(fileName); + if(!retval.empty()){ + retval1.append(retval); + retval1.append("+"); + } + } + } + return retval1; +} + + +slsDetectorDefs::runStatus multiSlsDetector::startReceiver(string status,int index) { + /**master receiver or writer?*/ + runStatus s, s1; + + if(detectors[0]) s1 = detectors[0]->startReceiver(status,index); + + for (int idet=1; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + s=detectors[idet]->startReceiver(status,index); + if(s==ERROR) + s1=ERROR; + if(s==IDLE && s1!=IDLE) + s1=ERROR; + } + } + return s1; +} diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 951a1383b..e0027ff6e 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -1002,6 +1002,21 @@ class multiSlsDetector : public slsDetectorUtils { slsDetector *getSlsDetector(int pos) {if (pos>=0 && pos< MAXDET) return detectors[pos]; return NULL;}; + /** Sets up the receiver + @param fileName file name + \returns receiver ip or none + */ + string setupReceiver(string fileName=""); + + + /** Starts/Stops the receiver + @param status status of receiver + @param index starting index of data file + \returns status + */ + runStatus startReceiver(string status="",int index=0); + + protected: diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 35984539f..e6fc287a6 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -5317,3 +5317,97 @@ slsDetectorDefs::synchronizationMode slsDetector::setSynchronization(synchroniza return retval; } + + + +string slsDetector::setupReceiver(string fileName) { + int fnum=F_SETUP_RECEIVER; + int ret = FAIL; + char mess[100]; + char arg[MAX_STR_LENGTH]; + strcpy(arg,fileName.c_str()); + + MySocketTCP *receiverSocket = new MySocketTCP(thisDetector->clientIP,thisDetector->dataPort); + + if (receiverSocket->getErrorStatus()){ +#ifdef VERBOSE + std::cout<< "Could not connect Control socket " << thisDetector->clientIP << " " << thisDetector->dataPort << std::endl; +#endif + delete receiverSocket; + receiverSocket=NULL; + } + else{ + if(receiverSocket){ + if (receiverSocket->Connect()>=0){ + if (receiverSocket->SendDataOnly(&fnum,sizeof(fnum))>=0) + if (receiverSocket->SendDataOnly(arg,MAX_STR_LENGTH)>=0){ + receiverSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if(ret==FAIL){ + receiverSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Receiver returned error: " << mess << std::endl; + } + } + receiverSocket->Disconnect(); + } + else strcpy(thisDetector->clientIP,"none"); + delete receiverSocket;//should I include also for good connection? cuz setTCPSocket() still uses it? + receiverSocket=NULL;//should I include also for good connection? cuz setTCPSocket() still uses it? + } + } + /**if force update, updateReceiver?*/ + if(ret==OK) return fileName; + return string(""); +} + + + + + + +slsDetectorDefs::runStatus slsDetector::startReceiver(string status,int index){ + int fnum=F_START_RECEIVER; + int ret = FAIL; + char mess[100]; + runStatus retval=ERROR; + int arg[2]; + arg[1] = index; + + //start=1,stop=0,get=-1 + arg[0] = -1; + if(status=="start") arg[0] = 1; + else if(status=="stop") arg[0] = 0; + + + MySocketTCP *receiverSocket = new MySocketTCP(thisDetector->clientIP,thisDetector->dataPort); + + if (receiverSocket->getErrorStatus()){ +#ifdef VERBOSE + std::cout<< "Could not connect Control socket " << thisDetector->clientIP << " " << thisDetector->dataPort << std::endl; +#endif + delete receiverSocket; + receiverSocket=NULL; + } + else{ + if(receiverSocket){ + if (receiverSocket->Connect()>=0){ + if (receiverSocket->SendDataOnly(&fnum,sizeof(fnum))>=0) + if (receiverSocket->SendDataOnly(arg,sizeof(arg))>=0){ + receiverSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if(ret!=FAIL){ + receiverSocket->ReceiveDataOnly(&retval,sizeof(retval)); + } + else{ + receiverSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Receiver returned error: " << mess << std::endl; + } + } + receiverSocket->Disconnect(); + } + else strcpy(thisDetector->clientIP,"none"); + delete receiverSocket;//should I include also for good connection? cuz setTCPSocket() still uses it? + receiverSocket=NULL;//should I include also for good connection? cuz setTCPSocket() still uses it? + } + } + /**if force update, updateReceiver?*/ + return retval; +} diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 401f776d3..5b24fc9af 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -1354,6 +1354,21 @@ typedef struct sharedSlsDetector { /** Frees the shared memory - should not be used*/ int freeSharedMemory(); + /** + Sets up the receiver + @param fileName file name + \returns receiver ip or none + */ + string setupReceiver(string fileName=""); + + + /** Starts/Stops the receiver + @param status status of receiver + @param index starting index of data file + \returns status + */ + runStatus startReceiver(string status="",int index=0); + protected: diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 5ea67a2b8..c9c9f8bdf 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -637,6 +637,13 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdConfiguration; i++; + + /* receiver functions */ + descrToFuncMap[i].m_pFuncName="receiver"; + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdReceiver; + i++; + + numberOfCommands=i; // #ifdef VERBOSE @@ -2075,6 +2082,8 @@ string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int actio networkParameter t; + string fileName = myDet->getFilePath()+string("/")+myDet->getFileName()+string("_"); + if (action==HELP_ACTION) return helpNetworkParameter(narg,args,action); @@ -2086,8 +2095,13 @@ string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int actio t=SERVER_MAC; } else return ("unknown network parameter")+cmd; - if (action==PUT_ACTION) - myDet->setNetworkParameter(t, args[1]); + if (action==PUT_ACTION){ + if(!strcmp(myDet->setNetworkParameter(t, args[1]),args[1])){ + if(t==CLIENT_IP) + if(myDet->setupReceiver(fileName).empty()) + return string("could not set up receiver file name."); + } + } return myDet->getNetworkParameter(t); } @@ -3378,3 +3392,39 @@ string slsDetectorCommand::helpConfiguration(int narg, char *args[], int action) } +string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) { + runStatus s; + if (action==HELP_ACTION) + return helpReceiver(narg, args, action); + + if (action==PUT_ACTION) { + if((strcasecmp(args[1],"start"))&&(strcasecmp(args[1],"stop"))) + return helpReceiver(narg, args, action); + s = myDet->startReceiver(string(args[1]),myDet->getFileIndex()); + //increment index by 1 if stopped successfully + if((!strcasecmp(args[1],"stop"))&&(s!=ERROR)) + myDet->setFileIndex(myDet->getFileIndex()+1); + } + + return myDet->runStatusType(myDet->startReceiver()); +} + + +string slsDetectorCommand::helpReceiver(int narg, char *args[], int action) { + + ostringstream os; + if (action==PUT_ACTION || action==HELP_ACTION) + os << "receiver [status] \t starts/stops the receiver to listen to detector packets. - can be start or stop" << std::endl; + if (action==GET_ACTION || action==HELP_ACTION) + os << "receiver \t returns the status of receiver - can be running or idle" << std::endl; + + return os.str(); + + + + + + + + +} diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.h b/slsDetectorSoftware/slsDetector/slsDetectorCommand.h index df3d4c598..d852bdd46 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.h @@ -82,7 +82,7 @@ class slsDetectorCommand : public virtual slsDetectorDefs { static string helpCounter(int narg, char *args[], int action); static string helpADC(int narg, char *args[], int action); static string helpEnablefwrite(int narg, char *args[], int action); - + static string helpReceiver(int narg, char *args[], int action); @@ -152,7 +152,7 @@ class slsDetectorCommand : public virtual slsDetectorDefs { string cmdCounter(int narg, char *args[], int action); string cmdADC(int narg, char *args[], int action); string cmdEnablefwrite(int narg, char *args[], int action); - + string cmdReceiver(int narg, char *args[], int action); int numberOfCommands; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index 1e6a1780e..06be3975c 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -570,6 +570,21 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { static int dummyAcquisitionFinished(double prog,int status,void* p){cout <<"Acquisition finished callback! " << prog << " " << status << endl; return 0;} static int dummyMeasurementFinished(int im,int findex,void* p){cout <<"Measurement finished callback! " << im << " " << findex << endl; return 0;} + /** + Sets up the receiver + @param fileName file name + \returns receiver ip or none + */ + virtual string setupReceiver(string fileName="")=0; + + /** Starts/Stops the receiver + @param status status of receiver + @param index starting index of data file + \returns status + */ + virtual runStatus startReceiver(string status="",int index=0)=0; + + protected: static const int64_t thisSoftwareVersion=0x20120124;