mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-20 02:40:03 +02:00
Gotthard class implemented
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@34 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
parent
3367bb3026
commit
ab27ab1c5d
@ -1,14 +1,12 @@
|
||||
CFLAGS= -DC_ONLY
|
||||
FLAGS=-DVERBOSE
|
||||
INCLUDES= -I commonFiles -I slsDetector -I MySocketTCP -I eigerDetector -ImythenDetector -I usersFunctions
|
||||
FLAGS=
|
||||
#-DVERBOSE
|
||||
INCLUDES= -I commonFiles -I slsDetector -I MySocketTCP -I eigerDetector -ImythenDetector -IgotthardDetector -I usersFunctions
|
||||
|
||||
#EPICSFLAGS=-D EPICS -I/usr/local/epics/base/include/ -I /usr/local/epics/base/include/os/Linux/ -L /usr/local/epics/base/lib/SL5-x86/ -Wl,-R/usr/local/epics/base/lib/SL5-x86 -lca -lCom
|
||||
|
||||
|
||||
#SRC_H= slsDetector/slsDetector.h mythenDetector/mythenDetector.h eigerDetector/eigerDetector.h MySocketTCP/MySocketTCP.h usersFunctions/usersFunctions.h commonFiles/sls_detector_defs.h
|
||||
|
||||
#mythenDetectorServer/communication_funcs.h mythenDetectorServer/firmware_funcs.h mythenDetectorServer/mcb_funcs.h mythenDetectorServer/registers.h mythenDetectorServer/server_defs.h mythenDetectorServer/server_funcs.h mythenDetectorServer/trimming_funcs.h
|
||||
|
||||
|
||||
SRC_CLNT= slsDetector/slsDetector.cpp MySocketTCP/MySocketTCP.cxx usersFunctions/usersFunctions.c mythenDetector/mythenDetector.cpp eigerDetector/eigerDetector.cpp
|
||||
SRC_CLNT= slsDetector/slsDetector.cpp MySocketTCP/MySocketTCP.cxx usersFunctions/usersFunctions.c mythenDetector/mythenDetector.cpp eigerDetector/eigerDetector.cpp gotthardDetector/gotthardDetector.cpp
|
||||
|
||||
SRC_MYTHEN_SVC = mythenDetectorServer/server.c mythenDetectorServer/server_funcs.c mythenDetectorServer/communication_funcs.c mythenDetectorServer/firmware_funcs.c mythenDetectorServer/mcb_funcs.c mythenDetectorServer/trimming_funcs.c
|
||||
#mythenDetectorServer/sharedmemory.c
|
||||
@ -20,17 +18,13 @@ doc: $(SRC_H) $(SRC_CLNT)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
mythenServer: $(SRC_MYTHEN_SVC)
|
||||
$(CC) $(SRC_MYTHEN_SVC) $(CFLAGS) $(FLAGS) $(INCLUDES) -ImythenDetectorServer -D VIRTUAL -lm -D MCB_FUNCS -D C_ONLY
|
||||
$(CC) $(SRC_MYTHEN_SVC) $(CFLAGS) $(FLAGS) $(INCLUDES) -ImythenDetectorServer -DVIRTUAL -lm -D MCB_FUNCS -DC_ONLY
|
||||
mv a.out mythenServer
|
||||
|
||||
|
||||
picassoServer: $(SRC_MYTHEN_SVC)
|
||||
$(CXX) $(SRC_MYTHEN_SVC) $(CFLAGS) $(FLAGS) $(INCLUDES) -ImythenDetectorServer -D VIRTUAL -lm -D MCB_FUNCS -DPICASSOD
|
||||
$(CC) $(SRC_MYTHEN_SVC) $(CFLAGS) $(FLAGS) $(INCLUDES) -ImythenDetectorServer -D VIRTUAL -lm -DMCB_FUNCS -DPICASSOD -DC_ONLY
|
||||
mv a.out picassoServer
|
||||
|
||||
|
||||
@ -39,11 +33,12 @@ package: $(SRC_CLNT)
|
||||
$(CXX) -fPIC -g -o objs/slsDetector.o -c -Wall slsDetector/slsDetector.cpp $(INCLUDES) $(FLAGS)
|
||||
# $(CXX) -fPIC -g -o objs/eigerDetector.o -c -Wall eigerDetector/eigerDetector.cpp $(INCLUDES) $(FLAGS)
|
||||
$(CXX) -fPIC -g -o objs/mythenDetector.o -c -Wall mythenDetector/mythenDetector.cpp $(INCLUDES) $(FLAGS)
|
||||
$(CXX) -fPIC -g -o objs/usersFunctions.o -c -Wall usersFunctions/usersFunctions.c $(INCLUDES) $(FLAGS)
|
||||
$(CXX) -fPIC -g -o objs/gotthardDetector.o -c -Wall gotthardDetector/gotthardDetector.cpp $(INCLUDES) $(FLAGS)
|
||||
$(CXX) -fPIC -g -o objs/usersFunctions.o -c -Wall usersFunctions/usersFunctions.c $(INCLUDES) $(FLAGS) $(EPICSFLAGS)
|
||||
$(CXX) -fPIC -g -o objs/MySocketTCP.o -c -Wall MySocketTCP/MySocketTCP.cxx $(INCLUDES) $(FLAGS)
|
||||
$(CXX) -shared -Wl,-soname,libSlsDetector.so.1 -o libSlsDetector.so.1.0.1 objs/slsDetector.o objs/mythenDetector.o objs/usersFunctions.o objs/MySocketTCP.o -lc $(INCLUDES) $(FLAGS)
|
||||
$(CXX) -shared -Wl,-soname,libSlsDetector.so.1 -o libSlsDetector.so.1.0.1 objs/slsDetector.o objs/mythenDetector.o objs/gotthardDetector.o objs/usersFunctions.o objs/MySocketTCP.o -lc $(INCLUDES) $(FLAGS) $(EPICSFLAGS)
|
||||
ln -sf libSlsDetector.so.1.0.1 libSlsDetector.so
|
||||
ar rcs libSlsDetector.a objs/slsDetector.o objs/mythenDetector.o objs/usersFunctions.o objs/MySocketTCP.o
|
||||
ar rcs libSlsDetector.a objs/slsDetector.o objs/mythenDetector.o objs/gotthardDetector.o objs/usersFunctions.o objs/MySocketTCP.o
|
||||
|
||||
clean:
|
||||
rm -rf libSlsDetector.so.1.0.1 libSlsDetector.so core objs/* docs/*
|
||||
@ -62,6 +57,7 @@ install_inc:
|
||||
cp -P ../slsDetectorSoftware/MySocketTCP/MySocketTCP.h $(DESTDIR)
|
||||
cp -P ../slsDetectorSoftware/eigerDetector/eigerDetector.h $(DESTDIR)
|
||||
cp -P ../slsDetectorSoftware/mythenDetector/mythenDetector.h $(DESTDIR)
|
||||
cp -P ../slsDetectorSoftware/gotthardDetector/gotthardDetector.h $(DESTDIR)
|
||||
cp -P ../slsDetectorSoftware/slsDetector/slsDetector.h $(DESTDIR)
|
||||
cp -P ../slsDetectorSoftware/commonFiles/sls_detector_defs.h $(DESTDIR)
|
||||
cp -P ../slsDetectorSoftware/usersFunctions/usersFunctions.h $(DESTDIR)
|
||||
|
@ -4,9 +4,13 @@
|
||||
|
||||
#define SEND_REC_MAX_SIZE 4096
|
||||
#define DEFAULT_PORTNO 1952
|
||||
|
||||
#define DEFAULT_PORTNO_GOTTHARD 1955
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @libdoc The MySocketTCP class provides a simple interface for creating and sending/receiving data over a TCP socket.
|
||||
|
@ -253,8 +253,15 @@ enum dacIndex {
|
||||
VDD_POT, /**< chiptest board power supply vdd */
|
||||
VSH_POT, /**< chiptest board power supply vsh */
|
||||
VIO_POT, /**< chiptest board power supply va */
|
||||
HV_POT /**< chiptest board high voltage */
|
||||
|
||||
HV_POT, /**< chiptest board high voltage */
|
||||
G_VREF_DS, /**< gotthard */
|
||||
G_VCASCN_PB, /**< gotthard */
|
||||
G_VCASCP_PB, /**< gotthard */
|
||||
G_VOUT_CM, /**< gotthard */
|
||||
G_VCASC_OUT, /**< gotthard */
|
||||
G_VIN_CM, /**< gotthard */
|
||||
G_VREF_COMP, /**< gotthard */
|
||||
G_IB_TESTC /**< gotthard */
|
||||
};
|
||||
|
||||
/**
|
||||
@ -265,6 +272,10 @@ enum detectorSettings{
|
||||
STANDARD, /**< standard settings */
|
||||
FAST, /**< fast settings */
|
||||
HIGHGAIN, /**< highgain settings */
|
||||
DYNAMICGAIN, /**< dynamic gain settings */
|
||||
GAIN1, /**< gain 1 settings */
|
||||
GAIN2, /**< gain 2 settings */
|
||||
GAIN3, /**< gain 3 settings */
|
||||
UNDEFINED, /**< undefined or custom settings */
|
||||
UNINITIALIZED /**< uninitialiazed (status at startup) */
|
||||
};
|
||||
@ -448,10 +459,18 @@ enum {
|
||||
//Trimming
|
||||
F_EXECUTE_TRIMMING, /**< execute trimming */
|
||||
|
||||
|
||||
F_EXIT_SERVER, /**< turnoff detector server */
|
||||
|
||||
F_GET_TEMPERATURE,
|
||||
F_SET_GOTTHARD,
|
||||
F_GET_GOTTHARD,
|
||||
|
||||
F_GET_ACTUAL_TIME, /**< Gets the actual time of the detector's internal timer */
|
||||
F_GET_MEASUREMENT_TIME /**< Gets the time of the measurement from the detector (fifo) */
|
||||
|
||||
|
||||
F_EXIT_SERVER /**< turnoff detector server */
|
||||
/* Always append functions hereafter!!! */
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
3345
slsDetectorSoftware/gotthardDetector/gotthardDetector.cpp
Normal file
3345
slsDetectorSoftware/gotthardDetector/gotthardDetector.cpp
Normal file
File diff suppressed because it is too large
Load Diff
352
slsDetectorSoftware/gotthardDetector/gotthardDetector.h
Normal file
352
slsDetectorSoftware/gotthardDetector/gotthardDetector.h
Normal file
@ -0,0 +1,352 @@
|
||||
|
||||
|
||||
|
||||
#ifndef GOTTHARD_DETECTOR_H
|
||||
#define GOTTHARD_DETECTOR_H
|
||||
|
||||
//#include <ostream>
|
||||
#include "slsDetector.h"
|
||||
#include "usersFunctions.h"
|
||||
|
||||
#define defaultTDead {170,90,750}
|
||||
|
||||
//using namespace std;
|
||||
/**
|
||||
\mainpage C++ class with GOTTHARD specific functions
|
||||
*
|
||||
|
||||
|
||||
@author Anna Bergamaschi
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
class gotthardDetector : public slsDetector{
|
||||
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
(default) constructor
|
||||
*/
|
||||
gotthardDetector(int id=0, detectorType t=GOTTHARD) : slsDetector(t, id){};
|
||||
//slsDetector(string const fname);
|
||||
// ~slsDetector(){while(dataQueue.size()>0){}};
|
||||
/** destructor */
|
||||
virtual ~gotthardDetector(){};
|
||||
|
||||
|
||||
char* gotthardStringname(string name);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
executes a set of string arguments according to a given format. It is used to read/write configuration file, dump and retrieve detector settings and for the command line interface command parsing
|
||||
\param narg number of arguments
|
||||
\param args array of string arguments
|
||||
\param action can be PUT_ACTION or GET_ACTION (from text client even READOUT_ACTION for acquisition)
|
||||
\returns answer string
|
||||
*/
|
||||
string executeLine(int narg, char *args[], int action=GET_ACTION);
|
||||
|
||||
/**
|
||||
returns the help for the executeLine command
|
||||
\param os output stream to return the help to
|
||||
\param action can be PUT_ACTION or GET_ACTION (from text client even READOUT_ACTION for acquisition)
|
||||
*/
|
||||
static string helpLine(int action=GET_ACTION);
|
||||
|
||||
|
||||
/**
|
||||
type of action performed
|
||||
*/
|
||||
enum {GET_ACTION, PUT_ACTION, READOUT_ACTION};
|
||||
|
||||
|
||||
/**
|
||||
reads configuration file fname calling executeLine
|
||||
\param fname file to be read
|
||||
*/
|
||||
int readConfigurationFile(string const fname);
|
||||
/**
|
||||
writes configuration file calling executeLine
|
||||
\param fname file to write to
|
||||
*/
|
||||
int writeConfigurationFile(string const fname);
|
||||
/**
|
||||
dumps all the possible detector parameters calling executeLine
|
||||
\param fname file to write to
|
||||
\param level 0 dumps only main parameters and filenames for flat field correction etc.; 2 dumps really the complete configuration including flat field files, badchannels files, trimbits, angular conversion etc.
|
||||
*/
|
||||
int dumpDetectorSetup(string const fname, int level=0);
|
||||
/**
|
||||
retrieves all possible detector parameters from file calling executeLine
|
||||
\param fname file to be read
|
||||
*/
|
||||
int retrieveDetectorSetup(string const fname, int level=0);
|
||||
|
||||
/**
|
||||
reads a trim/settings file
|
||||
\param fname name of the file to be read
|
||||
\param myMod pointer to the module structure which has to be set. <BR> If it is NULL a new module structure will be created
|
||||
\returns the pointer to myMod or NULL if reading the file failed
|
||||
*/
|
||||
|
||||
sls_detector_module* readSettingsFile(string fname, sls_detector_module* myMod=NULL);
|
||||
|
||||
/**
|
||||
writes a trim/settings file
|
||||
\param fname name of the file to be written
|
||||
\param mod module structure which has to be written to file
|
||||
\returns OK or FAIL if the file could not be written
|
||||
|
||||
\sa ::sls_detector_module
|
||||
*/
|
||||
int writeSettingsFile(string fname, sls_detector_module mod);
|
||||
|
||||
/**
|
||||
writes a trim/settings file for module number imod - the values will be read from the current detector structure
|
||||
\param fname name of the file to be written
|
||||
\param imod module number
|
||||
\returns OK or FAIL if the file could not be written
|
||||
\sa ::sls_detector_module sharedSlsDetector
|
||||
*/
|
||||
int writeSettingsFile(string fname, int imod);
|
||||
|
||||
/**
|
||||
writes a data file
|
||||
\param name of the file to be written
|
||||
\param data array of data values
|
||||
\param err array of arrors on the data. If NULL no errors will be written
|
||||
|
||||
\param ang array of angular values. If NULL data will be in the form chan-val(-err) otherwise ang-val(-err)
|
||||
\param dataformat format of the data: can be 'i' integer or 'f' float (default)
|
||||
\param nch number of channels to be written to file. if -1 defaults to the number of installed channels of the detector
|
||||
\returns OK or FAIL if it could not write the file or data=NULL
|
||||
|
||||
|
||||
*/
|
||||
int writeDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=-1);
|
||||
|
||||
/**
|
||||
writes a data file
|
||||
\param name of the file to be written
|
||||
\param data array of data values
|
||||
\returns OK or FAIL if it could not write the file or data=NULL
|
||||
*/
|
||||
int writeDataFile(string fname, int *data);
|
||||
|
||||
/**
|
||||
reads a data file
|
||||
\param name of the file to be read
|
||||
\param data array of data values to be filled
|
||||
\param err array of arrors on the data. If NULL no errors are expected on the file
|
||||
|
||||
\param ang array of angular values. If NULL data are expected in the form chan-val(-err) otherwise ang-val(-err)
|
||||
\param dataformat format of the data: can be 'i' integer or 'f' float (default)
|
||||
\param nch number of channels to be written to file. if <=0 defaults to the number of installed channels of the detector
|
||||
\returns OK or FAIL if it could not read the file or data=NULL
|
||||
|
||||
|
||||
*/
|
||||
int readDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=0);
|
||||
|
||||
/**
|
||||
reads a data file
|
||||
\param name of the file to be read
|
||||
\param data array of data values
|
||||
\returns OK or FAIL if it could not read the file or data=NULL
|
||||
*/
|
||||
int readDataFile(string fname, int *data);
|
||||
|
||||
|
||||
/**
|
||||
reads a calibration file
|
||||
\param fname file to be read
|
||||
\param gain reference to the gain variable
|
||||
\offset reference to the offset variable
|
||||
\sa sharedSlsDetector
|
||||
*/
|
||||
int readCalibrationFile(string fname, float &gain, float &offset);
|
||||
/**
|
||||
writes a clibration file
|
||||
\param fname file to be written
|
||||
\param gain
|
||||
\param offset
|
||||
\sa sharedSlsDetector
|
||||
*/
|
||||
int writeCalibrationFile(string fname, float gain, float offset);
|
||||
|
||||
|
||||
/**
|
||||
reads an angular conversion file
|
||||
\param fname file to be read
|
||||
\sa angleConversionConstant
|
||||
*/
|
||||
int readAngularConversion(string fname="");
|
||||
/**
|
||||
writes an angular conversion file
|
||||
\param fname file to be written
|
||||
\sa angleConversionConstant
|
||||
*/
|
||||
int writeAngularConversion(string fname="");
|
||||
|
||||
|
||||
|
||||
|
||||
//Corrections
|
||||
|
||||
|
||||
/**
|
||||
set angular conversion
|
||||
\param fname file with angular conversion constants ("" disable)
|
||||
\returns 0 if angular conversion disabled, >0 otherwise
|
||||
*/
|
||||
int setAngularConversion(string fname="");
|
||||
|
||||
/**
|
||||
get angular conversion
|
||||
\param reference to diffractometer direction
|
||||
\param angconv array that will be filled with the angular conversion constants
|
||||
\returns 0 if angular conversion disabled, >0 otherwise
|
||||
*/
|
||||
int getAngularConversion(int &direction, angleConversionConstant *angconv=NULL);
|
||||
|
||||
|
||||
/** returns the angular conversion file */
|
||||
string getAngularConversion() {if (thisDetector->correctionMask&(1<< ANGULAR_CONVERSION)) return string(thisDetector->angConvFile); else return string("none");};
|
||||
|
||||
/**
|
||||
set detector global offset
|
||||
*/
|
||||
float setGlobalOffset(float f){thisDetector->globalOffset=f; return thisDetector->globalOffset;};
|
||||
|
||||
/**
|
||||
set detector fine offset
|
||||
*/
|
||||
float setFineOffset(float f){thisDetector->fineOffset=f; return thisDetector->fineOffset;};
|
||||
/**
|
||||
get detector fine offset
|
||||
*/
|
||||
float getFineOffset(){return thisDetector->fineOffset;};
|
||||
|
||||
/**
|
||||
get detector global offset
|
||||
*/
|
||||
float getGlobalOffset(){return thisDetector->globalOffset;};
|
||||
|
||||
/**
|
||||
set positions for the acquisition
|
||||
\param nPos number of positions
|
||||
\param pos array with the encoder positions
|
||||
\returns number of positions
|
||||
*/
|
||||
int setPositions(int nPos, float *pos);
|
||||
/**
|
||||
get positions for the acquisition
|
||||
\param pos array which will contain the encoder positions
|
||||
\returns number of positions
|
||||
*/
|
||||
int getPositions(float *pos=NULL);
|
||||
|
||||
|
||||
/** set detector bin size used for merging (approx angular resolution)*/
|
||||
float setBinSize(float bs) {thisDetector->binSize=bs; return thisDetector->binSize;}
|
||||
/** return detector bin size used for merging (approx angular resolution)*/
|
||||
float getBinSize() {return thisDetector->binSize;}
|
||||
|
||||
|
||||
|
||||
|
||||
/** sets the arrays of the merged data to 0. NB The array should be created with size >= 360./getBinSize();
|
||||
\param mp already merged postions
|
||||
\param mv already merged data
|
||||
\param me already merged errors (squared sum)
|
||||
\param mm multiplicity of merged arrays
|
||||
\returns OK or FAIL
|
||||
*/
|
||||
int resetMerging(float *mp, float *mv,float *me, int *mm);
|
||||
/** merge dataset
|
||||
\param p1 angular positions of dataset
|
||||
\param v1 data
|
||||
\param e1 errors
|
||||
\param mp already merged postions
|
||||
\param mv already merged data
|
||||
\param me already merged errors (squared sum)
|
||||
\param mm multiplicity of merged arrays
|
||||
*/
|
||||
int addToMerging(float *p1, float *v1, float *e1, float *mp, float *mv,float *me, int *mm);
|
||||
|
||||
/**
|
||||
calculates the "final" positions, data value and errors for the emrged data
|
||||
\param mp already merged postions
|
||||
\param mv already merged data
|
||||
\param me already merged errors (squared sum)
|
||||
\param mm multiplicity of merged arrays
|
||||
\returns FAIL or the
|
||||
*/
|
||||
int finalizeMerging(float *mp, float *mv,float *me, int *mm);
|
||||
|
||||
|
||||
/**
|
||||
function for processing data
|
||||
\param delflag if 1 the data are deleted, else left there for further processing (or plotting?)
|
||||
*/
|
||||
void* processData(int delflag=1); // thread function
|
||||
|
||||
/** performs the complete acquisition and data processing
|
||||
moves the detector to next position <br>
|
||||
starts and reads the detector <br>
|
||||
reads the IC (if required) <br>
|
||||
reads the encoder (iof required for angualr conversion) <br>
|
||||
processes the data (flat field, rate, angular conversion and merging ::processData())
|
||||
\param delflag if 1 the data are deleted, else left there for further processing (or plotting?)
|
||||
*/
|
||||
|
||||
void acquire(int delflag=1);
|
||||
|
||||
/**
|
||||
get current timer value on the stop socket
|
||||
\param index timer index
|
||||
\returns elapsed time value in ns or number of...(e.g. frames, gates, probes)
|
||||
*/
|
||||
|
||||
int64_t getTimeLeft(timerIndex index);
|
||||
|
||||
/**
|
||||
get run status on the stop socket
|
||||
\returns status mask
|
||||
*/
|
||||
runStatus getRunStatus();
|
||||
|
||||
|
||||
/**
|
||||
get current temperature
|
||||
\returns current temperature
|
||||
*/
|
||||
|
||||
float getTemperature(int imod=0);
|
||||
|
||||
private:
|
||||
/**
|
||||
start data processing thread
|
||||
*/
|
||||
void startThread(int delflag=1); //
|
||||
/** the data processing thread */
|
||||
|
||||
pthread_t dataProcessingThread;
|
||||
|
||||
/** sets when the acquisition is finished */
|
||||
int jointhread;
|
||||
|
||||
/** data queue size */
|
||||
int queuesize;
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void* startProcessData(void *n);
|
||||
static void* startProcessDataNoDelete(void *n);
|
||||
|
||||
#endif
|
1
slsDetectorSoftware/gotthardDetectorServer/.target-makefrag
Executable file
1
slsDetectorSoftware/gotthardDetectorServer/.target-makefrag
Executable file
@ -0,0 +1 @@
|
||||
AXIS_BUILDTYPE ?= cris-axis-linux-gnu
|
59
slsDetectorSoftware/gotthardDetectorServer/Makefile
Executable file
59
slsDetectorSoftware/gotthardDetectorServer/Makefile
Executable file
@ -0,0 +1,59 @@
|
||||
# $Id: Makefile,v 1.1.1.1 2006/02/04 03:35:01 freza Exp $
|
||||
# first compile
|
||||
# make cris-axis-linux-gnu
|
||||
|
||||
|
||||
CROSS = bfin-uclinux-
|
||||
CC = $(CROSS)gcc
|
||||
|
||||
CFLAGS += -Wall -DMCB_FUNCS -DVERBOSE -DVERY_VERBOSE #-DVIRTUAL
|
||||
|
||||
#INCLUDES= /usr/src/kernels/2.6.18-238.12.1.el5-i686/include
|
||||
#/home/l_maliakal_d/bfin/blackfin-linux-dist/linux-2.6.x/include
|
||||
#/usr/include/asm/page.h
|
||||
|
||||
|
||||
PROGS= gotthardDetectorServer
|
||||
|
||||
INSTDIR= /tftpboot
|
||||
INSTMODE= 0777
|
||||
|
||||
|
||||
|
||||
BINS = testlib_sharedlibc
|
||||
SRCS = server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c trimming_funcs.c sharedmemory.c
|
||||
OBJS = $(SRCS:%.c=%.o)
|
||||
|
||||
|
||||
#LDLIBS+= -lm
|
||||
|
||||
|
||||
|
||||
all: clean $(PROGS)
|
||||
|
||||
boot: $(OBJS)
|
||||
|
||||
$(PROGS): $(OBJS)
|
||||
echo $(OBJS)
|
||||
$(CC) $(CFLAGS) -o $@ $^ $(LDLIBS_$@) $(LDFLAGS_$@)
|
||||
|
||||
|
||||
install: $(PROGS)
|
||||
$(INSTALL) -d $(INSTDIR)
|
||||
$(INSTALL) -m $(INSTMODE) $(PROGS) $(INSTDIR)
|
||||
|
||||
|
||||
#CFLAGS+= -Wall -DC_ONLY -DMCB_FUNCS
|
||||
#-DVERBOSE
|
||||
#-DVERYVERBOSE
|
||||
#-Werror
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf $(PROGS) *.o
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
540
slsDetectorSoftware/gotthardDetectorServer/communication_funcs.c
Executable file
540
slsDetectorSoftware/gotthardDetectorServer/communication_funcs.c
Executable file
@ -0,0 +1,540 @@
|
||||
|
||||
|
||||
#include "communication_funcs.h"
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/tcp.h> /* for TCP_NODELAY */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
|
||||
//int socketDescriptor, file_des;
|
||||
int socketDescriptor, file_des;
|
||||
const int send_rec_max_size=SEND_REC_MAX_SIZE;
|
||||
extern int errno;
|
||||
|
||||
//struct sockaddr_in address;
|
||||
//#define VERBOSE
|
||||
|
||||
|
||||
int bindSocket(unsigned short int port_number) {
|
||||
int i;
|
||||
|
||||
struct sockaddr_in addressS;
|
||||
|
||||
|
||||
file_des= -1;
|
||||
socketDescriptor = socket(AF_INET, SOCK_STREAM,0); //tcp
|
||||
|
||||
//socketDescriptor = socket(PF_INET, SOCK_STREAM, 0);
|
||||
|
||||
|
||||
|
||||
if (socketDescriptor < 0) {
|
||||
printf("Cannot create socket..socketdescript less than 0\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("Cannot create socket..did not bind\n");
|
||||
|
||||
socketDescriptor=-1;
|
||||
} else {
|
||||
listen(socketDescriptor, 5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//int getrlimit(int resource, struct rlimit *rlim);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return socketDescriptor;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
only client funcs
|
||||
*/
|
||||
/*
|
||||
#ifndef C_ONLY
|
||||
|
||||
MySocketTCP::MySocketTCP(const char* const host_ip_or_name, unsigned short int const port_number):
|
||||
last_keep_connection_open_action_was_a_send(0), file_des(-1), send_rec_max_size(SEND_REC_MAX_SIZE), is_a_server(0), portno(DEFAULT_PORTNO), socketDescriptor(-1)
|
||||
{ // sender (client): where to? ip
|
||||
//is_a_server = 0;
|
||||
// SetupParameters();
|
||||
strcpy(hostname,host_ip_or_name);
|
||||
portno=port_number;
|
||||
struct hostent *hostInfo = gethostbyname(host_ip_or_name);
|
||||
if (hostInfo == NULL){
|
||||
cerr << "Exiting: Problem interpreting host: " << host_ip_or_name << "\n";
|
||||
} else {
|
||||
// Set some fields in the serverAddress structure.
|
||||
serverAddress.sin_family = hostInfo->h_addrtype;
|
||||
memcpy((char *) &serverAddress.sin_addr.s_addr,
|
||||
hostInfo->h_addr_list[0], hostInfo->h_length);
|
||||
serverAddress.sin_port = htons(port_number);
|
||||
socketDescriptor=0; //You can use send and recv, //would it work?????
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int MySocketTCP::getHostname(char *name) {
|
||||
if (is_a_server==0) {
|
||||
strcpy(name,hostname);
|
||||
}
|
||||
return is_a_server;
|
||||
};
|
||||
#endif
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
int getServerError()
|
||||
{
|
||||
if (socketDescriptor<0) return 1;
|
||||
else return 0;
|
||||
};
|
||||
|
||||
|
||||
int acceptConnection() {
|
||||
struct sockaddr_in addressC;
|
||||
//socklen_t address_length;
|
||||
size_t address_length=sizeof(struct sockaddr_in);
|
||||
|
||||
if(file_des>0) return file_des;
|
||||
|
||||
|
||||
//#ifndef C_ONLY
|
||||
// if(is_a_server){ //server; the server will wait for the clients connection
|
||||
//#endif
|
||||
|
||||
|
||||
if (socketDescriptor>0) {
|
||||
//if ((file_des = accept(socketDescriptor,(struct sockaddr *) &addressC, &address_length)) < 0) {
|
||||
if ((file_des = accept(socketDescriptor,(struct sockaddr *) &addressC, &address_length)) < 0) {
|
||||
|
||||
|
||||
|
||||
printf("Error: with server accept, connection refused %d\n", errno);
|
||||
|
||||
|
||||
switch(errno) {
|
||||
case EWOULDBLOCK:
|
||||
printf("ewouldblock eagain\n");
|
||||
break;
|
||||
case EBADF:
|
||||
printf("ebadf\n");
|
||||
break;
|
||||
case ECONNABORTED:
|
||||
printf("econnaborted\n");
|
||||
break;
|
||||
case EFAULT:
|
||||
printf("efault\n");
|
||||
break;
|
||||
case EINTR:
|
||||
printf("eintr\n");
|
||||
break;
|
||||
case EINVAL:
|
||||
printf("einval\n");
|
||||
break;
|
||||
case EMFILE:
|
||||
printf("emfile\n");
|
||||
break;
|
||||
case ENFILE:
|
||||
printf("enfile\n");
|
||||
break;
|
||||
case ENOTSOCK:
|
||||
printf("enotsock\n");
|
||||
break;
|
||||
case EOPNOTSUPP:
|
||||
printf("eOPNOTSUPP\n");
|
||||
break;
|
||||
case ENOBUFS:
|
||||
printf("ENOBUFS\n");
|
||||
break;
|
||||
case ENOMEM:
|
||||
printf("ENOMEM\n");
|
||||
break;
|
||||
case ENOSR:
|
||||
printf("ENOSR\n");
|
||||
break;
|
||||
case EPROTO:
|
||||
printf("EPROTO\n");
|
||||
break;
|
||||
default:
|
||||
printf("unknown error\n");
|
||||
}
|
||||
|
||||
|
||||
socketDescriptor=-1;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
printf("client connected %d\n", file_des);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
return file_des;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void closeConnection() {
|
||||
//fflush(stdout);
|
||||
//printf("Closing file_des %d\n", file_des);
|
||||
//sleep(1);
|
||||
#ifdef VERY_VERBOSE
|
||||
#endif
|
||||
if(file_des>=0)
|
||||
close(file_des);
|
||||
file_des=-1;
|
||||
}
|
||||
|
||||
void exitServer() {
|
||||
if (socketDescriptor>=0)
|
||||
close(socketDescriptor);
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("Closing server\n");
|
||||
#endif
|
||||
socketDescriptor=-1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* client close conenction */
|
||||
/*
|
||||
#ifndef C_ONLY
|
||||
void MySocketTCP::Disconnect(){
|
||||
|
||||
if(file_des>=0){ //then was open
|
||||
if(is_a_server){
|
||||
close(file_des);
|
||||
}
|
||||
else {
|
||||
close(socketDescriptor);
|
||||
socketDescriptor=-1;
|
||||
}
|
||||
file_des=-1;
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
|
||||
|
||||
int sendDataOnly(void* buf,int length) {
|
||||
/*
|
||||
int total_sent=0;
|
||||
int nsending;
|
||||
int nsent;
|
||||
|
||||
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("want to send %d Bytes\n", length);
|
||||
#endif
|
||||
if (file_des<0) return -1;
|
||||
|
||||
while(length>0){
|
||||
nsending = (length>send_rec_max_size) ? send_rec_max_size:length;
|
||||
nsent = write(file_des,(char*)buf+total_sent,nsending);
|
||||
if(!nsent) break;
|
||||
length-=nsent;
|
||||
total_sent+=nsent;
|
||||
// cout<<"nsent: "<<nsent<<endl;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
return write(file_des, buf, length);
|
||||
}
|
||||
|
||||
|
||||
int receiveDataOnly(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: "<<nreceived<<" waiting for ("<<length<<")"<<endl;
|
||||
}
|
||||
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("received %d Bytes\n", total_received);
|
||||
#endif
|
||||
|
||||
return total_received;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int sendChannel(sls_detector_channel *myChan) {
|
||||
return sendDataOnly(myChan, sizeof(sls_detector_channel));
|
||||
}
|
||||
|
||||
int sendChip(sls_detector_chip *myChip) {
|
||||
int ts=0;
|
||||
int nChans=myChip->nchan;
|
||||
ts+=sendDataOnly(myChip,sizeof(sls_detector_chip));
|
||||
ts+=sendDataOnly(myChip->chanregs,nChans*sizeof(int));
|
||||
return ts;
|
||||
}
|
||||
|
||||
int sendModule(sls_detector_module *myMod) {
|
||||
int ts=0;
|
||||
int idac;
|
||||
int nChips=myMod->nchip;
|
||||
int nChans=myMod->nchan;
|
||||
int nAdcs=myMod->nadc;
|
||||
int nDacs=myMod->ndac;
|
||||
ts+= sendDataOnly(myMod,sizeof(sls_detector_module));
|
||||
#ifdef VERBOSE
|
||||
printf("module %d of size %d sent\n",myMod->module, ts);
|
||||
#endif
|
||||
ts+= sendDataOnly(myMod->dacs,sizeof(float)*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,myMod->dacs[idac]);
|
||||
#endif
|
||||
ts+= sendDataOnly(myMod->adcs,sizeof(float)*nAdcs);
|
||||
#ifdef VERBOSE
|
||||
printf("adcs %d of size %d sent\n",myMod->module, ts);
|
||||
#endif
|
||||
ts+=sendDataOnly(myMod->chipregs,sizeof(int)*nChips);
|
||||
#ifdef VERBOSE
|
||||
printf("chips %d of size %d sent\n",myMod->module, ts);
|
||||
#endif
|
||||
ts+=sendDataOnly(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(sls_detector_channel *myChan) {
|
||||
return receiveDataOnly(myChan,sizeof(sls_detector_channel));
|
||||
}
|
||||
|
||||
int receiveChip(sls_detector_chip* myChip) {
|
||||
|
||||
int *ptr=myChip->chanregs;
|
||||
int ts=0;
|
||||
int nChans, nchanold=myChip->nchan, chdiff;
|
||||
|
||||
ts+= receiveDataOnly(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(myChip->chanregs, sizeof(int)*nChans);
|
||||
else {
|
||||
ptr=malloc(chdiff*sizeof(int));
|
||||
myChip->nchan=nchanold;
|
||||
ts+=receiveDataOnly(myChip->chanregs, sizeof(int)*nchanold);
|
||||
ts+=receiveDataOnly(ptr, sizeof(int)*chdiff);
|
||||
free(ptr);
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("chip's channels received\n");
|
||||
#endif
|
||||
return ts;
|
||||
}
|
||||
|
||||
int receiveModule(sls_detector_module* myMod) {
|
||||
|
||||
|
||||
float *dacptr=myMod->dacs;
|
||||
float *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;
|
||||
|
||||
|
||||
ts+= receiveDataOnly(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(myMod->dacs, sizeof(float)*nDacs);
|
||||
#ifdef VERBOSE
|
||||
printf("dacs received\n");
|
||||
#endif
|
||||
} else {
|
||||
dacptr=malloc(ndacdiff*sizeof(float));
|
||||
myMod->ndac=ndold;
|
||||
ts+=receiveDataOnly(myMod->dacs, sizeof(float)*ndold);
|
||||
ts+=receiveDataOnly(dacptr, sizeof(float)*ndacdiff);
|
||||
free(dacptr);
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (nadcdiff<=0) {
|
||||
ts+=receiveDataOnly(myMod->adcs, sizeof(float)*nAdcs);
|
||||
#ifdef VERBOSE
|
||||
printf("adcs received\n");
|
||||
#endif
|
||||
} else {
|
||||
adcptr=malloc(nadcdiff*sizeof(float));
|
||||
myMod->nadc=naold;
|
||||
ts+=receiveDataOnly(myMod->adcs, sizeof(float)*naold);
|
||||
ts+=receiveDataOnly(adcptr, sizeof(float)*nadcdiff);
|
||||
free(adcptr);
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (nchipdiff<=0) {
|
||||
ts+=receiveDataOnly(myMod->chipregs, sizeof(int)*nChips);
|
||||
#ifdef VERBOSE
|
||||
printf("chips received\n");
|
||||
#endif
|
||||
} else {
|
||||
chipptr=malloc(nchipdiff*sizeof(int));
|
||||
myMod->nchip=nchipold;
|
||||
ts+=receiveDataOnly(myMod->chipregs, sizeof(int)*nchipold);
|
||||
ts+=receiveDataOnly(chipptr, sizeof(int)*nchipdiff);
|
||||
free(chipptr);
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (nchandiff<=0) {
|
||||
ts+=receiveDataOnly(myMod->chanregs, sizeof(int)*nChans);
|
||||
#ifdef VERBOSE
|
||||
printf("chans received\n");
|
||||
#endif
|
||||
} else {
|
||||
chanptr=malloc(nchandiff*sizeof(int));
|
||||
myMod->nchan=nchanold;
|
||||
ts+=receiveDataOnly(myMod->chanregs, sizeof(int)*nchanold);
|
||||
ts+=receiveDataOnly(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;
|
||||
}
|
32
slsDetectorSoftware/gotthardDetectorServer/communication_funcs.h
Executable file
32
slsDetectorSoftware/gotthardDetectorServer/communication_funcs.h
Executable file
@ -0,0 +1,32 @@
|
||||
#ifndef COMMUNICATION_FUNCS_H
|
||||
#define COMMUNICATION_FUNCS_H
|
||||
|
||||
#define SEND_REC_MAX_SIZE 4096
|
||||
#define DEFAULT_PORTNO 1955
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
int bindSocket(unsigned short int port_number);
|
||||
int acceptConnection();
|
||||
void closeConnection();
|
||||
void exitServer();
|
||||
int sendDataOnly(void* buf,int length);
|
||||
int receiveDataOnly(void* buf,int length);
|
||||
|
||||
int getServerError();
|
||||
int sendChannel(sls_detector_channel *myChan);
|
||||
int sendChip(sls_detector_chip *myChip);
|
||||
int sendModule(sls_detector_module *myMod);
|
||||
int receiveChannel(sls_detector_channel *myChan);
|
||||
int receiveChip(sls_detector_chip* myChip);
|
||||
int receiveModule(sls_detector_module* myMod);
|
||||
|
||||
#endif
|
1361
slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c
Executable file
1361
slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c
Executable file
File diff suppressed because it is too large
Load Diff
138
slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.h
Executable file
138
slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.h
Executable file
@ -0,0 +1,138 @@
|
||||
#ifndef FIRMWARE_FUNCS_H
|
||||
#define FIRMWARE_FUNCS_H
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
//#include <asm/page.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
int mapCSP0(void);
|
||||
int setDummyRegister();
|
||||
u_int16_t bus_w16(u_int32_t offset, u_int16_t data);//aldos function
|
||||
u_int32_t bus_w(u_int32_t offset, u_int32_t data);
|
||||
u_int32_t bus_r(u_int32_t offset);
|
||||
|
||||
|
||||
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 setTotClockDutyCycle(int d);
|
||||
u_int32_t getTotClockDutyCycle();
|
||||
|
||||
u_int32_t setExtSignal(int d, enum externalSignalFlag mode);
|
||||
int getExtSignal(int d);
|
||||
int setConfigurationRegister(int d);
|
||||
int setToT(int d);
|
||||
int setContinousReadOut(int d);
|
||||
|
||||
int setDACRegister(int idac, int val, int imod);
|
||||
|
||||
|
||||
u_int64_t getMcsNumber();
|
||||
u_int32_t getMcsVersion();
|
||||
u_int32_t testFifos(void);
|
||||
u_int32_t testFpga(void);
|
||||
u_int32_t testRAM(void);
|
||||
int testBus(void);
|
||||
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 getDelaye();
|
||||
|
||||
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();
|
||||
|
||||
int64_t getProgress();
|
||||
int64_t setProgress();
|
||||
|
||||
|
||||
|
||||
u_int32_t runBusy(void);
|
||||
u_int32_t runState(void);
|
||||
u_int32_t dataPresent(void);
|
||||
|
||||
|
||||
u_int32_t startStateMachine();
|
||||
u_int32_t stopStateMachine();
|
||||
u_int32_t 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();
|
||||
|
||||
/*
|
||||
|
||||
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
|
2581
slsDetectorSoftware/gotthardDetectorServer/mcb_funcs.c
Executable file
2581
slsDetectorSoftware/gotthardDetectorServer/mcb_funcs.c
Executable file
File diff suppressed because it is too large
Load Diff
175
slsDetectorSoftware/gotthardDetectorServer/mcb_funcs.h
Executable file
175
slsDetectorSoftware/gotthardDetectorServer/mcb_funcs.h
Executable file
@ -0,0 +1,175 @@
|
||||
#ifdef MCB_FUNCS
|
||||
|
||||
#ifndef MCB_FUNCS_H
|
||||
#define MCB_FUNCS_H
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
#define RGPRVALS {100,50,200}
|
||||
#define RGSH1VALS {300,200,400}
|
||||
#define RGSH2VALS {260,300,260}
|
||||
|
||||
#define VREFDS_VALS {0,0,200,300,400,500,600}
|
||||
#define VCASCN_VALS {0,0,220,320,420,520,620}
|
||||
#define VCASCP_VALS {0,0,240,340,440,540,640}
|
||||
#define VOUTCM_VALS {0,0,260,360,460,560,660}
|
||||
#define VCASCOUT_VALS {0,0,280,380,480,580,680}
|
||||
#define VINCM_VALS {0,0,300,400,500,600,700}
|
||||
#define VREFCOMP_VALS {0,0,320,420,520,620,720}
|
||||
#define IBTESTC_VALS {0,0,340,440,540,640,740}
|
||||
|
||||
|
||||
#define DEFAULTGAIN {11.66,9.32,14.99}
|
||||
#define DEFAULTOFFSET {817.5,828.6,804.2}
|
||||
|
||||
|
||||
|
||||
// DAC definitions
|
||||
|
||||
enum {VREF_DS, VCASCN_PB, VCASCP_PB, VOUT_CM, VCASC_OUT, VIN_CM, VREF_COMP, IB_TESTC};
|
||||
|
||||
|
||||
/* DAC adresses */
|
||||
//#define DACCS {0,0,1,1,2,2}
|
||||
//#define DACADDR {0,1,0,1,0,1}
|
||||
|
||||
/* DAC adresses */
|
||||
#define DACCS {0,0,1,1,2,2,3,3,4,4,5,5,6,6}
|
||||
#define DACADDR {0,1,0,1,0,1,0,1,0,1,0,1,0,1}
|
||||
|
||||
|
||||
//dynamic range
|
||||
#define MAX5523
|
||||
#ifndef MAX5523
|
||||
#define MAX5533
|
||||
#endif
|
||||
#ifdef MAX5533
|
||||
#define DAC_DR 4096
|
||||
#endif
|
||||
#ifdef MAX5523
|
||||
#define DAC_DR 1024
|
||||
#endif
|
||||
|
||||
|
||||
//reference voltage
|
||||
#define DAC_REFOUT1
|
||||
#ifdef DAC_REFOUT2
|
||||
#define DAC_MAX 2.425
|
||||
#define DAC_REFOUT 2
|
||||
#define DAC_REFOUT1
|
||||
#endif
|
||||
#ifdef DAC_REFOUT3
|
||||
#define DAC_MAX 3.885
|
||||
#define DAC_REFOUT 3
|
||||
#define DAC_REFOUT1
|
||||
#endif
|
||||
#ifdef DAC_REFOUT0
|
||||
#define DAC_MAX 1.214
|
||||
#define DAC_REFOUT 0
|
||||
#endif
|
||||
#ifdef DAC_REFOUT1
|
||||
#define DAC_MAX 1.940
|
||||
#define DAC_REFOUT 1
|
||||
#endif
|
||||
|
||||
/* dac calibration constants */
|
||||
|
||||
#define VA 1.11
|
||||
|
||||
#define CVTRIM 52.430851
|
||||
#define BVTRIM -0.102022
|
||||
#define AVTRIM 0.000050
|
||||
|
||||
#define PARTREF {100,1.55,-2.5,-2.5,0,-2.5}
|
||||
#define PARTR1 {78,10,10,10,10,10}
|
||||
#define PARTR2 {0,4.7,27,47,22,47}
|
||||
|
||||
|
||||
//chip shiftin register meaning
|
||||
#define OUTMUX_OFFSET 20
|
||||
#define PROBES_OFFSET 4
|
||||
#define OUTBUF_OFFSET 0
|
||||
|
||||
|
||||
void showbits(int h);
|
||||
|
||||
int initDetector();
|
||||
int copyChannel(sls_detector_channel *destChan, sls_detector_channel *srcChan);
|
||||
int copyChip(sls_detector_chip *destChip, sls_detector_chip *srcChip);
|
||||
int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod);
|
||||
|
||||
/* Register commands */
|
||||
int clearDACSregister(int imod );
|
||||
int nextDAC(int imod );
|
||||
int clearCSregister(int imod );
|
||||
int setCSregister(int imod );
|
||||
int nextChip(int imod );
|
||||
int firstChip(int imod );
|
||||
int clearSSregister(int imod );
|
||||
int setSSregister(int imod );
|
||||
int nextStrip(int imod );
|
||||
int selChannel(int strip,int imod );
|
||||
int selChip(int chip,int imod );
|
||||
int selMod(int mod,int imod );
|
||||
|
||||
/* DACs routines */
|
||||
int program_one_dac(int addr, int value,int imod );
|
||||
int set_one_dac(int imod);
|
||||
int initDAC(int dac_addr, int value,int imod );
|
||||
int initDACs(int* v,int imod );
|
||||
int setSettings(int i);
|
||||
float initDACbyIndex(int ind,float val, int imod);
|
||||
float initDACbyIndexDACU(int ind,int val, int imod);
|
||||
float getDACbyIndexDACU(int ind, int imod);
|
||||
int getThresholdEnergy();
|
||||
int setThresholdEnergy(int ethr);
|
||||
/* Initialization*/
|
||||
int initChannel(int ft,int cae, int ae, int coe, int ocoe, int counts,int imod );
|
||||
int initChannelbyNumber(sls_detector_channel myChan);
|
||||
int getChannelbyNumber(sls_detector_channel*);
|
||||
|
||||
int getTrimbit(int imod, int ichip, int ichan);
|
||||
|
||||
int initChip(int obe, int ow,int imod );
|
||||
|
||||
int initChipWithProbes(int obe, int ow,int nprobes, int imod);
|
||||
//int getNProbes();
|
||||
|
||||
int initChipbyNumber(sls_detector_chip myChip);
|
||||
int getChipbyNumber(sls_detector_chip*);
|
||||
int initMCBregisters(int cm,int imod );
|
||||
int initModulebyNumber(sls_detector_module);
|
||||
int getModulebyNumber(sls_detector_module*);
|
||||
|
||||
/* To chips */
|
||||
int clearCounter(int imod );
|
||||
int clearOutReg(int imod);
|
||||
int setOutReg(int imod );
|
||||
int extPulse(int ncal,int imod );
|
||||
int calPulse(int ncal,int imod );
|
||||
int counterClear(int imod );
|
||||
int countEnable(int imod );
|
||||
int counterSet(int imod );
|
||||
|
||||
|
||||
/* moved from firmware_funcs */
|
||||
|
||||
int readOutChan(int *val);
|
||||
|
||||
int 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
|
||||
|
||||
#endif
|
181
slsDetectorSoftware/gotthardDetectorServer/registers_g.h
Executable file
181
slsDetectorSoftware/gotthardDetectorServer/registers_g.h
Executable file
@ -0,0 +1,181 @@
|
||||
#ifndef REGISTERS_G_H
|
||||
#define REGISTERS_G_H
|
||||
|
||||
|
||||
/* Definitions for FPGA*/
|
||||
#define CSP0 0x20200000 // Base Addresse CSP0 //done
|
||||
//#define CSP4 0xa0000000 // Base Addresse CSP4
|
||||
|
||||
//#define MEM_SIZE 0xFFFFFF // map so much memory
|
||||
#define MEM_SIZE 0x100000 // map so much memory //done
|
||||
|
||||
|
||||
|
||||
/* registers defined in FPGA */
|
||||
#define FIX_PATT_REG 0x45<<11 //0x000000
|
||||
#define FPGA_VERSION_REG 0x47<<11 //0x001000
|
||||
#define DUMMY_REG 0x13<<11 //0x002000
|
||||
|
||||
#define CONTROL_REG 0x5d<<11 //0x003000
|
||||
#define STATUS_REG 0x5e<<11 //0x004000
|
||||
#define CONFIG_REG 0x5f<<11 //0x005000
|
||||
#define EXT_SIGNAL_REG 0x6a<<11 //0x007000
|
||||
|
||||
#define SPEED_REG 0x006000
|
||||
#define SET_NBITS_REG 0x008000
|
||||
#define LOOK_AT_ME_REG 0x009000
|
||||
|
||||
#define SET_DELAY_LSB_REG 0x44<<11 //0x01A000
|
||||
#define SET_DELAY_MSB_REG 0x45<<11 //0x01B000
|
||||
#define GET_DELAY_LSB_REG 0x46<<11 //0x01C000
|
||||
#define GET_DELAY_MSB_REG 0x47<<11 //0x01D000
|
||||
|
||||
#define SET_TRAINS_LSB_REG 0x48<<11 //0x01E000
|
||||
#define SET_TRAINS_MSB_REG 0x49<<11 //0x01F000
|
||||
#define GET_TRAINS_LSB_REG 0x4a<<11 //0x020000
|
||||
#define GET_TRAINS_MSB_REG 0x4b<<11 //0x021000
|
||||
|
||||
#define SET_FRAMES_LSB_REG 0x4c<<11 //0x00A000
|
||||
#define SET_FRAMES_MSB_REG 0x4d<<11 //0x00B000
|
||||
#define GET_FRAMES_LSB_REG 0x4e<<11 //0x00C000
|
||||
#define GET_FRAMES_MSB_REG 0x4f<<11 //0x00D000
|
||||
|
||||
#define SET_PERIOD_LSB_REG 0x51<<11 //0x016000
|
||||
#define SET_PERIOD_MSB_REG 0x52<<11 //0x017000
|
||||
#define GET_PERIOD_LSB_REG 0x53<<11 //0x018000
|
||||
#define GET_PERIOD_MSB_REG 0x54<<11 //0x019000
|
||||
|
||||
#define SET_EXPTIME_LSB_REG 0x55<<11 //0x00E000
|
||||
#define SET_EXPTIME_MSB_REG 0x56<<11 //0x00F000
|
||||
#define GET_EXPTIME_LSB_REG 0x57<<11 //0x010000
|
||||
#define GET_EXPTIME_MSB_REG 0x58<<11 //0x011000
|
||||
|
||||
#define SET_GATES_LSB_REG 0x59<<11 //0x012000
|
||||
#define SET_GATES_MSB_REG 0x5a<<11 //0x013000
|
||||
#define GET_GATES_LSB_REG 0x5b<<11 //0x014000
|
||||
#define GET_GATES_MSB_REG 0x5c<<11 //0x015000
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define GET_SHIFT_IN_REG 0x022000
|
||||
|
||||
#define MOD_DACS1_REG 0x41<<11//edited by dhanya
|
||||
#define MOD_DACS2_REG 0x42<<11
|
||||
#define MOD_DACS3_REG 0x43<<11
|
||||
|
||||
#define MCB_CNTRL_REG_OFF 0x37<<11 //0x100000 used to send vals to dacs
|
||||
#define MCB_DOUT_REG_OFF 0x200000
|
||||
#define FIFO_CNTRL_REG_OFF 0x300000
|
||||
#define FIFO_COUNTR_REG_OFF 0x400000
|
||||
#define FIFO_DATA_REG_OFF 0x800000
|
||||
|
||||
#define SHIFTMOD 2
|
||||
#define SHIFTFIFO 9
|
||||
|
||||
|
||||
|
||||
/* values defined for FPGA */
|
||||
#define MCSNUM 0x0
|
||||
#define MCSVERSION 0x101
|
||||
#define FIXED_PATT_VAL 0xacdc1980
|
||||
#define FPGA_VERSION_VAL 0x01110825 //0x00090514
|
||||
#define FPGA_INIT_PAT 0x60008
|
||||
#define FPGA_INIT_ADDR 0xb0000000
|
||||
|
||||
/* for control register */
|
||||
#define START_ACQ_BIT 0x00000001
|
||||
#define STOP_ACQ_BIT 0x00000002
|
||||
#define START_FIFOTEST_BIT 0x00000004 // ?????
|
||||
#define STOP_FIFOTEST_BIT 0x00000008 // ??????
|
||||
#define START_READOUT_BIT 0x00000010
|
||||
#define STOP_READOUT_BIT 0x00000020
|
||||
#define START_EXPOSURE_BIT 0x00000040
|
||||
#define STOP_EXPOSURE_BIT 0x00000080
|
||||
#define START_TRAIN_BIT 0x00000100
|
||||
#define STOP_TRAIN_BIT 0x00000200
|
||||
#define SYNC_RESET 0x80000000
|
||||
|
||||
/* for status register */
|
||||
#define RUN_BUSY_BIT 0x00000001
|
||||
#define READOUT_BUSY_BIT 0x00000002
|
||||
#define FIFOTEST_BUSY_BIT 0x00000004 //????
|
||||
#define WAITING_FOR_TRIGGER_BIT 0x00000008
|
||||
#define DELAYBEFORE_BIT 0x00000010
|
||||
#define DELAYAFTER_BIT 0x00000020
|
||||
#define EXPOSING_BIT 0x00000040
|
||||
#define COUNT_ENABLE_BIT 0x00000080
|
||||
#define SOME_FIFO_FULL_BIT 0x00008000 // error!
|
||||
#define ALL_FIFO_EMPTY_BIT 0x00010000 // data ready
|
||||
|
||||
/* for fifo status register */
|
||||
#define FIFO_ENABLED_BIT 0x80000000
|
||||
#define FIFO_DISABLED_BIT 0x01000000
|
||||
#define FIFO_ERROR_BIT 0x08000000
|
||||
#define FIFO_EMPTY_BIT 0x04000000
|
||||
#define FIFO_DATA_READY_BIT 0x02000000
|
||||
#define FIFO_COUNTER_MASK 0x000001ff
|
||||
#define FIFO_NM_MASK 0x00e00000
|
||||
#define FIFO_NM_OFF 21
|
||||
#define FIFO_NC_MASK 0x001ffe00
|
||||
#define FIFO_NC_OFF 9
|
||||
|
||||
/* for config register */
|
||||
|
||||
#define TOT_ENABLE_BIT 0x00000002
|
||||
#define TIMED_GATE_BIT 0x00000004
|
||||
#define CONT_RO_ENABLE_BIT 0x00080000
|
||||
|
||||
|
||||
|
||||
/* for speed register */
|
||||
|
||||
#define CLK_DIVIDER_MASK 0x000000ff
|
||||
#define CLK_DIVIDER_OFFSET 0
|
||||
#define SET_LENGTH_MASK 0x00000f00
|
||||
#define SET_LENGTH_OFFSET 8
|
||||
#define WAIT_STATES_MASK 0x0000f000
|
||||
#define WAIT_STATES_OFFSET 12
|
||||
#define TOTCLK_DIVIDER_MASK 0xff000000
|
||||
#define TOTCLK_DIVIDER_OFFSET 24
|
||||
#define TOTCLK_DUTYCYCLE_MASK 0x00ff0000
|
||||
#define TOTCLK_DUTYCYCLE_OFFSET 16
|
||||
|
||||
/* for external signal register */
|
||||
|
||||
#define SIGNAL_OFFSET 4
|
||||
#define SIGNAL_MASK 0xF
|
||||
#define EXT_SIG_OFF 0x0
|
||||
#define EXT_GATE_IN_ACTIVEHIGH 0x1
|
||||
#define EXT_GATE_IN_ACTIVELOW 0x2
|
||||
#define EXT_TRIG_IN_RISING 0x3
|
||||
#define EXT_TRIG_IN_FALLING 0x4
|
||||
#define EXT_RO_TRIG_IN_RISING 0x5
|
||||
#define EXT_RO_TRIG_IN_FALLING 0x6
|
||||
#define EXT_GATE_OUT_ACTIVEHIGH 0x7
|
||||
#define EXT_GATE_OUT_ACTIVELOW 0x8
|
||||
#define EXT_TRIG_OUT_RISING 0x9
|
||||
#define EXT_TRIG_OUT_FALLING 0xA
|
||||
#define EXT_RO_TRIG_OUT_RISING 0xB
|
||||
#define EXT_RO_TRIG_OUT_FALLING 0xC
|
||||
|
||||
|
||||
|
||||
/* fifo control register */
|
||||
#define FIFO_RESET_BIT 0x00000001
|
||||
#define FIFO_DISABLE_TOGGLE_BIT 0x00000002
|
||||
|
||||
|
||||
//chip shiftin register meaning
|
||||
|
||||
#define OUTMUX_OFF 20
|
||||
#define OUTMUX_MASK 0x1f
|
||||
#define PROBES_OFF 4
|
||||
#define PROBES_MASK 0x7f
|
||||
#define OUTBUF_OFF 0
|
||||
#define OUTBUF_MASK 1
|
||||
|
||||
#endif
|
80
slsDetectorSoftware/gotthardDetectorServer/server.c
Executable file
80
slsDetectorSoftware/gotthardDetectorServer/server.c
Executable file
@ -0,0 +1,80 @@
|
||||
/* A simple server in the internet domain using TCP
|
||||
The port number is passed as an argument */
|
||||
#include "communication_funcs.h"
|
||||
#include "server_funcs.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
int sockfd;
|
||||
|
||||
|
||||
void error(char *msg)
|
||||
{
|
||||
perror(msg);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int portno, b;
|
||||
char cmd[100];
|
||||
int retval=OK;
|
||||
|
||||
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);
|
||||
|
||||
|
||||
bindSocket(portno);
|
||||
if (getServerError()) {
|
||||
printf("server error!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* assign function table */
|
||||
function_table();
|
||||
#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
|
||||
acceptConnection();
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("Conenction accepted\n");
|
||||
#endif
|
||||
retval=decode_function();
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("function executed\n");
|
||||
#endif
|
||||
closeConnection();
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("connection closed\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
exitServer();
|
||||
printf("Goodbye!\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
42
slsDetectorSoftware/gotthardDetectorServer/server_defs.h
Executable file
42
slsDetectorSoftware/gotthardDetectorServer/server_defs.h
Executable file
@ -0,0 +1,42 @@
|
||||
#ifndef SERVER_DEFS_H
|
||||
#define SERVER_DEFS_H
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
// Hardware definitions
|
||||
|
||||
#define NCHAN 128
|
||||
#define NCHIP 10
|
||||
#define NMAXMODX 1
|
||||
#define NMAXMODY 1
|
||||
#define NMAXMOD NMAXMODX*NMAXMODY
|
||||
#define NDAC 8
|
||||
#define NADC 5
|
||||
|
||||
#define NCHANS NCHAN*NCHIP*NMAXMOD
|
||||
#define NDACS NDAC*NMAXMOD
|
||||
|
||||
#define NTRIMBITS 6
|
||||
#define NCOUNTBITS 24
|
||||
|
||||
//#define TRIM_DR ((2**NTRIMBITS)-1)
|
||||
//#define COUNT_DR ((2**NCOUNTBITS)-1)
|
||||
#define TRIM_DR (((int)pow(2,NTRIMBITS))-1)
|
||||
#define COUNT_DR (((int)pow(2,NCOUNTBITS))-1)
|
||||
|
||||
|
||||
#define ALLMOD 0xffff
|
||||
#define ALLFIFO 0xffff
|
||||
|
||||
#ifdef VIRTUAL
|
||||
#define DEBUGOUT
|
||||
#endif
|
||||
|
||||
#define CLK_FREQ 100E+6
|
||||
|
||||
|
||||
#define THIS_SOFTWARE_VERSION 0x20100429
|
||||
#endif
|
2488
slsDetectorSoftware/gotthardDetectorServer/server_funcs.c
Executable file
2488
slsDetectorSoftware/gotthardDetectorServer/server_funcs.c
Executable file
File diff suppressed because it is too large
Load Diff
71
slsDetectorSoftware/gotthardDetectorServer/server_funcs.h
Executable file
71
slsDetectorSoftware/gotthardDetectorServer/server_funcs.h
Executable file
@ -0,0 +1,71 @@
|
||||
#ifndef SERVER_FUNCS_H
|
||||
#define SERVER_FUNCS_H
|
||||
#include <stdio.h>
|
||||
/*
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
*/
|
||||
#include "communication_funcs.h"
|
||||
|
||||
|
||||
|
||||
|
||||
#define GOODBYE -200
|
||||
int function_table();
|
||||
|
||||
int decode_function();
|
||||
|
||||
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);
|
||||
|
||||
// to take out/not by dhanya..
|
||||
int getGotthard(int);
|
||||
int setGotthard(int);
|
||||
float get_temperature(int);
|
||||
|
||||
|
||||
#endif
|
180
slsDetectorSoftware/gotthardDetectorServer/server_funcs_old.c
Executable file
180
slsDetectorSoftware/gotthardDetectorServer/server_funcs_old.c
Executable file
@ -0,0 +1,180 @@
|
||||
#include "sls_detector_defs.h"
|
||||
#include "server_funcs.h"
|
||||
//#include "server_defs.h"
|
||||
|
||||
// Global variables
|
||||
|
||||
int (*flist[256])(int);
|
||||
|
||||
|
||||
|
||||
|
||||
const enum detectorType myDetectorType=GOTTHARD;
|
||||
char mess[1000];
|
||||
char stringname[100]="what i want it to be";
|
||||
|
||||
|
||||
int init_detector(int b) {
|
||||
printf("This is a GOTTHARD detector\n");
|
||||
sprintf(mess,"dummy message");
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int decode_function() {
|
||||
int fnum,n;
|
||||
int retval=FAIL;
|
||||
#ifdef VERBOSE
|
||||
printf( "receive data\n");
|
||||
#endif
|
||||
n = receiveDataOnly(&fnum,sizeof(fnum));
|
||||
if (n <= 0) {
|
||||
printf("ERROR reading from socket %d", n);
|
||||
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])(fnum);
|
||||
if (retval==FAIL)
|
||||
printf( "Error executing the function = %d \n",fnum);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int function_table(int b) {
|
||||
int i;
|
||||
for (i=0;i<256;i++){
|
||||
flist[i]=&M_nofunc;
|
||||
}
|
||||
flist[F_EXIT_SERVER]=&exit_server;
|
||||
flist[F_GET_GOTTHARD]=&getGotthard;
|
||||
flist[F_SET_GOTTHARD]=&setGotthard;
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int M_nofunc(int fnum){
|
||||
|
||||
int retval=FAIL;
|
||||
sprintf(mess,"Unrecognized Function %d\n",fnum);
|
||||
printf(mess);
|
||||
sendDataOnly(&retval,sizeof(retval));
|
||||
sendDataOnly(mess,sizeof(mess));
|
||||
return GOODBYE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int exit_server(int fnum) {
|
||||
int retval=FAIL;
|
||||
sendDataOnly(&retval,sizeof(retval));
|
||||
printf("closing server.");
|
||||
sprintf(mess,"closing server");
|
||||
sendDataOnly(mess,sizeof(mess));
|
||||
return GOODBYE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int getGotthard(int fnum) {
|
||||
|
||||
int retval=OK;
|
||||
int ret=0;
|
||||
char val[100];
|
||||
int n=0;
|
||||
printf("in getgotthard fn\n");
|
||||
/* receive arguments
|
||||
n = receiveDataOnly(val,sizeof(val));
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error reading from socket\n");
|
||||
retval=FAIL;
|
||||
}
|
||||
*/
|
||||
/* execute action if the arguments correctly arrived*/
|
||||
if (retval==OK) {
|
||||
|
||||
printf("getting stringname %s\n", stringname);
|
||||
|
||||
}
|
||||
|
||||
/* send ret */
|
||||
n = sendDataOnly(&ret,sizeof(ret));
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error writing to socket");
|
||||
retval=FAIL;
|
||||
}
|
||||
|
||||
/* send answer */
|
||||
n = sendDataOnly(stringname,sizeof(stringname));
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error writing to socket");
|
||||
retval=FAIL;
|
||||
}
|
||||
|
||||
if(retval==FAIL)
|
||||
sendDataOnly(mess,sizeof(mess));
|
||||
|
||||
|
||||
|
||||
/*return ok/fail*/
|
||||
return retval;
|
||||
|
||||
}
|
||||
|
||||
int setGotthard(int fnum) {
|
||||
int retval=OK;
|
||||
int ret=0;
|
||||
char val[100];
|
||||
int n=0;
|
||||
printf("in setgotthard fn\n");
|
||||
/* receive arguments */
|
||||
n = receiveDataOnly(val,sizeof(val));
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error reading from socket\n");
|
||||
retval=FAIL;
|
||||
}
|
||||
|
||||
/* execute action if the arguments correctly arrived*/
|
||||
if (retval==OK) {
|
||||
|
||||
printf("setting stringname %s\n", val);
|
||||
|
||||
}
|
||||
|
||||
strcpy(stringname, val);
|
||||
|
||||
/* send ret */
|
||||
n = sendDataOnly(&ret,sizeof(ret));
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error writing to socket");
|
||||
retval=FAIL;
|
||||
}
|
||||
|
||||
/* send answer */
|
||||
n = sendDataOnly(stringname,sizeof(stringname));
|
||||
if (n < 0) {
|
||||
sprintf(mess,"Error writing to socket");
|
||||
retval=FAIL;
|
||||
}
|
||||
|
||||
if(retval==FAIL)
|
||||
sendDataOnly(mess,sizeof(mess));
|
||||
|
||||
/*return ok/fail*/
|
||||
return retval;
|
||||
|
||||
}
|
||||
|
24
slsDetectorSoftware/gotthardDetectorServer/server_funcs_old.h
Executable file
24
slsDetectorSoftware/gotthardDetectorServer/server_funcs_old.h
Executable file
@ -0,0 +1,24 @@
|
||||
#ifndef SERVER_FUNCS_H
|
||||
#define SERVER_FUNCS_H
|
||||
#include <stdio.h>
|
||||
#include "communication_funcs.h"
|
||||
|
||||
|
||||
|
||||
|
||||
#define GOODBYE -200
|
||||
int function_table();
|
||||
|
||||
int decode_function();
|
||||
|
||||
int init_detector(int);
|
||||
|
||||
int M_nofunc(int);
|
||||
int exit_server(int);
|
||||
|
||||
int getGotthard(int);
|
||||
int setGotthard(int);
|
||||
|
||||
|
||||
|
||||
#endif
|
39
slsDetectorSoftware/gotthardDetectorServer/sharedmemory.c
Executable file
39
slsDetectorSoftware/gotthardDetectorServer/sharedmemory.c
Executable file
@ -0,0 +1,39 @@
|
||||
#include "sharedmemory.h"
|
||||
|
||||
struct statusdata *stdata;
|
||||
|
||||
int inism(int clsv) {
|
||||
|
||||
static int scansmid;
|
||||
|
||||
if (clsv==SMSV) {
|
||||
if ( (scansmid=shmget(SMKEY,1024,IPC_CREAT | 0666 ))==-1 ) {
|
||||
return -1;
|
||||
}
|
||||
if ( (stdata=shmat(scansmid,NULL,0))==(void*)-1) {
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
if (clsv==SMCL) {
|
||||
if ( (scansmid=shmget(SMKEY,0,0) )==-1 ) {
|
||||
return -3;
|
||||
}
|
||||
if ( (stdata=shmat(scansmid,NULL,0))==(void*)-1) {
|
||||
return -4;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void write_status_sm(char *status) {
|
||||
strcpy(stdata->status,status);
|
||||
}
|
||||
|
||||
void write_stop_sm(int v) {
|
||||
stdata->stop=v;
|
||||
}
|
||||
|
||||
void write_runnumber_sm(int v) {
|
||||
stdata->runnumber=v;
|
||||
}
|
47
slsDetectorSoftware/gotthardDetectorServer/sharedmemory.h
Executable file
47
slsDetectorSoftware/gotthardDetectorServer/sharedmemory.h
Executable file
@ -0,0 +1,47 @@
|
||||
#ifndef SM
|
||||
#define SM
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
//#include <asm/page.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#include <sys/shm.h>
|
||||
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
/* key for shared memory */
|
||||
#define SMKEY 10001
|
||||
|
||||
#define SMSV 1
|
||||
#define SMCL 2
|
||||
|
||||
|
||||
struct statusdata {
|
||||
int runnumber;
|
||||
int stop;
|
||||
char status[20];
|
||||
} ;
|
||||
|
||||
|
||||
/* for shared memory */
|
||||
|
||||
int inism(int clsv);
|
||||
void write_status_sm(char *status);
|
||||
void write_stop_sm(int v);
|
||||
void write_runnumber_sm(int v);
|
||||
|
||||
#endif
|
41
slsDetectorSoftware/gotthardDetectorServer/stop_server.c
Executable file
41
slsDetectorSoftware/gotthardDetectorServer/stop_server.c
Executable file
@ -0,0 +1,41 @@
|
||||
/* A simple server in the internet domain using TCP
|
||||
The port number is passed as an argument */
|
||||
#include "communication_funcs.h"
|
||||
//#include "firmware_funcs.h"
|
||||
|
||||
|
||||
int sockfd;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int portno;
|
||||
int retval=0;
|
||||
|
||||
portno = DEFAULT_PORTNO;
|
||||
|
||||
|
||||
bindSocket(portno);
|
||||
if (getServerError())
|
||||
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();
|
||||
retval=stopStateMachine();
|
||||
closeConnection();
|
||||
}
|
||||
|
||||
exitServer();
|
||||
printf("Goodbye!\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
755
slsDetectorSoftware/gotthardDetectorServer/trimming_funcs.c
Executable file
755
slsDetectorSoftware/gotthardDetectorServer/trimming_funcs.c
Executable file
@ -0,0 +1,755 @@
|
||||
#ifndef PICASSOD
|
||||
#include "server_defs.h"
|
||||
#else
|
||||
#include "picasso_defs.h"
|
||||
#endif
|
||||
#include "trimming_funcs.h"
|
||||
#include "mcb_funcs.h"
|
||||
#include "firmware_funcs.h"
|
||||
#include <math.h>
|
||||
|
||||
|
||||
|
||||
extern int nModX;
|
||||
//extern int *values;
|
||||
|
||||
extern const int nChans;
|
||||
extern const int nChips;
|
||||
extern const int nDacs;
|
||||
extern const int nAdcs;
|
||||
|
||||
|
||||
int trim_fixed_settings(int countlim, int par2, int im)
|
||||
{
|
||||
|
||||
int retval=OK;
|
||||
#ifdef VERBOSE
|
||||
printf("Trimming with fixed settings\n");
|
||||
#endif
|
||||
#ifdef VIRTUAL
|
||||
return OK;
|
||||
#endif
|
||||
|
||||
if (par2<=0)
|
||||
retval=trim_with_level(countlim, im);
|
||||
else
|
||||
retval=trim_with_median(countlim,im);
|
||||
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
int trim_with_noise(int countlim, int nsigma, int im)
|
||||
{
|
||||
|
||||
|
||||
int retval=OK, retval1=OK, retval2=OK;
|
||||
#ifdef VERBOSE
|
||||
printf("Trimming using noise\n");
|
||||
#endif
|
||||
#ifdef VIRTUAL
|
||||
return OK;
|
||||
#endif
|
||||
|
||||
/* threshold scan */
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("chosing vthresh and vtrim.....");
|
||||
#endif
|
||||
retval1=choose_vthresh_and_vtrim(countlim,nsigma, im);
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("trimming with noise.....\n");
|
||||
#endif
|
||||
retval2=trim_with_level(countlim, im);
|
||||
|
||||
#ifdef DEBUGOUT
|
||||
printf("done\n");
|
||||
#endif
|
||||
if (retval1==OK && retval2==OK)
|
||||
retval=OK;
|
||||
else
|
||||
retval=FAIL;
|
||||
|
||||
return retval;
|
||||
|
||||
}
|
||||
|
||||
int trim_with_beam(int countlim, int nsigma, int im) //rpc
|
||||
{
|
||||
|
||||
|
||||
int retval=OK, retval1=OK, retval2=OK;
|
||||
|
||||
printf("Trimming using beam\n");
|
||||
//return OK;
|
||||
#ifdef VIRTUAL
|
||||
printf("Trimming using beam\n");
|
||||
return OK;
|
||||
#endif
|
||||
/* threshold scan */
|
||||
#ifdef DEBUGOUT
|
||||
printf("chosing vthresh and vtrim.....");
|
||||
#endif
|
||||
|
||||
retval1=choose_vthresh_and_vtrim(countlim,nsigma,im);
|
||||
retval2=trim_with_median(TRIM_DR, im);
|
||||
|
||||
#ifdef DEBUGOUT
|
||||
printf("done\n");
|
||||
#endif
|
||||
|
||||
if (retval1==OK && retval2==OK)
|
||||
retval=OK;
|
||||
else
|
||||
retval=FAIL;
|
||||
|
||||
return retval;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int trim_improve(int maxit, int par2, int im) //rpc
|
||||
{
|
||||
|
||||
int retval=OK, retval1=OK, retval2=OK;
|
||||
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("Improve the trimming\n");
|
||||
#endif
|
||||
#ifdef VIRTUAL
|
||||
return OK;
|
||||
#endif
|
||||
|
||||
|
||||
if (par2!=0 && im==ALLMOD)
|
||||
retval1=choose_vthresh();
|
||||
|
||||
retval2=trim_with_median(2*maxit+1, im);
|
||||
#ifdef DEBUGOUT
|
||||
printf("done\n");
|
||||
#endif
|
||||
if (retval1==OK && retval2==OK)
|
||||
retval=OK;
|
||||
else
|
||||
retval=FAIL;
|
||||
|
||||
return retval;
|
||||
|
||||
}
|
||||
|
||||
int calcthr_from_vcal(int vcal) {
|
||||
int thrmin;
|
||||
//thrmin=140+3*vcal/5;
|
||||
thrmin=180+3*vcal/5;
|
||||
return thrmin;
|
||||
}
|
||||
|
||||
int calccal_from_vthr(int vthr) {
|
||||
int vcal;
|
||||
vcal=5*(vthr-140)/3;
|
||||
return vcal;
|
||||
}
|
||||
|
||||
int choose_vthresh_and_vtrim(int countlim, int nsigma, int im) {
|
||||
int retval=OK;
|
||||
#ifdef MCB_FUNCS
|
||||
int modma, modmi, nm;
|
||||
int thr, thrstep=5, nthr=31;
|
||||
|
||||
int *fifodata;
|
||||
|
||||
float vthreshmean, vthreshSTDev;
|
||||
int *thrmi, *thrma;
|
||||
float c;
|
||||
float b=BVTRIM;
|
||||
float a=AVTRIM;
|
||||
int *trim;
|
||||
int ich, imod, ichan;
|
||||
int nvalid=0;
|
||||
u_int32_t *scan;
|
||||
int ithr;
|
||||
sls_detector_channel myChan;
|
||||
|
||||
|
||||
|
||||
setFrames(1);
|
||||
// setNMod(getNModBoard());
|
||||
|
||||
if (im==ALLMOD){
|
||||
modmi=0;
|
||||
modma=nModX;
|
||||
} else {
|
||||
modmi=im;
|
||||
modma=im+1;
|
||||
}
|
||||
nm=modma-modmi;
|
||||
|
||||
trim=malloc(sizeof(int)*nChans*nChips*nModX);
|
||||
thrmi=malloc(sizeof(int)*nModX);
|
||||
thrma=malloc(sizeof(int)*nModX);
|
||||
|
||||
|
||||
for (ich=0; ich<nChans*nChips*nm; ich++)
|
||||
trim[ich]=-1;
|
||||
/*
|
||||
setCSregister(im);
|
||||
setSSregister(im);
|
||||
initChannel(0,0,0,1,0,0,im);
|
||||
counterClear(im);
|
||||
clearSSregister(im);
|
||||
usleep(500);
|
||||
*/
|
||||
myChan.chan=-1;
|
||||
myChan.chip=-1;
|
||||
myChan.module=ALLMOD;
|
||||
myChan.reg=COMPARATOR_ENABLE;
|
||||
initChannelbyNumber(myChan);
|
||||
|
||||
|
||||
for (ithr=0; ithr<nthr; ithr++) {
|
||||
fifoReset();
|
||||
/* scanning threshold */
|
||||
/* commented out by dhanya
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
thr=getDACbyIndexDACU(VTHRESH,imod);
|
||||
if (ithr==0) {
|
||||
thrmi[imod]=thr;
|
||||
initDACbyIndexDACU(VTHRESH,thr,imod);
|
||||
} else
|
||||
initDACbyIndexDACU(VTHRESH,thr+thrstep,imod);
|
||||
}
|
||||
*/
|
||||
|
||||
/* setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
initChannel(0,0,0,1,0,0,im);
|
||||
setDynamicRange(32);
|
||||
*/
|
||||
|
||||
|
||||
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
}
|
||||
usleep(500);
|
||||
fifodata=fifo_read_event();
|
||||
scan=decode_data(fifodata);
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
for (ichan=0; ichan<nChans*nChips; ichan++){
|
||||
ich=imod*nChips*nChans+ichan;
|
||||
/*commented out by dhanya
|
||||
if (scan[ich]>countlim && trim[ich]==-1) {
|
||||
trim[ich]=getDACbyIndexDACU(VTHRESH,imod);
|
||||
#ifdef VERBOSE
|
||||
// printf("yes: %d %d %d\n",ich,ithr,scan[ich]);
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
#ifdef VERBOSE
|
||||
/* else {
|
||||
printf("no: %d %d %d\n",ich,ithr,scan[ich]);
|
||||
}*/
|
||||
#endif
|
||||
}
|
||||
}
|
||||
free(scan);
|
||||
}
|
||||
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
vthreshmean=0;
|
||||
vthreshSTDev=0;
|
||||
nvalid=0;
|
||||
// commented out by dhanya thrma[imod]=getDACbyIndexDACU(VTHRESH,imod);
|
||||
|
||||
for (ichan=0; ichan<nChans*nChips; ichan++){
|
||||
ich=imod*nChans*nChips+ichan;
|
||||
if(trim[ich]>thrmi[imod] && trim[ich]<thrma[imod]) {
|
||||
vthreshmean=vthreshmean+trim[ich];
|
||||
vthreshSTDev=vthreshSTDev+trim[ich]*trim[ich];
|
||||
nvalid++;
|
||||
}
|
||||
}
|
||||
|
||||
if (nvalid>0) {
|
||||
vthreshmean=vthreshmean/nvalid;
|
||||
//vthreshSTDev=sqrt((vthreshSTDev/nvalid)-vthreshmean*vthreshmean); cuz <asm/page.h> is commented in firmware_funcs.c and in shared_memory.c
|
||||
} else {
|
||||
vthreshmean=thrmi[imod];
|
||||
vthreshSTDev=nthr*thrstep;
|
||||
printf("No valid channel for module %d\n",imod);
|
||||
retval=FAIL;
|
||||
}
|
||||
|
||||
#ifdef DEBUGOUT
|
||||
printf("module= %d nvalid = %d mean=%f RMS=%f\n",imod, nvalid, vthreshmean,vthreshSTDev);
|
||||
#endif
|
||||
// *vthresh=round(vthreshmean-nsigma*vthreshSTDev);
|
||||
thr=(int)(vthreshmean-nsigma*vthreshSTDev);
|
||||
if (thr<0 || thr>(DAC_DR-1)) {
|
||||
thr=thrmi[imod]/2;
|
||||
printf("Can't find correct threshold for module %d\n",imod);
|
||||
retval=FAIL;
|
||||
}
|
||||
//commented out by dhanya initDACbyIndexDACU(VTHRESH,thr,imod);
|
||||
#ifdef VERBOSE
|
||||
printf("vthresh=%d \n",thr);
|
||||
#endif
|
||||
c=CVTRIM-2.*nsigma*vthreshSTDev/63.;
|
||||
// thr=(int)((-b-sqrt(b*b-4*a*c))/(2*a)); cuz <asm/page.h> is commented in firmware_funcs.c and in shared_memory.c
|
||||
if (thr<500 || thr>(DAC_DR-1)) {
|
||||
thr=750;
|
||||
printf("Can't find correct trimbit size for module %d\n",imod);
|
||||
retval=FAIL;
|
||||
}
|
||||
|
||||
//commented out by dhanya initDACbyIndexDACU(VTRIM,thr,imod);
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf("vtrim=%d \n",thr);
|
||||
#endif
|
||||
|
||||
}
|
||||
free(trim);
|
||||
free(thrmi);
|
||||
free(thrma);
|
||||
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int trim_with_level(int countlim, int im) {
|
||||
int ich, itrim, ichan, ichip, imod;
|
||||
u_int32_t *scan;
|
||||
int *inttrim;
|
||||
int modma, modmi, nm;
|
||||
int retval=OK;
|
||||
int *fifodata;
|
||||
sls_detector_channel myChan;
|
||||
printf("trimming module number %d", im);
|
||||
|
||||
|
||||
#ifdef MCB_FUNCS
|
||||
setFrames(1);
|
||||
// setNMod(getNModBoard());
|
||||
|
||||
if (im==ALLMOD){
|
||||
modmi=0;
|
||||
modma=nModX;
|
||||
} else {
|
||||
modmi=im;
|
||||
modma=im+1;
|
||||
}
|
||||
nm=modma-modmi;
|
||||
|
||||
inttrim=malloc(sizeof(int)*nChips*nChans*nModX);
|
||||
printf("countlim=%d\n",countlim);
|
||||
for (ich=0; ich<nChans*nChips*nModX; ich++)
|
||||
inttrim[ich]=-1;
|
||||
|
||||
for (itrim=0; itrim<TRIM_DR+1; itrim++) {
|
||||
fifoReset();
|
||||
printf("Trimbit %d\n",itrim);
|
||||
myChan.chan=-1;
|
||||
myChan.chip=-1;
|
||||
myChan.module=ALLMOD;
|
||||
myChan.reg=COMPARATOR_ENABLE|(itrim<<TRIMBIT_OFF);
|
||||
initChannelbyNumber(myChan);
|
||||
|
||||
/*
|
||||
setCSregister(im);
|
||||
setSSregister(im);
|
||||
initChannel(itrim,0,0,1,0,0,ALLMOD);
|
||||
setDynamicRange(32);
|
||||
*/
|
||||
setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
}
|
||||
usleep(500);
|
||||
|
||||
fifodata=fifo_read_event();
|
||||
scan=decode_data(fifodata);
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
for (ichan=0; ichan<nChans*nChips; ichan++) {
|
||||
ich=ichan+imod*nChans*nChips;
|
||||
if (inttrim[ich]==-1) {
|
||||
if (scan[ich]>countlim){
|
||||
inttrim[ich]=itrim;
|
||||
if (scan[ich]>2*countlim && itrim>0) {
|
||||
//if (scan[ich]>2*countlim || itrim==0) {
|
||||
inttrim[ich]=itrim-1;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
printf("Channel %d trimbit %d counted %d (%08x) countlim %d\n",ich,itrim,scan[ich],fifodata[ich],countlim);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
/* else
|
||||
printf("Channel %d trimbit %d counted %d countlim %d\n",ich,itrim,scan[ich],countlim);*/
|
||||
#endif
|
||||
}
|
||||
}
|
||||
free(scan);
|
||||
}
|
||||
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
clearCSregister(imod);
|
||||
firstChip(im);
|
||||
for (ichip=0; ichip<nChips; ichip++) {
|
||||
clearSSregister(imod);
|
||||
for (ichan=0; ichan<nChans; ichan++) {
|
||||
nextStrip(imod);
|
||||
ich=ichan+imod*nChans*nChips+ichip*nChans;
|
||||
if (*(inttrim+ich)==-1) {
|
||||
*(inttrim+ich)=TRIM_DR;
|
||||
// printf("could not trim channel %d chip %d module %d - set to %d\n", ichan, ichip, imod, *(inttrim+ich) );
|
||||
retval=FAIL;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
// else
|
||||
// printf("channel %d trimbit %d\n",ich,*(inttrim+ich) );
|
||||
#endif
|
||||
initChannel(inttrim[ich],0,0,1,0,0,imod);
|
||||
}
|
||||
nextChip(imod);
|
||||
}
|
||||
}
|
||||
free(inttrim);
|
||||
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
#define ELEM_SWAP(a,b) { register int t=(a);(a)=(b);(b)=t; }
|
||||
#define median(a,n) kth_smallest(a,n,(((n)&1)?((n)/2):(((n)/2)-1)))
|
||||
|
||||
|
||||
int kth_smallest(int *a, int n, int k)
|
||||
{
|
||||
register int i,j,l,m ;
|
||||
register float x ;
|
||||
|
||||
l=0 ; m=n-1 ;
|
||||
while (l<m) {
|
||||
x=a[k] ;
|
||||
i=l ;
|
||||
j=m ;
|
||||
do {
|
||||
while (a[i]<x) i++ ;
|
||||
while (x<a[j]) j-- ;
|
||||
if (i<=j) {
|
||||
ELEM_SWAP(a[i],a[j]) ;
|
||||
i++ ; j-- ;
|
||||
}
|
||||
} while (i<=j) ;
|
||||
if (j<k) l=i ;
|
||||
if (k<i) m=j ;
|
||||
}
|
||||
return a[k] ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int ave(int *a, int n)
|
||||
{
|
||||
int av=0,i;
|
||||
for (i=0; i<n; i++)
|
||||
av=av+((float)*(a+i))/((float)n);
|
||||
return av;
|
||||
}
|
||||
|
||||
|
||||
int choose_vthresh() {
|
||||
|
||||
int retval=OK;
|
||||
/* commented out by dhanya
|
||||
#ifdef MCB_FUNCS
|
||||
int imod, ichan;
|
||||
u_int32_t *scan, *scan1;
|
||||
int olddiff[nModX], direction[nModX];
|
||||
int med[nModX], med1[nModX], diff, media;
|
||||
int change_flag=1;
|
||||
int iteration=0;
|
||||
int maxiterations=10;
|
||||
int vthreshmean=0;
|
||||
int vthresh;
|
||||
int im=ALLMOD;
|
||||
int modma, modmi, nm;
|
||||
int *fifodata;
|
||||
|
||||
setFrames(1);
|
||||
// setNMod(getNModBoard());
|
||||
|
||||
if (im==ALLMOD){
|
||||
modmi=0;
|
||||
modma=nModX;
|
||||
} else {
|
||||
modmi=im;
|
||||
modma=im+1;
|
||||
}
|
||||
nm=modma-modmi;
|
||||
|
||||
|
||||
|
||||
setDynamicRange(32);
|
||||
|
||||
setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
//printf(".");
|
||||
}
|
||||
usleep(500);
|
||||
|
||||
fifodata=fifo_read_event();
|
||||
scan=decode_data(fifodata);
|
||||
//
|
||||
scan1=decode_data(fifodata);
|
||||
|
||||
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
//
|
||||
med[imod]=median(scan1+imod*nChans*nChips,nChans*nChips);
|
||||
med1[imod]=med[imod];
|
||||
// commented out by dhanya vthreshmean=vthreshmean+getDACbyIndexDACU(VTHRESH,imod);
|
||||
olddiff[imod]=0xffffff;
|
||||
direction[imod]=0;
|
||||
printf("Median of module %d=%d\n",imod,med[imod]);
|
||||
}
|
||||
vthreshmean=vthreshmean/nm;
|
||||
//media=median(scan,nChans*nChips*nModX);
|
||||
//printf("Median overall=%d\n",media);
|
||||
media=median(med1+modmi,nm);
|
||||
printf("Median of modules=%d\n",media);
|
||||
free(scan);
|
||||
free(scan1);
|
||||
|
||||
|
||||
while(change_flag && iteration<maxiterations) {
|
||||
|
||||
setDynamicRange(32);
|
||||
fifoReset();
|
||||
setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
}
|
||||
usleep(500);
|
||||
|
||||
fifodata=fifo_read_event();
|
||||
scan=decode_data(fifodata);
|
||||
//
|
||||
scan1=decode_data(fifodata);
|
||||
|
||||
change_flag=0;
|
||||
printf("Vthresh iteration %3d 0f %3d\n",iteration, maxiterations);
|
||||
for (ichan=modmi; ichan<modma; ichan++) {
|
||||
med[ichan]=median(scan1+ichan*nChans*nChips,nChans*nChips);
|
||||
med1[imod]=med[imod];
|
||||
media=median(med1+modmi,nm);
|
||||
|
||||
diff=med[ichan]-media;
|
||||
if (direction[ichan]==0) {
|
||||
if (diff>0)
|
||||
direction[ichan]=1;
|
||||
else
|
||||
direction[ichan]=-1;
|
||||
}
|
||||
vthresh=getDACbyIndexDACU(VTHRESH,imod);
|
||||
if ( direction[ichan]!=-3) {
|
||||
if (abs(diff)>abs(olddiff[ichan])) {
|
||||
vthresh=vthresh-direction[ichan];
|
||||
if (vthresh>(DAC_DR-1)) {
|
||||
vthresh=(DAC_DR-1);
|
||||
printf("can't equalize threshold for module %d\n", ichan);
|
||||
retval=FAIL;
|
||||
}
|
||||
if (vthresh<0) {
|
||||
vthresh=0;
|
||||
printf("can't equalize threshold for module %d\n", ichan);
|
||||
retval=FAIL;
|
||||
}
|
||||
direction[ichan]=-3;
|
||||
} else {
|
||||
vthresh=vthresh+direction[ichan];
|
||||
olddiff[ichan]=diff;
|
||||
change_flag=1;
|
||||
}
|
||||
initDACbyIndex(VTHRESH,vthresh, ichan);
|
||||
}
|
||||
}
|
||||
iteration++;
|
||||
free(scan);
|
||||
free(scan1);
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int trim_with_median(int stop, int im) {
|
||||
|
||||
|
||||
int retval=OK;
|
||||
|
||||
#ifdef MCB_FUNCS
|
||||
int ichan, imod, ichip, ich;
|
||||
u_int32_t *scan, *scan1;
|
||||
int *olddiff, *direction;
|
||||
int med, diff;
|
||||
int change_flag=1;
|
||||
int iteration=0;
|
||||
int me[nModX], me1[nModX];
|
||||
int modma, modmi, nm;
|
||||
int trim;
|
||||
int *fifodata;
|
||||
|
||||
setFrames(1);
|
||||
// setNMod(getNModBoard());
|
||||
|
||||
if (im==ALLMOD){
|
||||
modmi=0;
|
||||
modma=nModX;
|
||||
} else {
|
||||
modmi=im;
|
||||
modma=im+1;
|
||||
}
|
||||
nm=modma-modmi;
|
||||
|
||||
olddiff=malloc(4*nModX*nChips*nChans);
|
||||
direction=malloc(4*nModX*nChips*nChans);
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
for (ichip=0; ichip<nChips; ichip++) {
|
||||
for (ich=0; ich<nChans; ich++) {
|
||||
ichan=imod*nChips*nChans+ichip*nChans+ich;
|
||||
direction[ichan]=0;
|
||||
olddiff[ichan]=0x0fffffff;
|
||||
}
|
||||
}
|
||||
}
|
||||
/********
|
||||
fifoReset();
|
||||
setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
}
|
||||
usleep(500);
|
||||
scan=decode_data(fifo_read_event());
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
me[imod]=median(scan+imod*nChans*nChips,nChans*nChips);
|
||||
printf("Median of module %d=%d\n",imod,me[imod]);
|
||||
}
|
||||
med=median(me,nm);
|
||||
printf("median is %d\n",med);
|
||||
free(scan);
|
||||
**************/
|
||||
while(change_flag && iteration<stop) {
|
||||
|
||||
setDynamicRange(32);
|
||||
fifoReset();
|
||||
setCSregister(ALLMOD);
|
||||
setSSregister(ALLMOD);
|
||||
counterClear(ALLMOD);
|
||||
clearSSregister(ALLMOD);
|
||||
usleep(500);
|
||||
startStateMachine();
|
||||
while (runBusy()) {
|
||||
}
|
||||
usleep(500);
|
||||
fifodata=fifo_read_event();
|
||||
scan=decode_data(fifodata);
|
||||
scan1=decode_data(fifodata);
|
||||
|
||||
|
||||
|
||||
/********* calculates median every time ***********/
|
||||
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
me[imod]=median(scan1+imod*nChans*nChips,nChans*nChips);
|
||||
me1[imod]=me[imod];
|
||||
printf("Median of module %d=%d\n",imod,me[imod]);
|
||||
}
|
||||
med=median(me1,nm);
|
||||
printf("median is %d\n",med);
|
||||
|
||||
change_flag=0;
|
||||
printf("Trimbits iteration %d of %d\n",iteration, stop);
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
for (ichip=0; ichip<nChips; ichip++) {
|
||||
selChip(ichip,imod);
|
||||
clearSSregister(imod);
|
||||
for (ich=0; ich<nChans; ich++) {
|
||||
ichan=imod*nChips*nChans+ichip*nChans+ich;
|
||||
nextStrip(imod);
|
||||
diff=scan[ichan]-med;
|
||||
if (direction[ichan]==0) {
|
||||
if (diff>0) {
|
||||
direction[ichan]=1;
|
||||
} else {
|
||||
direction[ichan]=-1;
|
||||
}
|
||||
}
|
||||
if ( direction[ichan]!=-3) {
|
||||
if (abs(diff)>abs(olddiff[ichan])) {
|
||||
trim=getTrimbit(imod,ichip,ich)+direction[ichan];
|
||||
printf("%d old diff %d < new diff %d %d - trimbit %d\n",ichan, olddiff[ichan], diff, direction[ichan], trim);
|
||||
direction[ichan]=-3;
|
||||
} else {
|
||||
trim=getTrimbit(imod,ichip,ich)-direction[ichan];
|
||||
olddiff[ichan]=diff;
|
||||
change_flag=1;
|
||||
}
|
||||
if (trim>TRIM_DR) {
|
||||
trim=63;
|
||||
printf("can't trim channel %d chip %d module %d to trim %d\n",ich, ichip, imod, trim);
|
||||
retval=FAIL;
|
||||
}
|
||||
if (trim<0) {
|
||||
printf("can't trim channel %d chip %d module %d to trim %d\n",ich, ichip, imod, trim);
|
||||
trim=0;
|
||||
retval=FAIL;
|
||||
}
|
||||
initChannel(trim,0,0,1,0,0,imod);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
iteration++;
|
||||
free(scan);
|
||||
free(scan1);
|
||||
}
|
||||
free(olddiff);
|
||||
free(direction);
|
||||
#endif
|
||||
return retval;
|
||||
}
|
17
slsDetectorSoftware/gotthardDetectorServer/trimming_funcs.h
Executable file
17
slsDetectorSoftware/gotthardDetectorServer/trimming_funcs.h
Executable file
@ -0,0 +1,17 @@
|
||||
#ifndef TRIMMING_FUNCS_H
|
||||
#define TRIMMING_FUNCS_H
|
||||
int trim_fixed_settings(int countlim, int par2, int imod);
|
||||
int trim_with_noise(int countlim, int nsigma, int imod);
|
||||
int trim_with_beam(int countlim, int nsigma, int imod);
|
||||
int trim_improve(int maxit, int par2, int imod);
|
||||
int calcthr_from_vcal(int vcal);
|
||||
int calccal_from_vthr(int vthr);
|
||||
int choose_vthresh_and_vtrim(int countlim, int nsigma, int imod);
|
||||
|
||||
int choose_vthresh();
|
||||
int trim_with_level(int countlim, int imod);
|
||||
int trim_with_median(int stop, int imod);
|
||||
int calcthr_from_vcal(int vcal);
|
||||
int calccal_from_vthr(int vthr);
|
||||
|
||||
#endif
|
3624
slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp
Normal file
3624
slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1277
slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h
Normal file
1277
slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -6,10 +6,6 @@
|
||||
//using namespace std;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
string mythenDetector::executeLine(int narg, char *args[], int action) {
|
||||
|
||||
|
||||
@ -99,8 +95,8 @@ string mythenDetector::executeLine(int narg, char *args[], int action) {
|
||||
std::cout<< helpLine(action);
|
||||
return string("more questions? Refere to software documentation!");
|
||||
}
|
||||
|
||||
if (var=="hostname") {
|
||||
|
||||
if (var=="hostname") {
|
||||
if (action==PUT_ACTION) {
|
||||
setTCPSocket(args[1]);
|
||||
}
|
||||
@ -270,9 +266,9 @@ string mythenDetector::executeLine(int narg, char *args[], int action) {
|
||||
if (var=="trimdir") {
|
||||
if (action==PUT_ACTION) {
|
||||
sval=string(args[1]);
|
||||
setTrimDir(sval);
|
||||
setSettingsDir(sval);
|
||||
}
|
||||
return string(getTrimDir());
|
||||
return string(getSettingsDir());
|
||||
} else if (var=="caldir") {
|
||||
if (action==PUT_ACTION) {
|
||||
sval=string(args[1]);
|
||||
@ -730,9 +726,11 @@ string mythenDetector::executeLine(int narg, char *args[], int action) {
|
||||
sett=FAST;
|
||||
else if (sval=="highgain")
|
||||
sett=HIGHGAIN;
|
||||
//setSettings(sett);
|
||||
else {
|
||||
sprintf(answer,"%s not defined for this detector",sval.c_str());
|
||||
return string(answer);
|
||||
}
|
||||
}
|
||||
//switch (setSettings( GET_SETTINGS)) {
|
||||
switch (setSettings(sett)) {
|
||||
case STANDARD:
|
||||
return string("standard");
|
||||
@ -740,6 +738,14 @@ string mythenDetector::executeLine(int narg, char *args[], int action) {
|
||||
return string("fast");
|
||||
case HIGHGAIN:
|
||||
return string("highgain");
|
||||
case DYNAMICGAIN:
|
||||
return string("dynamicgain");
|
||||
case GAIN1:
|
||||
return string("gain1");
|
||||
case GAIN2:
|
||||
return string("gain2");
|
||||
case GAIN3:
|
||||
return string("gain3");
|
||||
default:
|
||||
return string("undefined");
|
||||
}
|
||||
@ -981,14 +987,14 @@ string mythenDetector::executeLine(int narg, char *args[], int action) {
|
||||
if (action==GET_ACTION) {
|
||||
ostfn << sval << ".sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im);
|
||||
if ((myMod=getModule(im))) {
|
||||
writeTrimFile(ostfn.str(),*myMod);
|
||||
writeSettingsFile(ostfn.str(),*myMod);
|
||||
deleteModule(myMod);
|
||||
}
|
||||
} else if (action==PUT_ACTION) {
|
||||
ostfn << sval ;
|
||||
if (sval.find('.',sval.length()-7)<string::npos)
|
||||
ostfn << ".sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im);
|
||||
myMod=readTrimFile(ostfn.str());
|
||||
myMod=readSettingsFile(ostfn.str());
|
||||
if (myMod) {
|
||||
myMod->module=im;
|
||||
setModule(*myMod);
|
||||
@ -998,7 +1004,7 @@ string mythenDetector::executeLine(int narg, char *args[], int action) {
|
||||
}
|
||||
}
|
||||
std::cout<< "Returning trimfile " << std::endl;
|
||||
return string(getTrimFile());
|
||||
return string(getSettingsFile());
|
||||
} else if (var.find("trim")==0) {
|
||||
if (action==GET_ACTION) {
|
||||
trimMode mode=NOISE_TRIMMING;
|
||||
@ -1040,7 +1046,7 @@ string mythenDetector::executeLine(int narg, char *args[], int action) {
|
||||
//create file names
|
||||
ostfn << sval << ".sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im);
|
||||
if ((myMod=getModule(im))) {
|
||||
writeTrimFile(ostfn.str(),*myMod);
|
||||
writeSettingsFile(ostfn.str(),*myMod);
|
||||
deleteModule(myMod);
|
||||
}
|
||||
}
|
||||
@ -1549,29 +1555,6 @@ string mythenDetector::helpLine( int action) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* detector configuration (no communication to server) */
|
||||
|
||||
/*
|
||||
@ -1921,11 +1904,10 @@ int mythenDetector::retrieveDetectorSetup(string fname1, int level){
|
||||
|
||||
|
||||
|
||||
|
||||
/* I/O */
|
||||
|
||||
|
||||
sls_detector_module* mythenDetector::readTrimFile(string fname, sls_detector_module *myMod){
|
||||
sls_detector_module* mythenDetector::readSettingsFile(string fname, sls_detector_module *myMod){
|
||||
|
||||
int nflag=0;
|
||||
|
||||
@ -2056,7 +2038,7 @@ int mythenDetector::retrieveDetectorSetup(string fname1, int level){
|
||||
std::cout<< "read " << ichan*ichip << " channels" <<std::endl;
|
||||
#endif
|
||||
infile.close();
|
||||
strcpy(thisDetector->trimFile,fname.c_str());
|
||||
strcpy(thisDetector->settingsFile,fname.c_str());
|
||||
return myMod;
|
||||
} else {
|
||||
std::cout<< "could not open trim file " << myfname << std::endl;
|
||||
@ -2068,7 +2050,7 @@ int mythenDetector::retrieveDetectorSetup(string fname1, int level){
|
||||
};
|
||||
|
||||
|
||||
int mythenDetector::writeTrimFile(string fname, sls_detector_module mod){
|
||||
int mythenDetector::writeSettingsFile(string fname, sls_detector_module mod){
|
||||
|
||||
ofstream outfile;
|
||||
string names[]={"Vtrim", "Vthresh", "Rgsh1", "Rgsh2", "Rgpr", "Vcal", "outBuffEnable"};
|
||||
@ -2119,9 +2101,9 @@ int mythenDetector::writeTrimFile(string fname, sls_detector_module mod){
|
||||
|
||||
|
||||
|
||||
int mythenDetector::writeTrimFile(string fname, int imod){
|
||||
int mythenDetector::writeSettingsFile(string fname, int imod){
|
||||
|
||||
return writeTrimFile(fname,detectorModules[imod]);
|
||||
return writeSettingsFile(fname,detectorModules[imod]);
|
||||
|
||||
};
|
||||
|
||||
|
@ -35,7 +35,8 @@ class mythenDetector : public slsDetector{
|
||||
// ~slsDetector(){while(dataQueue.size()>0){}};
|
||||
/** destructor */
|
||||
virtual ~mythenDetector(){};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
executes a set of string arguments according to a given format. It is used to read/write configuration file, dump and retrieve detector settings and for the command line interface command parsing
|
||||
\param narg number of arguments
|
||||
@ -81,35 +82,33 @@ enum {GET_ACTION, PUT_ACTION, READOUT_ACTION};
|
||||
*/
|
||||
int retrieveDetectorSetup(string const fname, int level=0);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
reads a trim file
|
||||
reads a trim/settings file
|
||||
\param fname name of the file to be read
|
||||
\param myMod pointer to the module structure which has to be set. <BR> If it is NULL a new module structure will be created
|
||||
\returns the pointer to myMod or NULL if reading the file failed
|
||||
*/
|
||||
|
||||
sls_detector_module* readTrimFile(string fname, sls_detector_module* myMod=NULL);
|
||||
sls_detector_module* readSettingsFile(string fname, sls_detector_module* myMod=NULL);
|
||||
|
||||
/**
|
||||
writes a trim file
|
||||
writes a trim/settings file
|
||||
\param fname name of the file to be written
|
||||
\param mod module structure which has to be written to file
|
||||
\returns OK or FAIL if the file could not be written
|
||||
|
||||
\sa ::sls_detector_module
|
||||
*/
|
||||
int writeTrimFile(string fname, sls_detector_module mod);
|
||||
int writeSettingsFile(string fname, sls_detector_module mod);
|
||||
|
||||
/**
|
||||
writes a trim file for module number imod - the values will be read from the current detector structure
|
||||
writes a trim/settings file for module number imod - the values will be read from the current detector structure
|
||||
\param fname name of the file to be written
|
||||
\param imod module number
|
||||
\returns OK or FAIL if the file could not be written
|
||||
\sa ::sls_detector_module sharedSlsDetector
|
||||
*/
|
||||
int writeTrimFile(string fname, int imod);
|
||||
int writeSettingsFile(string fname, int imod);
|
||||
|
||||
/**
|
||||
writes a data file
|
||||
|
@ -69,7 +69,7 @@ int mapCSP0(void) {
|
||||
fd = open("/dev/mem", O_RDWR | O_SYNC, 0);
|
||||
if (fd == -1) {
|
||||
printf("\nCan't find /dev/mem!\n");
|
||||
return FAIL;
|
||||
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);
|
||||
|
@ -150,7 +150,7 @@ int M_nofunc(int fnum){
|
||||
printf(mess);
|
||||
sendDataOnly(&retval,sizeof(retval));
|
||||
sendDataOnly(mess,sizeof(mess));
|
||||
return -1;
|
||||
return GOODBYE;
|
||||
}
|
||||
|
||||
|
||||
@ -825,6 +825,14 @@ int set_dac(int fnum) {
|
||||
case PREAMP:
|
||||
idac=RGPR;
|
||||
break;
|
||||
/***************************************************************
|
||||
add possible potentiometers like in chiptest board!!!!!!!!!!!!!!!
|
||||
|
||||
****************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
default:
|
||||
printf("Unknown DAC index %d\n",ind);
|
||||
sprintf(mess,"Unknown DAC index %d\n",ind);
|
||||
|
@ -476,9 +476,9 @@ int choose_vthresh() {
|
||||
int retval=OK;
|
||||
#ifdef MCB_FUNCS
|
||||
int imod, ichan;
|
||||
u_int32_t *scan;
|
||||
u_int32_t *scan, *scan1;
|
||||
int olddiff[nModX], direction[nModX];
|
||||
int med[nModX], diff, media;
|
||||
int med[nModX], med1[nModX], diff, media;
|
||||
int change_flag=1;
|
||||
int iteration=0;
|
||||
int maxiterations=10;
|
||||
@ -517,10 +517,14 @@ int choose_vthresh() {
|
||||
|
||||
fifodata=fifo_read_event();
|
||||
scan=decode_data(fifodata);
|
||||
//
|
||||
scan1=decode_data(fifodata);
|
||||
|
||||
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
med[imod]=median(scan+imod*nChans*nChips,nChans*nChips);
|
||||
//
|
||||
med[imod]=median(scan1+imod*nChans*nChips,nChans*nChips);
|
||||
med1[imod]=med[imod];
|
||||
vthreshmean=vthreshmean+getDACbyIndexDACU(VTHRESH,imod);
|
||||
olddiff[imod]=0xffffff;
|
||||
direction[imod]=0;
|
||||
@ -529,9 +533,12 @@ int choose_vthresh() {
|
||||
vthreshmean=vthreshmean/nm;
|
||||
//media=median(scan,nChans*nChips*nModX);
|
||||
//printf("Median overall=%d\n",media);
|
||||
media=median(med+modmi,nm);
|
||||
media=median(med1+modmi,nm);
|
||||
printf("Median of modules=%d\n",media);
|
||||
free(scan);
|
||||
free(scan1);
|
||||
|
||||
|
||||
while(change_flag && iteration<maxiterations) {
|
||||
|
||||
setDynamicRange(32);
|
||||
@ -548,12 +555,16 @@ int choose_vthresh() {
|
||||
|
||||
fifodata=fifo_read_event();
|
||||
scan=decode_data(fifodata);
|
||||
//
|
||||
scan1=decode_data(fifodata);
|
||||
|
||||
change_flag=0;
|
||||
printf("Vthresh iteration %3d 0f %3d\n",iteration, maxiterations);
|
||||
for (ichan=modmi; ichan<modma; ichan++) {
|
||||
med[ichan]=median(scan+ichan*nChans*nChips,nChans*nChips);
|
||||
media=median(med+modmi,nm);
|
||||
med[ichan]=median(scan1+ichan*nChans*nChips,nChans*nChips);
|
||||
med1[imod]=med[imod];
|
||||
media=median(med1+modmi,nm);
|
||||
|
||||
diff=med[ichan]-media;
|
||||
if (direction[ichan]==0) {
|
||||
if (diff>0)
|
||||
@ -586,6 +597,7 @@ int choose_vthresh() {
|
||||
}
|
||||
iteration++;
|
||||
free(scan);
|
||||
free(scan1);
|
||||
}
|
||||
#endif
|
||||
return retval;
|
||||
@ -602,12 +614,12 @@ int trim_with_median(int stop, int im) {
|
||||
|
||||
#ifdef MCB_FUNCS
|
||||
int ichan, imod, ichip, ich;
|
||||
u_int32_t *scan;
|
||||
u_int32_t *scan, *scan1;
|
||||
int *olddiff, *direction;
|
||||
int med, diff;
|
||||
int change_flag=1;
|
||||
int iteration=0;
|
||||
int me[nModX];
|
||||
int me[nModX], me1[nModX];
|
||||
int modma, modmi, nm;
|
||||
int trim;
|
||||
int *fifodata;
|
||||
@ -631,7 +643,7 @@ int trim_with_median(int stop, int im) {
|
||||
for (ich=0; ich<nChans; ich++) {
|
||||
ichan=imod*nChips*nChans+ichip*nChans+ich;
|
||||
direction[ichan]=0;
|
||||
olddiff[ichan]=0xffffffff;
|
||||
olddiff[ichan]=0x0fffffff;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -670,16 +682,18 @@ int trim_with_median(int stop, int im) {
|
||||
usleep(500);
|
||||
fifodata=fifo_read_event();
|
||||
scan=decode_data(fifodata);
|
||||
scan1=decode_data(fifodata);
|
||||
|
||||
|
||||
|
||||
/********* calculates median every time ***********/
|
||||
|
||||
for (imod=modmi; imod<modma; imod++) {
|
||||
me[imod]=median(scan+imod*nChans*nChips,nChans*nChips);
|
||||
me[imod]=median(scan1+imod*nChans*nChips,nChans*nChips);
|
||||
me1[imod]=me[imod];
|
||||
printf("Median of module %d=%d\n",imod,me[imod]);
|
||||
}
|
||||
med=median(me,nm);
|
||||
med=median(me1,nm);
|
||||
printf("median is %d\n",med);
|
||||
|
||||
change_flag=0;
|
||||
@ -691,7 +705,7 @@ int trim_with_median(int stop, int im) {
|
||||
for (ich=0; ich<nChans; ich++) {
|
||||
ichan=imod*nChips*nChans+ichip*nChans+ich;
|
||||
nextStrip(imod);
|
||||
diff=scan[ichan]-med;
|
||||
diff=scan[ichan]-me[imod];
|
||||
if (direction[ichan]==0) {
|
||||
if (diff>0) {
|
||||
direction[ichan]=1;
|
||||
@ -726,6 +740,7 @@ int trim_with_median(int stop, int im) {
|
||||
}
|
||||
iteration++;
|
||||
free(scan);
|
||||
free(scan1);
|
||||
}
|
||||
free(olddiff);
|
||||
free(direction);
|
||||
|
@ -5,10 +5,6 @@
|
||||
#include <sys/shm.h>
|
||||
|
||||
|
||||
|
||||
//using namespace std;
|
||||
|
||||
|
||||
int slsDetector::initSharedMemory(detectorType type, int id) {
|
||||
|
||||
|
||||
@ -34,6 +30,12 @@ int slsDetector::initSharedMemory(detectorType type, int id) {
|
||||
nc=12;
|
||||
nd=6; // dacs+adcs
|
||||
break;
|
||||
case GOTTHARD:
|
||||
nch=128;
|
||||
nm=1;
|
||||
nc=10;
|
||||
nd=13; // dacs+adcs
|
||||
break;
|
||||
default:
|
||||
nch=65535; // one EIGER module
|
||||
nm=1; //modules/detector
|
||||
@ -115,22 +117,25 @@ slsDetector::slsDetector(detectorType type, int id):
|
||||
chanregs(NULL),
|
||||
badChannelMask(NULL)
|
||||
{
|
||||
while (shmId<0) {
|
||||
/**Initlializes shared memory \sa initSharedMemory
|
||||
while (shmId<0) {
|
||||
/**Initlializes shared memory \sa initSharedMemory
|
||||
|
||||
if it fails the detector id is incremented until it succeeds
|
||||
*/
|
||||
shmId=initSharedMemory(type,id);
|
||||
id++;
|
||||
}
|
||||
id--;
|
||||
if it fails the detector id is incremented until it succeeds
|
||||
*/
|
||||
shmId=initSharedMemory(type,id);
|
||||
id++;
|
||||
}
|
||||
id--;
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Detector id is " << id << std::endl;
|
||||
std::cout<< "Detector id is " << id << std::endl;
|
||||
#endif
|
||||
detId=id;
|
||||
/**Initializes the detector stucture \sa initializeDetectorSize
|
||||
*/
|
||||
initializeDetectorSize(type);
|
||||
detId=id;
|
||||
|
||||
|
||||
/**Initializes the detector stucture \sa initializeDetectorSize
|
||||
*/
|
||||
initializeDetectorSize(type);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -146,10 +151,17 @@ int slsDetector::initializeDetectorSize(detectorType type) {
|
||||
/** sets onlineFlag to OFFLINE_FLAG */
|
||||
thisDetector->onlineFlag=OFFLINE_FLAG;
|
||||
/** set ports to defaults */
|
||||
switch(type){
|
||||
case GOTTHARD:
|
||||
thisDetector->controlPort=DEFAULT_PORTNO_GOTTHARD;
|
||||
thisDetector->stopPort=DEFAULT_PORTNO_GOTTHARD+1;
|
||||
thisDetector->dataPort=DEFAULT_PORTNO_GOTTHARD+2;
|
||||
break;
|
||||
default:
|
||||
thisDetector->controlPort=DEFAULT_PORTNO;
|
||||
thisDetector->stopPort=DEFAULT_PORTNO+1;
|
||||
thisDetector->dataPort=DEFAULT_PORTNO+2;
|
||||
|
||||
}
|
||||
/** set thisDetector->myDetectorType to type and according to this set nChans, nChips, nDacs, nAdcs, nModMax, dynamicRange, nMod*/
|
||||
thisDetector->myDetectorType=type;
|
||||
switch(thisDetector->myDetectorType) {
|
||||
@ -171,6 +183,15 @@ int slsDetector::initializeDetectorSize(detectorType type) {
|
||||
thisDetector->nModMax[Y]=1;
|
||||
thisDetector->dynamicRange=24;
|
||||
break;
|
||||
case GOTTHARD:
|
||||
thisDetector->nChans=128;
|
||||
thisDetector->nChips=10;
|
||||
thisDetector->nDacs=8;
|
||||
thisDetector->nAdcs=5;
|
||||
thisDetector->nModMax[X]=1;
|
||||
thisDetector->nModMax[Y]=1;
|
||||
thisDetector->dynamicRange=1;
|
||||
break;
|
||||
default:
|
||||
thisDetector->nChans=65536;
|
||||
thisDetector->nChips=8;
|
||||
@ -196,11 +217,11 @@ int slsDetector::initializeDetectorSize(detectorType type) {
|
||||
else
|
||||
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*thisDetector->dynamicRange/8;
|
||||
/** set trimDsdir, calDir and filePath to default to home directory*/
|
||||
strcpy(thisDetector->trimDir,getenv("HOME"));
|
||||
strcpy(thisDetector->settingsDir,getenv("HOME"));
|
||||
strcpy(thisDetector->calDir,getenv("HOME"));
|
||||
strcpy(thisDetector->filePath,getenv("HOME"));
|
||||
/** sets trimbit file */
|
||||
strcpy(thisDetector->trimFile,"none");
|
||||
strcpy(thisDetector->settingsFile,"none");
|
||||
/** set fileName to default to run*/
|
||||
strcpy(thisDetector->fileName,"run");
|
||||
/** set fileIndex to default to 0*/
|
||||
@ -2324,7 +2345,7 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti
|
||||
*/
|
||||
detectorSettings slsDetector::getSettings(int imod){
|
||||
|
||||
|
||||
|
||||
int fnum=F_SET_SETTINGS;
|
||||
int ret=FAIL;
|
||||
char mess[100];
|
||||
@ -2359,16 +2380,29 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
detectorSettings slsDetector::setSettings( detectorSettings isettings, int imod){
|
||||
#ifdef VERBOSE
|
||||
//#ifdef VERBOSE
|
||||
std::cout<< "slsDetector setSettings "<< std::endl;
|
||||
#endif
|
||||
//#endif
|
||||
sls_detector_module *myMod=createModule();
|
||||
int modmi=imod, modma=imod+1, im=imod;
|
||||
string trimfname, calfname;
|
||||
string settingsfname, calfname;
|
||||
string ssettings;
|
||||
detectorSettings minsettings, maxsettings;
|
||||
|
||||
if (isettings>=STANDARD && isettings<=HIGHGAIN) {
|
||||
switch(thisDetector->myDetectorType){
|
||||
case GOTTHARD:
|
||||
minsettings = HIGHGAIN;
|
||||
maxsettings = GAIN3;
|
||||
break;
|
||||
default:
|
||||
minsettings = STANDARD;
|
||||
maxsettings = HIGHGAIN;
|
||||
}
|
||||
|
||||
if (isettings>=minsettings && isettings<=maxsettings) {
|
||||
switch (isettings) {
|
||||
case STANDARD:
|
||||
ssettings="/standard";
|
||||
@ -2382,10 +2416,26 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti
|
||||
ssettings="/highgain";
|
||||
thisDetector->currentSettings=HIGHGAIN;
|
||||
break;
|
||||
case DYNAMICGAIN:
|
||||
ssettings="/dynamicgain";
|
||||
thisDetector->currentSettings=DYNAMICGAIN;
|
||||
break;
|
||||
case GAIN1:
|
||||
ssettings="/gain1";
|
||||
thisDetector->currentSettings=GAIN1;
|
||||
break;
|
||||
case GAIN2:
|
||||
ssettings="/gain2";
|
||||
thisDetector->currentSettings=GAIN2;
|
||||
break;
|
||||
case GAIN3:
|
||||
ssettings="/gain3";
|
||||
thisDetector->currentSettings=GAIN3;
|
||||
break;
|
||||
default:
|
||||
std::cout<< "Unknown settings!" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
if (imod<0) {
|
||||
modmi=0;
|
||||
// modma=thisDetector->nModMax[X]*thisDetector->nModMax[Y];
|
||||
@ -2396,31 +2446,46 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti
|
||||
ostringstream ostfn, oscfn;
|
||||
myMod->module=im;
|
||||
//create file names
|
||||
ostfn << thisDetector->trimDir << ssettings <<"/noise.sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im) << setbase(10);
|
||||
oscfn << thisDetector->calDir << ssettings << "/calibration.sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im) << setbase(10);
|
||||
//
|
||||
trimfname=ostfn.str();
|
||||
#ifdef VERBOSE
|
||||
cout << trimfname << endl;
|
||||
#endif
|
||||
if (readTrimFile(trimfname,myMod)) {
|
||||
switch(thisDetector->myDetectorType){
|
||||
case GOTTHARD:
|
||||
ostfn << thisDetector->settingsDir << ssettings <<"/settings.sn";// << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im) << setbase(10);
|
||||
oscfn << thisDetector->calDir << ssettings << "/calibration.sn";// << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im) << setbase(10);
|
||||
std::cout<< thisDetector->settingsDir<<endl<< thisDetector->calDir <<endl;
|
||||
break;
|
||||
default:
|
||||
ostfn << thisDetector->settingsDir << ssettings <<"/noise.sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im) << setbase(10);
|
||||
oscfn << thisDetector->calDir << ssettings << "/calibration.sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im) << setbase(10);
|
||||
}
|
||||
//oscfn << thisDetector->calDir << ssettings << "/calibration.sn" << setfill('0') << setw(3) << hex << getId(MODULE_SERIAL_NUMBER, im) << setbase(10);
|
||||
|
||||
settingsfname=ostfn.str();
|
||||
//#ifdef VERBOSE
|
||||
cout << "the settings name is "<<settingsfname << endl;
|
||||
//#endif
|
||||
if (readSettingsFile(settingsfname,myMod)) {
|
||||
calfname=oscfn.str();
|
||||
#ifdef VERBOSE
|
||||
cout << calfname << endl;
|
||||
cout << calfname << endl;
|
||||
#endif
|
||||
readCalibrationFile(calfname,myMod->gain, myMod->offset);
|
||||
setModule(*myMod);
|
||||
} else {
|
||||
ostringstream ostfn,oscfn;
|
||||
ostfn << thisDetector->trimDir << ssettings << ssettings << ".trim";
|
||||
switch(thisDetector->myDetectorType){
|
||||
case GOTTHARD:
|
||||
ostfn << thisDetector->settingsDir << ssettings << ssettings << ".settings";
|
||||
break;
|
||||
default:
|
||||
ostfn << thisDetector->settingsDir << ssettings << ssettings << ".trim";
|
||||
}
|
||||
oscfn << thisDetector->calDir << ssettings << ssettings << ".cal";
|
||||
calfname=oscfn.str();
|
||||
trimfname=ostfn.str();
|
||||
settingsfname=ostfn.str();
|
||||
#ifdef VERBOSE
|
||||
cout << trimfname << endl;
|
||||
cout << calfname << endl;
|
||||
cout << settingsfname << endl;
|
||||
cout << calfname << endl;
|
||||
#endif
|
||||
if (readTrimFile(trimfname,myMod)) {
|
||||
if (readSettingsFile(settingsfname,myMod)) {
|
||||
calfname=oscfn.str();
|
||||
readCalibrationFile(calfname,myMod->gain, myMod->offset);
|
||||
setModule(*myMod);
|
||||
@ -2429,18 +2494,23 @@ int slsDetector::setThresholdEnergy(int e_eV, int imod, detectorSettings isetti
|
||||
}
|
||||
}
|
||||
deleteModule(myMod);
|
||||
/*
|
||||
if (thisDetector->correctionMask&(1<<RATE_CORRECTION)) {
|
||||
int isett=getSettings(imod);
|
||||
float t[]=defaultTDead;
|
||||
if (isett>-1 && isett<3) {
|
||||
thisDetector->tDead=t[isett];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
return getSettings(imod);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Acquisition functions
|
||||
/* change these funcs accepting also ok/fail */
|
||||
|
||||
@ -3698,8 +3768,7 @@ int slsDetector::exitServer(){
|
||||
|
||||
int retval;
|
||||
int fnum=F_EXIT_SERVER;
|
||||
|
||||
|
||||
|
||||
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
||||
if (controlSocket) {
|
||||
controlSocket->Connect();
|
||||
@ -3708,12 +3777,13 @@ int slsDetector::exitServer(){
|
||||
controlSocket->Disconnect();
|
||||
}
|
||||
}
|
||||
if (retval==OK) {
|
||||
if (retval!=OK) {
|
||||
std::cout<< std::endl;
|
||||
std::cout<< "Shutting down the server" << std::endl;
|
||||
std::cout<< std::endl;
|
||||
}
|
||||
return retval;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -160,8 +160,8 @@ typedef struct sharedSlsDetector {
|
||||
detectorType myDetectorType;
|
||||
|
||||
|
||||
/** path of the trimbits files */
|
||||
char trimDir[MAX_STR_LENGTH];
|
||||
/** path of the trimbits/settings files */
|
||||
char settingsDir[MAX_STR_LENGTH];
|
||||
/** path of the calibration files */
|
||||
char calDir[MAX_STR_LENGTH];
|
||||
/** number of energies at which the detector has been trimmed (unused) */
|
||||
@ -253,7 +253,7 @@ typedef struct sharedSlsDetector {
|
||||
|
||||
/* detector setup - not needed */
|
||||
/** name root of the output files */
|
||||
char trimFile[MAX_STR_LENGTH];
|
||||
char settingsFile[MAX_STR_LENGTH];
|
||||
/** detector settings (standard, fast, etc.) */
|
||||
detectorSettings currentSettings;
|
||||
/** detector threshold (eV) */
|
||||
@ -322,6 +322,7 @@ typedef struct sharedSlsDetector {
|
||||
\returns 1 if the detector structure has already be initlialized, 0 otherwise */
|
||||
int exists() {return thisDetector->alreadyExisting;};
|
||||
|
||||
|
||||
/**
|
||||
Purely virtual function
|
||||
Should be implemented in the specific detector class
|
||||
@ -378,10 +379,10 @@ typedef struct sharedSlsDetector {
|
||||
|
||||
|
||||
/* I/O */
|
||||
/** returns the detector trimbit directory \sa sharedSlsDetector */
|
||||
char* getTrimDir() {return thisDetector->trimDir;};
|
||||
/** sets the detector trimbit directory \sa sharedSlsDetector */
|
||||
char* setTrimDir(string s) {sprintf(thisDetector->trimDir, s.c_str()); return thisDetector->trimDir;};
|
||||
/** returns the detector trimbit/settings directory \sa sharedSlsDetector */
|
||||
char* getSettingsDir() {return thisDetector->settingsDir;};
|
||||
/** sets the detector trimbit/settings directory \sa sharedSlsDetector */
|
||||
char* setSettingsDir(string s) {sprintf(thisDetector->settingsDir, s.c_str()); return thisDetector->settingsDir;};
|
||||
/** returns the number of trim energies and their value \sa sharedSlsDetector
|
||||
\param point to the array that will contain the trim energies (in ev)
|
||||
\returns number of trim energies
|
||||
@ -404,49 +405,49 @@ typedef struct sharedSlsDetector {
|
||||
|
||||
/**
|
||||
Pure virtual function
|
||||
reads a trim file
|
||||
reads a trim/settings file
|
||||
\param fname name of the file to be read
|
||||
\param myMod pointer to the module structure which has to be set. <BR> If it is NULL a new module structure will be created
|
||||
\returns the pointer to myMod or NULL if reading the file failed
|
||||
\sa mythenDetector::readTrimFile
|
||||
\sa mythenDetector::readSettingsFile
|
||||
*/
|
||||
|
||||
virtual sls_detector_module* readTrimFile(string fname, sls_detector_module* myMod=NULL)=0;
|
||||
virtual sls_detector_module* readSettingsFile(string fname, sls_detector_module* myMod=NULL)=0;
|
||||
|
||||
/**
|
||||
Pure virtual function
|
||||
writes a trim file
|
||||
writes a trim/settings file
|
||||
\param fname name of the file to be written
|
||||
\param mod module structure which has to be written to file
|
||||
\returns OK or FAIL if the file could not be written
|
||||
|
||||
\sa ::sls_detector_module mythenDetector::writeTrimFile(string, sls_detector_module)
|
||||
\sa ::sls_detector_module mythenDetector::writeSettingsFile(string, sls_detector_module)
|
||||
*/
|
||||
virtual int writeTrimFile(string fname, sls_detector_module mod)=0;
|
||||
virtual int writeSettingsFile(string fname, sls_detector_module mod)=0;
|
||||
|
||||
/**
|
||||
returns currently the loaded trimfile name
|
||||
Pure virtual function
|
||||
writes a trim/settings file for module number imod - the values will be read from the current detector structure
|
||||
\param fname name of the file to be written
|
||||
\param imod module number
|
||||
\returns OK or FAIL if the file could not be written
|
||||
\sa ::sls_detector_module sharedSlsDetector mythenDetector::writeSettingsFile(string, int)
|
||||
*/
|
||||
virtual int writeSettingsFile(string fname, int imod)=0;
|
||||
|
||||
const char *getTrimFile(){\
|
||||
string s(thisDetector->trimFile); \
|
||||
|
||||
/**
|
||||
returns currently the loaded trimfile/settingsfile name
|
||||
*/
|
||||
const char *getSettingsFile(){\
|
||||
string s(thisDetector->settingsFile); \
|
||||
if (s.length()>6) {\
|
||||
if (s.substr(s.length()-6,3)==string(".sn") && s.substr(s.length()-3)!=string("xxx") ) \
|
||||
return s.substr(0,s.length()-6).c_str(); \
|
||||
} \
|
||||
return thisDetector->trimFile;\
|
||||
return thisDetector->settingsFile;\
|
||||
};
|
||||
|
||||
/**
|
||||
Pure virtual function
|
||||
writes a trim file for module number imod - the values will be read from the current detector structure
|
||||
\param fname name of the file to be written
|
||||
\param imod module number
|
||||
\returns OK or FAIL if the file could not be written
|
||||
\sa ::sls_detector_module sharedSlsDetector mythenDetector::writeTrimFile(string, int)
|
||||
*/
|
||||
virtual int writeTrimFile(string fname, int imod)=0;
|
||||
|
||||
/**
|
||||
sets the default output files path
|
||||
\sa sharedSlsDetector
|
||||
@ -899,7 +900,7 @@ typedef struct sharedSlsDetector {
|
||||
\param imod module number (-1 all)
|
||||
\returns current settings
|
||||
|
||||
in this function trimbits and calibration files are searched in the trimDir and calDir directories and the detector is initialized
|
||||
in this function trimbits/settings and calibration files are searched in the settingsDir and calDir directories and the detector is initialized
|
||||
*/
|
||||
virtual detectorSettings setSettings(detectorSettings isettings, int imod=-1);
|
||||
|
||||
|
@ -2,6 +2,142 @@
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#ifdef EPICS
|
||||
|
||||
#include <cadef.h>
|
||||
#include <epicsEvent.h>
|
||||
|
||||
static double timeout = 3.0;
|
||||
|
||||
/* connect to a PV */
|
||||
int connect_channel(const char *name, chid *ch_id) {
|
||||
int status = ECA_NORMAL;
|
||||
status = ca_create_channel(name, NULL, NULL, CA_PRIORITY_DEFAULT, ch_id);
|
||||
if (status != ECA_NORMAL)
|
||||
return status;
|
||||
|
||||
status = ca_pend_io(timeout);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* disconnect to a PV */
|
||||
int disconnect_channel(chid ch_id)
|
||||
{
|
||||
ca_clear_channel(ch_id);
|
||||
ca_flush_io();
|
||||
}
|
||||
|
||||
int caget(chid ch_id, double *value) {
|
||||
|
||||
int status = ECA_NORMAL;
|
||||
|
||||
status = ca_get(DBR_DOUBLE, ch_id, value);
|
||||
if (status != ECA_NORMAL) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = ca_pend_io(timeout);
|
||||
if (status != ECA_NORMAL) {
|
||||
return status;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int caputq(chid ch_id, double value) {
|
||||
// does not wait!
|
||||
int status = ECA_NORMAL;
|
||||
|
||||
status = ca_put(DBR_DOUBLE, ch_id, &value);
|
||||
if (status != ECA_NORMAL)
|
||||
return status;
|
||||
|
||||
status = ca_pend_io(timeout);
|
||||
if (status != ECA_NORMAL) {
|
||||
return status;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void put_callback(struct event_handler_args args)
|
||||
{
|
||||
epicsEventId eid = (epicsEventId)args.usr;
|
||||
epicsEventSignal(eid);
|
||||
}
|
||||
|
||||
int caput(chid ch_id, double value) {
|
||||
|
||||
// waits!
|
||||
int status = ECA_NORMAL;
|
||||
epicsEventId eid = epicsEventCreate(epicsEventEmpty);
|
||||
|
||||
status = ca_put_callback(DBR_DOUBLE,
|
||||
ch_id,
|
||||
&value,
|
||||
put_callback,
|
||||
eid);
|
||||
status = ca_pend_io(timeout);
|
||||
if (status != ECA_NORMAL)
|
||||
return status;
|
||||
|
||||
if (epicsEventWait(eid) != epicsEventWaitOK)
|
||||
status = ECA_TIMEOUT;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/* int main(int argc, char *argv[]) { */
|
||||
/* double value = 256; */
|
||||
/* /\* channel name *\/ */
|
||||
/* const char *name = "ARIDI-PCT:CURRENT"; */
|
||||
/* /\* channel id *\/ */
|
||||
/* chid ch_id; */
|
||||
/* /\* status code *\/ */
|
||||
/* int status; */
|
||||
|
||||
/* /\* init channel access context before any caget/put *\/ */
|
||||
/* ca_context_create(ca_enable_preemptive_callback); */
|
||||
|
||||
/* /\* open the channel by name and return ch_id *\/ */
|
||||
/* status = connect_channel(name, &ch_id); */
|
||||
/* if (status == ECA_NORMAL) */
|
||||
/* printf("channel connected %s\n", name); */
|
||||
/* else { */
|
||||
/* printf(ca_message(status)); */
|
||||
/* return -1; */
|
||||
/* } */
|
||||
/* /\* caput and wait until done *\/ */
|
||||
/* if ((status = caput(ch_id, value)) == ECA_NORMAL) */
|
||||
/* printf("caput: success\n"); */
|
||||
/* else */
|
||||
/* printf(ca_message(status)); */
|
||||
|
||||
/* /\* caget *\/ */
|
||||
/* if (caget(ch_id, &value) == ECA_NORMAL) */
|
||||
/* printf("caget: %f\n", value); */
|
||||
/* else */
|
||||
/* printf(ca_message(status)); */
|
||||
|
||||
/* /\* close channel connect *\/ */
|
||||
/* disconnect_channel(ch_id); */
|
||||
|
||||
/* /\* delete channel access context before program exits *\/ */
|
||||
/* ca_context_destroy(); */
|
||||
/* } */
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
float pos;
|
||||
float i0=0;
|
||||
|
||||
|
@ -9,11 +9,27 @@ Functions depending on the experimental setup should be defined here
|
||||
#define PI 3.14159265358979323846
|
||||
|
||||
|
||||
#ifdef EPICS
|
||||
#include <cadef.h>
|
||||
#include <epicsEvent.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef EPICS
|
||||
int connect_channel(const char *name, chid *ch_id);
|
||||
int disconnect_channel(chid ch_id);
|
||||
int caget(chid ch_id, double *value);
|
||||
int caputq(chid ch_id, double value);
|
||||
void put_callback(struct event_handler_args args);
|
||||
int caput(chid ch_id, double value);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
float angle(int ichan, float encoder, float totalOffset, float conv_r, float center, float offset, float tilt, int direction);
|
||||
float get_position();
|
||||
int go_to_position(float p);
|
||||
|
Loading…
x
Reference in New Issue
Block a user