mythenDetectorServer now works with dacs_t and the commands vpreamp and vcalibration respond correctly

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@226 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
bergamaschi
2012-08-22 09:44:08 +00:00
parent cd7cfadac8
commit 362ba2af11
6 changed files with 68 additions and 43 deletions

View File

@ -1,5 +1,7 @@
CFLAGS= -DC_ONLY CFLAGS= -DC_ONLY
FLAGS+= -DDACS_INT #-DVERBOSE -DVERYVERBOSE #FLAGS+= #-DVERBOSE -DVERYVERBOSE
#DFLAGS= -DDACS_INT
INCLUDES= -IcommonFiles -IslsDetector -IMySocketTCP -IusersFunctions -ImultiSlsDetector -IslsDetectorUtils -IslsDetectorCommand -IslsDetectorAnalysis INCLUDES= -IcommonFiles -IslsDetector -IMySocketTCP -IusersFunctions -ImultiSlsDetector -IslsDetectorUtils -IslsDetectorCommand -IslsDetectorAnalysis
#EPICSFLAGS=-D EPICS -I/usr/local/epics/base/include/ -I /usr/local/epics/base/include/os/Linux/ -L /usr/local/epics/base/lib/SL5-x86/ -Wl,-R/usr/local/epics/base/lib/SL5-x86 -lca -lCom #EPICSFLAGS=-D EPICS -I/usr/local/epics/base/include/ -I /usr/local/epics/base/include/os/Linux/ -L /usr/local/epics/base/lib/SL5-x86/ -Wl,-R/usr/local/epics/base/lib/SL5-x86 -lca -lCom
@ -25,23 +27,23 @@ doc: $(SRC_H) $(SRC_CLNT)
mythenServer: $(SRC_MYTHEN_SVC) mythenServer: $(SRC_MYTHEN_SVC)
$(CC) $(SRC_MYTHEN_SVC) $(CFLAGS) $(FLAGS) $(INCLUDES) -ImythenDetectorServer -DVIRTUAL -lm -D MCB_FUNCS -DC_ONLY -DVERBOSE $(CC) $(SRC_MYTHEN_SVC) $(CFLAGS) $(FLAGS) $(DFLAGS) $(INCLUDES) -ImythenDetectorServer -DVIRTUAL -lm -D MCB_FUNCS -DC_ONLY -DVERBOSE
mv a.out mythenServer mv a.out mythenServer
picassoServer: $(SRC_MYTHEN_SVC) picassoServer: $(SRC_MYTHEN_SVC)
$(CC) $(SRC_MYTHEN_SVC) $(CFLAGS) $(FLAGS) $(INCLUDES) -ImythenDetectorServer -D VIRTUAL -lm -DMCB_FUNCS -DPICASSOD -DC_ONLY $(CC) $(SRC_MYTHEN_SVC) $(CFLAGS) $(FLAGS) $(DFLAGS) $(INCLUDES) -ImythenDetectorServer -D VIRTUAL -lm -DMCB_FUNCS -DPICASSOD -DC_ONLY
mv a.out picassoServer mv a.out picassoServer
%.o : %.cpp %.h %.o : %.cpp %.h
$(CXX) -Wall -o $@ -c $< $(INCLUDES) $(FLAGS) $(EPICSFLAGS) $(CXX) -Wall -o $@ -c $< $(INCLUDES) $(DFLAGS) $(FLAGS) $(EPICSFLAGS)
package: $(OBJS) package: $(OBJS)
$(CXX) -shared -Wl,-soname,libSlsDetector.so -o libSlsDetector.so $(OBJS) -lc $(INCLUDES) $(FLAGS) $(EPICSFLAGS) $(CXX) -shared -Wl,-soname,libSlsDetector.so -o libSlsDetector.so $(OBJS) -lc $(INCLUDES) $(DFLAGS) $(FLAGS) $(EPICSFLAGS)
ar rcs libSlsDetector.a $(OBJS) ar rcs libSlsDetector.a $(OBJS)
clean: clean:

View File

