got rid of extra servers for eiger, converted to c and it works

This commit is contained in:
Maliakal Dhanya
2014-08-29 16:41:19 +02:00
parent 10ca7c10e8
commit c5a4f357bf
31 changed files with 662 additions and 720 deletions

View File

@ -51,7 +51,6 @@ int masterMode=NO_MASTER, syncMode=NO_SYNCHRONIZATION, timingMode=AUTO_TIMING;
enum externalSignalFlag signals[4]={EXT_SIG_OFF, EXT_SIG_OFF, EXT_SIG_OFF, EXT_SIG_OFF};
int withGotthard = 0;
#ifdef MCB_FUNCS
extern const int nChans;
@ -286,10 +285,7 @@ int cleanFifo(){
printf("Cleaning FIFO\n");
addr=ADC_SYNC_REG;
if(withGotthard)
adc_sync = GOTTHARD_ADCSYNC_VAL;
else
adc_sync = ADCSYNC_VAL;
adc_sync = ADCSYNC_VAL;
reg = bus_r(addr) & CLEAN_FIFO_MASK;
@ -1404,19 +1400,7 @@ int setADC(int adc){
setDAQRegister();//token timing
cleanFifo();//adc sync
//with gotthard module
if(withGotthard){
//set packet size
ipPacketSize= DEFAULT_IP_PACKETSIZE;
udpPacketSize=DEFAULT_UDP_PACKETSIZE;
//set channel mask
nchips = GOTTHARDNCHIP;
nchans = GOTTHARDNCHAN;
mask = ACTIVE_ADC_MASK;
}
//with moench module all adc
else{/* if(adc==-1){*/
/* if(adc==-1){*/
//set packet size
ipPacketSize= DEFAULT_IP_PACKETSIZE;
udpPacketSize=DEFAULT_UDP_PACKETSIZE;
@ -1424,7 +1408,7 @@ int setADC(int adc){
nchips = NCHIP;
nchans = NCHANS;
mask = ACTIVE_ADC_MASK;
}/*
/*
//with moench module 1 adc -- NOT IMPLEMENTED
else{
ipPacketSize= ADC1_IP_PACKETSIZE;

View File

@ -1,9 +1,9 @@
Path: slsDetectorsPackage/slsDetectorSoftware/moenchDetectorServer
URL: origin git@gitorious.psi.ch:sls_det_software/sls_detector_software.git/moenchDetectorServer
Repository Root: origin git@gitorious.psi.ch:sls_det_software/sls_detector_software.git
Repsitory UUID: 046a469b1e6582c4c55bd6eaeb4818b618d0a9a9
Revision: 55
Branch: separate_receiver
Repsitory UUID: 8c994ea0d538628b36a9497508960388816749fa
Revision: 57
Branch: master
Last Changed Author: Maliakal_Dhanya
Last Changed Rev: 14
Last Changed Date: 2014-06-03 12:26:45 +0200
Last Changed Rev: 278
Last Changed Date: 2014-08-08 14:03:30 +0200

View File

@ -1,11 +1,11 @@
//#define SVNPATH ""
#define SVNURL "git@gitorious.psi.ch:sls_det_software/sls_detector_software.git/moenchDetectorServer"
//#define SVNREPPATH ""
#define SVNREPUUID "046a469b1e6582c4c55bd6eaeb4818b618d0a9a9"
//#define SVNREV 0x14
#define SVNREPUUID "8c994ea0d538628b36a9497508960388816749fa"
//#define SVNREV 0x278
//#define SVNKIND ""
//#define SVNSCHED ""
#define SVNAUTH "Maliakal_Dhanya"
#define SVNREV 0x14
#define SVNDATE 0x20140603
#define SVNREV 0x278
#define SVNDATE 0x20140808
//

View File

@ -513,7 +513,6 @@ int set_one_dac(int imod) {
bit=value & (1<<(15-ibit));
if (bit) {
putout("0000010001000000",imod);
putout("0000011001000000",imod);
putout("0000010001000000",imod);
#ifdef DEBUGOUT
fprintf(stdout,"1");
@ -551,15 +550,15 @@ int initDACbyIndex(int ind,int val, int imod) {
int ref=partref[ind];
int r1=partr1[ind];
int r2=partr2[ind];
int retval[2];
v=(val+(val-ref)*r1/r2)*DAC_DR/DAC_MAX;
v=initDACbyIndexDACU(ind,v,imod);
v=initDACbyIndexDACU(ind,v,imod,0,retval);
return (v*DAC_MAX/DAC_DR+ref*r1/r2)/(1+r1/r2);
}
int initDACbyIndexDACU(int ind, int val, int imod) {
int initDACbyIndexDACU(int ind, int val, int imod, int mV, int retval[]) {
// const double daccs[NDAC]=DACCS;
// const double dacaddr[NDAC]=DACADDR;
@ -568,6 +567,8 @@ int initDACbyIndexDACU(int ind, int val, int imod) {
// int addr=dacaddr[ind];
// int iv;
int im;
if(mV)
val = (val*4096)/2500;
if (val>=0)
initDAC(ind,val, imod);
@ -598,124 +599,12 @@ int initDACbyIndexDACU(int ind, int val, int imod) {
#ifdef VERBOSE
printf("returning %d\n",setDACRegister(ind, -1, 0));
#endif
return setDACRegister(ind, -1, 0);
retval[0] = setDACRegister(ind, -1, 0);
retval[1] = (retval[0]*2500)/4096;
return retval[0];
}
}
int getThresholdEnergy() {
double g[3]=DEFAULTGAIN;
double o[3]=DEFAULTOFFSET;
double myg=-1, myo=-1;
// int dacu;
int imod;
int ethr=-1;
int ret=FAIL;
if (detectorModules) {
// for (imod=0; imod<getNModBoard(); imod++) {
for (imod=0; imod<nModX; imod++) {
#ifdef VERBOSE
printf("module=%d settings=%d, gain=%f, offset=%f\n",imod,thisSettings, (detectorModules+imod)->gain,(detectorModules+imod)->offset);
#endif
if ((detectorModules+imod)->gain>0)
myg=(detectorModules+imod)->gain;
else {
if (thisSettings>=0 && thisSettings<3)
myg=g[thisSettings];
// else
//myg=-1;
}
if ((detectorModules+imod)->offset>0)
myo=(detectorModules+imod)->offset;
else {
if (thisSettings>=0 && thisSettings<3)
myo=o[thisSettings];
// else
//myo=-1;
}
if (myg>0 && myo>0) {
//ethr=(myo-detectorDacs[VTHRESH+imod*NDAC])*1000/myg;
ethr=(myo-setDACRegister(VDAC0,-1,imod))*1000/myg;//edited by dhanya
// else
// ethr=-1;
}
#ifdef VERBOSE
//printf("module=%d gain=%f, offset=%f, dacu=%f\n",imod, myg, myo, detectorDacs[VTHRESH+imod*NDAC]);
printf("module=%d gain=%f, offset=%f, dacu=%d\n",imod, myg, myo,(int)(setDACRegister(VDAC0,-1,imod)));//edited by dhanya
printf("Threshold energy of module %d is %d eV\n", imod, ethr);
#endif
if (imod==0)
ret=ethr;
else {
if (ethr>(ret+100) || ethr<(ret-100))
return FAIL;
}
}
}
return ret;
}
int setThresholdEnergy(int ethr) {
double g[3]=DEFAULTGAIN;
double o[3]=DEFAULTOFFSET;
double myg=-1, myo=-1;
int dacu;
int imod;
int ret=ethr;
setSettings(GET_SETTINGS,-1);//-1 added by dhanya
if (thisSettings>=0 || thisSettings<3){
myg=g[thisSettings];
myo=o[thisSettings];
}
for (imod=0; imod<nModX; imod++) {
if (detectorModules) {
if ((detectorModules+imod)->gain>0)
myg=(detectorModules+imod)->gain;
else
if (thisSettings>=0 && thisSettings<3)
myg=g[thisSettings];
else
myg=-1;
if ((detectorModules+imod)->offset>0)
myo=(detectorModules+imod)->offset;
else
if (thisSettings>=0 && thisSettings<3)
myo=o[thisSettings];
else
myo=-1;
} else {
if (thisSettings>=0 && thisSettings<3)
myo=o[thisSettings];
else
myo=-1;
if (thisSettings>=0 && thisSettings<3)
myg=g[thisSettings];
else
myg=-1;
}
if (myg>0 && myo>0) {
dacu=myo-myg*((double)ethr)/1000.;
#ifdef VERBOSE
printf("module %d (%x): gain %f, off %f, energy %d eV, dac %d\n",imod,(unsigned int)((detectorModules+imod)),(detectorModules+imod)->gain,(detectorModules+imod)->offset, ethr,dacu);
#endif
} else {
dacu=ethr;
#ifdef VERBOSE
printf("could not set threshold energy for module %d, settings %d (offset is %f; gain is %f)\n",imod,thisSettings,myo,myg);
#endif
}
initDACbyIndexDACU(VDAC0, dacu, imod); ///needs to be fixed dhanya
}
return ret;
}
int getDACbyIndexDACU(int ind, int imod) {
/*
@ -2585,19 +2474,9 @@ ROI* setROI(int n, ROI arg[], int *retvalsize, int *ret){
int i,adc;
ROI temp;
/*
if(n>=0){
//clear rois
for(i=0;i<MAX_ROIS;i++)
rois[i]=temp;
/*ideal way to set roi
for(i=0;i<n;i++)
rois[i]=arg[i];
nROI = n;
*/
if(n==0)
adc=-1;
else{
@ -2633,7 +2512,7 @@ ROI* setROI(int n, ROI arg[], int *retvalsize, int *ret){
//set adc of interest
setADC(adc);
}
}*/
//#ifdef VERBOSE
printf("Rois:\n");

View File

@ -109,10 +109,9 @@ int initDAC(int dac_addr, int value,int imod );
int initDACs(int* v,int imod );
int setSettings(int i,int imod);
int initDACbyIndex(int ind,int val, int imod);
int initDACbyIndexDACU(int ind,int val, int imod);
int initDACbyIndexDACU(int ind,int val, int imod, int mV, int retval[]);
int getDACbyIndexDACU(int ind, int imod);
int getThresholdEnergy();
int setThresholdEnergy(int ethr);
/* Other DAC index routines*/
int getTemperatureByModule(int tempSensor, int imod);

View File

@ -25,7 +25,6 @@ int main(int argc, char *argv[])
int retval=OK;
int sd, fd;
int iarg;
int checkType = 1;
for(iarg=1; iarg<argc; iarg++){
@ -40,20 +39,6 @@ int main(int argc, char *argv[])
return 1;
}
}
else if(!strcasecmp(argv[iarg],"-test")){
if(argc==iarg+1){
printf("No test condition given. Exiting.\n");
return 1;
}
if(!strcasecmp(argv[iarg+1],"with_gotthard")){
checkType = 0;
}else{
printf("could not decode test condition. Possible arguments: with_gotthard. Exiting\n");
return 1;
}
}
}
@ -71,10 +56,7 @@ int main(int argc, char *argv[])
//control server
else {
portno = DEFAULT_PORTNO;
if(checkType)
sprintf(cmd,"%s %d stopserver &",argv[0],DEFAULT_PORTNO+1);
else
sprintf(cmd,"%s %d stopserver -test with_gotthard &",argv[0],DEFAULT_PORTNO+1);
sprintf(cmd,"%s %d stopserver &",argv[0],DEFAULT_PORTNO+1);
printf("\n\nControl Server\nOpening control server on port %d\n",portno );
//printf("\n\ncmd:%s\n",cmd);
@ -83,7 +65,7 @@ int main(int argc, char *argv[])
}
init_detector(b, checkType);
init_detector(b);
sd=bindSocket(portno);

View File

@ -16,9 +16,7 @@
#define NDAC 8
#define NADC 1
/**when moench readout tested with gotthard module*/
#define GOTTHARDNCHAN 128
#define GOTTHARDNCHIP 10

View File

@ -54,10 +54,8 @@ char mess[1000];
int digitalTestBit = 0;
extern int withGotthard;
int init_detector(int b, int checkType) {
int init_detector(int b) {
if (mapCSP0()==FAIL) { printf("Could not map memory\n");
exit(1);
}
@ -69,21 +67,13 @@ int init_detector(int b, int checkType) {
//confirm if it is really moench
if(((bus_r(PCB_REV_REG) & DETECTOR_TYPE_MASK)>>DETECTOR_TYPE_OFFSET) != MOENCH_MODULE ){
if(checkType){
printf("This is a Gotthard detector. Exiting Moench Server.\n\n");
exit(-1);
}
//no check required as specified in command line arguments
else if(b){
printf("***This is a GOTTHARD detector with %d chips per module***\n",GOTTHARDNCHIP);
printf("***Assuming this to be a MOENCH detector***\n");
}
withGotthard = 1;
} else if(b){
printf("***This is a MOENCH detector with %d chips per module***\n",NCHIP);
printf("This is a Gotthard detector. Exiting Moench Server.\n\n");
exit(-1);
}
if (b) {
printf("***This is a MOENCH detector with %d chips per module***\n",NCHIP);
#ifdef MCB_FUNCS
printf("\nBoard Revision:0x%x\n",(bus_r(PCB_REV_REG)&BOARD_REVISION_MASK));
initDetector();
@ -914,13 +904,15 @@ int read_register(int file_des) {
int set_dac(int file_des) {
//default:all mods
int retval;
int retval[2];retval[1]=-1;
int temp;
int ret=OK;
int arg[3];
enum dacIndex ind;
int imod;
int n;
int val;
int mV;
int idac=0;
sprintf(mess,"Can't set DAC\n");
@ -932,6 +924,7 @@ int set_dac(int file_des) {
}
ind=arg[0];
imod=arg[1];
mV=arg[2];
n = receiveDataOnly(file_des,&val,sizeof(val));
if (n < 0) {
@ -990,45 +983,50 @@ int set_dac(int file_des) {
ret=FAIL;
sprintf(mess,"Detector locked by %s\n",lastClientIP);
} else{
if(idac==HIGH_VOLTAGE)
retval=initHighVoltageByModule(val,imod);
else
retval=initDACbyIndexDACU(idac,val,imod);
if(idac==HIGH_VOLTAGE){
retval[0]=initHighVoltageByModule(val,imod);
ret=FAIL;
if(retval[0]==-2)
strcpy(mess,"Invalid Voltage.Valid values are 0,90,110,120,150,180,200");
else if(retval[0]==-3)
strcpy(mess,"Weird value read back or it has not been set yet\n");
else
ret=OK;
}else{
initDACbyIndexDACU(idac,val,imod,mV,retval);
ret=FAIL;
if(mV)
temp = retval[1];
else
temp = retval[0];
if ((abs(temp-val)<=3) || val==-1) {
ret=OK;
#ifdef VERBOSE
printf("DAC set to %d in dac units and %d mV\n", retval[0],retval[1]);
#endif
}
}
}
}
if(ret==OK){
ret=FAIL;
if(idac==HIGH_VOLTAGE){
if(retval==-2)
strcpy(mess,"Invalid Voltage.Valid values are 0,90,110,120,150,180,200");
else if(retval==-3)
strcpy(mess,"Weird value read back or it has not been set yet\n");
else
ret=OK;
}//since v r saving only msb
else if ((retval-val)<=3 || val==-1)
ret=OK;
}
#endif
#ifdef VERBOSE
printf("DAC set to %d V\n", retval);
#endif
if(ret==FAIL)
printf("Setting dac %d of module %d: wrote %d but read %d\n", ind, imod, val, retval);
printf("Setting dac %d of module %d: wrote %d but read %d\n", ind, imod, val, temp);
else{
if (differentClients)
ret=FORCE_UPDATE;
}
/* send answer */
/* send OK/failed */
n = sendDataOnly(file_des,&ret,sizeof(ret));
if (ret!=FAIL) {
/* send return argument */
n += sendDataOnly(file_des,&retval,sizeof(retval));
n += sendDataOnly(file_des,retval,sizeof(retval));
} else {
n += sendDataOnly(file_des,mess,sizeof(mess));
}
@ -1610,7 +1608,7 @@ int get_threshold_energy(int file_des) {
n += sendDataOnly(file_des,mess,sizeof(mess));
/*return ok/fail*/
return OK;
return ret;
}
@ -1631,7 +1629,7 @@ int set_threshold_energy(int file_des) {
n += sendDataOnly(file_des,mess,sizeof(mess));
/*return ok/fail*/
return OK;
return ret;
}

View File

@ -23,7 +23,7 @@ int sockfd;
int function_table();
int decode_function(int);
int init_detector(int,int);
int init_detector(int);
int M_nofunc(int);
int exit_server(int);