From 22bd638f64e055f63c7affb9c3478444731603fb Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Wed, 30 Jan 2013 16:41:36 +0000 Subject: [PATCH] the gotthard receiver works for short frames, gui commented out for now git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@444 951219d9-93cf-4727-9268-0efd64621fa3 --- .../MySocketTCP/genericSocket.h | 12 +- .../commonFiles/sls_detector_defs.h | 7 +- .../gotthardDetectorServer/firmware_funcs.c | 30 +- .../gotthardDetectorServer/server_funcs.c | 6 +- .../slsDetector/slsDetector.cpp | 270 ++++++++++-------- .../slsDetectorAnalysis/postProcessing.cpp | 7 +- .../slsDetectorServer_funcs.c | 8 +- .../slsReceiver/receiver_defs.h | 16 +- .../slsReceiver/slsReceiverFunctionList.cpp | 62 +++- .../slsReceiver/slsReceiverFunctionList.h | 18 +- .../slsReceiver/slsReceiver_funcs.cpp | 80 +++++- .../slsReceiver/slsReceiver_funcs.h | 6 + 12 files changed, 349 insertions(+), 173 deletions(-) diff --git a/slsDetectorSoftware/MySocketTCP/genericSocket.h b/slsDetectorSoftware/MySocketTCP/genericSocket.h index cb0a3d219..5ef06778b 100644 --- a/slsDetectorSoftware/MySocketTCP/genericSocket.h +++ b/slsDetectorSoftware/MySocketTCP/genericSocket.h @@ -72,6 +72,7 @@ class sockaddr_in; using namespace std; #define DEFAULT_PACKET_SIZE 1286 +#define DEFAULT_PACKETS_PER_FRAME 2 #define DEFAULT_PORTNO 1952 #define DEFAULT_BACKLOG 5 #define DEFAULT_UDP_PORTNO 50001 @@ -89,9 +90,9 @@ enum communicationProtocol{ }; - genericSocket(const char* const host_ip_or_name, unsigned short int const port_number, communicationProtocol p) : + genericSocket(const char* const host_ip_or_name, unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE, int t = DEFAULT_PACKETS_PER_FRAME) : // portno(port_number), -protocol(p), is_a_server(0), socketDescriptor(-1),file_des(-1), packet_size(DEFAULT_PACKET_SIZE)// sender (client): where to? ip +protocol(p), is_a_server(0), socketDescriptor(-1),file_des(-1), packet_size(ps),packets_per_frame(t)// sender (client): where to? ip { // strcpy(hostname,host_ip_or_name); @@ -138,9 +139,9 @@ protocol(p), is_a_server(0), socketDescriptor(-1),file_des(-1), packet_size(DEFA */ - genericSocket(unsigned short int const port_number, communicationProtocol p, const char *eth=NULL): + genericSocket(unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE, int t = DEFAULT_PACKETS_PER_FRAME, const char *eth=NULL): //portno(port_number), - protocol(p), is_a_server(1),socketDescriptor(-1), file_des(-1), packet_size(DEFAULT_PACKET_SIZE){ + protocol(p), is_a_server(1),socketDescriptor(-1), file_des(-1), packet_size(ps), packets_per_frame(t){ /* // you can specify an IP address: */ /* */ @@ -521,7 +522,7 @@ protocol(p), is_a_server(0), socketDescriptor(-1),file_des(-1), packet_size(DEFA case UDP: if (socketDescriptor<0) return -1; // while(length>0){ - for(int i=0;i<2;i++){ + for(int i=0;ipacket_size) ? packet_size:length; nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length); @@ -625,6 +626,7 @@ protocol(p), is_a_server(0), socketDescriptor(-1),file_des(-1), packet_size(DEFA int nsending; int nsent; int total_sent; + int packets_per_frame; diff --git a/slsDetectorSoftware/commonFiles/sls_detector_defs.h b/slsDetectorSoftware/commonFiles/sls_detector_defs.h index 12fa8504a..fef414876 100755 --- a/slsDetectorSoftware/commonFiles/sls_detector_defs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_defs.h @@ -35,6 +35,9 @@ typedef float dacs_t; #define DEFAULT_DET_MAC "00:aa:bb:cc:dd:ee" #define DEFAULT_DET_IP "129.129.202.46" +#define MAX_FRAMES_PER_FILE 20000 +#define SHORT_MAX_FRAMES_PER_FILE 100000 + /** \file sls_detector_defs.h This file contains all the basic definitions common to the slsDetector class @@ -518,10 +521,10 @@ enum angleConversionParameter { /** Error flags */ -#define NUM_ERROR_FLAGS=32 +#define NUM_ERROR_FLAGS 32 #define CANNOT_CONNECT_TO_DETECTOR 0x80000000 #define CANNOT_CONNECT_TO_RECEIVER 0x40000000 -#define COULD_NOT_CONFIGURE_MAC 0x00008000 //cant seem to get this error +#define COULD_NOT_CONFIGURE_MAC 0x00008000 //typedef struct { diff --git a/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c b/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c index c838719ac..b79af8c8e 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c +++ b/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c @@ -244,26 +244,26 @@ int cleanFifo(){ printf("\nCleaning FIFO\n"); addr=ADC_SYNC_REG; - //88322114 + //88332214 if (ROI_flag==0) { val=ADCSYNC_VAL | ADCSYNC_CLEAN_FIFO_BITS | TOKEN_RESTART_DELAY; bus_w(addr,val); - //88022114 + //88032214 val=ADCSYNC_VAL | TOKEN_RESTART_DELAY; bus_w(addr,val); } else { - //1b322114 + //1b332214 val=ADCSYNC_VAL | ADCSYNC_CLEAN_FIFO_BITS | TOKEN_RESTART_DELAY_ROI; bus_w(addr,val); - //1b022114 + //1b032214 val=ADCSYNC_VAL | TOKEN_RESTART_DELAY_ROI; - + bus_w(addr,val); } reg=bus_r(addr); //#ifdef DDEBUG - printf("\n***ADC SYNC reg:%x****\n",reg); + printf("ADC SYNC reg 0x19:%x\n",reg); //#endif return OK; } @@ -290,11 +290,9 @@ int setDAQRegister(int adcval) reg=bus_r(addr); bus_w(addr,val); reg=bus_r(addr); -#ifdef VERBOSE - printf("DAQ reg:%x\n",reg); -#endif - - cleanFifo(); +//#ifdef VERBOSE + printf("DAQ reg 0x15:%x\n",reg); +//#endif return OK; } @@ -1182,11 +1180,11 @@ int configureMAC(int ipad,long long int macad,long long int detectormacad, int d //update adc configured adcConfigured = adc; - printf("configuring with adc:%d\n",adc); //setting adc mask int reg; int udpPacketSize=0x050E; int ipPacketSize=0x0522; + switch(adc){ case 0: case 1: @@ -1196,6 +1194,7 @@ int configureMAC(int ipad,long long int macad,long long int detectormacad, int d ROI_flag=1; //setting daqregister setDAQRegister(adc); + cleanFifo(); reg = (NCHAN*2)<fileIndex; framesPerFile=parentDet->framesPerFile; if(thisDetector->myDetectorType==GOTTHARD) - setFramesPerFile(20000); + setFramesPerFile(MAX_FRAMES_PER_FILE); thisReceiver = new receiverInterface(dataSocket); @@ -4548,6 +4548,9 @@ char* slsDetector::setDetectorIP(string detectorIP){ char* slsDetector::setReceiver(string receiverIP){ + if(getRunStatus()==RUNNING) + stopAcquisition(); + strcpy(thisDetector->receiver_hostname,receiverIP.c_str()); if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ @@ -4655,8 +4658,8 @@ int slsDetector::setUDPConnection(){ if(ret==FORCE_UPDATE) updateReceiver(); - //configure detector with udp details - if(configureMAC()==FAIL){ + //configure detector with udp details, -100 is so it doesnt overwrite the previous value + if(configureMAC(-1)==FAIL){ setReceiverOnline(OFFLINE_FLAG); std::cout << "could not configure mac" << endl; } @@ -4671,124 +4674,155 @@ int slsDetector::setUDPConnection(){ int slsDetector::configureMAC(int adc){ - int i; - int ret=FAIL; - int fnum=F_CONFIGURE_MAC; - char mess[100]; - char arg[5][50]; - char cword[50]="", *pcword; - string sword; + int i; + int ret=FAIL; + int fnum=F_CONFIGURE_MAC; + char mess[100]; + char arg[5][50]; + char cword[50]="", *pcword; + string sword; + int shortframe=1; + int retval=-100; - //if udpip wasnt initialized in config file - if(!(strcmp(thisDetector->receiverUDPIP,"none"))){ - //hostname is an ip address - if(strchr(thisDetector->receiver_hostname,'.')!=NULL) - strcpy(thisDetector->receiverUDPIP,thisDetector->receiver_hostname); - //if hostname not ip, convert it to ip - else{ - struct hostent *he = gethostbyname(thisDetector->receiver_hostname); - if (he != NULL) - strcpy(thisDetector->receiverUDPIP,inet_ntoa(*(struct in_addr*)he->h_addr)); - else{ - std::cout << "no rx_udpip given and invalid receiver hostname" << endl; - setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC)); - return FAIL; - } - } - } - strcpy(arg[0],thisDetector->receiverUDPIP); - strcpy(arg[1],thisDetector->receiverUDPMAC); - sprintf(arg[2],"%x",thisDetector->receiverUDPPort); - strcpy(arg[3],thisDetector->detectorMAC); - strcpy(arg[4],thisDetector->detectorIP); - -#ifdef VERBOSE - std::cout<< "Configuring MAC with adc:"<< adc << std::endl; -#endif - - - for(i=0;i<2;i++){ - if(!strcmp(arg[i],"none")){ - std::cout<< "Configure MAC Error. IP/MAC Addresses not set"<< std::endl; - setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC)); - return FAIL; - } - } - -#ifdef VERBOSE - std::cout<< "IP/MAC Addresses valid "<< std::endl; -#endif - - //converting IPaddress to hex. - pcword = strtok (arg[0],"."); - while (pcword != NULL) { - sprintf(arg[0],"%02x",atoi(pcword)); - strcat(cword,arg[0]); - pcword = strtok (NULL, "."); - } - strcpy(arg[0],cword); -#ifdef VERBOSE - std::cout<<"receiver udp ip:"<onlineFlag==ONLINE_FLAG) { - if (controlSocket) { - if (controlSocket->Connect()>=0) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(arg,sizeof(arg)); - controlSocket->SendDataOnly(&adc,sizeof(adc)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL){ - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC)); + if(((adc>=-1)&&(adc<=4))||(adc==-100)); + else{ + std::cout << "configure mac failed.\nConfigure [adc]; adc should be -1, 0, 1, 2, 3 or 4" << endl; + setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC)); + return FAIL; } - controlSocket->Disconnect(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } - } - if (ret==FAIL) { - std::cout<< "Configuring MAC failed " << std::endl; - setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC)); - } - return ret; + //if udpip wasnt initialized in config file + if(!(strcmp(thisDetector->receiverUDPIP,"none"))){ + //hostname is an ip address + if(strchr(thisDetector->receiver_hostname,'.')!=NULL) + strcpy(thisDetector->receiverUDPIP,thisDetector->receiver_hostname); + //if hostname not ip, convert it to ip + else{ + struct hostent *he = gethostbyname(thisDetector->receiver_hostname); + if (he != NULL) + strcpy(thisDetector->receiverUDPIP,inet_ntoa(*(struct in_addr*)he->h_addr)); + else{ + std::cout << "configure mac failed. no rx_udpip given and invalid receiver hostname" << endl; + setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC)); + return FAIL; + } + } + } + strcpy(arg[0],thisDetector->receiverUDPIP); + strcpy(arg[1],thisDetector->receiverUDPMAC); + sprintf(arg[2],"%x",thisDetector->receiverUDPPort); + strcpy(arg[3],thisDetector->detectorMAC); + strcpy(arg[4],thisDetector->detectorIP); + +#ifdef VERBOSE + std::cout<< "Configuring MAC with adc:"<< adc << std::endl; +#endif + + + for(i=0;i<2;i++){ + if(!strcmp(arg[i],"none")){ + std::cout<< "Configure MAC Error. IP/MAC Addresses not set"<< std::endl; + setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC)); + return FAIL; + } + } + +#ifdef VERBOSE + std::cout<< "IP/MAC Addresses valid "<< std::endl; +#endif + + //converting IPaddress to hex. + pcword = strtok (arg[0],"."); + while (pcword != NULL) { + sprintf(arg[0],"%02x",atoi(pcword)); + strcat(cword,arg[0]); + pcword = strtok (NULL, "."); + } + strcpy(arg[0],cword); +#ifdef VERBOSE + std::cout<<"receiver udp ip:"<onlineFlag==ONLINE_FLAG) { + if (controlSocket) { + if (controlSocket->Connect()>=0) { + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(arg,sizeof(arg)); + controlSocket->SendDataOnly(&adc,sizeof(adc)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL){ + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC)); + } + else + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + controlSocket->Disconnect(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + } + if (ret==FAIL) { + ret=FAIL; + std::cout<< "Configuring MAC failed " << std::endl; + setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC)); + } + else{ + //set frames per file + if(retval==-1) + setFramesPerFile(MAX_FRAMES_PER_FILE); + else + setFramesPerFile(SHORT_MAX_FRAMES_PER_FILE); + //connect to receiver + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ + if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ + if(retval==-1) shortframe=0; +#ifdef VERBOSE + std::cout << "Sending shortframe to receiver " << shortframe << std::endl; +#endif + ret=thisReceiver->sendInt(fnum,retval,shortframe); + if(ret==FAIL) + setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC)); + } + } + } + + return ret; } diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp index 63c4c9bbf..86a365075 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp @@ -393,6 +393,11 @@ void* postProcessing::processData(int delflag) { } //receiver else{ + while(1){ + if (checkJoinThread()) break; + usleep(200000); + } + /* pthread_mutex_lock(&mg); int prevCaught=getReceiverCurrentFrameIndex(); pthread_mutex_unlock(&mg); @@ -441,7 +446,7 @@ void* postProcessing::processData(int delflag) { cout<<"****Detector returned mismatched indeices***"<255) fnum=255; retval=(*flist[fnum])(file_des); diff --git a/slsDetectorSoftware/slsReceiver/receiver_defs.h b/slsDetectorSoftware/slsReceiver/receiver_defs.h index 6f30ebf69..62236f1b3 100755 --- a/slsDetectorSoftware/slsReceiver/receiver_defs.h +++ b/slsDetectorSoftware/slsReceiver/receiver_defs.h @@ -5,13 +5,19 @@ #include -#define GOODBYE -200 -#define BUFFER_SIZE 1286*2 -#define SHORT_BUFFER_SIZE 518 -#define DATABYTES 2560 -#define FIFO_SIZE 25000 +#define GOODBYE -200 + +#define BUFFER_SIZE 1286*2 +#define DATA_BYTES 2560 +#define MAX_FRAMES 20000 +#define PACKETS_PER_FRAME 2 + +#define SHORT_BUFFER_SIZE 518 +#define SHORT_MAX_FRAMES 100000 +#define SHORT_PACKETS_PER_FRAME 1 +#define FIFO_SIZE 25000 //#define THIS_SOFTWARE_VERSION 0x20120919 #endif diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp index 5cecd7ec2..ab17a3e10 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp @@ -26,6 +26,7 @@ FILE* slsReceiverFunctionList::sfilefd(NULL); int slsReceiverFunctionList::listening_thread_running(0); slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname): + maxFramesPerFile(MAX_FRAMES), enableFileWrite(1), shortFileName(shortfname), shortFileNameIndex(0), @@ -43,7 +44,10 @@ slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname): latestData(NULL), udpSocket(NULL), server_port(DEFAULT_UDP_PORTNO), - fifo(NULL) + fifo(NULL), + shortFrame(0), + bufferSize(BUFFER_SIZE), + packetsPerFrame(2) { strcpy(savefilename,""); strcpy(actualfilename,""); @@ -73,7 +77,7 @@ int slsReceiverFunctionList::getFrameIndex(){ if(startFrameIndex==-1) frameIndex=0; else - frameIndex=((int)(*((int*)latestData)) - startFrameIndex)/2; + frameIndex=((int)(*((int*)latestData)) - startFrameIndex)/packetsPerFrame; return frameIndex; } @@ -83,7 +87,7 @@ int slsReceiverFunctionList::getAcquisitionIndex(){ if(startAcquisitionIndex==-1) acquisitionIndex=0; else - acquisitionIndex=((int)(*((int*)latestData)) - startAcquisitionIndex)/2; + acquisitionIndex=((int)(*((int*)latestData)) - startAcquisitionIndex)/packetsPerFrame; return acquisitionIndex; } @@ -104,6 +108,10 @@ char* slsReceiverFunctionList::setFilePath(char c[]){ struct stat st; if(stat(c,&st) == 0) strcpy(filePath,c); + else{ + strcpy(filePath,""); + cout<<"FilePath does not exist:"<getErrorStatus()){ +#ifdef VERBOSE + std::cout<< "Could not create UDP socket "<< server_port << std::endl; +#endif break; } + while (listening_thread_running) { status = RUNNING; - buffer = new char[BUFFER_SIZE]; + buffer = new char[bufferSize]; //receiver 2 half frames rc = udpSocket->ReceiveDataOnly(buffer,sizeof(buffer)); if( rc < 0) @@ -254,7 +272,7 @@ int slsReceiverFunctionList::startListening(){ //start for each scan if(startFrameIndex==-1){ - startFrameIndex=(int)(*((int*)buffer))-2; + startFrameIndex=(int)(*((int*)buffer))-packetsPerFrame; //cout<<"startFrameIndex:"<buffer,BUFFER_SIZE); + memcpy(latestData,dataWriteFrame->buffer,bufferSize); //cout<<"list write \t index:"<<(int)(*(int*)latestData)<buffer, 1, dataWriteFrame->rc, sfilefd); @@ -423,5 +441,23 @@ char* slsReceiverFunctionList::readFrame(char* c){ } +int slsReceiverFunctionList::setShortFrame(int i){ + shortFrame=i; + + if(shortFrame){ + bufferSize = SHORT_BUFFER_SIZE; + maxFramesPerFile = SHORT_MAX_FRAMES; + packetsPerFrame = 1; + + }else{ + bufferSize = BUFFER_SIZE; + maxFramesPerFile = MAX_FRAMES; + packetsPerFrame = 2; + } + + return shortFrame; +} + + #endif diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h index b09518f6f..ecdbd7ff8 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h @@ -170,11 +170,18 @@ public: */ char* readFrame(char* c); + /** + * Set short frame + * @param i if shortframe i=1 + */ + int setShortFrame(int i); + private: - static const int MAX_FRAMES_PER_FILE = 20000; + /** max frames per file **/ + int maxFramesPerFile; /** File write enable */ int enableFileWrite; @@ -260,6 +267,15 @@ private: /** circular fifo to read and write data*/ CircularFifo* fifo; + /** short frames */ + int shortFrame; + + /** buffer size can be 1286*2 or 518 */ + int bufferSize; + + /** number of packets per frame*/ + int packetsPerFrame; + public: /** File Descriptor */ static FILE *sfilefd; diff --git a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp index b99fd0110..f94b1ba71 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp @@ -22,7 +22,8 @@ int slsReceiverFuncs::socketDescriptor(-1); slsReceiverFuncs::slsReceiverFuncs(MySocketTCP *&mySocket,string const fname,int &success, bool shortfname): socket(mySocket), ret(OK), - lockStatus(0){ + lockStatus(0), + shortFrame(0){ int port_no = DEFAULT_PORTNO+2; ifstream infile; @@ -128,6 +129,7 @@ int slsReceiverFuncs::function_table(){ flist[F_READ_FRAME] = &slsReceiverFuncs::read_frame; flist[F_ENABLE_FILE_WRITE] = &slsReceiverFuncs::enable_file_write; flist[F_GET_ID] = &slsReceiverFuncs::get_version; + flist[F_CONFIGURE_MAC] = &slsReceiverFuncs::set_short_frame; //General Functions flist[F_LOCK_SERVER] = &slsReceiverFuncs::lock_receiver; @@ -475,7 +477,7 @@ int slsReceiverFuncs::start_receiver(){ sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } - else if(!strlen(slsReceiverList->setFilePath(""))){ + else if(!strlen(slsReceiverList->getFilePath())){ strcpy(mess,"receiver not set up. set receiver ip again.\n"); ret = FAIL; } @@ -649,11 +651,22 @@ int slsReceiverFuncs::read_frame(){ char fName[MAX_STR_LENGTH]; int arg = -1; - int nel = BUFFER_SIZE/(sizeof(int)); - int onebuffersize = BUFFER_SIZE/2; - int onedatasize = DATABYTES/2; + int bufferSize = BUFFER_SIZE; + int databytes = DATA_BYTES; + int packetsPerFrame = PACKETS_PER_FRAME; - char* raw = new char[BUFFER_SIZE]; + if(shortFrame){ + bufferSize = SHORT_BUFFER_SIZE; + databytes = SHORT_BUFFER_SIZE; + packetsPerFrame = SHORT_PACKETS_PER_FRAME; + } + + int nel = bufferSize/(sizeof(int)); + int onebuffersize = bufferSize/packetsPerFrame; + int onedatasize = databytes/packetsPerFrame; + + + char* raw = new char[bufferSize]; int* origVal = new int[nel]; int* retval = new int[nel]; @@ -676,7 +689,7 @@ int slsReceiverFuncs::read_frame(){ ret=OK; break; }else - usleep(1000000); + usleep(500000); } @@ -687,7 +700,7 @@ int slsReceiverFuncs::read_frame(){ raw=slsReceiverList->readFrame(fName); index=(int)(*(int*)raw); index2= (int)(*((int*)((char*)(raw+onebuffersize)))); - memcpy(origVal,raw,BUFFER_SIZE); + memcpy(origVal,raw,bufferSize); raw=NULL; //cout<<"funcs\tindex:"<SendDataOnly(fName,MAX_STR_LENGTH); socket->SendDataOnly(&arg,sizeof(arg)); - socket->SendDataOnly(retval,DATABYTES); + socket->SendDataOnly(retval,DATA_BYTES); } //return ok/fail return ret; @@ -836,6 +849,55 @@ int slsReceiverFuncs::get_version(){ +int slsReceiverFuncs::set_short_frame() { + ret=OK; + int index=0; + int retval=-100; + strcpy(mess,"Could not set/reset short frame for receiver\n"); + + + // receive arguments + if(socket->ReceiveDataOnly(&index,sizeof(index)) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + ret = FAIL; + } + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_FUNCTION_LIST + if (ret==OK) { + if (lockStatus==1 && socket->differentClients==1){//necessary??? + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + else if(slsReceiverList->getStatus()==RUNNING){ + strcpy(mess,"Cannot set short frame while status is running\n"); + ret=FAIL; + } + else{ + retval=slsReceiverList->setShortFrame(index); + shortFrame = retval; + } + } +#endif + + if(ret==OK && socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + socket->SendDataOnly(&retval,sizeof(retval)); + + //return ok/fail + return ret; +} + + + + diff --git a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h index 8cc845b8b..37d3ebadf 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h +++ b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h @@ -83,6 +83,9 @@ public: /** Get Version */ int get_version(); + /** set short frame */ + int set_short_frame(); + //General Functions /** Locks Receiver */ int lock_receiver(); @@ -130,6 +133,9 @@ private: /** Lock Status if server locked to a client */ int lockStatus; + /** Short frame */ + int shortFrame; + static int file_des; static int socketDescriptor;