fixed the receiver index turning negative for moench problem

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@594 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
l_maliakal_d 2013-06-12 10:10:58 +00:00
parent 91adb03daa
commit d4bedf5ce6
8 changed files with 184 additions and 155 deletions

View File

@ -2,10 +2,10 @@
#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/gotthardDetectorServer" #define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/gotthardDetectorServer"
//#define SVNREPPATH "" //#define SVNREPPATH ""
#define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3" #define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3"
//#define SVNREV 0x579 //#define SVNREV 0x590
//#define SVNKIND "" //#define SVNKIND ""
//#define SVNSCHED "" //#define SVNSCHED ""
#define SVNAUTH "l_maliakal_d" #define SVNAUTH "l_maliakal_d"
#define SVNREV 0x579 #define SVNREV 0x590
#define SVNDATE 0x20130527 #define SVNDATE 0x20130603
// //

View File

@ -2,10 +2,10 @@
#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/moenchDetectorServer" #define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/moenchDetectorServer"
//#define SVNREPPATH "" //#define SVNREPPATH ""
#define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3" #define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3"
//#define SVNREV 0x579 //#define SVNREV 0x590
//#define SVNKIND "" //#define SVNKIND ""
//#define SVNSCHED "" //#define SVNSCHED ""
#define SVNAUTH "l_maliakal_d" #define SVNAUTH "l_maliakal_d"
#define SVNREV 0x579 #define SVNREV 0x590
#define SVNDATE 0x20130527 #define SVNDATE 0x20130603
// //

View File

@ -2,10 +2,10 @@
#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/mythenDetectorServer" #define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/mythenDetectorServer"
//#define SVNREPPATH "" //#define SVNREPPATH ""
#define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3" #define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3"
//#define SVNREV 0x579 //#define SVNREV 0x590
//#define SVNKIND "" //#define SVNKIND ""
//#define SVNSCHED "" //#define SVNSCHED ""
#define SVNAUTH "l_maliakal_d" #define SVNAUTH "l_maliakal_d"
#define SVNREV 0x579 #define SVNREV 0x590
#define SVNDATE 0x20130527 #define SVNDATE 0x20130603
// //

View File

@ -2,10 +2,10 @@
#define SVNURLLIB "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware" #define SVNURLLIB "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware"
//#define SVNREPPATH "" //#define SVNREPPATH ""
#define SVNREPUUIDLIB "951219d9-93cf-4727-9268-0efd64621fa3" #define SVNREPUUIDLIB "951219d9-93cf-4727-9268-0efd64621fa3"
//#define SVNREV 0x589 //#define SVNREV 0x592
//#define SVNKIND "" //#define SVNKIND ""
//#define SVNSCHED "" //#define SVNSCHED ""
#define SVNAUTHLIB "l_maliakal_d" #define SVNAUTHLIB "l_maliakal_d"
#define SVNREVLIB 0x589 #define SVNREVLIB 0x592
#define SVNDATELIB 0x20130529 #define SVNDATELIB 0x20130611
// //

View File

