included exitReceiver, using different threads to listen and write packets in receiver, edited circularfifo to use pointer references, and acquire returns frames caught

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@362 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
l_maliakal_d 2012-11-30 09:28:52 +00:00
parent d8af12456d
commit 6b935f3bd2
12 changed files with 335 additions and 101 deletions

View File

@ -3808,3 +3808,21 @@ string multiSlsDetector::getReceiverLastClientIP() {
} }
int multiSlsDetector::exitReceiver() {
int ival=FAIL, iv;
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
if (detectors[idet]) {
iv=detectors[idet]->exitReceiver();
if (iv==OK)
ival=iv;
}
}
return ival;
}

View File

@ -1112,6 +1112,11 @@ class multiSlsDetector : public slsDetectorUtils {
*/ */
string getReceiverLastClientIP(); string getReceiverLastClientIP();
/**
Turns off the receiver server!
*/
int exitReceiver();
int fillModuleMask(int *mM); int fillModuleMask(int *mM);
protected: protected:

View File

@ -5805,3 +5805,30 @@ int slsDetector::updateReceiver() {
} }
int slsDetector::exitReceiver(){
int retval;
int fnum=F_EXIT_SERVER;
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
if (dataSocket) {
dataSocket->Connect();
dataSocket->SendDataOnly(&fnum,sizeof(fnum));
dataSocket->ReceiveDataOnly(&retval,sizeof(retval));
dataSocket->Disconnect();
}
}
if (retval!=OK) {
std::cout<< std::endl;
std::cout<< "Shutting down the receiver" << std::endl;
std::cout<< std::endl;
}
return retval;
};

View File

@ -1496,6 +1496,13 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
/returns OK /returns OK
*/ */
int updateReceiver(); int updateReceiver();
/**
Turns off the receiver server!
*/
int exitReceiver();
int fillModuleMask(int *mM); int fillModuleMask(int *mM);
protected: protected:

View File

@ -83,6 +83,11 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdExitServer; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdExitServer;
i++; i++;
descrToFuncMap[i].m_pFuncName="exitreceiver";//OK
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdExitServer;
i++;
/* data processing commands */ /* data processing commands */
@ -782,6 +787,11 @@ string slsDetectorCommand::cmdAcquire(int narg, char *args[], int action) {
myDet->setOnline(ONLINE_FLAG); myDet->setOnline(ONLINE_FLAG);
myDet->acquire(); myDet->acquire();
if(myDet->setReceiverOnline()==ONLINE_FLAG){
char answer[100];
sprintf(answer,"\n%d",myDet->getFramesCaughtByReceiver());
return string(answer);
}
return string(""); return string("");
@ -1209,19 +1219,32 @@ string slsDetectorCommand::cmdExitServer(int narg, char *args[], int action){
if (action==HELP_ACTION) { if (action==HELP_ACTION) {
return helpExitServer(narg, args, action); return helpExitServer(narg, args, action);
} }
myDet->setOnline(ONLINE_FLAG);
if (action==PUT_ACTION) { if (action==PUT_ACTION) {
if (myDet->exitServer()!=OK) if (cmd=="exitserver"){
return string("Server shut down."); myDet->setOnline(ONLINE_FLAG);
else if (myDet->exitServer()!=OK)
return string("Error closing server\n"); return string("Server shut down.");
else
return string("Error closing server\n");
}
else if (cmd=="exitreceiver"){
if(myDet->exitReceiver()!=OK)
return string("Receiver shut down\n");
else
return string("Error closing receiver\n");
}
else return("cannot decode command\n");
} else } else
return ("cannot get"); return ("cannot get");
} }
string slsDetectorCommand::helpExitServer(int narg, char *args[], int action){ string slsDetectorCommand::helpExitServer(int narg, char *args[], int action){
return string("exitserver \t shuts down all the detector servers. Don't use it!!!!"); ostringstream os;
os << string("exitserver \t shuts down all the detector servers. Don't use it!!!!\n");
os << string("exitreceiver \t shuts down all the receiver servers.\n");
return os.str();
} }

View File

