diff --git a/slsDetectorSoftware/eigerDetectorServer/Makefile b/slsDetectorSoftware/eigerDetectorServer/Makefile deleted file mode 100644 index fd04ecadd..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -CC = powerpc-4xx-softfloat-g++ -CLAGS += -Wall -DDACS_INT -DSLS_DETECTOR_FUNCTION_LIST -DEIGERD #-DVIRTUAL -LDLIBS += -lm -lstdc++ - -PROGS = eigerDetectorServer -DESTDIR ?= bin -INSTMODE = 0777 - -SRC_CLNT = slsDetectorServer.cpp -SRC_CLNTC = slsDetectorServer_funcs.c communication_funcs.c slsDetector_firmware.c slsDetectorFunctionList.c -OBJS = $(SRC_CLNT:.cpp=.o) $(SRC_CLNTC:%.c=%.o) - - - -all: clean $(PROGS) - -boot: $(OBJS) - -$(PROGS): - echo $(OBJS) - mkdir -p $(DESTDIR) - $(CC) $(CLAGS) $(SRC_CLNT) $(SRC_CLNTC) $(LDLIBS) -o $@ - mv $(PROGS) $(DESTDIR) - - -clean: - rm -rf $(DESTDIR)/$(PROGS) *.o diff --git a/slsDetectorSoftware/eigerDetectorServer/communication_funcs.c b/slsDetectorSoftware/eigerDetectorServer/communication_funcs.c deleted file mode 100755 index 339021929..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/communication_funcs.c +++ /dev/null @@ -1,547 +0,0 @@ - - -#include "communication_funcs.h" -//#include -#include /* for TCP_NODELAY */ -#include -#include -#include -#include - -#include - - - -//int socketDescriptor, file_des; -const int send_rec_max_size=SEND_REC_MAX_SIZE; -extern int errno; - - -char dummyClientIP[INET_ADDRSTRLEN]; - - -fd_set readset, tempset; -int isock=0, maxfd; - - -int myport=-1; - -//struct sockaddr_in address; -//#define VERBOSE - - -int bindSocket(unsigned short int port_number) { - int i; - - struct sockaddr_in addressS; - int socketDescriptor; - //int file_des; - - //file_des= -1; - - - - - - - - - - - if (myport==port_number) - return -10; - - - - - - socketDescriptor = socket(AF_INET, SOCK_STREAM,0); //tcp - - //socketDescriptor = socket(PF_INET, SOCK_STREAM, 0); - - - - if (socketDescriptor < 0) { - printf("Can not create socket\n"); - } else { - - i = 1; - setsockopt(socketDescriptor, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i)); - // setsockopt(socketDescriptor, IPPROTO_TCP, TCP_NODELAY, (char *) &i, sizeof(i)); - // TCP_CORK - - // Set some fields in the serverAddress structure. - addressS.sin_family = AF_INET; - addressS.sin_addr.s_addr = htonl(INADDR_ANY); - addressS.sin_port = htons(port_number); - - // memset(&address.sin_addr, 0, sizeof(address.sin_addr)); - - - if(bind(socketDescriptor,(struct sockaddr *) &addressS,sizeof(addressS))<0){ - - printf("Can not create socket\n"); - - socketDescriptor=-1; - } else { - if (listen(socketDescriptor, 5)==0) { - - if (isock==0) { - FD_ZERO(&readset); - } - - - FD_SET(socketDescriptor, &readset); - isock++; - maxfd = socketDescriptor; - printf ("%d port %d fd %d\n",isock, port_number,socketDescriptor); - myport=port_number; - } else - printf("error on listen"); - } - } - - - - //int getrlimit(int resource, struct rlimit *rlim); - - - - return socketDescriptor; - -} - - - - - -int getServerError(int socketDescriptor) -{ - if (socketDescriptor<0) return 1; - else return 0; -}; - - -int acceptConnection(int socketDescriptor) { - - - int j; - - - struct sockaddr_in addressC; - int file_des=-1; - struct timeval tv; - int result; - - - //socklen_t address_length; - size_t address_length=sizeof(struct sockaddr_in); - - if (socketDescriptor<0) - return -1; - - memcpy(&tempset, &readset, sizeof(tempset)); - tv.tv_sec = 10000000; - tv.tv_usec = 0; - result = select(maxfd + 1, &tempset, NULL, NULL, &tv); - - if (result == 0) { - printf("select() timed out!\n"); - } else if (result < 0 && errno != EINTR) { - printf("Error in select(): %s\n", strerror(errno)); - } else if (result > 0) { -#ifdef VERBOSE - printf("select returned!\n"); -#endif - for (j=0; j=0) - close(file_des); - FD_CLR(file_des, &readset); -} - -void exitServer(int socketDescriptor) { - if (socketDescriptor>=0) - close(socketDescriptor); -#ifdef VERY_VERBOSE - printf("Closing server\n"); -#endif - FD_CLR(socketDescriptor, &readset); - socketDescriptor=-1; - isock--; -} - - - - - int sendDataOnly(int file_des, void* buf,int length) { - - - return write(file_des, buf, length); -} - - - int receiveDataOnly(int file_des, void* buf,int length) { - - int total_received=0; - int nreceiving; - int nreceived; - if (file_des<0) return -1; -#ifdef VERY_VERBOSE - printf("want to receive %d Bytes\n", length); -#endif - - while(length>0){ - nreceiving = (length>send_rec_max_size) ? send_rec_max_size:length; - -#ifdef VERY_VERBOSE - printf("want to receive %d Bytes\n", nreceiving); -#endif - nreceived = read(file_des,(char*)buf+total_received,nreceiving); -#ifdef VERY_VERBOSE - printf("read %d \n", nreceived); -#endif - if(!nreceived) break; - // if(nreceived<0) break; - length-=nreceived; - total_received+=nreceived; - // cout<<"nrec: "<0) - strcpy(thisClientIP,dummyClientIP); - - //if (strcmp(lastClientIP,"none")==0) - //strcpy(lastClientIP,thisClientIP); - - if (strcmp(lastClientIP,thisClientIP)) - differentClients=1; - else - differentClients=0; - - return total_received; -} - - - - - - - - - - - - - - - -int sendChannel(int file_des, sls_detector_channel *myChan) { - return sendDataOnly(file_des,myChan, sizeof(sls_detector_channel)); -} - -int sendChip(int file_des, sls_detector_chip *myChip) { - int ts=0; - int nChans=myChip->nchan; - ts+=sendDataOnly(file_des,myChip,sizeof(sls_detector_chip)); - ts+=sendDataOnly(file_des,myChip->chanregs,nChans*sizeof(int)); - return ts; -} - -int sendModule(int file_des, sls_detector_module *myMod) { - int ts=0; -#ifdef VERBOSE - int idac; -#endif - int nChips=myMod->nchip; - int nChans=myMod->nchan; - int nAdcs=myMod->nadc; - int nDacs=myMod->ndac; - ts+= sendDataOnly(file_des,myMod,sizeof(sls_detector_module)); -#ifdef VERBOSE - printf("module %d of size %d sent\n",myMod->module, ts); -#endif - ts+= sendDataOnly(file_des,myMod->dacs,sizeof(dacs_t)*nDacs); -#ifdef VERBOSE - printf("dacs %d of size %d sent\n",myMod->module, ts); - for (idac=0; idac< nDacs; idac++) - printf("dac %d is %d\n",idac,(int)myMod->dacs[idac]); -#endif - ts+= sendDataOnly(file_des,myMod->adcs,sizeof(dacs_t)*nAdcs); -#ifdef VERBOSE - printf("adcs %d of size %d sent\n",myMod->module, ts); -#endif - ts+=sendDataOnly(file_des,myMod->chipregs,sizeof(int)*nChips); -#ifdef VERBOSE - printf("chips %d of size %d sent\n",myMod->module, ts); -#endif - ts+=sendDataOnly(file_des,myMod->chanregs,sizeof(int)*nChans); -#ifdef VERBOSE - printf("chans %d of size %d sent - %d\n",myMod->module, ts, myMod->nchan); -#endif -#ifdef VERBOSE - printf("module %d of size %d sent register %x\n",myMod->module, ts, myMod->reg); -#endif - return ts; -} - -int receiveChannel(int file_des, sls_detector_channel *myChan) { - return receiveDataOnly(file_des,myChan,sizeof(sls_detector_channel)); -} - -int receiveChip(int file_des, sls_detector_chip* myChip) { - - int *ptr=myChip->chanregs; - int ts=0; - int nChans, nchanold=myChip->nchan, chdiff; - - ts+= receiveDataOnly(file_des,myChip,sizeof(sls_detector_chip)); - - - myChip->chanregs=ptr; - nChans=myChip->nchan; - chdiff=nChans-nchanold; - if (nchanold!=nChans) { - printf("wrong number of channels received!\n"); - } - - -#ifdef VERBOSE - printf("chip structure received\n"); - printf("now receiving %d channels\n", nChans); -#endif - - if (chdiff<=0) - ts+=receiveDataOnly(file_des,myChip->chanregs, sizeof(int)*nChans); - else { - ptr=(int *)malloc(chdiff*sizeof(int)); - myChip->nchan=nchanold; - ts+=receiveDataOnly(file_des,myChip->chanregs, sizeof(int)*nchanold); - ts+=receiveDataOnly(file_des,ptr, sizeof(int)*chdiff); - free(ptr); - return FAIL; - } - -#ifdef VERBOSE - printf("chip's channels received\n"); -#endif - return ts; -} - -int receiveModule(int file_des, sls_detector_module* myMod) { - - - dacs_t *dacptr=myMod->dacs; - dacs_t *adcptr=myMod->adcs; - int *chipptr=myMod->chipregs, *chanptr=myMod->chanregs; - int ts=0; - int nChips, nchipold=myMod->nchip, nchipdiff; - int nChans, nchanold=myMod->nchan, nchandiff; - int nDacs, ndold=myMod->ndac, ndacdiff; - int nAdcs, naold=myMod->nadc, nadcdiff; - // int id=0; - - ts+= receiveDataOnly(file_des,myMod,sizeof(sls_detector_module)); - - myMod->dacs=dacptr; - myMod->adcs=adcptr; - myMod->chipregs=chipptr; - myMod->chanregs=chanptr; - - nChips=myMod->nchip; - nchipdiff=nChips-nchipold; - if (nchipold!=nChips) { - printf("received wrong number of chips\n"); - } -#ifdef VERBOSE - else - printf("received %d chips\n",nChips); -#endif - - nChans=myMod->nchan; - nchandiff=nChans-nchanold; - if (nchanold!=nChans) { - printf("received wrong number of channels\n"); - } -#ifdef VERBOSE - else - printf("received %d chans\n",nChans); -#endif - - - nDacs=myMod->ndac; - ndacdiff=nDacs-ndold; - if (ndold!=nDacs) { - printf("received wrong number of dacs\n"); - } -#ifdef VERBOSE - else - printf("received %d dacs\n",nDacs); -#endif - - nAdcs=myMod->nadc; - nadcdiff=nAdcs-naold; - if (naold!=nAdcs) { - printf("received wrong number of adcs\n"); - } -#ifdef VERBOSE - else - printf("received %d adcs\n",nAdcs); -#endif - if (ndacdiff<=0) { - ts+=receiveDataOnly(file_des,myMod->dacs, sizeof(dacs_t)*nDacs); -#ifdef VERBOSE - printf("dacs received\n"); - for (id=0; iddacs[id]); - - -#endif - } else { - dacptr=(dacs_t *)malloc(ndacdiff*sizeof(dacs_t)); - myMod->ndac=ndold; - ts+=receiveDataOnly(file_des,myMod->dacs, sizeof(dacs_t)*ndold); - ts+=receiveDataOnly(file_des,dacptr, sizeof(dacs_t)*ndacdiff); - free(dacptr); - return FAIL; - } - - if (nadcdiff<=0) { - ts+=receiveDataOnly(file_des,myMod->adcs, sizeof(dacs_t)*nAdcs); -#ifdef VERBOSE - printf("adcs received\n"); -#endif - } else { - adcptr=(dacs_t *)malloc(nadcdiff*sizeof(dacs_t)); - myMod->nadc=naold; - ts+=receiveDataOnly(file_des,myMod->adcs, sizeof(dacs_t)*naold); - ts+=receiveDataOnly(file_des,adcptr, sizeof(dacs_t)*nadcdiff); - free(adcptr); - return FAIL; - } - - if (nchipdiff<=0) { - ts+=receiveDataOnly(file_des,myMod->chipregs, sizeof(int)*nChips); -#ifdef VERBOSE - printf("chips received\n"); -#endif - } else { - chipptr=(int *)malloc(nchipdiff*sizeof(int)); - myMod->nchip=nchipold; - ts+=receiveDataOnly(file_des,myMod->chipregs, sizeof(int)*nchipold); - ts+=receiveDataOnly(file_des,chipptr, sizeof(int)*nchipdiff); - free(chipptr); - return FAIL; - } - - if (nchandiff<=0) { - ts+=receiveDataOnly(file_des,myMod->chanregs, sizeof(int)*nChans); -#ifdef VERBOSE - printf("chans received\n"); -#endif - } else { - chanptr=(int *)malloc(nchandiff*sizeof(int)); - myMod->nchan=nchanold; - ts+=receiveDataOnly(file_des,myMod->chanregs, sizeof(int)*nchanold); - ts+=receiveDataOnly(file_des,chanptr, sizeof(int)*nchandiff); - free(chanptr); - return FAIL; - } -#ifdef VERBOSE - printf("received module %d of size %d register %x\n",myMod->module,ts,myMod->reg); -#endif - return ts; -} diff --git a/slsDetectorSoftware/eigerDetectorServer/communication_funcs.h b/slsDetectorSoftware/eigerDetectorServer/communication_funcs.h deleted file mode 100755 index 34e5b05b7..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/communication_funcs.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef COMMUNICATION_FUNCS_H -#define COMMUNICATION_FUNCS_H - -#define SEND_REC_MAX_SIZE 4096 -#define DEFAULT_PORTNO 1952 -#include -#include - - -#include -#include -#include -#include - -#include "sls_detector_defs.h" - -char lastClientIP[INET_ADDRSTRLEN]; -char thisClientIP[INET_ADDRSTRLEN]; -int lockStatus; -int differentClients; - -int bindSocket(unsigned short int port_number); -int acceptConnection(int socketDescriptor); -void closeConnection(int file_Des); -void exitServer(int socketDescriptor); -int sendDataOnly(int file_des, void* buf,int length); -int receiveDataOnly(int file_des, void* buf,int length); - -int getServerError(int socketDescriptor); -int sendChannel(int file_des, sls_detector_channel *myChan); -int sendChip(int file_des, sls_detector_chip *myChip); -int sendModule(int file_des, sls_detector_module *myMod); -int receiveChannel(int file_des, sls_detector_channel *myChan); -int receiveChip(int file_des, sls_detector_chip* myChip); -int receiveModule(int file_des, sls_detector_module* myMod); - -#endif diff --git a/slsDetectorSoftware/eigerDetectorServer/registers.h b/slsDetectorSoftware/eigerDetectorServer/registers.h deleted file mode 100644 index a54f10b42..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/registers.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * registers.h - * - * Created on: Jan 24, 2013 - * Author: l_maliakal_d - */ - -#ifndef REGISTERS_H_ -#define REGISTERS_H_ - -#include "sls_detector_defs.h" - -#define CSP0 0xC4100000 //XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_LEFT_BASEADDR -#define MEM_SIZE 0xFFFFFFF - - - -#define FIFO_CNTRL_REG 0x0 //PLB_LL_FIFO_REG_CTRL -#define FIFO_STATUS_REG 0x1 //PLB_LL_FIFO_REG_STATUS -#define FIFO_FIFO_REG 0x2 //PLB_LL_FIFO_REG_FIFO - - -#define FIFO_THRESHOLD_WORDS 100 //PLB_LL_FIFO_ALMOST_FULL_THRESHOLD_WORDS - - - -/*Fifo Control Register*/ -#define FIFOCNTRL_RESET_MASK 0x0CE00000 //PLB_LL_FIFO_CTRL_RESET_STD - - -/*Fifo Status Register*/ -#define FIFOSTATUS_SOF_BIT 0x10000000 //PLB_LL_FIFO_STATUS_LL_SOF -#define FIFOSTATUS_EOF_BIT 0x20000000 //PLB_LL_FIFO_STATUS_LL_EOF -#define FIFOSTATUS_REM_OFFSET 30 //PLB_LL_FIFO_STATUS_LL_REM_SHIFT -#define FIFOSTATUS_REM_MASK 0xC0000000 //PLB_LL_FIFO_STATUS_LL_REM - -#define FIFOSTATUS_EMPTY_BIT 0x08000000 //PLB_LL_FIFO_STATUS_EMPTY -#define FIFOSTATUS_ALMOST_FULL_BIT 0x01000000 //PLB_LL_FIFO_STATUS_ALMOSTFULL - - -/*Fifo Fifo Register*/ -#define FIFOCNTRL_SOF_BIT 0x10000000 //PLB_LL_FIFO_CTRL_LL_SOF -#define FIFOCNTRL_EOF_BIT 0x20000000 //PLB_LL_FIFO_CTRL_LL_EOF -#define FIFOCNTRL_REM_OFFSET 30 //PLB_LL_FIFO_CTRL_LL_REM_SHIFT -#define FIFOCNTRL_REM_MASK 0xC0000000 //PLB_LL_FIFO_CTRL_LL_REM -#define FIFOCNTRL_MASK 0xF0000000 //PLB_LL_FIFO_CTRL_LL_MASK - - - - -#define SET_FRAMES_LSB_REG 0x1 -#define SET_FRAMES_MSB_REG 0x1 -#define GET_FRAMES_LSB_REG 0x1 -#define GET_FRAMES_MSB_REG 0x1 - -#define SET_EXPTIME_LSB_REG 0x1 -#define SET_EXPTIME_MSB_REG 0x1 -#define GET_EXPTIME_LSB_REG 0x1 -#define GET_EXPTIME_MSB_REG 0x1 - -#define SET_GATES_LSB_REG 0x1 -#define SET_GATES_MSB_REG 0x1 -#define GET_GATES_LSB_REG 0x1 -#define GET_GATES_MSB_REG 0x1 - -#define SET_PERIOD_LSB_REG 0x1 -#define SET_PERIOD_MSB_REG 0x1 -#define GET_PERIOD_LSB_REG 0x1 -#define GET_PERIOD_MSB_REG 0x1 - -#define SET_DELAY_LSB_REG 0x1 -#define SET_DELAY_MSB_REG 0x1 -#define GET_DELAY_LSB_REG 0x1 -#define GET_DELAY_MSB_REG 0x1 - -#define SET_TRAINS_LSB_REG 0x1 -#define SET_TRAINS_MSB_REG 0x1 -#define GET_TRAINS_LSB_REG 0x1 -#define GET_TRAINS_MSB_REG 0x1 - - - - - -#endif /* REGISTERS_H_ */ diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c deleted file mode 100644 index 75fb8948f..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c +++ /dev/null @@ -1,802 +0,0 @@ -#ifdef SLS_DETECTOR_FUNCTION_LIST - -#include "slsDetectorFunctionList.h" -#include "slsDetectorServer_defs.h" - -#include -#include - - - - -extern int nModX; -extern int nModBoard; -extern int dataBytes; -extern int dynamicRange; -const int nChans=NCHAN; -const int nChips=NCHIP; -const int nDacs=NDAC; -const int nAdcs=NADC; -enum detectorSettings thisSettings; - -int sChan, sChip, sMod, sDac, sAdc; -const int allSelected=-2; -const int noneSelected=-1; - - -sls_detector_module *detectorModules=NULL; -int *detectorChips=NULL; -int *detectorChans=NULL; -dacs_t *detectorDacs=NULL; -dacs_t *detectorAdcs=NULL; - - -int initializeDetector(){ - - int imod; - - int n=getNModBoard(X)*getNModBoard(Y); - /*nModX=n;*/ - -#ifdef VERBOSE - printf("Board is for %d modules\n",n); -#endif - detectorModules=(sls_detector_module *)malloc(n*sizeof(sls_detector_module)); - detectorChips=(int *)malloc(n*NCHIP*sizeof(int)); - detectorChans=(int *)malloc(n*NCHIP*NCHAN*sizeof(int)); - detectorDacs=(dacs_t *)malloc(n*NDAC*sizeof(int)); - detectorAdcs=(dacs_t *)malloc(n*NADC*sizeof(int)); -#ifdef VERBOSE - printf("modules from 0x%x to 0x%x\n",(unsigned int)(detectorModules), (unsigned int)(detectorModules+n)); - printf("chips from 0x%x to 0x%x\n",(unsigned int)(detectorChips), (unsigned int)(detectorChips+n*NCHIP)); - printf("chans from 0x%x to 0x%x\n",(unsigned int)(detectorChans), (unsigned int)(detectorChans+n*NCHIP*NCHAN)); - printf("dacs from 0x%x to 0x%x\n",(unsigned int)(detectorDacs), (unsigned int)(detectorDacs+n*NDAC)); - printf("adcs from 0x%x to 0x%x\n",(unsigned int)(detectorAdcs), (unsigned int)(detectorAdcs+n*NADC)); -#endif - for (imod=0; imoddacs=detectorDacs+imod*NDAC; - (detectorModules+imod)->adcs=detectorAdcs+imod*NADC; - (detectorModules+imod)->chipregs=detectorChips+imod*NCHIP; - (detectorModules+imod)->chanregs=detectorChans+imod*NCHIP*NCHAN; - (detectorModules+imod)->ndac=NDAC; - (detectorModules+imod)->nadc=NADC; - (detectorModules+imod)->nchip=NCHIP; - (detectorModules+imod)->nchan=NCHIP*NCHAN; - (detectorModules+imod)->module=imod; - (detectorModules+imod)->gain=0; - (detectorModules+imod)->offset=0; - (detectorModules+imod)->reg=0; - /* initialize registers, dacs, retrieve sn, adc values etc */ - } - thisSettings=UNINITIALIZED; - sChan=noneSelected; - sChip=noneSelected; - sMod=noneSelected; - sDac=noneSelected; - sAdc=noneSelected; - - return OK; -} - - - -int setNMod(int nm, enum dimension dim){ - return 1; -} - - - -int getNModBoard(enum dimension arg){ - return 1; -} - - - - - - - - -int64_t getModuleId(enum idMode arg, int imod){ - //DETECTOR_SERIAL_NUMBER - //DETECTOR_FIRMWARE_VERSION - return 0; -} - - - - -int64_t getDetectorId(enum idMode arg){ - //DETECTOR_SOFTWARE_VERSION defined in slsDetector_defs.h? - return 0; -} - - - - - -int moduleTest( enum digitalTestMode arg, int imod){ - //template testShiftIn from mcb_funcs.c - - //CHIP_TEST - //testShiftIn - //testShiftOut - //testShiftStSel - //testDataInOutMux - //testExtPulseMux - //testOutMux - //testFpgaMux - - return OK; -} - - - - - -int detectorTest( enum digitalTestMode arg){ - //templates from firmware_funcs.c - - //DETECTOR_FIRMWARE_TEST:testFpga() - //DETECTOR_MEMORY_TEST:testRAM() - //DETECTOR_BUS_TEST:testBus() - //DETECTOR_SOFTWARE_TEST:testFpga() - return OK; -} - - - - - - -double setDAC(enum dacIndex ind, double val, int imod){ - //template initDACbyIndexDACU from mcb_funcs.c - - //check that slsDetectorServer_funcs.c set_dac() has all the specific dac enums - //set dac and write to a register in fpga to remember dac value when server restarts - return 0; -} - - - -double getADC(enum dacIndex ind, int imod){ - //get adc value - return 0; -} - - - - -int setChannel(sls_detector_channel myChan){ - //template initChannelByNumber() from mcb_funcs.c - - return myChan.reg; -} - - -int getChannel(sls_detector_channel *myChan){ - //template getChannelbyNumber() from mcb_funcs.c - return FAIL; -} - - - -int setChip(sls_detector_chip myChip){ - //template initChipbyNumber() from mcb_funcs.c - return myChip.reg; -} - - -int getChip(sls_detector_chip *myChip){ - //template getChipbyNumber() from mcb_funcs.c - return FAIL; -} - -int setModule(sls_detector_module myChan){ - //template initModulebyNumber() from mcb_funcs.c - return OK; -} - -int getModule(sls_detector_module *myChan){ - //template getModulebyNumber() from mcb_funcs.c - return FAIL; -} - -int getThresholdEnergy(int imod){ - //template getThresholdEnergy() from mcb_funcs.c - //depending on settings - return FAIL; -} - - -int setThresholdEnergy(int thr, int imod){ - //template getThresholdEnergy() from mcb_funcs.c - //depending on settings - return FAIL; -} - - - -enum detectorSettings setSettings(enum detectorSettings sett, int imod){ - //template setSettings() from mcb_funcs.c - //reads the dac registers from fpga to confirm which settings, if weird, undefined - - return GET_SETTINGS; -} - -int startStateMachine(){ - //template startStateMachine() from firmware_funcs.c - /* - fifoReset(); - now_ptr=(char*)ram_values; - //send start acquisition to fpga - */ - return FAIL; -} - - -int stopStateMachine(){ - //template stopStateMachine() from firmware_funcs.c - // send stop to fpga - //if status = busy after 500us, return FAIL - return FAIL; -} - - -int startReadOut(){ - //template startReadOut() from firmware_funcs.c - //send fpga start readout - return FAIL; -} - - -enum runStatus getRunStatus(){ - //template runState() from firmware_funcs.c - //get status from fpga - return ERROR; -} - - -char *readFrame(int *ret, char *mess){ - //template fifo_read_event() from firmware_funcs.c - //checks if state machine running and if fifo has data(look_at_me_reg) and accordingly reads frame - // memcpy(now_ptr, values, dataBytes); - //returns ptr to values - return NULL; -} - - -int64_t setTimer(enum timerIndex ind, int64_t val){ - //template setDelay() from firmware_funcs.c - //writes to reg - //FRAME_NUMBER - //ACQUISITION_TIME - //FRAME_PERIOD - //DELAY_AFTER_TRIGGER - //GATES_NUMBER - //PROBES_NUMBER - //CYCLES_NUMBER - return 0; -} - - -int64_t getTimeLeft(enum timerIndex ind){ - //template getDelay() from firmware_funcs.c - //reads from reg - //FRAME_NUMBER - //ACQUISITION_TIME - //FRAME_PERIOD - //DELAY_AFTER_TRIGGER - //GATES_NUMBER - //PROBES_NUMBER - //CYCLES_NUMBER - return -1; -} - - -int setDynamicRange(int dr){ - //template setDynamicRange() from firmware_funcs.c - return 0; -} - -int setROI(int mask){ //////????????????????? - return FAIL; -} - - -int getROI(int *mask){ //////////????????????????????? - return FAIL; -} - - -int setSpeed(enum speedVariable arg, int val){ - //template setClockDivider() from firmware_funcs.c - //CLOCK_DIVIDER - //WAIT_STATES - //SET_SIGNAL_LENGTH - //TOT_CLOCK_DIVIDER - //TOT_DUTY_CYCLE - - //returns eg getClockDivider from firmware_funcs.c - return 0; -} - - -enum readOutFlags setReadOutFlags(enum readOutFlags val){ - //template setStoreInRAM from firmware_funcs.c - return GET_READOUT_FLAGS; -} - - -int executeTrimming(enum trimMode mode, int par1, int par2, int imod){ - // template trim_with_noise from trimming_funcs.c - return FAIL; -} - - - - -int configureMAC(int ipad, long long int imacadd, long long int iservermacadd, int dtb){ - //detector specific. - return FAIL; -} - - -int loadImage(enum imageType index, char *imageVals){ - //detector specific. - return FAIL; -} - - -int readCounterBlock(int startACQ, char *counterVals){ - //detector specific. - return FAIL; -} - -int resetCounterBlock(int startACQ){ - //detector specific. - return FAIL; -} - -int calculateDataBytes(){ - return 0; -} - -int getTotalNumberOfChannels(){return 0;} -int getTotalNumberOfChips(){return 0;} -int getTotalNumberOfModules(){return 0;} -int getNumberOfChannelsPerChip(){return 0;} -int getNumberOfChannelsPerModule(){return 0;} -int getNumberOfChipsPerModule(){return 0;} -int getNumberOfDACsPerModule(){return 0;} -int getNumberOfADCsPerModule(){return 0;} - - - - - - - -enum externalSignalFlag getExtSignal(int signalindex){ - //template getExtSignal from firmware_funcs.c - //return signals[signalindex]; - return GET_EXTERNAL_SIGNAL_FLAG; -} - - - - - -enum externalSignalFlag setExtSignal(int signalindex, enum externalSignalFlag flag){ - //template setExtSignal from firmware_funcs.c - - //in short..sets signals array, checks if agrees with timing mode, writes to fpga reg, calls synchronization and then settiming - /* - if (signalindex>=0 && signalindex<4) { - signals[signalindex]=flag; -#ifdef VERBOSE - printf("settings signal variable number %d to value %04x\n", signalindex, signals[signalindex]); -#endif - // if output signal, set it! - switch (flag) { - case GATE_IN_ACTIVE_HIGH: - case GATE_IN_ACTIVE_LOW: - if (timingMode==GATE_FIX_NUMBER || timingMode==GATE_WITH_START_TRIGGER)//timingMode = AUTO_TIMING by default and is set in setTiming() - setFPGASignal(signalindex,flag); //not implemented here, checks if flag within limits and writes to fpga reg - else - setFPGASignal(signalindex,SIGNAL_OFF); - break; - case TRIGGER_IN_RISING_EDGE: - case TRIGGER_IN_FALLING_EDGE: - if (timingMode==TRIGGER_EXPOSURE || timingMode==GATE_WITH_START_TRIGGER) - setFPGASignal(signalindex,flag); - else - setFPGASignal(signalindex,SIGNAL_OFF); - break; - case RO_TRIGGER_IN_RISING_EDGE: - case RO_TRIGGER_IN_FALLING_EDGE: - if (timingMode==TRIGGER_READOUT) - setFPGASignal(signalindex,flag); - else - setFPGASignal(signalindex,SIGNAL_OFF); - break; - case MASTER_SLAVE_SYNCHRONIZATION: - setSynchronization(syncMode);//syncmode = NO_SYNCHRONIZATION by default and set with this function - break; - default: - setFPGASignal(signalindex,mode); - } - - setTiming(GET_EXTERNAL_COMMUNICATION_MODE); - } - */ - return getExtSignal(signalindex); -} - - - - - - -enum externalCommunicationMode setTiming( enum externalCommunicationMode arg){ - //template setTiming from firmware_funcs.c - //template getFPGASignal from firmware_funcs.c - - - //getFPGASignal(signalindex) used later on in this fucntion - //gets flag from fpga reg, checks if flag within limits, - //if( flag=SIGNAL_OFF and signals[signalindex]==MASTER_SLAVE_SYNCHRONIZATION), return -1, (ensures masterslaveflag !=off now) - //else return flag - - //int ret=(externalCommunicationMode)GET_EXTERNAL_COMMUNICATION_MODE; - //sets timingmode variable - //ensures that the signals are in acceptance with timing mode and according sets the timing mode - /* - int g=-1, t=-1, rot=-1; - - int i; - - switch (ti) { - case AUTO_TIMING: - timingMode=ti; - // disable all gates/triggers in except if used for master/slave synchronization - for (i=0; i<4; i++) { - if (getFPGASignal(i)>0 && getFPGASignal(i)=0 && t>=0 && rot<0) { - ret=GATE_WITH_START_TRIGGER; - } else if (g<0 && t>=0 && rot<0) { - ret=TRIGGER_EXPOSURE; - } else if (g>=0 && t<0 && rot<0) { - ret=GATE_FIX_NUMBER; - } else if (g<0 && t<0 && rot>0) { - ret=TRIGGER_READOUT; - } else if (g<0 && t<0 && rot<0) { - ret=AUTO_TIMING; - } - - */ - return GET_EXTERNAL_COMMUNICATION_MODE; -} - - - -enum masterFlags setMaster(enum masterFlags arg){ - //template setMaster from firmware_funcs.c - /* - int i; - switch(f) { - case NO_MASTER: - // switch of gates or triggers - masterMode=NO_MASTER; - for (i=0; i<4; i++) { - if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) { - setFPGASignal(i,SIGNAL_OFF); - } - } - break; - case IS_MASTER: - // configure gate or trigger out - masterMode=IS_MASTER; - for (i=0; i<4; i++) { - if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) { - switch (syncMode) { - case NO_SYNCHRONIZATION: - setFPGASignal(i,SIGNAL_OFF); - break; - case MASTER_GATES: - setFPGASignal(i,GATE_OUT_ACTIVE_HIGH); - break; - case MASTER_TRIGGERS: - setFPGASignal(i,TRIGGER_OUT_RISING_EDGE); - break; - case SLAVE_STARTS_WHEN_MASTER_STOPS: - setFPGASignal(i,RO_TRIGGER_OUT_RISING_EDGE); - break; - default: - ; - } - } - } - break; - case IS_SLAVE: - // configure gate or trigger in - masterMode=IS_SLAVE; - for (i=0; i<4; i++) { - if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) { - switch (syncMode) { - case NO_SYNCHRONIZATION: - setFPGASignal(i,SIGNAL_OFF); - break; - case MASTER_GATES: - setFPGASignal(i,GATE_IN_ACTIVE_HIGH); - break; - case MASTER_TRIGGERS: - setFPGASignal(i,TRIGGER_IN_RISING_EDGE); - break; - case SLAVE_STARTS_WHEN_MASTER_STOPS: - setFPGASignal(i,TRIGGER_IN_RISING_EDGE); - break; - default: - ; - } - } - } - break; - default: - //do nothing - ; - } - - switch(masterMode) { - case NO_MASTER: - return NO_MASTER; - - - case IS_MASTER: - for (i=0; i<4; i++) { - if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) { - switch (syncMode) { - case NO_SYNCHRONIZATION: - return IS_MASTER; - case MASTER_GATES: - if (getFPGASignal(i)==GATE_OUT_ACTIVE_HIGH) - return IS_MASTER; - else - return NO_MASTER; - case MASTER_TRIGGERS: - if (getFPGASignal(i)==TRIGGER_OUT_RISING_EDGE) - return IS_MASTER; - else - return NO_MASTER; - case SLAVE_STARTS_WHEN_MASTER_STOPS: - if (getFPGASignal(i)==RO_TRIGGER_OUT_RISING_EDGE) - return IS_MASTER; - else - return NO_MASTER; - default: - return NO_MASTER; - } - - } - } - - case IS_SLAVE: - for (i=0; i<4; i++) { - if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) { - switch (syncMode) { - case NO_SYNCHRONIZATION: - return IS_SLAVE; - case MASTER_GATES: - if (getFPGASignal(i)==GATE_IN_ACTIVE_HIGH) - return IS_SLAVE; - else - return NO_MASTER; - case MASTER_TRIGGERS: - case SLAVE_STARTS_WHEN_MASTER_STOPS: - if (getFPGASignal(i)==TRIGGER_IN_RISING_EDGE) - return IS_SLAVE; - else - return NO_MASTER; - default: - return NO_MASTER; - } - - } - } - - } - */ - - return NO_MASTER; -} - - - -enum synchronizationMode setSynchronization(enum synchronizationMode arg){ - /* - int i; - - switch(s) { - case NO_SYNCHRONIZATION: - syncMode=NO_SYNCHRONIZATION; - for (i=0; i<4; i++) { - if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) { - setFPGASignal(i,SIGNAL_OFF); - } - } - break; - // disable external signals? - case MASTER_GATES: - // configure gate in or out - syncMode=MASTER_GATES; - for (i=0; i<4; i++) { - if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) { - if (masterMode==IS_MASTER) - setFPGASignal(i,GATE_OUT_ACTIVE_HIGH); - else if (masterMode==IS_SLAVE) - setFPGASignal(i,GATE_IN_ACTIVE_HIGH); - } - } - - break; - case MASTER_TRIGGERS: - // configure trigger in or out - syncMode=MASTER_TRIGGERS; - for (i=0; i<4; i++) { - if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) { - if (masterMode==IS_MASTER) - setFPGASignal(i,TRIGGER_OUT_RISING_EDGE); - else if (masterMode==IS_SLAVE) - setFPGASignal(i,TRIGGER_IN_RISING_EDGE); - } - } - break; - - - case SLAVE_STARTS_WHEN_MASTER_STOPS: - // configure trigger in or out - syncMode=SLAVE_STARTS_WHEN_MASTER_STOPS; - for (i=0; i<4; i++) { - if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) { - if (masterMode==IS_MASTER) - setFPGASignal(i,RO_TRIGGER_OUT_RISING_EDGE); - else if (masterMode==IS_SLAVE) - setFPGASignal(i,TRIGGER_IN_RISING_EDGE); - } - } - break; - - - default: - //do nothing - ; - } - - switch (syncMode) { - - case NO_SYNCHRONIZATION: - return NO_SYNCHRONIZATION; - - case MASTER_GATES: - - for (i=0; i<4; i++) { - if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) { - if (masterMode==IS_MASTER && getFPGASignal(i)==GATE_OUT_ACTIVE_HIGH) - return MASTER_GATES; - else if (masterMode==IS_SLAVE && getFPGASignal(i)==GATE_IN_ACTIVE_HIGH) - return MASTER_GATES; - } - } - return NO_SYNCHRONIZATION; - - case MASTER_TRIGGERS: - for (i=0; i<4; i++) { - if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) { - if (masterMode==IS_MASTER && getFPGASignal(i)==TRIGGER_OUT_RISING_EDGE) - return MASTER_TRIGGERS; - else if (masterMode==IS_SLAVE && getFPGASignal(i)==TRIGGER_IN_RISING_EDGE) - return MASTER_TRIGGERS; - } - } - return NO_SYNCHRONIZATION; - - case SLAVE_STARTS_WHEN_MASTER_STOPS: - for (i=0; i<4; i++) { - if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) { - if (masterMode==IS_MASTER && getFPGASignal(i)==RO_TRIGGER_OUT_RISING_EDGE) - return SLAVE_STARTS_WHEN_MASTER_STOPS; - else if (masterMode==IS_SLAVE && getFPGASignal(i)==TRIGGER_IN_RISING_EDGE) - return SLAVE_STARTS_WHEN_MASTER_STOPS; - } - } - return NO_SYNCHRONIZATION; - - default: - return NO_SYNCHRONIZATION; - - } - - - */ - return NO_SYNCHRONIZATION; -} - - - -#endif diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.h b/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.h deleted file mode 100644 index 0da50207f..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.h +++ /dev/null @@ -1,106 +0,0 @@ -#ifdef SLS_DETECTOR_FUNCTION_LIST - -#ifndef SLS_DETECTOR_FUNCTION_LIST_H -#define SLS_DETECTOR_FUNCTION_LIST_H - -#include "sls_detector_defs.h" - -#include - - -/* -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -*/ - -/**************************************************** -This functions are used by the slsDetectroServer_funcs interface. -Here are the definitions, but the actual implementation should be done for each single detector. - -****************************************************/ - - - -int initializeDetector(); - - - -int setNMod(int nm, enum dimension dim); -int getNModBoard(enum dimension arg); - -int64_t getModuleId(enum idMode arg, int imod); -int64_t getDetectorId(enum idMode arg); -int moduleTest( enum digitalTestMode arg, int imod); -int detectorTest( enum digitalTestMode arg); - - -double setDAC(enum dacIndex ind, double val, int imod); -double getADC(enum dacIndex ind, int imod); -int setChannel(sls_detector_channel myChan); -int getChannel(sls_detector_channel *myChan); -int setChip(sls_detector_chip myChip); -int getChip(sls_detector_chip *myChip); -int setModule(sls_detector_module myChan); -int getModule(sls_detector_module *myChan); -int getThresholdEnergy(int imod); -int setThresholdEnergy(int thr, int imod); -enum detectorSettings setSettings(enum detectorSettings sett, int imod); - - -int startStateMachine(); -int stopStateMachine(); -int startReadOut(); -enum runStatus getRunStatus(); -char *readFrame(int *ret, char *mess); -int64_t setTimer(enum timerIndex ind, int64_t val); -int64_t getTimeLeft(enum timerIndex ind); -int setDynamicRange(int dr); - - -int setROI(int mask); //////????????????????? -int getROI(int *mask); //////////????????????????????? -int setSpeed(enum speedVariable arg, int val); -enum readOutFlags setReadOutFlags(enum readOutFlags val); -int executeTrimming(enum trimMode mode, int par1, int par2, int imod); - - - -int configureMAC(int ipad, long long int imacadd, long long int iservermacadd, int dtb); -int loadImage(enum imageType index, char *imageVals); -int readCounterBlock(int startACQ, char *counterVals); -int resetCounterBlock(int startACQ); - -int calculateDataBytes(); - -int getTotalNumberOfChannels(); -int getTotalNumberOfChips(); -int getTotalNumberOfModules(); -int getNumberOfChannelsPerChip(); -int getNumberOfChannelsPerModule(); -int getNumberOfChipsPerModule(); -int getNumberOfDACsPerModule(); -int getNumberOfADCsPerModule(); - - -enum externalSignalFlag getExtSignal(int signalindex); -enum externalSignalFlag setExtSignal(int signalindex, enum externalSignalFlag flag); -enum externalCommunicationMode setTiming( enum externalCommunicationMode arg); -enum masterFlags setMaster(enum masterFlags arg); -enum synchronizationMode setSynchronization(enum synchronizationMode arg); - - -#endif - -#endif diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer.c b/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer.c deleted file mode 100755 index c488db801..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer.c +++ /dev/null @@ -1,96 +0,0 @@ -/* A simple server in the internet domain using TCP - The port number is passed as an argument */ - -#include "sls_detector_defs.h" -#include "communication_funcs.h" -#include "slsDetectorServer_funcs.h" -#include "slsDetectorServer_defs.h" - -#include -#include - - -extern int sockfd; - - -void error(char *msg) -{ - perror(msg); -} - -int main(int argc, char *argv[]) -{ - int portno, b; - char cmd[100]; - int retval=OK; - int sd, fd; - - - if (argc==1) { - portno = DEFAULT_PORTNO; - sprintf(cmd,"%s %d &",argv[0],DEFAULT_PORTNO+1); - printf("opening control server on port %d\n",portno ); - /* system(cmd);*/ - b=1; - } else { - portno = DEFAULT_PORTNO+1; - if ( sscanf(argv[1],"%d",&portno) ==0) { - printf("could not open stop server: unknown port\n"); - return 1; - } - b=0; - printf("opening stop server on port %d\n",portno); - } - - - - init_detector(b); //defined in slsDetectorServer_funcs - - - sd=bindSocket(portno); //defined in communication_funcs - - sockfd=sd; - - - if (getServerError(sd)) { //defined in communication_funcs - printf("server error!\n"); - return -1; - } - - /* assign function table */ - function_table(); //defined in slsDetectorServer_funcs -#ifdef VERBOSE - printf("function table assigned \n"); -#endif - - - /* waits for connection */ - while(retval!=GOODBYE) { -#ifdef VERBOSE - printf("\n"); -#endif -#ifdef VERY_VERBOSE - printf("Waiting for client call\n"); -#endif - fd=acceptConnection(sockfd); //defined in communication_funcs -#ifdef VERY_VERBOSE - printf("Conenction accepted\n"); -#endif - if (fd>0) { - retval=decode_function(fd); //defined in slsDetectorServer_funcs -#ifdef VERY_VERBOSE - printf("function executed\n"); -#endif - closeConnection(fd); //defined in communication_funcs -#ifdef VERY_VERBOSE - printf("connection closed\n"); -#endif - } - } - - exitServer(sockfd); //defined in communication_funcs - printf("Goodbye!\n"); - - return 0; -} - diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h b/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h deleted file mode 100644 index f1fb51e5f..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * slsDetectorServer_defs.h - * - * Created on: Jan 24, 2013 - * Author: l_maliakal_d - */ - -#ifndef SLSDETECTORSERVER_DEFS_H_ -#define SLSDETECTORSERVER_DEFS_H_ - -#include "sls_detector_defs.h" -#include - -#define GOODBYE -200 - - -#define NCHAN 1 -#define NCHIP 1 -#define NDAC 1 -#define NADC 1 -#define NMAXMODX 1 -#define NMAXMODY 1 -#define NMAXMOD NMAXMODX*NMAXMODY -#define NCHANS NCHAN*NCHIP*NMAXMOD -#define NDACS NDAC*NMAXMOD - -#define DYNAMIC_RANGE 16 - -#define CLK_FREQ 100E+6 - -#endif /* SLSDETECTORSERVER_DEFS_H_ */ diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_funcs.c b/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_funcs.c deleted file mode 100755 index 221dcb7ab..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_funcs.c +++ /dev/null @@ -1,2848 +0,0 @@ - -#include "slsDetectorServer_funcs.h" -#include "slsDetectorFunctionList.h" -#include "slsDetector_firmware.h" -#include "slsDetectorServer_defs.h" -#include "communication_funcs.h" - - -#include -#include - - - - - -// Global variables - -int (*flist[256])(int); - - -//defined in the detector specific file -#ifdef MYTHEND -const enum detectorType myDetectorType=MYTHEN; -#elif GOTTHARDD -const enum detectorType myDetectorType=GOTTHARD; -#elif EIGERD -const enum detectorType myDetectorType=EIGER; -#elif PICASSOD -const enum detectorType myDetectorType=PICASSO; -#else -const enum detectorType myDetectorType=GENERIC; -#endif - - -//define in communication_funcs -/* -extern int lockStatus; -extern char lastClientIP[INET_ADDRSTRLEN]; -extern char thisClientIP[INET_ADDRSTRLEN]; -extern int differentClients; -*/ - - -/* global variables for optimized readout */ -char *dataretval=NULL; -int dataret; -char mess[1000]; -int dataBytes; - - - - -int init_detector(int b) { -#ifdef VIRTUAL - printf("This is a VIRTUAL detector\n"); -#else - mapCSP0(); - //only for control server - if(b){ - printf("\ninitializing detector\n"); -#endif -#ifdef SLS_DETECTOR_FUNCTION_LIST - initializeDetector(); - - - fifoReset(); - fifoTest(); - - //testFpga(); - //testRAM(); - //setSettings(GET_SETTINGS,-1); - //Initialization - //setFrames(1); - //setTrains(1); - //setExposureTime(1e6); - //setPeriod(1e9); - //setDelay(0); - //setGates(0); - //setTiming(GET_EXTERNAL_COMMUNICATION_MODE); - //setMaster(GET_MASTER); - //setSynchronization(GET_SYNCHRONIZATION_MODE); -#endif - } - strcpy(mess,"dummy message"); - strcpy(lastClientIP,"none"); - strcpy(thisClientIP,"none1"); - lockStatus=0; - return OK; -} - -int swap_int32(int val) -{ - val = ((val << 8) & 0xFF00FF00) | ((val >> 8) & 0xFF00FF ); - return (val << 16) | ((val >> 16) & 0xFFFF); -} - - -int64_t swap_int64(int64_t val) -{ - val = ((val << 8) & 0xFF00FF00FF00FF00ULL ) | ((val >> 8) & 0x00FF00FF00FF00FFULL ); - val = ((val << 16) & 0xFFFF0000FFFF0000ULL ) | ((val >> 16) & 0x0000FFFF0000FFFFULL ); - return (val << 32) | ((val >> 32) & 0xFFFFFFFFULL); -} - -int decode_function(int file_des) { - int fnum,n; - int retval=FAIL; -#ifdef VERBOSE - printf( "receive data\n"); -#endif - n = receiveDataOnly(file_des,&fnum,sizeof(fnum)); - fnum=swap_int32(fnum); - if (n <= 0) { -#ifdef VERBOSE - printf("ERROR reading from socket %d, %x %d\n", n, fnum, file_des); -#endif - return FAIL; - } -#ifdef VERBOSE - else - printf("size of data received %d\n",n); -#endif -//#ifdef VERBOSE - printf( "calling function fnum = %d %x\n",fnum,(unsigned int)flist[fnum]); -//#endif - if (fnum<0 || fnum>255) - fnum=255; - retval=(*flist[fnum])(file_des); - if (retval==FAIL) - printf( "Error executing the function = %d \n",fnum); - return retval; -} - - -int function_table() { - int i; - for (i=0;i<256;i++){ - flist[i]=&M_nofunc; - } - flist[F_EXIT_SERVER]=&exit_server; - flist[F_EXEC_COMMAND]=&exec_command; - flist[F_GET_DETECTOR_TYPE]=&get_detector_type; - flist[F_SET_NUMBER_OF_MODULES]=&set_number_of_modules; - flist[F_GET_MAX_NUMBER_OF_MODULES]=&get_max_number_of_modules; - flist[F_SET_EXTERNAL_SIGNAL_FLAG]=&set_external_signal_flag; - flist[F_SET_EXTERNAL_COMMUNICATION_MODE]=&set_external_communication_mode; - flist[F_GET_ID]=&get_id; - flist[F_DIGITAL_TEST]=&digital_test; - flist[F_WRITE_REGISTER]=&write_register; - flist[F_READ_REGISTER]=&read_register; - flist[F_SET_DAC]=&set_dac; - flist[F_GET_ADC]=&get_adc; - flist[F_SET_CHANNEL]=&set_channel; - flist[F_SET_CHIP]=&set_chip; - flist[F_SET_MODULE]=&set_module; - flist[F_GET_CHANNEL]=&get_channel; - flist[F_GET_CHIP]=&get_chip; - flist[F_GET_MODULE]=&get_module; - flist[F_GET_THRESHOLD_ENERGY]=&get_threshold_energy; - flist[F_SET_THRESHOLD_ENERGY]=&set_threshold_energy; - flist[F_SET_SETTINGS]=&set_settings; - flist[F_START_ACQUISITION]=&start_acquisition; - flist[F_STOP_ACQUISITION]=&stop_acquisition; - flist[F_START_READOUT]=&start_readout; - flist[F_GET_RUN_STATUS]=&get_run_status; - flist[F_READ_FRAME]=&read_frame; - flist[F_READ_ALL]=&read_all; - flist[F_START_AND_READ_ALL]=&start_and_read_all; - flist[F_SET_TIMER]=&set_timer; - flist[F_GET_TIME_LEFT]=&get_time_left; - flist[F_SET_DYNAMIC_RANGE]=&set_dynamic_range; - flist[F_SET_ROI]=&set_roi; - flist[F_SET_SPEED]=&set_speed; - flist[F_SET_READOUT_FLAGS]=&set_readout_flags; - flist[F_EXECUTE_TRIMMING]=&execute_trimming; - flist[F_CONFIGURE_MAC]=&configure_mac; - flist[F_LOAD_IMAGE]=&load_image; - flist[F_READ_COUNTER_BLOCK]=&read_counter_block; - flist[F_RESET_COUNTER_BLOCK]=&reset_counter_block; - - - flist[F_LOCK_SERVER]=&lock_server; - flist[F_SET_PORT]=&set_port; - flist[F_GET_LAST_CLIENT_IP]=&get_last_client_ip; - flist[F_UPDATE_CLIENT]=&update_client; - flist[F_SET_MASTER]=&set_master; - flist[F_SET_SYNCHRONIZATION_MODE]=&set_synchronization; - -#ifdef VERBOSE - /* for (i=0;i<256;i++){ - printf("function %d located at %x\n",i,flist[i]); - }*/ -#endif - return OK; -} - - -int M_nofunc(int file_des){ - - int retval=FAIL; - sprintf(mess,"Unrecognized Function\n"); - printf(mess); - sendDataOnly(file_des,&retval,sizeof(retval)); - sendDataOnly(file_des,mess,sizeof(mess)); - return GOODBYE; -} - - -int exit_server(int file_des) { - int retval=FAIL; - sendDataOnly(file_des,&retval,sizeof(retval)); - printf("closing server."); - sprintf(mess,"closing server"); - sendDataOnly(file_des,mess,sizeof(mess)); - return GOODBYE; -} - -int exec_command(int file_des) { - char cmd[MAX_STR_LENGTH]; - char answer[MAX_STR_LENGTH]; - int retval=OK; - int sysret=0; - int n=0; - - /* receive arguments */ - n = receiveDataOnly(file_des,cmd,MAX_STR_LENGTH); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - retval=FAIL; - } - - /* execute action if the arguments correctly arrived*/ - if (retval==OK) { -#ifdef VERBOSE - printf("executing command %s\n", cmd); -#endif - if (lockStatus==0 || differentClients==0) - sysret=system(cmd); - - //should be replaced by popen - if (sysret==0) { - sprintf(answer,"Succeeded\n"); - if (lockStatus==1 && differentClients==1) - sprintf(answer,"Detector locked by %s\n", lastClientIP); - } else { - sprintf(answer,"Failed\n"); - retval=FAIL; - } - } else { - sprintf(answer,"Could not receive the command\n"); - } - - /* send answer */ - n = sendDataOnly(file_des,&retval,sizeof(retval)); - n = sendDataOnly(file_des,answer,MAX_STR_LENGTH); - if (n < 0) { - sprintf(mess,"Error writing to socket"); - retval=FAIL; - } - - - /*return ok/fail*/ - return retval; - -} - - - -int get_detector_type(int file_des) { - int n=0; - enum detectorType ret; - int retval=OK; - - sprintf(mess,"Can't return detector type\n"); - - - /* receive arguments */ - /* execute action */ - ret=myDetectorType; - -#ifdef VERBOSE - printf("Returning detector type %d\n",ret); -#endif - - /* send answer */ - /* send OK/failed */ - if (differentClients==1) - retval=FORCE_UPDATE; - - n += sendDataOnly(file_des,&retval,sizeof(retval)); - if (retval!=FAIL) { - /* send return argument */ - ret=(detectorType)swap_int32(ret); - n += sendDataOnly(file_des,&ret,sizeof(ret)); - } else { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } - /*return ok/fail*/ - return retval; - - -} - - -int set_number_of_modules(int file_des) { - int n; - int arg[2], ret=0; - int retval=OK; - enum dimension dim; - int nm; - - sprintf(mess,"Can't set number of modules\n"); - - /* receive arguments */ - n = receiveDataOnly(file_des,&arg,sizeof(arg)); - if (n < 0) { - sprintf(mess,"Error reading from socket %d", n); - retval=GOODBYE; - } - if (retval==OK) { - dim=(dimension)arg[0]; - nm=arg[1]; - - /* execute action */ -#ifdef VERBOSE - printf("Setting the number of modules in dimension %d to %d\n",dim,nm ); -#endif - - - if (lockStatus==1 && differentClients==1 && nm!=GET_FLAG) { - sprintf(mess,"Detector locked by %s\n", lastClientIP); - retval=FAIL; - } else { - ret=setNMod(nm, dim); - if (ret==nm || nm==GET_FLAG) { - retval=OK; - if (differentClients==1) - retval=FORCE_UPDATE; - } else - retval=FAIL; - } - } - - - dataBytes=calculateDataBytes(); - - /* send answer */ - /* send OK/failed */ - n = sendDataOnly(file_des,&retval,sizeof(retval)); - if (retval!=FAIL) { - /* send return argument */ - n += sendDataOnly(file_des,&ret,sizeof(ret)); - } else { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } - /*return ok/fail*/ - return retval; - -} - - -int get_max_number_of_modules(int file_des) { - int n; - int ret; - int retval=OK; - enum dimension arg; - - sprintf(mess,"Can't get max number of modules\n"); - /* receive arguments */ - n = receiveDataOnly(file_des,&arg,sizeof(arg)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - retval=FAIL; - } - /* execute action */ -#ifdef VERBOSE - printf("Getting the max number of modules in dimension %d \n",arg); -#endif - - - ret=getNModBoard(arg); -#ifdef VERBOSE - printf("Max number of module in dimension %d is %d\n",arg,ret ); -#endif - - - - if (differentClients==1 && retval==OK) { - retval=FORCE_UPDATE; - } - - /* send answer */ - /* send OK/failed */ - n = sendDataOnly(file_des,&retval,sizeof(retval)); - if (retval!=FAIL) { - /* send return argument */ - n += sendDataOnly(file_des,&ret,sizeof(ret)); - } else { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } - - - - /*return ok/fail*/ - return retval; -} - - -//index 0 is in gate -//index 1 is in trigger -//index 2 is out gate -//index 3 is out trigger - -int set_external_signal_flag(int file_des) { - int n; - int arg[2]; - int ret=OK; - int signalindex; - enum externalSignalFlag flag, retval; - - sprintf(mess,"Can't set external signal flag\n"); - - /* receive arguments */ - n = receiveDataOnly(file_des,&arg,sizeof(arg)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - retval=SIGNAL_OFF; - if (ret==OK) { - signalindex=arg[0]; - flag=(externalSignalFlag)arg[1]; - /* execute action */ - switch (flag) { - case GET_EXTERNAL_SIGNAL_FLAG: - retval=getExtSignal(signalindex); - break; - - default: - if (differentClients==0 || lockStatus==0) { - retval=setExtSignal(signalindex,flag); - if (retval!=flag) { - ret=FAIL; - sprintf(mess,"External signal %d flag should be 0x%04x but is 0x%04x\n", signalindex, flag, retval); - } - - } else { - if (lockStatus!=0) { - ret=FAIL; - sprintf(mess,"Detector locked by %s\n", lastClientIP); - } - } - - - } - -#ifdef VERBOSE - printf("Setting external signal %d to flag %d\n",signalindex,flag ); - printf("Set to flag %d\n",retval); -#endif - - } else { - ret=FAIL; - } - - if (ret==OK && differentClients!=0) - 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)); - } else { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } - - - /*return ok/fail*/ - return ret; - -} - - -int set_external_communication_mode(int file_des) { - int n; - enum externalCommunicationMode arg, ret=GET_EXTERNAL_COMMUNICATION_MODE; - int retval=OK; - - sprintf(mess,"Can't set external communication mode\n"); - - - /* receive arguments */ - n = receiveDataOnly(file_des,&arg,sizeof(arg)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - retval=FAIL; - } - /* -enum externalCommunicationMode{ - GET_EXTERNAL_COMMUNICATION_MODE, - AUTO, - TRIGGER_EXPOSURE_SERIES, - TRIGGER_EXPOSURE_BURST, - TRIGGER_READOUT, - TRIGGER_COINCIDENCE_WITH_INTERNAL_ENABLE, - GATE_FIX_NUMBER, - GATE_FIX_DURATION, - GATE_WITH_START_TRIGGER, - GATE_COINCIDENCE_WITH_INTERNAL_ENABLE -}; - */ - if (retval==OK) { - /* execute action */ - - ret=setTiming(arg); - - /* switch(arg) { */ - /* default: */ - /* sprintf(mess,"The meaning of single signals should be set\n"); */ - /* retval=FAIL; */ - /* } */ - - -#ifdef VERBOSE - printf("Setting external communication mode to %d\n", arg); -#endif - } else - ret=(externalCommunicationMode)FAIL; - - /* send answer */ - /* send OK/failed */ - n = sendDataOnly(file_des,&retval,sizeof(retval)); - if (retval!=FAIL) { - /* send return argument */ - n += sendDataOnly(file_des,&ret,sizeof(ret)); - } else { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } - - /*return ok/fail*/ - return retval; - - -} - - - -int get_id(int file_des) { - // sends back 64 bits! - int64_t retval; - int ret=OK; - int imod=-1; - int n=0; - enum idMode arg; - - sprintf(mess,"Can't return id\n"); - - /* receive arguments */ - n = receiveDataOnly(file_des,&arg,sizeof(arg)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - -#ifdef VERBOSE - printf("Getting id %d\n", arg); -#endif - - switch (arg) { - case MODULE_SERIAL_NUMBER: - case MODULE_FIRMWARE_VERSION: - n = receiveDataOnly(file_des,&imod,sizeof(imod)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } else { -#ifdef VERBOSE - printf("of module %d\n", imod); -#endif - if (imod>=0 && imod=0 && imod=getTotalNumberOfModules()) { - ret=FAIL; - sprintf(mess,"Module number %d out of range\n",imod); - } - - - // check if dac exists for this detector - switch (ind) { - case TRIMBIT_SIZE: - if (myDetectorType==MYTHEN) - break; - case THRESHOLD: - if (myDetectorType==MYTHEN) - break; - case SHAPER1: - if (myDetectorType==MYTHEN) - break; - case SHAPER2: - if (myDetectorType==MYTHEN) - break; - case CALIBRATION_PULSE: - if (myDetectorType==MYTHEN) - break; - case PREAMP: - if (myDetectorType==MYTHEN) - break; - default: - printf("Unknown DAC index %d\n",ind); - sprintf(mess,"Unknown DAC index %d\n",ind); - ret=FAIL; - } - - if (ret==OK) { - if (differentClients==1 && lockStatus==1 && val!=-1) { - ret=FAIL; - sprintf(mess,"Detector locked by %s\n",lastClientIP); - } else - retval=setDAC(ind,val,imod); - } - -#ifdef VERBOSE - printf("DAC set to %f V\n", retval); -#endif - if (retval==val || val==-1) { - ret=OK; - if (differentClients) - ret=FORCE_UPDATE; - } else { - ret=FAIL; - printf("Setting dac %d of module %d: wrote %f but read %f\n", ind, imod, val, retval); - } - - - /* 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)); - } else { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } - - /* Maybe this is done inside the initialization funcs */ - //detectorDacs[imod][ind]=val; - /*return ok/fail*/ - return ret; - -} - - - -int get_adc(int file_des) { - - double retval; - int ret=OK; - int arg[2]; - enum dacIndex ind; - int imod; - int n; - - sprintf(mess,"Can't read ADC\n"); - - - n = receiveDataOnly(file_des,arg,sizeof(arg)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - ind=(dacIndex)arg[0]; - imod=arg[1]; - - - if (imod>=getTotalNumberOfModules() || imod<0) { - ret=FAIL; - sprintf(mess,"Module number %d out of range\n",imod); - } - - - switch (ind) { - case TRIMBIT_SIZE: - if (myDetectorType==MYTHEN) - break; - case THRESHOLD: - if (myDetectorType==MYTHEN) - break; - case SHAPER1: - if (myDetectorType==MYTHEN) - break; - case SHAPER2: - if (myDetectorType==MYTHEN) - break; - case CALIBRATION_PULSE: - if (myDetectorType==MYTHEN) - break; - case PREAMP: - if (myDetectorType==MYTHEN) - break; - default: - printf("Unknown DAC index %d\n",ind); - ret=FAIL; - sprintf(mess,"Unknown ADC index %d\n",ind); - } - - if (ret==OK) { - retval=getADC(ind,imod); - } -#ifdef VERBOSE - printf("Getting ADC %d of module %d\n", ind, imod); -#endif - -#ifdef VERBOSE - printf("ADC is %f V\n", retval); -#endif - if (ret==FAIL) { - printf("Getting adc %d of module %d failed\n", ind, imod); - } - - - 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)); - } else { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } - - /*return ok/fail*/ - return ret; - -} - -int set_channel(int file_des) { - int ret=OK; - sls_detector_channel myChan; - int retval; - int n; - - - sprintf(mess,"Can't set channel\n"); - -#ifdef VERBOSE - printf("Setting channel\n"); -#endif - ret=receiveChannel(file_des, &myChan); - if (ret>=0) - ret=OK; - else - ret=FAIL; -#ifdef VERBOSE - printf("channel number is %d, chip number is %d, module number is %d, register is %lld\n", myChan.chan,myChan.chip, myChan.module, myChan.reg); -#endif - - if (myChan.chan>=getNumberOfChannelsPerChip()) { - ret=FAIL; - sprintf(mess, "channel number %d too large!\n",myChan.chan); - } - if (myChan.chip>=getNumberOfChipsPerModule()) { - ret=FAIL; - sprintf(mess, "chip number %d too large!\n",myChan.chip); - } - - if (myChan.module>=getTotalNumberOfModules()) { - ret=FAIL; - sprintf(mess, "chip number %d too large!\n",myChan.module); - } - - - if (ret==OK) { - if (differentClients==1 && lockStatus==1) { - ret=FAIL; - sprintf(mess,"Detector locked by %s\n",lastClientIP); - } else { - retval=setChannel(myChan); - } - } - /* Maybe this is done inside the initialization funcs */ - //copyChannel(detectorChans[myChan.module][myChan.chip]+(myChan.chan), &myChan); - - - - if (differentClients==1 && ret==OK) - 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)); - } else { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } - - - /*return ok/fail*/ - return ret; - -} - - - - -int get_channel(int file_des) { - - int ret=OK; - sls_detector_channel retval; - - int arg[3]; - int ichan, ichip, imod; - int n; - - sprintf(mess,"Can't get channel\n"); - - - - n = receiveDataOnly(file_des,arg,sizeof(arg)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - ichan=arg[0]; - ichip=arg[1]; - imod=arg[2]; - - if (ichan>=getNumberOfChannelsPerChip()) { - ret=FAIL; - sprintf(mess, "channel number %d too large!\n",ichan); - } else - retval.chan=ichan; - if (ichip>=getNumberOfChipsPerModule()) { - ret=FAIL; - sprintf(mess, "chip number %d too large!\n",ichip); - } else - retval.chip=ichip; - - if (imod>=getTotalNumberOfModules()) { - ret=FAIL; - sprintf(mess, "chip number %d too large!\n",imod); - } else - retval.module=imod; - - - if (ret==OK) { - ret=getChannel(&retval); - if (differentClients && ret==OK) - ret=FORCE_UPDATE; - } - -#ifdef VERBOSE - printf("Returning channel %d %d %d, 0x%llx\n", retval.chan, retval.chip, retval.mod, (retval.reg)); -#endif - - /* send answer */ - /* send OK/failed */ - n = sendDataOnly(file_des,&ret,sizeof(ret)); - if (ret!=FAIL) { - /* send return argument */ - ret=sendChannel(file_des, &retval); - } else { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } - - - - /*return ok/fail*/ - return ret; - - -} - - -int set_chip(int file_des) { - - sls_detector_chip myChip; - int *ch; - int n, retval; - int ret=OK; - - - myChip.nchan=getNumberOfChannelsPerChip(); - ch=(int *)malloc((myChip.nchan)*sizeof(int)); - myChip.chanregs=ch; - - - - -#ifdef VERBOSE - printf("Setting chip\n"); -#endif - ret=receiveChip(file_des, &myChip); -#ifdef VERBOSE - printf("Chip received\n"); -#endif - if (ret>=0) - ret=OK; - else - ret=FAIL; -#ifdef VERBOSE - printf("chip number is %d, module number is %d, register is %d, nchan %d\n",myChip.chip, myChip.module, myChip.reg, myChip.nchan); -#endif - - - if (myChip.chip>=getNumberOfChipsPerModule()) { - ret=FAIL; - sprintf(mess, "chip number %d too large!\n",myChip.chip); - } - - if (myChip.module>=getTotalNumberOfModules()) { - ret=FAIL; - sprintf(mess, "chip number %d too large!\n",myChip.module); - } - - - if (differentClients==1 && lockStatus==1) { - ret=FAIL; - sprintf(mess,"Detector locked by %s\n",lastClientIP); - } else { - retval=setChip(myChip); - } - /* Maybe this is done inside the initialization funcs */ - //copyChip(detectorChips[myChip.module]+(myChip.chip), &myChip); - - if (differentClients && ret==OK) - 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)); - } else { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } - free(ch); - - return ret; -} - -int get_chip(int file_des) { - - - int ret=OK; - sls_detector_chip retval; - int arg[2]; - int ichip, imod; - int n; - int *ch; - - - retval.nchan=getNumberOfChannelsPerChip(); - ch=(int *)malloc((retval.nchan)*sizeof(int)); - retval.chanregs=ch; - - - n = receiveDataOnly(file_des,arg,sizeof(arg)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - ichip=arg[0]; - imod=arg[1]; - - - if (ichip>=getNumberOfChipsPerModule()) { - ret=FAIL; - sprintf(mess, "chip number %d too large!\n",ichip); - } else - retval.chip=ichip; - - if (imod>=getTotalNumberOfModules()) { - ret=FAIL; - sprintf(mess, "chip number %d too large!\n",imod); - } else - retval.module=imod; - - if (ret==OK) { - ret=getChip(&retval); - if (differentClients && ret==OK) - ret=FORCE_UPDATE; - } - -#ifdef VERBOSE - printf("Returning chip %d %d\n", ichip, imod); -#endif - - - /* send answer */ - /* send OK/failed */ - n = sendDataOnly(file_des,&ret,sizeof(ret)); - if (ret!=FAIL) { - /* send return argument */ - ret=sendChip(file_des, &retval); - } else { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } - - free(ch); - - /*return ok/fail*/ - return ret; - - -} -int set_module(int file_des) { - sls_detector_module myModule; - int *myChip=(int *)malloc(getNumberOfChipsPerModule()*sizeof(int)); - int *myChan=(int *)malloc(getNumberOfChannelsPerModule()*sizeof(int)); - int *myDac=(int *)malloc(getNumberOfDACsPerModule()*sizeof(int)); - int *myAdc=(int *)malloc(getNumberOfADCsPerModule()*sizeof(int)); - int retval, n; - int ret=OK; - - - if (myDac) - myModule.dacs=myDac; - else { - sprintf(mess,"could not allocate dacs\n"); - ret=FAIL; - } - if (myAdc) - myModule.adcs=myAdc; - else { - sprintf(mess,"could not allocate adcs\n"); - ret=FAIL; - } - if (myChip) - myModule.chipregs=myChip; - else { - sprintf(mess,"could not allocate chips\n"); - ret=FAIL; - } - if (myChan) - myModule.chanregs=myChan; - else { - sprintf(mess,"could not allocate chans\n"); - ret=FAIL; - } - - myModule.ndac=getNumberOfADCsPerModule(); - myModule.nchip=getNumberOfChipsPerModule(); - myModule.nchan=getNumberOfChannelsPerModule(); - myModule.nadc=getNumberOfADCsPerModule(); - - -#ifdef VERBOSE - printf("Setting module\n"); -#endif - ret=receiveModule(file_des, &myModule); - - - if (ret>=0) - ret=OK; - else - ret=FAIL; - - -#ifdef VERBOSE - printf("module number is %d,register is %d, nchan %d, nchip %d, ndac %d, nadc %d, gain %f, offset %f\n",myModule.module, myModule.reg, myModule.nchan, myModule.nchip, myModule.ndac, myModule.nadc, myModule.gain,myModule.offset); -#endif - - - if (ret==OK) { - if (differentClients==1 && lockStatus==1) { - ret=FAIL; - sprintf(mess,"Detector locked by %s\n",lastClientIP); - } else { - retval=setModule(myModule); - } - } - - if (differentClients==1 && ret==OK) - ret=FORCE_UPDATE; - - /* Maybe this is done inside the initialization funcs */ - //copyChip(detectorChips[myChip.module]+(myChip.chip), &myChip); - - /* 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)); - } else { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } - free(myChip); - free(myChan); - free(myDac); - free(myAdc); - - return ret; -} - - - - -int get_module(int file_des) { - - - int ret=OK; - - - int arg; - int imod; - int n; - - - - sls_detector_module myModule; - int *myChip=(int *)malloc(getNumberOfChipsPerModule()*sizeof(int)); - int *myChan=(int *)malloc(getNumberOfChannelsPerModule()*sizeof(int)); - int *myDac=(int *)malloc(getNumberOfDACsPerModule()*sizeof(int)); - int *myAdc=(int *)malloc(getNumberOfADCsPerModule()*sizeof(int)); - - - if (myDac) - myModule.dacs=myDac; - else { - sprintf(mess,"could not allocate dacs\n"); - ret=FAIL; - } - if (myAdc) - myModule.adcs=myAdc; - else { - sprintf(mess,"could not allocate adcs\n"); - ret=FAIL; - } - if (myChip) - myModule.chipregs=myChip; - else { - sprintf(mess,"could not allocate chips\n"); - ret=FAIL; - } - if (myChan) - myModule.chanregs=myChan; - else { - sprintf(mess,"could not allocate chans\n"); - ret=FAIL; - } - - myModule.ndac=getNumberOfDACsPerModule(); - myModule.nchip=getNumberOfChipsPerModule(); - myModule.nchan=getNumberOfChannelsPerModule(); - myModule.nadc=getNumberOfADCsPerModule(); - - - - - - n = receiveDataOnly(file_des,&arg,sizeof(arg)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - imod=arg; - - if (ret==OK) { - ret=FAIL; - if (imod>=0) { - ret=OK; - myModule.module=imod; - getModule(&myModule); - -#ifdef VERBOSE - printf("Returning module %d of register %x\n", imod, myModule.reg); -#endif - } - } - - if (differentClients==1 && ret==OK) - ret=FORCE_UPDATE; - - /* send answer */ - /* send OK/failed */ - n = sendDataOnly(file_des,&ret,sizeof(ret)); - if (ret!=FAIL) { - /* send return argument */ - ret=sendModule(file_des, &myModule); - } else { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } - - - - free(myChip); - free(myChan); - free(myDac); - free(myAdc); - - - - - - - - - /*return ok/fail*/ - return ret; - -} -int get_threshold_energy(int file_des) { - int retval; - int ret=OK; - int n; - int imod; - - - n = receiveDataOnly(file_des,&imod,sizeof(imod)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - - -#ifdef VERBOSE - printf("Getting threshold energy of module %d\n", imod); -#endif - - if (imod>=getTotalNumberOfModules()) { - ret=FAIL; - sprintf(mess,"Module number %d out of range\n",imod); - } - - retval=getThresholdEnergy(imod); - - -#ifdef VERBOSE - printf("Threshold is %d eV\n", retval); -#endif - - - if (differentClients==1 && ret==OK) - ret=FORCE_UPDATE; - - /* send answer */ - n = sendDataOnly(file_des,&ret,sizeof(ret)); - if (ret==FAIL) { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } else - n += sendDataOnly(file_des,&retval,sizeof(retval)); - - - /* Maybe this is done inside the initialization funcs */ - //detectorDacs[imod][ind]=val; - /*return ok/fail*/ - return ret; - -} - -int set_threshold_energy(int file_des) { - int retval; - int ret=OK; - int arg[3]; - int n; - int ethr, imod; - enum detectorSettings isett; - - - n = receiveDataOnly(file_des,&arg,sizeof(arg)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - ethr=arg[0]; - imod=arg[1]; - isett=(detectorSettings)arg[2]; - - if (imod>=getTotalNumberOfModules()) { - ret=FAIL; - sprintf(mess,"Module number %d out of range\n",imod); - } - - -#ifdef VERBOSE - printf("Setting threshold energy of module %d to %d eV with settings %d\n", imod, ethr, isett); -#endif - - if (differentClients==1 && lockStatus==1) { - ret=FAIL; - sprintf(mess,"Detector locked by %s\n",lastClientIP); - } else { - retval=setThresholdEnergy(ethr, imod); - } - -#ifdef VERBOSE - printf("Threshold set to %d eV\n", retval); -#endif - if (retval==ethr) - ret=OK; - else { - ret=FAIL; - printf("Setting threshold of module %d: wrote %d but read %d\n", imod, ethr, retval); - sprintf(mess,"Setting threshold of module %d: wrote %d but read %d\n", imod, ethr, retval); - } - if (ret==OK && differentClients==1) - ret=FORCE_UPDATE; - - /* send answer */ - n = sendDataOnly(file_des,&ret,sizeof(ret)); - if (ret==FAIL) { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } else - n += sendDataOnly(file_des,&retval,sizeof(retval)); - - - /* Maybe this is done inside the initialization funcs */ - //detectorDacs[imod][ind]=val; - /*return ok/fail*/ - return ret; - -} - -int set_settings(int file_des) { - - int retval; - int ret=OK; - int arg[2]; - int n; - int imod; - enum detectorSettings isett; - - - n = receiveDataOnly(file_des,&arg,sizeof(arg)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - imod=arg[1]; - isett=(detectorSettings)arg[0]; - - - if (imod>=getTotalNumberOfModules()) { - ret=FAIL; - sprintf(mess,"Module number %d out of range\n",imod); - } - -#ifdef VERBOSE - printf("Changing settings of module %d to %d\n", imod, isett); -#endif - - if (differentClients==1 && lockStatus==1 && arg[0]!=GET_SETTINGS) { - ret=FAIL; - sprintf(mess,"Detector locked by %s\n",lastClientIP); - } else { - retval=setSettings((detectorSettings)arg[0], imod); -#ifdef VERBOSE - printf("Settings changed to %d\n", isett); -#endif - - if (retval==isett || isett<0) { - ret=OK; - } else { - ret=FAIL; - printf("Changing settings of module %d: wrote %d but read %d\n", imod, isett, retval); - } - - } - if (ret==OK && differentClients==1) - ret=FORCE_UPDATE; - - /* send answer */ - n = sendDataOnly(file_des,&ret,sizeof(ret)); - if (ret==FAIL) { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } else - n += sendDataOnly(file_des,&retval,sizeof(retval)); - - - - return ret; - - -} - -int start_acquisition(int file_des) { - - int ret=OK; - int n; - - - sprintf(mess,"can't start acquisition\n"); - -#ifdef VERBOSE - printf("Starting acquisition\n"); -#endif - - if (differentClients==1 && lockStatus==1) { - ret=FAIL; - sprintf(mess,"Detector locked by %s\n",lastClientIP); - } else { - ret=startStateMachine(); - } - if (ret==FAIL) - sprintf(mess,"Start acquisition failed\n"); - else if (differentClients) - ret=FORCE_UPDATE; - - n = sendDataOnly(file_des,&ret,sizeof(ret)); - if (ret==FAIL) { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } - return ret; - -} - -int stop_acquisition(int file_des) { - - int ret=OK; - int n; - - - sprintf(mess,"can't stop acquisition\n"); - -#ifdef VERBOSE - printf("Stopping acquisition\n"); -#endif - - - if (differentClients==1 && lockStatus==1) { - ret=FAIL; - sprintf(mess,"Detector locked by %s\n",lastClientIP); - } else { - ret=stopStateMachine(); - } - - if (ret==FAIL) - sprintf(mess,"Stop acquisition failed\n"); - else if (differentClients) - ret=FORCE_UPDATE; - - n = sendDataOnly(file_des,&ret,sizeof(ret)); - if (ret==FAIL) { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } - return ret; - - -} - -int start_readout(int file_des) { - - - int ret=OK; - int n; - - - sprintf(mess,"can't start readout\n"); - -#ifdef VERBOSE - printf("Starting readout\n"); -#endif - if (differentClients==1 && lockStatus==1) { - ret=FAIL; - sprintf(mess,"Detector locked by %s\n",lastClientIP); - } else { - ret=startReadOut(); - } - if (ret==FAIL) - sprintf(mess,"Start readout failed\n"); - else if (differentClients) - ret=FORCE_UPDATE; - - n = sendDataOnly(file_des,&ret,sizeof(ret)); - if (ret==FAIL) { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } - return ret; - - - -} - -int get_run_status(int file_des) { - - int ret=OK; - int n; - - enum runStatus s; - sprintf(mess,"getting run status\n"); - -#ifdef VERBOSE - printf("Getting status\n"); -#endif - - s= getRunStatus(); - - - - - if (ret!=OK) { - printf("get status failed\n"); - } else if (differentClients) - ret=FORCE_UPDATE; - - n = sendDataOnly(file_des,&ret,sizeof(ret)); - if (ret==FAIL) { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } else { - n += sendDataOnly(file_des,&s,sizeof(s)); - } - return ret; - - - -} - -int read_frame(int file_des) { - -#ifdef VERBOSE - int n; -#endif - - dataret=OK; - - if (differentClients==1 && lockStatus==1) { - dataret=FAIL; - sprintf(mess,"Detector locked by %s\n",lastClientIP); - sendDataOnly(file_des,&dataret,sizeof(dataret)); - sendDataOnly(file_des,mess,sizeof(mess)); - printf("dataret %d\n",dataret); - return dataret; - } - - - dataretval=readFrame(&dataret, mess); - - sendDataOnly(file_des,&dataret,sizeof(dataret)); - if (dataret==FAIL) - sendDataOnly(file_des,mess,sizeof(mess));//sizeof(mess));//sizeof(mess)); - else - sendDataOnly(file_des,dataretval,dataBytes); - - printf("dataret %d\n",dataret); - return dataret; -} - - - - - - - -int read_all(int file_des) { - - - while(read_frame(file_des)==OK) { -#ifdef VERBOSE - printf("frame read\n"); -#endif - ; - } - -#ifdef VERBOSE - printf("Frames finished\n"); -#endif - return OK; - - -} - -int start_and_read_all(int file_des) { - //int dataret=OK; -#ifdef VERBOSE - printf("Starting and reading all frames\n"); -#endif - - if (differentClients==1 && lockStatus==1) { - dataret=FAIL; - sprintf(mess,"Detector locked by %s\n",lastClientIP); - sendDataOnly(file_des,&dataret,sizeof(dataret)); - sendDataOnly(file_des,mess,sizeof(mess)); - return dataret; - - } - - - startStateMachine(); - read_all(file_des); -#ifdef VERBOSE - printf("Frames finished\n"); -#endif - - - return OK; - - -} - -int set_timer(int file_des) { - enum timerIndex ind; - int64_t tns; - int n; - int64_t retval; - int ret=OK; - - - sprintf(mess,"can't set timer\n"); - - n = receiveDataOnly(file_des,&ind,sizeof(ind)); - ind=(timerIndex)swap_int32(ind); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - - n = receiveDataOnly(file_des,&tns,sizeof(tns)); - tns=swap_int64(tns); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - - if (ret!=OK) { - printf(mess); - } - - //#ifdef VERBOSE - printf("setting timer %d to %lld ns\n",ind,tns); - //#endif - if (ret==OK) { - - if (differentClients==1 && lockStatus==1 && tns!=-1) { - ret=FAIL; - sprintf(mess,"Detector locked by %s\n",lastClientIP); - } else { - switch(ind) { - case FRAME_NUMBER: - retval=setFrames(tns);retval=swap_int64(retval); - break; - case ACQUISITION_TIME: - retval=setExposureTime(tns); - break; - case FRAME_PERIOD: - retval=setPeriod(tns); - break; - case DELAY_AFTER_TRIGGER: - retval=setDelay(tns); - break; - case GATES_NUMBER: - retval=setGates(tns); - break; - case PROBES_NUMBER: - retval=setProbes(tns); - break; - case CYCLES_NUMBER: - retval=setTrains(tns); - break; - default: - ret=FAIL; - sprintf(mess,"timer index unknown %d\n",ind); - } - } - } - if (ret!=OK) { - printf(mess); - if (differentClients) - ret=FORCE_UPDATE; - } - - if (ret!=OK) { - printf(mess); - printf("set timer failed\n"); - sprintf(mess, "set timer %d failed\n", ind); - } else if (ind==FRAME_NUMBER) { - /*ret=allocateRAM();*/ - if (ret!=OK) - sprintf(mess, "could not allocate RAM for %lld frames\n", tns); - } - - n = sendDataOnly(file_des,&ret,sizeof(ret)); - if (ret==FAIL) { - n = sendDataOnly(file_des,mess,sizeof(mess)); - } else { - #ifdef VERBOSE - printf("returning ok %d\n",sizeof(retval)); - #endif - - n = sendDataOnly(file_des,&retval,sizeof(retval)); - } - - return ret; - -} - - - - - - - - -int get_time_left(int file_des) { - - enum timerIndex ind; - int n; - int64_t retval; - int ret=OK; - - sprintf(mess,"can't get timer\n"); - n = receiveDataOnly(file_des,&ind,sizeof(ind)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - - -#ifdef VERBOSE - - printf("getting time left on timer %d \n",ind); -#endif - - if (ret==OK) { - switch(ind) { - case FRAME_NUMBER: - case ACQUISITION_TIME: - case FRAME_PERIOD: - case DELAY_AFTER_TRIGGER: - case GATES_NUMBER: - case CYCLES_NUMBER: - case PROGRESS: - retval=getTimeLeft(ind); - break; - case PROBES_NUMBER: - case ACTUAL_TIME: - case MEASUREMENT_TIME: - if (myDetectorType==MYTHEN) { - retval=getTimeLeft(ind); - break; - } - default: - ret=FAIL; - sprintf(mess,"timer index unknown %d\n",ind); - } - } - - - if (ret!=OK) { - printf("get time left failed\n"); - } else if (differentClients) - ret=FORCE_UPDATE; - -#ifdef VERBOSE - - printf("time left on timer %d is %lld\n",ind, retval); -#endif - - n = sendDataOnly(file_des,&ret,sizeof(ret)); - if (ret==FAIL) { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } else { - n = sendDataOnly(file_des,&retval,sizeof(retval)); - } -#ifdef VERBOSE - - printf("data sent\n"); -#endif - - return ret; - - -} - -int set_dynamic_range(int file_des) { - - - - int dr; - int n; - int retval; - int ret=OK; - - - sprintf(mess,"can't set dynamic range\n"); - - - n = receiveDataOnly(file_des,&dr,sizeof(dr)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - - - if (differentClients==1 && lockStatus==1 && dr>=0) { - ret=FAIL; - sprintf(mess,"Detector locked by %s\n",lastClientIP); - } else { - retval=setDynamicRange(dr); - } - - if (dr>=0 && retval!=dr) - ret=FAIL; - if (ret!=OK) { - sprintf(mess,"set dynamic range failed\n"); - } else if (differentClients) - ret=FORCE_UPDATE; - - - dataBytes=calculateDataBytes(); - - n = sendDataOnly(file_des,&ret,sizeof(ret)); - if (ret==FAIL) { - n = sendDataOnly(file_des,mess,sizeof(mess)); - } else { - n = sendDataOnly(file_des,&retval,sizeof(retval)); - } - return ret; -} - -int set_roi(int file_des) { - - dataBytes=calculateDataBytes(); - - return FAIL; - -} - -int get_roi(int file_des) { - - dataBytes=calculateDataBytes(); - - return FAIL; -} - -int set_speed(int file_des) { - - enum speedVariable arg; - int val, n; - int ret=OK; - int retval; - - sprintf(mess,"can't set speed variable\n"); - - - n = receiveDataOnly(file_des,&arg,sizeof(arg)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - n = receiveDataOnly(file_des,&val,sizeof(val)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - -#ifdef VERBOSE - printf("setting speed variable %d to %d\n",arg,val); -#endif - if (ret==OK) { - - if (differentClients==1 && lockStatus==1 && val>=0) { - ret=FAIL; - sprintf(mess,"Detector locked by %s\n",lastClientIP); - } else { - switch (arg) { - case CLOCK_DIVIDER: - case WAIT_STATES: - case SET_SIGNAL_LENGTH: - case TOT_CLOCK_DIVIDER: - case TOT_DUTY_CYCLE: - if (myDetectorType==MYTHEN) { - retval=setSpeed(arg, val); - break; - } - default: - sprintf(mess,"unknown speed variable %d\n",arg); - ret=FAIL; - } - } - if (ret==OK && val>=0) { - if (retval!=val) { - ret=FAIL; - sprintf(mess,"could not change speed variable %d: should be %d but is %d \n",arg, val, retval); - } - } - if (differentClients && ret==OK) - ret=FORCE_UPDATE; - } - - n = sendDataOnly(file_des,&ret,sizeof(ret)); - if (ret==FAIL) { - n = sendDataOnly(file_des,mess,sizeof(mess)); - } else { - n = sendDataOnly(file_des,&retval,sizeof(retval)); - } - return ret; -} - - -int set_readout_flags(int file_des) { - - enum readOutFlags retval; - enum readOutFlags arg; - int n; - int ret=OK; - - - sprintf(mess,"can't set readout flags\n"); - - - n = receiveDataOnly(file_des,&arg,sizeof(arg)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - - -#ifdef VERBOSE - printf("setting readout flags to %d\n",arg); -#endif - - if (differentClients==1 && lockStatus==1 && arg!=GET_READOUT_FLAGS) { - ret=FAIL; - sprintf(mess,"Detector locked by %s\n",lastClientIP); - } else { - - - - switch(arg) { - case GET_READOUT_FLAGS: - case STORE_IN_RAM: - case TOT_MODE: - case CONTINOUS_RO: - case NORMAL_READOUT: - if (myDetectorType==MYTHEN) { - retval=setReadOutFlags(arg); - break; - } - default: - sprintf(mess,"Unknown readout flag %d\n", arg); - ret=FAIL; - } - } - - - - if (ret==OK) { - if (differentClients) - ret=FORCE_UPDATE; - if (arg!=GET_READOUT_FLAGS && arg!=retval) { - ret=FAIL; - sprintf(mess,"Could not change readout flag: should be %d but is %d\n", arg, retval); - } - } - - - n = sendDataOnly(file_des,&ret,sizeof(ret)); - if (ret==FAIL) { - n = sendDataOnly(file_des,mess,sizeof(mess)); - } else { - n = sendDataOnly(file_des,&retval,sizeof(retval)); - } - return ret; -} - - - -int execute_trimming(int file_des) { - - int arg[3]; - int n; - int ret=OK, retval; - int imod, par1,par2; - enum trimMode mode; - - printf("called function execute trimming\n"); - - sprintf(mess,"can't set execute trimming\n"); - - n = receiveDataOnly(file_des,&mode,sizeof(mode)); - printf("mode received\n"); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - printf("Error reading from socket (mode)\n"); - ret=FAIL; - } - - n = receiveDataOnly(file_des,arg,sizeof(arg)); - printf("arg received\n"); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - printf("Error reading from socket (args)\n"); - ret=FAIL; - } - - imod=arg[0]; - par1=arg[1]; - par2=arg[2]; - - if (imod>=getTotalNumberOfModules()) { - ret=FAIL; - sprintf(mess,"Module number out of range %d\n",imod); - } - - if (ret==OK) { - -#ifdef VERBOSE - printf("trimming module %d mode %d, parameters %d %d \n",imod,mode, par1, par2); -#endif - - if (differentClients==1 && lockStatus==1 ) { - ret=FAIL; - sprintf(mess,"Detector locked by %s\n",lastClientIP); - } else { - - if (ret==OK) { - switch(mode) { - case NOISE_TRIMMING: - case BEAM_TRIMMING: - case IMPROVE_TRIMMING: - case FIXEDSETTINGS_TRIMMING: - if (myDetectorType==MYTHEN) { - retval=executeTrimming(mode, par1, par2, imod); - break; - } - - default: - printf("Unknown trimming mode %d\n",mode); - sprintf(mess,"Unknown trimming mode %d\n",mode); - ret=FAIL; - } - } - } - } - - if (ret!=OK) { - sprintf(mess,"can't set execute trimming\n"); - ret=FAIL; - } else if (retval>0) { - sprintf(mess,"Could not trim %d channels\n", retval); - ret=FAIL; - } else if (differentClients) - ret=FORCE_UPDATE; - - n = sendDataOnly(file_des,&ret,sizeof(ret)); - if (ret==FAIL) { - n = sendDataOnly(file_des,mess,sizeof(mess)); - } - - return ret; -} - - -int lock_server(int file_des) { - - - int n; - int ret=OK; - - int lock; - n = receiveDataOnly(file_des,&lock,sizeof(lock)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - printf("Error reading from socket (lock)\n"); - ret=FAIL; - } - if (lock>=0) { - if (lockStatus==0 || strcmp(lastClientIP,thisClientIP)==0 || strcmp(lastClientIP,"none")==0) { - lockStatus=lock; - strcpy(lastClientIP,thisClientIP); - } else { - ret=FAIL; - sprintf(mess,"Server already locked by %s\n", lastClientIP); - } - } - if (differentClients && ret==OK) - ret=FORCE_UPDATE; - - n = sendDataOnly(file_des,&ret,sizeof(ret)); - if (ret==FAIL) { - n = sendDataOnly(file_des,mess,sizeof(mess)); - } else - n = sendDataOnly(file_des,&lockStatus,sizeof(lockStatus)); - - return ret; - -} - -int set_port(int file_des) { - int n; - int ret=OK; - int sd=-1; - - enum portType p_type; /** data? control? stop? Unused! */ - int p_number; /** new port number */ - - n = receiveDataOnly(file_des,&p_type,sizeof(p_type)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - printf("Error reading from socket (ptype)\n"); - ret=FAIL; - } - - n = receiveDataOnly(file_des,&p_number,sizeof(p_number)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - printf("Error reading from socket (pnum)\n"); - ret=FAIL; - } - if (differentClients==1 && lockStatus==1 ) { - ret=FAIL; - sprintf(mess,"Detector locked by %s\n",lastClientIP); - } else { - if (p_number<1024) { - sprintf(mess,"Too low port number %d\n", p_number); - printf("\n"); - ret=FAIL; - } - - printf("set port %d to %d\n",p_type, p_number); - - sd=bindSocket(p_number); - } - if (sd>=0) { - ret=OK; - if (differentClients ) - ret=FORCE_UPDATE; - } else { - ret=FAIL; - sprintf(mess,"Could not bind port %d\n", p_number); - printf("Could not bind port %d\n", p_number); - if (sd==-10) { - sprintf(mess,"Port %d already set\n", p_number); - printf("Port %d already set\n", p_number); - - } - } - - n = sendDataOnly(file_des,&ret,sizeof(ret)); - if (ret==FAIL) { - n = sendDataOnly(file_des,mess,sizeof(mess)); - } else { - n = sendDataOnly(file_des,&p_number,sizeof(p_number)); - closeConnection(file_des); - exitServer(sockfd); - sockfd=sd; - - } - - return ret; - -} - -int get_last_client_ip(int file_des) { - int ret=OK; - if (differentClients ) - ret=FORCE_UPDATE; - sendDataOnly(file_des,&ret,sizeof(ret)); - sendDataOnly(file_des,lastClientIP,sizeof(lastClientIP)); - - return ret; - -} - - -int send_update(int file_des) { - - int ret=OK; - enum detectorSettings t; - int thr, n; - // int it; - int64_t retval;/*, tns=-1;*/ - int nm; - - - sendDataOnly(file_des,lastClientIP,sizeof(lastClientIP)); - nm=setNMod(-1,X); - sendDataOnly(file_des,&nm,sizeof(nm)); - nm=setNMod(-1,Y); - sendDataOnly(file_des,&nm,sizeof(nm)); - nm=setDynamicRange(-1); - sendDataOnly(file_des,&nm,sizeof(nm)); - - sendDataOnly(file_des,&dataBytes,sizeof(dataBytes)); - - t=setSettings(GET_SETTINGS, -1); - sendDataOnly(file_des,&t,sizeof(t)); - thr=getThresholdEnergy(-1); - sendDataOnly(file_des,&thr,sizeof(thr)); - /*retval=setFrames(tns);*/ - sendDataOnly(file_des,&retval,sizeof(int64_t)); - /*retval=setExposureTime(tns);*/ - sendDataOnly(file_des,&retval,sizeof(int64_t)); - /*retval=setPeriod(tns);*/ - sendDataOnly(file_des,&retval,sizeof(int64_t)); - /*retval=setDelay(tns);*/ - sendDataOnly(file_des,&retval,sizeof(int64_t)); - /*retval=setGates(tns);*/ - sendDataOnly(file_des,&retval,sizeof(int64_t)); - /*retval=setProbes(tns);*/ - sendDataOnly(file_des,&retval,sizeof(int64_t)); - /*retval=setTrains(tns);*/ - sendDataOnly(file_des,&retval,sizeof(int64_t)); - - if (lockStatus==0) { - strcpy(lastClientIP,thisClientIP); - } - - return ret; - - -} - - -int update_client(int file_des) { - - int ret=OK; - sendDataOnly(file_des,&ret,sizeof(ret)); - return send_update(file_des); - - - -} - - -int set_master(int file_des) { - - enum masterFlags retval=GET_MASTER; - enum masterFlags arg; - int n; - int ret=OK; - // int regret=OK; - - - sprintf(mess,"can't set master flags\n"); - - - n = receiveDataOnly(file_des,&arg,sizeof(arg)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - - -#ifdef VERBOSE - printf("setting master flags to %d\n",arg); -#endif - - if (differentClients==1 && lockStatus==1 && (int)arg!=(int)GET_READOUT_FLAGS) { - ret=FAIL; - sprintf(mess,"Detector locked by %s\n",lastClientIP); - } else { - retval=setMaster(arg); - - } - if (retval==GET_MASTER) { - ret=FAIL; - } - n = sendDataOnly(file_des,&ret,sizeof(ret)); - if (ret==FAIL) { - n = sendDataOnly(file_des,mess,sizeof(mess)); - } else { - n = sendDataOnly(file_des,&retval,sizeof(retval)); - } - return ret; -} - - - - - - -int set_synchronization(int file_des) { - - enum synchronizationMode retval=GET_SYNCHRONIZATION_MODE; - enum synchronizationMode arg; - int n; - int ret=OK; - //int regret=OK; - - - sprintf(mess,"can't set synchronization mode\n"); - - - n = receiveDataOnly(file_des,&arg,sizeof(arg)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } -#ifdef VERBOSE - printf("setting master flags to %d\n",arg); -#endif - - if (differentClients==1 && lockStatus==1 && (int)arg!=(int)GET_READOUT_FLAGS) { - ret=FAIL; - sprintf(mess,"Detector locked by %s\n",lastClientIP); - } else { - retval=setSynchronization(arg); - } - if (retval==GET_SYNCHRONIZATION_MODE) { - ret=FAIL; - } - n = sendDataOnly(file_des,&ret,sizeof(ret)); - if (ret==FAIL) { - n = sendDataOnly(file_des,mess,sizeof(mess)); - } else { - n = sendDataOnly(file_des,&retval,sizeof(retval)); - } - return ret; -} - - - - - - - - -int configure_mac(int file_des) { - - int retval; - int ret=OK; - char arg[3][50]; - int n; - - int imod=0;//should be in future sent from client as -1, arg[2] - int ipad; - long long int imacadd; - long long int iservermacadd; - - sprintf(mess,"Can't configure MAC\n"); - - - n = receiveDataOnly(file_des,arg,sizeof(arg)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - - sscanf(arg[0], "%x", &ipad); - sscanf(arg[1], "%llx", &imacadd); - sscanf(arg[2], "%llx", &iservermacadd); - - - - if (imod>=getTotalNumberOfModules()) { - ret=FAIL; - sprintf(mess,"Module number out of range %d\n",imod); - } - - -#ifdef VERBOSE - int i; - printf("\ndigital_test_bit in server %d\t",digitalTestBit); - printf("\nipadd %x\t",ipad); - printf("destination ip is %d.%d.%d.%d = 0x%x \n",(ipad>>24)&0xff,(ipad>>16)&0xff,(ipad>>8)&0xff,(ipad)&0xff,ipad); - printf("macad:%llx\n",imacadd); - for (i=0;i<6;i++) - printf("mac adress %d is 0x%x \n",6-i,(unsigned int)(((imacadd>>(8*i))&0xFF))); - printf("server macad:%llx\n",iservermacadd); - for (i=0;i<6;i++) - printf("server mac adress %d is 0x%x \n",6-i,(unsigned int)(((iservermacadd>>(8*i))&0xFF))); - printf("\n"); -#endif - - - - -#ifdef VERBOSE - printf("Configuring MAC of module %d\n", imod); -#endif - - if (ret==OK) { - /*retval=configureMAC(ipad,imacadd,iservermacadd,digitalTestBit);*/ - if(retval==-1) ret=FAIL; - } - -#ifdef VERBOSE - printf("Configured MAC with retval %d\n", retval); -#endif - if (ret==FAIL) { - printf("configuring MAC of mod %d failed\n", imod); - } - - - 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)); - } else { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } - - /*return ok/fail*/ - return ret; - -} - - - -int load_image(int file_des) { - int retval; - int ret=OK; - int n; - enum imageType index; - char ImageVals[dataBytes]; - - sprintf(mess,"Loading image failed\n"); - - n = receiveDataOnly(file_des,&index,sizeof(index)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - - n = receiveDataOnly(file_des,ImageVals,dataBytes); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - if (ret==OK) { - if (differentClients==1 && lockStatus==1) { - ret=FAIL; - sprintf(mess,"Detector locked by %s\n",lastClientIP); - } - - - switch (index) { - case DARK_IMAGE : -#ifdef VERBOSE - printf("Loading Dark image\n"); -#endif - case GAIN_IMAGE : -#ifdef VERBOSE - printf("Loading Gain image\n"); -#endif - if (myDetectorType==GOTTHARD) { - retval=loadImage(index,ImageVals); - if (retval==-1) - ret = FAIL; - } - default: - printf("Unknown index %d\n",index); - sprintf(mess,"Unknown index %d\n",index); - ret=FAIL; - break; - } - - } - - if(ret==OK){ - 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)); - } else { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } - - /*return ok/fail*/ - return ret; -} - - - - - -int read_counter_block(int file_des) { - - int ret=OK; - int n; - int startACQ; - //char *retval=NULL; - char CounterVals[NCHAN*NCHIP]; - - sprintf(mess,"Read counter block failed\n"); - - n = receiveDataOnly(file_des,&startACQ,sizeof(startACQ)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - - if (ret==OK) { - if (differentClients==1 && lockStatus==1) { - ret=FAIL; - sprintf(mess,"Detector locked by %s\n",lastClientIP); - } else{ - ret=readCounterBlock(startACQ,CounterVals); -#ifdef VERBOSE - int i; - for(i=0;i<6;i++) - printf("%d:%d\t",i,CounterVals[i]); -#endif - } - } - - if(ret!=FAIL){ - 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,CounterVals,dataBytes);//1280*2 - } else { - n += sendDataOnly(file_des,mess,sizeof(mess)); - } - - /*return ok/fail*/ - return ret; -} - - - - - -int reset_counter_block(int file_des) { - - int ret=OK; - int n; - int startACQ; - - sprintf(mess,"Reset counter block failed\n"); - - n = receiveDataOnly(file_des,&startACQ,sizeof(startACQ)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - - if (ret==OK) { - if (differentClients==1 && lockStatus==1) { - ret=FAIL; - sprintf(mess,"Detector locked by %s\n",lastClientIP); - } else - ret=resetCounterBlock(startACQ); - } - - if(ret==OK){ - if (differentClients) - ret=FORCE_UPDATE; - } - - /* send answer */ - /* send OK/failed */ - n = sendDataOnly(file_des,&ret,sizeof(ret)); - if (ret==FAIL) - n += sendDataOnly(file_des,mess,sizeof(mess)); - - /*return ok/fail*/ - return ret; -} - - - diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_funcs.h b/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_funcs.h deleted file mode 100755 index 439d3e29c..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_funcs.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef SERVER_FUNCS_H -#define SERVER_FUNCS_H - - -#include "sls_detector_defs.h" - -#include - - - - -int sockfd; - -int function_table(); - -int swap_int32(int val); -int64_t swap_int64(int64_t val); - -int decode_function(int); - -//if b>0 all the detector must be initialized, otherwise it is just the stop server -int init_detector(int); - -int M_nofunc(int); -int exit_server(int); - - - - - // General purpose functions -int get_detector_type(int); -int set_number_of_modules(int); -int get_max_number_of_modules(int); - - -int exec_command(int); -int set_external_signal_flag(int); -int set_external_communication_mode(int); -int get_id(int); -int digital_test(int); -int write_register(int); -int read_register(int); -int set_dac(int); -int get_adc(int); -int set_channel(int); -int set_chip(int); -int set_module(int); -int get_channel(int); -int get_chip(int); -int get_module(int); - -int get_threshold_energy(int); -int set_threshold_energy(int); -int set_settings(int); -int start_acquisition(int); -int stop_acquisition(int); -int start_readout(int); -int get_run_status(int); -int read_frame(int); -int read_all(int); -int start_and_read_all(int); -int set_timer(int); -int get_time_left(int); -int set_dynamic_range(int); -int set_roi(int); -int get_roi(int); -int set_speed(int); -int set_readout_flags(int); -int execute_trimming(int); -int lock_server(int); -int set_port(int); -int get_last_client_ip(int); -int set_master(int); -int set_synchronization(int); -int configure_mac(int); -int load_image(int); -int read_counter_block(int); -int reset_counter_block(int); -int update_client(int); -int send_update(int); - -#endif diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetector_firmware.c b/slsDetectorSoftware/eigerDetectorServer/slsDetector_firmware.c deleted file mode 100644 index 773c8343a..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetector_firmware.c +++ /dev/null @@ -1,387 +0,0 @@ - - -#include "sls_detector_defs.h" - -#include "slsDetector_firmware.h" -#include "slsDetectorServer_defs.h" -#include "registers.h" - - -#include -#include - -#include -#include //PROT_READ,PROT_WRITE,MAP_FILE,MAP_SHARED,MAP_FAILED -#include //O_RDWR - - -u_int32_t CSP0BASE; -u_int32_t fifo_control_reg; - - -int nModBoard; -int nModY = NMAXMOD; -int nModX = NMAXMOD; -int dynamicRange= DYNAMIC_RANGE; -int dataBytes = NMAXMOD*NCHIP*NCHAN*2; -int masterMode = NO_MASTER; -int syncMode = NO_SYNCHRONIZATION; -int timingMode = AUTO_TIMING; - - -#ifdef SLS_DETECTOR_FUNCTION_LIST -extern const int nChans; -extern const int nChips; -extern const int nDacs; -extern const int nAdcs; -#endif -#ifndef SLS_DETECTOR_FUNCTION_LIST -const int nChans = NCHAN; -const int nChips = NCHIP; -const int nDacs = NDAC; -const int nAdcs = NADC; -#endif - - - -int64_t dummy=0; - -/* Gerd example - if ((fd=open("/dev/mem", O_RDWR)) < 0){ - printf("Cant find /dev/mem!\n"); - return FAIL; - } - printf("/dev/mem opened\n"); - - void *plb_ll_fifo_ptr; - plb_ll_fifo_ptr = mmap(0, MEM_SIZE, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, CSP0); - if (plb_ll_fifo_ptr == MAP_FAILED){ - printf("\nCan't map memmory area!!\n"); - return FAIL; - } - CSP0BASE = (u_int32_t) plb_ll_fifo_ptr; - //plb_ll_fifo_ctrl_reg = 0; -*/ - -int mapCSP0(void) { - int fd; - printf("Mapping memory\n"); - -#ifdef VIRTUAL - CSP0BASE = (u_int32_t)malloc(MEM_SIZE); - printf("memory allocated\n"); -#else - - if ((fd=open("/dev/mem", O_RDWR | O_SYNC)) < 0){ - printf("Cant find /dev/mem!\n"); - return FAIL; - } - printf("/dev/mem opened\n"); - - CSP0BASE = (u_int32_t)mmap(0, MEM_SIZE, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, fd, CSP0); - if (CSP0BASE == (u_int32_t)MAP_FAILED) { - printf("\nCan't map memmory area!!\n"); - return FAIL; - } -#endif - printf("CSPOBASE is 0x%x \n",CSP0BASE); - printf("CSPOBASE=from %08x to %x\n",CSP0BASE,CSP0BASE+MEM_SIZE); - - fifo_control_reg = 0; - - return OK; -} - - - - - -u_int32_t bus_w(u_int32_t offset, u_int32_t data) { - __asm__ volatile ("stw %0,0(%1); eieio"::"r" (data), "b"(CSP0BASE+4*offset)); - return OK; -} - - - -u_int32_t bus_r(u_int32_t offset) { - u_int32_t ptr1; - __asm__ volatile ("eieio; lwz %0,0(%1)":"=r" (ptr1):"b"(CSP0BASE+4*offset)); - return ptr1; -} - - - - - - - - - -int fifoReset(){ - - u_int32_t mask = FIFOCNTRL_RESET_MASK; - - fifo_control_reg |= mask; - //printf("CTRL Register bits: 0x%08x\n",fifo_control_reg); - - bus_w(FIFO_CNTRL_REG,fifo_control_reg); - bus_w(FIFO_CNTRL_REG,fifo_control_reg); - bus_w(FIFO_CNTRL_REG,fifo_control_reg); - bus_w(FIFO_CNTRL_REG,fifo_control_reg); - - fifo_control_reg &= (~mask); - bus_w(FIFO_CNTRL_REG,fifo_control_reg); - - printf("fifo has been reset\n\n"); - - return OK; -} - - - - -int fifoTest(void){ - - int buffer_length = 256; - int rec_buffer_length = 4096; - char cmd[] = "help"; - unsigned int buffer[buffer_length]; - unsigned int rec_buffer[rec_buffer_length]; - unsigned int send_len; - int rec_len; - char *char_ptr; - char_ptr = (char *)buffer; - - //fill the buffer with numbers for(i=0; i < BUFF_LEN; i++) {char_ptr[i]=i+1;} - - //sending command - strcpy(char_ptr,cmd); - send_len = strlen(cmd); - fifoSend(char_ptr,send_len); - - // printf("status : 0x%08x \n",PLB_LL_fifo_get_status_vector()); - usleep(10000); - - do{ - rec_len = fifoReceive(rec_buffer,rec_buffer_length); - if (rec_len > 0){ - //printf("receive buffer 0x%08x length: %i\n",rec_buffer,rec_len); - char_ptr = (char*) &rec_buffer[0]; - char_ptr[rec_len]=0; - printf(char_ptr); - } - } while(rec_len > 0); - - return OK; -} - - -// note: buffer must be word (4 byte) aligned, frameLength in byte -int fifoSend(void *buffer, unsigned int frameLength){ - - int vacancy=0; - int i; - int words_send = 0; - int last_word; - unsigned int *word_ptr; - unsigned int val,mask; - u_int32_t status; - - if (frameLength < 1) - return -1; - - /**4?*/ - last_word = (frameLength-1)/4; - word_ptr = (unsigned int *)buffer; - - /*what does this do*/ - while (words_send <= last_word){ - - //wait for Fifo to be empty again - while (!vacancy){ - status = bus_r(FIFO_STATUS_REG); - if(!(status & FIFOSTATUS_ALMOST_FULL_BIT)) - vacancy = 1; - } - - /**fifo threshold words?*/ - for (i=0; ((i>>> SOF\n\r"); - buffer_ptr = 0;/**not needed */ - sof = 1; - } - - - //read from fifo - fifo_val = bus_r(FIFO_FIFO_REG); - - - if ((buffer_ptr > 0) || sof){ - if ( (bufflen >> 2) > buffer_ptr) - word_ptr[buffer_ptr++] = fifo_val; //write to buffer - else{ - buffer_ptr = 0; - return -2; // buffer overflow - } - - if (status & FIFOSTATUS_EOF_BIT){ - len = (buffer_ptr << 2) -3 + ( (status & FIFOSTATUS_REM_MASK)>>FIFOSTATUS_REM_OFFSET ); - // printf(">>>>status=0x%08x EOF len = %d \n\r\n\r",status, len); - buffer_ptr = 0; - return len; - } - - } - } - } - while(!(status & FIFOSTATUS_EMPTY_BIT)); - - - return OK; -} - - - - - - -int64_t set64BitReg(int64_t value, int aLSB, int aMSB){ - int64_t v64; - u_int32_t vLSB,vMSB; - if (value!=-1) { - vLSB=value&(0xffffffff); - bus_w(aLSB,vLSB); - v64=value>> 32; - vMSB=v64&(0xffffffff); - bus_w(aMSB,vMSB); - } - return get64BitReg(aLSB, aMSB); - -} - -int64_t get64BitReg(int aLSB, int aMSB){ - int64_t v64; - u_int32_t vLSB,vMSB; - vLSB=bus_r(aLSB); - vMSB=bus_r(aMSB); - v64=vMSB; - v64=(v64<<32) | vLSB; - return v64; -} - - -int64_t setFrames(int64_t value){//dummy = value;return dummy; - return set64BitReg(value, SET_FRAMES_LSB_REG, SET_FRAMES_MSB_REG); -} -int64_t getFrames(){//return dummy; - return get64BitReg(GET_FRAMES_LSB_REG, GET_FRAMES_MSB_REG); -} - - -int64_t setExposureTime(int64_t value){ - /* time is in ns */ - if (value!=-1) - value*=(int64_t)(1E-9*CLK_FREQ); - return (int64_t)(set64BitReg(value,SET_EXPTIME_LSB_REG, SET_EXPTIME_MSB_REG)/(1E-9*CLK_FREQ)); -} -int64_t getExposureTime(){ - return (int64_t)(get64BitReg(GET_EXPTIME_LSB_REG, GET_EXPTIME_MSB_REG)/(1E-9*CLK_FREQ)); -} - - -int64_t setGates(int64_t value){ - return set64BitReg(value, SET_GATES_LSB_REG, SET_GATES_MSB_REG); -} -int64_t getGates(){ - return get64BitReg(GET_GATES_LSB_REG, GET_GATES_MSB_REG); -} - - -int64_t setPeriod(int64_t value){ - /* time is in ns */ - if (value!=-1) - value*=(int64_t)(1E-9*CLK_FREQ); - return (int64_t)(set64BitReg(value,SET_PERIOD_LSB_REG, SET_PERIOD_MSB_REG)/(1E-9*CLK_FREQ)); -} -int64_t getPeriod(){ - return (int64_t)(get64BitReg(GET_PERIOD_LSB_REG, GET_PERIOD_MSB_REG)/(1E-9*CLK_FREQ)); -} - - -int64_t setDelay(int64_t value){ - /* time is in ns */ - if (value!=-1) { - value*=(int64_t)(1E-9*CLK_FREQ); - } - return (int64_t)(set64BitReg(value,SET_DELAY_LSB_REG, SET_DELAY_MSB_REG)/(1E-9*CLK_FREQ)); -} -int64_t getDelay(){ - return (int64_t)(get64BitReg(GET_DELAY_LSB_REG, GET_DELAY_MSB_REG)/(1E-9*CLK_FREQ)); -} - - -int64_t setTrains(int64_t value){ - return set64BitReg(value, SET_TRAINS_LSB_REG, SET_TRAINS_MSB_REG); -} -int64_t getTrains(){ - return get64BitReg(GET_TRAINS_LSB_REG, GET_TRAINS_MSB_REG); -} - - - -int64_t setProbes(int64_t value){ - return 0; -} -int64_t getProbes(){ - return 0; -} - - diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetector_firmware.h b/slsDetectorSoftware/eigerDetectorServer/slsDetector_firmware.h deleted file mode 100644 index 343ebb4f5..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetector_firmware.h +++ /dev/null @@ -1,179 +0,0 @@ -/* - * slsDetector_firmware.h - * - * Created on: Jan 24, 2013 - * Author: l_maliakal_d - */ - -#ifndef SLSDETECTOR_FIRMWARE_H_ -#define SLSDETECTOR_FIRMWARE_H_ - - -#include "sls_detector_defs.h" - -#include - - - -//memory -int mapCSP0(void); - -u_int32_t bus_w(u_int32_t offset, u_int32_t data); -u_int32_t bus_r(u_int32_t offset); - -int fifoReset(); -int fifoTest(void); - -int fifoSend(void *buffer, unsigned int frame_len); -int fifoReceive(void *buffer, unsigned int bufflen); - - - -//Acquisition Parameters -int64_t set64BitReg(int64_t value, int aLSB, int aMSB); -int64_t get64BitReg(int aLSB, int aMSB); - -int64_t setFrames(int64_t value); -int64_t getFrames(); - -int64_t setExposureTime(int64_t value); -int64_t getExposureTime(); - -int64_t setGates(int64_t value); -int64_t getGates(); - -int64_t setDelay(int64_t value); -int64_t getDelay(); - -int64_t setPeriod(int64_t value); -int64_t getPeriod(); - -int64_t setTrains(int64_t value); -int64_t getTrains(); - -int64_t setProbes(int64_t value); -int64_t getProbes(); - - -/* -u_int16_t bus_w16(u_int32_t offset, u_int16_t data);//aldos function -u_int32_t bus_r(u_int32_t offset); - -int setPhaseShiftOnce(); -int cleanFifo(); -int setDAQRegister(int adcval); - -u_int32_t putout(char *s, int modnum); -u_int32_t readin(int modnum); -u_int32_t setClockDivider(int d); -u_int32_t getClockDivider(); -u_int32_t setSetLength(int d); -u_int32_t getSetLength(); -u_int32_t setWaitStates(int d); -u_int32_t getWaitStates(); -u_int32_t setTotClockDivider(int d); -u_int32_t getTotClockDivider(); -u_int32_t setTotDutyCycle(int d); -u_int32_t getTotDutyCycle(); - -u_int32_t setExtSignal(int d, enum externalSignalFlag mode); -int getExtSignal(int d); -u_int32_t setFPGASignal(int d, enum externalSignalFlag mode); -int getFPGASignal(int d); -int setTiming(int t); - - -int setConfigurationRegister(int d); -int setToT(int d); -int setContinousReadOut(int d); -int startReceiver(int d); - -int setDACRegister(int idac, int val, int imod); - -int getTemperature(int tempSensor,int imod); -int initHighVoltage(int val,int imod); -int initConfGain(int isettings,int val,int imod); - -int configureMAC(int ipad, long long int macad, long long int detectormacadd, int detipad, int ival, int adc,int udpport); -int getAdcConfigured(); - -u_int64_t getDetectorNumber(); -u_int32_t getFirmwareVersion(); -int testFifos(void); -u_int32_t testFpga(void); -u_int32_t testRAM(void); -int testBus(void); -int setDigitalTestBit(int ival); - - -int64_t getProgress(); -int64_t setProgress(); - -int64_t getActualTime(); -int64_t getMeasurementTime(); - - -u_int32_t runBusy(void); -u_int32_t runState(void); -u_int32_t dataPresent(void); - - -int startStateMachine(); -int stopStateMachine(); -int startReadOut(); -u_int32_t fifoReset(void); -u_int32_t fifoReadCounter(int fifonum); -u_int32_t fifoReadStatus(); - - -u_int32_t fifo_full(void); - - - -u_int32_t* fifo_read_event(); -u_int32_t* decode_data(int* datain); -//u_int32_t move_data(u_int64_t* datain, u_int64_t* dataout); -int setDynamicRange(int dr); -int getDynamicRange(); -int getNModBoard(); -int setNMod(int n); -int setStoreInRAM(int b); -int allocateRAM(); -int clearRAM(); - - -int setMaster(int f); -int setSynchronization(int s); - -int loadImage(int index, short int ImageVals[]); -int readCounterBlock(int startACQ, short int CounterVals[]); -int resetCounterBlock(int startACQ); - - -u_int32_t setNBits(u_int32_t); -u_int32_t getNBits(); -*/ - -/* -//move to mcb_funcs? - -int readOutChan(int *val); -u_int32_t getModuleNumber(int modnum); -int testShiftIn(int imod); -int testShiftOut(int imod); -int testShiftStSel(int imod); -int testDataInOut(int num, int imod); -int testExtPulse(int imod); -int testExtPulseMux(int imod, int ow); -int testDataInOutMux(int imod, int ow, int num); -int testOutMux(int imod); -int testFpgaMux(int imod); -int calibration_sensor(int num, int *values, int *dacs) ; -int calibration_chip(int num, int *values, int *dacs); -*/ - - - - - -#endif /* SLSDETECTOR_FIRMWARE_H_ */ diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetector_stopServer.c b/slsDetectorSoftware/eigerDetectorServer/slsDetector_stopServer.c deleted file mode 100755 index 39f651f0f..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetector_stopServer.c +++ /dev/null @@ -1,46 +0,0 @@ -/* A simple server in the internet domain using TCP - The port number is passed as an argument */ -#include "communication_funcs.h" - -#include "slsDetectorFunctionList.h"/*#include "slsDetector_firmware.h" for the time being*/ -#include "slsDetectorServer_defs.h" - -//#include -//#include - -int sockfd; - -int main(int argc, char *argv[]) -{ - int portno; - int retval=0; - // int sd,fd; - - portno = DEFAULT_PORTNO; - - - bindSocket(portno); //defined in communication_funcs - if (getServerError()) //defined in communication_funcs - return -1; - - - - /* waits for connection */ - while(retval!=GOODBYE) { -#ifdef VERBOSE - printf("\n"); -#endif -#ifdef VERY_VERBOSE - printf("Stop server: waiting for client call\n"); -#endif - acceptConnection(); //defined in communication_funcs - retval=stopStateMachine();//defined in slsDetectorFirmare_funcs - closeConnection(); //defined in communication_funcs - } - - exitServer(); //defined in communication_funcs - printf("Goodbye!\n"); - - return 0; -} - diff --git a/slsDetectorSoftware/eigerDetectorServer/sls_detector_defs.h b/slsDetectorSoftware/eigerDetectorServer/sls_detector_defs.h deleted file mode 100755 index ca52b0c27..000000000 --- a/slsDetectorSoftware/eigerDetectorServer/sls_detector_defs.h +++ /dev/null @@ -1,554 +0,0 @@ -#ifndef SLS_DETECTOR_DEFS_H -#define SLS_DETECTOR_DEFS_H - - -#ifdef __CINT__ -#define MYROOT -#define __cplusplus -#endif - -#include - -/** default maximum string length */ -#define MAX_STR_LENGTH 1000 -/** default maximum string length */ -#define MAX_SCAN_STEPS 2000 -/** maxmimum number of modules per controller*/ -#define MAXMODS 24 -/** maxmimum number of detectors ina multidetector structure*/ -#define MAXDET 100 -/** header length for data :gotthard*/ -#define HEADERLENGTH 12 - -/** maximum rois */ -#define MAX_ROIS 100 - -typedef double double32_t; -typedef float float32_t; -typedef int int32_t; -typedef char mystring[MAX_STR_LENGTH]; -typedef double mysteps[MAX_SCAN_STEPS]; - - -#ifdef DACS_INT -typedef int dacs_t; -#else -typedef float dacs_t; -#endif - -#define DEFAULT_DET_MAC "00:aa:bb:cc:dd:ee" -#define DEFAULT_DET_IP "129.129.202.46" - -#define MAX_FRAMES_PER_FILE 20000 -#define SHORT_MAX_FRAMES_PER_FILE 100000 - -/** - \file sls_detector_defs.h -This file contains all the basic definitions common to the slsDetector class -and to the server programs running on the detector - - - * @author Anna Bergamaschi - * @version 0.1alpha (any string) - * @see slsDetector - -$Revision: 464 $ - -*/ - - -/** get flag form most functions */ -#define GET_FLAG -1 - -#ifdef MYROOT - -/** @short class containing all the structures, constants and enum definitions */ -class slsDetectorDefs { - - public: - - slsDetectorDefs(){}; - -#endif - - - enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, enCalLog, angCalLog, MAX_ACTIONS}; - - - -/** - @short structure for a detector channel - - should not be used by unexperienced users - - \see ::channelRegisterBit -*/ - typedef struct { - int chan; /**< is the channel number */ - int chip; /**< is the chip number */ - int module; /**< is the module number */ - int64_t reg; /**< is the is the channel register (e.g. trimbits, calibration enable, comparator enable...) */ - } sls_detector_channel; - - /** - @short structure for a detector chip - - should not be used by unexperienced users - \see ::chipRegisterBit ::channelRegisterBit -*/ - typedef struct { - int chip; /**< is the chip number */ - int module; /**< is the module number */ - int nchan; /**< is the number of channels in the chip */ - int reg; /**