mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-12 12:57:13 +02:00
gotthard server fix: problem for new board due to component version change
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@675 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
@ -1815,33 +1815,112 @@ int allocateRAM() {
|
||||
int prepareADC(){
|
||||
printf("Preparing ADC\n");
|
||||
u_int32_t valw,codata,csmask;
|
||||
int i,cdx,ddx;
|
||||
int i,j,cdx,ddx,value;
|
||||
cdx=0; ddx=1;
|
||||
csmask=0x7c; // 1111100
|
||||
|
||||
for(j=0;j<3;j++){
|
||||
//command and value;
|
||||
codata = 0;
|
||||
if(j==0)
|
||||
codata=(0x08<<8)+(0x3);//Power modes(global) //reset
|
||||
else if(j==1)
|
||||
codata=(0x08<<8)+(0x0);//Power modes(global) //chip run
|
||||
else
|
||||
codata = (0x14<<8)+(0x0);//Output mode //offset binary
|
||||
|
||||
|
||||
// start point
|
||||
valw=0xff;
|
||||
bus_w(ADC_WRITE_REG,(valw));
|
||||
|
||||
//chip sel bar down
|
||||
valw=((0xffffffff&(~csmask)));
|
||||
bus_w(ADC_WRITE_REG,valw);
|
||||
|
||||
for (i=0;i<24;i++) {
|
||||
//cldwn
|
||||
valw=valw&(~(0x1<<cdx));
|
||||
bus_w(ADC_WRITE_REG,valw);
|
||||
usleep(0);
|
||||
|
||||
//write data (i)
|
||||
valw=(valw&(~(0x1<<ddx)))+(((codata>>(23-i))&0x1)<<ddx);
|
||||
bus_w(ADC_WRITE_REG,valw);
|
||||
usleep(0);
|
||||
|
||||
//clkup
|
||||
valw=valw+(0x1<<cdx);
|
||||
bus_w(ADC_WRITE_REG,valw);
|
||||
usleep(0);
|
||||
}
|
||||
|
||||
// stop point =start point
|
||||
valw=valw&(~(0x1<<cdx));
|
||||
usleep(0);
|
||||
valw=0xff;
|
||||
bus_w(ADC_WRITE_REG,(valw));
|
||||
|
||||
//usleep in between
|
||||
usleep(50000);
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
||||
/*
|
||||
codata=0;
|
||||
codata=(0x14<<8)+(0x0); //command and value;
|
||||
valw=0xff; bus_w(ADC_WRITE_REG,(valw)); // start point
|
||||
valw=((0xffffffff&(~csmask)));bus_w(ADC_WRITE_REG,valw); //chip sel bar down
|
||||
for (i=0;i<24;i++) {
|
||||
valw=valw&(~(0x1<<cdx));bus_w(ADC_WRITE_REG,valw);usleep(0); //cldwn
|
||||
#ifdef VERBOSE
|
||||
printf("DOWN 0x%x \n",valw);
|
||||
#endif
|
||||
|
||||
valw=(valw&(~(0x1<<ddx)))+(((codata>>(23-i))&0x1)<<ddx); bus_w(ADC_WRITE_REG,valw); usleep(0); //write data (i)
|
||||
#ifdef VERBOSE
|
||||
printf("LOW 0x%x \n",valw);
|
||||
#endif
|
||||
|
||||
valw=valw+(0x1<<cdx);bus_w(ADC_WRITE_REG,valw); usleep(0); //clkup
|
||||
#ifdef VERBOSE
|
||||
printf("up 0x%x \n",valw);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
valw=valw&(~(0x1<<cdx));usleep(0);
|
||||
valw=0xff; bus_w(ADC_WRITE_REG,(valw)); // stop point =start point */
|
||||
valw=0xff; bus_w(ADC_WRITE_REG,(valw)); // stop point =start point
|
||||
|
||||
return;
|
||||
|
||||
|
||||
usleep(5000);
|
||||
|
||||
codata=0;
|
||||
codata=(0x08<<8)+(0x3); //command and value;Power modes(global) reset
|
||||
valw=0xff; bus_w(ADC_WRITE_REG,(valw)); // start point
|
||||
valw=((0xffffffff&(~csmask)));bus_w(ADC_WRITE_REG,valw); //chip sel bar down
|
||||
for (i=0;i<24;i++) {
|
||||
valw=valw&(~(0x1<<cdx));bus_w(ADC_WRITE_REG,valw);usleep(0); //cldwn
|
||||
|
||||
valw=(valw&(~(0x1<<ddx)))+(((codata>>(23-i))&0x1)<<ddx); bus_w(ADC_WRITE_REG,valw); usleep(0); //write data (i)
|
||||
valw=valw+(0x1<<cdx);bus_w(ADC_WRITE_REG,valw); usleep(0); //clkup
|
||||
|
||||
}
|
||||
|
||||
valw=valw&(~(0x1<<cdx));usleep(0);
|
||||
valw=0xff; bus_w(ADC_WRITE_REG,(valw)); // stop point =start point
|
||||
|
||||
|
||||
|
||||
usleep(50000);
|
||||
codata=0;
|
||||
codata=(0x08<<8)+(0x0); //command and value;Power modes(global) reset
|
||||
valw=0xff; bus_w(ADC_WRITE_REG,(valw)); // start point
|
||||
valw=((0xffffffff&(~csmask)));bus_w(ADC_WRITE_REG,valw); //chip sel bar down
|
||||
for (i=0;i<24;i++) {
|
||||
valw=valw&(~(0x1<<cdx));bus_w(ADC_WRITE_REG,valw);usleep(0); //cldwn
|
||||
|
||||
valw=(valw&(~(0x1<<ddx)))+(((codata>>(23-i))&0x1)<<ddx); bus_w(ADC_WRITE_REG,valw); usleep(0); //write data (i)
|
||||
valw=valw+(0x1<<cdx);bus_w(ADC_WRITE_REG,valw); usleep(0); //clkup
|
||||
|
||||
}
|
||||
|
||||
valw=valw&(~(0x1<<cdx));usleep(0);
|
||||
valw=0xff; bus_w(ADC_WRITE_REG,(valw)); // stop point =start point
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
@ -153,28 +153,28 @@ int slsDetectorUsers::setBeamEnergy(int e_eV){
|
||||
}
|
||||
|
||||
double slsDetectorUsers::setExposureTime(double t, bool inseconds){
|
||||
int64_t tms = t * (1E+9);
|
||||
int64_t tms = (int64_t)(t * (1E+9));
|
||||
if (t < 0) tms = -1;
|
||||
if(!inseconds)
|
||||
return myDetector->setExposureTime(t);
|
||||
return myDetector->setExposureTime((int64_t)t);
|
||||
else
|
||||
return ((1E-9) * (double)myDetector->setExposureTime(tms));
|
||||
}
|
||||
|
||||
double slsDetectorUsers::setExposurePeriod(double t, bool inseconds){
|
||||
int64_t tms = t * (1E+9);
|
||||
int64_t tms = (int64_t)(t * (1E+9));
|
||||
if (t < 0) tms = -1;
|
||||
if(!inseconds)
|
||||
return myDetector->setExposurePeriod(t);
|
||||
return myDetector->setExposurePeriod((int64_t)t);
|
||||
else
|
||||
return ((1E-9) * (double)myDetector->setExposurePeriod(tms));
|
||||
}
|
||||
|
||||
double slsDetectorUsers::setDelayAfterTrigger(double t, bool inseconds){
|
||||
int64_t tms = t * (1E+9);
|
||||
int64_t tms = (int64_t)(t * (1E+9));
|
||||
if (t < 0) tms = -1;
|
||||
if(!inseconds)
|
||||
return myDetector->setDelayAfterTrigger(t);
|
||||
return myDetector->setDelayAfterTrigger((int64_t)t);
|
||||
else
|
||||
return ((1E-9) * (double)myDetector->setDelayAfterTrigger(tms));
|
||||
}
|
||||
|
@ -15,18 +15,24 @@
|
||||
|
||||
//all max frames defined in sls_detector_defs.h. 20000 gotthard, 100000 for short gotthard, 1000 for moench
|
||||
|
||||
|
||||
#define GOTTHARD_FIFO_SIZE 25000
|
||||
#define GOTTHARD_ALIGNED_FRAME_SIZE 4096
|
||||
#define GOTTHARD_PACKETS_PER_FRAME 2
|
||||
#define GOTTHARD_BUFFER_SIZE (1286*GOTTHARD_PACKETS_PER_FRAME)
|
||||
#define GOTTHARD_DATA_BYTES (1280*GOTTHARD_PACKETS_PER_FRAME)
|
||||
#define GOTTHARD_ONE_PACKET_SIZE 1286
|
||||
#define GOTTHARD_BUFFER_SIZE (GOTTHARD_ONE_PACKET_SIZE*GOTTHARD_PACKETS_PER_FRAME) //1286*2
|
||||
#define GOTTHARD_DATA_BYTES (1280*GOTTHARD_PACKETS_PER_FRAME) //1280*2
|
||||
|
||||
#define GOTTHARD_SHORT_PACKETS_PER_FRAME 1
|
||||
#define GOTTHARD_SHORT_BUFFER_SIZE 518
|
||||
#define GOTTHARD_SHORT_DATABYTES 512
|
||||
#define GOTTHARD_SHORT_FRAME_INDEX_MASK 0xFFFFFFFF
|
||||
#define GOTTHARD_SHORT_FRAME_INDEX_OFFSET 0
|
||||
#define GOTTHARD_SHORT_PACKET_INDEX_MASK 0
|
||||
|
||||
#define GOTTHARD_FRAME_INDEX_MASK 0xFFFFFFFF
|
||||
#define GOTTHARD_FRAME_INDEX_OFFSET 0
|
||||
#define GOTTHARD_FRAME_INDEX_MASK 0xFFFFFFFE
|
||||
#define GOTTHARD_FRAME_INDEX_OFFSET 1
|
||||
#define GOTTHARD_PACKET_INDEX_MASK 0x1
|
||||
|
||||
|
||||
|
||||
@ -34,8 +40,9 @@
|
||||
#define MOENCH_FIFO_SIZE 2500
|
||||
#define MOENCH_ALIGNED_FRAME_SIZE 65536
|
||||
#define MOENCH_PACKETS_PER_FRAME 40
|
||||
#define MOENCH_BUFFER_SIZE (1286*MOENCH_PACKETS_PER_FRAME)
|
||||
#define MOENCH_DATA_BYTES (1280*MOENCH_PACKETS_PER_FRAME)
|
||||
#define MOENCH_ONE_PACKET_SIZE 1286
|
||||
#define MOENCH_BUFFER_SIZE (MOENCH_ONE_PACKET_SIZE*MOENCH_PACKETS_PER_FRAME) //1286*40
|
||||
#define MOENCH_DATA_BYTES (1280*MOENCH_PACKETS_PER_FRAME) //1280*40
|
||||
|
||||
#define MOENCH_BYTES_PER_ADC (40*2)
|
||||
#define MOENCH_PIXELS_IN_ONE_ROW 160
|
||||
|
@ -23,7 +23,7 @@ using namespace std;
|
||||
FILE* slsReceiverFunctionList::sfilefd(NULL);
|
||||
int slsReceiverFunctionList::receiver_threads_running(0);
|
||||
|
||||
slsReceiverFunctionList::slsReceiverFunctionList(detectorType det,bool moenchwithGotthardTest):
|
||||
slsReceiverFunctionList::slsReceiverFunctionList(detectorType det):
|
||||
myDetectorType(det),
|
||||
maxFramesPerFile(MAX_FRAMES_PER_FILE),
|
||||
enableFileWrite(1),
|
||||
@ -37,7 +37,7 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det,bool moenchwit
|
||||
totalFramesCaught(0),
|
||||
startAcquisitionIndex(0),
|
||||
acquisitionIndex(0),
|
||||
framesInFile(0),
|
||||
packetsInFile(0),
|
||||
prevframenum(0),
|
||||
listening_thread_running(0),
|
||||
writing_thread_running(0),
|
||||
@ -56,15 +56,16 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det,bool moenchwit
|
||||
guiFileName(NULL),
|
||||
currframenum(0),
|
||||
nFrameToGui(0),
|
||||
frameIndexMask(GOTTHARD_FRAME_INDEX_MASK),
|
||||
frameIndexOffset(GOTTHARD_FRAME_INDEX_OFFSET),
|
||||
dataCompression(false),
|
||||
startAcquisitionCallBack(NULL),
|
||||
pStartAcquisition(NULL),
|
||||
acquisitionFinishedCallBack(NULL),
|
||||
pAcquisitionFinished(NULL),
|
||||
rawDataReadyCallBack(NULL),
|
||||
pRawDataReady(NULL),
|
||||
withGotthard(moenchwithGotthardTest),
|
||||
frameIndexMask(GOTTHARD_FRAME_INDEX_MASK),
|
||||
frameIndexOffset(GOTTHARD_FRAME_INDEX_OFFSET)
|
||||
pRawDataReady(NULL)
|
||||
|
||||
|
||||
|
||||
{
|
||||
@ -76,11 +77,8 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det,bool moenchwit
|
||||
maxFramesPerFile = MOENCH_MAX_FRAMES_PER_FILE;
|
||||
bufferSize = MOENCH_BUFFER_SIZE;
|
||||
packetsPerFrame = MOENCH_PACKETS_PER_FRAME;
|
||||
if(!withGotthard){
|
||||
frameIndexMask = MOENCH_FRAME_INDEX_MASK;
|
||||
frameIndexOffset = MOENCH_FRAME_INDEX_OFFSET;
|
||||
}
|
||||
}
|
||||
oneBufferSize = bufferSize/packetsPerFrame;
|
||||
|
||||
strcpy(savefilename,"");
|
||||
strcpy(filePath,"");
|
||||
@ -106,12 +104,105 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det,bool moenchwit
|
||||
buffer+=aligned_frame_size;
|
||||
}
|
||||
|
||||
if(withGotthard)
|
||||
cout << "Testing MOENCH Receiver with GOTTHARD Detector" << endl;
|
||||
|
||||
vector <vector<int16_t> > map;
|
||||
vector <vector<int16_t> > mask;
|
||||
int initial_offset = 4;
|
||||
int later_offset = 2;
|
||||
|
||||
int mask_y_offset = 120;
|
||||
int mask_adc = 0x7fff;
|
||||
int num_packets_in_col = 4;
|
||||
int num_packets_in_row = 10;
|
||||
int num_pixels_per_packet_in_row = 40;
|
||||
int num_pixels_per_packet_in_col = 16;
|
||||
int offset,ipacket;
|
||||
|
||||
|
||||
int x;
|
||||
int y;
|
||||
int i, j;
|
||||
|
||||
/** not for roi */
|
||||
//filter
|
||||
switch(myDetectorType){
|
||||
case MOENCH:
|
||||
x = MOENCH_PIXELS_IN_ONE_ROW;
|
||||
y = MOENCH_PIXELS_IN_ONE_ROW;
|
||||
mask.resize(x);
|
||||
for(i=0;i<x; i++)
|
||||
mask[i].resize(y);
|
||||
map.resize(x);
|
||||
for(i=0;i<x; i++)
|
||||
map[i].resize(y);
|
||||
|
||||
|
||||
//set up mask for moench
|
||||
|
||||
for(int i=0;i<x; i++)
|
||||
for(j=0;i<y; i++)
|
||||
if (j<mask_y_offset)
|
||||
mask[i][j] = mask_adc;
|
||||
else
|
||||
mask[i][j] = 0;
|
||||
|
||||
//set up mapping for moench
|
||||
for (int ipx = 0; ipx < num_packets_in_col; ipx++ )
|
||||
for (int ipy = 0; ipy < num_packets_in_row; ipy++ )
|
||||
for (int ix = 0; ix < num_pixels_per_packet_in_col; ix++ ){
|
||||
offset = initial_offset;
|
||||
for (int iy = 0; iy < num_pixels_per_packet_in_row; iy++ ){
|
||||
ipacket = (ipx + 1) + (ipy * num_packets_in_row);
|
||||
if (ipacket == MOENCH_PACKETS_PER_FRAME)
|
||||
ipacket = 0;
|
||||
map[ ipx * num_pixels_per_packet_in_col + ix][ ipy * num_pixels_per_packet_in_row + iy] =
|
||||
ipacket * MOENCH_ONE_PACKET_SIZE + offset;
|
||||
offset += later_offset;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
filter = new singlePhotonFilter(x,y, MOENCH_FRAME_INDEX_MASK, MOENCH_PACKET_INDEX_MASK, MOENCH_FRAME_INDEX_OFFSET, 0, MOENCH_PACKETS_PER_FRAME, 0,map, mask,MOENCH_BUFFER_SIZE);
|
||||
break;
|
||||
default:
|
||||
x = 1;
|
||||
y = (GOTTHARD_DATA_BYTES/GOTTHARD_PACKETS_PER_FRAME);
|
||||
offset = initial_offset;
|
||||
|
||||
mask.resize(x);
|
||||
for(int i=0;i<x; i++)
|
||||
mask[i].resize(y);
|
||||
map.resize(x);
|
||||
for(int i=0;i<x; i++)
|
||||
map[i].resize(y);
|
||||
|
||||
//set up mask for moench
|
||||
for (int i=0; i < x; i++)
|
||||
for (int j=0; j < y; j++){
|
||||
mask[i][j] = 0;
|
||||
}
|
||||
|
||||
//set up mapping for gotthard
|
||||
for (int i=0; i < x; i++)
|
||||
for (int j=0; j < y; j++){
|
||||
//since there are 2 packets
|
||||
if (y == y/2)
|
||||
offset += initial_offset;
|
||||
map[i][j] = offset;
|
||||
offset += 2;
|
||||
}
|
||||
|
||||
|
||||
filter = new singlePhotonFilter(x,y,GOTTHARD_FRAME_INDEX_MASK, GOTTHARD_PACKET_INDEX_MASK, GOTTHARD_FRAME_INDEX_OFFSET, 0, GOTTHARD_PACKETS_PER_FRAME, 1,map, mask,GOTTHARD_BUFFER_SIZE);
|
||||
break;
|
||||
}
|
||||
|
||||
pthread_mutex_init(&status_mutex,NULL);
|
||||
pthread_mutex_init(&dataReadyMutex,NULL);
|
||||
|
||||
|
||||
dataCompression = false;
|
||||
}
|
||||
|
||||
|
||||
@ -144,10 +235,8 @@ void slsReceiverFunctionList::setEthernetInterface(char* c){
|
||||
uint32_t slsReceiverFunctionList::getFrameIndex(){
|
||||
if(!framesCaught)
|
||||
frameIndex=0;
|
||||
else if(frameIndexOffset)
|
||||
frameIndex = currframenum - startFrameIndex; //moench
|
||||
else
|
||||
frameIndex = (currframenum - startFrameIndex)/packetsPerFrame;//moench with gotthard, gotthard
|
||||
frameIndex = currframenum - startFrameIndex;
|
||||
return frameIndex;
|
||||
}
|
||||
|
||||
@ -156,10 +245,8 @@ uint32_t slsReceiverFunctionList::getFrameIndex(){
|
||||
uint32_t slsReceiverFunctionList::getAcquisitionIndex(){
|
||||
if(!totalFramesCaught)
|
||||
acquisitionIndex=0;
|
||||
else if(frameIndexOffset)
|
||||
acquisitionIndex = currframenum - startAcquisitionIndex; //moench
|
||||
else
|
||||
acquisitionIndex = (currframenum - startAcquisitionIndex)/packetsPerFrame; //moench with gotthard, gotthard
|
||||
acquisitionIndex = currframenum - startAcquisitionIndex;
|
||||
return acquisitionIndex;
|
||||
}
|
||||
|
||||
@ -377,6 +464,13 @@ int slsReceiverFunctionList::startListening(){
|
||||
measurementStarted = false;
|
||||
startFrameIndex = 0;
|
||||
|
||||
int offset=0;
|
||||
int ret=1;
|
||||
int i=0;
|
||||
uint32_t *framenum;
|
||||
char *tempchar = new char[oneBufferSize];
|
||||
|
||||
|
||||
// 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
|
||||
// very end of the program.
|
||||
@ -405,10 +499,10 @@ int slsReceiverFunctionList::startListening(){
|
||||
delete udpSocket;
|
||||
udpSocket = NULL;
|
||||
}
|
||||
udpSocket = new genericSocket(server_port,genericSocket::UDP,bufferSize/packetsPerFrame,packetsPerFrame);
|
||||
udpSocket = new genericSocket(server_port,genericSocket::UDP,oneBufferSize,1);//packetsPerFrame);
|
||||
}else{
|
||||
cout<<"eth:"<<eth<<endl;
|
||||
udpSocket = new genericSocket(server_port,genericSocket::UDP,bufferSize/packetsPerFrame,packetsPerFrame,eth);
|
||||
udpSocket = new genericSocket(server_port,genericSocket::UDP,oneBufferSize,1,eth);//packetsPerFrame,eth);
|
||||
}
|
||||
if (udpSocket->getErrorStatus()){
|
||||
#ifdef VERBOSE
|
||||
@ -420,30 +514,43 @@ int slsReceiverFunctionList::startListening(){
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
filter->setupAcquisitionParameters();
|
||||
|
||||
while (receiver_threads_running) {
|
||||
if(!listening_thread_running){
|
||||
pthread_mutex_lock(&status_mutex);
|
||||
listening_thread_running = 1;
|
||||
pthread_mutex_unlock(&(status_mutex));
|
||||
}
|
||||
|
||||
if (!fifofree->isEmpty()) {
|
||||
if (ret!=0)
|
||||
fifofree->pop(buffer);
|
||||
|
||||
if(ret == -2){
|
||||
memcpy(buffer,tempchar,oneBufferSize);
|
||||
offset = oneBufferSize;
|
||||
}
|
||||
|
||||
//receiver 2 half frames / 1 short frame / 40 moench frames
|
||||
rc = udpSocket->ReceiveDataOnly(buffer,bufferSize);
|
||||
if( rc < 0)
|
||||
rc = udpSocket->ReceiveDataOnly(buffer+offset,oneBufferSize);
|
||||
if( rc <= 0){
|
||||
#ifdef VERYVERBOSE
|
||||
cerr << "recvfrom() failed" << endl;
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
if ((myDetectorType == GOTTHARD) && (shortFrame == -1))
|
||||
(*((uint32_t*)(buffer+offset)))++;
|
||||
|
||||
|
||||
ret = filter->verifyFrame(buffer+offset);
|
||||
|
||||
|
||||
//start for each scan
|
||||
if(!measurementStarted){
|
||||
if(!frameIndexOffset)
|
||||
startFrameIndex = ((uint32_t)(*((uint32_t*)buffer)));
|
||||
else
|
||||
startFrameIndex = ((((uint32_t)(*((uint32_t*)buffer))) & (frameIndexMask)) >> frameIndexOffset);
|
||||
|
||||
cout<<"startFrameIndex:"<<startFrameIndex<<endl;
|
||||
cout<<"startFrameIndex:"<<hex<<startFrameIndex<<endl;
|
||||
prevframenum=startFrameIndex;
|
||||
measurementStarted = true;
|
||||
}
|
||||
@ -453,24 +560,47 @@ int slsReceiverFunctionList::startListening(){
|
||||
startAcquisitionIndex=startFrameIndex;
|
||||
currframenum = startAcquisitionIndex;
|
||||
acqStarted = true;
|
||||
cout<<"startAcquisitionIndex:"<<startAcquisitionIndex<<endl;
|
||||
cout<<"startAcquisitionIndex:"<<hex<<startAcquisitionIndex<<endl;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
if(ret < 0){
|
||||
offset = 0;
|
||||
continue;
|
||||
}
|
||||
*/
|
||||
//last packet, but not the full frame, must push previous frame
|
||||
if(ret == -1){
|
||||
//set reminaing headers invalid
|
||||
for( i = offset+ oneBufferSize; i < bufferSize; i += oneBufferSize)
|
||||
(*((uint32_t*)(buffer+i))) = 0xFFFFFFFF;
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
//first packet of new frame, must push previous frame
|
||||
else if(ret == -2){
|
||||
//copy the new frame to a temp
|
||||
memcpy(tempchar, buffer+offset, oneBufferSize);
|
||||
//set all the new frame header and remaining headers invalid
|
||||
for(i = offset; i < bufferSize; i += oneBufferSize);
|
||||
(*((uint32_t*)(buffer+i))) = 0xFFFFFFFF;
|
||||
}
|
||||
//wait for new packets of same frame
|
||||
else if (ret == 0){
|
||||
offset += oneBufferSize;
|
||||
continue;
|
||||
}
|
||||
//wait for next frame
|
||||
else{
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
//so that it doesnt write the last frame twice
|
||||
if(receiver_threads_running){
|
||||
//s.assign(buffer);
|
||||
if(fifo->isFull())
|
||||
;//cout<<"**********************FIFO FULLLLLLLL************************"<<endl;
|
||||
else{
|
||||
//cout<<"read index:"<<dec<<(int)(*(int*)buffer)<<endl;& (frameIndexMask)) >> frameIndexOffset;
|
||||
if((receiver_threads_running) && (!fifo->isFull())){
|
||||
fifo->push(buffer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (receiver_threads_running);
|
||||
@ -482,6 +612,7 @@ int slsReceiverFunctionList::startListening(){
|
||||
|
||||
//Close down any open socket descriptors
|
||||
udpSocket->Disconnect();
|
||||
delete tempchar;
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "receiver_threads_running:" << receiver_threads_running << endl;
|
||||
@ -512,9 +643,10 @@ int slsReceiverFunctionList::startWriting(){
|
||||
char *wbuf;
|
||||
int sleepnumber=0;
|
||||
int frameFactor=0;
|
||||
int packetloss=0;
|
||||
int i;
|
||||
/*int i1,i2;*/
|
||||
|
||||
framesInFile=0;
|
||||
packetsInFile=0;
|
||||
framesCaught=0;
|
||||
frameIndex=0;
|
||||
if(sfilefd) sfilefd=NULL;
|
||||
@ -546,11 +678,16 @@ int slsReceiverFunctionList::startWriting(){
|
||||
|
||||
|
||||
cout << "Ready!" << endl;
|
||||
|
||||
|
||||
if (dataCompression)
|
||||
filter->enableFilter(true);
|
||||
|
||||
//will always run till acquisition over and then runs till fifo is empty
|
||||
while(receiver_threads_running || (!fifo->isEmpty())){
|
||||
|
||||
//start a new file
|
||||
if ((framesInFile == maxFramesPerFile) || (strlen(savefilename) == 0)){
|
||||
if (((int)(packetsInFile/packetsPerFrame) >= maxFramesPerFile) || (strlen(savefilename) == 0)){
|
||||
|
||||
//create file name
|
||||
if(frameIndexNeeded==-1) sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex);
|
||||
@ -558,6 +695,14 @@ int slsReceiverFunctionList::startWriting(){
|
||||
|
||||
if(enableFileWrite && cbAction > DO_NOTHING){
|
||||
|
||||
//create tree and file
|
||||
if(dataCompression){
|
||||
if(enableFileWrite){
|
||||
filter->writeToFile();
|
||||
filter->initTree(savefilename);
|
||||
}
|
||||
}
|
||||
/*else{*///the standard way
|
||||
if(sfilefd){
|
||||
fclose(sfilefd);
|
||||
sfilefd = NULL;
|
||||
@ -570,24 +715,22 @@ int slsReceiverFunctionList::startWriting(){
|
||||
pthread_mutex_unlock(&(status_mutex));
|
||||
break;
|
||||
}
|
||||
|
||||
//setting buffer
|
||||
setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE);
|
||||
/*}*/
|
||||
|
||||
//printing packet losses and file names
|
||||
//if(prevframenum != 0)
|
||||
if(!framesCaught)
|
||||
cout << savefilename << endl;
|
||||
else{
|
||||
if(!frameIndexOffset)
|
||||
packetloss = (int)(((currframenum-prevframenum-(packetsPerFrame*framesInFile))/(double)(packetsPerFrame*framesInFile))*100.000);
|
||||
else
|
||||
packetloss = (int)(((currframenum-prevframenum-(framesInFile))/(double)(framesInFile))*100.000);
|
||||
cout << savefilename
|
||||
<< "\tpacket loss " << setw(4)<<fixed << setprecision(4) << packetloss
|
||||
<< "\tpacket loss "
|
||||
<< setw(4)<<fixed << setprecision(4)<< dec <<
|
||||
(int)(((((currframenum-prevframenum)*packetsPerFrame)-(packetsInFile))/(double)((currframenum-prevframenum)*packetsPerFrame))*100.000)/*packetloss*/
|
||||
<< "%\tframenum "
|
||||
<< currframenum //<< "\t\t p " << prevframenum
|
||||
<< "\tindex " << getFrameIndex()
|
||||
<< dec << currframenum //<< "\t\t p " << prevframenum
|
||||
<< "\tindex " << dec << getFrameIndex()
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
@ -600,7 +743,7 @@ int slsReceiverFunctionList::startWriting(){
|
||||
//if(prevframenum != 0){
|
||||
if(framesCaught){
|
||||
prevframenum = currframenum;
|
||||
framesInFile = 0;
|
||||
packetsInFile=0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -609,36 +752,59 @@ int slsReceiverFunctionList::startWriting(){
|
||||
if(!fifo->isEmpty()){
|
||||
|
||||
if(fifo->pop(wbuf)){
|
||||
|
||||
currframenum = ((uint32_t)(*((uint32_t*)wbuf))& frameIndexMask) >>frameIndexOffset;
|
||||
//cout<<"currframenum: "<<hex<<currframenum<<endl;
|
||||
//cout<<"currframenum2:"<<hex<<((((uint32_t)(*((uint32_t*)((char*)(wbuf+oneBufferSize)))))& frameIndexMask) >> frameIndexOffset)<<endl;;
|
||||
|
||||
for(i=0; i < packetsPerFrame; i++){
|
||||
if(((uint32_t)(*((uint32_t*)((char*)(wbuf+oneBufferSize))))) == 0xFFFFFFFF){
|
||||
//cout<<"found one: currframenum:"<<currframenum<<" currframe2:"<<((((uint32_t)(*((uint32_t*)((char*)(wbuf+oneBufferSize)))))& frameIndexMask) >> frameIndexOffset)<<endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
packetsInFile += i;
|
||||
//count only if you get full frames
|
||||
if(i == packetsPerFrame){
|
||||
framesCaught++;
|
||||
totalFramesCaught++;
|
||||
if(!frameIndexOffset)
|
||||
currframenum = (uint32_t)(*((uint32_t*)wbuf));
|
||||
else
|
||||
currframenum = (((uint32_t)(*((uint32_t*)wbuf))) & (frameIndexMask)) >> frameIndexOffset;
|
||||
|
||||
//cout<<"currframenum:"<<currframenum<<endl;
|
||||
}
|
||||
|
||||
//write data call back
|
||||
if (cbAction < DO_EVERYTHING) {
|
||||
rawDataReadyCallBack(currframenum, wbuf, bufferSize, sfilefd, guiData,pRawDataReady);
|
||||
rawDataReadyCallBack(currframenum, wbuf, i*oneBufferSize, sfilefd, guiData,pRawDataReady);
|
||||
}
|
||||
//default writing to file
|
||||
else if(enableFileWrite){
|
||||
/*if(!dataCompression){*/
|
||||
if(sfilefd)
|
||||
fwrite(wbuf, 1, bufferSize, sfilefd);
|
||||
fwrite(wbuf, 1, i*oneBufferSize, sfilefd);
|
||||
else{
|
||||
cout << "You do not have permissions to overwrite: " << savefilename << endl;
|
||||
usleep(50000);
|
||||
}
|
||||
/*}*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//does not read every frame
|
||||
if(!nFrameToGui){
|
||||
if(guiData){
|
||||
if((guiData) && (i == packetsPerFrame)){
|
||||
pthread_mutex_lock(&dataReadyMutex);
|
||||
guiDataReady=0;
|
||||
pthread_mutex_unlock(&dataReadyMutex);
|
||||
memcpy(latestData,wbuf,bufferSize);
|
||||
strcpy(guiFileName,savefilename);
|
||||
pthread_mutex_lock(&dataReadyMutex);
|
||||
guiDataReady=1;
|
||||
/* i1 = ((((uint32_t)(*((uint32_t*)latestData))) & (frameIndexMask)) >> frameIndexOffset);
|
||||
i2 = ((((uint32_t)(*((uint32_t*)(latestData+oneBufferSize)))) & (frameIndexMask)) >> frameIndexOffset);
|
||||
if ( i1 == (i2+1))
|
||||
cout<<"222WEIRDDD:"<<i1<<":"<<i2<<endl;*/
|
||||
pthread_mutex_unlock(&dataReadyMutex);
|
||||
}else{
|
||||
pthread_mutex_lock(&dataReadyMutex);
|
||||
@ -648,13 +814,18 @@ int slsReceiverFunctionList::startWriting(){
|
||||
}
|
||||
//reads every nth frame
|
||||
else{
|
||||
if(frameFactor){
|
||||
if (i != packetsPerFrame)//so no 1 packet frame writing over previous 2 packet frame
|
||||
;
|
||||
else if(frameFactor){
|
||||
frameFactor--;
|
||||
}else{
|
||||
frameFactor = nFrameToGui-1;
|
||||
//block current process if the guireader hasnt read it yet
|
||||
sem_wait(&smp);
|
||||
//copy data and set guidataready
|
||||
pthread_mutex_lock(&dataReadyMutex);
|
||||
guiDataReady=0;
|
||||
pthread_mutex_unlock(&dataReadyMutex);
|
||||
memcpy(latestData,wbuf,bufferSize);
|
||||
strcpy(guiFileName,savefilename);
|
||||
pthread_mutex_lock(&dataReadyMutex);
|
||||
@ -663,7 +834,7 @@ int slsReceiverFunctionList::startWriting(){
|
||||
|
||||
}
|
||||
}
|
||||
framesInFile++;
|
||||
|
||||
fifofree->push(wbuf);
|
||||
}
|
||||
}
|
||||
@ -685,8 +856,8 @@ int slsReceiverFunctionList::startWriting(){
|
||||
receiver_threads_running=0;
|
||||
pthread_mutex_unlock(&status_mutex);
|
||||
|
||||
cout << "RealTime Frames Caught:" << framesCaught << endl;
|
||||
cout << "Total Frames Caught:"<< totalFramesCaught << endl;
|
||||
cout << "RealTime Frames Caught:" << dec <<framesCaught << endl;
|
||||
cout << "Total Frames Caught:"<< dec << totalFramesCaught << endl;
|
||||
|
||||
|
||||
if(sfilefd){
|
||||
@ -712,6 +883,7 @@ int slsReceiverFunctionList::startWriting(){
|
||||
|
||||
|
||||
void slsReceiverFunctionList::readFrame(char* c,char** raw){
|
||||
int i1,i2;
|
||||
//point to gui data
|
||||
if (guiData == NULL)
|
||||
guiData = latestData;
|
||||
@ -724,6 +896,10 @@ void slsReceiverFunctionList::readFrame(char* c,char** raw){
|
||||
//data ready, set guidata to receive new data
|
||||
else{
|
||||
*raw = guiData;
|
||||
i1 = ((((uint32_t)(*((uint32_t*)guiData))) & (frameIndexMask)) >> frameIndexOffset);
|
||||
i2 = ((((uint32_t)(*((uint32_t*)(guiData+oneBufferSize)))) & (frameIndexMask)) >> frameIndexOffset);
|
||||
if ( i1 == (i2+1))
|
||||
cout<<"WEIRDDD:"<<i1<<":"<<i2<<endl;
|
||||
guiData = NULL;
|
||||
pthread_mutex_lock(&dataReadyMutex);
|
||||
guiDataReady = 0;
|
||||
@ -745,13 +921,92 @@ int slsReceiverFunctionList::setShortFrame(int i){
|
||||
bufferSize = GOTTHARD_SHORT_BUFFER_SIZE;
|
||||
maxFramesPerFile = SHORT_MAX_FRAMES_PER_FILE;
|
||||
packetsPerFrame = GOTTHARD_SHORT_PACKETS_PER_FRAME;
|
||||
frameIndexMask = GOTTHARD_SHORT_FRAME_INDEX_MASK;
|
||||
frameIndexOffset = GOTTHARD_SHORT_FRAME_INDEX_OFFSET;
|
||||
|
||||
}else{
|
||||
bufferSize = GOTTHARD_BUFFER_SIZE;
|
||||
maxFramesPerFile = MAX_FRAMES_PER_FILE;
|
||||
packetsPerFrame = GOTTHARD_PACKETS_PER_FRAME;
|
||||
frameIndexMask = GOTTHARD_FRAME_INDEX_MASK;
|
||||
frameIndexOffset = GOTTHARD_FRAME_INDEX_OFFSET;
|
||||
}
|
||||
|
||||
oneBufferSize = bufferSize/packetsPerFrame;
|
||||
|
||||
//if the filter is inititalized with the wrong readout
|
||||
if(filter->getPacketsPerFrame() != packetsPerFrame){
|
||||
|
||||
vector <vector<int16_t> > map;
|
||||
vector <vector<int16_t> > mask;
|
||||
int initial_offset = 4;
|
||||
int later_offset = 2;
|
||||
int x,y,i,j,offset = 0;
|
||||
|
||||
switch(packetsPerFrame){
|
||||
case GOTTHARD_SHORT_PACKETS_PER_FRAME://roi readout for gotthard
|
||||
x = 1;
|
||||
y = (GOTTHARD_DATA_BYTES/GOTTHARD_PACKETS_PER_FRAME)/2;
|
||||
offset = initial_offset;
|
||||
|
||||
mask.resize(x);
|
||||
for(int i=0;i<x; i++)
|
||||
mask[i].resize(y);
|
||||
map.resize(x);
|
||||
for(int i=0;i<x; i++)
|
||||
map[i].resize(y);
|
||||
//set up mask for moench
|
||||
for (int i=0; i < x; i++)
|
||||
for (int j=0; j < y; j++){
|
||||
mask[i][j] = 0;
|
||||
}
|
||||
//set up mapping for gotthard
|
||||
for (int i=0; i < x; i++)
|
||||
for (int j=0; j < y; j++){
|
||||
map[i][j] = offset;
|
||||
offset += 2;
|
||||
}
|
||||
|
||||
delete filter;
|
||||
filter = new singlePhotonFilter(x,y,frameIndexMask, GOTTHARD_PACKET_INDEX_MASK, frameIndexOffset, 0, GOTTHARD_SHORT_PACKETS_PER_FRAME, 0,map, mask,GOTTHARD_SHORT_BUFFER_SIZE);
|
||||
break;
|
||||
|
||||
default: //normal readout for gotthard
|
||||
x = 1;
|
||||
y = (GOTTHARD_DATA_BYTES/GOTTHARD_PACKETS_PER_FRAME);
|
||||
offset = initial_offset;
|
||||
|
||||
mask.resize(x);
|
||||
for(int i=0;i<x; i++)
|
||||
mask[i].resize(y);
|
||||
map.resize(x);
|
||||
for(int i=0;i<x; i++)
|
||||
map[i].resize(y);
|
||||
|
||||
//set up mask for moench
|
||||
for (int i=0; i < x; i++)
|
||||
for (int j=0; j < y; j++){
|
||||
mask[i][j] = 0;
|
||||
}
|
||||
|
||||
//set up mapping for gotthard
|
||||
for (int i=0; i < x; i++)
|
||||
for (int j=0; j < y; j++){
|
||||
//since there are 2 packets
|
||||
if (y == y/2)
|
||||
offset += initial_offset;
|
||||
map[i][j] = offset;
|
||||
offset += 2;
|
||||
}
|
||||
|
||||
delete filter;
|
||||
filter = new singlePhotonFilter(x,y,frameIndexMask, GOTTHARD_PACKET_INDEX_MASK, frameIndexOffset, 0, GOTTHARD_PACKETS_PER_FRAME, 1,map, mask,GOTTHARD_BUFFER_SIZE);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
return shortFrame;
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "receiver_defs.h"
|
||||
#include "genericSocket.h"
|
||||
#include "circularFifo.h"
|
||||
#include "singlePhotonFilter.h"
|
||||
|
||||
|
||||
#include <string.h>
|
||||
@ -30,7 +31,7 @@ public:
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
slsReceiverFunctionList(detectorType det, bool moenchwithGotthardTest);
|
||||
slsReceiverFunctionList(detectorType det);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
@ -207,6 +208,12 @@ public:
|
||||
* when fifo is empty later, sets status to run_finished */
|
||||
void startReadout();
|
||||
|
||||
/** enabl data compression, by saving only hits */
|
||||
void enableDataCompression(bool enable){dataCompression = enable;};
|
||||
|
||||
/** get data compression, by saving only hits */
|
||||
bool getDataCompression(){ return dataCompression;};
|
||||
|
||||
private:
|
||||
|
||||
/** detector type */
|
||||
@ -257,8 +264,8 @@ private:
|
||||
/** Actual current frame index of an entire acquisition (including all scans) */
|
||||
uint32_t acquisitionIndex;
|
||||
|
||||
/** Frames currently in current file, starts new file when it reaches max */
|
||||
uint32_t framesInFile;
|
||||
/** Packets currently in current file, starts new file when it reaches max */
|
||||
uint32_t packetsInFile;
|
||||
|
||||
/** Previous Frame number from buffer */
|
||||
uint32_t prevframenum;
|
||||
@ -338,6 +345,26 @@ private:
|
||||
/** send every nth frame to gui or only upon gui request*/
|
||||
int nFrameToGui;
|
||||
|
||||
/** frame index mask */
|
||||
int frameIndexMask;
|
||||
|
||||
/** frame index offset */
|
||||
int frameIndexOffset;
|
||||
|
||||
/** datacompression - save only hits */
|
||||
bool dataCompression;
|
||||
|
||||
/** single photon filter */
|
||||
singlePhotonFilter *filter;
|
||||
|
||||
/** oen buffer size */
|
||||
int oneBufferSize;
|
||||
|
||||
/** semaphore to synchronize writer and guireader threads */
|
||||
sem_t smp;
|
||||
|
||||
/** guiDataReady mutex */
|
||||
pthread_mutex_t dataReadyMutex;
|
||||
|
||||
/**
|
||||
callback arguments are
|
||||
@ -381,21 +408,6 @@ private:
|
||||
* 2 we open, close, write file, callback does not do anything */
|
||||
int cbAction;
|
||||
|
||||
/**temporary variable to test moench with gotthard module*/
|
||||
bool withGotthard;
|
||||
|
||||
/** frame index mask */
|
||||
int frameIndexMask;
|
||||
|
||||
/** frame index offset */
|
||||
int frameIndexOffset;
|
||||
|
||||
/** semaphore to synchronize writer and guireader threads */
|
||||
sem_t smp;
|
||||
|
||||
/** guiDataReady mutex */
|
||||
pthread_mutex_t dataReadyMutex;
|
||||
|
||||
|
||||
public:
|
||||
/** File Descriptor */
|
||||
|
@ -34,7 +34,6 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
|
||||
lockStatus(0),
|
||||
shortFrame(-1),
|
||||
packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME),
|
||||
withGotthard(0),
|
||||
socket(NULL){
|
||||
|
||||
int port_no = DEFAULT_PORTNO+2;
|
||||
@ -147,20 +146,6 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
|
||||
}
|
||||
}
|
||||
}
|
||||
//test with gotthard module
|
||||
else if(!strcasecmp(argv[iarg],"-test")){
|
||||
if(iarg+1==argc){
|
||||
cout << "no test condition given after -test in command line. Exiting." << endl;
|
||||
success=FAIL;
|
||||
}else{
|
||||
if(!strcasecmp(argv[iarg+1],"with_gotthard"))
|
||||
withGotthard = 1;
|
||||
else{
|
||||
cout << "could not decode test condition in command line. \nOptions are:\nwith_gotthard.\n\nExiting." << endl;
|
||||
success=FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
//tcp port
|
||||
else if(!strcasecmp(argv[iarg],"-rx_tcpport")){
|
||||
if(iarg+1==argc){
|
||||
@ -184,17 +169,9 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
|
||||
//display detector message
|
||||
switch(myDetectorType){
|
||||
case GOTTHARD:
|
||||
if(withGotthard){
|
||||
cout << "Option -test with_gotthard exists only for MOENCH detectors. Exiting" << endl;
|
||||
exit(-1);
|
||||
}else
|
||||
cout << "This is a GOTTHARD Receiver" << endl;
|
||||
break;
|
||||
case MOENCH:
|
||||
if(withGotthard)
|
||||
cout << "This is a MOENCH Receiver using a GOTTHARD Detector."
|
||||
"\nNote:Packet numbers are not matched for its corresponding frames." << endl;
|
||||
else
|
||||
cout << "This is a MOENCH Receiver" << endl;
|
||||
break;
|
||||
default:
|
||||
@ -218,7 +195,7 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
|
||||
strcpy(mess,"dummy message");
|
||||
|
||||
function_table();
|
||||
slsReceiverList = new slsReceiverFunctionList(myDetectorType,withGotthard);
|
||||
slsReceiverList = new slsReceiverFunctionList(myDetectorType);
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "Function table assigned." << endl;
|
||||
@ -933,7 +910,7 @@ int slsReceiverFuncs::read_frame(){
|
||||
int slsReceiverFuncs::moench_read_frame(){
|
||||
ret=OK;
|
||||
char fName[MAX_STR_LENGTH]="";
|
||||
int arg = -1,i,j,x,y;
|
||||
int arg = -1,i;
|
||||
|
||||
|
||||
int bufferSize = MOENCH_BUFFER_SIZE;
|
||||
@ -948,7 +925,6 @@ int slsReceiverFuncs::moench_read_frame(){
|
||||
|
||||
uint32_t startIndex=0;
|
||||
int index = 0;
|
||||
int count=0;
|
||||
int offset=0;
|
||||
|
||||
|
||||
@ -982,41 +958,8 @@ int slsReceiverFuncs::moench_read_frame(){
|
||||
memcpy(origVal,raw,bufferSize);
|
||||
raw=NULL;
|
||||
|
||||
|
||||
//************** default order*****************************
|
||||
if(withGotthard){
|
||||
count = 0;
|
||||
offset = 4;
|
||||
j=0;
|
||||
for(x=0;x<(MOENCH_BYTES_IN_ONE_ROW/MOENCH_BYTES_PER_ADC);x++){
|
||||
for(y=0;y<MOENCH_PIXELS_IN_ONE_ROW;y++){
|
||||
|
||||
memcpy((((char*)retval) +
|
||||
y * MOENCH_BYTES_IN_ONE_ROW +
|
||||
x * MOENCH_BYTES_PER_ADC),
|
||||
(((char*) origVal) +
|
||||
offset +
|
||||
j * MOENCH_BYTES_PER_ADC) ,
|
||||
MOENCH_BYTES_PER_ADC);
|
||||
j++;
|
||||
count++;
|
||||
if(count==16){
|
||||
count=0;
|
||||
offset+=6;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
//********************************************************
|
||||
|
||||
|
||||
|
||||
//************** packet number order**********************
|
||||
else{
|
||||
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
|
||||
@ -1027,7 +970,7 @@ int slsReceiverFuncs::moench_read_frame(){
|
||||
int iPacket = 0;
|
||||
offset = 4;
|
||||
|
||||
while (iPacket < numPackets){
|
||||
while (iPacket < (int)numPackets){
|
||||
#ifdef VERBOSE
|
||||
printf("iPacket:%d\n",iPacket);cout << endl;
|
||||
#endif
|
||||
@ -1048,7 +991,7 @@ int slsReceiverFuncs::moench_read_frame(){
|
||||
cout<<"x:"<<x<<" y:"<<y<<endl;
|
||||
#endif
|
||||
//copy 16 times 80 bytes
|
||||
for (i = 0; i < partsPerFrame; i++) {
|
||||
for (i = 0; i < (int)partsPerFrame; i++) {
|
||||
memcpy((((char*)retval) +
|
||||
y * packetDatabytes_row +
|
||||
i * MOENCH_BYTES_IN_ONE_ROW +
|
||||
@ -1067,23 +1010,11 @@ int slsReceiverFuncs::moench_read_frame(){
|
||||
iPacket++;
|
||||
packetOffset = packetOffset + offset + onePacketSize;
|
||||
|
||||
// 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) != index){cout<<"did not match"<<endl;
|
||||
if(iPacket >= numPackets)
|
||||
break;
|
||||
//increment
|
||||
offset+=6;
|
||||
iPacket++;
|
||||
packetOffset = packetOffset + offset + onePacketSize;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
arg = index - startIndex;
|
||||
if(withGotthard)
|
||||
arg = arg/MOENCH_PACKETS_PER_FRAME;
|
||||
}
|
||||
//********************************************************
|
||||
|
||||
}
|
||||
|
||||
@ -1152,8 +1083,9 @@ int slsReceiverFuncs::gotthard_read_frame(){
|
||||
|
||||
|
||||
uint32_t index=0,index2=0;
|
||||
uint32_t pindex=0,pindex2=0;
|
||||
uint32_t bindex=0,bindex2=0;
|
||||
uint32_t startIndex=0;
|
||||
int count=0;
|
||||
|
||||
strcpy(mess,"Could not read frame\n");
|
||||
|
||||
@ -1179,40 +1111,63 @@ int slsReceiverFuncs::gotthard_read_frame(){
|
||||
cout<<"data not ready for gui yet"<<endl;
|
||||
#endif
|
||||
}else{
|
||||
index=(uint32_t)(*(uint32_t*)raw);
|
||||
if(shortFrame!=-1){
|
||||
bindex = (uint32_t)(*((uint32_t*)raw));
|
||||
pindex = (bindex & GOTTHARD_SHORT_PACKET_INDEX_MASK);
|
||||
index = ((bindex & GOTTHARD_SHORT_FRAME_INDEX_MASK) >> GOTTHARD_SHORT_FRAME_INDEX_OFFSET);
|
||||
#ifdef VERBOSE
|
||||
cout<<"index:"<<index<<endl;
|
||||
cout<<"index:"<<hex<<index<<endl;
|
||||
#endif
|
||||
if(shortFrame==-1)
|
||||
index2= (uint32_t)(*((uint32_t*)((char*)(raw+onebuffersize))));
|
||||
}else{
|
||||
bindex = (uint32_t)(*((uint32_t*)raw));
|
||||
pindex = (bindex & GOTTHARD_PACKET_INDEX_MASK);
|
||||
index = ((bindex & GOTTHARD_FRAME_INDEX_MASK) >> GOTTHARD_FRAME_INDEX_OFFSET);
|
||||
bindex2 = (uint32_t)(*((uint32_t*)((char*)(raw+onebuffersize))));
|
||||
pindex2 =(bindex2 & GOTTHARD_PACKET_INDEX_MASK);
|
||||
index2 =((bindex2 & GOTTHARD_FRAME_INDEX_MASK) >> GOTTHARD_FRAME_INDEX_OFFSET);
|
||||
#ifdef VERBOSE
|
||||
cout<<"index1:"<<hex<<index<<endl;
|
||||
cout<<"index2:"<<hex<<index<<endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
memcpy(origVal,raw,bufferSize);
|
||||
raw=NULL;
|
||||
|
||||
|
||||
//1 adc
|
||||
if(shortFrame!=-1){
|
||||
if(bindex != 0xFFFFFFFF)
|
||||
memcpy((((char*)retval)+(GOTTHARD_SHORT_DATABYTES*shortFrame)),((char*) origVal)+4, GOTTHARD_SHORT_DATABYTES);
|
||||
else
|
||||
index = startIndex - 1;
|
||||
}
|
||||
//all adc
|
||||
else{
|
||||
//1 odd, 1 even
|
||||
if((index%2)!=index2%2){
|
||||
//ignore if half frame is missing
|
||||
if ((bindex != 0xFFFFFFFF) && (bindex2 != 0xFFFFFFFF)){
|
||||
|
||||
//should be same frame
|
||||
if (index == index2){
|
||||
//ideal situation (should be odd, even(index+1))
|
||||
if(index%2){
|
||||
if(!pindex){
|
||||
memcpy(retval,((char*) origVal)+4, onedatasize);
|
||||
memcpy((((char*)retval)+onedatasize), ((char*) origVal)+10+onedatasize, onedatasize);
|
||||
}
|
||||
|
||||
//swap to even,odd
|
||||
if(index2%2){
|
||||
else{
|
||||
memcpy((((char*)retval)+onedatasize),((char*) origVal)+4, onedatasize);
|
||||
memcpy(retval, ((char*) origVal)+10+onedatasize, onedatasize);
|
||||
index=index2;
|
||||
}
|
||||
}else
|
||||
cout << "same type: index:" << index << "\tindex2:" << index2 << endl;
|
||||
cout << "different frames caught. frame1:"<< hex << index << ":"<<pindex<<" frame2:" << hex << index2 << ":"<<pindex2<<endl;
|
||||
}
|
||||
else
|
||||
index = startIndex - 1;
|
||||
}
|
||||
|
||||
arg = ((index - startIndex)/packetsPerFrame);
|
||||
arg = (index - startIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,9 +200,6 @@ public:
|
||||
/** Packets per frame */
|
||||
int packetsPerFrame;
|
||||
|
||||
/** temporary variable to debug moench receiver with gotthard module */
|
||||
int withGotthard;
|
||||
|
||||
static int file_des;
|
||||
static int socketDescriptor;
|
||||
|
||||
|
Reference in New Issue
Block a user