@ -30,10 +30,12 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det,bool moenchwit
fileIndex(0), fileIndex(0),
frameIndexNeeded(0), frameIndexNeeded(0),
framesCaught(0), framesCaught(0),
startFrameIndex(-1), acqStarted(false),
measurementStarted(false),
startFrameIndex(0),
frameIndex(0), frameIndex(0),
totalFramesCaught(0), totalFramesCaught(0),
startAcquisitionIndex(-1), startAcquisitionIndex(0),
acquisitionIndex(0), acquisitionIndex(0),
framesInFile(0), framesInFile(0),
prevframenum(0), prevframenum(0),
@ -119,26 +121,25 @@ void slsReceiverFunctionList::setEthernetInterface(char* c){
int slsReceiverFunctionList::getFrameIndex(){ uint32_t slsReceiverFunctionList::getFrameIndex(){
if(startFrameIndex==-1) if(!framesCaught)
frameIndex=0; frameIndex=0;
else if(myDetectorType == MOENCH) else if(frameIndexOffset)
frameIndex=currframenum - startFrameIndex; frameIndex = currframenum - startFrameIndex; //moench
else else
frameIndex=(currframenum - startFrameIndex)/packetsPerFrame; frameIndex = (currframenum - startFrameIndex)/packetsPerFrame;//moench with gotthard, gotthard
return frameIndex; return frameIndex;
} }
int slsReceiverFunctionList::getAcquisitionIndex(){ uint32_t slsReceiverFunctionList::getAcquisitionIndex(){
if(startAcquisitionIndex==-1) if(!totalFramesCaught)
acquisitionIndex=0; acquisitionIndex=0;
else if(myDetectorType == MOENCH) else if(frameIndexOffset)
acquisitionIndex=currframenum - startAcquisitionIndex; acquisitionIndex = currframenum - startAcquisitionIndex; //moench
else else
acquisitionIndex=(currframenum - startAcquisitionIndex)/packetsPerFrame; acquisitionIndex = (currframenum - startAcquisitionIndex)/packetsPerFrame; //moench with gotthard, gotthard
return acquisitionIndex; return acquisitionIndex;
} }
@ -177,7 +178,8 @@ int slsReceiverFunctionList::setFileIndex(int i){
void slsReceiverFunctionList::resetTotalFramesCaught(){ void slsReceiverFunctionList::resetTotalFramesCaught(){
startAcquisitionIndex = -1; acqStarted = false;
startAcquisitionIndex = 0;
totalFramesCaught = 0; totalFramesCaught = 0;
} }
@ -306,7 +308,9 @@ int slsReceiverFunctionList::startListening(){
#endif #endif
int rc; int rc;
startFrameIndex=-1;
measurementStarted = false;
startFrameIndex = 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
@ -343,20 +347,22 @@ int slsReceiverFunctionList::startListening(){
cerr << "recvfrom() failed" << endl; cerr << "recvfrom() failed" << endl;
//start for each scan //start for each scan
if(startFrameIndex==-1){ if(!measurementStarted){
if(!frameIndexOffset) if(!frameIndexOffset)
startFrameIndex = ((int)(*((int*)buffer)))- packetsPerFrame; startFrameIndex = ((uint32_t)(*((uint32_t*)buffer)));
else else
startFrameIndex = ((((int)(*((int*)buffer))) & (frameIndexMask)) >> frameIndexOffset)-1; startFrameIndex = ((((uint32_t)(*((uint32_t*)buffer))) & (frameIndexMask)) >> frameIndexOffset);
//cout<<"startFrameIndex:"<<startFrameIndex<<endl; //cout<<"startFrameIndex:"<<startFrameIndex<<endl;
prevframenum=startFrameIndex; prevframenum=startFrameIndex;
measurementStarted = true;
} }
//start of acquisition //start of acquisition
if(startAcquisitionIndex==-1){ if(!acqStarted){
startAcquisitionIndex=startFrameIndex; startAcquisitionIndex=startFrameIndex;
currframenum = startAcquisitionIndex; currframenum = startAcquisitionIndex;
acqStarted = true;
cout<<"startAcquisitionIndex:"<<startAcquisitionIndex<<endl; cout<<"startAcquisitionIndex:"<<startAcquisitionIndex<<endl;
} }
@ -475,16 +481,17 @@ int slsReceiverFunctionList::startWriting(){
else else
packetloss = ((currframenum-prevframenum-(framesInFile))/(double)(framesInFile))*100.000; packetloss = ((currframenum-prevframenum-(framesInFile))/(double)(framesInFile))*100.000;
cout << savefilename cout << savefilename
<< "\tpacket loss " << fixed << setprecision(4) << packetloss << "\tpacket loss " << setw(4)<<fixed << setprecision(4) << packetloss
<< "%\t\t framenum " << "%\tframenum "
<< currframenum //<< "\t\t p " << prevframenum << currframenum //<< "\t\t p " << prevframenum
<< "\tindex " << getFrameIndex()
<< endl; << endl;
} }
} }
//if(prevframenum != 0){ //if(prevframenum != 0){
if(framesCaught){ if(framesCaught){
prevframenum=currframenum; prevframenum = currframenum;
framesInFile = 0; framesInFile = 0;
} }
} }
@ -498,9 +505,9 @@ int slsReceiverFunctionList::startWriting(){
framesCaught++; framesCaught++;
totalFramesCaught++; totalFramesCaught++;
if(!frameIndexOffset) if(!frameIndexOffset)
currframenum = (int)(*((int*)wbuf)); currframenum = (uint32_t)(*((uint32_t*)wbuf));
else else
currframenum = (((int)(*((int*)wbuf))) & (frameIndexMask)) >> frameIndexOffset; currframenum = (((uint32_t)(*((uint32_t*)wbuf))) & (frameIndexMask)) >> frameIndexOffset;
//cout<<"**************curreframenm:"<<currframenum<<endl; //cout<<"**************curreframenm:"<<currframenum<<endl;

View File

@ -69,27 +69,39 @@ public:
/** /**
* Returns Frames Caught for each real time acquisition (eg. for each scan) * Returns Frames Caught for each real time acquisition (eg. for each scan)
*/ */
int getFramesCaught(){return framesCaught;}; uint32_t getFramesCaught(){return framesCaught;};
/** /**
* Returns Total Frames Caught for an entire acquisition (including all scans) * Returns Total Frames Caught for an entire acquisition (including all scans)
*/ */
int getTotalFramesCaught(){ return totalFramesCaught;}; uint32_t getTotalFramesCaught(){return totalFramesCaught;};
/** /**
* Returns the frame index at start of each real time acquisition (eg. for each scan) * Returns the frame index at start of each real time acquisition (eg. for each scan)
*/ */
int getStartFrameIndex(){return startFrameIndex;}; uint32_t getStartFrameIndex(){return startFrameIndex;};
/** /**
* Returns current Frame Index for each real time acquisition (eg. for each scan) * Returns current Frame Index for each real time acquisition (eg. for each scan)
*/ */
int getFrameIndex(); uint32_t getFrameIndex();
/** /**
* Returns current Frame Index Caught for an entire acquisition (including all scans) * Returns current Frame Index Caught for an entire acquisition (including all scans)
*/ */
int getAcquisitionIndex(); uint32_t getAcquisitionIndex();
/**
* Returns if acquisition started
*/
bool getAcquistionStarted(){return acqStarted;};
/**
* Returns if measurement started
*/
bool getMeasurementStarted(){return measurementStarted;};
/** /**
* Set File Name (without frame index, file index and extension) * Set File Name (without frame index, file index and extension)
@ -195,7 +207,7 @@ private:
detectorType myDetectorType; detectorType myDetectorType;
/** max frames per file **/ /** max frames per file **/
int maxFramesPerFile; uint32_t maxFramesPerFile;
/** File write enable */ /** File write enable */
int enableFileWrite; int enableFileWrite;
@ -216,28 +228,34 @@ private:
int frameIndexNeeded; int frameIndexNeeded;
/** Frames Caught for each real time acquisition (eg. for each scan) */ /** Frames Caught for each real time acquisition (eg. for each scan) */
int framesCaught; uint32_t framesCaught;
/* Acquisition started */
bool acqStarted;
/* Measurement started */
bool measurementStarted;
/** Frame index at start of each real time acquisition (eg. for each scan) */ /** Frame index at start of each real time acquisition (eg. for each scan) */
int startFrameIndex; uint32_t startFrameIndex;
/** Actual current frame index of each time acquisition (eg. for each scan) */ /** Actual current frame index of each time acquisition (eg. for each scan) */
int frameIndex; uint32_t frameIndex;
/** Total Frames Caught for an entire acquisition (including all scans) */ /** Total Frames Caught for an entire acquisition (including all scans) */
int totalFramesCaught; int totalFramesCaught;
/** Frame index at start of an entire acquisition (including all scans) */ /** Frame index at start of an entire acquisition (including all scans) */
int startAcquisitionIndex; uint32_t startAcquisitionIndex;
/** Actual current frame index of an entire acquisition (including all scans) */ /** Actual current frame index of an entire acquisition (including all scans) */
int acquisitionIndex; uint32_t acquisitionIndex;
/** 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; uint32_t framesInFile;
/** Previous Frame number from buffer */ /** Previous Frame number from buffer */
int prevframenum; uint32_t prevframenum;
/** thread listening to packets */ /** thread listening to packets */
pthread_t listening_thread; pthread_t listening_thread;
@ -283,10 +301,10 @@ private:
int shortFrame; int shortFrame;
/** buffer size can be 1286*2 or 518 or 1286*40 */ /** buffer size can be 1286*2 or 518 or 1286*40 */
int bufferSize; uint32_t bufferSize;
/** number of packets per frame*/ /** number of packets per frame*/
int packetsPerFrame; uint32_t packetsPerFrame;
/** gui data ready */ /** gui data ready */
int guiDataReady; int guiDataReady;
@ -298,7 +316,7 @@ private:
char* guiFileName; char* guiFileName;
/** current frame number */ /** current frame number */
int currframenum; uint32_t currframenum;
/** send every nth frame to gui or only upon gui request*/ /** send every nth frame to gui or only upon gui request*/
int nFrameToGui; int nFrameToGui;

View File

@ -932,8 +932,8 @@ int slsReceiverFuncs::moench_read_frame(){
for(i=0;i<rnel;i++) origVal[i]=0; for(i=0;i<rnel;i++) origVal[i]=0;
int index=-1; uint32_t startIndex=0;
int startIndex=-1; int index = 0;
int count=0; int count=0;
int offset=0; int offset=0;
@ -944,31 +944,32 @@ int slsReceiverFuncs::moench_read_frame(){
// execute action if the arguments correctly arrived // execute action if the arguments correctly arrived
#ifdef SLS_RECEIVER_FUNCTION_LIST #ifdef SLS_RECEIVER_FUNCTION_LIST
startIndex=slsReceiverList->getStartFrameIndex();
/**send garbage with -1 index to try again*/ /**send garbage with -1 index to try again*/
if(startIndex==-1) if(!slsReceiverList->getFramesCaught()){
cout<<"hadnt started yet"<<endl; arg = -1;
cout<<"haven't caught any frame yet"<<endl;
}
else{ else{
ret = OK; ret = OK;
//get frame startIndex=slsReceiverList->getStartFrameIndex();
slsReceiverList->readFrame(fName,&raw); slsReceiverList->readFrame(fName,&raw);
/**send garbage with -1 index to try again*/ /**send garbage with -1 index to try again*/
if (raw == NULL){ if (raw == NULL){
index = startIndex-1; arg = -1;
#ifdef VERBOSE #ifdef VERBOSE
cout<<"data not ready for gui yet"<<endl; cout<<"data not ready for gui yet"<<endl;
#endif #endif
}else{ }
//upto 40 indices, look at just index1 and index2 for now
index=(int)(*(int*)raw); else{
index = ((uint32_t)(*((uint32_t*)raw)));
memcpy(origVal,raw,bufferSize); memcpy(origVal,raw,bufferSize);
raw=NULL; raw=NULL;
}
//************** default order***************************** //************** default order*****************************
//filling up in y direction and then in x direcction
if(withGotthard){ if(withGotthard){
count = 0; count = 0;
offset = 4; offset = 4;
@ -996,25 +997,27 @@ int slsReceiverFuncs::moench_read_frame(){
//******************************************************** //********************************************************
//************** packet number order********************** //************** packet number order**********************
else{ else{
int numPackets = MOENCH_PACKETS_PER_FRAME; //40 if(!withGotthard)
int onePacketSize = MOENCH_DATA_BYTES / MOENCH_PACKETS_PER_FRAME; //1280*40 / 40 = 1280 index = ((index & (MOENCH_FRAME_INDEX_MASK)) >> MOENCH_FRAME_INDEX_OFFSET);
int packetDatabytes_row = onePacketSize * (MOENCH_BYTES_IN_ONE_ROW / MOENCH_BYTES_PER_ADC); //1280 * 4 = 5120 //cout<<"this frame number:"<<index<<endl;
int partsPerFrame = onePacketSize / MOENCH_BYTES_PER_ADC; // 1280 / 80 = 16
int packetOffset = 0; uint32_t numPackets = MOENCH_PACKETS_PER_FRAME; //40
int thisFrameNumber = (index & (MOENCH_FRAME_INDEX_MASK)) >> MOENCH_FRAME_INDEX_OFFSET; uint32_t onePacketSize = MOENCH_DATA_BYTES / MOENCH_PACKETS_PER_FRAME; //1280*40 / 40 = 1280
uint32_t packetDatabytes_row = onePacketSize * (MOENCH_BYTES_IN_ONE_ROW / MOENCH_BYTES_PER_ADC); //1280 * 4 = 5120
uint32_t partsPerFrame = onePacketSize / MOENCH_BYTES_PER_ADC; // 1280 / 80 = 16
uint32_t packetOffset = 0;
int packetIndex,x,y; int packetIndex,x,y;
int iPacket = 0; int iPacket = 0;
offset = 4; offset = 4;
//cout<<"this frame number:"<<thisFrameNumber<<endl;
while (iPacket < numPackets){ while (iPacket < numPackets){
#ifdef VERBOSE #ifdef VERBOSE
printf("iPacket:%d\n",iPacket);cout << endl; printf("iPacket:%d\n",iPacket);cout << endl;
#endif #endif
packetIndex = (*((int*)(((char*)origVal)+packetOffset))) & MOENCH_PACKET_INDEX_MASK; packetIndex = (*((uint32_t*)(((char*)origVal)+packetOffset))) & MOENCH_PACKET_INDEX_MASK;
//the first packet is placed in the end //the first packet is placed in the end
packetIndex--; packetIndex--;
if(packetIndex ==-1) if(packetIndex ==-1)
@ -1052,7 +1055,7 @@ int slsReceiverFuncs::moench_read_frame(){
// cout <<" checking next frame number:"<<hex<<(((*((int*)((char*)(origVal+packetOffset)))) & (MOENCH_FRAME_INDEX_MASK)) >> MOENCH_FRAME_INDEX_OFFSET)<<endl; // cout <<" checking next frame number:"<<hex<<(((*((int*)((char*)(origVal+packetOffset)))) & (MOENCH_FRAME_INDEX_MASK)) >> MOENCH_FRAME_INDEX_OFFSET)<<endl;
//check if same frame number //check if same frame number
/* while ((((*((int*)((char*)(origVal+packetOffset)))) & (MOENCH_FRAME_INDEX_MASK)) >> MOENCH_FRAME_INDEX_OFFSET) != thisFrameNumber){cout<<"did not match"<<endl; /* while ((((*((int*)((char*)(origVal+packetOffset)))) & (MOENCH_FRAME_INDEX_MASK)) >> MOENCH_FRAME_INDEX_OFFSET) != index){cout<<"did not match"<<endl;
if(iPacket >= numPackets) if(iPacket >= numPackets)
break; break;
//increment //increment
@ -1060,23 +1063,22 @@ int slsReceiverFuncs::moench_read_frame(){
iPacket++; iPacket++;
packetOffset = packetOffset + offset + onePacketSize; packetOffset = packetOffset + offset + onePacketSize;
}*/ }*/
} }
}
arg = index - startIndex;
if(withGotthard)
arg = arg/MOENCH_PACKETS_PER_FRAME;
} }
//******************************************************** //********************************************************
arg=index - startIndex;
} }
#ifdef VERBOSE #ifdef VERBOSE
cout << "\nstartIndex:" << startIndex << endl; cout << "\nstartIndex:" << startIndex << endl;
cout << "fName:" << fName << endl; cout << "fName:" << fName << endl;
cout << "index:" << arg << endl; cout << "index:" << arg << endl;
#endif #endif
#endif #endif
if(ret==OK && socket->differentClients){ if(ret==OK && socket->differentClients){
@ -1137,8 +1139,8 @@ int slsReceiverFuncs::gotthard_read_frame(){
//int* emptys = new int[rnel](); //int* emptys = new int[rnel]();
int index=-1,index2=-1; uint32_t index=0,index2=0;
int startIndex=-1; uint32_t startIndex=0;
int count=0; int count=0;
strcpy(mess,"Could not read frame\n"); strcpy(mess,"Could not read frame\n");
@ -1148,25 +1150,26 @@ int slsReceiverFuncs::gotthard_read_frame(){
#ifdef SLS_RECEIVER_FUNCTION_LIST #ifdef SLS_RECEIVER_FUNCTION_LIST
startIndex=slsReceiverList->getStartFrameIndex();
/**send garbage with -1 index to try again*/
if(startIndex==-1)
cout<<"hadnt started yet"<<endl;
else{
ret = OK;
//get frame /**send garbage with -1 index to try again*/
if(!slsReceiverList->getFramesCaught()){
arg=-1;
cout<<"haven't caught any frame yet"<<endl;
}else{
ret = OK;
startIndex=slsReceiverList->getStartFrameIndex();
slsReceiverList->readFrame(fName,&raw); slsReceiverList->readFrame(fName,&raw);
/**send garbage with -1 index to try again*/ /**send garbage with -1 index to try again*/
if (raw == NULL){ if (raw == NULL){
index = startIndex; arg = -1;
#ifdef VERBOSE #ifdef VERBOSE
cout<<"data not ready for gui yet"<<endl; cout<<"data not ready for gui yet"<<endl;
#endif #endif
}else{ }else{
index=(int)(*(int*)raw); index=(uint32_t)(*(uint32_t*)raw);
if(shortFrame==-1) if(shortFrame==-1)
index2= (int)(*((int*)((char*)(raw+onebuffersize)))); index2= (uint32_t)(*((uint32_t*)((char*)(raw+onebuffersize))));
memcpy(origVal,raw,bufferSize); memcpy(origVal,raw,bufferSize);
raw=NULL; raw=NULL;
@ -1193,8 +1196,9 @@ int slsReceiverFuncs::gotthard_read_frame(){
}else }else
cout << "same type: index:" << index << "\tindex2:" << index2 << endl; cout << "same type: index:" << index << "\tindex2:" << index2 << endl;
} }
arg = ((index - startIndex)/packetsPerFrame);
} }
arg=((index - startIndex)/packetsPerFrame)-1;
} }
#ifdef VERBOSE #ifdef VERBOSE

View File

@ -2,10 +2,10 @@
#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/slsReceiver" #define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/slsReceiver"
//#define SVNREPPATH "" //#define SVNREPPATH ""
#define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3" #define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3"
//#define SVNREV 0x589 //#define SVNREV 0x590
//#define SVNKIND "" //#define SVNKIND ""
//#define SVNSCHED "" //#define SVNSCHED ""
#define SVNAUTH "l_maliakal_d" #define SVNAUTH "l_maliakal_d"
#define SVNREV 0x589 #define SVNREV 0x590
#define SVNDATE 0x20130529 #define SVNDATE 0x20130603
// //