moench client and receiver works with gotthard module, without gui

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@511 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
l_maliakal_d 2013-04-12 12:54:36 +00:00
parent cb9de5973f
commit 27c91c36ff
18 changed files with 420 additions and 172 deletions

View File

@ -41,6 +41,8 @@ typedef float dacs_t;
#define MAX_FRAMES_PER_FILE 20000 #define MAX_FRAMES_PER_FILE 20000
#define SHORT_MAX_FRAMES_PER_FILE 100000 #define SHORT_MAX_FRAMES_PER_FILE 100000
#define MOENCH_MAX_FRAMES_PER_FILE 1000
/** /**
\file sls_detector_defs.h \file sls_detector_defs.h

View File

@ -1206,7 +1206,7 @@ int setADC(int adc){
ipPacketSize= DEFAULT_IP_PACKETSIZE; ipPacketSize= DEFAULT_IP_PACKETSIZE;
udpPacketSize=DEFAULT_UDP_PACKETSIZE; udpPacketSize=DEFAULT_UDP_PACKETSIZE;
//set channel mask //set channel mask
nchips = NCHIP; nchips = GOTTHARDNCHIP;
mask = ACTIVE_ADC_MASK; mask = ACTIVE_ADC_MASK;
} }
//1 adc //1 adc
@ -1219,7 +1219,7 @@ int setADC(int adc){
} }
//set channel mask //set channel mask
reg = (NCHAN*nchips)<<CHANNEL_OFFSET; reg = (GOTTHARDNCHAN*nchips)<<CHANNEL_OFFSET;
reg&=CHANNEL_MASK; reg&=CHANNEL_MASK;
reg|=(ACTIVE_ADC_MASK & mask); reg|=(ACTIVE_ADC_MASK & mask);
bus_w(CHIP_OF_INTRST_REG,reg); bus_w(CHIP_OF_INTRST_REG,reg);

View File

@ -2601,11 +2601,11 @@ ROI* setROI(int n, ROI arg[], int *retvalsize, int *ret){
adc=-1; adc=-1;
else{ else{
//if its for 1 adc or general //if its for 1 adc or general
if ((arg[0].xmin==0) && (arg[0].xmax==NCHIP*NCHAN)) if ((arg[0].xmin==0) && (arg[0].xmax==GOTTHARDNCHIP*GOTTHARDNCHAN))
adc=-1; adc=-1;
else{ else{
//adc = mid value/numchans also for only 1 roi //adc = mid value/numchans also for only 1 roi
adc = ((((arg[0].xmax)+(arg[0].xmin))/2)/(NCHAN*NCHIPS_PER_ADC)); adc = ((((arg[0].xmax)+(arg[0].xmin))/2)/(GOTTHARDNCHAN*NCHIPS_PER_ADC));
if((adc>=0) && (adc<=4)); if((adc>=0) && (adc<=4));
else { else {
printf("warning:adc value greater than 5. deleting roi\n"); printf("warning:adc value greater than 5. deleting roi\n");
@ -2617,8 +2617,8 @@ ROI* setROI(int n, ROI arg[], int *retvalsize, int *ret){
//set rois for just 1 adc - take only 1st roi //set rois for just 1 adc - take only 1st roi
if(adc!=-1){ if(adc!=-1){
rois[0].xmin=adc*(NCHAN*NCHIPS_PER_ADC); rois[0].xmin=adc*(GOTTHARDNCHAN*NCHIPS_PER_ADC);
rois[0].xmax=(adc+1)*(NCHAN*NCHIPS_PER_ADC)-1; rois[0].xmax=(adc+1)*(GOTTHARDNCHAN*NCHIPS_PER_ADC)-1;
rois[0].ymin=-1; rois[0].ymin=-1;
rois[0].ymax=-1; rois[0].ymax=-1;
nROI = 1; nROI = 1;

View File

@ -16,6 +16,13 @@
#define NDAC 8 #define NDAC 8
#define NADC 1 #define NADC 1
/**change this for the real moench chip*/
#define GOTTHARDNCHAN 128
#define GOTTHARDNCHIP 10
#define NCHANS NCHAN*NCHIP*NMAXMOD #define NCHANS NCHAN*NCHIP*NMAXMOD
#define NDACS NDAC*NMAXMOD #define NDACS NDAC*NMAXMOD

View File

@ -80,7 +80,7 @@ int init_detector( int b) {
prepareADC(); prepareADC();
setADC(-1); //already does setdaqreg and clean fifo setADC(-1); //already does setdaqreg and clean fifo
printf("in chip of interes reg:%d\n",bus_r(CHIP_OF_INTRST_REG)); printf("in chip of interes reg:%d\n",bus_r(CHIP_OF_INTRST_REG));
int reg = (NCHAN*NCHIP)<<CHANNEL_OFFSET; int reg = (GOTTHARDNCHAN*GOTTHARDNCHIP)<<CHANNEL_OFFSET;
reg&=CHANNEL_MASK; reg&=CHANNEL_MASK;
reg|=ACTIVE_ADC_MASK; reg|=ACTIVE_ADC_MASK;
bus_w(CHIP_OF_INTRST_REG,reg); bus_w(CHIP_OF_INTRST_REG,reg);
@ -277,7 +277,7 @@ int get_detector_type(int file_des) {
/* receive arguments */ /* receive arguments */
/* execute action */ /* execute action */
ret=myDetectorType; ret=myDetectorType;printf("det type:%d\n",myDetectorType);
#ifdef VERBOSE #ifdef VERBOSE
printf("Returning detector type %d\n",ret); printf("Returning detector type %d\n",ret);
@ -1592,7 +1592,7 @@ int get_threshold_energy(int file_des) {
n += sendDataOnly(file_des,mess,sizeof(mess)); n += sendDataOnly(file_des,mess,sizeof(mess));
/*return ok/fail*/ /*return ok/fail*/
return ret; return OK;
} }
@ -1613,7 +1613,7 @@ int set_threshold_energy(int file_des) {
n += sendDataOnly(file_des,mess,sizeof(mess)); n += sendDataOnly(file_des,mess,sizeof(mess));
/*return ok/fail*/ /*return ok/fail*/
return ret; return OK;
} }