@ -637,6 +637,11 @@ virtual int resetFramesCaught(int index=-1)=0;
virtual int* readFrameFromReceiver(char* fName, int &fIndex)=0; virtual int* readFrameFromReceiver(char* fName, int &fIndex)=0;
/**
Turns off the receiver server!
*/
virtual int exitReceiver()=0;
protected: protected:
static const int64_t thisSoftwareVersion=0x20120124; static const int64_t thisSoftwareVersion=0x20120124;

View File

@ -10,7 +10,7 @@
* Code & platform dependent issues with it was originally * Code & platform dependent issues with it was originally
* published at http://www.kjellkod.cc/threadsafecircularqueue * published at http://www.kjellkod.cc/threadsafecircularqueue
* 2009-11-02 * 2009-11-02
* @author Kjell Hedström, hedstrom@kjellkod.cc */ * @author Kjell Hedstr<EFBFBD>m, hedstrom@kjellkod.cc */
#ifndef CIRCULARFIFO_H_ #ifndef CIRCULARFIFO_H_
#define CIRCULARFIFO_H_ #define CIRCULARFIFO_H_
@ -25,15 +25,15 @@ public:
CircularFifo() : tail(0), head(0){} CircularFifo() : tail(0), head(0){}
virtual ~CircularFifo() {} virtual ~CircularFifo() {}
bool push(Element& item_); bool push(Element*& item_);
bool pop(Element& item_); bool pop(Element*& item_);
bool isEmpty() const; bool isEmpty() const;
bool isFull() const; bool isFull() const;
private: private:
volatile unsigned int tail; // input index volatile unsigned int tail; // input index
Element array[Capacity]; Element* array[Capacity];
volatile unsigned int head; // output index volatile unsigned int head; // output index
unsigned int increment(unsigned int idx_) const; unsigned int increment(unsigned int idx_) const;
@ -49,7 +49,7 @@ private:
* \param item_ copy by reference the input item * \param item_ copy by reference the input item
* \return whether operation was successful or not */ * \return whether operation was successful or not */
template<typename Element, unsigned int Size> template<typename Element, unsigned int Size>
bool CircularFifo<Element, Size>::push(Element& item_) bool CircularFifo<Element, Size>::push(Element*& item_)
{ {
int nextTail = increment(tail); int nextTail = increment(tail);
if(nextTail != head) if(nextTail != head)
@ -70,7 +70,7 @@ bool CircularFifo<Element, Size>::push(Element& item_)
* \param item_ return by reference the wanted item * \param item_ return by reference the wanted item
* \return whether operation was successful or not */ * \return whether operation was successful or not */
template<typename Element, unsigned int Size> template<typename Element, unsigned int Size>
bool CircularFifo<Element, Size>::pop(Element& item_) bool CircularFifo<Element, Size>::pop(Element*& item_)
{ {
if(head == tail) if(head == tail)
return false; // empty queue return false; // empty queue

View File

@ -9,6 +9,7 @@
#define BUFFER_SIZE 1286*2 #define BUFFER_SIZE 1286*2
#define DATABYTES 2560 #define DATABYTES 2560
#define DEFAULT_UDP_PORT 50001 #define DEFAULT_UDP_PORT 50001
#define FIFO_SIZE 25000

View File

@ -79,8 +79,10 @@ int main(int argc, char *argv[])
} }
} }
delete mysocket;
slsReceiverFuncs::closeFile(0);
cout << "Goodbye!" << endl; cout << "Goodbye!" << endl;
delete mysocket;
return 0; return 0;
} }

View File

