included settting up of udpport from client and getting receiver mac from receiver and also listening to only one ethernet interface

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@371 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
l_maliakal_d 2012-12-06 14:27:52 +00:00
parent e4d477b53e
commit ac2c4211e2
11 changed files with 294 additions and 173 deletions

View File

@ -74,6 +74,7 @@ using namespace std;
#define DEFAULT_PACKET_SIZE 1286 #define DEFAULT_PACKET_SIZE 1286
#define DEFAULT_PORTNO 1952 #define DEFAULT_PORTNO 1952
#define DEFAULT_BACKLOG 5 #define DEFAULT_BACKLOG 5
#define DEFAULT_UDP_PORTNO 50001
class genericSocket{ class genericSocket{
@ -157,7 +158,6 @@ protocol(p), is_a_server(0), socketDescriptor(-1),file_des(-1), packet_size(DEFA
strcpy(ip,"0.0.0.0"); strcpy(ip,"0.0.0.0");
clientAddress_length=sizeof(clientAddress); clientAddress_length=sizeof(clientAddress);
if (eth) { if (eth) {
strcpy(ip,nameToIp(string(eth)).c_str()); strcpy(ip,nameToIp(string(eth)).c_str());
if (string(ip)==string("0.0.0.0")) if (string(ip)==string("0.0.0.0"))
@ -432,7 +432,8 @@ protocol(p), is_a_server(0), socketDescriptor(-1),file_des(-1), packet_size(DEFA
sa = (struct sockaddr_in *)(iap->ifa_addr); sa = (struct sockaddr_in *)(iap->ifa_addr);
inet_ntop(iap->ifa_addr->sa_family, (void *)&(sa->sin_addr), buf, sizeof(buf)); inet_ntop(iap->ifa_addr->sa_family, (void *)&(sa->sin_addr), buf, sizeof(buf));
if (ip==string(buf)) { if (ip==string(buf)) {
printf("%s\n", iap->ifa_name); //printf("%s\n", iap->ifa_name);
strcpy(buf,iap->ifa_name);
} }
} }
} }

View File

@ -174,9 +174,10 @@ enum detectorType {
*/ */
enum networkParameter { enum networkParameter {
RECEIVER_IP, /**< receiver IP */ DETECTOR_MAC, /**< detector MAC */
RECEIVER_MAC, /**< receiver mac */ RECEIVER_HOSTNAME, /**< receiver IP/hostname */
SERVER_MAC /**< server MAC */ RECEIVER_UDP_IP, /**< receiever UDP IP */
RECEIVER_UDP_PORT /**< receiever UDP Port */
}; };
/** /**
@ -453,7 +454,7 @@ enum correctionFlags {
enum portType { enum portType {
CONTROL_PORT, /**< control port */ CONTROL_PORT, /**< control port */
STOP_PORT, /**<stop port */ STOP_PORT, /**<stop port */
DATA_PORT /**< data port */ DATA_PORT /**< receiver tcp port with client*/
}; };
/** hierarchy in multi-detector structure, if any */ /** hierarchy in multi-detector structure, if any */

View File

@ -124,7 +124,9 @@ enum {
F_GET_FRAME_INDEX, /**< gets the frame index */ F_GET_FRAME_INDEX, /**< gets the frame index */
F_RESET_FRAMES_CAUGHT /**< resets the frames caught */ F_RESET_FRAMES_CAUGHT, /**< resets the frames caught */
F_SETUP_UDP /**< sets the receiver udp connection and returns receiver mac address */
/* Always append functions hereafter!!! */ /* Always append functions hereafter!!! */

View File

@ -1129,11 +1129,11 @@ int setDACRegister(int idac, int val, int imod) {
int getTemperature(int tempSensor, int imod){ int getTemperature(int tempSensor, int imod){
int val; int val;
char cTempSensor[2][100]={"ADCs/ASICs","VRs/FPGAs"};
imod=0;//ignoring more than 1 mod for now imod=0;//ignoring more than 1 mod for now
int i,j,repeats=6; int i,j,repeats=6;
u_int32_t tempVal=0; u_int32_t tempVal=0;
#ifdef VERBOSE #ifdef VERBOSE
char cTempSensor[2][100]={"ADCs/ASICs","VRs/FPGAs"};
printf("Getting Temperature of module:%d for the %s for tempsensor:%d\n",imod,cTempSensor[tempSensor],tempSensor); printf("Getting Temperature of module:%d for the %s for tempsensor:%d\n",imod,cTempSensor[tempSensor],tempSensor);
#endif #endif
bus_w(TEMP_IN_REG,(T1_CLK_BIT)|(T1_CS_BIT)|(T2_CLK_BIT)|(T2_CS_BIT));//standby bus_w(TEMP_IN_REG,(T1_CLK_BIT)|(T1_CS_BIT)|(T2_CLK_BIT)|(T2_CS_BIT));//standby
@ -1250,7 +1250,7 @@ int initConfGain(int isettings,int val,int imod){
} }
int configureMAC(int ipad,long long int macad,long long int servermacad,int ival, int adc){ int configureMAC(int ipad,long long int macad,long long int servermacad,int ival, int adc,int udpport){
//setting daqregister //setting daqregister
setDAQRegister(adc); setDAQRegister(adc);
//setting adc mask //setting adc mask
@ -1409,7 +1409,7 @@ int configureMAC(int ipad,long long int macad,long long int servermacad,int ival
//#endif //#endif
mac_conf_regs->udp.udp_srcport = 0xE185; mac_conf_regs->udp.udp_srcport = 0xE185;
mac_conf_regs->udp.udp_destport = 0xC351; mac_conf_regs->udp.udp_destport = udpport;//0xC351;
mac_conf_regs->udp.udp_len = udpPacketSize;//0x050E; //was 0x0512; mac_conf_regs->udp.udp_len = udpPacketSize;//0x050E; //was 0x0512;
mac_conf_regs->udp.udp_chksum = 0x0000; mac_conf_regs->udp.udp_chksum = 0x0000;
@ -2231,7 +2231,6 @@ int readCounterBlock(int startACQ, short int CounterVals[]){
u_int32_t val; u_int32_t val;
volatile u_int16_t *ptr; volatile u_int16_t *ptr;
int i;
u_int32_t address = COUNTER_MEMORY_REG; u_int32_t address = COUNTER_MEMORY_REG;
ptr=(u_int16_t*)(CSP0BASE+address*2); ptr=(u_int16_t*)(CSP0BASE+address*2);
@ -2254,6 +2253,7 @@ int readCounterBlock(int startACQ, short int CounterVals[]){
memcpy(CounterVals,ptr,dataBytes); memcpy(CounterVals,ptr,dataBytes);
#ifdef VERBOSE #ifdef VERBOSE
int i;
printf("Copied counter memory block with size of %d bytes..\n",dataBytes); printf("Copied counter memory block with size of %d bytes..\n",dataBytes);
for(i=0;i<6;i++) for(i=0;i<6;i++)
printf("%d: %d\t",i,CounterVals[i]); printf("%d: %d\t",i,CounterVals[i]);
@ -2293,7 +2293,6 @@ int resetCounterBlock(int startACQ){
int ret = OK; int ret = OK;
u_int32_t val; u_int32_t val;
volatile u_int16_t *ptr; volatile u_int16_t *ptr;
int i;
u_int32_t address = COUNTER_MEMORY_REG; u_int32_t address = COUNTER_MEMORY_REG;
@ -2324,6 +2323,7 @@ int resetCounterBlock(int startACQ){
memcpy(counterVals,ptr,dataBytes); memcpy(counterVals,ptr,dataBytes);
#ifdef VERBOSE #ifdef VERBOSE
int i;
printf("Copied counter memory block with size of %d bytes..\n",(int)sizeof(counterVals)); printf("Copied counter memory block with size of %d bytes..\n",(int)sizeof(counterVals));
for(i=0;i<6;i=i+2) for(i=0;i<6;i=i+2)
printf("%d: %d\t",i,*(counterVals+i)); printf("%d: %d\t",i,*(counterVals+i));

View File

@ -62,7 +62,7 @@ int getTemperature(int tempSensor,int imod);
int initHighVoltage(int val,int imod); int initHighVoltage(int val,int imod);
int initConfGain(int isettings,int val,int imod); int initConfGain(int isettings,int val,int imod);
int configureMAC(int ipad, long long int macad, long long int servermacad, int ival, int adc); int configureMAC(int ipad, long long int macad, long long int servermacad, int ival, int adc,int udpport);
u_int64_t getDetectorNumber(); u_int64_t getDetectorNumber();
u_int32_t getFirmwareVersion(); u_int32_t getFirmwareVersion();

View File

@ -550,7 +550,6 @@ int get_id(int file_des) {
// sends back 64 bits! // sends back 64 bits!
int64_t retval; int64_t retval;
int ret=OK; int ret=OK;
int imod=-1;
int n=0; int n=0;
enum idMode arg; enum idMode arg;
@ -1892,7 +1891,7 @@ int get_run_status(int file_des) {
if (ret!=OK) { if (ret!=OK) {
printf("get status failed %04x\n"); printf("get status failed %04x\n",retval);
sprintf(mess, "get status failed %08x\n", retval); sprintf(mess, "get status failed %08x\n", retval);
} else if (differentClients) } else if (differentClients)
@ -2749,13 +2748,14 @@ int update_client(int file_des) {
int configure_mac(int file_des) { int configure_mac(int file_des) {
int ret=OK; int ret=OK;
char arg[3][50]; char arg[4][50];
int n,i; int n;
int imod=0;//should be in future sent from client as -1, arg[2] int imod=0;//should be in future sent from client as -1, arg[2]
int ipad; int ipad;
long long int imacadd; long long int imacadd;
long long int iservermacadd; long long int iservermacadd;
int udpport;
int adc=-1; int adc=-1;
sprintf(mess,"Can't configure MAC\n"); sprintf(mess,"Can't configure MAC\n");
@ -2770,7 +2770,9 @@ int configure_mac(int file_des) {
sscanf(arg[0], "%x", &ipad); sscanf(arg[0], "%x", &ipad);
sscanf(arg[1], "%llx", &imacadd); sscanf(arg[1], "%llx", &imacadd);
sscanf(arg[2], "%llx", &iservermacadd); sscanf(arg[2], "%llx", &iservermacadd);
sscanf(arg[3], "%x", &udpport);
#ifdef VERBOSE #ifdef VERBOSE
int i;
printf("\ndigital_test_bit in server %d\t",digitalTestBit); printf("\ndigital_test_bit in server %d\t",digitalTestBit);
printf("\nipadd %x\t",ipad); printf("\nipadd %x\t",ipad);
printf("destination ip is %d.%d.%d.%d = 0x%x \n",(ipad>>24)&0xff,(ipad>>16)&0xff,(ipad>>8)&0xff,(ipad)&0xff,ipad); printf("destination ip is %d.%d.%d.%d = 0x%x \n",(ipad>>24)&0xff,(ipad>>16)&0xff,(ipad>>8)&0xff,(ipad)&0xff,ipad);
@ -2780,6 +2782,7 @@ int configure_mac(int file_des) {
printf("server macad:%llx\n",iservermacadd); printf("server macad:%llx\n",iservermacadd);
for (i=0;i<6;i++) for (i=0;i<6;i++)
printf("server mac adress %d is 0x%x \n",6-i,(unsigned int)(((iservermacadd>>(8*i))&0xFF))); printf("server mac adress %d is 0x%x \n",6-i,(unsigned int)(((iservermacadd>>(8*i))&0xFF)));
printf("udp port:0x%x\n",udpport);
printf("\n"); printf("\n");
#endif #endif
@ -2796,11 +2799,11 @@ int configure_mac(int file_des) {
imod=ALLMOD; imod=ALLMOD;
//#ifdef VERBOSE //#ifdef VERBOSE
printf("Configuring MAC of module %d and adc %d\n", imod, adc); printf("Configuring MAC of module %d and adc %d at port %x\n", imod, adc,udpport);
//#endif //#endif
#ifdef MCB_FUNCS #ifdef MCB_FUNCS
if (ret==OK) if (ret==OK)
configureMAC(ipad,imacadd,iservermacadd,digitalTestBit,adc); configureMAC(ipad,imacadd,iservermacadd,digitalTestBit,adc,udpport);
#endif #endif
if (ret==FAIL) if (ret==FAIL)
printf("configuring MAC of mod %d failed\n", imod); printf("configuring MAC of mod %d failed\n", imod);

View File

@ -453,19 +453,23 @@ int slsDetector::initializeDetectorSize(detectorType type) {
/** set hostname to default */ /** set hostname to default */
strcpy(thisDetector->hostname,DEFAULT_HOSTNAME); strcpy(thisDetector->hostname,DEFAULT_HOSTNAME);
/** set client ip address */ /** set receiver tcp port */
strcpy(thisDetector->receiverIP,"none"); thisDetector->receiverTCPPort=DEFAULT_PORTNO+2;
/** set client mac address */ /** set receiver udp port */
strcpy(thisDetector->receiverMAC,"none"); thisDetector->receiverUDPPort=DEFAULT_UDP_PORTNO;
/** set receiver ip address/hostname */
strcpy(thisDetector->receiver_hostname,"none");
/** set receiver udp ip address */
strcpy(thisDetector->receiverUDPIP,"none");
/** set server mac address */ /** set server mac address */
strcpy(thisDetector->serverMAC,"00:aa:bb:cc:dd:ee"); strcpy(thisDetector->detectorMAC,"00:aa:bb:cc:dd:ee");
/** sets onlineFlag to OFFLINE_FLAG */ /** sets onlineFlag to OFFLINE_FLAG */
thisDetector->onlineFlag=OFFLINE_FLAG; thisDetector->onlineFlag=OFFLINE_FLAG;
/** set ports to defaults */ /** set ports to defaults */
thisDetector->controlPort=DEFAULT_PORTNO; thisDetector->controlPort=DEFAULT_PORTNO;
thisDetector->stopPort=DEFAULT_PORTNO+1; thisDetector->stopPort=DEFAULT_PORTNO+1;
thisDetector->receiverPort=DEFAULT_PORTNO+2;
/** set thisDetector->myDetectorType to type and according to this set nChans, nChips, nDacs, nAdcs, nModMax, dynamicRange, nMod*/ /** set thisDetector->myDetectorType to type and according to this set nChans, nChips, nDacs, nAdcs, nModMax, dynamicRange, nMod*/
thisDetector->myDetectorType=type; thisDetector->myDetectorType=type;
switch(thisDetector->myDetectorType) { switch(thisDetector->myDetectorType) {
@ -3459,7 +3463,6 @@ string slsDetector::getLastClientIP() {
int slsDetector::setPort(portType index, int num){ int slsDetector::setPort(portType index, int num){
int fnum=F_SET_PORT; int fnum=F_SET_PORT;
int retval; int retval;
// uint64_t ut; // uint64_t ut;
@ -3500,14 +3503,13 @@ int slsDetector::setPort(portType index, int num){
break; break;
case DATA_PORT: case DATA_PORT:
s=dataSocket; s=dataSocket;
retval=thisDetector->receiverPort; retval=thisDetector->receiverTCPPort;
if(strcmp(thisDetector->receiverIP,"none")){ if(strcmp(thisDetector->receiver_hostname,"none")){
if (s==NULL) {cout<<"s is null"<<endl;setReceiverTCPSocket("",retval);} if (s==NULL) setReceiverTCPSocket("",retval);
if (dataSocket){cout<<"datasocket now has value"<<endl; s=dataSocket;} if (dataSocket)s=dataSocket;
//else {cout<<"datasocket has no value"<<endl; setReceiverTCPSocket("",retval);} //else {cout<<"datasocket has no value"<<endl; setReceiverTCPSocket("",retval);}
} }
online = (thisDetector->receiverOnlineFlag==ONLINE_FLAG); online = (thisDetector->receiverOnlineFlag==ONLINE_FLAG);
cout<<"online:"<<online<<endl;
break; break;
case STOP_PORT: case STOP_PORT:
s=stopSocket; s=stopSocket;
@ -3548,11 +3550,9 @@ int slsDetector::setPort(portType index, int num){
break; break;
case DATA_PORT: case DATA_PORT:
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
cout<<"online,ret=ok"<<endl; thisDetector->receiverTCPPort=retval;
thisDetector->receiverPort=retval; setReceiverOnline(ONLINE_FLAG);
cout<<"first trying to set online:"<<setReceiverOnline(ONLINE_FLAG)<<endl; setReceiver(thisDetector->receiver_hostname);
cout<<"Setting up Receiver"<<endl;
setReceiverIP(thisDetector->receiverIP);
} }
break; break;
case STOP_PORT: case STOP_PORT:
@ -3571,16 +3571,12 @@ int slsDetector::setPort(portType index, int num){
thisDetector->controlPort=num; thisDetector->controlPort=num;
break; break;
case DATA_PORT: case DATA_PORT:
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ if(thisDetector->receiverOnlineFlag==ONLINE_FLAG)
cout<<"online,ret=fail"<<endl; thisDetector->receiverTCPPort=retval;
thisDetector->receiverPort=retval; else{
}else{ thisDetector->receiverTCPPort=num;
cout<<"not online,ret=fail"<<endl; if(strcmp(thisDetector->receiver_hostname,"none"))
thisDetector->receiverPort=num; setReceiver(thisDetector->receiver_hostname);
if(strcmp(thisDetector->receiverIP,"none")){
cout<<"ip not none, Setting up Receiver"<<endl;
setReceiverIP(thisDetector->receiverIP);
}
} }
break; break;
case STOP_PORT: case STOP_PORT:
@ -3596,7 +3592,7 @@ int slsDetector::setPort(portType index, int num){
retval=thisDetector->controlPort; retval=thisDetector->controlPort;
break; break;
case DATA_PORT: case DATA_PORT:
retval=thisDetector->receiverPort; retval=thisDetector->receiverTCPPort;
break; break;
case STOP_PORT: case STOP_PORT:
retval=thisDetector->stopPort; retval=thisDetector->stopPort;
@ -3609,7 +3605,7 @@ int slsDetector::setPort(portType index, int num){
#ifdef VERBOSE #ifdef VERBOSE
cout << thisDetector->controlPort<< " " << thisDetector->receiverPort << " " << thisDetector->stopPort << endl; cout << thisDetector->controlPort<< " " << thisDetector->receiverTCPPort << " " << thisDetector->stopPort << endl;
#endif #endif
@ -4445,15 +4441,16 @@ int slsDetector::exitServer(){
char* slsDetector::setNetworkParameter(networkParameter index, string value) { char* slsDetector::setNetworkParameter(networkParameter index, string value) {
switch (index) { switch (index) {
case RECEIVER_IP: case DETECTOR_MAC:
return setReceiverIP(value); return setDetectorMAC(value);
break; case RECEIVER_HOSTNAME:
case RECEIVER_MAC: return setReceiver(value);
return setReceiverMAC(value); case RECEIVER_UDP_IP:
break; setUDPConnection(value,"");
case SERVER_MAC: return getReceiverUDPIP();
return setServerMAC(value); case RECEIVER_UDP_PORT:
break; setUDPConnection("",value);
return getReceiverUDPPort();
default: default:
return ("unknown network parameter"); return ("unknown network parameter");
} }
@ -4463,14 +4460,17 @@ char* slsDetector::setNetworkParameter(networkParameter index, string value) {
char* slsDetector::getNetworkParameter(networkParameter index) { char* slsDetector::getNetworkParameter(networkParameter index) {
switch (index) { switch (index) {
case RECEIVER_IP: case DETECTOR_MAC:
return getReceiverIP(); return getDetectorMAC();
break; break;
case RECEIVER_MAC: case RECEIVER_HOSTNAME:
return getReceiverMAC(); return getReceiver();
break; break;
case SERVER_MAC: case RECEIVER_UDP_IP:
return getServerMAC(); return getReceiverUDPIP();
break;
case RECEIVER_UDP_PORT:
return getReceiverUDPPort();
break; break;
default: default:
return ("unknown network parameter"); return ("unknown network parameter");
@ -4483,14 +4483,16 @@ char* slsDetector::getNetworkParameter(networkParameter index) {
char* slsDetector::setReceiverIP(string receiverIP){ char* slsDetector::setReceiver(string receiverIP){
int wrongFormat=1; int wrongFormat=1;
struct sockaddr_in sa; struct sockaddr_in sa;
if(receiverIP.length()<16){ if(receiverIP.length()<16){
int result = inet_pton(AF_INET, receiverIP.c_str(), &(sa.sin_addr)); int result = inet_pton(AF_INET, receiverIP.c_str(), &(sa.sin_addr));
if(result!=0){ if(result!=0){
sprintf(thisDetector->receiverIP,receiverIP.c_str()); strcpy(thisDetector->receiver_hostname,receiverIP.c_str());
wrongFormat=0; wrongFormat=0;
} }
} }
@ -4499,79 +4501,139 @@ char* slsDetector::setReceiverIP(string receiverIP){
std::cout<< "IP Address should be VALID and in xxx.xxx.xxx.xxx format" << endl; std::cout<< "IP Address should be VALID and in xxx.xxx.xxx.xxx format" << endl;
else{ else{
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
setFilePath(fileIO::getFilePath()); setFilePath(fileIO::getFilePath());
setFileName(fileIO::getFileName()); setFileName(fileIO::getFileName());
setFileIndex(fileIO::getFileIndex()); setFileIndex(fileIO::getFileIndex());
if(thisDetector->myDetectorType==GOTTHARD){ setUDPConnection("","");
if(configureMAC()!=OK){
setReceiverOnline(OFFLINE_FLAG);
std::cout << "could not configure mac" << endl;
}
}
}else }else
std::cout << "cannot connect to receiver" << endl; std::cout << "cannot connect to receiver" << endl;
} }
return thisDetector->receiverIP; return thisDetector->receiver_hostname;
} }
char* slsDetector::setReceiverMAC(string receiverMAC){ char* slsDetector::setDetectorMAC(string detectorMAC){
if(receiverMAC.length()==17){ if(detectorMAC.length()==17){
if((receiverMAC[2]==':')&&(receiverMAC[5]==':')&&(receiverMAC[8]==':')&& if((detectorMAC[2]==':')&&(detectorMAC[5]==':')&&(detectorMAC[8]==':')&&
(receiverMAC[11]==':')&&(receiverMAC[14]==':')) (detectorMAC[11]==':')&&(detectorMAC[14]==':'))
sprintf(thisDetector->receiverMAC,receiverMAC.c_str()); strcpy(thisDetector->detectorMAC,detectorMAC.c_str());
else
return("MAC Address should be in xx:xx:xx:xx:xx:xx format");
}
else
return("MAC Address should be in xx:xx:xx:xx:xx:xx format");
return thisDetector->receiverMAC;
};
char* slsDetector::setServerMAC(string serverMAC){
if(serverMAC.length()==17){
if((serverMAC[2]==':')&&(serverMAC[5]==':')&&(serverMAC[8]==':')&&
(serverMAC[11]==':')&&(serverMAC[14]==':'))
sprintf(thisDetector->serverMAC,serverMAC.c_str());
else else
return("server MAC Address should be in xx:xx:xx:xx:xx:xx format"); return("server MAC Address should be in xx:xx:xx:xx:xx:xx format");
} }
else else
return("server MAC Address should be in xx:xx:xx:xx:xx:xx format"); return("server MAC Address should be in xx:xx:xx:xx:xx:xx format");
return thisDetector->serverMAC; return thisDetector->detectorMAC;
}; };
int slsDetector::setUDPConnection(string udpip, string udpport){
int ret = FAIL;
int fnum = F_SETUP_UDP;
char args[2][MAX_STR_LENGTH];
char retval[MAX_STR_LENGTH]="";
struct sockaddr_in sa;
//if no udp ip given
/*convert to IP if its only a hostname**/
if(!strcmp(thisDetector->receiverUDPIP,"none"))
strcpy(thisDetector->receiverUDPIP,thisDetector->receiver_hostname);
//copy to member if given in argument
if(udpip.length()){
if(udpip.length()<16){
int result = inet_pton(AF_INET, udpip.c_str(), &(sa.sin_addr));
if(result!=0)
strcpy(thisDetector->receiverUDPIP,udpip.c_str());
else{
std::cout<< "Receiver UDP IP Address should be VALID and in xxx.xxx.xxx.xxx format" << endl;
return FAIL;
}
}
}
if(udpport.length())
sscanf(udpport.c_str(),"%d",&thisDetector->receiverUDPPort);
//copy arguments to args[][]
strcpy(args[0],thisDetector->receiverUDPIP);
sprintf(args[1],"%d",thisDetector->receiverUDPPort);
//set up receiver for UDP Connection and get receivermac address
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "Setting up UDP Connection for Receiver " << arg[0] << "\t" << arg[1] << std::endl;
#endif
ret=thisReceiver->sendUDPDetails(fnum,retval,args);
if(ret!=FAIL){
#ifdef VERBOSE
std::cout << "Receiver mac address: " << retval << std::endl;
#endif
strcpy(thisDetector->receiverUDPMAC,retval);
strcpy(thisDetector->receiverUDPIP,args[0]);
sscanf(args[1],"%d",&thisDetector->receiverUDPPort);
//configure detector with udp details
if(configureMAC()!=OK){
setReceiverOnline(OFFLINE_FLAG);
std::cout << "could not configure mac" << endl;
}
}
if(ret==FORCE_UPDATE)
updateReceiver();
}else{
ret=FAIL;
std::cout << "cannot connect to receiver" << endl;
}
return ret;
}
int slsDetector::configureMAC(int adc){ int slsDetector::configureMAC(int adc){
int i; int i;
int ret=FAIL; int ret=FAIL;
int fnum=F_CONFIGURE_MAC; int fnum=F_CONFIGURE_MAC;
char mess[100]; char mess[100];
char arg[3][50]; char arg[4][50];
char cword[50]="", *pcword; char cword[50]="", *pcword;
string sword; string sword;
strcpy(arg[0],getReceiverIP()); //if udpip wasnt initialized in config file
strcpy(arg[1],getReceiverMAC()); if(!(strcmp(thisDetector->receiverUDPIP,"none")))
strcpy(arg[2],getServerMAC()); strcpy(thisDetector->receiverUDPIP,thisDetector->receiver_hostname);
strcpy(arg[0],thisDetector->receiverUDPIP);
strcpy(arg[1],thisDetector->receiverUDPMAC);
strcpy(arg[2],thisDetector->detectorMAC);
sprintf(arg[3],"%x",thisDetector->receiverUDPPort);
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "Configuring MAC with adc:"<< adc << std::endl; std::cout<< "Configuring MAC with adc:"<< adc << std::endl;
#endif #endif
for(i=0;i<3;i++){ for(i=0;i<3;i++){
if(!strcmp(arg[i],"none")){ if(!strcmp(arg[i],"none")){
std::cout<< "Configure MAC Error. IP/MAC Addresses has INVALID format"<< std::endl; std::cout<< "Configure MAC Error. IP/MAC Addresses not set"<< std::endl;
return FAIL; return FAIL;
} }
} }
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "IP/MAC Addresses in valid format "<< std::endl; std::cout<< "IP/MAC Addresses valid "<< std::endl;
#endif #endif
//converting IPaddress to hex. //converting IPaddress to hex.
@ -4583,7 +4645,7 @@ int slsDetector::configureMAC(int adc){
} }
strcpy(arg[0],cword); strcpy(arg[0],cword);
#ifdef VERBOSE #ifdef VERBOSE
std::cout<<"receiver ip:"<<arg[0]<<"."<<std::endl; std::cout<<"receiver udp ip:"<<arg[0]<<"."<<std::endl;
#endif #endif
//converting MACaddress to hex. //converting MACaddress to hex.
sword.assign(arg[1]); sword.assign(arg[1]);
@ -4601,8 +4663,12 @@ int slsDetector::configureMAC(int adc){
while(getline(ssstr,sword,':')) while(getline(ssstr,sword,':'))
strcat(arg[2],sword.c_str()); strcat(arg[2],sword.c_str());
#ifdef VERBOSE #ifdef VERBOSE
std::cout<<"server mac:"<<arg[2]<<"."<<std::endl; std::cout<<"detecotor mac:"<<arg[2]<<"."<<std::endl;
#endif #endif
#ifdef VERBOSE
std::cout<<"receiver udp port:"<<arg[3]<<"."<<std::endl;
#endif
//send to server //send to server
if (thisDetector->onlineFlag==ONLINE_FLAG) { if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (controlSocket) { if (controlSocket) {
@ -4968,7 +5034,7 @@ int slsDetector::writeConfigurationFile(ofstream &outfile, int id){
slsDetectorCommand *cmd=new slsDetectorCommand(this); slsDetectorCommand *cmd=new slsDetectorCommand(this);
int nvar=15; int nvar=15;
string names[]={ \ string names[20]={ \
"hostname", \ "hostname", \
"port", \ "port", \
"stopport", \ "stopport", \
@ -4987,26 +5053,27 @@ int slsDetector::writeConfigurationFile(ofstream &outfile, int id){
// to be added in the future // to be added in the future
// "trimen", // "trimen",
// "receiverPort", // "receiverTCPPort",
if (thisDetector->myDetectorType==GOTTHARD) { if (thisDetector->myDetectorType==GOTTHARD) {
names[0]= "hostname"; names[0]= "hostname";
names[1]= "port"; names[1]= "port";
names[2]= "stopport"; names[2]= "stopport";
names[3]= "receiverport"; names[3]= "settingsdir";
names[4]= "settingsdir"; names[4]= "angdir";
names[5]= "angdir"; names[5]= "moveflag";
names[6]= "moveflag"; names[6]= "lock";
names[7]= "lock"; names[7]= "caldir";
names[8]= "caldir"; names[8]= "ffdir";
names[9]= "ffdir"; names[9]= "extsig";
names[10]= "extsig"; names[10]="detectormac";
names[11]="receivermac"; names[11]= "rx_tcpport";
names[12]="servermac"; names[12]= "rx_udpport";
names[13]="receiverip"; names[13]="rx_hostname";
names[14]="outdir"; names[14]="rx_udpip";
names[15]="vhighvoltage"; names[15]="outdir";
nvar=16; names[16]="vhighvoltage";
nvar=17;
} }
@ -5281,7 +5348,7 @@ slsDetectorDefs::synchronizationMode slsDetector::setSynchronization(synchroniza
int slsDetector::setReceiverOnline(int off) { int slsDetector::setReceiverOnline(int off) {
// int prev = thisDetector->receiverOnlineFlag; // int prev = thisDetector->receiverOnlineFlag;
if (off!=GET_ONLINE_FLAG) { if (off!=GET_ONLINE_FLAG) {
if(strcmp(thisDetector->receiverIP,"none")){ if(strcmp(thisDetector->receiver_hostname,"none")){
thisDetector->receiverOnlineFlag=off; thisDetector->receiverOnlineFlag=off;
if (thisDetector->receiverOnlineFlag==ONLINE_FLAG){ if (thisDetector->receiverOnlineFlag==ONLINE_FLAG){
setReceiverTCPSocket(); setReceiverTCPSocket();
@ -5302,7 +5369,7 @@ string slsDetector::checkReceiverOnline() {
//this already sets the online/offline flag //this already sets the online/offline flag
setReceiverTCPSocket(); setReceiverTCPSocket();
if(thisDetector->receiverOnlineFlag==OFFLINE_FLAG) if(thisDetector->receiverOnlineFlag==OFFLINE_FLAG)
return string(thisDetector->receiverIP); return string(thisDetector->receiver_hostname);
else else
return string(""); return string("");
} }
@ -5345,27 +5412,27 @@ int slsDetector::setReceiverTCPSocket(string const name, int const receiver_port
std::cout<< "setting receiver" << std::endl; std::cout<< "setting receiver" << std::endl;
#endif #endif
strcpy(thisName,name.c_str()); strcpy(thisName,name.c_str());
strcpy(thisDetector->receiverIP,thisName); strcpy(thisDetector->receiver_hostname,thisName);
if (dataSocket){ if (dataSocket){
delete dataSocket; delete dataSocket;
dataSocket=NULL; dataSocket=NULL;
} }
} else } else
strcpy(thisName,thisDetector->receiverIP); strcpy(thisName,thisDetector->receiver_hostname);
//if receiverPort given //if receiverTCPPort given
if (receiver_port>0) { if (receiver_port>0) {
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "setting data port" << std::endl; std::cout<< "setting data port" << std::endl;
#endif #endif
thisRP=receiver_port; thisRP=receiver_port;
thisDetector->receiverPort=thisRP; thisDetector->receiverTCPPort=thisRP;
if (dataSocket){ if (dataSocket){
delete dataSocket; delete dataSocket;
dataSocket=NULL; dataSocket=NULL;
} }
} else } else
thisRP=thisDetector->receiverPort; thisRP=thisDetector->receiverTCPPort;
//create data socket //create data socket
if (!dataSocket) { if (!dataSocket) {

View File

@ -81,8 +81,6 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
int controlPort; int controlPort;
/** is the port used to stop the acquisition normally it should not be changed*/ /** is the port used to stop the acquisition normally it should not be changed*/
int stopPort; int stopPort;
/** is the port used to communicate with the receiver*/
int receiverPort;
/** detector type \ see :: detectorType*/ /** detector type \ see :: detectorType*/
detectorType myDetectorType; detectorType myDetectorType;
@ -232,14 +230,18 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
/* receiver*/ /* receiver*/
/** ip address/hostname of the receiver for the client to connect to**/
char receiver_hostname[MAX_STR_LENGTH];
/** ip address of the receiver **/ /** is the port used to communicate between client and the receiver*/
char receiverIP[MAX_STR_LENGTH]; int receiverTCPPort;
/** mac address of the receiver **/ /** is the port used to communicate between detector and the receiver*/
char receiverMAC[MAX_STR_LENGTH]; int receiverUDPPort;
/** mac address of the server **/ /** ip address of the receiver for the detector to send packets to**/
char serverMAC[MAX_STR_LENGTH]; char receiverUDPIP[MAX_STR_LENGTH];
/** mac address of receiver for the detector to send packets to **/
char receiverUDPMAC[MAX_STR_LENGTH];
/** mac address of the detector **/
char detectorMAC[MAX_STR_LENGTH];
/** online flag - is set if the receiver is connected, unset if socket connection is not possible */ /** online flag - is set if the receiver is connected, unset if socket connection is not possible */
int receiverOnlineFlag; int receiverOnlineFlag;
@ -364,7 +366,7 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
/** returns the detector stop port \sa sharedSlsDetector */ /** returns the detector stop port \sa sharedSlsDetector */
int getStopPort() {return thisDetector->stopPort;}; int getStopPort() {return thisDetector->stopPort;};
/** returns the receiver port \sa sharedSlsDetector */ /** returns the receiver port \sa sharedSlsDetector */
int getReceiverPort() {return thisDetector->receiverPort;}; int getReceiverPort() {return thisDetector->receiverTCPPort;};
/** Locks/Unlocks the connection to the server /** Locks/Unlocks the connection to the server
/param lock sets (1), usets (0), gets (-1) the lock /param lock sets (1), usets (0), gets (-1) the lock
@ -1614,19 +1616,22 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
/** returns the detector MAC address\sa sharedSlsDetector */
char* getDetectorMAC() {return thisDetector->detectorMAC;};
/** returns the receiver IP address \sa sharedSlsDetector */ /** returns the receiver IP address \sa sharedSlsDetector */
char* getReceiverIP() {return thisDetector->receiverIP;}; char* getReceiver() {return thisDetector->receiver_hostname;};
/** returns the receiver MAC address \sa sharedSlsDetector */ /** returns the receiver UDP IP address \sa sharedSlsDetector */
char* getReceiverMAC() {return thisDetector->receiverMAC;}; char* getReceiverUDPIP() {return thisDetector->receiverUDPIP;};
/** returns the server MAC address\sa sharedSlsDetector */ /** returns the receiver UDP IP address \sa sharedSlsDetector */
char* getServerMAC() {return thisDetector->serverMAC;}; char* getReceiverUDPPort() {char *c= new char[MAX_STR_LENGTH];sprintf(c,"%d",thisDetector->receiverUDPPort); return c;};
/** validates and sets the receiver IP address \sa sharedSlsDetector */
char* setReceiverIP(string receiverIP); /** validates the format of detector MAC address and sets it \sa sharedSlsDetector */
/** validates the format of receiver MAC address and sets it \sa sharedSlsDetector */ char* setDetectorMAC(string serverMAC);
char* setReceiverMAC(string receiverMAC); /** validates and sets the receiver IP address/hostname \sa sharedSlsDetector */
/** validates the format of server MAC address and sets it \sa sharedSlsDetector */ char* setReceiver(string receiver);
char* setServerMAC(string serverMAC);
/** Gets MAC from receiver and sets up UDP Connection */
int setUDPConnection(string udpip, string udpport);
}; };

View File

@ -321,15 +321,19 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
/* communication configuration */ /* communication configuration */
descrToFuncMap[i].m_pFuncName="receiverip"; // descrToFuncMap[i].m_pFuncName="rx_hostname"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter;
i++; i++;
descrToFuncMap[i].m_pFuncName="receivermac"; // descrToFuncMap[i].m_pFuncName="rx_udpip"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter;
i++; i++;
descrToFuncMap[i].m_pFuncName="servermac"; // descrToFuncMap[i].m_pFuncName="rx_udpport"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter;
i++;
descrToFuncMap[i].m_pFuncName="detectormac"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter;
i++; i++;
@ -337,6 +341,10 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdConfigureMac; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdConfigureMac;
i++; i++;
descrToFuncMap[i].m_pFuncName="rx_tcpport"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdPort;
i++;
descrToFuncMap[i].m_pFuncName="port"; // descrToFuncMap[i].m_pFuncName="port"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdPort; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdPort;
i++; i++;
@ -345,10 +353,6 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdPort; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdPort;
i++; i++;
descrToFuncMap[i].m_pFuncName="receiverport"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdPort;
i++;
descrToFuncMap[i].m_pFuncName="lock"; // descrToFuncMap[i].m_pFuncName="lock"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdLock; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdLock;
i++; i++;
@ -2218,17 +2222,22 @@ string slsDetectorCommand::helpScans(int narg, char *args[], int action) {
string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int action) { string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int action) {
networkParameter t; networkParameter t;
int i;
if (action==HELP_ACTION) if (action==HELP_ACTION)
return helpNetworkParameter(narg,args,action); return helpNetworkParameter(narg,args,action);
if (cmd=="receiverip") { myDet->setOnline(ONLINE_FLAG);
myDet->setOnline(ONLINE_FLAG);
t=RECEIVER_IP; if (cmd=="detectormac") {
} else if (cmd=="receivermac") { t=DETECTOR_MAC;
t=RECEIVER_MAC; } else if (cmd=="rx_hostname") {
} else if (cmd=="servermac") { t=RECEIVER_HOSTNAME;
t=SERVER_MAC; } else if (cmd=="rx_udpport") {
t=RECEIVER_UDP_PORT;
} else if (cmd=="rx_udpip") {
t=RECEIVER_UDP_IP;
if (!(sscanf(args[1],"%d",&i)))
return ("cannot parse argument") + string(args[1]);
} else return ("unknown network parameter")+cmd; } else return ("unknown network parameter")+cmd;
if (action==PUT_ACTION) if (action==PUT_ACTION)
@ -2244,15 +2253,16 @@ string slsDetectorCommand::helpNetworkParameter(int narg, char *args[], int acti
ostringstream os; ostringstream os;
if (action==PUT_ACTION || action==HELP_ACTION) { if (action==PUT_ACTION || action==HELP_ACTION) {
os << "receiverip ip \n sets receiver ip to ip"<< std::endl; os << "detectormac mac \n sets detector mac to mac"<< std::endl;
os << "receivermac mac \n sets receiver mac to mac"<< std::endl; os << "rx_hostname name \n sets receiver ip/hostname to name"<< std::endl;
os << "servermac mac \n sets server mac to mac"<< std::endl; os << "rx_udpip ip \n sets receiver udp ip to ip"<< std::endl;
os << "rx_udpport port \n sets receiver udp port to port"<< std::endl;
} }
if (action==GET_ACTION || action==HELP_ACTION) { if (action==GET_ACTION || action==HELP_ACTION) {
os << "receiverip \n gets receiver ip "<< std::endl; os << "detectormac \n gets detector mac "<< std::endl;
os << "receivermac \n gets receiver mac "<< std::endl; os << "rx_hostname \n gets receiver ip "<< std::endl;
os << "servermac \n gets server mac "<< std::endl; os << "rx_udpip \n gets receiver udp ip "<< std::endl;
os << "rx_udpport \n gets receiver udp port "<< std::endl;
} }
return os.str(); return os.str();
@ -2276,7 +2286,7 @@ string slsDetectorCommand::cmdPort(int narg, char *args[], int action) {
if (cmd=="port") { if (cmd=="port") {
index=CONTROL_PORT; index=CONTROL_PORT;
} else if (cmd=="receiverport") { } else if (cmd=="rx_tcpport") {
index=DATA_PORT; index=DATA_PORT;
} else if (cmd=="stopport") { } else if (cmd=="stopport") {
index=STOP_PORT; index=STOP_PORT;
@ -2300,13 +2310,13 @@ string slsDetectorCommand::helpPort(int narg, char *args[], int action) {
ostringstream os; ostringstream os;
if (action==PUT_ACTION || action==HELP_ACTION) { if (action==PUT_ACTION || action==HELP_ACTION) {
os << "port i \n sets the communication control port"<< std::endl; os << "port i \n sets the communication control port"<< std::endl;
os << "receiverport i \n sets the communication receiver port"<< std::endl; os << "rx_tcpport i \n sets the communication receiver port"<< std::endl;
os << "stopport i \n sets the communication stop port "<< std::endl; os << "stopport i \n sets the communication stop port "<< std::endl;
} }
if (action==GET_ACTION || action==HELP_ACTION) { if (action==GET_ACTION || action==HELP_ACTION) {
os << "port \n gets the communication control port"<< std::endl; os << "port \n gets the communication control port"<< std::endl;
os << "receiverport \n gets the communication receiver port"<< std::endl; os << "rx_tcpport \n gets the communication receiver port"<< std::endl;
os << "stopport \n gets the communication stop port "<< std::endl; os << "stopport \n gets the communication stop port "<< std::endl;
} }
return os.str(); return os.str();

View File

@ -1,5 +1,4 @@
#include "receiverInterface.h" #include "receiverInterface.h"
#include "sls_detector_defs.h"
#include <sys/types.h> #include <sys/types.h>
@ -44,6 +43,29 @@ int receiverInterface::sendString(int fnum, char retval[], char arg[]){
int receiverInterface::sendUDPDetails(int fnum, char retval[], char arg[2][MAX_STR_LENGTH]){
char args[2][MAX_STR_LENGTH];
int ret = slsDetectorDefs::FAIL;
char mess[100] = "";
if (dataSocket) {
if (dataSocket->Connect()>=0) {
dataSocket->SendDataOnly(&fnum,sizeof(fnum));
dataSocket->SendDataOnly(arg,sizeof(args));
dataSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret==slsDetectorDefs::FAIL){
dataSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Receiver returned error: " << mess << std::endl;
}
else
dataSocket->ReceiveDataOnly(retval,MAX_STR_LENGTH);
}
dataSocket->Disconnect();
}
return ret;
}
int receiverInterface::sendInt(int fnum, int &retval, int arg){ int receiverInterface::sendInt(int fnum, int &retval, int arg){
int ret = slsDetectorDefs::FAIL; int ret = slsDetectorDefs::FAIL;
char mess[100] = ""; char mess[100] = "";

View File

@ -4,6 +4,7 @@
#ifndef SLS_RECEIVER_INTERFACE_H #ifndef SLS_RECEIVER_INTERFACE_H
#define SLS_RECEIVER_INTERFACE_H #define SLS_RECEIVER_INTERFACE_H
#include "sls_detector_defs.h"
#include "MySocketTCP.h" #include "MySocketTCP.h"
@ -48,6 +49,15 @@ public:
*/ */
int sendString(int fnum, char retval[], char arg[]); int sendString(int fnum, char retval[], char arg[]);
/**
* Send a string to receiver
* @param fnum function enum to send udp ip and udp port
* @param retval return value receiver mac
* @param arg value to send
* \returns success of operation
*/
int sendUDPDetails(int fnum, char retval[], char arg[2][MAX_STR_LENGTH]);
/** /**
* Send an integer to receiver * Send an integer to receiver