diff --git a/slsDetectorSoftware/slsDetectorServer/Makefile b/slsDetectorSoftware/slsDetectorServer/Makefile deleted file mode 100644 index 4b373026d..000000000 --- a/slsDetectorSoftware/slsDetectorServer/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -CC =gcc -CLAGS += -Wall -DVIRTUAL -DDACS_INT -DSLS_DETECTOR_FUNCTION_LIST -DEIGERD -LDLIBS += -lm - -PROGS = slsDetectorServer -DESTDIR ?= bin -INSTMODE = 0777 - -SRC_CLNT = slsDetectorServer.c slsDetectorServer_funcs.c communication_funcs.c slsDetector_firmware.c slsDetectorFunctionList.c -OBJS = $(SRC_CLNT:.cpp=.o) - - - -all: clean $(PROGS) - -boot: $(OBJS) - -$(PROGS): - echo $(OBJS) - mkdir -p $(DESTDIR) - $(CC) $(SRC_CLNT) $(CLAGS) $(LDLIBS) -o $@ - mv $(PROGS) $(DESTDIR) - - -clean: - rm -rf $(DESTDIR)/$(PROGS) *.o diff --git a/slsDetectorSoftware/slsDetectorServer/communication_funcs.c b/slsDetectorSoftware/slsDetectorServer/communication_funcs.c deleted file mode 120000 index 87a4f95d1..000000000 --- a/slsDetectorSoftware/slsDetectorServer/communication_funcs.c +++ /dev/null @@ -1 +0,0 @@ -../commonFiles/communication_funcs.c \ No newline at end of file diff --git a/slsDetectorSoftware/slsDetectorServer/communication_funcs.h b/slsDetectorSoftware/slsDetectorServer/communication_funcs.h deleted file mode 120000 index f220903b2..000000000 --- a/slsDetectorSoftware/slsDetectorServer/communication_funcs.h +++ /dev/null @@ -1 +0,0 @@ -../commonFiles/communication_funcs.h \ No newline at end of file diff --git a/slsDetectorSoftware/slsDetectorServer/registers.h b/slsDetectorSoftware/slsDetectorServer/registers.h deleted file mode 100644 index abd9c78c9..000000000 --- a/slsDetectorSoftware/slsDetectorServer/registers.h +++ /dev/null @@ -1,53 +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 0x90000000 -#define MEM_SIZE 0xFFFFFFF - - -#define STATUS_REG 0x0a000 - -#define SET_FRAMES_LSB_REG 0x10000 -#define SET_FRAMES_MSB_REG 0x11000 -#define GET_FRAMES_LSB_REG 0x12000 -#define GET_FRAMES_MSB_REG 0x13000 - -#define SET_EXPTIME_LSB_REG 0x14000 -#define SET_EXPTIME_MSB_REG 0x15000 -#define GET_EXPTIME_LSB_REG 0x16000 -#define GET_EXPTIME_MSB_REG 0x17000 - -#define SET_GATES_LSB_REG 0x18000 -#define SET_GATES_MSB_REG 0x19000 -#define GET_GATES_LSB_REG 0x1a000 -#define GET_GATES_MSB_REG 0x1b000 - -#define SET_PERIOD_LSB_REG 0x1c000 -#define SET_PERIOD_MSB_REG 0x1d000 -#define GET_PERIOD_LSB_REG 0x1e000 -#define GET_PERIOD_MSB_REG 0x1f000 - -#define SET_DELAY_LSB_REG 0x20000 -#define SET_DELAY_MSB_REG 0x21000 -#define GET_DELAY_LSB_REG 0x22000 -#define GET_DELAY_MSB_REG 0x23000 - -#define SET_TRAINS_LSB_REG 0x24000 -#define SET_TRAINS_MSB_REG 0x25000 -#define GET_TRAINS_LSB_REG 0x26000 -#define GET_TRAINS_MSB_REG 0x27000 - - - - - -#endif /* REGISTERS_H_ */ diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.c b/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.c deleted file mode 100644 index ec8817edc..000000000 --- a/slsDetectorSoftware/slsDetectorServer/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=malloc(n*sizeof(sls_detector_module)); - detectorChips=malloc(n*NCHIP*sizeof(int)); - detectorChans=malloc(n*NCHIP*NCHAN*sizeof(int)); - detectorDacs=malloc(n*NDAC*sizeof(int)); - detectorAdcs=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 OK; -} - -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 -1; -} - - -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 -1; -} - - - - - -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=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 ret; -} - - - -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/slsDetectorServer/slsDetectorFunctionList.h b/slsDetectorSoftware/slsDetectorServer/slsDetectorFunctionList.h deleted file mode 100644 index 0da50207f..000000000 --- a/slsDetectorSoftware/slsDetectorServer/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/slsDetectorServer/slsDetectorServer.c b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer.c deleted file mode 100755 index 867ad426a..000000000 --- a/slsDetectorSoftware/slsDetectorServer/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/slsDetectorServer/slsDetectorServer_defs.h b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_defs.h deleted file mode 100644 index f1fb51e5f..000000000 --- a/slsDetectorSoftware/slsDetectorServer/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/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c deleted file mode 100755 index 3c3d07fd1..000000000 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c +++ /dev/null @@ -1,2819 +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"); -#endif - - mapCSP0(); - //only for control server - if(b){ -#ifdef SLS_DETECTOR_FUNCTION_LIST - initializeDetector(); - //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 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)); - if (n <= 0) { - printf("ERROR reading from socket %d, %d %d\n", n, fnum, file_des); - return FAIL; - } -//#ifdef VERBOSE - else - printf("size of data received %d\n",n); -//#endif - -//#ifdef VERBOSE - printf( "calling function fnum = %d %x\n",fnum,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 */ - 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=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=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=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=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=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=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=malloc(getNumberOfChipsPerModule()*sizeof(int)); - int *myChan=malloc(getNumberOfChannelsPerModule()*sizeof(int)); - int *myDac=malloc(getNumberOfDACsPerModule()*sizeof(int)); - int *myAdc=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=malloc(getNumberOfChipsPerModule()*sizeof(int)); - int *myChan=malloc(getNumberOfChannelsPerModule()*sizeof(int)); - int *myDac=malloc(getNumberOfDACsPerModule()*sizeof(int)); - int *myAdc=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=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=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(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)); - if (n < 0) { - sprintf(mess,"Error reading from socket\n"); - ret=FAIL; - } - - n = receiveDataOnly(file_des,&tns,sizeof(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); - 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; - int n; - if (differentClients ) - ret=FORCE_UPDATE; - n = sendDataOnly(file_des,&ret,sizeof(ret)); - n = 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; - - - n = sendDataOnly(file_des,lastClientIP,sizeof(lastClientIP)); - nm=setNMod(-1,X); - n = sendDataOnly(file_des,&nm,sizeof(nm)); - nm=setNMod(-1,Y); - n = sendDataOnly(file_des,&nm,sizeof(nm)); - nm=setDynamicRange(-1); - n = sendDataOnly(file_des,&nm,sizeof(nm)); - - n = sendDataOnly(file_des,&dataBytes,sizeof(dataBytes)); - - t=setSettings(GET_SETTINGS, -1); - n = sendDataOnly(file_des,&t,sizeof(t)); - thr=getThresholdEnergy(-1); - n = sendDataOnly(file_des,&thr,sizeof(thr)); - /*retval=setFrames(tns);*/ - n = sendDataOnly(file_des,&retval,sizeof(int64_t)); - /*retval=setExposureTime(tns);*/ - n = sendDataOnly(file_des,&retval,sizeof(int64_t)); - /*retval=setPeriod(tns);*/ - n = sendDataOnly(file_des,&retval,sizeof(int64_t)); - /*retval=setDelay(tns);*/ - n = sendDataOnly(file_des,&retval,sizeof(int64_t)); - /*retval=setGates(tns);*/ - n = sendDataOnly(file_des,&retval,sizeof(int64_t)); - /*retval=setProbes(tns);*/ - n = sendDataOnly(file_des,&retval,sizeof(int64_t)); - /*retval=setTrains(tns);*/ - n = 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 && arg!=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_MASTER; - 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 && arg!=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/slsDetectorServer/slsDetectorServer_funcs.h b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h deleted file mode 100755 index 0475e636e..000000000 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef SERVER_FUNCS_H -#define SERVER_FUNCS_H - - -#include "sls_detector_defs.h" - -#include - - - - -int sockfd; - -int function_table(); - -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/slsDetectorServer/slsDetector_firmware.c b/slsDetectorSoftware/slsDetectorServer/slsDetector_firmware.c deleted file mode 100644 index 208379c3b..000000000 --- a/slsDetectorSoftware/slsDetectorServer/slsDetector_firmware.c +++ /dev/null @@ -1,170 +0,0 @@ - - -#include "sls_detector_defs.h" - -#include "slsDetector_firmware.h" -#include "slsDetectorServer_defs.h" -#include "registers.h" - - -#include -#include - - - -u_int32_t CSP0BASE; - - -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 - - - - -int mapCSP0(void) { - printf("Mapping memory\n"); -#ifdef VIRTUAL - CSP0BASE = (u_int32_t)malloc(MEM_SIZE); - printf("memory allocated\n"); -#endif - printf("CSPOBASE=from %08x to %x\n",CSP0BASE,CSP0BASE+MEM_SIZE); - - return OK; -} - - - -u_int32_t bus_w(u_int32_t offset, u_int32_t data) { - volatile u_int32_t *ptr1; - ptr1=(u_int32_t*)(CSP0BASE+offset); - *ptr1=data; - return OK; -} - - - -u_int32_t bus_r(u_int32_t offset) { - volatile u_int32_t *ptr1; - ptr1=(u_int32_t*)(CSP0BASE+offset); - return *ptr1; -} - - - - - - - - -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){ - return set64BitReg(value, SET_FRAMES_LSB_REG, SET_FRAMES_MSB_REG); -} -int64_t getFrames(){ - return get64BitReg(GET_FRAMES_LSB_REG, GET_FRAMES_MSB_REG); -} - - -int64_t setExposureTime(int64_t value){ - /* time is in ns */ - if (value!=-1) - value*=(1E-9*CLK_FREQ); - return set64BitReg(value,SET_EXPTIME_LSB_REG, SET_EXPTIME_MSB_REG)/(1E-9*CLK_FREQ); -} -int64_t getExposureTime(){ - return 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*=(1E-9*CLK_FREQ); - return set64BitReg(value,SET_PERIOD_LSB_REG, SET_PERIOD_MSB_REG)/(1E-9*CLK_FREQ); -} -int64_t getPeriod(){ - return 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*=(1E-9*CLK_FREQ); - } - return set64BitReg(value,SET_DELAY_LSB_REG, SET_DELAY_MSB_REG)/(1E-9*CLK_FREQ); -} -int64_t getDelay(){ - return 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/slsDetectorServer/slsDetector_firmware.h b/slsDetectorSoftware/slsDetectorServer/slsDetector_firmware.h deleted file mode 100644 index 279297826..000000000 --- a/slsDetectorSoftware/slsDetectorServer/slsDetector_firmware.h +++ /dev/null @@ -1,171 +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); - - -//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/slsDetectorServer/slsDetector_stopServer.c b/slsDetectorSoftware/slsDetectorServer/slsDetector_stopServer.c deleted file mode 100755 index 1772ce2b6..000000000 --- a/slsDetectorSoftware/slsDetectorServer/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; - - - sd=bindSocket(portno); //defined in communication_funcs - if (getServerError(sd)) //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 - fd=acceptConnection(sd); //defined in communication_funcs - retval=stopStateMachine();//defined in slsDetectorFirmare_funcs - closeConnection(fd); //defined in communication_funcs - } - - exitServer(sd); //defined in communication_funcs - printf("Goodbye!\n"); - - return 0; -} - diff --git a/slsDetectorSoftware/slsDetectorServer/sls_detector_defs.h b/slsDetectorSoftware/slsDetectorServer/sls_detector_defs.h deleted file mode 120000 index c5062e03f..000000000 --- a/slsDetectorSoftware/slsDetectorServer/sls_detector_defs.h +++ /dev/null @@ -1 +0,0 @@ -../commonFiles/sls_detector_defs.h \ No newline at end of file diff --git a/slsDetectorSoftware/slsDetectorServer/sls_detector_funcs.h b/slsDetectorSoftware/slsDetectorServer/sls_detector_funcs.h deleted file mode 120000 index 844b67129..000000000 --- a/slsDetectorSoftware/slsDetectorServer/sls_detector_funcs.h +++ /dev/null @@ -1 +0,0 @@ -../commonFiles/sls_detector_funcs.h \ No newline at end of file