diff --git a/slsReceiverSoftware/src/UDPRESTImplementation.cpp b/slsReceiverSoftware/src/UDPRESTImplementation.cpp index 5ae3e670c..c3f6bf836 100644 --- a/slsReceiverSoftware/src/UDPRESTImplementation.cpp +++ b/slsReceiverSoftware/src/UDPRESTImplementation.cpp @@ -44,7 +44,9 @@ UDPRESTImplementation::UDPRESTImplementation(){ } -UDPRESTImplementation::~UDPRESTImplementation(){} +UDPRESTImplementation::~UDPRESTImplementation(){ + delete rest; +} void UDPRESTImplementation::configure(map config_map){ @@ -74,67 +76,67 @@ void UDPRESTImplementation::configure(map config_map){ void UDPRESTImplementation::initialize_REST(){ FILE_LOG(logDEBUG) << __AT__ << " called"; - - if (rest_hostname.empty()) { - FILE_LOG(logDEBUG) << __AT__ <<"can't initialize with empty string or NULL for detectorHostname"; - } - else if (isInitialized == true) { - FILE_LOG(logDEBUG) << __AT__ << "already initialized, can't initialize several times"; - } - else { - FILE_LOG(logDEBUG) << __AT__ << "with receiverHostName=" << rest_hostname << ":" << rest_port; - - rest = new RestHelper() ; - std::string answer; - int code; - try{ - rest->init(rest_hostname, rest_port); - code = rest->get_json("state", &answer); - - if (code != 0){ - throw answer; - } - else{ - isInitialized = true; - status = slsReceiverDefs::IDLE; - } - FILE_LOG(logDEBUG) << __func__ << "Answer: " << answer; - } - catch(std::string e){ - FILE_LOG(logERROR) << __func__ << ": " << e; - throw; - } - - //JsonBox::Object json_object; - //json_object["configfile"] = JsonBox::Value("FILENAME"); - JsonBox::Value json_request; - //json_request["configfile"] = "config.py"; - json_request["path"] = filePath; - - stringstream ss; - string test; - std::cout << "GetSTring: " << json_request << std::endl; - json_request.writeToStream(ss, false); - //ss << json_request; - ss >> test; - - - test = "{\"path\":\"" + string( getFilePath() ) + "\"}"; - 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; - - - /* - std::std::cout << string << std::endl; << "---- REST test 3: true, json object "<< std::endl; - JsonBox::Value json_value; - code = rest.get_json("status", &json_value); - std::cout << "JSON " << json_value["status"] << std::endl; + + if (rest_hostname.empty()) { + FILE_LOG(logDEBUG) << __AT__ <<"can't initialize with empty string or NULL for detectorHostname"; + } + else if (isInitialized == true) { + FILE_LOG(logDEBUG) << __AT__ << "already initialized, can't initialize several times"; + } + else { + FILE_LOG(logDEBUG) << __AT__ << "with receiverHostName=" << rest_hostname << ":" << rest_port; + + rest = new RestHelper() ; + std::string answer; + int code; + try{ + rest->init(rest_hostname, rest_port); + code = rest->get_json("state", &answer); + + if (code != 0){ + throw answer; + } + else{ + isInitialized = true; + status = slsReceiverDefs::IDLE; + } + FILE_LOG(logDEBUG) << __func__ << "Answer: " << answer; + } + catch(std::string e){ + FILE_LOG(logERROR) << __func__ << ": " << e; + throw; + } + + //JsonBox::Object json_object; + //json_object["configfile"] = JsonBox::Value("FILENAME"); + JsonBox::Value json_request; + //json_request["configfile"] = "config.py"; + json_request["path"] = filePath; + + stringstream ss; + string test; + std::cout << "GetSTring: " << json_request << std::endl; + json_request.writeToStream(ss, false); + //ss << json_request; + ss >> test; + + + test = "{\"path\":\"" + string( getFilePath() ) + "\"}"; + 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; + + + /* + std::std::cout << string << std::endl; << "---- REST test 3: true, json object "<< std::endl; + JsonBox::Value json_value; + code = rest.get_json("status", &json_value); + std::cout << "JSON " << json_value["status"] << std::endl; */ - } - - FILE_LOG(logDEBUG) << __func__ << ": initialize() done"; + } + + FILE_LOG(logDEBUG) << __func__ << ": initialize() done"; } @@ -166,6 +168,10 @@ int UDPRESTImplementation::getFramesCaught(){ int UDPRESTImplementation::getTotalFramesCaught(){ FILE_LOG(logDEBUG) << __AT__ << " called"; + if (packetsPerFrame == 0){ + FILE_LOG(logWARNING) << __AT__ << " packetsPerFrame is 0!!!"; + return 0; + } return (totalPacketsCaught/packetsPerFrame); } @@ -216,7 +222,6 @@ int UDPRESTImplementation::getFileIndex(){ int UDPRESTImplementation::setFileIndex(int i){ FILE_LOG(logDEBUG) << __AT__ << " called"; - cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; if(i>=0) fileIndex = i; @@ -390,56 +395,12 @@ bool UDPRESTImplementation::getDataCompression(){ } int UDPRESTImplementation::enableDataCompression(bool enable){ - FILE_LOG(logDEBUG) << __AT__ << " called"; - cout << "Data compression "; - if(enable) - cout << "enabled" << endl; - else - cout << "disabled" << endl; -#ifdef MYROOT1 - cout << " WITH ROOT" << endl; -#else - cout << " WITHOUT ROOT" << endl; -#endif - //delete filter for the current number of threads - deleteFilter(); - - dataCompression = enable; - pthread_mutex_lock(&status_mutex); - writerthreads_mask = 0x0; - pthread_mutex_unlock(&(status_mutex)); - - createWriterThreads(true); - - if(enable) - numWriterThreads = MAX_NUM_WRITER_THREADS; - else - numWriterThreads = 1; - - if(createWriterThreads() == FAIL){ - cout << "ERROR: Could not create writer threads" << endl; - return FAIL; - } - setThreadPriorities(); - - - if(enable) - setupFilter(); - + FILE_LOG(logDEBUG) << __AT__ << " called, doing nothing"; return OK; } - - - - - - - - - /*other functions*/ @@ -462,6 +423,8 @@ void UDPRESTImplementation::deleteFilter(){ void UDPRESTImplementation::setupFilter(){ + //LEO: check + FILE_LOG(logDEBUG) << __AT__ << " called"; double hc = 0; double sigma = 5; @@ -698,7 +661,7 @@ int UDPRESTImplementation::createUDPSockets(){ } //normal socket else{ - cout<<"eth:"<get_json("state", &answer); @@ -742,7 +704,7 @@ int UDPRESTImplementation::shutDownUDPSockets(){ code = rest->get_json("state", &answer); std::cout << answer << std::endl; - status = slsReceiverDefs::IDLE; + status = slsReceiverDefs::RUN_FINISHED; @@ -1744,7 +1706,11 @@ void UDPRESTImplementation::startFrameIndices(int ithread){ } +void UDPRESTImplementation::stopListening(int ithread, int rc, int &pc, int &t){ + FILE_LOG(logDEBUG) << __AT__ << " called, doing nothing"; +}; +/* void UDPRESTImplementation::stopListening(int ithread, int rc, int &pc, int &t){ FILE_LOG(logDEBUG) << __AT__ << " called"; @@ -1754,7 +1720,7 @@ int i; cerr << ithread << " recvfrom() failed:"<push(buffer[ithread]); exit(-1); } @@ -1815,7 +1781,7 @@ int i; } } - +*/ diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index 6f2f7eb69..b3e8aa098 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -125,7 +125,8 @@ void UDPStandardImplementation::initializeMembers(){ } -UDPStandardImplementation::UDPStandardImplementation(){ +UDPStandardImplementation::UDPStandardImplementation(){ FILE_LOG(logDEBUG) << __AT__ << " called"; + FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting" ; @@ -182,7 +183,8 @@ UDPStandardImplementation::UDPStandardImplementation(){ -UDPStandardImplementation::~UDPStandardImplementation(){ +UDPStandardImplementation::~UDPStandardImplementation(){ FILE_LOG(logDEBUG) << __AT__ << " called"; + createListeningThreads(true); createWriterThreads(true); deleteMembers(); @@ -191,7 +193,8 @@ UDPStandardImplementation::~UDPStandardImplementation(){ -void UDPStandardImplementation::deleteMembers(){ +void UDPStandardImplementation::deleteMembers(){ FILE_LOG(logDEBUG) << __AT__ << " called"; + //kill threads if(thread_started){ createListeningThreads(true); @@ -224,7 +227,8 @@ void UDPStandardImplementation::deleteMembers(){ -int UDPStandardImplementation::setDetectorType(detectorType det){ +int UDPStandardImplementation::setDetectorType(detectorType det){ FILE_LOG(logDEBUG) << __AT__ << " called"; + cout << "Setting Receiver Type " << endl; deleteMembers(); @@ -451,6 +455,9 @@ int UDPStandardImplementation::setEnableOverwrite(int i){ /*other parameters*/ slsReceiverDefs::runStatus UDPStandardImplementation::getStatus() const{ + FILE_LOG(logDEBUG) << __AT__ << " called, status: " << status; + + return status; } @@ -465,12 +472,14 @@ char *UDPStandardImplementation::getDetectorHostname() const{ return (char*)detHostname; } -void UDPStandardImplementation::setEthernetInterface(char* c){ +void UDPStandardImplementation::setEthernetInterface(char* c){ FILE_LOG(logDEBUG) << __AT__ << " called"; + strcpy(eth,c); } -void UDPStandardImplementation::setUDPPortNo(int p){ +void UDPStandardImplementation::setUDPPortNo(int p){ FILE_LOG(logDEBUG) << __AT__ << " called"; + for(int i=0;i= 0) numberOfFrames = fnum; @@ -494,7 +504,8 @@ int UDPStandardImplementation::getScanTag() const{ } -int32_t UDPStandardImplementation::setScanTag(int32_t stag){ +int32_t UDPStandardImplementation::setScanTag(int32_t stag){ FILE_LOG(logDEBUG) << __AT__ << " called"; + if(stag >= 0) scanTag = stag; @@ -506,7 +517,8 @@ int UDPStandardImplementation::getDynamicRange() const{ return dynamicRange; } -int32_t UDPStandardImplementation::setDynamicRange(int32_t dr){ +int32_t UDPStandardImplementation::setDynamicRange(int32_t dr){ FILE_LOG(logDEBUG) << __AT__ << " called"; + cout << "Setting Dynamic Range" << endl; int olddr = dynamicRange; @@ -566,7 +578,8 @@ int32_t UDPStandardImplementation::setDynamicRange(int32_t dr){ -int UDPStandardImplementation::setShortFrame(int i){ +int UDPStandardImplementation::setShortFrame(int i){ FILE_LOG(logDEBUG) << __AT__ << " called"; + shortFrame=i; if(shortFrame!=-1){ @@ -596,7 +609,8 @@ int UDPStandardImplementation::setShortFrame(int i){ } -int UDPStandardImplementation::setNFrameToGui(int i){ +int UDPStandardImplementation::setNFrameToGui(int i){ FILE_LOG(logDEBUG) << __AT__ << " called"; + if(i>=0){ nFrameToGui = i; setupFifoStructure(); @@ -606,7 +620,8 @@ int UDPStandardImplementation::setNFrameToGui(int i){ -int64_t UDPStandardImplementation::setAcquisitionPeriod(int64_t index){ +int64_t UDPStandardImplementation::setAcquisitionPeriod(int64_t index){ FILE_LOG(logDEBUG) << __AT__ << " called"; + if(index >= 0){ if(index != acquisitionPeriod){ @@ -618,9 +633,11 @@ int64_t UDPStandardImplementation::setAcquisitionPeriod(int64_t index){ } -bool UDPStandardImplementation::getDataCompression(){return dataCompression;} +bool UDPStandardImplementation::getDataCompression(){ FILE_LOG(logDEBUG) << __AT__ << " called"; +return dataCompression;} + +int UDPStandardImplementation::enableDataCompression(bool enable){ FILE_LOG(logDEBUG) << __AT__ << " called"; -int UDPStandardImplementation::enableDataCompression(bool enable){ cout << "Data compression "; if(enable) cout << "enabled" << endl; @@ -673,7 +690,8 @@ int UDPStandardImplementation::enableDataCompression(bool enable){ /*other functions*/ -void UDPStandardImplementation::deleteFilter(){ +void UDPStandardImplementation::deleteFilter(){ FILE_LOG(logDEBUG) << __AT__ << " called"; + int i; cmSub=NULL; @@ -691,6 +709,8 @@ void UDPStandardImplementation::deleteFilter(){ void UDPStandardImplementation::setupFilter(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + double hc = 0; double sigma = 5; int sign = 1; @@ -727,6 +747,7 @@ void UDPStandardImplementation::setupFilter(){ //LEO: it is not clear to me.. void UDPStandardImplementation::setupFifoStructure(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; int64_t i; int oldn = numJobsPerThread; @@ -816,6 +837,8 @@ void UDPStandardImplementation::setupFifoStructure(){ /** acquisition functions */ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + //point to gui data if (guiData == NULL) guiData = latestData; @@ -850,6 +873,8 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum){ void UDPStandardImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, char* buf){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + //random read when gui not ready if((!nFrameToGui) && (!guiData)){ @@ -905,6 +930,7 @@ void UDPStandardImplementation::copyFrameToGui(char* startbuf[], uint32_t fnum, int UDPStandardImplementation::createUDPSockets(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; //if eth is mistaken with ip address @@ -950,6 +976,8 @@ int UDPStandardImplementation::createUDPSockets(){ int UDPStandardImplementation::shutDownUDPSockets(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + for(int i=0;iShutDownSocket(); @@ -965,6 +993,8 @@ int UDPStandardImplementation::shutDownUDPSockets(){ // TODO: add a destroyListeningThreads int UDPStandardImplementation::createListeningThreads(bool destroy){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + int i; void* status; @@ -1022,6 +1052,8 @@ int UDPStandardImplementation::createListeningThreads(bool destroy){ int UDPStandardImplementation::createWriterThreads(bool destroy){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + int i; void* status; @@ -1083,6 +1115,8 @@ int UDPStandardImplementation::createWriterThreads(bool destroy){ void UDPStandardImplementation::setThreadPriorities(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + int i; //assign priorities struct sched_param tcp_param, listen_param, write_param; @@ -1120,6 +1154,7 @@ void UDPStandardImplementation::setThreadPriorities(){ int UDPStandardImplementation::setupWriter(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; //reset writing thread variables packetsInFile=0; @@ -1203,6 +1238,8 @@ int UDPStandardImplementation::setupWriter(){ int UDPStandardImplementation::createCompressionFile(int ithr, int iframe){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + #ifdef MYROOT1 char temp[MAX_STR_LENGTH]; //create file name for gui purposes, and set up acquistion parameters @@ -1231,6 +1268,8 @@ int UDPStandardImplementation::createCompressionFile(int ithr, int iframe){ int UDPStandardImplementation::createNewFile(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + int gt = getFrameIndex(); if(gt==-1) gt=0; //create file name @@ -1295,6 +1334,8 @@ int UDPStandardImplementation::createNewFile(){ void UDPStandardImplementation::closeFile(int ithr){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + #ifdef VERBOSE cout << "In closeFile for thread " << ithr << endl; #endif @@ -1352,6 +1393,8 @@ void UDPStandardImplementation::closeFile(int ithr){ int UDPStandardImplementation::startReceiver(char message[]){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + int i; @@ -1420,6 +1463,7 @@ int UDPStandardImplementation::startReceiver(char message[]){ int UDPStandardImplementation::stopReceiver(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; //#ifdef VERBOSE @@ -1450,6 +1494,7 @@ int UDPStandardImplementation::stopReceiver(){ void UDPStandardImplementation::startReadout(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; //#ifdef VERBOSE cout << "Start Receiver Readout" << endl; @@ -1473,6 +1518,7 @@ void UDPStandardImplementation::startReadout(){ void* UDPStandardImplementation::startListeningThread(void* this_pointer){ + FILE_LOG(logDEBUG) << __AT__ << " called"; ((UDPStandardImplementation*)this_pointer)->startListening(); return this_pointer; @@ -1481,6 +1527,7 @@ void* UDPStandardImplementation::startListeningThread(void* this_pointer){ void* UDPStandardImplementation::startWritingThread(void* this_pointer){ + FILE_LOG(logDEBUG) << __AT__ << " called"; ((UDPStandardImplementation*)this_pointer)->startWriting(); return this_pointer; } @@ -1491,6 +1538,7 @@ void* UDPStandardImplementation::startWritingThread(void* this_pointer){ int UDPStandardImplementation::startListening(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; int ithread = currentListeningThreadIndex; #ifdef VERYVERBOSE cout << "In startListening() " << endl; @@ -1692,6 +1740,8 @@ int UDPStandardImplementation::startListening(){ int UDPStandardImplementation::startWriting(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + int ithread = currentWriterThreadIndex; #ifdef VERYVERBOSE cout << ithread << "In startWriting()" <