@ -362,13 +362,13 @@ int sendModule(int file_des, sls_detector_module *myMod) {
#ifdef VERBOSE #ifdef VERBOSE
printf("module %d of size %d sent\n",myMod->module, ts); printf("module %d of size %d sent\n",myMod->module, ts);
#endif #endif
ts+= sendDataOnly(file_des,myMod->dacs,sizeof(double)*nDacs); ts+= sendDataOnly(file_des,myMod->dacs,sizeof(dacs_t)*nDacs);
#ifdef VERBOSE #ifdef VERBOSE
printf("dacs %d of size %d sent\n",myMod->module, ts); printf("dacs %d of size %d sent\n",myMod->module, ts);
for (idac=0; idac< nDacs; idac++) for (idac=0; idac< nDacs; idac++)
printf("dac %d is %d\n",idac,myMod->dacs[idac]); printf("dac %d is %d\n",idac,myMod->dacs[idac]);
#endif #endif
ts+= sendDataOnly(file_des,myMod->adcs,sizeof(double)*nAdcs); ts+= sendDataOnly(file_des,myMod->adcs,sizeof(dacs_t)*nAdcs);
#ifdef VERBOSE #ifdef VERBOSE
printf("adcs %d of size %d sent\n",myMod->module, ts); printf("adcs %d of size %d sent\n",myMod->module, ts);
#endif #endif
@ -432,15 +432,15 @@ int receiveChip(int file_des, sls_detector_chip* myChip) {
int receiveModule(int file_des, sls_detector_module* myMod) { int receiveModule(int file_des, sls_detector_module* myMod) {
double *dacptr=myMod->dacs; dacs_t *dacptr=myMod->dacs;
double *adcptr=myMod->adcs; dacs_t *adcptr=myMod->adcs;
int *chipptr=myMod->chipregs, *chanptr=myMod->chanregs; int *chipptr=myMod->chipregs, *chanptr=myMod->chanregs;
int ts=0; int ts=0;
int nChips, nchipold=myMod->nchip, nchipdiff; int nChips, nchipold=myMod->nchip, nchipdiff;
int nChans, nchanold=myMod->nchan, nchandiff; int nChans, nchanold=myMod->nchan, nchandiff;
int nDacs, ndold=myMod->ndac, ndacdiff; int nDacs, ndold=myMod->ndac, ndacdiff;
int nAdcs, naold=myMod->nadc, nadcdiff; int nAdcs, naold=myMod->nadc, nadcdiff;
int id=0;
ts+= receiveDataOnly(file_des,myMod,sizeof(sls_detector_module)); ts+= receiveDataOnly(file_des,myMod,sizeof(sls_detector_module));
@ -490,29 +490,33 @@ int receiveModule(int file_des, sls_detector_module* myMod) {
printf("received %d adcs\n",nAdcs); printf("received %d adcs\n",nAdcs);
#endif #endif
if (ndacdiff<=0) { if (ndacdiff<=0) {
ts+=receiveDataOnly(file_des,myMod->dacs, sizeof(double)*nDacs); ts+=receiveDataOnly(file_des,myMod->dacs, sizeof(dacs_t)*nDacs);
#ifdef VERBOSE #ifdef VERBOSE
printf("dacs received\n"); printf("dacs received\n");
for (id=0; id<nDacs; id++)
printf("dac %d val %d\n",id, myMod->dacs[id]);
#endif #endif
} else { } else {
dacptr=malloc(ndacdiff*sizeof(double)); dacptr=malloc(ndacdiff*sizeof(dacs_t));
myMod->ndac=ndold; myMod->ndac=ndold;
ts+=receiveDataOnly(file_des,myMod->dacs, sizeof(double)*ndold); ts+=receiveDataOnly(file_des,myMod->dacs, sizeof(dacs_t)*ndold);
ts+=receiveDataOnly(file_des,dacptr, sizeof(double)*ndacdiff); ts+=receiveDataOnly(file_des,dacptr, sizeof(dacs_t)*ndacdiff);
free(dacptr); free(dacptr);
return FAIL; return FAIL;
} }
if (nadcdiff<=0) { if (nadcdiff<=0) {
ts+=receiveDataOnly(file_des,myMod->adcs, sizeof(double)*nAdcs); ts+=receiveDataOnly(file_des,myMod->adcs, sizeof(dacs_t)*nAdcs);
#ifdef VERBOSE #ifdef VERBOSE
printf("adcs received\n"); printf("adcs received\n");
#endif #endif
} else { } else {
adcptr=malloc(nadcdiff*sizeof(double)); adcptr=malloc(nadcdiff*sizeof(dacs_t));
myMod->nadc=naold; myMod->nadc=naold;
ts+=receiveDataOnly(file_des,myMod->adcs, sizeof(double)*naold); ts+=receiveDataOnly(file_des,myMod->adcs, sizeof(dacs_t)*naold);
ts+=receiveDataOnly(file_des,adcptr, sizeof(double)*nadcdiff); ts+=receiveDataOnly(file_des,adcptr, sizeof(dacs_t)*nadcdiff);
free(adcptr); free(adcptr);
return FAIL; return FAIL;
} }

View File

@ -14,6 +14,7 @@ SRCS= server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_func
OBJS= $(SRCS:%.c=%.o) OBJS= $(SRCS:%.c=%.o)
CFLAGS+= -Wall -DC_ONLY -DMCB_FUNCS -DVERBOSE CFLAGS+= -Wall -DC_ONLY -DMCB_FUNCS -DVERBOSE
#-DDACS_INT
#-DVERYVERBOSE #-DVERYVERBOSE
#-Werror #-Werror

View File

@ -38,8 +38,8 @@ const int noneSelected=-1;
sls_detector_module *detectorModules=NULL; sls_detector_module *detectorModules=NULL;
int *detectorChips=NULL; int *detectorChips=NULL;
int *detectorChans=NULL; int *detectorChans=NULL;
float *detectorDacs=NULL; dacs_t *detectorDacs=NULL;
float *detectorAdcs=NULL; dacs_t *detectorAdcs=NULL;
//int numberOfProbes; //int numberOfProbes;
@ -61,8 +61,8 @@ int initDetector() {
detectorChips=malloc(n*NCHIP*sizeof(int)); detectorChips=malloc(n*NCHIP*sizeof(int));
detectorChans=malloc(n*NCHIP*NCHAN*sizeof(int)); detectorChans=malloc(n*NCHIP*NCHAN*sizeof(int));
detectorDacs=malloc(n*NDAC*sizeof(float)); detectorDacs=malloc(n*NDAC*sizeof(dacs_t));
detectorAdcs=malloc(n*NADC*sizeof(float)); detectorAdcs=malloc(n*NADC*sizeof(dacs_t));
#ifdef VERBOSE #ifdef VERBOSE
printf("modules from 0x%x to 0x%x\n",detectorModules, detectorModules+n); printf("modules from 0x%x to 0x%x\n",detectorModules, detectorModules+n);
printf("chips from 0x%x to 0x%x\n",detectorChips, detectorChips+n*NCHIP); printf("chips from 0x%x to 0x%x\n",detectorChips, detectorChips+n*NCHIP);
@ -440,6 +440,9 @@ int program_one_dac(int addr, int value, int imod) {
// sls_detector_module *myMod; // sls_detector_module *myMod;
control=9+addr; control=9+addr;
int ireg;
printf("programming dac %d value %d module %d\n",addr, value,imod); printf("programming dac %d value %d module %d\n",addr, value,imod);
#ifdef MAX5533 #ifdef MAX5533
@ -474,12 +477,16 @@ int program_one_dac(int addr, int value, int imod) {
#endif #endif
idac=sDac*2+addr; idac=sDac*2+addr;
ireg=idac;
if (idac==VCAL) { if (idac==VCAL) {
idac=RGPR; idac=RGPR;
} else if (idac==RGPR){ } else if (idac==RGPR){
idac=VCAL; idac=VCAL;
} }
if (detectorDacs) { if (detectorDacs) {
sMod=imod; sMod=imod;
if (imod==ALLMOD) if (imod==ALLMOD)
@ -488,13 +495,13 @@ int program_one_dac(int addr, int value, int imod) {
if (imod>=0 && imod<nModX) { if (imod>=0 && imod<nModX) {
// myMod=detectorModules+imod; // myMod=detectorModules+imod;
//(detectorModules+imod)->dacs[idac]=v; //(detectorModules+imod)->dacs[idac]=v;
detectorDacs[idac+NDAC*imod]=v; detectorDacs[ireg+NDAC*imod]=v;
//#ifdef VERBOSE //#ifdef VERBOSE
#ifdef VERBOSE #ifdef VERBOSE
printf("module=%d index=%d, val=%d addr=%x\n",imod, idac, v, detectorDacs+idac+NDAC*imod); printf("module=%d index=%d, val=%d addr=%x\n",imod, idac, v, detectorDacs+idac+NDAC*imod);
#endif #endif
setDACRegister(idac,v,imod); setDACRegister(ireg,v,imod);
/* /*
@ -542,7 +549,7 @@ int program_one_dac(int addr, int value, int imod) {
//#endif //#endif
} else if (imod==ALLMOD) { } else if (imod==ALLMOD) {
for (im=0; im<nModX; im++) { for (im=0; im<nModX; im++) {
detectorDacs[idac+NDAC*im]=v; detectorDacs[ireg+NDAC*im]=v;
/* /*
#ifdef VERBOSE #ifdef VERBOSE
@ -592,7 +599,7 @@ int program_one_dac(int addr, int value, int imod) {
printf("after setting dac %d module %d -- %x -- %x addr %d\n",idac, im, reg, bus_r(MOD_DACS2_REG+(im<<SHIFTMOD))); printf("after setting dac %d module %d -- %x -- %x addr %d\n",idac, im, reg, bus_r(MOD_DACS2_REG+(im<<SHIFTMOD)));
#endif #endif
*/ */
setDACRegister(idac,v,im); setDACRegister(ireg,v,im);
} }
} }
} }
@ -640,12 +647,19 @@ int set_one_dac(int imod) {
return OK; return OK;
} }
float initDACbyIndex(int ind,float val, int imod) { dacs_t initDACbyIndex(int ind,dacs_t ival, int imod) {
int v; int v;
const float partref[NDAC]=PARTREF; const float partref[NDAC]=PARTREF;
const float partr1[NDAC]=PARTR1; const float partr1[NDAC]=PARTR1;
const float partr2[NDAC]=PARTR2; const float partr2[NDAC]=PARTR2;
float val;
#ifdef DACS_INT
val=((float)ival)*1E-3;
#else
val=ival;
#endif
float ref=partref[ind]; float ref=partref[ind];
float r1=partr1[ind]; float r1=partr1[ind];
float r2=partr2[ind]; float r2=partr2[ind];
@ -657,10 +671,10 @@ float initDACbyIndex(int ind,float val, int imod) {
return (v*DAC_MAX/DAC_DR+ref*r1/r2)/(1+r1/r2); return (v*DAC_MAX/DAC_DR+ref*r1/r2)/(1+r1/r2);
} }
float initDACbyIndexDACU(int ind, int val, int imod) { dacs_t initDACbyIndexDACU(int ind, dacs_t val, int imod) {
const float daccs[NDAC]=DACCS; const int daccs[NDAC]=DACCS;
const float dacaddr[NDAC]=DACADDR; const int dacaddr[NDAC]=DACADDR;
int cs=daccs[ind]; int cs=daccs[ind];
int addr=dacaddr[ind]; int addr=dacaddr[ind];
@ -820,7 +834,7 @@ int setThresholdEnergy(int ethr) {
float getDACbyIndexDACU(int ind, int imod) { dacs_t getDACbyIndexDACU(int ind, int imod) {
/* /*
if (detectorDacs) { if (detectorDacs) {
if (imod<getNModBoard()) if (imod<getNModBoard())
@ -923,7 +937,7 @@ int setSettings(int i) {
irgsh2=detectorDacs[imod*NDAC+RGSH2]; irgsh2=detectorDacs[imod*NDAC+RGSH2];
*/ */
irgpr=setDACRegister(4,-1,imod); irgpr=setDACRegister(RGPR,-1,imod);
irgsh1=setDACRegister(RGSH1,-1,imod); irgsh1=setDACRegister(RGSH1,-1,imod);
irgsh2=setDACRegister(RGSH2,-1,imod); irgsh2=setDACRegister(RGSH2,-1,imod);
for (is=STANDARD; is<UNDEFINED; is++) { for (is=STANDARD; is<UNDEFINED; is++) {
@ -936,7 +950,7 @@ int setSettings(int i) {
#endif #endif
for (imod=1; imod<nModX; imod++) { for (imod=1; imod<nModX; imod++) {
if (isett!=UNDEFINED) { if (isett!=UNDEFINED) {
irgpr=setDACRegister(4,-1,imod); irgpr=setDACRegister(RGPR,-1,imod);
irgsh1=setDACRegister(RGSH1,-1,imod); irgsh1=setDACRegister(RGSH1,-1,imod);
irgsh2=setDACRegister(RGSH2,-1,imod); irgsh2=setDACRegister(RGSH2,-1,imod);
/* /*

View File

@ -100,9 +100,9 @@ int set_one_dac(int imod);
int initDAC(int dac_cs, int dac_addr, int value,int imod ); int initDAC(int dac_cs, int dac_addr, int value,int imod );
int initDACs(int* v,int imod ); int initDACs(int* v,int imod );
int setSettings(int i); int setSettings(int i);
float initDACbyIndex(int ind,float val, int imod); dacs_t initDACbyIndex(int ind,dacs_t val, int imod);
float initDACbyIndexDACU(int ind,int val, int imod); dacs_t initDACbyIndexDACU(int ind,dacs_t val, int imod);
float getDACbyIndexDACU(int ind, int imod); dacs_t getDACbyIndexDACU(int ind, int imod);
int getThresholdEnergy(); int getThresholdEnergy();
int setThresholdEnergy(int ethr); int setThresholdEnergy(int ethr);
/* Initialization*/ /* Initialization*/

View File

@ -842,13 +842,13 @@ int read_register(int file_des) {
int set_dac(int file_des) { int set_dac(int file_des) {
float retval; dacs_t retval;
int ret=OK; int ret=OK;
int arg[2]; int arg[2];
enum dacIndex ind; enum dacIndex ind;
int imod; int imod;
int n; int n;
float val; dacs_t val;
int idac=0; int idac=0;
sprintf(mess,"Can't set DAC\n"); sprintf(mess,"Can't set DAC\n");
@ -954,7 +954,7 @@ add possible potentiometers like in chiptest board!!!!!!!!!!!!!!!
int get_adc(int file_des) { int get_adc(int file_des) {
float retval; dacs_t retval;
int ret=OK; int ret=OK;
int arg[2]; int arg[2];
enum dacIndex ind; enum dacIndex ind;
@ -1309,11 +1309,15 @@ int get_chip(int file_des) {
} }
int set_module(int file_des) { int set_module(int file_des) {
sls_detector_module myModule; sls_detector_module myModule;
int *myChip=malloc(NCHIP*sizeof(int)); int *myChip=malloc(NCHIP*sizeof(int));
int *myChan=malloc(NCHIP*NCHAN*sizeof(int)); int *myChan=malloc(NCHIP*NCHAN*sizeof(int));
float *myDac=malloc(NDAC*sizeof(int));
float *myAdc=malloc(NADC*sizeof(int)); dacs_t *myDac=malloc(NDAC*sizeof(dacs_t));
dacs_t *myAdc=malloc(NADC*sizeof(dacs_t));
int retval, n; int retval, n;
int ret=OK; int ret=OK;
int dr;//, ow; int dr;//, ow;
@ -1431,8 +1435,8 @@ int get_module(int file_des) {
sls_detector_module myModule; sls_detector_module myModule;
int *myChip=malloc(NCHIP*sizeof(int)); int *myChip=malloc(NCHIP*sizeof(int));
int *myChan=malloc(NCHIP*NCHAN*sizeof(int)); int *myChan=malloc(NCHIP*NCHAN*sizeof(int));
float *myDac=malloc(NDAC*sizeof(int)); dacs_t *myDac=malloc(NDAC*sizeof(dacs_t));
float *myAdc=malloc(NADC*sizeof(int)); dacs_t *myAdc=malloc(NADC*sizeof(dacs_t));
if (myDac) if (myDac)