mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-11 04:17:15 +02:00
changes in the software structure debugged
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@131 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
@ -8,6 +8,7 @@
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
|
||||
|
||||
@ -18,6 +19,13 @@ extern int errno;
|
||||
|
||||
char dummyClientIP[INET_ADDRSTRLEN];
|
||||
|
||||
|
||||
fd_set readset, tempset;
|
||||
int isock=0, maxfd;
|
||||
|
||||
|
||||
int myport=-1;
|
||||
|
||||
//struct sockaddr_in address;
|
||||
//#define VERBOSE
|
||||
|
||||
@ -30,6 +38,23 @@ int bindSocket(unsigned short int port_number) {
|
||||
//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);
|
||||
@ -59,12 +84,22 @@ int bindSocket(unsigned short int port_number) {
|
||||
|
||||
socketDescriptor=-1;
|
||||
} else {
|
||||
listen(socketDescriptor, 5);
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -88,94 +123,124 @@ int getServerError(int socketDescriptor)
|
||||
|
||||
|
||||
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(file_des>0) return file_des;
|
||||
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) {
|
||||
printf("select returned!\n");
|
||||
for (j=0; j<maxfd+1; j++) {
|
||||
if (FD_ISSET(j, &tempset)) {
|
||||
|
||||
printf("fd %d is set\n",j);
|
||||
FD_CLR(j, &tempset);
|
||||
|
||||
|
||||
#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:
|
||||
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 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");
|
||||
case EMFILE:
|
||||
printf("emfile\n");
|
||||
break;
|
||||
case ENFILE:
|
||||
printf("enfile\n");
|
||||
break;
|
||||
case ENOTSOCK:
|
||||
printf("enotsock\n");
|
||||
break;
|
||||
case EOPNOTSUPP:
|
||||
printf("eOPNOTSUPP\n");
|
||||
case EOPNOTSUPP:
|
||||
printf("eOPNOTSUPP\n");
|
||||
break;
|
||||
case ENOBUFS:
|
||||
printf("ENOBUFS\n");
|
||||
break;
|
||||
case ENOMEM:
|
||||
printf("ENOMEM\n");
|
||||
break;
|
||||
case ENOSR:
|
||||
printf("ENOSR\n");
|
||||
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");
|
||||
}
|
||||
default:
|
||||
printf("unknown error\n");
|
||||
}
|
||||
|
||||
// should remove descriptor
|
||||
|
||||
socketDescriptor=-1;
|
||||
} else {
|
||||
|
||||
inet_ntop(AF_INET, &(addressC.sin_addr), dummyClientIP, INET_ADDRSTRLEN);
|
||||
|
||||
printf("connection accepted %d\n",file_des);
|
||||
FD_SET(file_des, &readset);
|
||||
maxfd = (maxfd < file_des)?file_des:maxfd;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
/* for (j=0; j<maxfd+1; j++) { */
|
||||
/* if (FD_ISSET(j, &tempset)) { */
|
||||
|
||||
/* printf("%d is set!\n",j); */
|
||||
/* ///////////executes the function!!!! */
|
||||
|
||||
|
||||
socketDescriptor=-1;
|
||||
}
|
||||
inet_ntop(AF_INET, &(addressC.sin_addr), dummyClientIP, INET_ADDRSTRLEN);
|
||||
|
||||
|
||||
/* } // end if (FD_ISSET(j, &tempset)) */
|
||||
/* } // end for (j=0;...) */
|
||||
/* } // end else if (result > 0) */
|
||||
|
||||
|
||||
// struct sockaddr_in
|
||||
//{
|
||||
//short int sin_family; /* Famyly of the address*/
|
||||
//unsigned short int sin_port; /* Port */
|
||||
//struct in_addr sin_addr; /* Network address */
|
||||
//unsigned char sin_zero[8]; /* Same size of struct sockaddr */
|
||||
//};
|
||||
}
|
||||
|
||||
|
||||
return file_des;
|
||||
return file_des;
|
||||
}
|
||||
|
||||
|
||||
@ -185,14 +250,11 @@ int acceptConnection(int socketDescriptor) {
|
||||
|
||||
|
||||
void closeConnection(int file_des) {
|
||||
//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;
|
||||
if(file_des>=0)
|
||||
close(file_des);
|
||||
FD_CLR(file_des, &readset);
|
||||
}
|
||||
|
||||
void exitServer(int socketDescriptor) {
|
||||
@ -201,7 +263,9 @@ void exitServer(int socketDescriptor) {
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("Closing server\n");
|
||||
#endif
|
||||
FD_CLR(socketDescriptor, &readset);
|
||||
socketDescriptor=-1;
|
||||
isock--;
|
||||
}
|
||||
|
||||
|
||||
|
@ -147,9 +147,9 @@ enum networkParameter {
|
||||
SERVER_MAC /**< server MAC */
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
type of action performed (for text client)
|
||||
*/
|
||||
*/
|
||||
enum {GET_ACTION, PUT_ACTION, READOUT_ACTION, HELP_ACTION};
|
||||
|
||||
/** online flags enum \sa setOnline*/
|
||||
@ -158,18 +158,6 @@ enum {GET_ONLINE_FLAG=-1, /**< returns wether the detector is in online or offli
|
||||
ONLINE_FLAG =1/**< detector in online state (i.e. communication to the detector updating the local structure) */
|
||||
};
|
||||
|
||||
/** synchronization of the various detectors (should be set for each detector individually?!?!?) */
|
||||
|
||||
enum synchronizationMode {
|
||||
GET_SYNCHRONIZATION_MODE=-1, /**< the multidetector will return its synchronization mode */
|
||||
NONE, /**< 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 */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
flags to get (or set) the size of the detector
|
||||
*/
|
||||
@ -423,18 +411,36 @@ enum correctionFlags {
|
||||
ANGULAR_CONVERSION,/**< angular conversion is calculated */
|
||||
I0_NORMALIZATION
|
||||
};
|
||||
|
||||
/** port type */
|
||||
enum portType {
|
||||
CONTROL_PORT, /**< control port */
|
||||
STOP_PORT, /**<stop port */
|
||||
DATA_PORT /**< data port */
|
||||
};
|
||||
|
||||
enum image {
|
||||
/** 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 */
|
||||
NONE, /**< 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 */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
function indexes to call on the server
|
||||
|
||||
@ -527,12 +533,18 @@ enum {
|
||||
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_LOAD_IMAGE /**< Loads Dark/Gain image to the Gotthard detector */
|
||||
|
||||
/* Always append functions hereafter!!! */
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -551,5 +563,14 @@ typedef struct {
|
||||
} 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 */
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user