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
This commit is contained in:
l_maliakal_d 2012-12-10 13:58:47 +00:00
parent 9d9d00cdc7
commit f74ea5191d
9 changed files with 104 additions and 47 deletions

View File

@ -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 */

View File

@ -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,

View File

@ -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();

View File

@ -32,7 +32,6 @@
#define ALLFIFO 0xffff
#define ADCSYNC_VAL 0x32214
#define TOKEN_RESTART_DELAY 0x88000000
#define TOKEN_RESTART_DELAY_ROI 0x1b000000

View File

@ -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,10 +2784,11 @@ 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
@ -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);

View File

@ -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:"<<arg[1]<<"."<<std::endl;
#endif
#ifdef VERBOSE
std::cout<<"receiver udp port:"<<arg[2]<<"."<<std::endl;
#endif
//converting server MACaddress to hex.
sword.assign(arg[2]);
strcpy(arg[2],"");
sword.assign(arg[3]);
strcpy(arg[3],"");
stringstream ssstr(sword);
while(getline(ssstr,sword,':'))
strcat(arg[2],sword.c_str());
strcat(arg[3],sword.c_str());
#ifdef VERBOSE
std::cout<<"detecotor mac:"<<arg[2]<<"."<<std::endl;
std::cout<<"detecotor mac:"<<arg[3]<<"."<<std::endl;
#endif
//converting IPaddress to hex.
strcpy(cword,"");
pcword = strtok (arg[4],".");
while (pcword != NULL) {
sprintf(arg[4],"%02x",atoi(pcword));
strcat(cword,arg[4]);
pcword = strtok (NULL, ".");
}
strcpy(arg[4],cword);
#ifdef VERBOSE
std::cout<<"receiver udp port:"<<arg[3]<<"."<<std::endl;
std::cout<<"detector ip:"<<arg[4]<<"."<<std::endl;
#endif
//send to server
@ -5090,13 +5124,14 @@ int slsDetector::writeConfigurationFile(ofstream &outfile, int id){
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;
names[11]="detectorip";
names[12]= "rx_tcpport";
names[13]= "rx_udpport";
names[14]="rx_hostname";
names[15]="rx_udpip";
names[16]="outdir";
names[17]="vhighvoltage";
nvar=18;
}

View File

@ -242,6 +242,8 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
char receiverUDPMAC[MAX_STR_LENGTH];
/** mac address of the detector **/
char detectorMAC[MAX_STR_LENGTH];
/** ip address of the detector **/
char detectorIP[MAX_STR_LENGTH];
/** online flag - is set if the receiver is connected, unset if socket connection is not possible */
int receiverOnlineFlag;
@ -1618,6 +1620,8 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
/** returns the detector MAC address\sa sharedSlsDetector */
char* getDetectorMAC() {return thisDetector->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 */

View File

@ -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") {
@ -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;

View File

@ -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++;