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 SHORT_MAX_FRAMES_PER_FILE 100000
#define MOENCH_MAX_FRAMES_PER_FILE 1000
/**
\file sls_detector_defs.h

View File

@ -1206,7 +1206,7 @@ int setADC(int adc){
ipPacketSize= DEFAULT_IP_PACKETSIZE;
udpPacketSize=DEFAULT_UDP_PACKETSIZE;
//set channel mask
nchips = NCHIP;
nchips = GOTTHARDNCHIP;
mask = ACTIVE_ADC_MASK;
}
//1 adc
@ -1219,7 +1219,7 @@ int setADC(int adc){
}
//set channel mask
reg = (NCHAN*nchips)<<CHANNEL_OFFSET;
reg = (GOTTHARDNCHAN*nchips)<<CHANNEL_OFFSET;
reg&=CHANNEL_MASK;
reg|=(ACTIVE_ADC_MASK & mask);
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;
else{
//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;
else{
//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));
else {
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
if(adc!=-1){
rois[0].xmin=adc*(NCHAN*NCHIPS_PER_ADC);
rois[0].xmax=(adc+1)*(NCHAN*NCHIPS_PER_ADC)-1;
rois[0].xmin=adc*(GOTTHARDNCHAN*NCHIPS_PER_ADC);
rois[0].xmax=(adc+1)*(GOTTHARDNCHAN*NCHIPS_PER_ADC)-1;
rois[0].ymin=-1;
rois[0].ymax=-1;
nROI = 1;

View File

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

View File

@ -80,7 +80,7 @@ int init_detector( int b) {
prepareADC();
setADC(-1); //already does setdaqreg and clean fifo
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|=ACTIVE_ADC_MASK;
bus_w(CHIP_OF_INTRST_REG,reg);
@ -277,7 +277,7 @@ int get_detector_type(int file_des) {
/* receive arguments */
/* execute action */
ret=myDetectorType;
ret=myDetectorType;printf("det type:%d\n",myDetectorType);
#ifdef VERBOSE
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));
/*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));
/*return ok/fail*/
return ret;
return OK;
}

View File

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

View File

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

View File

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

View File

@ -310,7 +310,7 @@ void slsDetectorUtils::acquire(int delflag){
usleep(100000);
}
if (getDetectorsType()==GOTTHARD){
if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH)){
if((*correctionMask)&(1<<WRITE_FILE))
closeDataFile();
}
@ -466,7 +466,7 @@ int slsDetectorUtils::setTotalProgress() {
if (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)
nc=timerValue[CYCLES_NUMBER];

View File

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

View File

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

View File

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

View File

@ -7,18 +7,30 @@
#define GOODBYE -200
#define BUFFER_SIZE 1286*2
#define DATA_BYTES 2560
#define MAX_FRAMES 20000
#define PACKETS_PER_FRAME 2
//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_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
#endif

View File

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

View File

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

View File

@ -15,7 +15,6 @@
using namespace std;
int slsReceiverFuncs::file_des(-1);
int slsReceiverFuncs::socketDescriptor(-1);
@ -30,11 +29,12 @@ slsReceiverFuncs::~slsReceiverFuncs() {
slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
myDetectorType(GOTTHARD),
socket(NULL),
ret(OK),
lockStatus(0),
shortFrame(-1),
packetsPerFrame(PACKETS_PER_FRAME){
packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME){
int port_no = DEFAULT_PORTNO+2;
ifstream infile;
@ -49,13 +49,27 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
if((!strcasecmp(argv[iarg],"-config"))||(!strcasecmp(argv[iarg],"-f"))){
if(iarg+1==argc){
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;
}
}
}
}
if(!fname.empty()){
if((!fname.empty()) && (success == OK)){
#ifdef VERBOSE
std::cout<< "config file name "<< fname << std::endl;
#endif
@ -84,15 +98,38 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
if(sstr.good())
sstr >> sargname;
//value
if(sargname=="rx_tcpport"){
if(sstr.good()) {
sstr >> sargname;
sscanf(sargname.c_str(),"%d",&port_no);
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();
}else {
@ -119,7 +156,7 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
strcpy(mess,"dummy message");
function_table();
slsReceiverList = new slsReceiverFunctionList();
slsReceiverList = new slsReceiverFunctionList(myDetectorType);
#ifdef VERBOSE
cout << "Function table assigned." << endl;
@ -131,6 +168,12 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
//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(){
@ -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(){
switch(myDetectorType){
case MOENCH:
return moench_read_frame();
default:
return gotthard_read_frame();
}
}
int slsReceiverFuncs::moench_read_frame(){
ret=OK;
char fName[MAX_STR_LENGTH]="";
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
int rnel = BUFFER_SIZE/(sizeof(int));
int rnel = GOTTHARD_BUFFER_SIZE/(sizeof(int));
int* retval = new int[rnel];
//all initialized to 0
for(i=0;i<rnel;i++) retval[i]=0;
//only for full frames
int onebuffersize = BUFFER_SIZE/PACKETS_PER_FRAME;
int onedatasize = DATA_BYTES/PACKETS_PER_FRAME;
int onebuffersize = GOTTHARD_BUFFER_SIZE/GOTTHARD_PACKETS_PER_FRAME;
int onedatasize = GOTTHARD_DATA_BYTES/GOTTHARD_PACKETS_PER_FRAME;
//depending on shortframe or not
int bufferSize = BUFFER_SIZE;
int bufferSize = GOTTHARD_BUFFER_SIZE;
if(shortFrame!=-1)
bufferSize=SHORT_BUFFER_SIZE;
bufferSize=GOTTHARD_SHORT_BUFFER_SIZE;
char* raw = new char[bufferSize];
int* origVal = new int[rnel];
@ -811,14 +1038,14 @@ int slsReceiverFuncs::read_frame(){
//sending garbage values with index = -1 to try again
if (raw == NULL){
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{
index=(int)(*(int*)raw);
memcpy(origVal,raw,bufferSize);
raw=NULL;
//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{
@ -901,7 +1128,7 @@ int slsReceiverFuncs::read_frame(){
else{
socket->SendDataOnly(fName,MAX_STR_LENGTH);
socket->SendDataOnly(&arg,sizeof(arg));
socket->SendDataOnly(retval,DATA_BYTES);
socket->SendDataOnly(retval,GOTTHARD_DATA_BYTES);
}
//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 */
int reset_frames_caught();
/** set short frame */
int set_short_frame();
/** Reads Frame/ buffer */
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 */
int set_read_frequency();
@ -136,8 +145,6 @@ public:
/** Get Version */
int get_version();
/** set short frame */
int set_short_frame();
//General Functions
/** Locks Receiver */
@ -161,7 +168,12 @@ public:
/** Execute command */
int exec_command();
//private:
/** detector type */
detectorType myDetectorType;
/** slsReceiverFunctionList object */
slsReceiverFunctionList *slsReceiverList;