mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-28 17:10:03 +02:00
added eiger server to svn
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@436 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
parent
1847eaf1d7
commit
55bfeb6044
26
slsDetectorSoftware/eigerDetectorServer/Makefile
Normal file
26
slsDetectorSoftware/eigerDetectorServer/Makefile
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
CC = powerpc-4xx-softfloat-gcc
|
||||||
|
CLAGS += -Wall -DVIRTUAL -DDACS_INT -DSLS_DETECTOR_FUNCTION_LIST -DEIGERD
|
||||||
|
LDLIBS += -lm
|
||||||
|
|
||||||
|
PROGS = eigerDetectorServer
|
||||||
|
DESTDIR ?= bin
|
||||||
|
INSTMODE = 0777
|
||||||
|
|
||||||
|
SRC_CLNT = slsDetectorServer.c slsDetectorServer_funcs.c communication_funcs.c slsDetector_firmware.c slsDetectorFunctionList.c
|
||||||
|
OBJS = $(SRC_CLNT:.cpp=.o)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
all: clean $(PROGS)
|
||||||
|
|
||||||
|
boot: $(OBJS)
|
||||||
|
|
||||||
|
$(PROGS):
|
||||||
|
echo $(OBJS)
|
||||||
|
mkdir -p $(DESTDIR)
|
||||||
|
$(CC) $(SRC_CLNT) $(CLAGS) $(LDLIBS) -o $@
|
||||||
|
mv $(PROGS) $(DESTDIR)
|
||||||
|
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(DESTDIR)/$(PROGS) *.o
|
547
slsDetectorSoftware/eigerDetectorServer/communication_funcs.c
Executable file
547
slsDetectorSoftware/eigerDetectorServer/communication_funcs.c
Executable file
@ -0,0 +1,547 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#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>
|
||||||
|
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//int socketDescriptor, file_des;
|
||||||
|
const int send_rec_max_size=SEND_REC_MAX_SIZE;
|
||||||
|
extern int errno;
|
||||||
|
|
||||||
|
|
||||||
|
char dummyClientIP[INET_ADDRSTRLEN];
|
||||||
|
|
||||||
|
|
||||||
|
fd_set readset, tempset;
|
||||||
|
int isock=0, maxfd;
|
||||||
|
|
||||||
|
|
||||||
|
int myport=-1;
|
||||||
|
|
||||||
|
//struct sockaddr_in address;
|
||||||
|
//#define VERBOSE
|
||||||
|
|
||||||
|
|
||||||
|
int bindSocket(unsigned short int port_number) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
struct sockaddr_in addressS;
|
||||||
|
int socketDescriptor;
|
||||||
|
//int file_des;
|
||||||
|
|
||||||
|
//file_des= -1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (myport==port_number)
|
||||||
|
return -10;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
socketDescriptor = socket(AF_INET, SOCK_STREAM,0); //tcp
|
||||||
|
|
||||||
|
//socketDescriptor = socket(PF_INET, SOCK_STREAM, 0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (socketDescriptor < 0) {
|
||||||
|
printf("Can not create socket\n");
|
||||||
|
} else {
|
||||||
|
|
||||||
|
i = 1;
|
||||||
|
setsockopt(socketDescriptor, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
|
||||||
|
// setsockopt(socketDescriptor, IPPROTO_TCP, TCP_NODELAY, (char *) &i, sizeof(i));
|
||||||
|
// TCP_CORK
|
||||||
|
|
||||||
|
// Set some fields in the serverAddress structure.
|
||||||
|
addressS.sin_family = AF_INET;
|
||||||
|
addressS.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||||
|
addressS.sin_port = htons(port_number);
|
||||||
|
|
||||||
|
// memset(&address.sin_addr, 0, sizeof(address.sin_addr));
|
||||||
|
|
||||||
|
|
||||||
|
if(bind(socketDescriptor,(struct sockaddr *) &addressS,sizeof(addressS))<0){
|
||||||
|
|
||||||
|
printf("Can not create socket\n");
|
||||||
|
|
||||||
|
socketDescriptor=-1;
|
||||||
|
} else {
|
||||||
|
if (listen(socketDescriptor, 5)==0) {
|
||||||
|
|
||||||
|
if (isock==0) {
|
||||||
|
FD_ZERO(&readset);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FD_SET(socketDescriptor, &readset);
|
||||||
|
isock++;
|
||||||
|
maxfd = socketDescriptor;
|
||||||
|
printf ("%d port %d fd %d\n",isock, port_number,socketDescriptor);
|
||||||
|
myport=port_number;
|
||||||
|
} else
|
||||||
|
printf("error on listen");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//int getrlimit(int resource, struct rlimit *rlim);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return socketDescriptor;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int getServerError(int socketDescriptor)
|
||||||
|
{
|
||||||
|
if (socketDescriptor<0) return 1;
|
||||||
|
else return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int acceptConnection(int socketDescriptor) {
|
||||||
|
|
||||||
|
|
||||||
|
int j;
|
||||||
|
|
||||||
|
|
||||||
|
struct sockaddr_in addressC;
|
||||||
|
int file_des=-1;
|
||||||
|
struct timeval tv;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
|
||||||
|
//socklen_t address_length;
|
||||||
|
size_t address_length=sizeof(struct sockaddr_in);
|
||||||
|
|
||||||
|
if (socketDescriptor<0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
memcpy(&tempset, &readset, sizeof(tempset));
|
||||||
|
tv.tv_sec = 10000000;
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
result = select(maxfd + 1, &tempset, NULL, NULL, &tv);
|
||||||
|
|
||||||
|
if (result == 0) {
|
||||||
|
printf("select() timed out!\n");
|
||||||
|
} else if (result < 0 && errno != EINTR) {
|
||||||
|
printf("Error in select(): %s\n", strerror(errno));
|
||||||
|
} else if (result > 0) {
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("select returned!\n");
|
||||||
|
#endif
|
||||||
|
for (j=0; j<maxfd+1; j++) {
|
||||||
|
if (FD_ISSET(j, &tempset)) {
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("fd %d is set\n",j);
|
||||||
|
#endif
|
||||||
|
FD_CLR(j, &tempset);
|
||||||
|
|
||||||
|
|
||||||
|
if ((file_des = accept(j,(struct sockaddr *) &addressC, &address_length)) < 0) {
|
||||||
|
printf("Error in accept(): %s\n", strerror(errno));
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
// should remove descriptor
|
||||||
|
|
||||||
|
socketDescriptor=-1;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
inet_ntop(AF_INET, &(addressC.sin_addr), dummyClientIP, INET_ADDRSTRLEN);
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("connection accepted %d\n",file_des);
|
||||||
|
#endif
|
||||||
|
FD_SET(file_des, &readset);
|
||||||
|
maxfd = (maxfd < file_des)?file_des:maxfd;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return file_des;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void closeConnection(int file_des) {
|
||||||
|
#ifdef VERY_VERBOSE
|
||||||
|
#endif
|
||||||
|
if(file_des>=0)
|
||||||
|
close(file_des);
|
||||||
|
FD_CLR(file_des, &readset);
|
||||||
|
}
|
||||||
|
|
||||||
|
void exitServer(int socketDescriptor) {
|
||||||
|
if (socketDescriptor>=0)
|
||||||
|
close(socketDescriptor);
|
||||||
|
#ifdef VERY_VERBOSE
|
||||||
|
printf("Closing server\n");
|
||||||
|
#endif
|
||||||
|
FD_CLR(socketDescriptor, &readset);
|
||||||
|
socketDescriptor=-1;
|
||||||
|
isock--;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int sendDataOnly(int file_des, void* buf,int length) {
|
||||||
|
|
||||||
|
|
||||||
|
return write(file_des, buf, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int receiveDataOnly(int file_des, void* buf,int length) {
|
||||||
|
|
||||||
|
int total_received=0;
|
||||||
|
int nreceiving;
|
||||||
|
int nreceived;
|
||||||
|
if (file_des<0) return -1;
|
||||||
|
#ifdef VERY_VERBOSE
|
||||||
|
printf("want to receive %d Bytes\n", length);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
while(length>0){
|
||||||
|
nreceiving = (length>send_rec_max_size) ? send_rec_max_size:length;
|
||||||
|
|
||||||
|
#ifdef VERY_VERBOSE
|
||||||
|
printf("want to receive %d Bytes\n", nreceiving);
|
||||||
|
#endif
|
||||||
|
nreceived = read(file_des,(char*)buf+total_received,nreceiving);
|
||||||
|
#ifdef VERY_VERBOSE
|
||||||
|
printf("read %d \n", nreceived);
|
||||||
|
#endif
|
||||||
|
if(!nreceived) break;
|
||||||
|
// if(nreceived<0) break;
|
||||||
|
length-=nreceived;
|
||||||
|
total_received+=nreceived;
|
||||||
|
// cout<<"nrec: "<<nreceived<<" waiting for ("<<length<<")"<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef VERY_VERBOSE
|
||||||
|
printf("received %d Bytes\n", total_received);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (total_received>0)
|
||||||
|
strcpy(thisClientIP,dummyClientIP);
|
||||||
|
|
||||||
|
//if (strcmp(lastClientIP,"none")==0)
|
||||||
|
//strcpy(lastClientIP,thisClientIP);
|
||||||
|
|
||||||
|
if (strcmp(lastClientIP,thisClientIP))
|
||||||
|
differentClients=1;
|
||||||
|
else
|
||||||
|
differentClients=0;
|
||||||
|
|
||||||
|
return total_received;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int sendChannel(int file_des, sls_detector_channel *myChan) {
|
||||||
|
return sendDataOnly(file_des,myChan, sizeof(sls_detector_channel));
|
||||||
|
}
|
||||||
|
|
||||||
|
int sendChip(int file_des, sls_detector_chip *myChip) {
|
||||||
|
int ts=0;
|
||||||
|
int nChans=myChip->nchan;
|
||||||
|
ts+=sendDataOnly(file_des,myChip,sizeof(sls_detector_chip));
|
||||||
|
ts+=sendDataOnly(file_des,myChip->chanregs,nChans*sizeof(int));
|
||||||
|
return ts;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sendModule(int file_des, sls_detector_module *myMod) {
|
||||||
|
int ts=0;
|
||||||
|
#ifdef VERBOSE
|
||||||
|
int idac;
|
||||||
|
#endif
|
||||||
|
int nChips=myMod->nchip;
|
||||||
|
int nChans=myMod->nchan;
|
||||||
|
int nAdcs=myMod->nadc;
|
||||||
|
int nDacs=myMod->ndac;
|
||||||
|
ts+= sendDataOnly(file_des,myMod,sizeof(sls_detector_module));
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("module %d of size %d sent\n",myMod->module, ts);
|
||||||
|
#endif
|
||||||
|
ts+= sendDataOnly(file_des,myMod->dacs,sizeof(dacs_t)*nDacs);
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("dacs %d of size %d sent\n",myMod->module, ts);
|
||||||
|
for (idac=0; idac< nDacs; idac++)
|
||||||
|
printf("dac %d is %d\n",idac,(int)myMod->dacs[idac]);
|
||||||
|
#endif
|
||||||
|
ts+= sendDataOnly(file_des,myMod->adcs,sizeof(dacs_t)*nAdcs);
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("adcs %d of size %d sent\n",myMod->module, ts);
|
||||||
|
#endif
|
||||||
|
ts+=sendDataOnly(file_des,myMod->chipregs,sizeof(int)*nChips);
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("chips %d of size %d sent\n",myMod->module, ts);
|
||||||
|
#endif
|
||||||
|
ts+=sendDataOnly(file_des,myMod->chanregs,sizeof(int)*nChans);
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("chans %d of size %d sent - %d\n",myMod->module, ts, myMod->nchan);
|
||||||
|
#endif
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("module %d of size %d sent register %x\n",myMod->module, ts, myMod->reg);
|
||||||
|
#endif
|
||||||
|
return ts;
|
||||||
|
}
|
||||||
|
|
||||||
|
int receiveChannel(int file_des, sls_detector_channel *myChan) {
|
||||||
|
return receiveDataOnly(file_des,myChan,sizeof(sls_detector_channel));
|
||||||
|
}
|
||||||
|
|
||||||
|
int receiveChip(int file_des, sls_detector_chip* myChip) {
|
||||||
|
|
||||||
|
int *ptr=myChip->chanregs;
|
||||||
|
int ts=0;
|
||||||
|
int nChans, nchanold=myChip->nchan, chdiff;
|
||||||
|
|
||||||
|
ts+= receiveDataOnly(file_des,myChip,sizeof(sls_detector_chip));
|
||||||
|
|
||||||
|
|
||||||
|
myChip->chanregs=ptr;
|
||||||
|
nChans=myChip->nchan;
|
||||||
|
chdiff=nChans-nchanold;
|
||||||
|
if (nchanold!=nChans) {
|
||||||
|
printf("wrong number of channels received!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("chip structure received\n");
|
||||||
|
printf("now receiving %d channels\n", nChans);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (chdiff<=0)
|
||||||
|
ts+=receiveDataOnly(file_des,myChip->chanregs, sizeof(int)*nChans);
|
||||||
|
else {
|
||||||
|
ptr=malloc(chdiff*sizeof(int));
|
||||||
|
myChip->nchan=nchanold;
|
||||||
|
ts+=receiveDataOnly(file_des,myChip->chanregs, sizeof(int)*nchanold);
|
||||||
|
ts+=receiveDataOnly(file_des,ptr, sizeof(int)*chdiff);
|
||||||
|
free(ptr);
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("chip's channels received\n");
|
||||||
|
#endif
|
||||||
|
return ts;
|
||||||
|
}
|
||||||
|
|
||||||
|
int receiveModule(int file_des, sls_detector_module* myMod) {
|
||||||
|
|
||||||
|
|
||||||
|
dacs_t *dacptr=myMod->dacs;
|
||||||
|
dacs_t *adcptr=myMod->adcs;
|
||||||
|
int *chipptr=myMod->chipregs, *chanptr=myMod->chanregs;
|
||||||
|
int ts=0;
|
||||||
|
int nChips, nchipold=myMod->nchip, nchipdiff;
|
||||||
|
int nChans, nchanold=myMod->nchan, nchandiff;
|
||||||
|
int nDacs, ndold=myMod->ndac, ndacdiff;
|
||||||
|
int nAdcs, naold=myMod->nadc, nadcdiff;
|
||||||
|
// int id=0;
|
||||||
|
|
||||||
|
ts+= receiveDataOnly(file_des,myMod,sizeof(sls_detector_module));
|
||||||
|
|
||||||
|
myMod->dacs=dacptr;
|
||||||
|
myMod->adcs=adcptr;
|
||||||
|
myMod->chipregs=chipptr;
|
||||||
|
myMod->chanregs=chanptr;
|
||||||
|
|
||||||
|
nChips=myMod->nchip;
|
||||||
|
nchipdiff=nChips-nchipold;
|
||||||
|
if (nchipold!=nChips) {
|
||||||
|
printf("received wrong number of chips\n");
|
||||||
|
}
|
||||||
|
#ifdef VERBOSE
|
||||||
|
else
|
||||||
|
printf("received %d chips\n",nChips);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
nChans=myMod->nchan;
|
||||||
|
nchandiff=nChans-nchanold;
|
||||||
|
if (nchanold!=nChans) {
|
||||||
|
printf("received wrong number of channels\n");
|
||||||
|
}
|
||||||
|
#ifdef VERBOSE
|
||||||
|
else
|
||||||
|
printf("received %d chans\n",nChans);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
nDacs=myMod->ndac;
|
||||||
|
ndacdiff=nDacs-ndold;
|
||||||
|
if (ndold!=nDacs) {
|
||||||
|
printf("received wrong number of dacs\n");
|
||||||
|
}
|
||||||
|
#ifdef VERBOSE
|
||||||
|
else
|
||||||
|
printf("received %d dacs\n",nDacs);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
nAdcs=myMod->nadc;
|
||||||
|
nadcdiff=nAdcs-naold;
|
||||||
|
if (naold!=nAdcs) {
|
||||||
|
printf("received wrong number of adcs\n");
|
||||||
|
}
|
||||||
|
#ifdef VERBOSE
|
||||||
|
else
|
||||||
|
printf("received %d adcs\n",nAdcs);
|
||||||
|
#endif
|
||||||
|
if (ndacdiff<=0) {
|
||||||
|
ts+=receiveDataOnly(file_des,myMod->dacs, sizeof(dacs_t)*nDacs);
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("dacs received\n");
|
||||||
|
for (id=0; id<nDacs; id++)
|
||||||
|
printf("dac %d val %d\n",id, (int)myMod->dacs[id]);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
dacptr=malloc(ndacdiff*sizeof(dacs_t));
|
||||||
|
myMod->ndac=ndold;
|
||||||
|
ts+=receiveDataOnly(file_des,myMod->dacs, sizeof(dacs_t)*ndold);
|
||||||
|
ts+=receiveDataOnly(file_des,dacptr, sizeof(dacs_t)*ndacdiff);
|
||||||
|
free(dacptr);
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nadcdiff<=0) {
|
||||||
|
ts+=receiveDataOnly(file_des,myMod->adcs, sizeof(dacs_t)*nAdcs);
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("adcs received\n");
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
adcptr=malloc(nadcdiff*sizeof(dacs_t));
|
||||||
|
myMod->nadc=naold;
|
||||||
|
ts+=receiveDataOnly(file_des,myMod->adcs, sizeof(dacs_t)*naold);
|
||||||
|
ts+=receiveDataOnly(file_des,adcptr, sizeof(dacs_t)*nadcdiff);
|
||||||
|
free(adcptr);
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nchipdiff<=0) {
|
||||||
|
ts+=receiveDataOnly(file_des,myMod->chipregs, sizeof(int)*nChips);
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("chips received\n");
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
chipptr=malloc(nchipdiff*sizeof(int));
|
||||||
|
myMod->nchip=nchipold;
|
||||||
|
ts+=receiveDataOnly(file_des,myMod->chipregs, sizeof(int)*nchipold);
|
||||||
|
ts+=receiveDataOnly(file_des,chipptr, sizeof(int)*nchipdiff);
|
||||||
|
free(chipptr);
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nchandiff<=0) {
|
||||||
|
ts+=receiveDataOnly(file_des,myMod->chanregs, sizeof(int)*nChans);
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("chans received\n");
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
chanptr=malloc(nchandiff*sizeof(int));
|
||||||
|
myMod->nchan=nchanold;
|
||||||
|
ts+=receiveDataOnly(file_des,myMod->chanregs, sizeof(int)*nchanold);
|
||||||
|
ts+=receiveDataOnly(file_des,chanptr, sizeof(int)*nchandiff);
|
||||||
|
free(chanptr);
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("received module %d of size %d register %x\n",myMod->module,ts,myMod->reg);
|
||||||
|
#endif
|
||||||
|
return ts;
|
||||||
|
}
|
37
slsDetectorSoftware/eigerDetectorServer/communication_funcs.h
Executable file
37
slsDetectorSoftware/eigerDetectorServer/communication_funcs.h
Executable file
@ -0,0 +1,37 @@
|
|||||||
|
#ifndef COMMUNICATION_FUNCS_H
|
||||||
|
#define COMMUNICATION_FUNCS_H
|
||||||
|
|
||||||
|
#define SEND_REC_MAX_SIZE 4096
|
||||||
|
#define DEFAULT_PORTNO 1952
|
||||||
|
#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"
|
||||||
|
|
||||||
|
char lastClientIP[INET_ADDRSTRLEN];
|
||||||
|
char thisClientIP[INET_ADDRSTRLEN];
|
||||||
|
int lockStatus;
|
||||||
|
int differentClients;
|
||||||
|
|
||||||
|
int bindSocket(unsigned short int port_number);
|
||||||
|
int acceptConnection(int socketDescriptor);
|
||||||
|
void closeConnection(int file_Des);
|
||||||
|
void exitServer(int socketDescriptor);
|
||||||
|
int sendDataOnly(int file_des, void* buf,int length);
|
||||||
|
int receiveDataOnly(int file_des, void* buf,int length);
|
||||||
|
|
||||||
|
int getServerError(int socketDescriptor);
|
||||||
|
int sendChannel(int file_des, sls_detector_channel *myChan);
|
||||||
|
int sendChip(int file_des, sls_detector_chip *myChip);
|
||||||
|
int sendModule(int file_des, sls_detector_module *myMod);
|
||||||
|
int receiveChannel(int file_des, sls_detector_channel *myChan);
|
||||||
|
int receiveChip(int file_des, sls_detector_chip* myChip);
|
||||||
|
int receiveModule(int file_des, sls_detector_module* myMod);
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,802 @@
|
|||||||
|
#ifdef SLS_DETECTOR_FUNCTION_LIST
|
||||||
|
|
||||||
|
#include "slsDetectorFunctionList.h"
|
||||||
|
#include "slsDetectorServer_defs.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
extern int nModX;
|
||||||
|
extern int nModBoard;
|
||||||
|
extern int dataBytes;
|
||||||
|
extern int dynamicRange;
|
||||||
|
const int nChans=NCHAN;
|
||||||
|
const int nChips=NCHIP;
|
||||||
|
const int nDacs=NDAC;
|
||||||
|
const int nAdcs=NADC;
|
||||||
|
enum detectorSettings thisSettings;
|
||||||
|
|
||||||
|
int sChan, sChip, sMod, sDac, sAdc;
|
||||||
|
const int allSelected=-2;
|
||||||
|
const int noneSelected=-1;
|
||||||
|
|
||||||
|
|
||||||
|
sls_detector_module *detectorModules=NULL;
|
||||||
|
int *detectorChips=NULL;
|
||||||
|
int *detectorChans=NULL;
|
||||||
|
dacs_t *detectorDacs=NULL;
|
||||||
|
dacs_t *detectorAdcs=NULL;
|
||||||
|
|
||||||
|
|
||||||
|
int initializeDetector(){
|
||||||
|
|
||||||
|
int imod;
|
||||||
|
|
||||||
|
int n=getNModBoard(X)*getNModBoard(Y);
|
||||||
|
/*nModX=n;*/
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("Board is for %d modules\n",n);
|
||||||
|
#endif
|
||||||
|
detectorModules=malloc(n*sizeof(sls_detector_module));
|
||||||
|
detectorChips=malloc(n*NCHIP*sizeof(int));
|
||||||
|
detectorChans=malloc(n*NCHIP*NCHAN*sizeof(int));
|
||||||
|
detectorDacs=malloc(n*NDAC*sizeof(int));
|
||||||
|
detectorAdcs=malloc(n*NADC*sizeof(int));
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("modules from 0x%x to 0x%x\n",(unsigned int)(detectorModules), (unsigned int)(detectorModules+n));
|
||||||
|
printf("chips from 0x%x to 0x%x\n",(unsigned int)(detectorChips), (unsigned int)(detectorChips+n*NCHIP));
|
||||||
|
printf("chans from 0x%x to 0x%x\n",(unsigned int)(detectorChans), (unsigned int)(detectorChans+n*NCHIP*NCHAN));
|
||||||
|
printf("dacs from 0x%x to 0x%x\n",(unsigned int)(detectorDacs), (unsigned int)(detectorDacs+n*NDAC));
|
||||||
|
printf("adcs from 0x%x to 0x%x\n",(unsigned int)(detectorAdcs), (unsigned int)(detectorAdcs+n*NADC));
|
||||||
|
#endif
|
||||||
|
for (imod=0; imod<n; imod++) {
|
||||||
|
(detectorModules+imod)->dacs=detectorDacs+imod*NDAC;
|
||||||
|
(detectorModules+imod)->adcs=detectorAdcs+imod*NADC;
|
||||||
|
(detectorModules+imod)->chipregs=detectorChips+imod*NCHIP;
|
||||||
|
(detectorModules+imod)->chanregs=detectorChans+imod*NCHIP*NCHAN;
|
||||||
|
(detectorModules+imod)->ndac=NDAC;
|
||||||
|
(detectorModules+imod)->nadc=NADC;
|
||||||
|
(detectorModules+imod)->nchip=NCHIP;
|
||||||
|
(detectorModules+imod)->nchan=NCHIP*NCHAN;
|
||||||
|
(detectorModules+imod)->module=imod;
|
||||||
|
(detectorModules+imod)->gain=0;
|
||||||
|
(detectorModules+imod)->offset=0;
|
||||||
|
(detectorModules+imod)->reg=0;
|
||||||
|
/* initialize registers, dacs, retrieve sn, adc values etc */
|
||||||
|
}
|
||||||
|
thisSettings=UNINITIALIZED;
|
||||||
|
sChan=noneSelected;
|
||||||
|
sChip=noneSelected;
|
||||||
|
sMod=noneSelected;
|
||||||
|
sDac=noneSelected;
|
||||||
|
sAdc=noneSelected;
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int setNMod(int nm, enum dimension dim){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int getNModBoard(enum dimension arg){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int64_t getModuleId(enum idMode arg, int imod){
|
||||||
|
//DETECTOR_SERIAL_NUMBER
|
||||||
|
//DETECTOR_FIRMWARE_VERSION
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int64_t getDetectorId(enum idMode arg){
|
||||||
|
//DETECTOR_SOFTWARE_VERSION defined in slsDetector_defs.h?
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int moduleTest( enum digitalTestMode arg, int imod){
|
||||||
|
//template testShiftIn from mcb_funcs.c
|
||||||
|
|
||||||
|
//CHIP_TEST
|
||||||
|
//testShiftIn
|
||||||
|
//testShiftOut
|
||||||
|
//testShiftStSel
|
||||||
|
//testDataInOutMux
|
||||||
|
//testExtPulseMux
|
||||||
|
//testOutMux
|
||||||
|
//testFpgaMux
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int detectorTest( enum digitalTestMode arg){
|
||||||
|
//templates from firmware_funcs.c
|
||||||
|
|
||||||
|
//DETECTOR_FIRMWARE_TEST:testFpga()
|
||||||
|
//DETECTOR_MEMORY_TEST:testRAM()
|
||||||
|
//DETECTOR_BUS_TEST:testBus()
|
||||||
|
//DETECTOR_SOFTWARE_TEST:testFpga()
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
double setDAC(enum dacIndex ind, double val, int imod){
|
||||||
|
//template initDACbyIndexDACU from mcb_funcs.c
|
||||||
|
|
||||||
|
//check that slsDetectorServer_funcs.c set_dac() has all the specific dac enums
|
||||||
|
//set dac and write to a register in fpga to remember dac value when server restarts
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
double getADC(enum dacIndex ind, int imod){
|
||||||
|
//get adc value
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int setChannel(sls_detector_channel myChan){
|
||||||
|
//template initChannelByNumber() from mcb_funcs.c
|
||||||
|
|
||||||
|
return myChan.reg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int getChannel(sls_detector_channel *myChan){
|
||||||
|
//template getChannelbyNumber() from mcb_funcs.c
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int setChip(sls_detector_chip myChip){
|
||||||
|
//template initChipbyNumber() from mcb_funcs.c
|
||||||
|
return myChip.reg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int getChip(sls_detector_chip *myChip){
|
||||||
|
//template getChipbyNumber() from mcb_funcs.c
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int setModule(sls_detector_module myChan){
|
||||||
|
//template initModulebyNumber() from mcb_funcs.c
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getModule(sls_detector_module *myChan){
|
||||||
|
//template getModulebyNumber() from mcb_funcs.c
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getThresholdEnergy(int imod){
|
||||||
|
//template getThresholdEnergy() from mcb_funcs.c
|
||||||
|
//depending on settings
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int setThresholdEnergy(int thr, int imod){
|
||||||
|
//template getThresholdEnergy() from mcb_funcs.c
|
||||||
|
//depending on settings
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
enum detectorSettings setSettings(enum detectorSettings sett, int imod){
|
||||||
|
//template setSettings() from mcb_funcs.c
|
||||||
|
//reads the dac registers from fpga to confirm which settings, if weird, undefined
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int startStateMachine(){
|
||||||
|
//template startStateMachine() from firmware_funcs.c
|
||||||
|
/*
|
||||||
|
fifoReset();
|
||||||
|
now_ptr=(char*)ram_values;
|
||||||
|
//send start acquisition to fpga
|
||||||
|
*/
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int stopStateMachine(){
|
||||||
|
//template stopStateMachine() from firmware_funcs.c
|
||||||
|
// send stop to fpga
|
||||||
|
//if status = busy after 500us, return FAIL
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int startReadOut(){
|
||||||
|
//template startReadOut() from firmware_funcs.c
|
||||||
|
//send fpga start readout
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
enum runStatus getRunStatus(){
|
||||||
|
//template runState() from firmware_funcs.c
|
||||||
|
//get status from fpga
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char *readFrame(int *ret, char *mess){
|
||||||
|
//template fifo_read_event() from firmware_funcs.c
|
||||||
|
//checks if state machine running and if fifo has data(look_at_me_reg) and accordingly reads frame
|
||||||
|
// memcpy(now_ptr, values, dataBytes);
|
||||||
|
//returns ptr to values
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int64_t setTimer(enum timerIndex ind, int64_t val){
|
||||||
|
//template setDelay() from firmware_funcs.c
|
||||||
|
//writes to reg
|
||||||
|
//FRAME_NUMBER
|
||||||
|
//ACQUISITION_TIME
|
||||||
|
//FRAME_PERIOD
|
||||||
|
//DELAY_AFTER_TRIGGER
|
||||||
|
//GATES_NUMBER
|
||||||
|
//PROBES_NUMBER
|
||||||
|
//CYCLES_NUMBER
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int64_t getTimeLeft(enum timerIndex ind){
|
||||||
|
//template getDelay() from firmware_funcs.c
|
||||||
|
//reads from reg
|
||||||
|
//FRAME_NUMBER
|
||||||
|
//ACQUISITION_TIME
|
||||||
|
//FRAME_PERIOD
|
||||||
|
//DELAY_AFTER_TRIGGER
|
||||||
|
//GATES_NUMBER
|
||||||
|
//PROBES_NUMBER
|
||||||
|
//CYCLES_NUMBER
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int setDynamicRange(int dr){
|
||||||
|
//template setDynamicRange() from firmware_funcs.c
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int setROI(int mask){ //////?????????????????
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int getROI(int *mask){ //////////?????????????????????
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int setSpeed(enum speedVariable arg, int val){
|
||||||
|
//template setClockDivider() from firmware_funcs.c
|
||||||
|
//CLOCK_DIVIDER
|
||||||
|
//WAIT_STATES
|
||||||
|
//SET_SIGNAL_LENGTH
|
||||||
|
//TOT_CLOCK_DIVIDER
|
||||||
|
//TOT_DUTY_CYCLE
|
||||||
|
|
||||||
|
//returns eg getClockDivider from firmware_funcs.c
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
enum readOutFlags setReadOutFlags(enum readOutFlags val){
|
||||||
|
//template setStoreInRAM from firmware_funcs.c
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int executeTrimming(enum trimMode mode, int par1, int par2, int imod){
|
||||||
|
// template trim_with_noise from trimming_funcs.c
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int configureMAC(int ipad, long long int imacadd, long long int iservermacadd, int dtb){
|
||||||
|
//detector specific.
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int loadImage(enum imageType index, char *imageVals){
|
||||||
|
//detector specific.
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int readCounterBlock(int startACQ, char *counterVals){
|
||||||
|
//detector specific.
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int resetCounterBlock(int startACQ){
|
||||||
|
//detector specific.
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int calculateDataBytes(){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getTotalNumberOfChannels(){return 0;}
|
||||||
|
int getTotalNumberOfChips(){return 0;}
|
||||||
|
int getTotalNumberOfModules(){return 0;}
|
||||||
|
int getNumberOfChannelsPerChip(){return 0;}
|
||||||
|
int getNumberOfChannelsPerModule(){return 0;}
|
||||||
|
int getNumberOfChipsPerModule(){return 0;}
|
||||||
|
int getNumberOfDACsPerModule(){return 0;}
|
||||||
|
int getNumberOfADCsPerModule(){return 0;}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
enum externalSignalFlag getExtSignal(int signalindex){
|
||||||
|
//template getExtSignal from firmware_funcs.c
|
||||||
|
//return signals[signalindex];
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
enum externalSignalFlag setExtSignal(int signalindex, enum externalSignalFlag flag){
|
||||||
|
//template setExtSignal from firmware_funcs.c
|
||||||
|
|
||||||
|
//in short..sets signals array, checks if agrees with timing mode, writes to fpga reg, calls synchronization and then settiming
|
||||||
|
/*
|
||||||
|
if (signalindex>=0 && signalindex<4) {
|
||||||
|
signals[signalindex]=flag;
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("settings signal variable number %d to value %04x\n", signalindex, signals[signalindex]);
|
||||||
|
#endif
|
||||||
|
// if output signal, set it!
|
||||||
|
switch (flag) {
|
||||||
|
case GATE_IN_ACTIVE_HIGH:
|
||||||
|
case GATE_IN_ACTIVE_LOW:
|
||||||
|
if (timingMode==GATE_FIX_NUMBER || timingMode==GATE_WITH_START_TRIGGER)//timingMode = AUTO_TIMING by default and is set in setTiming()
|
||||||
|
setFPGASignal(signalindex,flag); //not implemented here, checks if flag within limits and writes to fpga reg
|
||||||
|
else
|
||||||
|
setFPGASignal(signalindex,SIGNAL_OFF);
|
||||||
|
break;
|
||||||
|
case TRIGGER_IN_RISING_EDGE:
|
||||||
|
case TRIGGER_IN_FALLING_EDGE:
|
||||||
|
if (timingMode==TRIGGER_EXPOSURE || timingMode==GATE_WITH_START_TRIGGER)
|
||||||
|
setFPGASignal(signalindex,flag);
|
||||||
|
else
|
||||||
|
setFPGASignal(signalindex,SIGNAL_OFF);
|
||||||
|
break;
|
||||||
|
case RO_TRIGGER_IN_RISING_EDGE:
|
||||||
|
case RO_TRIGGER_IN_FALLING_EDGE:
|
||||||
|
if (timingMode==TRIGGER_READOUT)
|
||||||
|
setFPGASignal(signalindex,flag);
|
||||||
|
else
|
||||||
|
setFPGASignal(signalindex,SIGNAL_OFF);
|
||||||
|
break;
|
||||||
|
case MASTER_SLAVE_SYNCHRONIZATION:
|
||||||
|
setSynchronization(syncMode);//syncmode = NO_SYNCHRONIZATION by default and set with this function
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
setFPGASignal(signalindex,mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
setTiming(GET_EXTERNAL_COMMUNICATION_MODE);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return getExtSignal(signalindex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
enum externalCommunicationMode setTiming( enum externalCommunicationMode arg){
|
||||||
|
//template setTiming from firmware_funcs.c
|
||||||
|
//template getFPGASignal from firmware_funcs.c
|
||||||
|
|
||||||
|
|
||||||
|
//getFPGASignal(signalindex) used later on in this fucntion
|
||||||
|
//gets flag from fpga reg, checks if flag within limits,
|
||||||
|
//if( flag=SIGNAL_OFF and signals[signalindex]==MASTER_SLAVE_SYNCHRONIZATION), return -1, (ensures masterslaveflag !=off now)
|
||||||
|
//else return flag
|
||||||
|
|
||||||
|
int ret=GET_EXTERNAL_COMMUNICATION_MODE;
|
||||||
|
//sets timingmode variable
|
||||||
|
//ensures that the signals are in acceptance with timing mode and according sets the timing mode
|
||||||
|
/*
|
||||||
|
int g=-1, t=-1, rot=-1;
|
||||||
|
|
||||||
|
int i;
|
||||||
|
|
||||||
|
switch (ti) {
|
||||||
|
case AUTO_TIMING:
|
||||||
|
timingMode=ti;
|
||||||
|
// disable all gates/triggers in except if used for master/slave synchronization
|
||||||
|
for (i=0; i<4; i++) {
|
||||||
|
if (getFPGASignal(i)>0 && getFPGASignal(i)<GATE_OUT_ACTIVE_HIGH && signals[i]!=MASTER_SLAVE_SYNCHRONIZATION)
|
||||||
|
setFPGASignal(i,SIGNAL_OFF);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TRIGGER_EXPOSURE:
|
||||||
|
timingMode=ti;
|
||||||
|
// if one of the signals is configured to be trigger, set it and unset possible gates
|
||||||
|
for (i=0; i<4; i++) {
|
||||||
|
if (signals[i]==TRIGGER_IN_RISING_EDGE || signals[i]==TRIGGER_IN_FALLING_EDGE)
|
||||||
|
setFPGASignal(i,signals[i]);
|
||||||
|
else if (signals[i]==GATE_IN_ACTIVE_HIGH || signals[i]==GATE_IN_ACTIVE_LOW)
|
||||||
|
setFPGASignal(i,SIGNAL_OFF);
|
||||||
|
else if (signals[i]==RO_TRIGGER_IN_RISING_EDGE || signals[i]==RO_TRIGGER_IN_FALLING_EDGE)
|
||||||
|
setFPGASignal(i,SIGNAL_OFF);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
case TRIGGER_READOUT:
|
||||||
|
timingMode=ti;
|
||||||
|
// if one of the signals is configured to be trigger, set it and unset possible gates
|
||||||
|
for (i=0; i<4; i++) {
|
||||||
|
if (signals[i]==RO_TRIGGER_IN_RISING_EDGE || signals[i]==RO_TRIGGER_IN_FALLING_EDGE)
|
||||||
|
setFPGASignal(i,signals[i]);
|
||||||
|
else if (signals[i]==GATE_IN_ACTIVE_HIGH || signals[i]==GATE_IN_ACTIVE_LOW)
|
||||||
|
setFPGASignal(i,SIGNAL_OFF);
|
||||||
|
else if (signals[i]==TRIGGER_IN_RISING_EDGE || signals[i]==TRIGGER_IN_FALLING_EDGE)
|
||||||
|
setFPGASignal(i,SIGNAL_OFF);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GATE_FIX_NUMBER:
|
||||||
|
timingMode=ti;
|
||||||
|
// if one of the signals is configured to be trigger, set it and unset possible gates
|
||||||
|
for (i=0; i<4; i++) {
|
||||||
|
if (signals[i]==RO_TRIGGER_IN_RISING_EDGE || signals[i]==RO_TRIGGER_IN_FALLING_EDGE)
|
||||||
|
setFPGASignal(i,SIGNAL_OFF);
|
||||||
|
else if (signals[i]==GATE_IN_ACTIVE_HIGH || signals[i]==GATE_IN_ACTIVE_LOW)
|
||||||
|
setFPGASignal(i,signals[i]);
|
||||||
|
else if (signals[i]==TRIGGER_IN_RISING_EDGE || signals[i]==TRIGGER_IN_FALLING_EDGE)
|
||||||
|
setFPGASignal(i,SIGNAL_OFF);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case GATE_WITH_START_TRIGGER:
|
||||||
|
timingMode=ti;
|
||||||
|
for (i=0; i<4; i++) {
|
||||||
|
if (signals[i]==RO_TRIGGER_IN_RISING_EDGE || signals[i]==RO_TRIGGER_IN_FALLING_EDGE)
|
||||||
|
setFPGASignal(i,SIGNAL_OFF);
|
||||||
|
else if (signals[i]==GATE_IN_ACTIVE_HIGH || signals[i]==GATE_IN_ACTIVE_LOW)
|
||||||
|
setFPGASignal(i,signals[i]);
|
||||||
|
else if (signals[i]==TRIGGER_IN_RISING_EDGE || signals[i]==TRIGGER_IN_FALLING_EDGE)
|
||||||
|
setFPGASignal(i,signals[i]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (i=0; i<4; i++) {
|
||||||
|
if (signals[i]!=MASTER_SLAVE_SYNCHRONIZATION) {
|
||||||
|
if (getFPGASignal(i)==RO_TRIGGER_IN_RISING_EDGE || getFPGASignal(i)==RO_TRIGGER_IN_FALLING_EDGE)
|
||||||
|
rot=i;
|
||||||
|
else if (getFPGASignal(i)==GATE_IN_ACTIVE_HIGH || getFPGASignal(i)==GATE_IN_ACTIVE_LOW)
|
||||||
|
g=i;
|
||||||
|
else if (getFPGASignal(i)==TRIGGER_IN_RISING_EDGE || getFPGASignal(i)==TRIGGER_IN_FALLING_EDGE)
|
||||||
|
t=i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (g>=0 && t>=0 && rot<0) {
|
||||||
|
ret=GATE_WITH_START_TRIGGER;
|
||||||
|
} else if (g<0 && t>=0 && rot<0) {
|
||||||
|
ret=TRIGGER_EXPOSURE;
|
||||||
|
} else if (g>=0 && t<0 && rot<0) {
|
||||||
|
ret=GATE_FIX_NUMBER;
|
||||||
|
} else if (g<0 && t<0 && rot>0) {
|
||||||
|
ret=TRIGGER_READOUT;
|
||||||
|
} else if (g<0 && t<0 && rot<0) {
|
||||||
|
ret=AUTO_TIMING;
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
enum masterFlags setMaster(enum masterFlags arg){
|
||||||
|
//template setMaster from firmware_funcs.c
|
||||||
|
/*
|
||||||
|
int i;
|
||||||
|
switch(f) {
|
||||||
|
case NO_MASTER:
|
||||||
|
// switch of gates or triggers
|
||||||
|
masterMode=NO_MASTER;
|
||||||
|
for (i=0; i<4; i++) {
|
||||||
|
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||||
|
setFPGASignal(i,SIGNAL_OFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case IS_MASTER:
|
||||||
|
// configure gate or trigger out
|
||||||
|
masterMode=IS_MASTER;
|
||||||
|
for (i=0; i<4; i++) {
|
||||||
|
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||||
|
switch (syncMode) {
|
||||||
|
case NO_SYNCHRONIZATION:
|
||||||
|
setFPGASignal(i,SIGNAL_OFF);
|
||||||
|
break;
|
||||||
|
case MASTER_GATES:
|
||||||
|
setFPGASignal(i,GATE_OUT_ACTIVE_HIGH);
|
||||||
|
break;
|
||||||
|
case MASTER_TRIGGERS:
|
||||||
|
setFPGASignal(i,TRIGGER_OUT_RISING_EDGE);
|
||||||
|
break;
|
||||||
|
case SLAVE_STARTS_WHEN_MASTER_STOPS:
|
||||||
|
setFPGASignal(i,RO_TRIGGER_OUT_RISING_EDGE);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case IS_SLAVE:
|
||||||
|
// configure gate or trigger in
|
||||||
|
masterMode=IS_SLAVE;
|
||||||
|
for (i=0; i<4; i++) {
|
||||||
|
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||||
|
switch (syncMode) {
|
||||||
|
case NO_SYNCHRONIZATION:
|
||||||
|
setFPGASignal(i,SIGNAL_OFF);
|
||||||
|
break;
|
||||||
|
case MASTER_GATES:
|
||||||
|
setFPGASignal(i,GATE_IN_ACTIVE_HIGH);
|
||||||
|
break;
|
||||||
|
case MASTER_TRIGGERS:
|
||||||
|
setFPGASignal(i,TRIGGER_IN_RISING_EDGE);
|
||||||
|
break;
|
||||||
|
case SLAVE_STARTS_WHEN_MASTER_STOPS:
|
||||||
|
setFPGASignal(i,TRIGGER_IN_RISING_EDGE);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//do nothing
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(masterMode) {
|
||||||
|
case NO_MASTER:
|
||||||
|
return NO_MASTER;
|
||||||
|
|
||||||
|
|
||||||
|
case IS_MASTER:
|
||||||
|
for (i=0; i<4; i++) {
|
||||||
|
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||||
|
switch (syncMode) {
|
||||||
|
case NO_SYNCHRONIZATION:
|
||||||
|
return IS_MASTER;
|
||||||
|
case MASTER_GATES:
|
||||||
|
if (getFPGASignal(i)==GATE_OUT_ACTIVE_HIGH)
|
||||||
|
return IS_MASTER;
|
||||||
|
else
|
||||||
|
return NO_MASTER;
|
||||||
|
case MASTER_TRIGGERS:
|
||||||
|
if (getFPGASignal(i)==TRIGGER_OUT_RISING_EDGE)
|
||||||
|
return IS_MASTER;
|
||||||
|
else
|
||||||
|
return NO_MASTER;
|
||||||
|
case SLAVE_STARTS_WHEN_MASTER_STOPS:
|
||||||
|
if (getFPGASignal(i)==RO_TRIGGER_OUT_RISING_EDGE)
|
||||||
|
return IS_MASTER;
|
||||||
|
else
|
||||||
|
return NO_MASTER;
|
||||||
|
default:
|
||||||
|
return NO_MASTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case IS_SLAVE:
|
||||||
|
for (i=0; i<4; i++) {
|
||||||
|
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||||
|
switch (syncMode) {
|
||||||
|
case NO_SYNCHRONIZATION:
|
||||||
|
return IS_SLAVE;
|
||||||
|
case MASTER_GATES:
|
||||||
|
if (getFPGASignal(i)==GATE_IN_ACTIVE_HIGH)
|
||||||
|
return IS_SLAVE;
|
||||||
|
else
|
||||||
|
return NO_MASTER;
|
||||||
|
case MASTER_TRIGGERS:
|
||||||
|
case SLAVE_STARTS_WHEN_MASTER_STOPS:
|
||||||
|
if (getFPGASignal(i)==TRIGGER_IN_RISING_EDGE)
|
||||||
|
return IS_SLAVE;
|
||||||
|
else
|
||||||
|
return NO_MASTER;
|
||||||
|
default:
|
||||||
|
return NO_MASTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
return NO_MASTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
enum synchronizationMode setSynchronization(enum synchronizationMode arg){
|
||||||
|
/*
|
||||||
|
int i;
|
||||||
|
|
||||||
|
switch(s) {
|
||||||
|
case NO_SYNCHRONIZATION:
|
||||||
|
syncMode=NO_SYNCHRONIZATION;
|
||||||
|
for (i=0; i<4; i++) {
|
||||||
|
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||||
|
setFPGASignal(i,SIGNAL_OFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// disable external signals?
|
||||||
|
case MASTER_GATES:
|
||||||
|
// configure gate in or out
|
||||||
|
syncMode=MASTER_GATES;
|
||||||
|
for (i=0; i<4; i++) {
|
||||||
|
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||||
|
if (masterMode==IS_MASTER)
|
||||||
|
setFPGASignal(i,GATE_OUT_ACTIVE_HIGH);
|
||||||
|
else if (masterMode==IS_SLAVE)
|
||||||
|
setFPGASignal(i,GATE_IN_ACTIVE_HIGH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case MASTER_TRIGGERS:
|
||||||
|
// configure trigger in or out
|
||||||
|
syncMode=MASTER_TRIGGERS;
|
||||||
|
for (i=0; i<4; i++) {
|
||||||
|
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||||
|
if (masterMode==IS_MASTER)
|
||||||
|
setFPGASignal(i,TRIGGER_OUT_RISING_EDGE);
|
||||||
|
else if (masterMode==IS_SLAVE)
|
||||||
|
setFPGASignal(i,TRIGGER_IN_RISING_EDGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case SLAVE_STARTS_WHEN_MASTER_STOPS:
|
||||||
|
// configure trigger in or out
|
||||||
|
syncMode=SLAVE_STARTS_WHEN_MASTER_STOPS;
|
||||||
|
for (i=0; i<4; i++) {
|
||||||
|
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||||
|
if (masterMode==IS_MASTER)
|
||||||
|
setFPGASignal(i,RO_TRIGGER_OUT_RISING_EDGE);
|
||||||
|
else if (masterMode==IS_SLAVE)
|
||||||
|
setFPGASignal(i,TRIGGER_IN_RISING_EDGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
default:
|
||||||
|
//do nothing
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (syncMode) {
|
||||||
|
|
||||||
|
case NO_SYNCHRONIZATION:
|
||||||
|
return NO_SYNCHRONIZATION;
|
||||||
|
|
||||||
|
case MASTER_GATES:
|
||||||
|
|
||||||
|
for (i=0; i<4; i++) {
|
||||||
|
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||||
|
if (masterMode==IS_MASTER && getFPGASignal(i)==GATE_OUT_ACTIVE_HIGH)
|
||||||
|
return MASTER_GATES;
|
||||||
|
else if (masterMode==IS_SLAVE && getFPGASignal(i)==GATE_IN_ACTIVE_HIGH)
|
||||||
|
return MASTER_GATES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NO_SYNCHRONIZATION;
|
||||||
|
|
||||||
|
case MASTER_TRIGGERS:
|
||||||
|
for (i=0; i<4; i++) {
|
||||||
|
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||||
|
if (masterMode==IS_MASTER && getFPGASignal(i)==TRIGGER_OUT_RISING_EDGE)
|
||||||
|
return MASTER_TRIGGERS;
|
||||||
|
else if (masterMode==IS_SLAVE && getFPGASignal(i)==TRIGGER_IN_RISING_EDGE)
|
||||||
|
return MASTER_TRIGGERS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NO_SYNCHRONIZATION;
|
||||||
|
|
||||||
|
case SLAVE_STARTS_WHEN_MASTER_STOPS:
|
||||||
|
for (i=0; i<4; i++) {
|
||||||
|
if (signals[i]==MASTER_SLAVE_SYNCHRONIZATION) {
|
||||||
|
if (masterMode==IS_MASTER && getFPGASignal(i)==RO_TRIGGER_OUT_RISING_EDGE)
|
||||||
|
return SLAVE_STARTS_WHEN_MASTER_STOPS;
|
||||||
|
else if (masterMode==IS_SLAVE && getFPGASignal(i)==TRIGGER_IN_RISING_EDGE)
|
||||||
|
return SLAVE_STARTS_WHEN_MASTER_STOPS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NO_SYNCHRONIZATION;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return NO_SYNCHRONIZATION;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
return NO_SYNCHRONIZATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,106 @@
|
|||||||
|
#ifdef SLS_DETECTOR_FUNCTION_LIST
|
||||||
|
|
||||||
|
#ifndef SLS_DETECTOR_FUNCTION_LIST_H
|
||||||
|
#define SLS_DETECTOR_FUNCTION_LIST_H
|
||||||
|
|
||||||
|
#include "sls_detector_defs.h"
|
||||||
|
|
||||||
|
#include <stdlib.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>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/****************************************************
|
||||||
|
This functions are used by the slsDetectroServer_funcs interface.
|
||||||
|
Here are the definitions, but the actual implementation should be done for each single detector.
|
||||||
|
|
||||||
|
****************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int initializeDetector();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int setNMod(int nm, enum dimension dim);
|
||||||
|
int getNModBoard(enum dimension arg);
|
||||||
|
|
||||||
|
int64_t getModuleId(enum idMode arg, int imod);
|
||||||
|
int64_t getDetectorId(enum idMode arg);
|
||||||
|
int moduleTest( enum digitalTestMode arg, int imod);
|
||||||
|
int detectorTest( enum digitalTestMode arg);
|
||||||
|
|
||||||
|
|
||||||
|
double setDAC(enum dacIndex ind, double val, int imod);
|
||||||
|
double getADC(enum dacIndex ind, int imod);
|
||||||
|
int setChannel(sls_detector_channel myChan);
|
||||||
|
int getChannel(sls_detector_channel *myChan);
|
||||||
|
int setChip(sls_detector_chip myChip);
|
||||||
|
int getChip(sls_detector_chip *myChip);
|
||||||
|
int setModule(sls_detector_module myChan);
|
||||||
|
int getModule(sls_detector_module *myChan);
|
||||||
|
int getThresholdEnergy(int imod);
|
||||||
|
int setThresholdEnergy(int thr, int imod);
|
||||||
|
enum detectorSettings setSettings(enum detectorSettings sett, int imod);
|
||||||
|
|
||||||
|
|
||||||
|
int startStateMachine();
|
||||||
|
int stopStateMachine();
|
||||||
|
int startReadOut();
|
||||||
|
enum runStatus getRunStatus();
|
||||||
|
char *readFrame(int *ret, char *mess);
|
||||||
|
int64_t setTimer(enum timerIndex ind, int64_t val);
|
||||||
|
int64_t getTimeLeft(enum timerIndex ind);
|
||||||
|
int setDynamicRange(int dr);
|
||||||
|
|
||||||
|
|
||||||
|
int setROI(int mask); //////?????????????????
|
||||||
|
int getROI(int *mask); //////////?????????????????????
|
||||||
|
int setSpeed(enum speedVariable arg, int val);
|
||||||
|
enum readOutFlags setReadOutFlags(enum readOutFlags val);
|
||||||
|
int executeTrimming(enum trimMode mode, int par1, int par2, int imod);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int configureMAC(int ipad, long long int imacadd, long long int iservermacadd, int dtb);
|
||||||
|
int loadImage(enum imageType index, char *imageVals);
|
||||||
|
int readCounterBlock(int startACQ, char *counterVals);
|
||||||
|
int resetCounterBlock(int startACQ);
|
||||||
|
|
||||||
|
int calculateDataBytes();
|
||||||
|
|
||||||
|
int getTotalNumberOfChannels();
|
||||||
|
int getTotalNumberOfChips();
|
||||||
|
int getTotalNumberOfModules();
|
||||||
|
int getNumberOfChannelsPerChip();
|
||||||
|
int getNumberOfChannelsPerModule();
|
||||||
|
int getNumberOfChipsPerModule();
|
||||||
|
int getNumberOfDACsPerModule();
|
||||||
|
int getNumberOfADCsPerModule();
|
||||||
|
|
||||||
|
|
||||||
|
enum externalSignalFlag getExtSignal(int signalindex);
|
||||||
|
enum externalSignalFlag setExtSignal(int signalindex, enum externalSignalFlag flag);
|
||||||
|
enum externalCommunicationMode setTiming( enum externalCommunicationMode arg);
|
||||||
|
enum masterFlags setMaster(enum masterFlags arg);
|
||||||
|
enum synchronizationMode setSynchronization(enum synchronizationMode arg);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
96
slsDetectorSoftware/eigerDetectorServer/slsDetectorServer.c
Executable file
96
slsDetectorSoftware/eigerDetectorServer/slsDetectorServer.c
Executable file
@ -0,0 +1,96 @@
|
|||||||
|
/* A simple server in the internet domain using TCP
|
||||||
|
The port number is passed as an argument */
|
||||||
|
|
||||||
|
#include "sls_detector_defs.h"
|
||||||
|
#include "communication_funcs.h"
|
||||||
|
#include "slsDetectorServer_funcs.h"
|
||||||
|
#include "slsDetectorServer_defs.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
extern int sockfd;
|
||||||
|
|
||||||
|
|
||||||
|
void error(char *msg)
|
||||||
|
{
|
||||||
|
perror(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int portno, b;
|
||||||
|
char cmd[100];
|
||||||
|
int retval=OK;
|
||||||
|
int sd, fd;
|
||||||
|
|
||||||
|
|
||||||
|
if (argc==1) {
|
||||||
|
portno = DEFAULT_PORTNO;
|
||||||
|
sprintf(cmd,"%s %d &",argv[0],DEFAULT_PORTNO+1);
|
||||||
|
printf("opening control server on port %d\n",portno );
|
||||||
|
system(cmd);
|
||||||
|
b=1;
|
||||||
|
} else {
|
||||||
|
portno = DEFAULT_PORTNO+1;
|
||||||
|
if ( sscanf(argv[1],"%d",&portno) ==0) {
|
||||||
|
printf("could not open stop server: unknown port\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
b=0;
|
||||||
|
printf("opening stop server on port %d\n",portno);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
init_detector(b); //defined in slsDetectorServer_funcs
|
||||||
|
|
||||||
|
|
||||||
|
sd=bindSocket(portno); //defined in communication_funcs
|
||||||
|
|
||||||
|
sockfd=sd;
|
||||||
|
|
||||||
|
|
||||||
|
if (getServerError(sd)) { //defined in communication_funcs
|
||||||
|
printf("server error!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* assign function table */
|
||||||
|
function_table(); //defined in slsDetectorServer_funcs
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("function table assigned \n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* waits for connection */
|
||||||
|
while(retval!=GOODBYE) {
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("\n");
|
||||||
|
#endif
|
||||||
|
#ifdef VERY_VERBOSE
|
||||||
|
printf("Waiting for client call\n");
|
||||||
|
#endif
|
||||||
|
fd=acceptConnection(sockfd); //defined in communication_funcs
|
||||||
|
#ifdef VERY_VERBOSE
|
||||||
|
printf("Conenction accepted\n");
|
||||||
|
#endif
|
||||||
|
if (fd>0) {
|
||||||
|
retval=decode_function(fd); //defined in slsDetectorServer_funcs
|
||||||
|
#ifdef VERY_VERBOSE
|
||||||
|
printf("function executed\n");
|
||||||
|
#endif
|
||||||
|
closeConnection(fd); //defined in communication_funcs
|
||||||
|
#ifdef VERY_VERBOSE
|
||||||
|
printf("connection closed\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exitServer(sockfd); //defined in communication_funcs
|
||||||
|
printf("Goodbye!\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
2819
slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_funcs.c
Executable file
2819
slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_funcs.c
Executable file
File diff suppressed because it is too large
Load Diff
79
slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_funcs.h
Executable file
79
slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_funcs.h
Executable file
@ -0,0 +1,79 @@
|
|||||||
|
#ifndef SERVER_FUNCS_H
|
||||||
|
#define SERVER_FUNCS_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "sls_detector_defs.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int sockfd;
|
||||||
|
|
||||||
|
int function_table();
|
||||||
|
|
||||||
|
int decode_function(int);
|
||||||
|
|
||||||
|
//if b>0 all the detector must be initialized, otherwise it is just the stop server
|
||||||
|
int init_detector(int);
|
||||||
|
|
||||||
|
int M_nofunc(int);
|
||||||
|
int exit_server(int);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// General purpose functions
|
||||||
|
int get_detector_type(int);
|
||||||
|
int set_number_of_modules(int);
|
||||||
|
int get_max_number_of_modules(int);
|
||||||
|
|
||||||
|
|
||||||
|
int exec_command(int);
|
||||||
|
int set_external_signal_flag(int);
|
||||||
|
int set_external_communication_mode(int);
|
||||||
|
int get_id(int);
|
||||||
|
int digital_test(int);
|
||||||
|
int write_register(int);
|
||||||
|
int read_register(int);
|
||||||
|
int set_dac(int);
|
||||||
|
int get_adc(int);
|
||||||
|
int set_channel(int);
|
||||||
|
int set_chip(int);
|
||||||
|
int set_module(int);
|
||||||
|
int get_channel(int);
|
||||||
|
int get_chip(int);
|
||||||
|
int get_module(int);
|
||||||
|
|
||||||
|
int get_threshold_energy(int);
|
||||||
|
int set_threshold_energy(int);
|
||||||
|
int set_settings(int);
|
||||||
|
int start_acquisition(int);
|
||||||
|
int stop_acquisition(int);
|
||||||
|
int start_readout(int);
|
||||||
|
int get_run_status(int);
|
||||||
|
int read_frame(int);
|
||||||
|
int read_all(int);
|
||||||
|
int start_and_read_all(int);
|
||||||
|
int set_timer(int);
|
||||||
|
int get_time_left(int);
|
||||||
|
int set_dynamic_range(int);
|
||||||
|
int set_roi(int);
|
||||||
|
int get_roi(int);
|
||||||
|
int set_speed(int);
|
||||||
|
int set_readout_flags(int);
|
||||||
|
int execute_trimming(int);
|
||||||
|
int lock_server(int);
|
||||||
|
int set_port(int);
|
||||||
|
int get_last_client_ip(int);
|
||||||
|
int set_master(int);
|
||||||
|
int set_synchronization(int);
|
||||||
|
int configure_mac(int);
|
||||||
|
int load_image(int);
|
||||||
|
int read_counter_block(int);
|
||||||
|
int reset_counter_block(int);
|
||||||
|
int update_client(int);
|
||||||
|
int send_update(int);
|
||||||
|
|
||||||
|
#endif
|
46
slsDetectorSoftware/eigerDetectorServer/slsDetector_stopServer.c
Executable file
46
slsDetectorSoftware/eigerDetectorServer/slsDetector_stopServer.c
Executable file
@ -0,0 +1,46 @@
|
|||||||
|
/* A simple server in the internet domain using TCP
|
||||||
|
The port number is passed as an argument */
|
||||||
|
#include "communication_funcs.h"
|
||||||
|
|
||||||
|
#include "slsDetectorFunctionList.h"/*#include "slsDetector_firmware.h" for the time being*/
|
||||||
|
#include "slsDetectorServer_defs.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int sockfd;
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int portno;
|
||||||
|
int retval=0;
|
||||||
|
int sd,fd;
|
||||||
|
|
||||||
|
portno = DEFAULT_PORTNO;
|
||||||
|
|
||||||
|
|
||||||
|
sd=bindSocket(portno); //defined in communication_funcs
|
||||||
|
if (getServerError(sd)) //defined in communication_funcs
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* waits for connection */
|
||||||
|
while(retval!=GOODBYE) {
|
||||||
|
#ifdef VERBOSE
|
||||||
|
printf("\n");
|
||||||
|
#endif
|
||||||
|
#ifdef VERY_VERBOSE
|
||||||
|
printf("Stop server: waiting for client call\n");
|
||||||
|
#endif
|
||||||
|
fd=acceptConnection(sd); //defined in communication_funcs
|
||||||
|
retval=stopStateMachine();//defined in slsDetectorFirmare_funcs
|
||||||
|
closeConnection(fd); //defined in communication_funcs
|
||||||
|
}
|
||||||
|
|
||||||
|
exitServer(sd); //defined in communication_funcs
|
||||||
|
printf("Goodbye!\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
554
slsDetectorSoftware/eigerDetectorServer/sls_detector_defs.h
Executable file
554
slsDetectorSoftware/eigerDetectorServer/sls_detector_defs.h
Executable file
@ -0,0 +1,554 @@
|
|||||||
|
#ifndef SLS_DETECTOR_DEFS_H
|
||||||
|
#define SLS_DETECTOR_DEFS_H
|
||||||
|
|
||||||
|
#ifdef __CINT__
|
||||||
|
#define MYROOT
|
||||||
|
#define __cplusplus
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/** default maximum string length */
|
||||||
|
#define MAX_STR_LENGTH 1000
|
||||||
|
/** default maximum string length */
|
||||||
|
#define MAX_SCAN_STEPS 2000
|
||||||
|
/** maxmimum number of modules per controller*/
|
||||||
|
#define MAXMODS 24
|
||||||
|
/** maxmimum number of detectors ina multidetector structure*/
|
||||||
|
#define MAXDET 100
|
||||||
|
/** header length for data :gotthard*/
|
||||||
|
#define HEADERLENGTH 12
|
||||||
|
|
||||||
|
typedef double double32_t;
|
||||||
|
typedef float float32_t;
|
||||||
|
typedef int int32_t;
|
||||||
|
typedef char mystring[MAX_STR_LENGTH];
|
||||||
|
typedef double mysteps[MAX_SCAN_STEPS];
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef DACS_INT
|
||||||
|
typedef int dacs_t;
|
||||||
|
#else
|
||||||
|
typedef float dacs_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define DEFAULT_DET_MAC "00:aa:bb:cc:dd:ee"
|
||||||
|
#define DEFAULT_DET_IP "129.129.202.46"
|
||||||
|
|
||||||
|
/**
|
||||||
|
\file sls_detector_defs.h
|
||||||
|
This file contains all the basic definitions common to the slsDetector class
|
||||||
|
and to the server programs running on the detector
|
||||||
|
|
||||||
|
|
||||||
|
* @author Anna Bergamaschi
|
||||||
|
* @version 0.1alpha (any string)
|
||||||
|
* @see slsDetector
|
||||||
|
|
||||||
|
$Revision: 434 $
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** get flag form most functions */
|
||||||
|
#define GET_FLAG -1
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
|
||||||
|
/** @short class containing all the structures, constants and enum definitions */
|
||||||
|
class slsDetectorDefs {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
slsDetectorDefs(){};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, enCalLog, angCalLog, MAX_ACTIONS};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
@short structure for a detector channel
|
||||||
|
|
||||||
|
should not be used by unexperienced users
|
||||||
|
|
||||||
|
\see ::channelRegisterBit
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
int chan; /**< is the channel number */
|
||||||
|
int chip; /**< is the chip number */
|
||||||
|
int module; /**< is the module number */
|
||||||
|
int64_t reg; /**< is the is the channel register (e.g. trimbits, calibration enable, comparator enable...) */
|
||||||
|
} sls_detector_channel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
@short structure for a detector chip
|
||||||
|
|
||||||
|
should not be used by unexperienced users
|
||||||
|
\see ::chipRegisterBit ::channelRegisterBit
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
int chip; /**< is the chip number */
|
||||||
|
int module; /**< is the module number */
|
||||||
|
int nchan; /**< is the number of channels in the chip */
|
||||||
|
int reg; /**<is the chip register (e.g. output analogue buffer enable)
|
||||||
|
\see ::chipRegisterBit */
|
||||||
|
int *chanregs; /**< is the pointer to the array of the channel registers
|
||||||
|
\see ::channelRegisterBit */
|
||||||
|
} sls_detector_chip;
|
||||||
|
|
||||||
|
/**
|
||||||
|
@short structure for a detector module
|
||||||
|
|
||||||
|
should not be used by unexperienced users
|
||||||
|
|
||||||
|
\see :: moduleRegisterBit ::chipRegisterBit :channelRegisterBit
|
||||||
|
|
||||||
|
@li reg is the module register (e.g. dynamic range? see moduleRegisterBit)
|
||||||
|
@li dacs is the pointer to the array of dac values (in V)
|
||||||
|
@li adcs is the pointer to the array of adc values (in V)
|
||||||
|
@li chipregs is the pointer to the array of chip registers
|
||||||
|
@li chanregs is the pointer to the array of channel registers
|
||||||
|
@li gain is the module gain
|
||||||
|
@li offset is the module offset
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
int module; /**< is the module number */
|
||||||
|
int serialnumber; /**< is the module serial number */
|
||||||
|
int nchan; /**< is the number of channels per chip */
|
||||||
|
int nchip; /**< is the number of chips on the module */
|
||||||
|
int ndac; /**< is the number of dacs on the module */
|
||||||
|
int nadc; /**< is the number of adcs on the module */
|
||||||
|
int reg; /**< is the module register (e.g. dynamic range?)
|
||||||
|
\see moduleRegisterBit */
|
||||||
|
dacs_t *dacs; /**< is the pointer to the array of the dac values (in V) */
|
||||||
|
dacs_t *adcs; /**< is the pointer to the array of the adc values (in V) FLAT_FIELD_CORRECTION*/
|
||||||
|
int *chipregs; /**< is the pointer to the array of the chip registers
|
||||||
|
\see ::chipRegisterBit */
|
||||||
|
int *chanregs; /**< is the pointer to the array of the channel registers
|
||||||
|
\see ::channelRegisterBit */
|
||||||
|
double gain; /**< is the module gain (V/keV) */
|
||||||
|
double offset; /**< is the module offset (V) */
|
||||||
|
} sls_detector_module;
|
||||||
|
|
||||||
|
/**
|
||||||
|
@short structure for a region of interest
|
||||||
|
|
||||||
|
xmin,xmax,ymin,ymax define the limits of the region
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
int xmin; /**< is the roi xmin (in channel number) */
|
||||||
|
int xmax; /**< is the roi xmax (in channel number)*/
|
||||||
|
int ymin; /**< is the roi ymin (in channel number)*/
|
||||||
|
int ymax; /**< is the roi ymax (in channel number)*/
|
||||||
|
} ROI ;
|
||||||
|
|
||||||
|
/* /\* */
|
||||||
|
/* @short structure for a generic integer array */
|
||||||
|
/* *\/ */
|
||||||
|
/* typedef struct { */
|
||||||
|
/* int len; /\**< is the number of elements of the array *\/ */
|
||||||
|
/* int *iptr; /\**< is the pointer to the array *\/ */
|
||||||
|
/* } iarray ; */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Type of the detector
|
||||||
|
*/
|
||||||
|
enum detectorType {
|
||||||
|
GET_DETECTOR_TYPE=-1, /**< the detector will return its type */
|
||||||
|
GENERIC, /**< generic sls detector */
|
||||||
|
MYTHEN, /**< mythen */
|
||||||
|
PILATUS, /**< pilatus */
|
||||||
|
EIGER, /**< eiger */
|
||||||
|
GOTTHARD, /**< gotthard */
|
||||||
|
PICASSO, /**< picasso */
|
||||||
|
AGIPD /**< agipd */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* /\** */
|
||||||
|
/* Communication protocol (normally TCP) */
|
||||||
|
/* *\/ */
|
||||||
|
/* enum communicationProtocol{ */
|
||||||
|
/* TCP, /\**< TCP/IP *\/ */
|
||||||
|
/* UDP /\**< UDP *\/ */
|
||||||
|
/* }; */
|
||||||
|
|
||||||
|
/**
|
||||||
|
network parameters
|
||||||
|
*/
|
||||||
|
|
||||||
|
enum networkParameter {
|
||||||
|
DETECTOR_MAC, /**< detector MAC */
|
||||||
|
DETECTOR_IP, /**< detector IP */
|
||||||
|
RECEIVER_HOSTNAME, /**< receiver IP/hostname */
|
||||||
|
RECEIVER_UDP_IP, /**< receiever UDP IP */
|
||||||
|
RECEIVER_UDP_PORT, /**< receiever UDP Port */
|
||||||
|
RECEIVER_UDP_MAC /**< receiever UDP MAC */
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
type of action performed (for text client)
|
||||||
|
*/
|
||||||
|
enum {GET_ACTION, PUT_ACTION, READOUT_ACTION, HELP_ACTION};
|
||||||
|
|
||||||
|
/** online flags enum \sa setOnline*/
|
||||||
|
enum {GET_ONLINE_FLAG=-1, /**< returns wether the detector is in online or offline state */
|
||||||
|
OFFLINE_FLAG=0, /**< detector in offline state (i.e. no communication to the detector - using only local structure - no data acquisition possible!) */
|
||||||
|
ONLINE_FLAG =1/**< detector in online state (i.e. communication to the detector updating the local structure) */
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
flags to get (or set) the size of the detector
|
||||||
|
*/
|
||||||
|
enum numberOf {
|
||||||
|
MAXMODX, /**<maximum number of module in X direction */
|
||||||
|
MAXMODY, /**<maximum number of module in Y direction */
|
||||||
|
NMODX, /**<installed number of module in X direction */
|
||||||
|
NMODY, /**<installed number of module in Y direction */
|
||||||
|
NCHANSX, /**<number of channels in X direction */
|
||||||
|
NCHANSY, /**<number of channels in Y direction */
|
||||||
|
NCHIPSX, /**<number of chips in X direction */
|
||||||
|
NCHIPSY /**<number of chips in Y direction */
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
dimension indexes
|
||||||
|
*/
|
||||||
|
enum dimension {
|
||||||
|
X=0, /**< X dimension */
|
||||||
|
Y=1, /**< Y dimension */
|
||||||
|
Z=2 /**< Z dimension */
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
return values
|
||||||
|
*/
|
||||||
|
enum {
|
||||||
|
OK, /**< function succeeded */
|
||||||
|
FAIL, /**< function failed */
|
||||||
|
FINISHED, /**< acquisition finished */
|
||||||
|
FORCE_UPDATE
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
enable/disable flags
|
||||||
|
*/
|
||||||
|
enum {
|
||||||
|
DISABLED, /**<flag disabled */
|
||||||
|
ENABLED /**<flag enabled */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
use of the external signals
|
||||||
|
*/
|
||||||
|
enum externalSignalFlag {
|
||||||
|
GET_EXTERNAL_SIGNAL_FLAG=-1, /**<return flag for signal */
|
||||||
|
SIGNAL_OFF, /**<signal unused - tristate*/
|
||||||
|
GATE_IN_ACTIVE_HIGH, /**<input gate active high*/
|
||||||
|
GATE_IN_ACTIVE_LOW, /**<input gate active low */
|
||||||
|
TRIGGER_IN_RISING_EDGE, /**<input exposure trigger on rising edge */
|
||||||
|
TRIGGER_IN_FALLING_EDGE, /**<input exposure trigger on falling edge */
|
||||||
|
RO_TRIGGER_IN_RISING_EDGE, /**<input raedout trigger on rising edge */
|
||||||
|
RO_TRIGGER_IN_FALLING_EDGE, /**<input readout trigger on falling edge */
|
||||||
|
GATE_OUT_ACTIVE_HIGH, /**<output active high when detector is exposing*/
|
||||||
|
GATE_OUT_ACTIVE_LOW, /**<output active low when detector is exposing*/
|
||||||
|
TRIGGER_OUT_RISING_EDGE, /**<output trigger rising edge at start of exposure */
|
||||||
|
TRIGGER_OUT_FALLING_EDGE, /**<output trigger falling edge at start of exposure */
|
||||||
|
RO_TRIGGER_OUT_RISING_EDGE, /**<output trigger rising edge at start of readout */
|
||||||
|
RO_TRIGGER_OUT_FALLING_EDGE, /**<output trigger falling edge at start of readout */
|
||||||
|
OUTPUT_LOW, /**< output always low */
|
||||||
|
OUTPUT_HIGH, /**< output always high */
|
||||||
|
MASTER_SLAVE_SYNCHRONIZATION /**< reserved for master/slave synchronization in multi detector systems */
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
communication mode using external signals
|
||||||
|
*/
|
||||||
|
enum externalCommunicationMode{
|
||||||
|
GET_EXTERNAL_COMMUNICATION_MODE=-1,/**<return flag for communication mode */
|
||||||
|
AUTO_TIMING, /**< internal timing */
|
||||||
|
TRIGGER_EXPOSURE, /**< trigger mode i.e. exposure is triggered */
|
||||||
|
TRIGGER_FRAME, /**< each trigger triggers one frame at a time */
|
||||||
|
TRIGGER_READOUT, /**< stop trigger mode i.e. readout is triggered by external signal */
|
||||||
|
GATE_FIX_NUMBER, /**< gated and reads out after a fixed number of gates */
|
||||||
|
GATE_WITH_START_TRIGGER, /**< gated with start trigger */
|
||||||
|
TRIGGER_WINDOW /**< exposure time coincides with the external signal */
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
detector IDs/versions
|
||||||
|
*/
|
||||||
|
enum idMode{
|
||||||
|
MODULE_SERIAL_NUMBER, /**<return module serial number */
|
||||||
|
MODULE_FIRMWARE_VERSION, /**<return module firmware */
|
||||||
|
DETECTOR_SERIAL_NUMBER, /**<return detector system serial number */
|
||||||
|
DETECTOR_FIRMWARE_VERSION, /**<return detector system firmware version */
|
||||||
|
DETECTOR_SOFTWARE_VERSION, /**<return detector system software version */
|
||||||
|
THIS_SOFTWARE_VERSION, /**<return this software version */
|
||||||
|
RECEIVER_VERSION /**<return receiver software version */
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
detector digital test modes
|
||||||
|
*/
|
||||||
|
enum digitalTestMode {
|
||||||
|
CHIP_TEST, /**< test chips */
|
||||||
|
MODULE_FIRMWARE_TEST, /**< test module firmware */
|
||||||
|
DETECTOR_FIRMWARE_TEST, /**< test detector system firmware */
|
||||||
|
DETECTOR_MEMORY_TEST, /**< test detector system memory */
|
||||||
|
DETECTOR_BUS_TEST, /**< test detector system CPU-FPGA bus */
|
||||||
|
DETECTOR_SOFTWARE_TEST, /**< test detector system software */
|
||||||
|
DIGITAL_BIT_TEST /**< gotthard digital bit test */
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
detector analogue test modes
|
||||||
|
*/
|
||||||
|
enum analogTestMode {
|
||||||
|
CALIBRATION_PULSES, /**< test using calibration pulses */
|
||||||
|
MY_ANALOG_TEST_MODE /**< other possible test modes */
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
detector dacs indexes
|
||||||
|
*/
|
||||||
|
enum dacIndex {
|
||||||
|
THRESHOLD, /**< comparator threshold level */
|
||||||
|
CALIBRATION_PULSE, /**< calibration input pulse height */
|
||||||
|
TRIMBIT_SIZE, /**< voltage to determine the trimbits LSB */
|
||||||
|
PREAMP, /**< preamp feedback */
|
||||||
|
SHAPER1, /**< shaper1 feedback */
|
||||||
|
SHAPER2, /**< shaper2 feedback */
|
||||||
|
TEMPERATURE_ADC, /**< temperature sensor (adc) */
|
||||||
|
TEMPERATURE_FPGA, /**< temperature sensor (fpga) */
|
||||||
|
HUMIDITY, /**< humidity sensor (adc) */
|
||||||
|
DETECTOR_BIAS,/**< detector bias */
|
||||||
|
VA_POT, /**< power supply va */
|
||||||
|
VDD_POT, /**< chiptest board power supply vdd */
|
||||||
|
VSH_POT, /**< chiptest board power supply vsh */
|
||||||
|
VIO_POT, /**< chiptest board power supply va */
|
||||||
|
HV_POT, /**< gotthard, 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 */
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
detector settings indexes
|
||||||
|
*/
|
||||||
|
enum detectorSettings{
|
||||||
|
GET_SETTINGS=-1, /**< return current detector settings */
|
||||||
|
STANDARD, /**< standard settings */
|
||||||
|
FAST, /**< fast settings */
|
||||||
|
HIGHGAIN, /**< highgain settings */
|
||||||
|
DYNAMICGAIN, /**< dynamic gain settings */
|
||||||
|
LOWGAIN, /**< low gain settings */
|
||||||
|
MEDIUMGAIN, /**< medium gain settings */
|
||||||
|
VERYHIGHGAIN, /**< very high gain settings */
|
||||||
|
UNDEFINED, /**< undefined or custom settings */
|
||||||
|
UNINITIALIZED /**< uninitialiazed (status at startup) */
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
meaning of the channel register bits
|
||||||
|
\see ::sls_detector_channel
|
||||||
|
*/
|
||||||
|
enum channelRegisterBit {
|
||||||
|
TRIMBIT_OFF=0, /**< offset of trimbit value in the channel register */
|
||||||
|
COMPARATOR_ENABLE=0x100, /**< mask of the comparator enable bit */
|
||||||
|
ANALOG_SIGNAL_ENABLE=0x200, /**< mask of the analogue output enable bit */
|
||||||
|
CALIBRATION_ENABLE=0x300, /**< mask of the calibration input enable bit */
|
||||||
|
};
|
||||||
|
|
||||||
|
#define TRIMBITMASK 0x3f
|
||||||
|
/**
|
||||||
|
meaning of the chip register bits
|
||||||
|
\see ::sls_detector_chip
|
||||||
|
*/
|
||||||
|
enum chipRegisterBit {
|
||||||
|
ENABLE_ANALOG_OUTPUT=0x1, /**< mask of the analogue output enable bit */
|
||||||
|
CHIP_OUTPUT_WIDTH=0x2 /**< mask of the chip output width */
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
meaning of the module register bits
|
||||||
|
*/
|
||||||
|
enum moduleRegisterBit {
|
||||||
|
MY_MODULE_REGISTER_BIT, /**< possible module register bit meaning */
|
||||||
|
MODULE_OUTPUT_WIDTH /**< possibly module dynamic range */
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
indexes for the acquisition timers
|
||||||
|
*/
|
||||||
|
enum timerIndex {
|
||||||
|
FRAME_NUMBER, /**< number of real time frames: total number of acquisitions is number or frames*number of cycles */
|
||||||
|
ACQUISITION_TIME, /**< exposure time */
|
||||||
|
FRAME_PERIOD, /**< period between exposures */
|
||||||
|
DELAY_AFTER_TRIGGER, /**< delay between trigger and start of exposure or readout (in triggered mode) */
|
||||||
|
GATES_NUMBER, /**< number of gates per frame (in gated mode) */
|
||||||
|
PROBES_NUMBER, /**< number of probe types in pump-probe mode */
|
||||||
|
CYCLES_NUMBER, /**< number of cycles: total number of acquisitions is number or frames*number of cycles */
|
||||||
|
ACTUAL_TIME, /**< Actual time of the detector's internal timer */
|
||||||
|
MEASUREMENT_TIME, /**< Time of the measurement from the detector (fifo) */
|
||||||
|
|
||||||
|
PROGRESS, /**< fraction of measurement elapsed - only get! */
|
||||||
|
MEASUREMENTS_NUMBER
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
important speed parameters
|
||||||
|
*/
|
||||||
|
enum speedVariable {
|
||||||
|
CLOCK_DIVIDER, /**< readout clock divider */
|
||||||
|
WAIT_STATES, /**< wait states for bus read */
|
||||||
|
TOT_CLOCK_DIVIDER, /**< wait states for bus read */
|
||||||
|
TOT_DUTY_CYCLE, /**< wait states for bus read */
|
||||||
|
SET_SIGNAL_LENGTH /**< set/clear signal length */
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
staus mask
|
||||||
|
*/
|
||||||
|
enum runStatus {
|
||||||
|
IDLE, /**< detector ready to start acquisition - no data in memory */
|
||||||
|
ERROR, /**< error i.e. normally fifo full */
|
||||||
|
WAITING, /**< waiting for trigger or gate signal */
|
||||||
|
RUN_FINISHED, /**< acquisition not running but data in memory */
|
||||||
|
TRANSMITTING, /**< acquisition running and data in memory */
|
||||||
|
RUNNING /**< acquisition running, no data in memory */
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
readout flags
|
||||||
|
*/
|
||||||
|
enum readOutFlags {
|
||||||
|
GET_READOUT_FLAGS=-1, /**< return readout flags */
|
||||||
|
NORMAL_READOUT=0, /**< no flag */
|
||||||
|
STORE_IN_RAM=0x1, /**< data are stored in ram and sent only after end of acquisition for faster frame rate */
|
||||||
|
READ_HITS=0x2, /**< return only the number of the channel which counted ate least one */
|
||||||
|
ZERO_COMPRESSION=0x4,/**< returned data are 0-compressed */
|
||||||
|
PUMP_PROBE_MODE=0x8,/**<pump-probe mode */
|
||||||
|
BACKGROUND_CORRECTIONS=0x1000, /**<background corrections */
|
||||||
|
TOT_MODE=0x2000,/**<pump-probe mode */
|
||||||
|
CONTINOUS_RO=0x4000/**<pump-probe mode */
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
trimming modes
|
||||||
|
*/
|
||||||
|
enum trimMode {
|
||||||
|
NOISE_TRIMMING, /**< trim with noise */
|
||||||
|
BEAM_TRIMMING, /**< trim with x-rays (on all 63 bits) */
|
||||||
|
IMPROVE_TRIMMING, /**< trim with x-rays (on a limited range of bits - should start from an already trimmed mode) */
|
||||||
|
FIXEDSETTINGS_TRIMMING,/**< trim without optimizing the threshold and the trimbit size */
|
||||||
|
OFFLINE_TRIMMING /**< trimming is performed offline */
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
data correction flags
|
||||||
|
*/
|
||||||
|
enum correctionFlags {
|
||||||
|
DISCARD_BAD_CHANNELS, /**< bad channels are discarded */
|
||||||
|
AVERAGE_NEIGHBOURS_FOR_BAD_CHANNELS, /**< bad channels are replaced with the avergae of the neighbours */
|
||||||
|
FLAT_FIELD_CORRECTION, /**< data are flat field corrected */
|
||||||
|
RATE_CORRECTION, /**< data are rate corrected */
|
||||||
|
ANGULAR_CONVERSION,/**< angular conversion is calculated */
|
||||||
|
WRITE_FILE,
|
||||||
|
I0_NORMALIZATION
|
||||||
|
};
|
||||||
|
/** port type */
|
||||||
|
enum portType {
|
||||||
|
CONTROL_PORT, /**< control port */
|
||||||
|
STOP_PORT, /**<stop port */
|
||||||
|
DATA_PORT /**< receiver tcp port with client*/
|
||||||
|
};
|
||||||
|
|
||||||
|
/** hierarchy in multi-detector structure, if any */
|
||||||
|
enum masterFlags {
|
||||||
|
GET_MASTER=-1, /**< return master flag */
|
||||||
|
NO_MASTER, /**< no master/slave hierarchy defined */
|
||||||
|
IS_MASTER, /**<is master */
|
||||||
|
IS_SLAVE /**< is slave */
|
||||||
|
};
|
||||||
|
|
||||||
|
/** synchronization in a multidetector structure, if any */
|
||||||
|
enum synchronizationMode {
|
||||||
|
GET_SYNCHRONIZATION_MODE=-1, /**< the multidetector will return its synchronization mode */
|
||||||
|
NO_SYNCHRONIZATION, /**< all detectors are independent (no cabling) */
|
||||||
|
MASTER_GATES, /**< the master gates the other detectors */
|
||||||
|
MASTER_TRIGGERS, /**< the master triggers the other detectors */
|
||||||
|
SLAVE_STARTS_WHEN_MASTER_STOPS /**< the slave acquires when the master finishes, to avoid deadtime */
|
||||||
|
};
|
||||||
|
|
||||||
|
enum imageType {
|
||||||
|
DARK_IMAGE, /**< dark image */
|
||||||
|
GAIN_IMAGE /**< gain image */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* /\** */
|
||||||
|
/* angular conversion constant for a module */
|
||||||
|
/* *\/ */
|
||||||
|
/* typedef struct { */
|
||||||
|
/* double center; /\**< center of the module (channel at which the radius is perpendicular to the module surface) *\/ */
|
||||||
|
/* double ecenter; /\**< error in the center determination *\/ */
|
||||||
|
/* double r_conversion; /\**< detector pixel size (or strip pitch) divided by the diffractometer radius *\/ */
|
||||||
|
/* double er_conversion; /\**< error in the r_conversion determination *\/ */
|
||||||
|
/* double offset; /\**< the module offset i.e. the position of channel 0 with respect to the diffractometer 0 *\/ */
|
||||||
|
/* double eoffset; /\**< error in the offset determination *\/ */
|
||||||
|
/* double tilt; /\**< ossible tilt in the orthogonal direction (unused)*\/ */
|
||||||
|
/* double etilt; /\**< error in the tilt determination *\/ */
|
||||||
|
/* } angleConversionConstant; */
|
||||||
|
|
||||||
|
|
||||||
|
enum angleConversionParameter {
|
||||||
|
ANGULAR_DIRECTION, /**< angular direction of the diffractometer */
|
||||||
|
GLOBAL_OFFSET, /**< global offset of the diffractometer */
|
||||||
|
FINE_OFFSET, /**< fine offset of the diffractometer */
|
||||||
|
BIN_SIZE, /**< angular bin size */
|
||||||
|
MOVE_FLAG, /**< wether the detector moves with the motor or not in a multi detector system */
|
||||||
|
SAMPLE_X, /**< sample displacement in the beam direction */
|
||||||
|
SAMPLE_Y /**< sample displacement orthogonal to the beam */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Error flags */
|
||||||
|
#define NUM_ERROR_FLAGS=32
|
||||||
|
#define CANNOT_CONNECT_TO_DETECTOR 0x80000000
|
||||||
|
#define CANNOT_CONNECT_TO_RECEIVER 0x40000000
|
||||||
|
#define COULD_NOT_CONFIGURE_MAC 0x00008000 //cant seem to get this error
|
||||||
|
|
||||||
|
|
||||||
|
//typedef struct {
|
||||||
|
//float center; /**< center of the module (channel at which the radius is perpendicular to the module surface) */
|
||||||
|
//float ecenter; /**< error in the center determination */
|
||||||
|
//float r_conversion; /**< detector pixel size (or strip pitch) divided by the diffractometer radius */
|
||||||
|
//float er_conversion; /**< error in the r_conversion determination */
|
||||||
|
//float offset; /**< the module offset i.e. the position of channel 0 with respect to the diffractometer 0 */
|
||||||
|
//float eoffset; /**< error in the offset determination */
|
||||||
|
//float tilt; /**< ossible tilt in the orthogonal direction (unused)*/
|
||||||
|
//float etilt; /**< error in the tilt determination *//
|
||||||
|
//} angleConversionConstant;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
protected:
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef MYROOT
|
||||||
|
#include "sls_detector_funcs.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
#endif
|
||||||
|
;
|
138
slsDetectorSoftware/eigerDetectorServer/sls_detector_funcs.h
Normal file
138
slsDetectorSoftware/eigerDetectorServer/sls_detector_funcs.h
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
/**
|
||||||
|
@internal
|
||||||
|
|
||||||
|
function indexes to call on the server
|
||||||
|
All set functions with argument -1 work as get, when possible
|
||||||
|
|
||||||
|
*/
|
||||||
|
#ifndef SLS_DETECTOR_FUNCS_H
|
||||||
|
#define SLS_DETECTOR_FUNCS_H
|
||||||
|
|
||||||
|
enum {
|
||||||
|
|
||||||
|
// General purpose functions
|
||||||
|
F_EXEC_COMMAND=0, /**< command is executed */
|
||||||
|
F_GET_ERROR, /**< return detector error status */
|
||||||
|
|
||||||
|
// configuration functions
|
||||||
|
F_GET_DETECTOR_TYPE, /**< return detector type */
|
||||||
|
F_SET_NUMBER_OF_MODULES, /**< set/get number of installed modules */
|
||||||
|
F_GET_MAX_NUMBER_OF_MODULES, /**< get maximum number of installed modules */
|
||||||
|
F_SET_EXTERNAL_SIGNAL_FLAG, /**< set/get flag for external signal */
|
||||||
|
F_SET_EXTERNAL_COMMUNICATION_MODE, /**< set/get external communication mode (obsolete) */
|
||||||
|
|
||||||
|
|
||||||
|
// Tests and identification
|
||||||
|
|
||||||
|
F_GET_ID, /**< get detector id of version */
|
||||||
|
F_DIGITAL_TEST, /**< digital test of the detector */
|
||||||
|
F_ANALOG_TEST, /**<analog test of the detector */
|
||||||
|
F_ENABLE_ANALOG_OUT, /**<enable the analog output */
|
||||||
|
F_CALIBRATION_PULSE, /**<pulse the calibration input */
|
||||||
|
|
||||||
|
// Initialization functions
|
||||||
|
F_SET_DAC, /**< set DAC value */
|
||||||
|
F_GET_ADC, /**< get ADC value */
|
||||||
|
F_WRITE_REGISTER, /**< write to register */
|
||||||
|
F_READ_REGISTER, /**< read register */
|
||||||
|
F_WRITE_MEMORY, /**< write to memory */
|
||||||
|
F_READ_MEMORY, /**< read memory */
|
||||||
|
|
||||||
|
|
||||||
|
F_SET_CHANNEL, /**< initialize channel */
|
||||||
|
F_GET_CHANNEL, /**< get channel register */
|
||||||
|
F_SET_ALL_CHANNELS, /**< initialize all channels */
|
||||||
|
|
||||||
|
F_SET_CHIP, /**< initialize chip */
|
||||||
|
F_GET_CHIP, /**< get chip status */
|
||||||
|
F_SET_ALL_CHIPS, /**< initialize all chips */
|
||||||
|
|
||||||
|
F_SET_MODULE, /**< initialize module */
|
||||||
|
F_GET_MODULE, /**< get module status */
|
||||||
|
F_SET_ALL_MODULES, /**< initialize all modules */
|
||||||
|
|
||||||
|
|
||||||
|
F_SET_SETTINGS, /**< set detector settings */
|
||||||
|
F_GET_THRESHOLD_ENERGY, /**< get detector threshold (in eV) */
|
||||||
|
F_SET_THRESHOLD_ENERGY, /**< set detector threshold (in eV) */
|
||||||
|
|
||||||
|
|
||||||
|
// Acquisition functions
|
||||||
|
F_START_ACQUISITION, /**< start acquisition */
|
||||||
|
F_STOP_ACQUISITION, /**< stop acquisition */
|
||||||
|
F_START_READOUT, /**< start readout */
|
||||||
|
F_GET_RUN_STATUS, /**< get acquisition status */
|
||||||
|
F_START_AND_READ_ALL, /**< start acquisition and read all frames*/
|
||||||
|
F_READ_FRAME, /**< read one frame */
|
||||||
|
F_READ_ALL, /**< read alla frames */
|
||||||
|
|
||||||
|
//Acquisition setup functions
|
||||||
|
F_SET_TIMER, /**< set/get timer value */
|
||||||
|
F_GET_TIME_LEFT, /**< get current value of the timer (time left) */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
F_SET_DYNAMIC_RANGE, /**< set/get detector dynamic range */
|
||||||
|
F_SET_READOUT_FLAGS, /**< set/get readout flags */
|
||||||
|
F_SET_ROI, /**< set/get region of interest */
|
||||||
|
|
||||||
|
F_SET_SPEED, /**< set/get readout speed parameters */
|
||||||
|
|
||||||
|
//Trimming
|
||||||
|
F_EXECUTE_TRIMMING, /**< execute trimming */
|
||||||
|
|
||||||
|
F_EXIT_SERVER, /**< turn off detector server */
|
||||||
|
|
||||||
|
F_LOCK_SERVER, /**< Locks/Unlocks server communication to the given client */
|
||||||
|
|
||||||
|
F_GET_LAST_CLIENT_IP, /**< returns the IP of the client last connected to the detector */
|
||||||
|
|
||||||
|
F_SET_PORT, /**< Changes communication port of the server */
|
||||||
|
|
||||||
|
F_UPDATE_CLIENT, /**< Returns all the important parameters to update the shared memory of the client */
|
||||||
|
|
||||||
|
F_CONFIGURE_MAC, /**< Configures MAC for Gotthard readout */
|
||||||
|
|
||||||
|
F_LOAD_IMAGE, /**< Loads Dark/Gain image to the Gotthard detector */
|
||||||
|
|
||||||
|
// multi detector structures
|
||||||
|
|
||||||
|
F_SET_MASTER, /**< sets master/slave flag for multi detector structures */
|
||||||
|
|
||||||
|
F_SET_SYNCHRONIZATION_MODE, /**< sets master/slave synchronization mode for multidetector structures */
|
||||||
|
|
||||||
|
F_READ_COUNTER_BLOCK, /**< reads the counter block memory for gotthard */
|
||||||
|
|
||||||
|
F_RESET_COUNTER_BLOCK, /**< resets the counter block memory for gotthard */
|
||||||
|
|
||||||
|
|
||||||
|
//receiver
|
||||||
|
|
||||||
|
F_SET_FILE_PATH, /**< sets receiver file directory */
|
||||||
|
|
||||||
|
F_SET_FILE_NAME, /**< sets receiver file name */
|
||||||
|
|
||||||
|
F_SET_FILE_INDEX, /**< sets receiver file index */
|
||||||
|
|
||||||
|
F_START_RECEIVER, /**< starts the receiver listening mode */
|
||||||
|
|
||||||
|
F_STOP_RECEIVER, /**< stops the receiver listening mode */
|
||||||
|
|
||||||
|
F_GET_RECEIVER_STATUS, /**< gets the status of receiver listening mode */
|
||||||
|
|
||||||
|
F_GET_FRAMES_CAUGHT, /**< gets the number of frames caught by receiver */
|
||||||
|
|
||||||
|
F_GET_FRAME_INDEX, /**< gets the frame index */
|
||||||
|
|
||||||
|
F_RESET_FRAMES_CAUGHT, /**< resets the frames caught */
|
||||||
|
|
||||||
|
F_SETUP_UDP, /**< sets the receiver udp connection and returns receiver mac address */
|
||||||
|
|
||||||
|
F_ENABLE_FILE_WRITE /**< sets the receiver file write */
|
||||||
|
|
||||||
|
/* Always append functions hereafter!!! */
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
/** @endinternal */
|
Loading…
x
Reference in New Issue
Block a user