@ -15,6 +15,8 @@
#include <arpa/inet.h> // sock_addr_in, htonl, INADDR_ANY #include <arpa/inet.h> // sock_addr_in, htonl, INADDR_ANY
#include <stdlib.h> // exit() #include <stdlib.h> // exit()
#include <iomanip> //set precision
#include <string.h> #include <string.h>
#include <iostream> #include <iostream>
@ -35,15 +37,18 @@ slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname):
startAcquisitionIndex(-1), startAcquisitionIndex(-1),
acquisitionIndex(0), acquisitionIndex(0),
framesInFile(0), framesInFile(0),
prevframenum(0),
status(IDLE), status(IDLE),
latestData(NULL),
udpSocket(NULL), udpSocket(NULL),
server_port(DEFAULT_UDP_PORT) server_port(DEFAULT_UDP_PORT),
fifo(NULL)
{ {
strcpy(savefilename,""); strcpy(savefilename,"");
strcpy(actualfilename,""); strcpy(actualfilename,"");
strcpy(filePath,""); strcpy(filePath,"");
strcpy(fileName,"run"); strcpy(fileName,"run");
strcpy(buffer,"");
} }
@ -52,7 +57,7 @@ int slsReceiverFunctionList::getFrameIndex(){
if(startFrameIndex==-1) if(startFrameIndex==-1)
frameIndex=0; frameIndex=0;
else else
frameIndex=((int)(*((int*)buffer)) - startFrameIndex)/2; frameIndex=((int)(*((int*)latestData)) - startFrameIndex)/2;
return frameIndex; return frameIndex;
} }
@ -62,7 +67,7 @@ int slsReceiverFunctionList::getAcquisitionIndex(){
if(startAcquisitionIndex==-1) if(startAcquisitionIndex==-1)
acquisitionIndex=0; acquisitionIndex=0;
else else
acquisitionIndex=((int)(*((int*)buffer)) - startAcquisitionIndex)/2; acquisitionIndex=((int)(*((int*)latestData)) - startAcquisitionIndex)/2;
return acquisitionIndex; return acquisitionIndex;
} }
@ -112,18 +117,38 @@ int slsReceiverFunctionList::startReceiver(){
#endif #endif
int err = 0; int err = 0;
if(!listening_thread_running){ if(!listening_thread_running){
printf("Starting new acquisition threadddd ....\n"); cout << "Starting new acquisition threadddd ...." << endl;
listening_thread_running=1; listening_thread_running=1;
err = pthread_create(&listening_thread, NULL,startListeningThread, (void*) this);
if(!err){ fifo = new CircularFifo<dataStruct,FIFO_SIZE>();
while(status!=RUNNING);
cout << endl << "Thread created successfully." << endl; //error creating writing thread
}else{ err = pthread_create(&writing_thread, NULL,startWritingThread, (void*) this);
if(err){
listening_thread_running=0; listening_thread_running=0;
status = IDLE; status = IDLE;
cout << endl << "Cant create thread. Status:" << status << endl; if(fifo) delete fifo;
cout << "Cant create writing thread. Status:" << status << endl << endl;
return FAIL; return FAIL;
} }
cout << "Writing thread created successfully." << endl;
//error creating listenign thread
err = 0;
err = pthread_create(&listening_thread, NULL,startListeningThread, (void*) this);
if(err){
listening_thread_running=0;
status = IDLE;
//stop writing thread
pthread_join(writing_thread,NULL);
if(fifo) delete fifo;
cout << endl << "Cant create listening thread. Status:" << status << endl << endl;
return FAIL;
}
while(status!=RUNNING);
cout << "Listening thread created successfully." << endl;
} }
return OK; return OK;
@ -140,14 +165,19 @@ int slsReceiverFunctionList::stopReceiver(){
if(listening_thread_running){ if(listening_thread_running){
cout << "Stopping new acquisition threadddd ...." << endl; cout << "Stopping new acquisition threadddd ...." << endl;
//stop thread //stop listening thread
listening_thread_running=0; listening_thread_running=0;
udpSocket->ShutDownSocket(); udpSocket->ShutDownSocket();
pthread_join(listening_thread,NULL); pthread_join(listening_thread,NULL);
status = IDLE; status = IDLE;
//stop writing thread
pthread_join(writing_thread,NULL);
if(fifo) delete fifo;
} }
cout << "Status:" << status << endl; cout << "Status:" << status << endl;
return OK; return OK;
} }
@ -161,33 +191,26 @@ void* slsReceiverFunctionList::startListeningThread(void* this_pointer){
int slsReceiverFunctionList::startListening(){ int slsReceiverFunctionList::startListening(){
#ifdef VERYVERBOSE #ifdef VERYVERBOSE
cout << "In startListening()\n"); cout << "In startListening()\n");
#endif #endif
// Variable and structure definitions // Variable and structure definitions
int rc, currframenum, prevframenum; int rc;
dataStruct *dataReadFrame;
//reset variables for each acquisition //reset variables for each acquisition
framesInFile=0;
framesCaught=0;
startFrameIndex=-1; startFrameIndex=-1;
frameIndex=0;
shortFileNameIndex=1; shortFileNameIndex=1;
//create file name
if(!frameIndexNeeded)
sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex);
else
sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,framesCaught,fileIndex);
if(!shortFileName)
strcpy(actualfilename,savefilename);
else
sprintf(actualfilename, "%s/%s_%d_%09d.raw", filePath,fileName,fileIndex, 0);
// A do/while(FALSE) loop is used to make error cleanup easier. The // A do/while(FALSE) loop is used to make error cleanup easier. The
// close() of each of the socket descriptors is only done once at the // close() of each of the socket descriptors is only done once at the
// very end of the program. // very end of the program.
@ -198,60 +221,42 @@ int slsReceiverFunctionList::startListening(){
break; break;
} }
sfilefd = fopen((const char *) (actualfilename), "w");
cout << "Saving to " << actualfilename << ". Ready! " << endl;
while (listening_thread_running) { while (listening_thread_running) {
if (framesInFile == 20000) {
fclose(sfilefd);
currframenum=(int)(*((int*)buffer));
//create file name
if(!frameIndexNeeded)
sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex);
else
sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,framesCaught,fileIndex);
if(!shortFileName)
strcpy(actualfilename,savefilename);
else
sprintf(actualfilename, "%s/%s_%d_%09d.raw", filePath,fileName,fileIndex, shortFileNameIndex);
shortFileNameIndex++;
cout << "saving to " << actualfilename << "\t\t"
"packet loss " << ((currframenum-prevframenum-(2*framesInFile))/(double)(2*framesInFile))*100.000 << "%\t\t"
"framenum " << currframenum << endl;
sfilefd = fopen((const char *) (actualfilename), "w");
prevframenum=currframenum;
framesInFile = 0;
}
status = RUNNING; status = RUNNING;
buffer = new char[BUFFER_SIZE];
//receiver 2 half frames //receiver 2 half frames
rc = udpSocket->ReceiveDataOnly(buffer,sizeof(buffer)); rc = udpSocket->ReceiveDataOnly(buffer,sizeof(buffer));
if( rc < 0) if( rc < 0)
cerr << "recvfrom() failed" << endl; cerr << "recvfrom() failed" << endl;
//for each scan //start for each scan
if(startFrameIndex==-1){ if(startFrameIndex==-1){
startFrameIndex=(int)(*((int*)buffer))-2; startFrameIndex=(int)(*((int*)buffer))-2;
//cout<<"startFrameIndex:"<<startFrameIndex<<endl;
prevframenum=startFrameIndex; prevframenum=startFrameIndex;
} }
//start of acquisition //start of acquisition
if(startAcquisitionIndex==-1) if(startAcquisitionIndex==-1){
startAcquisitionIndex=startFrameIndex; startAcquisitionIndex=startFrameIndex;
//cout<<"startAcquisitionIndex:"<<startAcquisitionIndex<<endl;
}
//so that it doesnt write the last frame twice //so that it doesnt write the last frame twice
if(listening_thread_running){ if(listening_thread_running){
fwrite(buffer, 1, rc, sfilefd); //s.assign(buffer);
framesInFile++; if(fifo->isFull())
framesCaught++; cout<<"**********************FIFO FULLLLLLLL************************"<<endl;
totalFramesCaught++; else{
dataReadFrame = new dataStruct;
dataReadFrame->buffer=buffer;
dataReadFrame->rc=rc;
//cout<<"read buffer:"<<dataReadFrame<<endl;
fifo->push(dataReadFrame);
}
} }
} }
@ -262,10 +267,108 @@ int slsReceiverFunctionList::startListening(){
//Close down any open socket descriptors //Close down any open socket descriptors
udpSocket->Disconnect(); udpSocket->Disconnect();
//close file
fclose(sfilefd);
#ifdef VERBOSE #ifdef VERBOSE
cout << "listening_thread_running:" << listening_thread_running << endl; cout << "listening_thread_running:" << listening_thread_running << endl;
#endif
return 0;
}
void* slsReceiverFunctionList::startWritingThread(void* this_pointer){
((slsReceiverFunctionList*)this_pointer)->startWriting();
return this_pointer;
}
int slsReceiverFunctionList::startWriting(){
#ifdef VERYVERBOSE
cout << "In startWriting()" <<endl;
#endif
// Variable and structure definitions
int currframenum,ret;
dataStruct *dataWriteFrame;
//reset variables for each acquisition
framesInFile=0;
framesCaught=0;
frameIndex=0;
latestData = new char[BUFFER_SIZE];
//create file name
if(!frameIndexNeeded) sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex);
else sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,framesCaught,fileIndex);
//for sebastian
if(!shortFileName) strcpy(actualfilename,savefilename);
else sprintf(actualfilename, "%s/%s_%d_%09d.raw", filePath,fileName,fileIndex, 0);
//start writing
sfilefd = fopen((const char *) (actualfilename), "w");
cout << "Saving to " << actualfilename << ". Ready! " << endl;
while(listening_thread_running){
//when it reaches 20000,start writing new file
if (framesInFile == 20000) {
fclose(sfilefd);
//create file name
if(!frameIndexNeeded) sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex);
else sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,framesCaught,fileIndex);
//for sebastian
if(!shortFileName) strcpy(actualfilename,savefilename);
else sprintf(actualfilename, "%s/%s_%d_%09d.raw", filePath,fileName,fileIndex, shortFileNameIndex);
shortFileNameIndex++;
currframenum=(int)(*((int*)latestData));
cout << "saving to " << actualfilename << "\t"
"packet loss " << fixed << setprecision(4) << ((currframenum-prevframenum-(2*framesInFile))/(double)(2*framesInFile))*100.000 << "%\t\t"
"framenum " << currframenum << "\t\t"
"p " << prevframenum << endl;
//start writing in new file
sfilefd = fopen((const char *) (actualfilename), "w");
prevframenum=currframenum;
framesInFile = 0;
}
//actual writing from fifo
if(!fifo->isEmpty()){
dataWriteFrame = new dataStruct;
if(fifo->pop(dataWriteFrame)){
//cout<<"write buffer:"<<dataWriteFrame<<endl<<endl;
framesCaught++;
totalFramesCaught++;
memcpy(latestData,dataWriteFrame->buffer,BUFFER_SIZE);
fwrite(dataWriteFrame->buffer, 1, dataWriteFrame->rc, sfilefd);
framesInFile++;
delete dataWriteFrame->buffer;
delete dataWriteFrame;
}
}
}
cout << "Total Frames Caught:"<< totalFramesCaught << endl;
//delete latestData;
//close file
fclose(sfilefd);
#ifdef VERBOSE
cout << "sfield:" << (int)sfilefd << endl; cout << "sfield:" << (int)sfilefd << endl;
#endif #endif
@ -277,9 +380,13 @@ int slsReceiverFunctionList::startListening(){
char* slsReceiverFunctionList::readFrame(char* c){ char* slsReceiverFunctionList::readFrame(char* c){
//cout<<"latestdata:"<<(int)(*(int*)latestData)<<endl;
strcpy(c,savefilename); strcpy(c,savefilename);
return buffer; return latestData;
} }

View File

@ -8,7 +8,9 @@
#include "sls_detector_defs.h" #include "sls_detector_defs.h"
#include "receiver_defs.h" #include "receiver_defs.h"
#include "genericSocket.h" #include "genericSocket.h"
#include "circularFifo.h"
#include <string.h>
#include <pthread.h> #include <pthread.h>
#include <stdio.h> #include <stdio.h>
@ -28,7 +30,7 @@ public:
/** /**
* Destructor * Destructor
*/ */
virtual ~slsReceiverFunctionList(){}; virtual ~slsReceiverFunctionList(){ if(latestData) delete latestData;};
/** /**
* Returns status of receiver: idle, running or error * Returns status of receiver: idle, running or error
@ -132,6 +134,20 @@ public:
*/ */
int startListening(); int startListening();
/**
* Static function - Thread started which writes packets to file.
* Called by startReceiver()
* @param this_pointer pointer to this object
*/
static void* startWritingThread(void *this_pointer);
/**
* Thread started which writes packets to file.
* Called by startReceiver()
*
*/
int startWriting();
/** /**
* Returns the buffer-current frame read by receiver * Returns the buffer-current frame read by receiver
*/ */
@ -185,20 +201,23 @@ private:
/** Frames currently in current file, starts new file when it reaches max */ /** Frames currently in current file, starts new file when it reaches max */
int framesInFile; int framesInFile;
/** if the listening thread is running*/ /** Previous Frame number from buffer */
//static int listening_thread_running; int prevframenum;
/** thread listening to packets */ /** thread listening to packets */
pthread_t listening_thread; pthread_t listening_thread;
/** thread writing packets */
pthread_t writing_thread;
/** status of receiver */ /** status of receiver */
runStatus status; runStatus status;
/** File Descriptor */
//static FILE *sfilefd;
/** Receiver buffer */ /** Receiver buffer */
char buffer[BUFFER_SIZE]; char* buffer;
/** latest data */
char* latestData;
/** UDP Socket between Receiver and Detector */ /** UDP Socket between Receiver and Detector */
genericSocket* udpSocket; genericSocket* udpSocket;
@ -206,6 +225,17 @@ private:
/** Server UDP Port*/ /** Server UDP Port*/
int server_port; int server_port;
/** Element structure to put inside a fifo */
struct dataStruct {
char* buffer;
int rc;
};
//dataStruct* dataReadFrame;
/** circular fifo to read and write data*/
CircularFifo<dataStruct,FIFO_SIZE>* fifo;
public: public:
/** File Descriptor */ /** File Descriptor */
static FILE *sfilefd; static FILE *sfilefd;

View File

@ -208,7 +208,7 @@ void slsReceiverFuncs::closeFile(int p){
close(file_des); close(file_des);
shutdown(socketDescriptor,SHUT_RDWR); //shutdown(socketDescriptor,SHUT_RDWR);
close(socketDescriptor); close(socketDescriptor);
} }
@ -479,7 +479,6 @@ int slsReceiverFuncs::get_frames_caught(){
#ifdef SLS_RECEIVER_FUNCTION_LIST #ifdef SLS_RECEIVER_FUNCTION_LIST
retval=slsReceiverList->getTotalFramesCaught(); retval=slsReceiverList->getTotalFramesCaught();
#endif #endif
if(ret==OK && socket->differentClients){ if(ret==OK && socket->differentClients){
cout << "Force update" << endl; cout << "Force update" << endl;
ret=FORCE_UPDATE; ret=FORCE_UPDATE;
@ -564,32 +563,31 @@ int slsReceiverFuncs::reset_frames_caught(){
int slsReceiverFuncs::read_frame(){ int slsReceiverFuncs::read_frame(){
ret=OK; ret=OK;
int nel = BUFFER_SIZE/(sizeof(int));
char fName[MAX_STR_LENGTH]; char fName[MAX_STR_LENGTH];
int arg = -1; int arg = -1;
int nel = BUFFER_SIZE/(sizeof(int));
int onebuffersize = BUFFER_SIZE/2; int onebuffersize = BUFFER_SIZE/2;
int onedatasize = DATABYTES/2; int onedatasize = DATABYTES/2;
char* raw=NULL; char* raw = new char[BUFFER_SIZE];
char* retval2=NULL; int* origVal = new int[nel];
int* origVal=new int[nel]; int* retval = new int[nel];
int* retval=new int[nel];
int index=-1,index2=-1; int index=-1,index2=-1;
int i,startIndex=-1; int startIndex=-1;
strcpy(mess,"Could not read frame\n"); strcpy(mess,"Could not read frame\n");
// execute action if the arguments correctly arrived // execute action if the arguments correctly arrived
#ifdef SLS_RECEIVER_FUNCTION_LIST #ifdef SLS_RECEIVER_FUNCTION_LIST
//wait till you get first frame 1. to get index(from startindex 2. filename corresponds to buffer value //wait till you get first frame 1. to get index(from startindex 2. filename corresponds to buffer value
if(startIndex==-1){ if(startIndex==-1){
ret=FAIL; ret=FAIL;
strcpy(mess,"did not start index\n"); strcpy(mess,"did not start index\n");
for(i=0;i<10;i++){ for(int i=0;i<10;i++){
startIndex=slsReceiverList->getStartFrameIndex(); startIndex=slsReceiverList->getStartFrameIndex();
if(startIndex==-1) if(startIndex==-1)
usleep(1000000); usleep(1000000);
@ -599,6 +597,7 @@ int slsReceiverFuncs::read_frame(){
} }
} }
} }
//got atleast first frame, read buffer //got atleast first frame, read buffer
if(ret==OK){ if(ret==OK){
int count=0; int count=0;
@ -606,10 +605,14 @@ int slsReceiverFuncs::read_frame(){
while(count<20){ while(count<20){
//get frame //get frame
raw=slsReceiverList->readFrame(fName); raw=slsReceiverList->readFrame(fName);
index=(int)(*((int*)raw)); //(int)(*(int*)buffer)
index=(int)(*(int*)raw);
index2= (int)(*((int*)((char*)(raw+onebuffersize)))); index2= (int)(*((int*)((char*)(raw+onebuffersize))));
memcpy(origVal,raw,BUFFER_SIZE); memcpy(origVal,raw,BUFFER_SIZE);
//cout<<"index:"<<index<<"\tindex2:"<<index2<<endl;
//1 odd, 1 even
if((index%2)!=index2%2){ if((index%2)!=index2%2){
//ideal situation (should be odd, even(index+1)) //ideal situation (should be odd, even(index+1))
if(index%2){ if(index%2){
@ -627,13 +630,18 @@ int slsReceiverFuncs::read_frame(){
ret=OK; ret=OK;
break; break;
} }
} }
#ifdef VERBOSE
strcpy(mess,"could not read frame due to more than 20 mismatched indices\n"); strcpy(mess,"could not read frame due to more than 20 mismatched indices\n");
cout<<"same type: index:"<<index<<"\tindex2:"<<index2<<endl<<endl; cout << "same type: index:" << index << "\tindex2:" << index2 << endl;;
usleep(1000); #endif
usleep(100000);
count++; count++;
} }
if(count==20)
cout << "same type: index:" << index << "\tindex2:" << index2 << endl;
arg=((index - startIndex)/2)-1; arg=((index - startIndex)/2)-1;
@ -641,6 +649,7 @@ int slsReceiverFuncs::read_frame(){
#ifdef VERBOSE #ifdef VERBOSE
cout << "\nstartIndex:" << startIndex << endl; cout << "\nstartIndex:" << startIndex << endl;
cout << "fName:" << fName << endl; cout << "fName:" << fName << endl;
cout << "index:" << arg << endl;
#endif #endif
} }
@ -866,12 +875,12 @@ int slsReceiverFuncs::update_client() {
int slsReceiverFuncs::exit_server() { int slsReceiverFuncs::exit_server() {
ret=FAIL; ret=GOODBYE;
socket->SendDataOnly(&ret,sizeof(ret)); socket->SendDataOnly(&ret,sizeof(ret));
strcpy(mess,"closing server"); strcpy(mess,"closing server");
cout << mess << endl;
socket->SendDataOnly(mess,sizeof(mess)); socket->SendDataOnly(mess,sizeof(mess));
return GOODBYE; cout << mess << endl;
return ret;
} }