mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-28 09:10:01 +02:00
works with gigabit
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@94 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
parent
9f7fe775e8
commit
f0ec4036be
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "communication_funcs.h"
|
#include "communication_funcs.h"
|
||||||
#include <sys/socket.h>
|
//#include <sys/socket.h>
|
||||||
#include <netinet/tcp.h> /* for TCP_NODELAY */
|
#include <netinet/tcp.h> /* for TCP_NODELAY */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -10,11 +10,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//int socketDescriptor, file_des;
|
//int socketDescriptor, file_des;
|
||||||
int socketDescriptor, file_des;
|
|
||||||
const int send_rec_max_size=SEND_REC_MAX_SIZE;
|
const int send_rec_max_size=SEND_REC_MAX_SIZE;
|
||||||
extern int errno;
|
extern int errno;
|
||||||
|
|
||||||
|
|
||||||
|
char dummyClientIP[INET_ADDRSTRLEN];
|
||||||
|
|
||||||
//struct sockaddr_in address;
|
//struct sockaddr_in address;
|
||||||
//#define VERBOSE
|
//#define VERBOSE
|
||||||
|
|
||||||
@ -23,9 +26,10 @@ int bindSocket(unsigned short int port_number) {
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
struct sockaddr_in addressS;
|
struct sockaddr_in addressS;
|
||||||
|
int socketDescriptor;
|
||||||
|
//int file_des;
|
||||||
|
|
||||||
|
//file_des= -1;
|
||||||
file_des= -1;
|
|
||||||
socketDescriptor = socket(AF_INET, SOCK_STREAM,0); //tcp
|
socketDescriptor = socket(AF_INET, SOCK_STREAM,0); //tcp
|
||||||
|
|
||||||
//socketDescriptor = socket(PF_INET, SOCK_STREAM, 0);
|
//socketDescriptor = socket(PF_INET, SOCK_STREAM, 0);
|
||||||
@ -33,7 +37,7 @@ int bindSocket(unsigned short int port_number) {
|
|||||||
|
|
||||||
|
|
||||||
if (socketDescriptor < 0) {
|
if (socketDescriptor < 0) {
|
||||||
printf("Cannot create socket..socketdescript less than 0\n");
|
printf("Can not create socket\n");
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
i = 1;
|
i = 1;
|
||||||
@ -51,7 +55,7 @@ int bindSocket(unsigned short int port_number) {
|
|||||||
|
|
||||||
if(bind(socketDescriptor,(struct sockaddr *) &addressS,sizeof(addressS))<0){
|
if(bind(socketDescriptor,(struct sockaddr *) &addressS,sizeof(addressS))<0){
|
||||||
|
|
||||||
printf("Cannot create socket..did not bind\n");
|
printf("Can not create socket\n");
|
||||||
|
|
||||||
socketDescriptor=-1;
|
socketDescriptor=-1;
|
||||||
} else {
|
} else {
|
||||||
@ -68,76 +72,39 @@ int bindSocket(unsigned short int port_number) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return socketDescriptor;
|
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(int socketDescriptor)
|
||||||
int getServerError()
|
|
||||||
{
|
{
|
||||||
if (socketDescriptor<0) return 1;
|
if (socketDescriptor<0) return 1;
|
||||||
else return 0;
|
else return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int acceptConnection() {
|
int acceptConnection(int socketDescriptor) {
|
||||||
struct sockaddr_in addressC;
|
struct sockaddr_in addressC;
|
||||||
|
int file_des=-1;
|
||||||
|
|
||||||
//socklen_t address_length;
|
//socklen_t address_length;
|
||||||
size_t address_length=sizeof(struct sockaddr_in);
|
size_t address_length=sizeof(struct sockaddr_in);
|
||||||
|
|
||||||
if(file_des>0) return file_des;
|
// if(file_des>0) return file_des;
|
||||||
|
|
||||||
|
|
||||||
|
//next 3 lines commented out by dhanya
|
||||||
//#ifndef C_ONLY
|
//#ifndef C_ONLY
|
||||||
// if(is_a_server){ //server; the server will wait for the clients connection
|
// if(is_a_server){ //server; the server will wait for the clients connection
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
|
|
||||||
if (socketDescriptor>0) {
|
if (socketDescriptor>0) {
|
||||||
if ((file_des = accept(socketDescriptor,(struct sockaddr *) &addressC, &address_length)) < 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);
|
printf("Error: with server accept, connection refused %d\n", errno);
|
||||||
@ -193,26 +160,9 @@ int acceptConnection() {
|
|||||||
|
|
||||||
socketDescriptor=-1;
|
socketDescriptor=-1;
|
||||||
}
|
}
|
||||||
#ifdef VERBOSE
|
inet_ntop(AF_INET, &(addressC.sin_addr), dummyClientIP, INET_ADDRSTRLEN);
|
||||||
|
|
||||||
|
|
||||||
struct sockaddr_in6 sa;
|
|
||||||
char str[INET6_ADDRSTRLEN];
|
|
||||||
|
|
||||||
// store this IP address in sa:
|
|
||||||
inet_pton(AF_INET6, "2001:db8:8714:3a90::12", &(sa.sin6_addr));
|
|
||||||
|
|
||||||
// now get it back and print it
|
|
||||||
inet_ntop(AF_INET6, &(sa.sin6_addr), str, INET6_ADDRSTRLEN);
|
|
||||||
|
|
||||||
//printf("%s\n\n", str); // prints "2001:db8:8714:3a90::12"
|
|
||||||
|
|
||||||
|
|
||||||
printf("client connected %d\n", file_des);
|
|
||||||
printf("addressC family %d port %d addr %s\n",addressC.sin_family,addressC.sin_port,inet_ntoa(addressC.sin_addr));//edited
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//strcpy(lastClientIP,inet_ntoa(addressC.sin_addr)); //In case you want to lock the server...
|
|
||||||
|
|
||||||
|
|
||||||
// struct sockaddr_in
|
// struct sockaddr_in
|
||||||
@ -234,7 +184,7 @@ inet_ntop(AF_INET6, &(sa.sin6_addr), str, INET6_ADDRSTRLEN);
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void closeConnection() {
|
void closeConnection(int file_des) {
|
||||||
//fflush(stdout);
|
//fflush(stdout);
|
||||||
//printf("Closing file_des %d\n", file_des);
|
//printf("Closing file_des %d\n", file_des);
|
||||||
//sleep(1);
|
//sleep(1);
|
||||||
@ -245,7 +195,7 @@ void closeConnection() {
|
|||||||
file_des=-1;
|
file_des=-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void exitServer() {
|
void exitServer(int socketDescriptor) {
|
||||||
if (socketDescriptor>=0)
|
if (socketDescriptor>=0)
|
||||||
close(socketDescriptor);
|
close(socketDescriptor);
|
||||||
#ifdef VERY_VERBOSE
|
#ifdef VERY_VERBOSE
|
||||||
@ -257,55 +207,14 @@ void exitServer() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* client close conenction */
|
int sendDataOnly(int file_des, void* buf,int length) {
|
||||||
/*
|
|
||||||
#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);
|
return write(file_des, buf, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int receiveDataOnly(void* buf,int length) {
|
int receiveDataOnly(int file_des, void* buf,int length) {
|
||||||
|
|
||||||
int total_received=0;
|
int total_received=0;
|
||||||
int nreceiving;
|
int nreceiving;
|
||||||
@ -336,6 +245,13 @@ int sendDataOnly(void* buf,int length) {
|
|||||||
printf("received %d Bytes\n", total_received);
|
printf("received %d Bytes\n", total_received);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (total_received>0)
|
||||||
|
strcpy(thisClientIP,dummyClientIP);
|
||||||
|
if (strcmp(lastClientIP,thisClientIP))
|
||||||
|
differentClients=1;
|
||||||
|
else
|
||||||
|
differentClients=0;
|
||||||
|
|
||||||
return total_received;
|
return total_received;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,44 +269,44 @@ int sendDataOnly(void* buf,int length) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int sendChannel(sls_detector_channel *myChan) {
|
int sendChannel(int file_des, sls_detector_channel *myChan) {
|
||||||
return sendDataOnly(myChan, sizeof(sls_detector_channel));
|
return sendDataOnly(file_des,myChan, sizeof(sls_detector_channel));
|
||||||
}
|
}
|
||||||
|
|
||||||
int sendChip(sls_detector_chip *myChip) {
|
int sendChip(int file_des, sls_detector_chip *myChip) {
|
||||||
int ts=0;
|
int ts=0;
|
||||||
int nChans=myChip->nchan;
|
int nChans=myChip->nchan;
|
||||||
ts+=sendDataOnly(myChip,sizeof(sls_detector_chip));
|
ts+=sendDataOnly(file_des,myChip,sizeof(sls_detector_chip));
|
||||||
ts+=sendDataOnly(myChip->chanregs,nChans*sizeof(int));
|
ts+=sendDataOnly(file_des,myChip->chanregs,nChans*sizeof(int));
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sendModule(sls_detector_module *myMod) {
|
int sendModule(int file_des, sls_detector_module *myMod) {
|
||||||
int ts=0;
|
int ts=0;
|
||||||
int idac;
|
int idac;
|
||||||
int nChips=myMod->nchip;
|
int nChips=myMod->nchip;
|
||||||
int nChans=myMod->nchan;
|
int nChans=myMod->nchan;
|
||||||
int nAdcs=myMod->nadc;
|
int nAdcs=myMod->nadc;
|
||||||
int nDacs=myMod->ndac;
|
int nDacs=myMod->ndac;
|
||||||
ts+= sendDataOnly(myMod,sizeof(sls_detector_module));
|
ts+= sendDataOnly(file_des,myMod,sizeof(sls_detector_module));
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("module %d of size %d sent\n",myMod->module, ts);
|
printf("module %d of size %d sent\n",myMod->module, ts);
|
||||||
#endif
|
#endif
|
||||||
ts+= sendDataOnly(myMod->dacs,sizeof(float)*nDacs);
|
ts+= sendDataOnly(file_des,myMod->dacs,sizeof(float)*nDacs);
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("dacs %d of size %d sent\n",myMod->module, ts);
|
printf("dacs %d of size %d sent\n",myMod->module, ts);
|
||||||
for (idac=0; idac< nDacs; idac++)
|
for (idac=0; idac< nDacs; idac++)
|
||||||
printf("dac %d is %d\n",idac,myMod->dacs[idac]);
|
printf("dac %d is %d\n",idac,myMod->dacs[idac]);
|
||||||
#endif
|
#endif
|
||||||
ts+= sendDataOnly(myMod->adcs,sizeof(float)*nAdcs);
|
ts+= sendDataOnly(file_des,myMod->adcs,sizeof(float)*nAdcs);
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("adcs %d of size %d sent\n",myMod->module, ts);
|
printf("adcs %d of size %d sent\n",myMod->module, ts);
|
||||||
#endif
|
#endif
|
||||||
ts+=sendDataOnly(myMod->chipregs,sizeof(int)*nChips);
|
ts+=sendDataOnly(file_des,myMod->chipregs,sizeof(int)*nChips);
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("chips %d of size %d sent\n",myMod->module, ts);
|
printf("chips %d of size %d sent\n",myMod->module, ts);
|
||||||
#endif
|
#endif
|
||||||
ts+=sendDataOnly(myMod->chanregs,sizeof(int)*nChans);
|
ts+=sendDataOnly(file_des,myMod->chanregs,sizeof(int)*nChans);
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("chans %d of size %d sent - %d\n",myMod->module, ts, myMod->nchan);
|
printf("chans %d of size %d sent - %d\n",myMod->module, ts, myMod->nchan);
|
||||||
#endif
|
#endif
|
||||||
@ -400,17 +316,17 @@ int sendModule(sls_detector_module *myMod) {
|
|||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
int receiveChannel(sls_detector_channel *myChan) {
|
int receiveChannel(int file_des, sls_detector_channel *myChan) {
|
||||||
return receiveDataOnly(myChan,sizeof(sls_detector_channel));
|
return receiveDataOnly(file_des,myChan,sizeof(sls_detector_channel));
|
||||||
}
|
}
|
||||||
|
|
||||||
int receiveChip(sls_detector_chip* myChip) {
|
int receiveChip(int file_des, sls_detector_chip* myChip) {
|
||||||
|
|
||||||
int *ptr=myChip->chanregs;
|
int *ptr=myChip->chanregs;
|
||||||
int ts=0;
|
int ts=0;
|
||||||
int nChans, nchanold=myChip->nchan, chdiff;
|
int nChans, nchanold=myChip->nchan, chdiff;
|
||||||
|
|
||||||
ts+= receiveDataOnly(myChip,sizeof(sls_detector_chip));
|
ts+= receiveDataOnly(file_des,myChip,sizeof(sls_detector_chip));
|
||||||
|
|
||||||
|
|
||||||
myChip->chanregs=ptr;
|
myChip->chanregs=ptr;
|
||||||
@ -427,12 +343,12 @@ int receiveChip(sls_detector_chip* myChip) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (chdiff<=0)
|
if (chdiff<=0)
|
||||||
ts+=receiveDataOnly(myChip->chanregs, sizeof(int)*nChans);
|
ts+=receiveDataOnly(file_des,myChip->chanregs, sizeof(int)*nChans);
|
||||||
else {
|
else {
|
||||||
ptr=malloc(chdiff*sizeof(int));
|
ptr=malloc(chdiff*sizeof(int));
|
||||||
myChip->nchan=nchanold;
|
myChip->nchan=nchanold;
|
||||||
ts+=receiveDataOnly(myChip->chanregs, sizeof(int)*nchanold);
|
ts+=receiveDataOnly(file_des,myChip->chanregs, sizeof(int)*nchanold);
|
||||||
ts+=receiveDataOnly(ptr, sizeof(int)*chdiff);
|
ts+=receiveDataOnly(file_des,ptr, sizeof(int)*chdiff);
|
||||||
free(ptr);
|
free(ptr);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@ -443,7 +359,7 @@ int receiveChip(sls_detector_chip* myChip) {
|
|||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
int receiveModule(sls_detector_module* myMod) {
|
int receiveModule(int file_des, sls_detector_module* myMod) {
|
||||||
|
|
||||||
|
|
||||||
float *dacptr=myMod->dacs;
|
float *dacptr=myMod->dacs;
|
||||||
@ -456,7 +372,7 @@ int receiveModule(sls_detector_module* myMod) {
|
|||||||
int nAdcs, naold=myMod->nadc, nadcdiff;
|
int nAdcs, naold=myMod->nadc, nadcdiff;
|
||||||
|
|
||||||
|
|
||||||
ts+= receiveDataOnly(myMod,sizeof(sls_detector_module));
|
ts+= receiveDataOnly(file_des,myMod,sizeof(sls_detector_module));
|
||||||
|
|
||||||
myMod->dacs=dacptr;
|
myMod->dacs=dacptr;
|
||||||
myMod->adcs=adcptr;
|
myMod->adcs=adcptr;
|
||||||
@ -504,57 +420,57 @@ int receiveModule(sls_detector_module* myMod) {
|
|||||||
printf("received %d adcs\n",nAdcs);
|
printf("received %d adcs\n",nAdcs);
|
||||||
#endif
|
#endif
|
||||||
if (ndacdiff<=0) {
|
if (ndacdiff<=0) {
|
||||||
ts+=receiveDataOnly(myMod->dacs, sizeof(float)*nDacs);
|
ts+=receiveDataOnly(file_des,myMod->dacs, sizeof(float)*nDacs);
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("dacs received\n");
|
printf("dacs received\n");
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
dacptr=malloc(ndacdiff*sizeof(float));
|
dacptr=malloc(ndacdiff*sizeof(float));
|
||||||
myMod->ndac=ndold;
|
myMod->ndac=ndold;
|
||||||
ts+=receiveDataOnly(myMod->dacs, sizeof(float)*ndold);
|
ts+=receiveDataOnly(file_des,myMod->dacs, sizeof(float)*ndold);
|
||||||
ts+=receiveDataOnly(dacptr, sizeof(float)*ndacdiff);
|
ts+=receiveDataOnly(file_des,dacptr, sizeof(float)*ndacdiff);
|
||||||
free(dacptr);
|
free(dacptr);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nadcdiff<=0) {
|
if (nadcdiff<=0) {
|
||||||
ts+=receiveDataOnly(myMod->adcs, sizeof(float)*nAdcs);
|
ts+=receiveDataOnly(file_des,myMod->adcs, sizeof(float)*nAdcs);
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("adcs received\n");
|
printf("adcs received\n");
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
adcptr=malloc(nadcdiff*sizeof(float));
|
adcptr=malloc(nadcdiff*sizeof(float));
|
||||||
myMod->nadc=naold;
|
myMod->nadc=naold;
|
||||||
ts+=receiveDataOnly(myMod->adcs, sizeof(float)*naold);
|
ts+=receiveDataOnly(file_des,myMod->adcs, sizeof(float)*naold);
|
||||||
ts+=receiveDataOnly(adcptr, sizeof(float)*nadcdiff);
|
ts+=receiveDataOnly(file_des,adcptr, sizeof(float)*nadcdiff);
|
||||||
free(adcptr);
|
free(adcptr);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nchipdiff<=0) {
|
if (nchipdiff<=0) {
|
||||||
ts+=receiveDataOnly(myMod->chipregs, sizeof(int)*nChips);
|
ts+=receiveDataOnly(file_des,myMod->chipregs, sizeof(int)*nChips);
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("chips received\n");
|
printf("chips received\n");
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
chipptr=malloc(nchipdiff*sizeof(int));
|
chipptr=malloc(nchipdiff*sizeof(int));
|
||||||
myMod->nchip=nchipold;
|
myMod->nchip=nchipold;
|
||||||
ts+=receiveDataOnly(myMod->chipregs, sizeof(int)*nchipold);
|
ts+=receiveDataOnly(file_des,myMod->chipregs, sizeof(int)*nchipold);
|
||||||
ts+=receiveDataOnly(chipptr, sizeof(int)*nchipdiff);
|
ts+=receiveDataOnly(file_des,chipptr, sizeof(int)*nchipdiff);
|
||||||
free(chipptr);
|
free(chipptr);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nchandiff<=0) {
|
if (nchandiff<=0) {
|
||||||
ts+=receiveDataOnly(myMod->chanregs, sizeof(int)*nChans);
|
ts+=receiveDataOnly(file_des,myMod->chanregs, sizeof(int)*nChans);
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printf("chans received\n");
|
printf("chans received\n");
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
chanptr=malloc(nchandiff*sizeof(int));
|
chanptr=malloc(nchandiff*sizeof(int));
|
||||||
myMod->nchan=nchanold;
|
myMod->nchan=nchanold;
|
||||||
ts+=receiveDataOnly(myMod->chanregs, sizeof(int)*nchanold);
|
ts+=receiveDataOnly(file_des,myMod->chanregs, sizeof(int)*nchanold);
|
||||||
ts+=receiveDataOnly(chanptr, sizeof(int)*nchandiff);
|
ts+=receiveDataOnly(file_des,chanptr, sizeof(int)*nchandiff);
|
||||||
free(chanptr);
|
free(chanptr);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
@ -14,19 +14,24 @@
|
|||||||
|
|
||||||
#include "sls_detector_defs.h"
|
#include "sls_detector_defs.h"
|
||||||
|
|
||||||
int bindSocket(unsigned short int port_number);
|
char lastClientIP[INET_ADDRSTRLEN];
|
||||||
int acceptConnection();
|
char thisClientIP[INET_ADDRSTRLEN];
|
||||||
void closeConnection();
|
int lockStatus;
|
||||||
void exitServer();
|
int differentClients;
|
||||||
int sendDataOnly(void* buf,int length);
|
|
||||||
int receiveDataOnly(void* buf,int length);
|
|
||||||
|
|
||||||
int getServerError();
|
int bindSocket(unsigned short int port_number);
|
||||||
int sendChannel(sls_detector_channel *myChan);
|
int acceptConnection(int socketDescriptor);
|
||||||
int sendChip(sls_detector_chip *myChip);
|
void closeConnection(int file_Des);
|
||||||
int sendModule(sls_detector_module *myMod);
|
void exitServer(int socketDescriptor);
|
||||||
int receiveChannel(sls_detector_channel *myChan);
|
int sendDataOnly(int file_des, void* buf,int length);
|
||||||
int receiveChip(sls_detector_chip* myChip);
|
int receiveDataOnly(int file_des, void* buf,int length);
|
||||||
int receiveModule(sls_detector_module* myMod);
|
|
||||||
|
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
|
#endif
|
||||||
|
@ -944,9 +944,8 @@ int setSettings(int i)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Initialization*/
|
/* Initialization*/
|
||||||
|
|
||||||
int initChannelbyNumber(sls_detector_channel myChan) {
|
int initChannelbyNumber(sls_detector_channel myChan) {
|
||||||
int reg=myChan.reg;
|
int reg=myChan.reg;
|
||||||
int ft=reg & TRIM_DR;
|
int ft=reg & TRIM_DR;
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
int sockfd;
|
extern int sockfd;
|
||||||
|
|
||||||
|
|
||||||
void error(char *msg)
|
void error(char *msg)
|
||||||
@ -18,6 +18,8 @@ int main(int argc, char *argv[])
|
|||||||
int portno, b;
|
int portno, b;
|
||||||
char cmd[100];
|
char cmd[100];
|
||||||
int retval=OK;
|
int retval=OK;
|
||||||
|
int sd, fd;
|
||||||
|
|
||||||
|
|
||||||
if (argc==1) {
|
if (argc==1) {
|
||||||
portno = DEFAULT_PORTNO;
|
portno = DEFAULT_PORTNO;
|
||||||
@ -37,8 +39,12 @@ int main(int argc, char *argv[])
|
|||||||
init_detector(b);
|
init_detector(b);
|
||||||
|
|
||||||
|
|
||||||
bindSocket(portno);
|
sd=bindSocket(portno);
|
||||||
if (getServerError()) {
|
|
||||||
|
sockfd=sd;
|
||||||
|
|
||||||
|
|
||||||
|
if (getServerError(sd)) {
|
||||||
printf("server error!\n");
|
printf("server error!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -58,21 +64,21 @@ int main(int argc, char *argv[])
|
|||||||
#ifdef VERY_VERBOSE
|
#ifdef VERY_VERBOSE
|
||||||
printf("Waiting for client call\n");
|
printf("Waiting for client call\n");
|
||||||
#endif
|
#endif
|
||||||
acceptConnection();
|
fd=acceptConnection(sockfd);
|
||||||
#ifdef VERY_VERBOSE
|
#ifdef VERY_VERBOSE
|
||||||
printf("Conenction accepted\n");
|
printf("Conenction accepted\n");
|
||||||
#endif
|
#endif
|
||||||
retval=decode_function();
|
retval=decode_function(fd);
|
||||||
#ifdef VERY_VERBOSE
|
//#ifdef VERY_VERBOSE
|
||||||
printf("function executed\n");
|
printf("function executed\n");
|
||||||
#endif
|
//#endif
|
||||||
closeConnection();
|
closeConnection(fd);
|
||||||
#ifdef VERY_VERBOSE
|
#ifdef VERY_VERBOSE
|
||||||
printf("connection closed\n");
|
printf("connection closed\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
exitServer();
|
exitServer(sockfd);
|
||||||
printf("Goodbye!\n");
|
printf("Goodbye!\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -12,15 +12,21 @@
|
|||||||
|
|
||||||
|
|
||||||
#define GOODBYE -200
|
#define GOODBYE -200
|
||||||
|
|
||||||
|
int sockfd;
|
||||||
|
|
||||||
int function_table();
|
int function_table();
|
||||||
|
|
||||||
int decode_function();
|
int decode_function(int);
|
||||||
|
|
||||||
int init_detector(int);
|
int init_detector(int);
|
||||||
|
|
||||||
int M_nofunc(int);
|
int M_nofunc(int);
|
||||||
int exit_server(int);
|
int exit_server(int);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// General purpose functions
|
// General purpose functions
|
||||||
int get_detector_type(int);
|
int get_detector_type(int);
|
||||||
int set_number_of_modules(int);
|
int set_number_of_modules(int);
|
||||||
@ -61,11 +67,12 @@ int get_roi(int);
|
|||||||
int set_speed(int);
|
int set_speed(int);
|
||||||
int set_readout_flags(int);
|
int set_readout_flags(int);
|
||||||
int execute_trimming(int);
|
int execute_trimming(int);
|
||||||
|
int lock_server(int);
|
||||||
|
int set_port(int);
|
||||||
|
int get_last_client_ip(int);
|
||||||
|
|
||||||
// to take out/not by dhanya..
|
int update_client(int);
|
||||||
int getGotthard(int);
|
int send_update(int);
|
||||||
int setGotthard(int);
|
int configure_mac(int);
|
||||||
float get_temperature(int);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user