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:
@ -1813,35 +1813,114 @@ int allocateRAM() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
int prepareADC(){
|
int prepareADC(){
|
||||||
printf("Preparing ADC\n");
|
printf("Preparing ADC\n");
|
||||||
u_int32_t valw,codata,csmask;
|
u_int32_t valw,codata,csmask;
|
||||||
int i,cdx,ddx;
|
int i,j,cdx,ddx,value;
|
||||||
cdx=0; ddx=1;
|
cdx=0; ddx=1;
|
||||||
csmask=0x7c; // 1111100
|
csmask=0x7c; // 1111100
|
||||||
|
|
||||||
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);
|
for(j=0;j<3;j++){
|
||||||
valw=0xff; bus_w(ADC_WRITE_REG,(valw)); // stop point =start point */
|
//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
|
||||||
|
|
||||||
return;
|
|
||||||
|
// 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
|
||||||
|
|
||||||
|
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(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){
|
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 (t < 0) tms = -1;
|
||||||
if(!inseconds)
|
if(!inseconds)
|
||||||
return myDetector->setExposureTime(t);
|
return myDetector->setExposureTime((int64_t)t);
|
||||||
else
|
else
|
||||||
return ((1E-9) * (double)myDetector->setExposureTime(tms));
|
return ((1E-9) * (double)myDetector->setExposureTime(tms));
|
||||||
}
|
}
|
||||||
|
|
||||||
double slsDetectorUsers::setExposurePeriod(double t, bool inseconds){
|
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 (t < 0) tms = -1;
|
||||||
if(!inseconds)
|
if(!inseconds)
|
||||||
return myDetector->setExposurePeriod(t);
|
return myDetector->setExposurePeriod((int64_t)t);
|
||||||
else
|
else
|
||||||
return ((1E-9) * (double)myDetector->setExposurePeriod(tms));
|
return ((1E-9) * (double)myDetector->setExposurePeriod(tms));
|
||||||
}
|
}
|
||||||
|
|
||||||
double slsDetectorUsers::setDelayAfterTrigger(double t, bool inseconds){
|
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 (t < 0) tms = -1;
|
||||||
if(!inseconds)
|
if(!inseconds)
|
||||||
return myDetector->setDelayAfterTrigger(t);
|
return myDetector->setDelayAfterTrigger((int64_t)t);
|
||||||
else
|
else
|
||||||
return ((1E-9) * (double)myDetector->setDelayAfterTrigger(tms));
|
return ((1E-9) * (double)myDetector->setDelayAfterTrigger(tms));
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++
|
|||||||
LIBS?= -L$(LIBDIR) -lSlsDetector
|
LIBS?= -L$(LIBDIR) -lSlsDetector
|
||||||
|
|
||||||
INCLUDES ?= -I ../MySocketTCP -I ../commonFiles -I -I ../slsDetectorAnalysis -I .
|
INCLUDES ?= -I ../MySocketTCP -I ../commonFiles -I -I ../slsDetectorAnalysis -I .
|
||||||
SRC_CLNT = slsReceiver.cpp
|
SRC_CLNT = slsReceiver.cpp
|
||||||
#../MySocketTCP/MySocketTCP.cpp slsReceiver_funcs.cpp UHRIXCallback.cpp slsReceiverFunctionList.cpp slsReceiverUsers.cpp
|
#../MySocketTCP/MySocketTCP.cpp slsReceiver_funcs.cpp UHRIXCallback.cpp slsReceiverFunctionList.cpp slsReceiverUsers.cpp
|
||||||
|
|
||||||
DESTDIR ?= bin
|
DESTDIR ?= bin
|
||||||
|
@ -15,18 +15,24 @@
|
|||||||
|
|
||||||
//all max frames defined in sls_detector_defs.h. 20000 gotthard, 100000 for short gotthard, 1000 for moench
|
//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_FIFO_SIZE 25000
|
||||||
#define GOTTHARD_ALIGNED_FRAME_SIZE 4096
|
#define GOTTHARD_ALIGNED_FRAME_SIZE 4096
|
||||||
#define GOTTHARD_PACKETS_PER_FRAME 2
|
#define GOTTHARD_PACKETS_PER_FRAME 2
|
||||||
#define GOTTHARD_BUFFER_SIZE (1286*GOTTHARD_PACKETS_PER_FRAME)
|
#define GOTTHARD_ONE_PACKET_SIZE 1286
|
||||||
#define GOTTHARD_DATA_BYTES (1280*GOTTHARD_PACKETS_PER_FRAME)
|
#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_PACKETS_PER_FRAME 1
|
||||||
#define GOTTHARD_SHORT_BUFFER_SIZE 518
|
#define GOTTHARD_SHORT_BUFFER_SIZE 518
|
||||||
#define GOTTHARD_SHORT_DATABYTES 512
|
#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_MASK 0xFFFFFFFE
|
||||||
#define GOTTHARD_FRAME_INDEX_OFFSET 0
|
#define GOTTHARD_FRAME_INDEX_OFFSET 1
|
||||||
|
#define GOTTHARD_PACKET_INDEX_MASK 0x1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -34,8 +40,9 @@
|
|||||||
#define MOENCH_FIFO_SIZE 2500
|
#define MOENCH_FIFO_SIZE 2500
|
||||||
#define MOENCH_ALIGNED_FRAME_SIZE 65536
|
#define MOENCH_ALIGNED_FRAME_SIZE 65536
|
||||||
#define MOENCH_PACKETS_PER_FRAME 40
|
#define MOENCH_PACKETS_PER_FRAME 40
|
||||||
#define MOENCH_BUFFER_SIZE (1286*MOENCH_PACKETS_PER_FRAME)
|
#define MOENCH_ONE_PACKET_SIZE 1286
|
||||||
#define MOENCH_DATA_BYTES (1280*MOENCH_PACKETS_PER_FRAME)
|
#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_BYTES_PER_ADC (40*2)
|
||||||
#define MOENCH_PIXELS_IN_ONE_ROW 160
|
#define MOENCH_PIXELS_IN_ONE_ROW 160
|
||||||
|
@ -23,48 +23,49 @@ using namespace std;
|
|||||||
FILE* slsReceiverFunctionList::sfilefd(NULL);
|
FILE* slsReceiverFunctionList::sfilefd(NULL);
|
||||||
int slsReceiverFunctionList::receiver_threads_running(0);
|
int slsReceiverFunctionList::receiver_threads_running(0);
|
||||||
|
|
||||||
slsReceiverFunctionList::slsReceiverFunctionList(detectorType det,bool moenchwithGotthardTest):
|
slsReceiverFunctionList::slsReceiverFunctionList(detectorType det):
|
||||||
myDetectorType(det),
|
myDetectorType(det),
|
||||||
maxFramesPerFile(MAX_FRAMES_PER_FILE),
|
maxFramesPerFile(MAX_FRAMES_PER_FILE),
|
||||||
enableFileWrite(1),
|
enableFileWrite(1),
|
||||||
fileIndex(0),
|
fileIndex(0),
|
||||||
frameIndexNeeded(0),
|
frameIndexNeeded(0),
|
||||||
framesCaught(0),
|
framesCaught(0),
|
||||||
acqStarted(false),
|
acqStarted(false),
|
||||||
measurementStarted(false),
|
measurementStarted(false),
|
||||||
startFrameIndex(0),
|
startFrameIndex(0),
|
||||||
frameIndex(0),
|
frameIndex(0),
|
||||||
totalFramesCaught(0),
|
totalFramesCaught(0),
|
||||||
startAcquisitionIndex(0),
|
startAcquisitionIndex(0),
|
||||||
acquisitionIndex(0),
|
acquisitionIndex(0),
|
||||||
framesInFile(0),
|
packetsInFile(0),
|
||||||
prevframenum(0),
|
prevframenum(0),
|
||||||
listening_thread_running(0),
|
listening_thread_running(0),
|
||||||
writing_thread_running(0),
|
writing_thread_running(0),
|
||||||
status(IDLE),
|
status(IDLE),
|
||||||
latestData(NULL),
|
latestData(NULL),
|
||||||
udpSocket(NULL),
|
udpSocket(NULL),
|
||||||
server_port(DEFAULT_UDP_PORTNO),
|
server_port(DEFAULT_UDP_PORTNO),
|
||||||
fifo(NULL),
|
fifo(NULL),
|
||||||
fifofree(NULL),
|
fifofree(NULL),
|
||||||
fifosize(GOTTHARD_FIFO_SIZE),
|
fifosize(GOTTHARD_FIFO_SIZE),
|
||||||
shortFrame(-1),
|
shortFrame(-1),
|
||||||
bufferSize(GOTTHARD_BUFFER_SIZE),
|
bufferSize(GOTTHARD_BUFFER_SIZE),
|
||||||
packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME),
|
packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME),
|
||||||
guiDataReady(0),
|
guiDataReady(0),
|
||||||
guiData(NULL),
|
guiData(NULL),
|
||||||
guiFileName(NULL),
|
guiFileName(NULL),
|
||||||
currframenum(0),
|
currframenum(0),
|
||||||
nFrameToGui(0),
|
nFrameToGui(0),
|
||||||
startAcquisitionCallBack(NULL),
|
frameIndexMask(GOTTHARD_FRAME_INDEX_MASK),
|
||||||
pStartAcquisition(NULL),
|
frameIndexOffset(GOTTHARD_FRAME_INDEX_OFFSET),
|
||||||
acquisitionFinishedCallBack(NULL),
|
dataCompression(false),
|
||||||
pAcquisitionFinished(NULL),
|
startAcquisitionCallBack(NULL),
|
||||||
rawDataReadyCallBack(NULL),
|
pStartAcquisition(NULL),
|
||||||
pRawDataReady(NULL),
|
acquisitionFinishedCallBack(NULL),
|
||||||
withGotthard(moenchwithGotthardTest),
|
pAcquisitionFinished(NULL),
|
||||||
frameIndexMask(GOTTHARD_FRAME_INDEX_MASK),
|
rawDataReadyCallBack(NULL),
|
||||||
frameIndexOffset(GOTTHARD_FRAME_INDEX_OFFSET)
|
pRawDataReady(NULL)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -76,11 +77,8 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det,bool moenchwit
|
|||||||
maxFramesPerFile = MOENCH_MAX_FRAMES_PER_FILE;
|
maxFramesPerFile = MOENCH_MAX_FRAMES_PER_FILE;
|
||||||
bufferSize = MOENCH_BUFFER_SIZE;
|
bufferSize = MOENCH_BUFFER_SIZE;
|
||||||
packetsPerFrame = MOENCH_PACKETS_PER_FRAME;
|
packetsPerFrame = MOENCH_PACKETS_PER_FRAME;
|
||||||
if(!withGotthard){
|
|
||||||
frameIndexMask = MOENCH_FRAME_INDEX_MASK;
|
|
||||||
frameIndexOffset = MOENCH_FRAME_INDEX_OFFSET;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
oneBufferSize = bufferSize/packetsPerFrame;
|
||||||
|
|
||||||
strcpy(savefilename,"");
|
strcpy(savefilename,"");
|
||||||
strcpy(filePath,"");
|
strcpy(filePath,"");
|
||||||
@ -106,12 +104,105 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det,bool moenchwit
|
|||||||
buffer+=aligned_frame_size;
|
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(&status_mutex,NULL);
|
||||||
pthread_mutex_init(&dataReadyMutex,NULL);
|
pthread_mutex_init(&dataReadyMutex,NULL);
|
||||||
|
|
||||||
|
|
||||||
|
dataCompression = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -144,10 +235,8 @@ void slsReceiverFunctionList::setEthernetInterface(char* c){
|
|||||||
uint32_t slsReceiverFunctionList::getFrameIndex(){
|
uint32_t slsReceiverFunctionList::getFrameIndex(){
|
||||||
if(!framesCaught)
|
if(!framesCaught)
|
||||||
frameIndex=0;
|
frameIndex=0;
|
||||||
else if(frameIndexOffset)
|
|
||||||
frameIndex = currframenum - startFrameIndex; //moench
|
|
||||||
else
|
else
|
||||||
frameIndex = (currframenum - startFrameIndex)/packetsPerFrame;//moench with gotthard, gotthard
|
frameIndex = currframenum - startFrameIndex;
|
||||||
return frameIndex;
|
return frameIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,10 +245,8 @@ uint32_t slsReceiverFunctionList::getFrameIndex(){
|
|||||||
uint32_t slsReceiverFunctionList::getAcquisitionIndex(){
|
uint32_t slsReceiverFunctionList::getAcquisitionIndex(){
|
||||||
if(!totalFramesCaught)
|
if(!totalFramesCaught)
|
||||||
acquisitionIndex=0;
|
acquisitionIndex=0;
|
||||||
else if(frameIndexOffset)
|
|
||||||
acquisitionIndex = currframenum - startAcquisitionIndex; //moench
|
|
||||||
else
|
else
|
||||||
acquisitionIndex = (currframenum - startAcquisitionIndex)/packetsPerFrame; //moench with gotthard, gotthard
|
acquisitionIndex = currframenum - startAcquisitionIndex;
|
||||||
return acquisitionIndex;
|
return acquisitionIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,6 +464,13 @@ int slsReceiverFunctionList::startListening(){
|
|||||||
measurementStarted = false;
|
measurementStarted = false;
|
||||||
startFrameIndex = 0;
|
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
|
// 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.
|
||||||
@ -405,10 +499,10 @@ int slsReceiverFunctionList::startListening(){
|
|||||||
delete udpSocket;
|
delete udpSocket;
|
||||||
udpSocket = NULL;
|
udpSocket = NULL;
|
||||||
}
|
}
|
||||||
udpSocket = new genericSocket(server_port,genericSocket::UDP,bufferSize/packetsPerFrame,packetsPerFrame);
|
udpSocket = new genericSocket(server_port,genericSocket::UDP,oneBufferSize,1);//packetsPerFrame);
|
||||||
}else{
|
}else{
|
||||||
cout<<"eth:"<<eth<<endl;
|
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()){
|
if (udpSocket->getErrorStatus()){
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
@ -420,30 +514,43 @@ int slsReceiverFunctionList::startListening(){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filter->setupAcquisitionParameters();
|
||||||
|
|
||||||
while (receiver_threads_running) {
|
while (receiver_threads_running) {
|
||||||
pthread_mutex_lock(&status_mutex);
|
if(!listening_thread_running){
|
||||||
listening_thread_running = 1;
|
pthread_mutex_lock(&status_mutex);
|
||||||
pthread_mutex_unlock(&(status_mutex));
|
listening_thread_running = 1;
|
||||||
|
pthread_mutex_unlock(&(status_mutex));
|
||||||
|
}
|
||||||
|
|
||||||
if (!fifofree->isEmpty()) {
|
if (!fifofree->isEmpty()) {
|
||||||
fifofree->pop(buffer);
|
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
|
//receiver 2 half frames / 1 short frame / 40 moench frames
|
||||||
rc = udpSocket->ReceiveDataOnly(buffer,bufferSize);
|
rc = udpSocket->ReceiveDataOnly(buffer+offset,oneBufferSize);
|
||||||
if( rc < 0)
|
if( rc <= 0){
|
||||||
|
#ifdef VERYVERBOSE
|
||||||
cerr << "recvfrom() failed" << endl;
|
cerr << "recvfrom() failed" << endl;
|
||||||
|
#endif
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ((myDetectorType == GOTTHARD) && (shortFrame == -1))
|
||||||
|
(*((uint32_t*)(buffer+offset)))++;
|
||||||
|
|
||||||
|
|
||||||
|
ret = filter->verifyFrame(buffer+offset);
|
||||||
|
|
||||||
|
|
||||||
//start for each scan
|
//start for each scan
|
||||||
if(!measurementStarted){
|
if(!measurementStarted){
|
||||||
if(!frameIndexOffset)
|
startFrameIndex = ((((uint32_t)(*((uint32_t*)buffer))) & (frameIndexMask)) >> frameIndexOffset);
|
||||||
startFrameIndex = ((uint32_t)(*((uint32_t*)buffer)));
|
cout<<"startFrameIndex:"<<hex<<startFrameIndex<<endl;
|
||||||
else
|
|
||||||
startFrameIndex = ((((uint32_t)(*((uint32_t*)buffer))) & (frameIndexMask)) >> frameIndexOffset);
|
|
||||||
|
|
||||||
cout<<"startFrameIndex:"<<startFrameIndex<<endl;
|
|
||||||
prevframenum=startFrameIndex;
|
prevframenum=startFrameIndex;
|
||||||
measurementStarted = true;
|
measurementStarted = true;
|
||||||
}
|
}
|
||||||
@ -453,24 +560,47 @@ int slsReceiverFunctionList::startListening(){
|
|||||||
startAcquisitionIndex=startFrameIndex;
|
startAcquisitionIndex=startFrameIndex;
|
||||||
currframenum = startAcquisitionIndex;
|
currframenum = startAcquisitionIndex;
|
||||||
acqStarted = true;
|
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
|
//so that it doesnt write the last frame twice
|
||||||
if(receiver_threads_running){
|
if((receiver_threads_running) && (!fifo->isFull())){
|
||||||
//s.assign(buffer);
|
fifo->push(buffer);
|
||||||
if(fifo->isFull())
|
|
||||||
;//cout<<"**********************FIFO FULLLLLLLL************************"<<endl;
|
|
||||||
else{
|
|
||||||
//cout<<"read index:"<<dec<<(int)(*(int*)buffer)<<endl;& (frameIndexMask)) >> frameIndexOffset;
|
|
||||||
fifo->push(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (receiver_threads_running);
|
} while (receiver_threads_running);
|
||||||
@ -482,6 +612,7 @@ int slsReceiverFunctionList::startListening(){
|
|||||||
|
|
||||||
//Close down any open socket descriptors
|
//Close down any open socket descriptors
|
||||||
udpSocket->Disconnect();
|
udpSocket->Disconnect();
|
||||||
|
delete tempchar;
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "receiver_threads_running:" << receiver_threads_running << endl;
|
cout << "receiver_threads_running:" << receiver_threads_running << endl;
|
||||||
@ -512,9 +643,10 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
char *wbuf;
|
char *wbuf;
|
||||||
int sleepnumber=0;
|
int sleepnumber=0;
|
||||||
int frameFactor=0;
|
int frameFactor=0;
|
||||||
int packetloss=0;
|
int i;
|
||||||
|
/*int i1,i2;*/
|
||||||
|
|
||||||
framesInFile=0;
|
packetsInFile=0;
|
||||||
framesCaught=0;
|
framesCaught=0;
|
||||||
frameIndex=0;
|
frameIndex=0;
|
||||||
if(sfilefd) sfilefd=NULL;
|
if(sfilefd) sfilefd=NULL;
|
||||||
@ -546,11 +678,16 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
|
|
||||||
|
|
||||||
cout << "Ready!" << endl;
|
cout << "Ready!" << endl;
|
||||||
|
|
||||||
|
|
||||||
|
if (dataCompression)
|
||||||
|
filter->enableFilter(true);
|
||||||
|
|
||||||
//will always run till acquisition over and then runs till fifo is empty
|
//will always run till acquisition over and then runs till fifo is empty
|
||||||
while(receiver_threads_running || (!fifo->isEmpty())){
|
while(receiver_threads_running || (!fifo->isEmpty())){
|
||||||
|
|
||||||
//start a new file
|
//start a new file
|
||||||
if ((framesInFile == maxFramesPerFile) || (strlen(savefilename) == 0)){
|
if (((int)(packetsInFile/packetsPerFrame) >= maxFramesPerFile) || (strlen(savefilename) == 0)){
|
||||||
|
|
||||||
//create file name
|
//create file name
|
||||||
if(frameIndexNeeded==-1) sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex);
|
if(frameIndexNeeded==-1) sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex);
|
||||||
@ -558,6 +695,14 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
|
|
||||||
if(enableFileWrite && cbAction > DO_NOTHING){
|
if(enableFileWrite && cbAction > DO_NOTHING){
|
||||||
|
|
||||||
|
//create tree and file
|
||||||
|
if(dataCompression){
|
||||||
|
if(enableFileWrite){
|
||||||
|
filter->writeToFile();
|
||||||
|
filter->initTree(savefilename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*else{*///the standard way
|
||||||
if(sfilefd){
|
if(sfilefd){
|
||||||
fclose(sfilefd);
|
fclose(sfilefd);
|
||||||
sfilefd = NULL;
|
sfilefd = NULL;
|
||||||
@ -570,24 +715,22 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
pthread_mutex_unlock(&(status_mutex));
|
pthread_mutex_unlock(&(status_mutex));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//setting buffer
|
//setting buffer
|
||||||
setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE);
|
setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE);
|
||||||
|
/*}*/
|
||||||
|
|
||||||
//printing packet losses and file names
|
//printing packet losses and file names
|
||||||
//if(prevframenum != 0)
|
//if(prevframenum != 0)
|
||||||
if(!framesCaught)
|
if(!framesCaught)
|
||||||
cout << savefilename << endl;
|
cout << savefilename << endl;
|
||||||
else{
|
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
|
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 "
|
<< "%\tframenum "
|
||||||
<< currframenum //<< "\t\t p " << prevframenum
|
<< dec << currframenum //<< "\t\t p " << prevframenum
|
||||||
<< "\tindex " << getFrameIndex()
|
<< "\tindex " << dec << getFrameIndex()
|
||||||
<< endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -600,7 +743,7 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
//if(prevframenum != 0){
|
//if(prevframenum != 0){
|
||||||
if(framesCaught){
|
if(framesCaught){
|
||||||
prevframenum = currframenum;
|
prevframenum = currframenum;
|
||||||
framesInFile = 0;
|
packetsInFile=0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -609,62 +752,90 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
if(!fifo->isEmpty()){
|
if(!fifo->isEmpty()){
|
||||||
|
|
||||||
if(fifo->pop(wbuf)){
|
if(fifo->pop(wbuf)){
|
||||||
framesCaught++;
|
|
||||||
totalFramesCaught++;
|
|
||||||
if(!frameIndexOffset)
|
|
||||||
currframenum = (uint32_t)(*((uint32_t*)wbuf));
|
|
||||||
else
|
|
||||||
currframenum = (((uint32_t)(*((uint32_t*)wbuf))) & (frameIndexMask)) >> frameIndexOffset;
|
|
||||||
|
|
||||||
//cout<<"currframenum:"<<currframenum<<endl;
|
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;;
|
||||||
|
|
||||||
//write data call back
|
for(i=0; i < packetsPerFrame; i++){
|
||||||
if (cbAction < DO_EVERYTHING) {
|
if(((uint32_t)(*((uint32_t*)((char*)(wbuf+oneBufferSize))))) == 0xFFFFFFFF){
|
||||||
rawDataReadyCallBack(currframenum, wbuf, bufferSize, sfilefd, guiData,pRawDataReady);
|
//cout<<"found one: currframenum:"<<currframenum<<" currframe2:"<<((((uint32_t)(*((uint32_t*)((char*)(wbuf+oneBufferSize)))))& frameIndexMask) >> frameIndexOffset)<<endl;
|
||||||
}
|
break;
|
||||||
//default writing to file
|
}
|
||||||
else if(enableFileWrite){
|
}
|
||||||
if(sfilefd)
|
|
||||||
fwrite(wbuf, 1, bufferSize, sfilefd);
|
packetsInFile += i;
|
||||||
|
//count only if you get full frames
|
||||||
|
if(i == packetsPerFrame){
|
||||||
|
framesCaught++;
|
||||||
|
totalFramesCaught++;
|
||||||
|
}
|
||||||
|
|
||||||
|
//write data call back
|
||||||
|
if (cbAction < DO_EVERYTHING) {
|
||||||
|
rawDataReadyCallBack(currframenum, wbuf, i*oneBufferSize, sfilefd, guiData,pRawDataReady);
|
||||||
|
}
|
||||||
|
//default writing to file
|
||||||
|
else if(enableFileWrite){
|
||||||
|
/*if(!dataCompression){*/
|
||||||
|
if(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) && (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);
|
||||||
|
guiDataReady=0;
|
||||||
|
pthread_mutex_unlock(&dataReadyMutex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//reads every nth frame
|
||||||
else{
|
else{
|
||||||
cout << "You do not have permissions to overwrite: " << savefilename << endl;
|
if (i != packetsPerFrame)//so no 1 packet frame writing over previous 2 packet frame
|
||||||
usleep(50000);
|
;
|
||||||
}
|
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);
|
||||||
|
guiDataReady = 1;
|
||||||
|
pthread_mutex_unlock(&dataReadyMutex);
|
||||||
|
|
||||||
//does not read every frame
|
}
|
||||||
if(!nFrameToGui){
|
|
||||||
if(guiData){
|
|
||||||
memcpy(latestData,wbuf,bufferSize);
|
|
||||||
strcpy(guiFileName,savefilename);
|
|
||||||
pthread_mutex_lock(&dataReadyMutex);
|
|
||||||
guiDataReady=1;
|
|
||||||
pthread_mutex_unlock(&dataReadyMutex);
|
|
||||||
}else{
|
|
||||||
pthread_mutex_lock(&dataReadyMutex);
|
|
||||||
guiDataReady=0;
|
|
||||||
pthread_mutex_unlock(&dataReadyMutex);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//reads every nth 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
|
|
||||||
memcpy(latestData,wbuf,bufferSize);
|
|
||||||
strcpy(guiFileName,savefilename);
|
|
||||||
pthread_mutex_lock(&dataReadyMutex);
|
|
||||||
guiDataReady = 1;
|
|
||||||
pthread_mutex_unlock(&dataReadyMutex);
|
|
||||||
|
|
||||||
}
|
fifofree->push(wbuf);
|
||||||
}
|
|
||||||
framesInFile++;
|
|
||||||
fifofree->push(wbuf);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{//cout<<"************************fifo empty**********************************"<<endl;
|
else{//cout<<"************************fifo empty**********************************"<<endl;
|
||||||
@ -685,8 +856,8 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
receiver_threads_running=0;
|
receiver_threads_running=0;
|
||||||
pthread_mutex_unlock(&status_mutex);
|
pthread_mutex_unlock(&status_mutex);
|
||||||
|
|
||||||
cout << "RealTime Frames Caught:" << framesCaught << endl;
|
cout << "RealTime Frames Caught:" << dec <<framesCaught << endl;
|
||||||
cout << "Total Frames Caught:"<< totalFramesCaught << endl;
|
cout << "Total Frames Caught:"<< dec << totalFramesCaught << endl;
|
||||||
|
|
||||||
|
|
||||||
if(sfilefd){
|
if(sfilefd){
|
||||||
@ -712,6 +883,7 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
|
|
||||||
|
|
||||||
void slsReceiverFunctionList::readFrame(char* c,char** raw){
|
void slsReceiverFunctionList::readFrame(char* c,char** raw){
|
||||||
|
int i1,i2;
|
||||||
//point to gui data
|
//point to gui data
|
||||||
if (guiData == NULL)
|
if (guiData == NULL)
|
||||||
guiData = latestData;
|
guiData = latestData;
|
||||||
@ -724,13 +896,17 @@ void slsReceiverFunctionList::readFrame(char* c,char** raw){
|
|||||||
//data ready, set guidata to receive new data
|
//data ready, set guidata to receive new data
|
||||||
else{
|
else{
|
||||||
*raw = guiData;
|
*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;
|
guiData = NULL;
|
||||||
pthread_mutex_lock(&dataReadyMutex);
|
pthread_mutex_lock(&dataReadyMutex);
|
||||||
guiDataReady = 0;
|
guiDataReady = 0;
|
||||||
pthread_mutex_unlock(&dataReadyMutex);
|
pthread_mutex_unlock(&dataReadyMutex);
|
||||||
if((nFrameToGui) && (receiver_threads_running)){
|
if((nFrameToGui) && (receiver_threads_running)){
|
||||||
//release after getting data
|
//release after getting data
|
||||||
sem_post(&smp);
|
sem_post(&smp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -745,13 +921,92 @@ int slsReceiverFunctionList::setShortFrame(int i){
|
|||||||
bufferSize = GOTTHARD_SHORT_BUFFER_SIZE;
|
bufferSize = GOTTHARD_SHORT_BUFFER_SIZE;
|
||||||
maxFramesPerFile = SHORT_MAX_FRAMES_PER_FILE;
|
maxFramesPerFile = SHORT_MAX_FRAMES_PER_FILE;
|
||||||
packetsPerFrame = GOTTHARD_SHORT_PACKETS_PER_FRAME;
|
packetsPerFrame = GOTTHARD_SHORT_PACKETS_PER_FRAME;
|
||||||
|
frameIndexMask = GOTTHARD_SHORT_FRAME_INDEX_MASK;
|
||||||
|
frameIndexOffset = GOTTHARD_SHORT_FRAME_INDEX_OFFSET;
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
bufferSize = GOTTHARD_BUFFER_SIZE;
|
bufferSize = GOTTHARD_BUFFER_SIZE;
|
||||||
maxFramesPerFile = MAX_FRAMES_PER_FILE;
|
maxFramesPerFile = MAX_FRAMES_PER_FILE;
|
||||||
packetsPerFrame = GOTTHARD_PACKETS_PER_FRAME;
|
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;
|
return shortFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "receiver_defs.h"
|
#include "receiver_defs.h"
|
||||||
#include "genericSocket.h"
|
#include "genericSocket.h"
|
||||||
#include "circularFifo.h"
|
#include "circularFifo.h"
|
||||||
|
#include "singlePhotonFilter.h"
|
||||||
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -30,7 +31,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
slsReceiverFunctionList(detectorType det, bool moenchwithGotthardTest);
|
slsReceiverFunctionList(detectorType det);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor
|
* Destructor
|
||||||
@ -207,6 +208,12 @@ public:
|
|||||||
* when fifo is empty later, sets status to run_finished */
|
* when fifo is empty later, sets status to run_finished */
|
||||||
void startReadout();
|
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:
|
private:
|
||||||
|
|
||||||
/** detector type */
|
/** detector type */
|
||||||
@ -257,8 +264,8 @@ private:
|
|||||||
/** Actual current frame index of an entire acquisition (including all scans) */
|
/** Actual current frame index of an entire acquisition (including all scans) */
|
||||||
uint32_t acquisitionIndex;
|
uint32_t acquisitionIndex;
|
||||||
|
|
||||||
/** Frames currently in current file, starts new file when it reaches max */
|
/** Packets currently in current file, starts new file when it reaches max */
|
||||||
uint32_t framesInFile;
|
uint32_t packetsInFile;
|
||||||
|
|
||||||
/** Previous Frame number from buffer */
|
/** Previous Frame number from buffer */
|
||||||
uint32_t prevframenum;
|
uint32_t prevframenum;
|
||||||
@ -338,6 +345,26 @@ private:
|
|||||||
/** 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;
|
||||||
|
|
||||||
|
/** 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
|
callback arguments are
|
||||||
@ -381,21 +408,6 @@ private:
|
|||||||
* 2 we open, close, write file, callback does not do anything */
|
* 2 we open, close, write file, callback does not do anything */
|
||||||
int cbAction;
|
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:
|
public:
|
||||||
/** File Descriptor */
|
/** File Descriptor */
|
||||||
|
@ -34,7 +34,6 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
|
|||||||
lockStatus(0),
|
lockStatus(0),
|
||||||
shortFrame(-1),
|
shortFrame(-1),
|
||||||
packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME),
|
packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME),
|
||||||
withGotthard(0),
|
|
||||||
socket(NULL){
|
socket(NULL){
|
||||||
|
|
||||||
int port_no = DEFAULT_PORTNO+2;
|
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
|
//tcp port
|
||||||
else if(!strcasecmp(argv[iarg],"-rx_tcpport")){
|
else if(!strcasecmp(argv[iarg],"-rx_tcpport")){
|
||||||
if(iarg+1==argc){
|
if(iarg+1==argc){
|
||||||
@ -184,18 +169,10 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
|
|||||||
//display detector message
|
//display detector message
|
||||||
switch(myDetectorType){
|
switch(myDetectorType){
|
||||||
case GOTTHARD:
|
case GOTTHARD:
|
||||||
if(withGotthard){
|
cout << "This is a GOTTHARD Receiver" << endl;
|
||||||
cout << "Option -test with_gotthard exists only for MOENCH detectors. Exiting" << endl;
|
|
||||||
exit(-1);
|
|
||||||
}else
|
|
||||||
cout << "This is a GOTTHARD Receiver" << endl;
|
|
||||||
break;
|
break;
|
||||||
case MOENCH:
|
case MOENCH:
|
||||||
if(withGotthard)
|
cout << "This is a MOENCH Receiver" << endl;
|
||||||
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;
|
break;
|
||||||
default:
|
default:
|
||||||
cout << "Unknown Receiver" << endl;
|
cout << "Unknown Receiver" << endl;
|
||||||
@ -218,7 +195,7 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
|
|||||||
strcpy(mess,"dummy message");
|
strcpy(mess,"dummy message");
|
||||||
|
|
||||||
function_table();
|
function_table();
|
||||||
slsReceiverList = new slsReceiverFunctionList(myDetectorType,withGotthard);
|
slsReceiverList = new slsReceiverFunctionList(myDetectorType);
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "Function table assigned." << endl;
|
cout << "Function table assigned." << endl;
|
||||||
@ -933,7 +910,7 @@ int slsReceiverFuncs::read_frame(){
|
|||||||
int slsReceiverFuncs::moench_read_frame(){
|
int slsReceiverFuncs::moench_read_frame(){
|
||||||
ret=OK;
|
ret=OK;
|
||||||
char fName[MAX_STR_LENGTH]="";
|
char fName[MAX_STR_LENGTH]="";
|
||||||
int arg = -1,i,j,x,y;
|
int arg = -1,i;
|
||||||
|
|
||||||
|
|
||||||
int bufferSize = MOENCH_BUFFER_SIZE;
|
int bufferSize = MOENCH_BUFFER_SIZE;
|
||||||
@ -948,7 +925,6 @@ int slsReceiverFuncs::moench_read_frame(){
|
|||||||
|
|
||||||
uint32_t startIndex=0;
|
uint32_t startIndex=0;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
int count=0;
|
|
||||||
int offset=0;
|
int offset=0;
|
||||||
|
|
||||||
|
|
||||||
@ -982,108 +958,63 @@ int slsReceiverFuncs::moench_read_frame(){
|
|||||||
memcpy(origVal,raw,bufferSize);
|
memcpy(origVal,raw,bufferSize);
|
||||||
raw=NULL;
|
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**********************
|
//************** packet number order**********************
|
||||||
else{
|
index = ((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 numPackets = MOENCH_PACKETS_PER_FRAME; //40
|
||||||
uint32_t onePacketSize = MOENCH_DATA_BYTES / MOENCH_PACKETS_PER_FRAME; //1280*40 / 40 = 1280
|
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 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 partsPerFrame = onePacketSize / MOENCH_BYTES_PER_ADC; // 1280 / 80 = 16
|
||||||
uint32_t packetOffset = 0;
|
uint32_t packetOffset = 0;
|
||||||
int packetIndex,x,y;
|
int packetIndex,x,y;
|
||||||
int iPacket = 0;
|
int iPacket = 0;
|
||||||
offset = 4;
|
offset = 4;
|
||||||
|
|
||||||
while (iPacket < numPackets){
|
while (iPacket < (int)numPackets){
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("iPacket:%d\n",iPacket);cout << endl;
|
printf("iPacket:%d\n",iPacket);cout << endl;
|
||||||
#endif
|
#endif
|
||||||
packetIndex = (*((uint32_t*)(((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)
|
||||||
packetIndex = 39;
|
packetIndex = 39;
|
||||||
|
|
||||||
//check validity
|
//check validity
|
||||||
if ((packetIndex >= 40) && (packetIndex < 0))
|
if ((packetIndex >= 40) && (packetIndex < 0))
|
||||||
cout << "cannot decode packet index:" << packetIndex << endl;
|
cout << "cannot decode packet index:" << packetIndex << endl;
|
||||||
else{
|
else{
|
||||||
|
|
||||||
x = packetIndex / 10;
|
x = packetIndex / 10;
|
||||||
y = packetIndex % 10;
|
y = packetIndex % 10;
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout<<"x:"<<x<<" y:"<<y<<endl;
|
cout<<"x:"<<x<<" y:"<<y<<endl;
|
||||||
#endif
|
#endif
|
||||||
//copy 16 times 80 bytes
|
//copy 16 times 80 bytes
|
||||||
for (i = 0; i < partsPerFrame; i++) {
|
for (i = 0; i < (int)partsPerFrame; i++) {
|
||||||
memcpy((((char*)retval) +
|
memcpy((((char*)retval) +
|
||||||
y * packetDatabytes_row +
|
y * packetDatabytes_row +
|
||||||
i * MOENCH_BYTES_IN_ONE_ROW +
|
i * MOENCH_BYTES_IN_ONE_ROW +
|
||||||
x * MOENCH_BYTES_PER_ADC),
|
x * MOENCH_BYTES_PER_ADC),
|
||||||
|
|
||||||
(((char*) origVal) +
|
(((char*) origVal) +
|
||||||
iPacket * offset +
|
iPacket * offset +
|
||||||
iPacket * onePacketSize +
|
iPacket * onePacketSize +
|
||||||
i * MOENCH_BYTES_PER_ADC + 4) ,
|
i * MOENCH_BYTES_PER_ADC + 4) ,
|
||||||
MOENCH_BYTES_PER_ADC);
|
MOENCH_BYTES_PER_ADC);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//increment
|
|
||||||
offset=6;
|
|
||||||
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;
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//increment
|
||||||
|
offset=6;
|
||||||
|
iPacket++;
|
||||||
|
packetOffset = packetOffset + offset + onePacketSize;
|
||||||
|
|
||||||
|
//check if same frame number
|
||||||
}
|
}
|
||||||
|
|
||||||
arg = index - startIndex;
|
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 index=0,index2=0;
|
||||||
|
uint32_t pindex=0,pindex2=0;
|
||||||
|
uint32_t bindex=0,bindex2=0;
|
||||||
uint32_t startIndex=0;
|
uint32_t startIndex=0;
|
||||||
int count=0;
|
|
||||||
|
|
||||||
strcpy(mess,"Could not read frame\n");
|
strcpy(mess,"Could not read frame\n");
|
||||||
|
|
||||||
@ -1179,40 +1111,63 @@ int slsReceiverFuncs::gotthard_read_frame(){
|
|||||||
cout<<"data not ready for gui yet"<<endl;
|
cout<<"data not ready for gui yet"<<endl;
|
||||||
#endif
|
#endif
|
||||||
}else{
|
}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
|
#ifdef VERBOSE
|
||||||
cout<<"index:"<<index<<endl;
|
cout<<"index:"<<hex<<index<<endl;
|
||||||
#endif
|
#endif
|
||||||
if(shortFrame==-1)
|
}else{
|
||||||
index2= (uint32_t)(*((uint32_t*)((char*)(raw+onebuffersize))));
|
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);
|
memcpy(origVal,raw,bufferSize);
|
||||||
raw=NULL;
|
raw=NULL;
|
||||||
|
|
||||||
|
|
||||||
//1 adc
|
//1 adc
|
||||||
if(shortFrame!=-1){
|
if(shortFrame!=-1){
|
||||||
memcpy((((char*)retval)+(GOTTHARD_SHORT_DATABYTES*shortFrame)),((char*) origVal)+4, GOTTHARD_SHORT_DATABYTES);
|
if(bindex != 0xFFFFFFFF)
|
||||||
|
memcpy((((char*)retval)+(GOTTHARD_SHORT_DATABYTES*shortFrame)),((char*) origVal)+4, GOTTHARD_SHORT_DATABYTES);
|
||||||
|
else
|
||||||
|
index = startIndex - 1;
|
||||||
}
|
}
|
||||||
//all adc
|
//all adc
|
||||||
else{
|
else{
|
||||||
//1 odd, 1 even
|
//ignore if half frame is missing
|
||||||
if((index%2)!=index2%2){
|
if ((bindex != 0xFFFFFFFF) && (bindex2 != 0xFFFFFFFF)){
|
||||||
//ideal situation (should be odd, even(index+1))
|
|
||||||
if(index%2){
|
|
||||||
memcpy(retval,((char*) origVal)+4, onedatasize);
|
|
||||||
memcpy((((char*)retval)+onedatasize), ((char*) origVal)+10+onedatasize, onedatasize);
|
|
||||||
}
|
|
||||||
|
|
||||||
//swap to even,odd
|
//should be same frame
|
||||||
if(index2%2){
|
if (index == index2){
|
||||||
memcpy((((char*)retval)+onedatasize),((char*) origVal)+4, onedatasize);
|
//ideal situation (should be odd, even(index+1))
|
||||||
memcpy(retval, ((char*) origVal)+10+onedatasize, onedatasize);
|
if(!pindex){
|
||||||
index=index2;
|
memcpy(retval,((char*) origVal)+4, onedatasize);
|
||||||
}
|
memcpy((((char*)retval)+onedatasize), ((char*) origVal)+10+onedatasize, onedatasize);
|
||||||
}else
|
}
|
||||||
cout << "same type: index:" << index << "\tindex2:" << index2 << endl;
|
//swap to even,odd
|
||||||
|
else{
|
||||||
|
memcpy((((char*)retval)+onedatasize),((char*) origVal)+4, onedatasize);
|
||||||
|
memcpy(retval, ((char*) origVal)+10+onedatasize, onedatasize);
|
||||||
|
index=index2;
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
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 */
|
/** Packets per frame */
|
||||||
int packetsPerFrame;
|
int packetsPerFrame;
|
||||||
|
|
||||||
/** temporary variable to debug moench receiver with gotthard module */
|
|
||||||
int withGotthard;
|
|
||||||
|
|
||||||
static int file_des;
|
static int file_des;
|
||||||
static int socketDescriptor;
|
static int socketDescriptor;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user