From ac2c4211e2ccf5506fd0b11c5a2cc5ed083f6de8 Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Thu, 6 Dec 2012 14:27:52 +0000 Subject: [PATCH] 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 --- .../MySocketTCP/genericSocket.h | 5 +- .../commonFiles/sls_detector_defs.h | 9 +- .../commonFiles/sls_detector_funcs.h | 4 +- .../gotthardDetectorServer/firmware_funcs.c | 10 +- .../gotthardDetectorServer/firmware_funcs.h | 2 +- .../gotthardDetectorServer/server_funcs.c | 15 +- .../slsDetector/slsDetector.cpp | 277 +++++++++++------- slsDetectorSoftware/slsDetector/slsDetector.h | 51 ++-- .../slsDetector/slsDetectorCommand.cpp | 60 ++-- .../receiverInterface.cpp | 24 +- .../slsReceiverInterface/receiverInterface.h | 10 + 11 files changed, 294 insertions(+), 173 deletions(-) diff --git a/slsDetectorSoftware/MySocketTCP/genericSocket.h b/slsDetectorSoftware/MySocketTCP/genericSocket.h index 6201c11e4..671efe44c 100644 --- a/slsDetectorSoftware/MySocketTCP/genericSocket.h +++ b/slsDetectorSoftware/MySocketTCP/genericSocket.h @@ -74,6 +74,7 @@ using namespace std; #define DEFAULT_PACKET_SIZE 1286 #define DEFAULT_PORTNO 1952 #define DEFAULT_BACKLOG 5 +#define DEFAULT_UDP_PORTNO 50001 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"); clientAddress_length=sizeof(clientAddress); - if (eth) { strcpy(ip,nameToIp(string(eth)).c_str()); 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); inet_ntop(iap->ifa_addr->sa_family, (void *)&(sa->sin_addr), buf, sizeof(buf)); if (ip==string(buf)) { - printf("%s\n", iap->ifa_name); + //printf("%s\n", iap->ifa_name); + strcpy(buf,iap->ifa_name); } } } diff --git a/slsDetectorSoftware/commonFiles/sls_detector_defs.h b/slsDetectorSoftware/commonFiles/sls_detector_defs.h index 27e0c848c..895bc6fe4 100755 --- a/slsDetectorSoftware/commonFiles/sls_detector_defs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_defs.h @@ -174,9 +174,10 @@ enum detectorType { */ enum networkParameter { - RECEIVER_IP, /**< receiver IP */ - RECEIVER_MAC, /**< receiver mac */ - SERVER_MAC /**< server MAC */ + DETECTOR_MAC, /**< detector MAC */ + RECEIVER_HOSTNAME, /**< receiver IP/hostname */ + RECEIVER_UDP_IP, /**< receiever UDP IP */ + RECEIVER_UDP_PORT /**< receiever UDP Port */ }; /** @@ -453,7 +454,7 @@ enum correctionFlags { enum portType { CONTROL_PORT, /**< control port */ STOP_PORT, /**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_chksum = 0x0000; @@ -2231,7 +2231,6 @@ int readCounterBlock(int startACQ, short int CounterVals[]){ u_int32_t val; volatile u_int16_t *ptr; - int i; u_int32_t address = COUNTER_MEMORY_REG; ptr=(u_int16_t*)(CSP0BASE+address*2); @@ -2254,6 +2253,7 @@ int readCounterBlock(int startACQ, short int CounterVals[]){ memcpy(CounterVals,ptr,dataBytes); #ifdef VERBOSE + int i; printf("Copied counter memory block with size of %d bytes..\n",dataBytes); for(i=0;i<6;i++) printf("%d: %d\t",i,CounterVals[i]); @@ -2293,7 +2293,6 @@ int resetCounterBlock(int startACQ){ int ret = OK; u_int32_t val; volatile u_int16_t *ptr; - int i; u_int32_t address = COUNTER_MEMORY_REG; @@ -2324,6 +2323,7 @@ int resetCounterBlock(int startACQ){ memcpy(counterVals,ptr,dataBytes); #ifdef VERBOSE + int i; printf("Copied counter memory block with size of %d bytes..\n",(int)sizeof(counterVals)); for(i=0;i<6;i=i+2) printf("%d: %d\t",i,*(counterVals+i)); diff --git a/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.h b/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.h index 22824a5e4..bb5e99689 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.h +++ b/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.h @@ -62,7 +62,7 @@ int getTemperature(int tempSensor,int imod); int initHighVoltage(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_int32_t getFirmwareVersion(); diff --git a/slsDetectorSoftware/gotthardDetectorServer/server_funcs.c b/slsDetectorSoftware/gotthardDetectorServer/server_funcs.c index 9087dd587..713dd0a3d 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/server_funcs.c +++ b/slsDetectorSoftware/gotthardDetectorServer/server_funcs.c @@ -550,7 +550,6 @@ int get_id(int file_des) { // sends back 64 bits! int64_t retval; int ret=OK; - int imod=-1; int n=0; enum idMode arg; @@ -1892,7 +1891,7 @@ int get_run_status(int file_des) { if (ret!=OK) { - printf("get status failed %04x\n"); + printf("get status failed %04x\n",retval); sprintf(mess, "get status failed %08x\n", retval); } else if (differentClients) @@ -2749,13 +2748,14 @@ int update_client(int file_des) { int configure_mac(int file_des) { int ret=OK; - char arg[3][50]; - int n,i; + char arg[4][50]; + int n; int imod=0;//should be in future sent from client as -1, arg[2] int ipad; long long int imacadd; long long int iservermacadd; + int udpport; int adc=-1; sprintf(mess,"Can't configure MAC\n"); @@ -2770,7 +2770,9 @@ int configure_mac(int file_des) { sscanf(arg[0], "%x", &ipad); sscanf(arg[1], "%llx", &imacadd); sscanf(arg[2], "%llx", &iservermacadd); + sscanf(arg[3], "%x", &udpport); #ifdef VERBOSE + int i; printf("\ndigital_test_bit in server %d\t",digitalTestBit); 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); @@ -2780,6 +2782,7 @@ int configure_mac(int file_des) { printf("server macad:%llx\n",iservermacadd); for (i=0;i<6;i++) 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"); #endif @@ -2796,11 +2799,11 @@ int configure_mac(int file_des) { imod=ALLMOD; //#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 #ifdef MCB_FUNCS if (ret==OK) - configureMAC(ipad,imacadd,iservermacadd,digitalTestBit,adc); + configureMAC(ipad,imacadd,iservermacadd,digitalTestBit,adc,udpport); #endif if (ret==FAIL) printf("configuring MAC of mod %d failed\n", imod); diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index cda53e221..0602f3701 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -453,19 +453,23 @@ int slsDetector::initializeDetectorSize(detectorType type) { /** set hostname to default */ strcpy(thisDetector->hostname,DEFAULT_HOSTNAME); - /** set client ip address */ - strcpy(thisDetector->receiverIP,"none"); - /** set client mac address */ - strcpy(thisDetector->receiverMAC,"none"); + /** set receiver tcp port */ + thisDetector->receiverTCPPort=DEFAULT_PORTNO+2; + /** set receiver udp port */ + 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 */ - strcpy(thisDetector->serverMAC,"00:aa:bb:cc:dd:ee"); + strcpy(thisDetector->detectorMAC,"00:aa:bb:cc:dd:ee"); /** sets onlineFlag to OFFLINE_FLAG */ thisDetector->onlineFlag=OFFLINE_FLAG; /** set ports to defaults */ thisDetector->controlPort=DEFAULT_PORTNO; 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*/ thisDetector->myDetectorType=type; switch(thisDetector->myDetectorType) { @@ -3459,7 +3463,6 @@ string slsDetector::getLastClientIP() { int slsDetector::setPort(portType index, int num){ - int fnum=F_SET_PORT; int retval; // uint64_t ut; @@ -3500,14 +3503,13 @@ int slsDetector::setPort(portType index, int num){ break; case DATA_PORT: s=dataSocket; - retval=thisDetector->receiverPort; - if(strcmp(thisDetector->receiverIP,"none")){ - if (s==NULL) {cout<<"s is null"<receiverTCPPort; + if(strcmp(thisDetector->receiver_hostname,"none")){ + if (s==NULL) setReceiverTCPSocket("",retval); + if (dataSocket)s=dataSocket; //else {cout<<"datasocket has no value"<receiverOnlineFlag==ONLINE_FLAG); - cout<<"online:"<receiverOnlineFlag==ONLINE_FLAG){ - cout<<"online,ret=ok"<receiverPort=retval; - cout<<"first trying to set online:"<receiverIP); + thisDetector->receiverTCPPort=retval; + setReceiverOnline(ONLINE_FLAG); + setReceiver(thisDetector->receiver_hostname); } break; case STOP_PORT: @@ -3571,16 +3571,12 @@ int slsDetector::setPort(portType index, int num){ thisDetector->controlPort=num; break; case DATA_PORT: - if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){ - cout<<"online,ret=fail"<receiverPort=retval; - }else{ - cout<<"not online,ret=fail"<receiverPort=num; - if(strcmp(thisDetector->receiverIP,"none")){ - cout<<"ip not none, Setting up Receiver"<receiverIP); - } + if(thisDetector->receiverOnlineFlag==ONLINE_FLAG) + thisDetector->receiverTCPPort=retval; + else{ + thisDetector->receiverTCPPort=num; + if(strcmp(thisDetector->receiver_hostname,"none")) + setReceiver(thisDetector->receiver_hostname); } break; case STOP_PORT: @@ -3596,7 +3592,7 @@ int slsDetector::setPort(portType index, int num){ retval=thisDetector->controlPort; break; case DATA_PORT: - retval=thisDetector->receiverPort; + retval=thisDetector->receiverTCPPort; break; case STOP_PORT: retval=thisDetector->stopPort; @@ -3609,7 +3605,7 @@ int slsDetector::setPort(portType index, int num){ #ifdef VERBOSE - cout << thisDetector->controlPort<< " " << thisDetector->receiverPort << " " << thisDetector->stopPort << endl; + cout << thisDetector->controlPort<< " " << thisDetector->receiverTCPPort << " " << thisDetector->stopPort << endl; #endif @@ -4445,15 +4441,16 @@ int slsDetector::exitServer(){ char* slsDetector::setNetworkParameter(networkParameter index, string value) { switch (index) { - case RECEIVER_IP: - return setReceiverIP(value); - break; - case RECEIVER_MAC: - return setReceiverMAC(value); - break; - case SERVER_MAC: - return setServerMAC(value); - break; + case DETECTOR_MAC: + return setDetectorMAC(value); + case RECEIVER_HOSTNAME: + return setReceiver(value); + case RECEIVER_UDP_IP: + setUDPConnection(value,""); + return getReceiverUDPIP(); + case RECEIVER_UDP_PORT: + setUDPConnection("",value); + return getReceiverUDPPort(); default: return ("unknown network parameter"); } @@ -4463,14 +4460,17 @@ char* slsDetector::setNetworkParameter(networkParameter index, string value) { char* slsDetector::getNetworkParameter(networkParameter index) { switch (index) { - case RECEIVER_IP: - return getReceiverIP(); + case DETECTOR_MAC: + return getDetectorMAC(); break; - case RECEIVER_MAC: - return getReceiverMAC(); + case RECEIVER_HOSTNAME: + return getReceiver(); break; - case SERVER_MAC: - return getServerMAC(); + case RECEIVER_UDP_IP: + return getReceiverUDPIP(); + break; + case RECEIVER_UDP_PORT: + return getReceiverUDPPort(); break; default: 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; struct sockaddr_in sa; if(receiverIP.length()<16){ int result = inet_pton(AF_INET, receiverIP.c_str(), &(sa.sin_addr)); if(result!=0){ - sprintf(thisDetector->receiverIP,receiverIP.c_str()); + strcpy(thisDetector->receiver_hostname,receiverIP.c_str()); 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; else{ if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){ + setFilePath(fileIO::getFilePath()); setFileName(fileIO::getFileName()); setFileIndex(fileIO::getFileIndex()); - if(thisDetector->myDetectorType==GOTTHARD){ - if(configureMAC()!=OK){ - setReceiverOnline(OFFLINE_FLAG); - std::cout << "could not configure mac" << endl; - } - } + setUDPConnection("",""); }else std::cout << "cannot connect to receiver" << endl; } - return thisDetector->receiverIP; + return thisDetector->receiver_hostname; } -char* slsDetector::setReceiverMAC(string receiverMAC){ - if(receiverMAC.length()==17){ - if((receiverMAC[2]==':')&&(receiverMAC[5]==':')&&(receiverMAC[8]==':')&& - (receiverMAC[11]==':')&&(receiverMAC[14]==':')) - sprintf(thisDetector->receiverMAC,receiverMAC.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()); +char* slsDetector::setDetectorMAC(string detectorMAC){ + if(detectorMAC.length()==17){ + if((detectorMAC[2]==':')&&(detectorMAC[5]==':')&&(detectorMAC[8]==':')&& + (detectorMAC[11]==':')&&(detectorMAC[14]==':')) + strcpy(thisDetector->detectorMAC,detectorMAC.c_str()); else return("server MAC Address should be in xx:xx:xx:xx:xx:xx format"); } else 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 i; int ret=FAIL; int fnum=F_CONFIGURE_MAC; char mess[100]; - char arg[3][50]; + char arg[4][50]; char cword[50]="", *pcword; string sword; - strcpy(arg[0],getReceiverIP()); - strcpy(arg[1],getReceiverMAC()); - strcpy(arg[2],getServerMAC()); + //if udpip wasnt initialized in config file + if(!(strcmp(thisDetector->receiverUDPIP,"none"))) + 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 std::cout<< "Configuring MAC with adc:"<< adc << std::endl; #endif + for(i=0;i<3;i++){ 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; } } #ifdef VERBOSE - std::cout<< "IP/MAC Addresses in valid format "<< std::endl; + std::cout<< "IP/MAC Addresses valid "<< std::endl; #endif //converting IPaddress to hex. @@ -4583,7 +4645,7 @@ int slsDetector::configureMAC(int adc){ } strcpy(arg[0],cword); #ifdef VERBOSE - std::cout<<"receiver ip:"<onlineFlag==ONLINE_FLAG) { if (controlSocket) { @@ -4968,7 +5034,7 @@ int slsDetector::writeConfigurationFile(ofstream &outfile, int id){ slsDetectorCommand *cmd=new slsDetectorCommand(this); int nvar=15; - string names[]={ \ + string names[20]={ \ "hostname", \ "port", \ "stopport", \ @@ -4987,26 +5053,27 @@ int slsDetector::writeConfigurationFile(ofstream &outfile, int id){ // to be added in the future // "trimen", - // "receiverPort", + // "receiverTCPPort", if (thisDetector->myDetectorType==GOTTHARD) { names[0]= "hostname"; names[1]= "port"; names[2]= "stopport"; - names[3]= "receiverport"; - names[4]= "settingsdir"; - names[5]= "angdir"; - names[6]= "moveflag"; - names[7]= "lock"; - names[8]= "caldir"; - names[9]= "ffdir"; - names[10]= "extsig"; - names[11]="receivermac"; - names[12]="servermac"; - names[13]="receiverip"; - names[14]="outdir"; - names[15]="vhighvoltage"; - nvar=16; + names[3]= "settingsdir"; + names[4]= "angdir"; + names[5]= "moveflag"; + names[6]= "lock"; + names[7]= "caldir"; + names[8]= "ffdir"; + names[9]= "extsig"; + names[10]="detectormac"; + names[11]= "rx_tcpport"; + names[12]= "rx_udpport"; + names[13]="rx_hostname"; + names[14]="rx_udpip"; + names[15]="outdir"; + names[16]="vhighvoltage"; + nvar=17; } @@ -5281,7 +5348,7 @@ slsDetectorDefs::synchronizationMode slsDetector::setSynchronization(synchroniza int slsDetector::setReceiverOnline(int off) { // int prev = thisDetector->receiverOnlineFlag; if (off!=GET_ONLINE_FLAG) { - if(strcmp(thisDetector->receiverIP,"none")){ + if(strcmp(thisDetector->receiver_hostname,"none")){ thisDetector->receiverOnlineFlag=off; if (thisDetector->receiverOnlineFlag==ONLINE_FLAG){ setReceiverTCPSocket(); @@ -5302,7 +5369,7 @@ string slsDetector::checkReceiverOnline() { //this already sets the online/offline flag setReceiverTCPSocket(); if(thisDetector->receiverOnlineFlag==OFFLINE_FLAG) - return string(thisDetector->receiverIP); + return string(thisDetector->receiver_hostname); else return string(""); } @@ -5345,27 +5412,27 @@ int slsDetector::setReceiverTCPSocket(string const name, int const receiver_port std::cout<< "setting receiver" << std::endl; #endif strcpy(thisName,name.c_str()); - strcpy(thisDetector->receiverIP,thisName); + strcpy(thisDetector->receiver_hostname,thisName); if (dataSocket){ delete dataSocket; dataSocket=NULL; } } else - strcpy(thisName,thisDetector->receiverIP); + strcpy(thisName,thisDetector->receiver_hostname); - //if receiverPort given + //if receiverTCPPort given if (receiver_port>0) { #ifdef VERBOSE std::cout<< "setting data port" << std::endl; #endif thisRP=receiver_port; - thisDetector->receiverPort=thisRP; + thisDetector->receiverTCPPort=thisRP; if (dataSocket){ delete dataSocket; dataSocket=NULL; } } else - thisRP=thisDetector->receiverPort; + thisRP=thisDetector->receiverTCPPort; //create data socket if (!dataSocket) { diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 22e7212ec..55c3da0b2 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -81,8 +81,6 @@ class slsDetector : public slsDetectorUtils, public energyConversion { int controlPort; /** is the port used to stop the acquisition normally it should not be changed*/ int stopPort; - /** is the port used to communicate with the receiver*/ - int receiverPort; /** detector type \ see :: detectorType*/ detectorType myDetectorType; @@ -232,14 +230,18 @@ class slsDetector : public slsDetectorUtils, public energyConversion { /* receiver*/ - - - /** ip address of the receiver **/ - char receiverIP[MAX_STR_LENGTH]; - /** mac address of the receiver **/ - char receiverMAC[MAX_STR_LENGTH]; - /** mac address of the server **/ - char serverMAC[MAX_STR_LENGTH]; + /** ip address/hostname of the receiver for the client to connect to**/ + char receiver_hostname[MAX_STR_LENGTH]; + /** is the port used to communicate between client and the receiver*/ + int receiverTCPPort; + /** is the port used to communicate between detector and the receiver*/ + int receiverUDPPort; + /** ip address of the receiver for the detector to send packets to**/ + 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 */ int receiverOnlineFlag; @@ -364,7 +366,7 @@ class slsDetector : public slsDetectorUtils, public energyConversion { /** returns the detector stop port \sa sharedSlsDetector */ int getStopPort() {return thisDetector->stopPort;}; /** returns the receiver port \sa sharedSlsDetector */ - int getReceiverPort() {return thisDetector->receiverPort;}; + int getReceiverPort() {return thisDetector->receiverTCPPort;}; /** Locks/Unlocks the connection to the server /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 */ - char* getReceiverIP() {return thisDetector->receiverIP;}; - /** returns the receiver MAC address \sa sharedSlsDetector */ - char* getReceiverMAC() {return thisDetector->receiverMAC;}; - /** returns the server MAC address\sa sharedSlsDetector */ - char* getServerMAC() {return thisDetector->serverMAC;}; - /** validates and sets the receiver IP address \sa sharedSlsDetector */ - char* setReceiverIP(string receiverIP); - /** validates the format of receiver MAC address and sets it \sa sharedSlsDetector */ - char* setReceiverMAC(string receiverMAC); - /** validates the format of server MAC address and sets it \sa sharedSlsDetector */ - char* setServerMAC(string serverMAC); + char* getReceiver() {return thisDetector->receiver_hostname;}; + /** returns the receiver UDP IP address \sa sharedSlsDetector */ + char* getReceiverUDPIP() {return thisDetector->receiverUDPIP;}; + /** returns the receiver UDP IP address \sa sharedSlsDetector */ + char* getReceiverUDPPort() {char *c= new char[MAX_STR_LENGTH];sprintf(c,"%d",thisDetector->receiverUDPPort); return c;}; + + /** validates the format of detector MAC address and sets it \sa sharedSlsDetector */ + char* setDetectorMAC(string serverMAC); + /** validates and sets the receiver IP address/hostname \sa sharedSlsDetector */ + char* setReceiver(string receiver); + + /** Gets MAC from receiver and sets up UDP Connection */ + int setUDPConnection(string udpip, string udpport); }; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index c36fdcc36..4203f66ca 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -321,15 +321,19 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { /* communication configuration */ - descrToFuncMap[i].m_pFuncName="receiverip"; // + descrToFuncMap[i].m_pFuncName="rx_hostname"; // descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter; i++; - descrToFuncMap[i].m_pFuncName="receivermac"; // + descrToFuncMap[i].m_pFuncName="rx_udpip"; // descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter; 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; i++; @@ -337,6 +341,10 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdConfigureMac; i++; + descrToFuncMap[i].m_pFuncName="rx_tcpport"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdPort; + i++; + descrToFuncMap[i].m_pFuncName="port"; // descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdPort; i++; @@ -345,10 +353,6 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdPort; i++; - descrToFuncMap[i].m_pFuncName="receiverport"; // - descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdPort; - i++; - descrToFuncMap[i].m_pFuncName="lock"; // descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdLock; i++; @@ -2218,17 +2222,22 @@ string slsDetectorCommand::helpScans(int narg, char *args[], int action) { string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int action) { networkParameter t; - + int i; if (action==HELP_ACTION) return helpNetworkParameter(narg,args,action); - if (cmd=="receiverip") { - myDet->setOnline(ONLINE_FLAG); - t=RECEIVER_IP; - } else if (cmd=="receivermac") { - t=RECEIVER_MAC; - } else if (cmd=="servermac") { - t=SERVER_MAC; + myDet->setOnline(ONLINE_FLAG); + + if (cmd=="detectormac") { + t=DETECTOR_MAC; + } else if (cmd=="rx_hostname") { + t=RECEIVER_HOSTNAME; + } 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; if (action==PUT_ACTION) @@ -2244,15 +2253,16 @@ string slsDetectorCommand::helpNetworkParameter(int narg, char *args[], int acti ostringstream os; if (action==PUT_ACTION || action==HELP_ACTION) { - os << "receiverip ip \n sets receiver ip to ip"<< std::endl; - os << "receivermac mac \n sets receiver mac to mac"<< std::endl; - os << "servermac mac \n sets server mac to mac"<< std::endl; - + os << "detectormac mac \n sets detector mac to mac"<< std::endl; + os << "rx_hostname name \n sets receiver ip/hostname to name"<< 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) { - os << "receiverip \n gets receiver ip "<< std::endl; - os << "receivermac \n gets receiver mac "<< std::endl; - os << "servermac \n gets server mac "<< std::endl; + os << "detectormac \n gets detector mac "<< std::endl; + os << "rx_hostname \n gets receiver ip "<< 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(); @@ -2276,7 +2286,7 @@ string slsDetectorCommand::cmdPort(int narg, char *args[], int action) { if (cmd=="port") { index=CONTROL_PORT; - } else if (cmd=="receiverport") { + } else if (cmd=="rx_tcpport") { index=DATA_PORT; } else if (cmd=="stopport") { index=STOP_PORT; @@ -2300,13 +2310,13 @@ string slsDetectorCommand::helpPort(int narg, char *args[], int action) { ostringstream os; if (action==PUT_ACTION || action==HELP_ACTION) { 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; } if (action==GET_ACTION || action==HELP_ACTION) { 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; } return os.str(); diff --git a/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp b/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp index 6b9fcfa5a..bcc3640e0 100644 --- a/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp +++ b/slsDetectorSoftware/slsReceiverInterface/receiverInterface.cpp @@ -1,5 +1,4 @@ #include "receiverInterface.h" -#include "sls_detector_defs.h" #include @@ -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 ret = slsDetectorDefs::FAIL; char mess[100] = ""; diff --git a/slsDetectorSoftware/slsReceiverInterface/receiverInterface.h b/slsDetectorSoftware/slsReceiverInterface/receiverInterface.h index b439d352a..1a2fd9eae 100644 --- a/slsDetectorSoftware/slsReceiverInterface/receiverInterface.h +++ b/slsDetectorSoftware/slsReceiverInterface/receiverInterface.h @@ -4,6 +4,7 @@ #ifndef SLS_RECEIVER_INTERFACE_H #define SLS_RECEIVER_INTERFACE_H +#include "sls_detector_defs.h" #include "MySocketTCP.h" @@ -48,6 +49,15 @@ public: */ 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