diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile index b245a634f..4f90d6107 100644 --- a/slsReceiverSoftware/Makefile +++ b/slsReceiverSoftware/Makefile @@ -1,4 +1,3 @@ - include ../Makefile.include DESTDIR ?= ../bin diff --git a/slsReceiverSoftware/include/RestHelper.h b/slsReceiverSoftware/include/RestHelper.h index 5c10d0ff9..93382a610 100644 --- a/slsReceiverSoftware/include/RestHelper.h +++ b/slsReceiverSoftware/include/RestHelper.h @@ -74,14 +74,11 @@ class RestHelper { */ //Check for http:// string - FILE_LOG(logDEBUG) << __func__ << " starting"; + FILE_LOG(logDEBUG4) << __func__ << " starting"; string proto_str = "http://"; if( size_t found = hostname.find(proto_str) != string::npos ){ - cout << hostname << endl; - char c1[hostname.size()-found-1]; - cout << c1 << endl; size_t length1 = hostname.copy(c1, hostname.size()-found-1, proto_str.size()); c1[length1]='\0'; hostname = c1; @@ -168,7 +165,7 @@ class RestHelper { string answer; int code = send_request(session, req, &answer); if(code == 0 ) { - FILE_LOG(logDEBUG) << "ANSWER " << answer; + FILE_LOG(logDEBUG4) << "REQUEST: " << " ANSWER: " << answer; json_value->loadFromString(answer); } delete uri; @@ -192,7 +189,6 @@ class RestHelper { if (path.empty()) path = "/"; HTTPRequest req(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1 ); req.setContentType("application/json\r\n"); - cout << "REQUEST BODY " << request_body << endl; req.setContentLength( request_body.length() ); int code = send_request(session, req, answer, request_body); @@ -266,9 +262,8 @@ class RestHelper { if (request_body == "") session->sendRequest( (req) ); else{ - cout << request_body << endl; - ostream &os = session->sendRequest( req ) ; - os << request_body; + ostream &os = session->sendRequest( req ) ; + os << request_body; } HTTPResponse res; @@ -276,7 +271,7 @@ class RestHelper { StreamCopier::copyToString(is, *answer); code = res.getStatus(); if (code != 200){ - cout << "HTTP ERROR " << res.getStatus() << ": " << res.getReason() << endl; + FILE_LOG(logERROR) << "HTTP ERROR " << res.getStatus() << ": " << res.getReason() ; code = -1; } else diff --git a/slsReceiverSoftware/include/UDPRESTImplementation.h b/slsReceiverSoftware/include/UDPRESTImplementation.h index 32213f50c..19dd034c2 100644 --- a/slsReceiverSoftware/include/UDPRESTImplementation.h +++ b/slsReceiverSoftware/include/UDPRESTImplementation.h @@ -50,6 +50,8 @@ class UDPRESTImplementation : protected virtual slsReceiverDefs, public UDPBaseI protected: void initialize_REST(); + int get_rest_state(RestHelper * rest, string *rest_state); + public: void configure(map config_map); diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 58d0f2395..42296fda4 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -147,17 +147,17 @@ int UDPBaseImplementation::setDetectorType(detectorType det){ /*Frame indices and numbers caught*/ -bool UDPBaseImplementation::getAcquistionStarted(){return acqStarted;}; +bool UDPBaseImplementation::getAcquistionStarted(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return acqStarted;}; -bool UDPBaseImplementation::getMeasurementStarted(){return measurementStarted;}; +bool UDPBaseImplementation::getMeasurementStarted(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return measurementStarted;}; -int UDPBaseImplementation::getFramesCaught(){return (packetsCaught/packetsPerFrame);} +int UDPBaseImplementation::getFramesCaught(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return (packetsCaught/packetsPerFrame);} -int UDPBaseImplementation::getTotalFramesCaught(){return (totalPacketsCaught/packetsPerFrame);} +int UDPBaseImplementation::getTotalFramesCaught(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return (totalPacketsCaught/packetsPerFrame);} -uint32_t UDPBaseImplementation::getStartFrameIndex(){return startFrameIndex;} +uint32_t UDPBaseImplementation::getStartFrameIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return startFrameIndex;} -uint32_t UDPBaseImplementation::getFrameIndex(){ +uint32_t UDPBaseImplementation::getFrameIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; if(!packetsCaught) frameIndex=-1; else @@ -166,7 +166,7 @@ uint32_t UDPBaseImplementation::getFrameIndex(){ } -uint32_t UDPBaseImplementation::getAcquisitionIndex(){ +uint32_t UDPBaseImplementation::getAcquisitionIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; if(!totalPacketsCaught) acquisitionIndex=-1; else @@ -175,7 +175,7 @@ uint32_t UDPBaseImplementation::getAcquisitionIndex(){ } -void UDPBaseImplementation::resetTotalFramesCaught(){ +void UDPBaseImplementation::resetTotalFramesCaught(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; acqStarted = false; startAcquisitionIndex = 0; totalPacketsCaught = 0; @@ -185,10 +185,12 @@ void UDPBaseImplementation::resetTotalFramesCaught(){ /*file parameters*/ char* UDPBaseImplementation::getFilePath() const{ + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; + return (char*)filePath; } -inline char* UDPBaseImplementation::setFilePath(const char c[]){ +inline char* UDPBaseImplementation::setFilePath(const char c[]){ FILE_LOG(logDEBUG) << __AT__ << " starting"; FILE_LOG(logDEBUG) << __AT__ << "called"; if(strlen(c)){ //check if filepath exists @@ -207,10 +209,12 @@ inline char* UDPBaseImplementation::setFilePath(const char c[]){ char* UDPBaseImplementation::getFileName() const{ + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; + return (char*)fileName; } -inline char* UDPBaseImplementation::setFileName(const char c[]){ +inline char* UDPBaseImplementation::setFileName(const char c[]){ FILE_LOG(logDEBUG) << __AT__ << " starting"; //cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; if(strlen(c)) @@ -220,11 +224,11 @@ inline char* UDPBaseImplementation::setFileName(const char c[]){ } -int UDPBaseImplementation::getFileIndex(){ +int UDPBaseImplementation::getFileIndex(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; return fileIndex; } -int UDPBaseImplementation::setFileIndex(int i){ +int UDPBaseImplementation::setFileIndex(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; //cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; if(i>=0) fileIndex = i; @@ -232,7 +236,7 @@ int UDPBaseImplementation::setFileIndex(int i){ } -int UDPBaseImplementation::setFrameIndexNeeded(int i){ +int UDPBaseImplementation::setFrameIndexNeeded(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; //cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; frameIndexNeeded = i; return frameIndexNeeded; @@ -240,19 +244,23 @@ int UDPBaseImplementation::setFrameIndexNeeded(int i){ int UDPBaseImplementation::getEnableFileWrite() const{ - return enableFileWrite; + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; + +return enableFileWrite; } -int UDPBaseImplementation::setEnableFileWrite(int i){ +int UDPBaseImplementation::setEnableFileWrite(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; enableFileWrite=i; return getEnableFileWrite(); } int UDPBaseImplementation::getEnableOverwrite() const{ + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; + return overwrite; } -int UDPBaseImplementation::setEnableOverwrite(int i){ +int UDPBaseImplementation::setEnableOverwrite(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; overwrite=i; return getEnableOverwrite(); } @@ -268,7 +276,7 @@ slsReceiverDefs::runStatus UDPBaseImplementation::getStatus() const{ } -void UDPBaseImplementation::initialize(const char *detectorHostName){ +void UDPBaseImplementation::initialize(const char *detectorHostName){ FILE_LOG(logDEBUG) << __AT__ << " starting"; if(strlen(detectorHostName)) strcpy(detHostname,detectorHostName); } @@ -278,12 +286,12 @@ char *UDPBaseImplementation::getDetectorHostname() const{ return (char*)detHostname; } -void UDPBaseImplementation::setEthernetInterface(char* c){ +void UDPBaseImplementation::setEthernetInterface(char* c){ FILE_LOG(logDEBUG) << __AT__ << " starting"; strcpy(eth,c); } -void UDPBaseImplementation::setUDPPortNo(int p){ +void UDPBaseImplementation::setUDPPortNo(int p){ FILE_LOG(logDEBUG) << __AT__ << " starting"; for(int i=0;i= 0) numberOfFrames = fnum; @@ -308,7 +316,7 @@ int UDPBaseImplementation::getScanTag() const{ } -int32_t UDPBaseImplementation::setScanTag(int32_t stag){ +int32_t UDPBaseImplementation::setScanTag(int32_t stag){ FILE_LOG(logDEBUG) << __AT__ << " starting"; if(stag >= 0) scanTag = stag; @@ -320,7 +328,7 @@ int UDPBaseImplementation::getDynamicRange() const{ return dynamicRange; } -int32_t UDPBaseImplementation::setDynamicRange(int32_t dr){ +int32_t UDPBaseImplementation::setDynamicRange(int32_t dr){ FILE_LOG(logDEBUG) << __AT__ << " starting"; cout << "Setting Dynamic Range" << endl; int olddr = dynamicRange; @@ -380,7 +388,7 @@ int32_t UDPBaseImplementation::setDynamicRange(int32_t dr){ -int UDPBaseImplementation::setShortFrame(int i){ +int UDPBaseImplementation::setShortFrame(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; shortFrame=i; if(shortFrame!=-1){ @@ -410,7 +418,7 @@ int UDPBaseImplementation::setShortFrame(int i){ } -int UDPBaseImplementation::setNFrameToGui(int i){ +int UDPBaseImplementation::setNFrameToGui(int i){ FILE_LOG(logDEBUG) << __AT__ << " starting"; if(i>=0){ nFrameToGui = i; setupFifoStructure(); @@ -420,7 +428,7 @@ int UDPBaseImplementation::setNFrameToGui(int i){ -int64_t UDPBaseImplementation::setAcquisitionPeriod(int64_t index){ +int64_t UDPBaseImplementation::setAcquisitionPeriod(int64_t index){ FILE_LOG(logDEBUG) << __AT__ << " starting"; if(index >= 0){ if(index != acquisitionPeriod){ @@ -432,9 +440,9 @@ int64_t UDPBaseImplementation::setAcquisitionPeriod(int64_t index){ } -bool UDPBaseImplementation::getDataCompression(){return dataCompression;} +bool UDPBaseImplementation::getDataCompression(){ FILE_LOG(logDEBUG) << __AT__ << " starting";return dataCompression;} -int UDPBaseImplementation::enableDataCompression(bool enable){ +int UDPBaseImplementation::enableDataCompression(bool enable){ FILE_LOG(logDEBUG) << __AT__ << " starting"; cout << "Data compression "; if(enable) cout << "enabled" << endl; @@ -487,7 +495,7 @@ int UDPBaseImplementation::enableDataCompression(bool enable){ /*other functions*/ -void UDPBaseImplementation::deleteFilter(){ +void UDPBaseImplementation::deleteFilter(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; int i; cmSub=NULL; @@ -504,7 +512,7 @@ void UDPBaseImplementation::deleteFilter(){ } -void UDPBaseImplementation::setupFilter(){ +void UDPBaseImplementation::setupFilter(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; double hc = 0; double sigma = 5; int sign = 1; @@ -540,7 +548,7 @@ void UDPBaseImplementation::setupFilter(){ //LEO: it is not clear to me.. -void UDPBaseImplementation::setupFifoStructure(){ +void UDPBaseImplementation::setupFifoStructure(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; int64_t i; int oldn = numJobsPerThread; @@ -629,7 +637,7 @@ void UDPBaseImplementation::setupFifoStructure(){ /** acquisition functions */ -void UDPBaseImplementation::readFrame(char* c,char** raw, uint32_t &fnum){ +void UDPBaseImplementation::readFrame(char* c,char** raw, uint32_t &fnum){ FILE_LOG(logDEBUG) << __AT__ << " starting"; //point to gui data if (guiData == NULL) guiData = latestData; @@ -663,7 +671,7 @@ void UDPBaseImplementation::readFrame(char* c,char** raw, uint32_t &fnum){ -void UDPBaseImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){ +void UDPBaseImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){ FILE_LOG(logDEBUG) << __AT__ << " starting"; //random read when gui not ready if((!nFrameToGui) && (!guiData)){ @@ -718,9 +726,7 @@ void UDPBaseImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char -int UDPBaseImplementation::createUDPSockets(){ - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; - +int UDPBaseImplementation::createUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; //if eth is mistaken with ip address if (strchr(eth,'.')!=NULL) @@ -764,7 +770,7 @@ int UDPBaseImplementation::createUDPSockets(){ -int UDPBaseImplementation::shutDownUDPSockets(){ +int UDPBaseImplementation::shutDownUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; for(int i=0;iShutDownSocket(); @@ -779,7 +785,7 @@ int UDPBaseImplementation::shutDownUDPSockets(){ -int UDPBaseImplementation::createListeningThreads(bool destroy){ +int UDPBaseImplementation::createListeningThreads(bool destroy){ FILE_LOG(logDEBUG) << __AT__ << " starting"; int i; void* status; @@ -834,7 +840,7 @@ int UDPBaseImplementation::createListeningThreads(bool destroy){ -int UDPBaseImplementation::createWriterThreads(bool destroy){ +int UDPBaseImplementation::createWriterThreads(bool destroy){ FILE_LOG(logDEBUG) << __AT__ << " starting"; int i; void* status; @@ -895,7 +901,7 @@ int UDPBaseImplementation::createWriterThreads(bool destroy){ -void UDPBaseImplementation::setThreadPriorities(){ +void UDPBaseImplementation::setThreadPriorities(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; int i; //assign priorities struct sched_param tcp_param, listen_param, write_param; @@ -932,7 +938,7 @@ void UDPBaseImplementation::setThreadPriorities(){ -int UDPBaseImplementation::setupWriter(){ +int UDPBaseImplementation::setupWriter(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; //reset writing thread variables packetsInFile=0; @@ -1017,7 +1023,7 @@ int UDPBaseImplementation::setupWriter(){ -int UDPBaseImplementation::createCompressionFile(int ithr, int iframe){ +int UDPBaseImplementation::createCompressionFile(int ithr, int iframe){ FILE_LOG(logDEBUG) << __AT__ << " starting"; #ifdef MYROOT1 char temp[MAX_STR_LENGTH]; //create file name for gui purposes, and set up acquistion parameters @@ -1045,7 +1051,7 @@ int UDPBaseImplementation::createCompressionFile(int ithr, int iframe){ -int UDPBaseImplementation::createNewFile(){ +int UDPBaseImplementation::createNewFile(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; cout << "[WARNING] This is a base implementation, " << __func__ << " not correctly implemented" << endl; @@ -1168,7 +1174,7 @@ void UDPBaseImplementation::closeFile(int ithr) -int UDPBaseImplementation::startReceiver(char message[]){ +int UDPBaseImplementation::startReceiver(char message[]){ FILE_LOG(logDEBUG) << __AT__ << " starting"; int i; @@ -1236,7 +1242,7 @@ int UDPBaseImplementation::startReceiver(char message[]){ -int UDPBaseImplementation::stopReceiver(){ +int UDPBaseImplementation::stopReceiver(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; //#ifdef VERBOSE @@ -1266,7 +1272,7 @@ int UDPBaseImplementation::stopReceiver(){ -void UDPBaseImplementation::startReadout(){ +void UDPBaseImplementation::startReadout(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; //#ifdef VERBOSE cout << "Start Receiver Readout" << endl; @@ -1289,7 +1295,7 @@ void UDPBaseImplementation::startReadout(){ -void* UDPBaseImplementation::startListeningThread(void* this_pointer){ +void* UDPBaseImplementation::startListeningThread(void* this_pointer){ FILE_LOG(logDEBUG) << __AT__ << " starting"; ((UDPBaseImplementation*)this_pointer)->startListening(); return this_pointer; @@ -1297,7 +1303,7 @@ void* UDPBaseImplementation::startListeningThread(void* this_pointer){ -void* UDPBaseImplementation::startWritingThread(void* this_pointer){ +void* UDPBaseImplementation::startWritingThread(void* this_pointer){ FILE_LOG(logDEBUG) << __AT__ << " starting"; ((UDPBaseImplementation*)this_pointer)->startWriting(); return this_pointer; } @@ -1307,7 +1313,7 @@ void* UDPBaseImplementation::startWritingThread(void* this_pointer){ -int UDPBaseImplementation::startListening(){ +int UDPBaseImplementation::startListening(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; int ithread = currentListeningThreadIndex; #ifdef VERYVERBOSE cout << "In startListening() " << endl; @@ -1508,7 +1514,7 @@ int UDPBaseImplementation::startListening(){ -int UDPBaseImplementation::startWriting(){ +int UDPBaseImplementation::startWriting(){ FILE_LOG(logDEBUG) << __AT__ << " starting"; int ithread = currentWriterThreadIndex; #ifdef VERYVERBOSE cout << ithread << "In startWriting()" < config_map){ }; +int UDPRESTImplementation::get_rest_state(RestHelper * rest, string *rest_state){ + + JsonBox::Value answer; + //string rest_state = ""; + int code = rest->get_json("state", &answer); + if ( code != -1 ){ + (*rest_state) = answer["state"].getString(); + } + + return code; +}; void UDPRESTImplementation::initialize_REST(){ FILE_LOG(logDEBUG) << __AT__ << " called"; @@ -91,7 +102,7 @@ void UDPRESTImplementation::initialize_REST(){ int code; try{ rest->init(rest_hostname, rest_port); - code = rest->get_json("state", &answer); + code = get_rest_state(rest, &answer); if (code != 0){ throw answer; @@ -115,7 +126,7 @@ void UDPRESTImplementation::initialize_REST(){ stringstream ss; string test; - std::cout << "GetSTring: " << json_request << std::endl; + //std::cout << "GetSTring: " << json_request << std::endl; json_request.writeToStream(ss, false); //ss << json_request; ss >> test; @@ -125,7 +136,7 @@ void UDPRESTImplementation::initialize_REST(){ code = rest->post_json("state/initialize", &answer, test); FILE_LOG(logDEBUG) << __AT__ << "state/configure got " << code; code = rest->get_json("state", &answer); - FILE_LOG(logDEBUG) << __AT__ << "state got " << code << " " << answer; + FILE_LOG(logDEBUG) << __AT__ << "state got " << code << " " << answer << "\n"; /* @@ -692,32 +703,28 @@ int UDPRESTImplementation::shutDownUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << "called"; - std::string answer; - int code = rest->get_json("state", &answer); - std::cout << answer << std::endl; + JsonBox::Value answer; + int code; + string be_state = ""; - code = rest->post_json("state/close", &answer); - std::cout << answer << std::endl; - code = rest->post_json("state/reset", &answer); - std::cout << answer << std::endl; - - code = rest->get_json("state", &answer); - std::cout << answer << std::endl; - - status = slsReceiverDefs::RUN_FINISHED; - - - - /* - for(int i=0;iShutDownSocket(); - delete udpSocket[i]; - udpSocket[i] = NULL; + // LEO: this is probably wrong + if (be_state == "OPEN"){ + while (be_state != "TRANSIENT"){ + code = rest->get_json("state", &answer); + be_state = answer["state"].getString(); + cout << be_state << endl; + usleep(10000); } } - */ + code = rest->post_json("state/close", &answer); + std::cout <post_json("state/reset", &answer); + std::cout << code << " " << answer << std::endl; + + code = rest->get_json("state", &answer); + std::cout << code << " " << answer << std::endl; + + status = slsReceiverDefs::RUN_FINISHED; FILE_LOG(logDEBUG) << __AT__ << "finished"; @@ -1131,17 +1138,14 @@ int UDPRESTImplementation::startReceiver(char message[]){ std::string answer; int code; - - //test = "{\"configfile\":\"config.pu\", \"path\":\"patto\"}"; - code = rest->post_json("state/configure", &answer); - std::cout << answer << std::endl; + // TODO: remove hardcode!!! + std::string request_body = "{\"settings\": {\"bit_depth\": 16, \"nimages\": 1}}"; //"{\"nimages\":\"1\", \"bit_depth\":\"16\"}"; + FILE_LOG(logDEBUG) << __FILE__ << "::" << " sending this configuration body: " << request_body; + code = rest->post_json("state/configure", &answer, request_body); code = rest->get_json("state", &answer); - std::cout << answer << std::endl; code = rest->post_json("state/open", &answer); - std::cout << answer << std::endl; code = rest->get_json("state", &answer); - std::cout << answer << std::endl; status = slsReceiverDefs::RUNNING; @@ -1234,17 +1238,21 @@ int UDPRESTImplementation::stopReceiver(){ void UDPRESTImplementation::startReadout(){ - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; + FILE_LOG(logDEBUG) << __AT__ << " starting"; //wait so that all packets which take time has arrived usleep(50000); + status = TRANSMITTING; + /********************************************/ + /* usleep(2000000); pthread_mutex_lock(&status_mutex); status = TRANSMITTING; pthread_mutex_unlock(&status_mutex); cout << "Status: Transmitting" << endl; + */ //kill udp socket to tell the listening thread to push last packet shutDownUDPSockets();