View File

@ -48,12 +48,19 @@ int slsDetector::initSharedMemory(detectorType type, int id) {
nm=1; //modules/detector nm=1; //modules/detector
nc=4; //chips nc=4; //chips
nd=16; //dacs+adcs nd=16; //dacs+adcs
break;
case MOENCH:
nch=160*160;
nm=1; //modules/detector
nc=1; //chips
nd=9; //dacs+adcs
break;
default: default:
nch=0; // dum! nch=0; // dum!
nm=0; //modules/detector nm=0; //modules/detector
nc=0; //chips nc=0; //chips
nd=0; //dacs+adcs nd=0; //dacs+adcs
break;
} }
/** /**
The size of the shared memory is: The size of the shared memory is:
@ -512,6 +519,15 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->nModMax[Y]=1; thisDetector->nModMax[Y]=1;
thisDetector->dynamicRange=16; thisDetector->dynamicRange=16;
break; break;
case MOENCH:
thisDetector->nChans=160*160;
thisDetector->nChips=1;
thisDetector->nDacs=8;
thisDetector->nAdcs=1;
thisDetector->nModMax[X]=1;
thisDetector->nModMax[Y]=1;
thisDetector->dynamicRange=16;
break;
default: default:
thisDetector->nChans=0; thisDetector->nChans=0;
thisDetector->nChips=0; thisDetector->nChips=0;
@ -691,7 +707,8 @@ int slsDetector::initializeDetectorSize(detectorType type) {
framesPerFile=parentDet->framesPerFile; framesPerFile=parentDet->framesPerFile;
if(thisDetector->myDetectorType==GOTTHARD) if(thisDetector->myDetectorType==GOTTHARD)
setFramesPerFile(MAX_FRAMES_PER_FILE); setFramesPerFile(MAX_FRAMES_PER_FILE);
if (thisDetector->myDetectorType==MOENCH)
setFramesPerFile(MOENCH_MAX_FRAMES_PER_FILE);
thisReceiver = new receiverInterface(dataSocket); thisReceiver = new receiverInterface(dataSocket);
// setAngularConversionPointer(thisDetector->angOff,&thisDetector->nMods, thisDetector->nChans*thisDetector->nChips); // setAngularConversionPointer(thisDetector->angOff,&thisDetector->nMods, thisDetector->nChans*thisDetector->nChips);
@ -798,6 +815,14 @@ slsDetectorDefs::sls_detector_module* slsDetector::createModule(detectorType t)
nc=4; //chips nc=4; //chips
nd=16; //dacs nd=16; //dacs
na=16; na=16;
break;
case MOENCH:
nch=160*160;
nm=1; //modules/detector
nc=1; //chips
nd=8; //dacs
na=1;
break;
default: default:
nch=0; // dum! nch=0; // dum!
nm=0; //modules/detector nm=0; //modules/detector
@ -1262,7 +1287,8 @@ int slsDetector::execCommand(string cmd, string answer){
PILATUS, PILATUS,
EIGER, EIGER,
GOTTHARD, GOTTHARD,
AGIPD AGIPD,
MOENCH
}; };
*/ */
@ -2757,6 +2783,7 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
detectorSettings minsettings, maxsettings; detectorSettings minsettings, maxsettings;
switch(thisDetector->myDetectorType){ switch(thisDetector->myDetectorType){
case MOENCH:
case GOTTHARD: case GOTTHARD:
minsettings = HIGHGAIN; minsettings = HIGHGAIN;
maxsettings = VERYHIGHGAIN; maxsettings = VERYHIGHGAIN;
@ -2811,6 +2838,7 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
myMod->module=im; myMod->module=im;
//create file names //create file names
switch(thisDetector->myDetectorType){ switch(thisDetector->myDetectorType){
case MOENCH:
case GOTTHARD: case GOTTHARD:
//settings is saved in myMod.reg for gotthard //settings is saved in myMod.reg for gotthard
myMod->reg=thisDetector->currentSettings; myMod->reg=thisDetector->currentSettings;
@ -2838,6 +2866,7 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings( detectorSettings ise
} else { } else {
ostringstream ostfn,oscfn; ostringstream ostfn,oscfn;
switch(thisDetector->myDetectorType){ switch(thisDetector->myDetectorType){
case MOENCH:
case GOTTHARD: case GOTTHARD:
ostfn << thisDetector->settingsDir << ssettings << ssettings << ".settings"; ostfn << thisDetector->settingsDir << ssettings << ssettings << ".settings";
break; break;
@ -2936,7 +2965,7 @@ int slsDetector::updateDetectorNoWait() {
n = controlSocket->ReceiveDataOnly( &t,sizeof(t)); n = controlSocket->ReceiveDataOnly( &t,sizeof(t));
thisDetector->currentSettings=t; thisDetector->currentSettings=t;
if(thisDetector->myDetectorType!= GOTTHARD){ if((thisDetector->myDetectorType!= GOTTHARD)&&(thisDetector->myDetectorType!= MOENCH)){
//thr=getThresholdEnergy(); //thr=getThresholdEnergy();
n = controlSocket->ReceiveDataOnly( &thr,sizeof(thr)); n = controlSocket->ReceiveDataOnly( &thr,sizeof(thr));
thisDetector->currentThresholdEV=thr; thisDetector->currentThresholdEV=thr;
@ -2960,7 +2989,7 @@ int slsDetector::updateDetectorNoWait() {
thisDetector->timerValue[GATES_NUMBER]=retval; thisDetector->timerValue[GATES_NUMBER]=retval;
//retval=setProbes(tns); //retval=setProbes(tns);
if(thisDetector->myDetectorType!= GOTTHARD){ if((thisDetector->myDetectorType!= GOTTHARD)&&(thisDetector->myDetectorType!= MOENCH)){
n = controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t)); n = controlSocket->ReceiveDataOnly( &retval,sizeof(int64_t));
thisDetector->timerValue[PROBES_NUMBER]=retval; thisDetector->timerValue[PROBES_NUMBER]=retval;
} }
@ -3401,7 +3430,7 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
//std::cout<< "offline " << std::endl; //std::cout<< "offline " << std::endl;
if (t>=0) if (t>=0)
thisDetector->timerValue[index]=t; thisDetector->timerValue[index]=t;
if(thisDetector->myDetectorType==GOTTHARD) if((thisDetector->myDetectorType==GOTTHARD)||(thisDetector->myDetectorType==MOENCH))
thisDetector->timerValue[PROBES_NUMBER]=0; thisDetector->timerValue[PROBES_NUMBER]=0;
} }
} else { } else {
@ -4941,8 +4970,8 @@ int slsDetector::configureMAC(){
std::cout<< "Configuring MAC failed " << std::endl; std::cout<< "Configuring MAC failed " << std::endl;
setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC)); setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC));
} }
else{ else if (thisDetector->myDetectorType==GOTTHARD){
//set frames per file //set frames per file - only for gotthard
if(retval==-1) if(retval==-1)
setFramesPerFile(MAX_FRAMES_PER_FILE); setFramesPerFile(MAX_FRAMES_PER_FILE);
else else
@ -5317,7 +5346,7 @@ int slsDetector::writeConfigurationFile(ofstream &outfile, int id){
// "trimen", // "trimen",
// "receiverTCPPort", // "receiverTCPPort",
if (thisDetector->myDetectorType==GOTTHARD) { if ((thisDetector->myDetectorType==GOTTHARD)||(thisDetector->myDetectorType==MOENCH)) {
names[0]= "hostname"; names[0]= "hostname";
names[1]= "port"; names[1]= "port";
names[2]= "stopport"; names[2]= "stopport";
@ -5417,8 +5446,8 @@ int slsDetector::loadSettingsFile(string fname, int imod) {
myMod=readSettingsFile(fn, thisDetector->myDetectorType); myMod=readSettingsFile(fn, thisDetector->myDetectorType);
if (myMod) { if (myMod) {
myMod->module=im; myMod->module=im;
//settings is saved in myMod.reg for gotthard //settings is saved in myMod.reg for gotthard or moench
if(thisDetector->myDetectorType==GOTTHARD) if((thisDetector->myDetectorType==GOTTHARD)||(thisDetector->myDetectorType==MOENCH))
myMod->reg=thisDetector->currentSettings; myMod->reg=thisDetector->currentSettings;
setModule(*myMod); setModule(*myMod);
deleteModule(myMod); deleteModule(myMod);

View File

@ -307,7 +307,7 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
static int exists(int id); static int exists(int id);
/** /**
configures mac for gotthard readout configures mac for gotthard, moench readout
\returns OK or FAIL \returns OK or FAIL
*/ */
int configureMAC(); int configureMAC();
@ -611,22 +611,22 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
sets/gets detector type sets/gets detector type
normally the detector knows what type of detector it is normally the detector knows what type of detector it is
\param type is the detector type (defaults to GET_DETECTOR_TYPE) \param type is the detector type (defaults to GET_DETECTOR_TYPE)
\returns returns detector type index (1 GENERIC, 2 MYTHEN, 3 PILATUS, 4 XFS, 5 GOTTHARD, 6 AGIPD, -1 command failed) \returns returns detector type index (1 GENERIC, 2 MYTHEN, 3 PILATUS, 4 XFS, 5 GOTTHARD, 6 AGIPD, 7 MOENCH, -1 command failed)
*/ */
int setDetectorType(detectorType type=GET_DETECTOR_TYPE); int setDetectorType(detectorType type=GET_DETECTOR_TYPE);
/** /**
sets/gets detector type sets/gets detector type
normally the detector knows what type of detector it is normally the detector knows what type of detector it is
\param type is the detector type ("Mythen", "Pilatus", "XFS", "Gotthard", Agipd") \param type is the detector type ("Mythen", "Pilatus", "XFS", "Gotthard", Agipd", "Mönch")
\returns returns detector type index (1 GENERIC, 2 MYTHEN, 3 PILATUS, 4 XFS, 5 GOTTHARD, 6 AGIPD, -1 command failed) \returns returns detector type index (1 GENERIC, 2 MYTHEN, 3 PILATUS, 4 XFS, 5 GOTTHARD, 6 AGIPD, 7 MOENCH, -1 command failed)
*/ */
int setDetectorType(string type); int setDetectorType(string type);
/** /**
gets detector type gets detector type
normally the detector knows what type of detector it is normally the detector knows what type of detector it is
\returns returns detector type index (1 GENERIC, 2 MYTHEN, 3 PILATUS, 4 XFS, 5 GOTTHARD, 6 AGIPD, -1 command failed) \returns returns detector type index (1 GENERIC, 2 MYTHEN, 3 PILATUS, 4 XFS, 5 GOTTHARD, 6 AGIPD, 7 MOENCH,-1 command failed)
*/ */
detectorType getDetectorsType(int pos=-1); detectorType getDetectorsType(int pos=-1);

View File

@ -486,7 +486,7 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef
case EIGER: return string("Eiger"); \ case EIGER: return string("Eiger"); \
case GOTTHARD: return string("Gotthard"); \ case GOTTHARD: return string("Gotthard"); \
case AGIPD: return string("Agipd"); \ case AGIPD: return string("Agipd"); \
case MOENCH: return string("Mönch"); \ case MOENCH: return string("Moench"); \
default: return string("Unknown"); \ default: return string("Unknown"); \
}}; }};
@ -500,7 +500,7 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef
if (type=="Eiger") return EIGER; \ if (type=="Eiger") return EIGER; \
if (type=="Gotthard") return GOTTHARD; \ if (type=="Gotthard") return GOTTHARD; \
if (type=="Agipd") return AGIPD; \ if (type=="Agipd") return AGIPD; \
if (type=="Mönch") return MOENCH; \ if (type=="Moench") return MOENCH; \
return GENERIC;}; return GENERIC;};

View File

@ -310,7 +310,7 @@ void slsDetectorUtils::acquire(int delflag){
usleep(100000); usleep(100000);
} }
if (getDetectorsType()==GOTTHARD){ if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH)){
if((*correctionMask)&(1<<WRITE_FILE)) if((*correctionMask)&(1<<WRITE_FILE))
closeDataFile(); closeDataFile();
} }
@ -466,7 +466,7 @@ int slsDetectorUtils::setTotalProgress() {
if (timerValue[FRAME_NUMBER]) if (timerValue[FRAME_NUMBER])
nf=timerValue[FRAME_NUMBER]; nf=timerValue[FRAME_NUMBER];
if(getDetectorsType() == MOENCH) nf/=20;/**TEMP SOLUTION:need to be removed when the proper moench is used*/
if (timerValue[CYCLES_NUMBER]>0) if (timerValue[CYCLES_NUMBER]>0)
nc=timerValue[CYCLES_NUMBER]; nc=timerValue[CYCLES_NUMBER];

View File

@ -200,7 +200,7 @@ slsDetectorDefs::sls_detector_module* energyConversion::readSettingsFile(string
break; break;
case MOENCH:
case GOTTHARD: case GOTTHARD:
//---------------dacs--------------- //---------------dacs---------------
for (int iarg=0; iarg<myMod->ndac; iarg++) { for (int iarg=0; iarg<myMod->ndac; iarg++) {
@ -262,6 +262,7 @@ int energyConversion::writeSettingsFile(string fname, detectorType myDetectorTyp
names[id++]="Vcal"; names[id++]="Vcal";
names[id++]="outBuffEnable"; names[id++]="outBuffEnable";
break; break;
case MOENCH:
case GOTTHARD: case GOTTHARD:
names[id++]="Vref"; names[id++]="Vref";
names[id++]="VcascN"; names[id++]="VcascN";
@ -288,7 +289,7 @@ int energyConversion::writeSettingsFile(string fname, detectorType myDetectorTyp
outfile << names[idac] << " " << iv << std::endl; outfile << names[idac] << " " << iv << std::endl;
} }
if(myDetectorType!=GOTTHARD){ if((myDetectorType!=GOTTHARD)&&(myDetectorType!=MOENCH)){
for (ichip=0; ichip<mod.nchip; ichip++) { for (ichip=0; ichip<mod.nchip; ichip++) {
iv1=mod.chipregs[ichip]&1; iv1=mod.chipregs[ichip]&1;
outfile << names[idac] << " " << iv1 << std::endl; outfile << names[idac] << " " << iv1 << std::endl;

View File

@ -393,12 +393,13 @@ void* postProcessing::processData(int delflag) {
} }
//receiver //receiver
else{ else{
/* /*
//without gui loop
while(1){ while(1){
if (checkJoinThread()) break; if (checkJoinThread()) break;
usleep(200000); usleep(200000);
} }
*/ */
/*if(setReadReceiverFrequency()>0)) ******Not implemented yet ******** /*if(setReadReceiverFrequency()>0)) ******Not implemented yet ********
* else * else
*/ */
@ -409,7 +410,7 @@ void* postProcessing::processData(int delflag) {
int caught=0; int caught=0;
bool newData=false; bool newData=false;
char currentfName[MAX_STR_LENGTH]; char currentfName[MAX_STR_LENGTH]="";
int currentfIndex=0; int currentfIndex=0;
while(1){ while(1){
cout.flush(); cout.flush();

View File

@ -1,5 +1,5 @@
CC = g++ CC = g++
CLAGS += -DSLS_RECEIVER_FUNCTION_LIST -DGOTTHARDD #-DUHRIXCALLBACK #-DTESTWRITE CLAGS += -DSLS_RECEIVER_FUNCTION_LIST #-DUHRIXCALLBACK #-DTESTWRITE
LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++

View File

@ -5,20 +5,32 @@
#include <stdint.h> #include <stdint.h>
#define GOODBYE -200 #define GOODBYE -200
#define BUFFER_SIZE 1286*2 //all max frames defined in sls_detector_defs.h. 20000 gotthard, 100000 for short gotthard, 1000 for moench
#define DATA_BYTES 2560
#define MAX_FRAMES 20000 #define GOTTHARD_FIFO_SIZE 25000
#define PACKETS_PER_FRAME 2
#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_SHORT_PACKETS_PER_FRAME 1
#define GOTTHARD_SHORT_BUFFER_SIZE 518
#define GOTTHARD_SHORT_DATABYTES 512
#define MOENCH_FIFO_SIZE 25000
#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 SHORT_BUFFER_SIZE 518
#define SHORT_DATABYTES 512
#define SHORT_MAX_FRAMES 100000
#define SHORT_PACKETS_PER_FRAME 1
#define FIFO_SIZE 25000
//#define THIS_SOFTWARE_VERSION 0x20120919 //#define THIS_SOFTWARE_VERSION 0x20120919
#endif #endif

View File

@ -31,8 +31,9 @@ using namespace std;
FILE* slsReceiverFunctionList::sfilefd(NULL); FILE* slsReceiverFunctionList::sfilefd(NULL);
int slsReceiverFunctionList::listening_thread_running(0); int slsReceiverFunctionList::listening_thread_running(0);
slsReceiverFunctionList::slsReceiverFunctionList(): slsReceiverFunctionList::slsReceiverFunctionList(detectorType det):
maxFramesPerFile(MAX_FRAMES), myDetectorType(det),
maxFramesPerFile(MAX_FRAMES_PER_FILE),
enableFileWrite(1), enableFileWrite(1),
fileIndex(0), fileIndex(0),
frameIndexNeeded(0), frameIndexNeeded(0),
@ -45,13 +46,13 @@ slsReceiverFunctionList::slsReceiverFunctionList():
framesInFile(0), framesInFile(0),
prevframenum(0), prevframenum(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),
shortFrame(-1), shortFrame(-1),
bufferSize(BUFFER_SIZE), bufferSize(GOTTHARD_BUFFER_SIZE),
packetsPerFrame(2), packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME),
guiDataReady(0), guiDataReady(0),
guiData(NULL), guiData(NULL),
guiFileName(NULL), guiFileName(NULL),
@ -67,6 +68,12 @@ slsReceiverFunctionList::slsReceiverFunctionList():
pRawDataReady(NULL) pRawDataReady(NULL)
{ {
if(myDetectorType == MOENCH){
maxFramesPerFile = MOENCH_MAX_FRAMES_PER_FILE;
bufferSize = MOENCH_BUFFER_SIZE;
packetsPerFrame = MOENCH_PACKETS_PER_FRAME;
}
strcpy(savefilename,""); strcpy(savefilename,"");
strcpy(filePath,""); strcpy(filePath,"");
strcpy(fileName,"run"); strcpy(fileName,"run");
@ -75,16 +82,16 @@ slsReceiverFunctionList::slsReceiverFunctionList():
strcpy(eth,""); strcpy(eth,"");
latestData = new char[bufferSize]; latestData = new char[bufferSize];
fifofree = new CircularFifo<char,FIFO_SIZE>(); fifofree = new CircularFifo<char,GOTTHARD_FIFO_SIZE>();/**MOENCH SAME FIFO SIZE FOR NOW,ELSE MEMBER DECLARATION ERROR*/
fifo = new CircularFifo<char,FIFO_SIZE>(); fifo = new CircularFifo<char,GOTTHARD_FIFO_SIZE>();
mem0=(char*)malloc(4096*FIFO_SIZE); mem0=(char*)malloc(4096*GOTTHARD_FIFO_SIZE);
if (mem0==NULL) { if (mem0==NULL) {
cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY!!!!!!!+++++++++++++++++++++" << endl; cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY!!!!!!!+++++++++++++++++++++" << endl;
} }
buffer=mem0; buffer=mem0;
while (buffer<(mem0+4096*(FIFO_SIZE-1))) { while (buffer<(mem0+4096*(GOTTHARD_FIFO_SIZE-1))) {
fifofree->push(buffer); fifofree->push(buffer);
buffer+=4096; buffer+=4096;
} }
@ -329,7 +336,7 @@ int slsReceiverFunctionList::startListening(){
if (!fifofree->isEmpty()) { if (!fifofree->isEmpty()) {
fifofree->pop(buffer); fifofree->pop(buffer);
//receiver 2 half frames //receiver 2 half frames / 1 short frame / 40 moench frames
rc = udpSocket->ReceiveDataOnly(buffer,bufferSize);//sizeof(buffer)); rc = udpSocket->ReceiveDataOnly(buffer,bufferSize);//sizeof(buffer));
if( rc < 0) if( rc < 0)
cerr << "recvfrom() failed" << endl; cerr << "recvfrom() failed" << endl;
@ -477,7 +484,7 @@ int slsReceiverFunctionList::startWriting(){
if(fifo->pop(wbuf)){ if(fifo->pop(wbuf)){
framesCaught++; framesCaught++;
totalFramesCaught++; totalFramesCaught++;
currframenum = (int)(*((int*)wbuf)); currframenum = (int)(*((int*)wbuf));//cout<<"curreframenm:"<<currframenum<<endl;
//write data //write data
if(enableFileWrite){ if(enableFileWrite){
@ -515,7 +522,7 @@ int slsReceiverFunctionList::startWriting(){
} }
// delete dataWriteFrame; // delete dataWriteFrame;
} }
else{ else{//cout<<"************************fifo empty**********************************"<<endl;
sleepnumber++; sleepnumber++;
usleep(50000); usleep(50000);
} }
@ -581,14 +588,14 @@ int slsReceiverFunctionList::setShortFrame(int i){
shortFrame=i; shortFrame=i;
if(shortFrame!=-1){ if(shortFrame!=-1){
bufferSize = SHORT_BUFFER_SIZE; bufferSize = GOTTHARD_SHORT_BUFFER_SIZE;
maxFramesPerFile = SHORT_MAX_FRAMES; maxFramesPerFile = SHORT_MAX_FRAMES_PER_FILE;
packetsPerFrame = 1; packetsPerFrame = GOTTHARD_SHORT_PACKETS_PER_FRAME;
}else{ }else{
bufferSize = BUFFER_SIZE; bufferSize = GOTTHARD_BUFFER_SIZE;
maxFramesPerFile = MAX_FRAMES; maxFramesPerFile = MAX_FRAMES_PER_FILE;
packetsPerFrame = 2; packetsPerFrame = GOTTHARD_PACKETS_PER_FRAME;
} }
return shortFrame; return shortFrame;

View File

@ -29,7 +29,7 @@ public:
/** /**
* Constructor * Constructor
*/ */
slsReceiverFunctionList(); slsReceiverFunctionList(detectorType det);
/** /**
* Destructor * Destructor
@ -200,6 +200,9 @@ public:
private: private:
/** detector type */
detectorType myDetectorType;
/** max frames per file **/ /** max frames per file **/
int maxFramesPerFile; int maxFramesPerFile;
@ -280,10 +283,10 @@ private:
/** circular fifo to read and write data*/ /** circular fifo to read and write data*/
//CircularFifo<dataStruct,FIFO_SIZE>* fifo; //CircularFifo<dataStruct,FIFO_SIZE>* fifo;
CircularFifo<char,FIFO_SIZE>* fifo; CircularFifo<char,GOTTHARD_FIFO_SIZE>* fifo;
/** circular fifo to read and write data*/ /** circular fifo to read and write data*/
CircularFifo<char,FIFO_SIZE>* fifofree; CircularFifo<char,GOTTHARD_FIFO_SIZE>* fifofree;
/** short frames */ /** short frames */
int shortFrame; int shortFrame;

View File

@ -15,7 +15,6 @@
using namespace std; using namespace std;
int slsReceiverFuncs::file_des(-1); int slsReceiverFuncs::file_des(-1);
int slsReceiverFuncs::socketDescriptor(-1); int slsReceiverFuncs::socketDescriptor(-1);
@ -30,11 +29,12 @@ slsReceiverFuncs::~slsReceiverFuncs() {
slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success): slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
myDetectorType(GOTTHARD),
socket(NULL), socket(NULL),
ret(OK), ret(OK),
lockStatus(0), lockStatus(0),
shortFrame(-1), shortFrame(-1),
packetsPerFrame(PACKETS_PER_FRAME){ packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME){
int port_no = DEFAULT_PORTNO+2; int port_no = DEFAULT_PORTNO+2;
ifstream infile; ifstream infile;
@ -49,51 +49,88 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
if((!strcasecmp(argv[iarg],"-config"))||(!strcasecmp(argv[iarg],"-f"))){ if((!strcasecmp(argv[iarg],"-config"))||(!strcasecmp(argv[iarg],"-f"))){
if(iarg+1==argc){ if(iarg+1==argc){
cout << "no config file name given. Exiting." << endl; cout << "no config file name given. Exiting." << endl;
success=slsDetectorDefs::FAIL; success=FAIL;
}else
fname.assign(argv[iarg+1]);
}
if(!strcasecmp(argv[iarg],"-type")){
if(iarg+1==argc){
cout << "no detector type given after -type in command line. Exiting." << endl;
success=FAIL;
}else{
if(!strcasecmp(argv[iarg+1],"gotthard"));
else if(!strcasecmp(argv[iarg+1],"moench"))
slsReceiverFuncs::myDetectorType = MOENCH;
else{
cout << "could not decode detector type in command line. Exiting." << endl;
success=FAIL;
}
} }
fname.assign(argv[iarg+1]);
} }
} }
if(!fname.empty()){ if((!fname.empty()) && (success == OK)){
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "config file name "<< fname << std::endl; std::cout<< "config file name "<< fname << std::endl;
#endif #endif
infile.open(fname.c_str(), ios_base::in); infile.open(fname.c_str(), ios_base::in);
if (infile.is_open()) { if (infile.is_open()) {
while(infile.good()){ while(infile.good()){
getline(infile,sLine); getline(infile,sLine);
iline++; iline++;
#ifdef VERBOSE #ifdef VERBOSE
cout << str << endl; cout << str << endl;
#endif #endif
if(sLine.find('#')!=string::npos){ if(sLine.find('#')!=string::npos){
#ifdef VERBOSE #ifdef VERBOSE
cout << "Line is a comment " << endl; cout << "Line is a comment " << endl;
#endif #endif
continue; continue;
}else if(sLine.length()<2){ }else if(sLine.length()<2){
#ifdef VERBOSE #ifdef VERBOSE
cout << "Empty line " << endl; cout << "Empty line " << endl;
#endif #endif
continue; continue;
}else{ }else{
istringstream sstr(sLine); istringstream sstr(sLine);
//parameter name //parameter name
if(sstr.good()) if(sstr.good())
sstr >> sargname; sstr >> sargname;
//value
if(sargname=="rx_tcpport"){
if(sstr.good()) { //value
sstr >> sargname; if(sargname=="rx_tcpport"){
sscanf(sargname.c_str(),"%d",&port_no); if(sstr.good()) {
cout<<"dataport:"<<port_no<<endl; sstr >> sargname;
} if(sscanf(sargname.c_str(),"%d",&port_no))
} cout<<"dataport:"<<port_no<<endl;
} else{
} cout << "could not decode port in config file. Exiting." << endl;
success=FAIL;
}
}
}
else if(sargname=="type"){
if(sstr.good()) {
sstr >> sargname;
if(!strcasecmp(sargname.c_str(),"gotthard"))
slsReceiverFuncs::myDetectorType = GOTTHARD;
else if(!strcasecmp(sargname.c_str(),"moench"))
slsReceiverFuncs::myDetectorType = MOENCH;
else{
cout << "could not decode detector type in config file. Exiting." << endl;
success=FAIL;
}
}
}
}
}
infile.close(); infile.close();
}else { }else {
cout << "Error opening configuration file " << fname << endl; cout << "Error opening configuration file " << fname << endl;
@ -119,7 +156,7 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
strcpy(mess,"dummy message"); strcpy(mess,"dummy message");
function_table(); function_table();
slsReceiverList = new slsReceiverFunctionList(); slsReceiverList = new slsReceiverFunctionList(myDetectorType);
#ifdef VERBOSE #ifdef VERBOSE
cout << "Function table assigned." << endl; cout << "Function table assigned." << endl;
@ -131,6 +168,12 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
//success = OK; //success = OK;
} }
} }
switch(myDetectorType){
case GOTTHARD: cout << "This is a GOTTHARD Receiver" << endl; break;
case MOENCH: cout << "This is a MOENCH Receiver" << endl; break;
default: cout << "Unknown Receiver" << endl;success=FAIL;break;
}
} }
void slsReceiverFuncs::start(){ void slsReceiverFuncs::start(){
@ -755,26 +798,210 @@ int slsReceiverFuncs::reset_frames_caught(){
} }
int slsReceiverFuncs::set_short_frame() {
ret=OK;
int index=0;
int retval=-100;
strcpy(mess,"Could not set/reset short frame for receiver\n");
//does not exist for moench
if(myDetectorType==MOENCH){
strcpy(mess,"can not set short frame for moench\n");
ret = FAIL;
}
// receive arguments
if(socket->ReceiveDataOnly(&index,sizeof(index)) < 0 ){
strcpy(mess,"Error reading from socket\n");
ret = FAIL;
}
// execute action if the arguments correctly arrived
#ifdef SLS_RECEIVER_FUNCTION_LIST
if (ret==OK) {
if (lockStatus==1 && socket->differentClients==1){//necessary???
sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP);
ret=FAIL;
}
else if(slsReceiverList->getStatus()==RUNNING){
strcpy(mess,"Cannot set short frame while status is running\n");
ret=FAIL;
}
else{
retval=slsReceiverList->setShortFrame(index);
shortFrame = retval;
if(shortFrame==-1)
packetsPerFrame=GOTTHARD_PACKETS_PER_FRAME;
else
packetsPerFrame=GOTTHARD_SHORT_PACKETS_PER_FRAME;
}
}
#endif
if(ret==OK && socket->differentClients){
cout << "Force update" << endl;
ret=FORCE_UPDATE;
}
// send answer
socket->SendDataOnly(&ret,sizeof(ret));
if(ret==FAIL)
socket->SendDataOnly(mess,sizeof(mess));
socket->SendDataOnly(&retval,sizeof(retval));
//return ok/fail
return ret;
}
int slsReceiverFuncs::read_frame(){ int slsReceiverFuncs::read_frame(){
switch(myDetectorType){
case MOENCH:
return moench_read_frame();
default:
return gotthard_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; int arg = -1,i;
int bufferSize = MOENCH_BUFFER_SIZE;
char* raw = new char[bufferSize];
int rnel = bufferSize/(sizeof(int));
int* retval = new int[rnel];
int* origVal = new int[rnel];
//all initialized to 0
for(i=0;i<rnel;i++) retval[i]=0;
int onebuffersize = bufferSize/MOENCH_PACKETS_PER_FRAME;
int onedatasize = MOENCH_DATA_BYTES/MOENCH_PACKETS_PER_FRAME;
int index=-1;//,index2=-1;
int startIndex=-1;
int count=0;
strcpy(mess,"Could not read frame\n");
// execute action if the arguments correctly arrived
#ifdef SLS_RECEIVER_FUNCTION_LIST
ret=FAIL;
strcpy(mess,"did not start index\n");
for(i=0;i<10;i++){
startIndex=slsReceiverList->getStartFrameIndex();
if(startIndex!=-1){
ret=OK;
break;
}else
usleep(500000);
}
if(ret==FAIL)
cout<<"failed to start"<<endl;
else{
//get frame
slsReceiverList->readFrame(fName,&raw);
if (raw == NULL){
index = startIndex;
cout << "didnt get data. Gui will try again" << endl;
for(i=0;i<MOENCH_PACKETS_PER_FRAME/2;i++){
memcpy(retval + onedatasize*i, ((char*) origVal)+4+ onedatasize*i , onedatasize);
memcpy((((char*)retval)+onedatasize*(i+1)), ((char*) origVal)+10+ onedatasize*(i+1), onedatasize);
}
}else{
//upto 40 indices, look at just index1 and index2 for now
index=(int)(*(int*)raw);
//index2= (int)(*((int*)((char*)(raw+onebuffersize))));
memcpy(origVal,raw,bufferSize);
delete [] raw;/****?????????FOR GOTTHARD AS WELL?????**/
raw=NULL;
for(i=0;i<MOENCH_PACKETS_PER_FRAME/2;i++){
memcpy(retval + onedatasize*i, ((char*) origVal)+4+ onedatasize*i , onedatasize);
memcpy((((char*)retval)+onedatasize*(i+1)), ((char*) origVal)+10+ onedatasize*(i+1), onedatasize);
}
}
arg=((index - startIndex)/MOENCH_PACKETS_PER_FRAME)-1;
#ifdef VERBOSE
cout << "\nstartIndex:" << startIndex << endl;
cout << "fName:" << fName << endl;
cout << "index:" << arg << endl;
#endif
}
#endif
if(ret==OK && socket->differentClients){
cout << "Force update" << endl;
ret=FORCE_UPDATE;
}
// send answer
socket->SendDataOnly(&ret,sizeof(ret));
if(ret==FAIL){
cout << "mess:" << mess << endl;
socket->SendDataOnly(mess,sizeof(mess));
}
else{
socket->SendDataOnly(fName,MAX_STR_LENGTH);
socket->SendDataOnly(&arg,sizeof(arg));
socket->SendDataOnly(retval,MOENCH_DATA_BYTES);
}
//return ok/fail
/* ///ADDED BY ANNA?!?!?!? //?????????FOR GOTTHARD AS WELL?????
if(retval) delete [] retval;
if(origVal) delete [] origVal;
*/
return ret;
}
int slsReceiverFuncs::gotthard_read_frame(){
ret=OK;
char fName[MAX_STR_LENGTH]="";
int arg = -1,i;
//retval is a full frame //retval is a full frame
int rnel = BUFFER_SIZE/(sizeof(int)); int rnel = GOTTHARD_BUFFER_SIZE/(sizeof(int));
int* retval = new int[rnel]; int* retval = new int[rnel];
//all initialized to 0 //all initialized to 0
for(i=0;i<rnel;i++) retval[i]=0; for(i=0;i<rnel;i++) retval[i]=0;
//only for full frames //only for full frames
int onebuffersize = BUFFER_SIZE/PACKETS_PER_FRAME; int onebuffersize = GOTTHARD_BUFFER_SIZE/GOTTHARD_PACKETS_PER_FRAME;
int onedatasize = DATA_BYTES/PACKETS_PER_FRAME; int onedatasize = GOTTHARD_DATA_BYTES/GOTTHARD_PACKETS_PER_FRAME;
//depending on shortframe or not //depending on shortframe or not
int bufferSize = BUFFER_SIZE; int bufferSize = GOTTHARD_BUFFER_SIZE;
if(shortFrame!=-1) if(shortFrame!=-1)
bufferSize=SHORT_BUFFER_SIZE; bufferSize=GOTTHARD_SHORT_BUFFER_SIZE;
char* raw = new char[bufferSize]; char* raw = new char[bufferSize];
int* origVal = new int[rnel]; int* origVal = new int[rnel];
@ -811,14 +1038,14 @@ int slsReceiverFuncs::read_frame(){
//sending garbage values with index = -1 to try again //sending garbage values with index = -1 to try again
if (raw == NULL){ if (raw == NULL){
index = startIndex; index = startIndex;
memcpy((((char*)retval)+(SHORT_DATABYTES*shortFrame)),((char*) origVal)+4, SHORT_DATABYTES); memcpy((((char*)retval)+(GOTTHARD_SHORT_DATABYTES*shortFrame)),((char*) origVal)+4, GOTTHARD_SHORT_DATABYTES);
}else{ }else{
index=(int)(*(int*)raw); index=(int)(*(int*)raw);
memcpy(origVal,raw,bufferSize); memcpy(origVal,raw,bufferSize);
raw=NULL; raw=NULL;
//copy only the adc part //copy only the adc part
memcpy((((char*)retval)+(SHORT_DATABYTES*shortFrame)),((char*) origVal)+4, SHORT_DATABYTES); memcpy((((char*)retval)+(GOTTHARD_SHORT_DATABYTES*shortFrame)),((char*) origVal)+4, GOTTHARD_SHORT_DATABYTES);
} }
}else{ }else{
@ -901,7 +1128,7 @@ int slsReceiverFuncs::read_frame(){
else{ else{
socket->SendDataOnly(fName,MAX_STR_LENGTH); socket->SendDataOnly(fName,MAX_STR_LENGTH);
socket->SendDataOnly(&arg,sizeof(arg)); socket->SendDataOnly(&arg,sizeof(arg));
socket->SendDataOnly(retval,DATA_BYTES); socket->SendDataOnly(retval,GOTTHARD_DATA_BYTES);
} }
//return ok/fail //return ok/fail
@ -1045,59 +1272,6 @@ int slsReceiverFuncs::get_version(){
int slsReceiverFuncs::set_short_frame() {
ret=OK;
int index=0;
int retval=-100;
strcpy(mess,"Could not set/reset short frame for receiver\n");
// receive arguments
if(socket->ReceiveDataOnly(&index,sizeof(index)) < 0 ){
strcpy(mess,"Error reading from socket\n");
ret = FAIL;
}
// execute action if the arguments correctly arrived
#ifdef SLS_RECEIVER_FUNCTION_LIST
if (ret==OK) {
if (lockStatus==1 && socket->differentClients==1){//necessary???
sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP);
ret=FAIL;
}
else if(slsReceiverList->getStatus()==RUNNING){
strcpy(mess,"Cannot set short frame while status is running\n");
ret=FAIL;
}
else{
retval=slsReceiverList->setShortFrame(index);
shortFrame = retval;
if(shortFrame==-1)
packetsPerFrame=PACKETS_PER_FRAME;
else
packetsPerFrame=SHORT_PACKETS_PER_FRAME;
}
}
#endif
if(ret==OK && socket->differentClients){
cout << "Force update" << endl;
ret=FORCE_UPDATE;
}
// send answer
socket->SendDataOnly(&ret,sizeof(ret));
if(ret==FAIL)
socket->SendDataOnly(mess,sizeof(mess));
socket->SendDataOnly(&retval,sizeof(retval));
//return ok/fail
return ret;
}

View File

@ -121,9 +121,18 @@ public:
/** Resets Total Frames Caught */ /** Resets Total Frames Caught */
int reset_frames_caught(); int reset_frames_caught();
/** set short frame */
int set_short_frame();
/** Reads Frame/ buffer */ /** Reads Frame/ buffer */
int read_frame(); int read_frame();
/** gotthard specific read frame */
int gotthard_read_frame();
/** moench specific read frame */
int moench_read_frame();
/** Sets the receiver to send every nth frame to gui, or only upon gui request */ /** Sets the receiver to send every nth frame to gui, or only upon gui request */
int set_read_frequency(); int set_read_frequency();
@ -136,8 +145,6 @@ public:
/** Get Version */ /** Get Version */
int get_version(); int get_version();
/** set short frame */
int set_short_frame();
//General Functions //General Functions
/** Locks Receiver */ /** Locks Receiver */
@ -161,7 +168,12 @@ public:
/** Execute command */ /** Execute command */
int exec_command(); int exec_command();
//private: //private:
/** detector type */
detectorType myDetectorType;
/** slsReceiverFunctionList object */ /** slsReceiverFunctionList object */
slsReceiverFunctionList *slsReceiverList; slsReceiverFunctionList *slsReceiverList;