From f74ea5191d9f47e16deb16b63b813ec4397986d6 Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Mon, 10 Dec 2012 13:58:47 +0000 Subject: [PATCH] included detector ip and detector mac defaults in client, which can be specified in config file git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@374 951219d9-93cf-4727-9268-0efd64621fa3 --- .../commonFiles/sls_detector_defs.h | 5 ++ .../gotthardDetectorServer/firmware_funcs.c | 18 ++--- .../gotthardDetectorServer/firmware_funcs.h | 2 +- .../gotthardDetectorServer/server_defs.h | 1 - .../gotthardDetectorServer/server_funcs.c | 26 ++++--- .../slsDetector/slsDetector.cpp | 73 ++++++++++++++----- slsDetectorSoftware/slsDetector/slsDetector.h | 8 +- .../slsDetector/slsDetectorCommand.cpp | 10 ++- .../slsReceiver/slsReceiver_funcs.cpp | 8 +- 9 files changed, 104 insertions(+), 47 deletions(-) diff --git a/slsDetectorSoftware/commonFiles/sls_detector_defs.h b/slsDetectorSoftware/commonFiles/sls_detector_defs.h index 895bc6fe4..f8ed667b9 100755 --- a/slsDetectorSoftware/commonFiles/sls_detector_defs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_defs.h @@ -31,6 +31,10 @@ typedef int dacs_t; #else typedef float dacs_t; #endif + +#define DEFAULT_DET_MAC "00:aa:bb:cc:dd:ee" +#define DEFAULT_DET_IP "129.129.202.46" + /** \file sls_detector_defs.h This file contains all the basic definitions common to the slsDetector class @@ -175,6 +179,7 @@ enum detectorType { enum networkParameter { DETECTOR_MAC, /**< detector MAC */ + DETECTOR_IP, /**< detector IP */ RECEIVER_HOSTNAME, /**< receiver IP/hostname */ RECEIVER_UDP_IP, /**< receiever UDP IP */ RECEIVER_UDP_PORT /**< receiever UDP Port */ diff --git a/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c b/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c index e74f1affa..94d03cd0d 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c +++ b/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c @@ -1258,7 +1258,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 udpport){ +int configureMAC(int ipad,long long int macad,long long int detectormacad, int detipad, int ival, int adc,int udpport){ //setting daqregister setDAQRegister(adc); //setting adc mask @@ -1361,12 +1361,12 @@ int configureMAC(int ipad,long long int macad,long long int servermacad,int ival mac_conf_regs->mac.mac_src_mac5 = 0xDD; mac_conf_regs->mac.mac_src_mac6 = 0xEE; */ - mac_conf_regs->mac.mac_src_mac1 =((servermacad>>(8*5))&0xFF); - mac_conf_regs->mac.mac_src_mac2 =((servermacad>>(8*4))&0xFF); - mac_conf_regs->mac.mac_src_mac3 =((servermacad>>(8*3))&0xFF); - mac_conf_regs->mac.mac_src_mac4 =((servermacad>>(8*2))&0xFF); - mac_conf_regs->mac.mac_src_mac5 =((servermacad>>(8*1))&0xFF); - mac_conf_regs->mac.mac_src_mac6 =((servermacad>>(8*0))&0xFF); + mac_conf_regs->mac.mac_src_mac1 =((detectormacad>>(8*5))&0xFF); + mac_conf_regs->mac.mac_src_mac2 =((detectormacad>>(8*4))&0xFF); + mac_conf_regs->mac.mac_src_mac3 =((detectormacad>>(8*3))&0xFF); + mac_conf_regs->mac.mac_src_mac4 =((detectormacad>>(8*2))&0xFF); + mac_conf_regs->mac.mac_src_mac5 =((detectormacad>>(8*1))&0xFF); + mac_conf_regs->mac.mac_src_mac6 =((detectormacad>>(8*0))&0xFF); mac_conf_regs->mac.mac_ether_type = 0x0800; //ipv4 @@ -1380,7 +1380,7 @@ int configureMAC(int ipad,long long int macad,long long int servermacad,int ival mac_conf_regs->ip.ip_ttl = 0x70; mac_conf_regs->ip.ip_protocol = 0x11; mac_conf_regs->ip.ip_chksum = 0x0000 ; //6E42 now is automatically computed - mac_conf_regs->ip.ip_sourceip = 0x8181CA2E; + mac_conf_regs->ip.ip_sourceip = detipad; //0x8181CA2E;129.129.202.46 mac_conf_regs->ip.ip_destip = ipad; //CA57 #ifdef VERBOSE @@ -1393,7 +1393,7 @@ int configureMAC(int ipad,long long int macad,long long int servermacad,int ival mac_conf_regs->mac.mac_dest_mac5, mac_conf_regs->mac.mac_dest_mac6); printf("mac_src:%llx %x:%x:%x:%x:%x:%x\n", - servermacad, + detectormacad, mac_conf_regs->mac.mac_src_mac1, mac_conf_regs->mac.mac_src_mac2, mac_conf_regs->mac.mac_src_mac3, diff --git a/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.h b/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.h index bb5e99689..f89e77b20 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 udpport); +int configureMAC(int ipad, long long int macad, long long int detectormacadd, int detipad, int ival, int adc,int udpport); u_int64_t getDetectorNumber(); u_int32_t getFirmwareVersion(); diff --git a/slsDetectorSoftware/gotthardDetectorServer/server_defs.h b/slsDetectorSoftware/gotthardDetectorServer/server_defs.h index 06b18f8b4..b57a20831 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/server_defs.h +++ b/slsDetectorSoftware/gotthardDetectorServer/server_defs.h @@ -32,7 +32,6 @@ #define ALLFIFO 0xffff - #define ADCSYNC_VAL 0x32214 #define TOKEN_RESTART_DELAY 0x88000000 #define TOKEN_RESTART_DELAY_ROI 0x1b000000 diff --git a/slsDetectorSoftware/gotthardDetectorServer/server_funcs.c b/slsDetectorSoftware/gotthardDetectorServer/server_funcs.c index 7a6d89319..4fdedb32e 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/server_funcs.c +++ b/slsDetectorSoftware/gotthardDetectorServer/server_funcs.c @@ -2750,14 +2750,15 @@ int update_client(int file_des) { int configure_mac(int file_des) { int ret=OK; - char arg[4][50]; + char arg[5][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; + long long int idetectormacadd; int udpport; + int detipad; int adc=-1; sprintf(mess,"Can't configure MAC\n"); @@ -2769,10 +2770,12 @@ int configure_mac(int file_des) { ret=FAIL; } - sscanf(arg[0], "%x", &ipad); - sscanf(arg[1], "%llx", &imacadd); - sscanf(arg[2], "%llx", &iservermacadd); - sscanf(arg[3], "%x", &udpport); + sscanf(arg[0], "%x", &ipad); + sscanf(arg[1], "%llx", &imacadd); + sscanf(arg[2], "%x", &udpport); + sscanf(arg[3], "%llx", &idetectormacadd); + sscanf(arg[4], "%x", &detipad); + #ifdef VERBOSE int i; printf("\ndigital_test_bit in server %d\t",digitalTestBit); @@ -2781,12 +2784,13 @@ int configure_mac(int file_des) { printf("macad:%llx\n",imacadd); for (i=0;i<6;i++) printf("mac adress %d is 0x%x \n",6-i,(unsigned int)(((imacadd>>(8*i))&0xFF))); - 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("detector macad:%llx\n",idetectormacadd); + for (i=0;i<6;i++) + printf("detector mac adress %d is 0x%x \n",6-i,(unsigned int)(((idetectormacadd>>(8*i))&0xFF))); + printf("detipad %x\n",detipad); printf("\n"); -#endif +#endif n = receiveDataOnly(file_des,&adc,sizeof(adc)); if (n < 0) { @@ -2805,7 +2809,7 @@ int configure_mac(int file_des) { //#endif #ifdef MCB_FUNCS if (ret==OK) - configureMAC(ipad,imacadd,iservermacadd,digitalTestBit,adc,udpport); + configureMAC(ipad,imacadd,idetectormacadd,detipad,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 75b7e8b75..12f9fa56e 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -461,8 +461,10 @@ int slsDetector::initializeDetectorSize(detectorType type) { strcpy(thisDetector->receiver_hostname,"none"); /** set receiver udp ip address */ strcpy(thisDetector->receiverUDPIP,"none"); - /** set server mac address */ - strcpy(thisDetector->detectorMAC,"00:aa:bb:cc:dd:ee"); + /** set detector mac address */ + strcpy(thisDetector->detectorMAC,DEFAULT_DET_MAC); + /** set detector ip address */ + strcpy(thisDetector->detectorIP,DEFAULT_DET_IP); /** sets onlineFlag to OFFLINE_FLAG */ thisDetector->onlineFlag=OFFLINE_FLAG; @@ -4445,6 +4447,8 @@ char* slsDetector::setNetworkParameter(networkParameter index, string value) { switch (index) { case DETECTOR_MAC: return setDetectorMAC(value); + case DETECTOR_IP: + return setDetectorIP(value); case RECEIVER_HOSTNAME: return setReceiver(value); case RECEIVER_UDP_IP: @@ -4467,6 +4471,9 @@ char* slsDetector::getNetworkParameter(networkParameter index) { case DETECTOR_MAC: return getDetectorMAC(); break; + case DETECTOR_IP: + return getDetectorIP(); + break; case RECEIVER_HOSTNAME: return getReceiver(); break; @@ -4501,6 +4508,21 @@ char* slsDetector::setDetectorMAC(string detectorMAC){ +char* slsDetector::setDetectorIP(string detectorIP){ + struct sockaddr_in sa; + //taking function arguments into consideration + if(detectorIP.length()){ + if(detectorIP.length()<16){ + int result = inet_pton(AF_INET, detectorIP.c_str(), &(sa.sin_addr)); + if(result!=0) + strcpy(thisDetector->detectorIP,detectorIP.c_str()); + else + return ("Detector IP Address should be VALID and in xxx.xxx.xxx.xxx format"); + } + } + return thisDetector->detectorIP; +} + char* slsDetector::setReceiver(string receiverIP){ @@ -4617,7 +4639,7 @@ int slsDetector::configureMAC(int adc){ int ret=FAIL; int fnum=F_CONFIGURE_MAC; char mess[100]; - char arg[4][50]; + char arg[5][50]; char cword[50]="", *pcword; string sword; @@ -4639,16 +4661,16 @@ int slsDetector::configureMAC(int adc){ } strcpy(arg[0],thisDetector->receiverUDPIP); strcpy(arg[1],thisDetector->receiverUDPMAC); - strcpy(arg[2],thisDetector->detectorMAC); - sprintf(arg[3],"%x",thisDetector->receiverUDPPort); - + sprintf(arg[2],"%x",thisDetector->receiverUDPPort); + strcpy(arg[3],thisDetector->detectorMAC); + strcpy(arg[4],thisDetector->detectorIP); #ifdef VERBOSE std::cout<< "Configuring MAC with adc:"<< adc << std::endl; #endif - for(i=0;i<3;i++){ + for(i=0;i<2;i++){ if(!strcmp(arg[i],"none")){ std::cout<< "Configure MAC Error. IP/MAC Addresses not set"<< std::endl; return FAIL; @@ -4678,18 +4700,30 @@ int slsDetector::configureMAC(int adc){ strcat(arg[1],sword.c_str()); #ifdef VERBOSE std::cout<<"receiver mac:"<detectorMAC;}; + /** returns the detector IP address\sa sharedSlsDetector */ + char* getDetectorIP() {return thisDetector->detectorIP;}; /** returns the receiver IP address \sa sharedSlsDetector */ char* getReceiver() {return thisDetector->receiver_hostname;}; /** returns the receiver UDP IP address \sa sharedSlsDetector */ @@ -1626,7 +1630,9 @@ class slsDetector : public slsDetectorUtils, public energyConversion { 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); + char* setDetectorMAC(string detectorMAC); + /** validates the format of detector IP address and sets it \sa sharedSlsDetector */ + char* setDetectorIP(string detectorIP); /** validates and sets the receiver IP address/hostname \sa sharedSlsDetector */ char* setReceiver(string receiver); /** validates the format of receiver udp ip and sets it \sa sharedSlsDetector */ diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index a7e28f598..bdafdcf61 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -337,6 +337,10 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter; i++; + descrToFuncMap[i].m_pFuncName="detectorip"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdNetworkParameter; + i++; + descrToFuncMap[i].m_pFuncName="configuremac"; // descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdConfigureMac; i++; @@ -2226,6 +2230,8 @@ string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int actio if (cmd=="detectormac") { t=DETECTOR_MAC; + } else if (cmd=="detectorip") { + t=DETECTOR_IP; } else if (cmd=="rx_hostname") { t=RECEIVER_HOSTNAME; } else if (cmd=="rx_udpip") { @@ -2235,7 +2241,7 @@ string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int actio if (!(sscanf(args[1],"%d",&i))) return ("cannot parse argument") + string(args[1]); } else return ("unknown network parameter")+cmd; - + if (action==PUT_ACTION) myDet->setNetworkParameter(t, args[1]); @@ -2250,12 +2256,14 @@ string slsDetectorCommand::helpNetworkParameter(int narg, char *args[], int acti ostringstream os; if (action==PUT_ACTION || action==HELP_ACTION) { os << "detectormac mac \n sets detector mac to mac"<< std::endl; + os << "detectorip ip \n sets detector ip to ip"<< 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 << "detectormac \n gets detector mac "<< std::endl; + os << "detectorip \n gets detector ip "<< 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; diff --git a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp index 3e8f72903..640839f74 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp @@ -691,14 +691,14 @@ int slsReceiverFuncs::read_frame(){ //1 odd, 1 even - /*if((index%2)!=index2%2){ + if((index%2)!=index2%2){ //ideal situation (should be odd, even(index+1)) - if(index%2){*/ + if(index%2){ memcpy(retval,((char*) origVal)+2, onedatasize); memcpy((((char*)retval)+onedatasize), ((char*) origVal)+8+onedatasize, onedatasize); ret=OK; break; - /*} + } //swap to even,odd if(index2%2){ @@ -709,7 +709,7 @@ int slsReceiverFuncs::read_frame(){ break; } - }*/ + } strcpy(mess,"could not read frame due to more than 20 mismatched indices\n"); usleep(100000); count++;