diff --git a/slsReceiverSoftware/include/UDPInterface.h b/slsReceiverSoftware/include/UDPInterface.h index e2454e09b..60d9cc75b 100644 --- a/slsReceiverSoftware/include/UDPInterface.h +++ b/slsReceiverSoftware/include/UDPInterface.h @@ -21,19 +21,15 @@ #include "utilities.h" #include "logger.h" -/* -void print_not_implemented(string method_name){ - std::cout << "[WARNING] Method " << method_name << " not implemented!" << std::endl; -} -*/ + class UDPInterface { - /* abstract class that defines the public interface of an sls detector data receiver. + /* abstract class that defines the public interface of an sls detector data receiver UDP part. * * Use the factory method slsReceiverBase::create() to get an instance: * - * slsReceiverBase *receiver = slsReceiverBase::create() + * UDPInterface *receiver = UDPInterface::create() * * supported sequence of method-calls: * @@ -64,11 +60,6 @@ class UDPInterface { public: - /** - * constructor - */ - //UDPInterface(){}; - /** * Destructor */ @@ -80,11 +71,10 @@ class UDPInterface { static UDPInterface *create(string receiver_type = "standard"); virtual void configure(map config_map) = 0; + public: - - /** * Initialize the Receiver @param detectorHostName detector hostname @@ -94,10 +84,10 @@ class UDPInterface { /* Returns detector hostname - /returns hostname - * caller needs to deallocate the returned char array. - * if uninitialized, it must return NULL - */ + /returns hostname + * caller needs to deallocate the returned char array. + * if uninitialized, it must return NULL + */ virtual char *getDetectorHostname() const = 0; /** diff --git a/slsReceiverSoftware/include/UDPRESTImplementation.h b/slsReceiverSoftware/include/UDPRESTImplementation.h index 30cd782ed..32213f50c 100644 --- a/slsReceiverSoftware/include/UDPRESTImplementation.h +++ b/slsReceiverSoftware/include/UDPRESTImplementation.h @@ -48,8 +48,10 @@ class UDPRESTImplementation : protected virtual slsReceiverDefs, public UDPBaseI virtual ~UDPRESTImplementation(); + protected: void initialize_REST(); + public: void configure(map config_map); /** diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index c831621ee..58d0f2395 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -2121,12 +2121,24 @@ int UDPBaseImplementation::enableTenGiga(int enable){ createWriterThreads(true); } for(int i=0;i // SIGINT -#include // stat -#include // socket(), bind(), listen(), accept(), shut down -#include // sock_addr_in, htonl, INADDR_ANY -#include // exit() -#include //set precision -#include //munmap -*/ - #include #include using namespace std; @@ -35,7 +25,6 @@ UDPInterface * UDPInterface::create(string receiver_type){ cout << "Starting " << receiver_type << endl; return new UDPStandardImplementation(); } - //#ifdef REST else if (receiver_type == "REST"){ return new UDPRESTImplementation(); diff --git a/slsReceiverSoftware/src/UDPRESTImplementation.cpp b/slsReceiverSoftware/src/UDPRESTImplementation.cpp index 8f40e9552..5ae3e670c 100644 --- a/slsReceiverSoftware/src/UDPRESTImplementation.cpp +++ b/slsReceiverSoftware/src/UDPRESTImplementation.cpp @@ -31,12 +31,14 @@ using namespace std; /* TODO + filePath != getFilePath - + + better state handling. Now it is only IDLE - RUNNING - IDLE */ UDPRESTImplementation::UDPRESTImplementation(){ - + FILE_LOG(logDEBUG) << __AT__ << " called"; + + // Default values rest_hostname = "localhost"; rest_port = 8081; } @@ -57,20 +59,21 @@ void UDPRESTImplementation::configure(map config_map){ if(pos != string::npos){ istringstream (host_port_str.substr (pos)) >> rest_port; rest_hostname = host_port_str.substr(0, pos); - cout << rest_hostname << " " << rest_port << endl; } } - + + /* for(map::const_iterator i=config_map.begin(); i != config_map.end(); i++){ std::cout << i->first << " " << i->second<< std::endl; } - + */ }; 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"; @@ -116,7 +119,6 @@ void UDPRESTImplementation::initialize_REST(){ ss >> test; - cout << "aaaa" <post_json("state/initialize", &answer, test); FILE_LOG(logDEBUG) << __AT__ << "state/configure got " << code; @@ -147,17 +149,34 @@ int UDPRESTImplementation::setDetectorType(detectorType det){ /*Frame indices and numbers caught*/ -bool UDPRESTImplementation::getAcquistionStarted(){return acqStarted;}; +bool UDPRESTImplementation::getAcquistionStarted(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + return acqStarted; +}; -bool UDPRESTImplementation::getMeasurementStarted(){return measurementStarted;}; +bool UDPRESTImplementation::getMeasurementStarted(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + return measurementStarted; +}; -int UDPRESTImplementation::getFramesCaught(){return (packetsCaught/packetsPerFrame);} +int UDPRESTImplementation::getFramesCaught(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + return (packetsCaught/packetsPerFrame); +} -int UDPRESTImplementation::getTotalFramesCaught(){return (totalPacketsCaught/packetsPerFrame);} +int UDPRESTImplementation::getTotalFramesCaught(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + return (totalPacketsCaught/packetsPerFrame); +} -uint32_t UDPRESTImplementation::getStartFrameIndex(){return startFrameIndex;} +uint32_t UDPRESTImplementation::getStartFrameIndex(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + return startFrameIndex; +} uint32_t UDPRESTImplementation::getFrameIndex(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + if(!packetsCaught) frameIndex=-1; else @@ -167,15 +186,22 @@ uint32_t UDPRESTImplementation::getFrameIndex(){ uint32_t UDPRESTImplementation::getAcquisitionIndex(){ + //FILE_LOG(logDEBUG) << __AT__ << " called, idx: " << acquisitionIndex; if(!totalPacketsCaught) - acquisitionIndex=-1; + acquisitionIndex = -1; else acquisitionIndex = currframenum - startAcquisitionIndex; + + //FILE_LOG(logDEBUG) << __AT__ << " idx: " << acquisitionIndex + // << " currframenum: " << currframenum + // << " startAcqIdx: " << startAcquisitionIndex; + return acquisitionIndex; } void UDPRESTImplementation::resetTotalFramesCaught(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; acqStarted = false; startAcquisitionIndex = 0; totalPacketsCaught = 0; @@ -184,21 +210,23 @@ void UDPRESTImplementation::resetTotalFramesCaught(){ /*file parameters*/ int UDPRESTImplementation::getFileIndex(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; return fileIndex; } 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; - */ + return getFileIndex(); } int UDPRESTImplementation::setFrameIndexNeeded(int i){ - cout << "[WARNING] This is a base implementation, " << __func__ << " could have no effects." << endl; + FILE_LOG(logDEBUG) << __AT__ << " called"; frameIndexNeeded = i; return frameIndexNeeded; } @@ -230,6 +258,7 @@ int UDPRESTImplementation::setEnableOverwrite(int i){ /*other parameters*/ slsReceiverDefs::runStatus UDPRESTImplementation::getStatus() const{ + FILE_LOG(logDEBUG) << __AT__ << " called, status: " << status; return status; } @@ -243,12 +272,15 @@ char *UDPRESTImplementation::getDetectorHostname() const{ void UDPRESTImplementation::setEthernetInterface(char* c){ FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " starting"; + + // TODO: this segfaults //strcpy(eth,c); - FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " done"; + //FILE_LOG(logDEBUG) << __FILE__ << "::" << __func__ << " done"; } void UDPRESTImplementation::setUDPPortNo(int p){ + FILE_LOG(logDEBUG) << __AT__ << " called"; for(int i=0;i=0){ nFrameToGui = i; setupFifoStructure(); @@ -339,7 +373,7 @@ int UDPRESTImplementation::setNFrameToGui(int i){ int64_t UDPRESTImplementation::setAcquisitionPeriod(int64_t index){ - + FILE_LOG(logDEBUG) << __AT__ << " called"; if(index >= 0){ if(index != acquisitionPeriod){ acquisitionPeriod = index; @@ -350,9 +384,13 @@ int64_t UDPRESTImplementation::setAcquisitionPeriod(int64_t index){ } -bool UDPRESTImplementation::getDataCompression(){return dataCompression;} +bool UDPRESTImplementation::getDataCompression(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + return dataCompression; +} int UDPRESTImplementation::enableDataCompression(bool enable){ + FILE_LOG(logDEBUG) << __AT__ << " called"; cout << "Data compression "; if(enable) cout << "enabled" << endl; @@ -406,6 +444,7 @@ int UDPRESTImplementation::enableDataCompression(bool enable){ void UDPRESTImplementation::deleteFilter(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; int i; cmSub=NULL; @@ -423,6 +462,7 @@ void UDPRESTImplementation::deleteFilter(){ void UDPRESTImplementation::setupFilter(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; double hc = 0; double sigma = 5; int sign = 1; @@ -459,6 +499,11 @@ void UDPRESTImplementation::setupFilter(){ //LEO: it is not clear to me.. void UDPRESTImplementation::setupFifoStructure(){ + FILE_LOG(logDEBUG) << __AT__ << " called, doing nothing"; +} +/* +void UDPRESTImplementation::setupFifoStructure(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; int64_t i; int oldn = numJobsPerThread; @@ -504,10 +549,6 @@ void UDPRESTImplementation::setupFifoStructure(){ cout << "Number of Frames per buffer:" << numJobsPerThread << endl; cout << "Fifo Size:" << fifosize << endl; - /* - //for testing - numJobsPerThread = 3; fifosize = 11; - */ for(int i=0;iget_json("state", &answer); + std::cout << answer << std::endl; + + 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::IDLE; + + /* for(int i=0;iget_json("state", &answer); std::cout << answer << std::endl; + status = slsReceiverDefs::RUNNING; //reset listening thread variables /* @@ -1172,8 +1237,6 @@ int UDPRESTImplementation::startReceiver(char message[]){ sem_post(&writersmp[i]); */ - cout << "Receiver Started.\nStatus:" << status << endl; - return OK; } @@ -1230,6 +1293,8 @@ void UDPRESTImplementation::startReadout(){ void* UDPRESTImplementation::startListeningThread(void* this_pointer){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + ((UDPRESTImplementation*)this_pointer)->startListening(); return this_pointer; @@ -1238,6 +1303,7 @@ void* UDPRESTImplementation::startListeningThread(void* this_pointer){ void* UDPRESTImplementation::startWritingThread(void* this_pointer){ + FILE_LOG(logDEBUG) << __AT__ << " called"; ((UDPRESTImplementation*)this_pointer)->startWriting(); return this_pointer; } @@ -1248,6 +1314,8 @@ void* UDPRESTImplementation::startWritingThread(void* this_pointer){ int UDPRESTImplementation::startListening(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; + int ithread = currentListeningThreadIndex; #ifdef VERYVERBOSE cout << "In startListening() " << endl; @@ -1449,6 +1517,7 @@ int UDPRESTImplementation::startListening(){ int UDPRESTImplementation::startWriting(){ + FILE_LOG(logDEBUG) << __AT__ << " called"; int ithread = currentWriterThreadIndex; #ifdef VERYVERBOSE cout << ithread << "In startWriting()" <0) - port_no = pn; - - success=OK; - + myDetectorType(GOTTHARD), + receiverBase(rbase), + ret(OK), + lockStatus(0), + shortFrame(-1), + packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME), + dynamicrange(16), + socket(NULL), + killTCPServerThread(0), + tenGigaEnable(0), portNumber(DEFAULT_PORTNO+2){ + + int port_no=portNumber; + + + if (pn>0) + port_no = pn; + + success=OK; + //create socket if(success == OK){ socket = new MySocketTCP(port_no); @@ -56,24 +56,25 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* delete socket; socket=NULL; } else { - portNumber=port_no; + portNumber=port_no; //initialize variables strcpy(socket->lastClientIP,"none"); strcpy(socket->thisClientIP,"none1"); strcpy(mess,"dummy message"); - + function_table(); #ifdef VERBOSE cout << "Function table assigned." << endl; #endif - + //Catch signal SIGINT to close files properly signal(SIGINT,staticCloseFile); } } - + } + int slsReceiverTCPIPInterface::setPortNumber(int pn){ int p_number; MySocketTCP *oldsocket=NULL;;