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 SVNREPPATH ""
#define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3"
//#define SVNREV 0x579
//#define SVNREV 0x590
//#define SVNKIND ""
//#define SVNSCHED ""
#define SVNAUTH "l_maliakal_d"
#define SVNREV 0x579
#define SVNDATE 0x20130527
#define SVNREV 0x590
#define SVNDATE 0x20130603
//

View File

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

View File

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

View File

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

View File

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

View File

@ -69,27 +69,39 @@ public:
/**
* 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)
*/
int getTotalFramesCaught(){ return totalFramesCaught;};
uint32_t getTotalFramesCaught(){return totalFramesCaught;};
/**
* 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)
*/
int getFrameIndex();
uint32_t getFrameIndex();
/**
* 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)
@ -195,7 +207,7 @@ private:
detectorType myDetectorType;
/** max frames per file **/
int maxFramesPerFile;
uint32_t maxFramesPerFile;
/** File write enable */
int enableFileWrite;
@ -216,28 +228,34 @@ private:
int frameIndexNeeded;
/** 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) */
int startFrameIndex;
uint32_t startFrameIndex;
/** 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) */
int totalFramesCaught;
/** 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) */
int acquisitionIndex;
uint32_t acquisitionIndex;
/** Frames currently in current file, starts new file when it reaches max */
int framesInFile;
uint32_t framesInFile;
/** Previous Frame number from buffer */
int prevframenum;
uint32_t prevframenum;
/** thread listening to packets */
pthread_t listening_thread;
@ -283,10 +301,10 @@ private:
int shortFrame;
/** buffer size can be 1286*2 or 518 or 1286*40 */
int bufferSize;
uint32_t bufferSize;
/** number of packets per frame*/
int packetsPerFrame;
uint32_t packetsPerFrame;
/** gui data ready */
int guiDataReady;
@ -298,7 +316,7 @@ private:
char* guiFileName;
/** current frame number */
int currframenum;
uint32_t currframenum;
/** send every nth frame to gui or only upon gui request*/
int nFrameToGui;

View File

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

View File

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