mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-11 04:17:15 +02:00
SlsDetector client library and servers. First import.
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@1 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
516
slsDetectorSoftware/commonFiles/communication_funcs.c
Executable file
516
slsDetectorSoftware/commonFiles/communication_funcs.c
Executable file
@ -0,0 +1,516 @@
|
||||
|
||||
|
||||
#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 VERY_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("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 {
|
||||
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 *) &address, &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 VERY_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);
|
||||
#ifdef VERBOSE
|
||||
// printf("sent %d Bytes\n", total_sent);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
nreceived = read(file_des,(char*)buf+total_received,nreceiving);
|
||||
if(!nreceived) 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 nChips=myMod->nchip;
|
||||
int nChans=myMod->nchan;
|
||||
int nAdcs=myMod->nadc;
|
||||
int nDacs=myMod->ndac;
|
||||
ts+= sendDataOnly(myMod,sizeof(sls_detector_module));
|
||||
ts+= sendDataOnly(myMod->dacs,sizeof(float)*nDacs);
|
||||
ts+= sendDataOnly(myMod->adcs,sizeof(float)*nAdcs);
|
||||
ts+=sendDataOnly(myMod->chipregs,sizeof(int)*nChips);
|
||||
ts+=sendDataOnly(myMod->chanregs,sizeof(int)*nChans);
|
||||
#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/commonFiles/communication_funcs.h
Executable file
32
slsDetectorSoftware/commonFiles/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 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"
|
||||
|
||||
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
|
434
slsDetectorSoftware/commonFiles/sls_detector_defs.h
Executable file
434
slsDetectorSoftware/commonFiles/sls_detector_defs.h
Executable file
@ -0,0 +1,434 @@
|
||||
#ifndef SLS_DETECTOR_DEFS_H
|
||||
#define SLS_DETECTOR_DEFS_H
|
||||
|
||||
#include <stdint.h>
|
||||
/**
|
||||
\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
|
||||
*/
|
||||
|
||||
/** default maximum string length */
|
||||
#define MAX_STR_LENGTH 1000
|
||||
|
||||
/** get flag form most functions */
|
||||
#define GET_FLAG -1
|
||||
/**
|
||||
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;
|
||||
|
||||
/**
|
||||
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;
|
||||
|
||||
/**
|
||||
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 */
|
||||
float *dacs; /**< is the pointer to the array of the dac values (in V) */
|
||||
float *adcs; /**< is the pointer to the array of the adc values (in V) */
|
||||
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 */
|
||||
float gain; /**< is the module gain (V/keV) */
|
||||
float offset; /**< is the module offset (V) */
|
||||
} sls_detector_module;
|
||||
|
||||
/**
|
||||
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 ;
|
||||
|
||||
/**
|
||||
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, /**< the detector will return its type */
|
||||
GENERIC, /**< generic sls detector */
|
||||
MYTHEN, /**< mythen */
|
||||
PILATUS, /**< pilatus */
|
||||
EIGER, /**< eiger */
|
||||
GOTTHARD, /**< gotthard */
|
||||
AGIPD /**< agipd */
|
||||
};
|
||||
|
||||
/**
|
||||
Communication protocol (normally TCP)
|
||||
*/
|
||||
enum communicationProtocol{
|
||||
TCP, /**< TCP/IP */
|
||||
UDP /**< UDP */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
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 */
|
||||
};
|
||||
|
||||
/**
|
||||
enable/disable flags
|
||||
*/
|
||||
enum {
|
||||
DISABLED, /**<flag disabled */
|
||||
ENABLED /**<flag enabled */
|
||||
};
|
||||
|
||||
/**
|
||||
use of the external signals
|
||||
*/
|
||||
enum externalSignalFlag {
|
||||
GET_EXTERNAL_SIGNAL_FLAG, /**<return flag for signal */
|
||||
SIGNAL_OFF, /**<signal unused*/
|
||||
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 */
|
||||
};
|
||||
|
||||
/**
|
||||
communication mode using external signals (obsolete: it will be authomatically determined by the external signal flags)
|
||||
|
||||
\see ::externalSignalFlag
|
||||
*/
|
||||
enum externalCommunicationMode{
|
||||
GET_EXTERNAL_COMMUNICATION_MODE,
|
||||
AUTO,
|
||||
TRIGGER_EXPOSURE,
|
||||
TRIGGER_READOUT,
|
||||
TRIGGER_COINCIDENCE_WITH_INTERNAL_ENABLE,
|
||||
GATE_FIX_NUMBER,
|
||||
GATE_FIX_DURATION,
|
||||
GATE_WITH_START_TRIGGER,
|
||||
GATE_COINCIDENCE_WITH_INTERNAL_ENABLE
|
||||
};
|
||||
/**
|
||||
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 */
|
||||
};
|
||||
/**
|
||||
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 */
|
||||
};
|
||||
/**
|
||||
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, /**< temperature sensor (adc) */
|
||||
HUMIDITY, /**< humidity sensor (adc) */
|
||||
DETECTOR_BIAS /**< detector bias */
|
||||
};
|
||||
|
||||
/**
|
||||
detector settings indexes
|
||||
*/
|
||||
enum detectorSettings{
|
||||
GET_SETTINGS=-1, /**< return current detector settings */
|
||||
STANDARD, /**< standard settings */
|
||||
FAST, /**< fast settings */
|
||||
HIGHGAIN, /**< highgain 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, /**< 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 */
|
||||
};
|
||||
/**
|
||||
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 */
|
||||
};
|
||||
|
||||
/**
|
||||
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 */
|
||||
};
|
||||
/**
|
||||
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 */
|
||||
I0_NORMALIZATION
|
||||
};
|
||||
|
||||
/**
|
||||
function indexes to call on the server
|
||||
|
||||
|
||||
All set functions with argument -1 work as get, when possible
|
||||
|
||||
*/
|
||||
|
||||
enum {
|
||||
|
||||
// General purpose functions
|
||||
F_EXEC_COMMAND, /**< 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 */
|
||||
|
||||
//Trimming
|
||||
F_EXECUTE_TRIMMING, /**< execute trimming */
|
||||
|
||||
|
||||
|
||||
|
||||
F_EXIT_SERVER /**< turnoff detector server */
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
angular conversion constant for a module
|
||||
*/
|
||||
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;
|
||||
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user