now u can use receiver hostname instead of only ip, got rid of acqtest, separated udpip and port from setudpconnection

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@372 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
l_maliakal_d 2012-12-07 15:51:03 +00:00
parent ac2c4211e2
commit 9341a2875a
6 changed files with 109 additions and 109 deletions

View File

@ -4439,6 +4439,8 @@ int slsDetector::exitServer(){
char* slsDetector::setNetworkParameter(networkParameter index, string value) {
char* answer;
int i;
switch (index) {
case DETECTOR_MAC:
@ -4446,17 +4448,19 @@ char* slsDetector::setNetworkParameter(networkParameter index, string value) {
case RECEIVER_HOSTNAME:
return setReceiver(value);
case RECEIVER_UDP_IP:
setUDPConnection(value,"");
return getReceiverUDPIP();
return setReceiverUDPIP(value);
case RECEIVER_UDP_PORT:
setUDPConnection("",value);
return getReceiverUDPPort();
sscanf(value.c_str(),"%d",&i);
sprintf(answer,"%d",setReceiverUDPPort(i));
return answer;
default:
return ("unknown network parameter");
}
}
char* slsDetector::getNetworkParameter(networkParameter index) {
switch (index) {
@ -4481,39 +4485,6 @@ char* slsDetector::getNetworkParameter(networkParameter index) {
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){
strcpy(thisDetector->receiver_hostname,receiverIP.c_str());
wrongFormat=0;
}
}
if(wrongFormat)
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());
setUDPConnection("","");
}else
std::cout << "cannot connect to receiver" << endl;
}
return thisDetector->receiver_hostname;
}
char* slsDetector::setDetectorMAC(string detectorMAC){
if(detectorMAC.length()==17){
if((detectorMAC[2]==':')&&(detectorMAC[5]==':')&&(detectorMAC[8]==':')&&
@ -4530,35 +4501,77 @@ char* slsDetector::setDetectorMAC(string 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]="";
char* slsDetector::setReceiver(string receiverIP){
strcpy(thisDetector->receiver_hostname,receiverIP.c_str());
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
setFilePath(fileIO::getFilePath());
setFileName(fileIO::getFileName());
setFileIndex(fileIO::getFileIndex());
setUDPConnection();
}else
std::cout << "cannot connect to receiver" << endl;
return thisDetector->receiver_hostname;
}
char* slsDetector::setReceiverUDPIP(string udpip){
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
//taking function arguments into consideration
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
return ("Receiver UDP IP Address should be VALID and in xxx.xxx.xxx.xxx format");
}
}
return thisDetector->receiverUDPIP;
}
int slsDetector::setReceiverUDPPort(int udpport){
thisDetector->receiverUDPPort = udpport;
return thisDetector->receiverUDPPort;
}
int slsDetector::setUDPConnection(){
int ret = FAIL;
int fnum = F_SETUP_UDP;
char args[2][MAX_STR_LENGTH];
char retval[MAX_STR_LENGTH]="";
//if no udp ip given, use hostname
if(!strcmp(thisDetector->receiverUDPIP,"none")){
//hostname is an ip address
if(strchr(thisDetector->receiver_hostname,'.')!=NULL)
strcpy(thisDetector->receiverUDPIP,thisDetector->receiver_hostname);
//if hostname not ip, convert it to ip
else{
std::cout<< "Receiver UDP IP Address should be VALID and in xxx.xxx.xxx.xxx format" << endl;
struct hostent *he = gethostbyname(thisDetector->receiver_hostname);
if (he == NULL){
std::cout << "no rx_udpip given and could not convert receiver hostname to ip" << endl;
return FAIL;
}else
strcpy(thisDetector->receiverUDPIP,inet_ntoa(*(struct in_addr*)he->h_addr));
}
}
}
if(udpport.length())
sscanf(udpport.c_str(),"%d",&thisDetector->receiverUDPPort);
//copy arguments to args[][]
@ -4567,7 +4580,6 @@ int slsDetector::setUDPConnection(string udpip, string udpport){
//set up receiver for UDP Connection and get receivermac address
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
#ifdef VERBOSE
@ -4580,9 +4592,6 @@ int slsDetector::setUDPConnection(string udpip, string udpport){
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){
@ -4611,9 +4620,23 @@ int slsDetector::configureMAC(int adc){
char arg[4][50];
char cword[50]="", *pcword;
string sword;
//if udpip wasnt initialized in config file
if(!(strcmp(thisDetector->receiverUDPIP,"none")))
if(!(strcmp(thisDetector->receiverUDPIP,"none"))){
//hostname is an ip address
if(strchr(thisDetector->receiver_hostname,'.')!=NULL)
strcpy(thisDetector->receiverUDPIP,thisDetector->receiver_hostname);
//if hostname not ip, convert it to ip
else{
struct hostent *he = gethostbyname(thisDetector->receiver_hostname);
if (he != NULL)
strcpy(thisDetector->receiverUDPIP,inet_ntoa(*(struct in_addr*)he->h_addr));
else{
std::cout << "no rx_udpip given and invalid receiver hostname" << endl;
return FAIL;
}
}
}
strcpy(arg[0],thisDetector->receiverUDPIP);
strcpy(arg[1],thisDetector->receiverUDPMAC);
strcpy(arg[2],thisDetector->detectorMAC);

View File

@ -1629,9 +1629,13 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
char* setDetectorMAC(string serverMAC);
/** 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 */
char* setReceiverUDPIP(string udpip);
/** sets the receiver udp port \sa sharedSlsDetector */
int setReceiverUDPPort(int udpport);
/** Gets MAC from receiver and sets up UDP Connection */
int setUDPConnection(string udpip, string udpport);
int setUDPConnection();
};

View File

@ -431,10 +431,6 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDigiTest;
i++;
descrToFuncMap[i].m_pFuncName="acqtest"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDigiTest;
i++;
descrToFuncMap[i].m_pFuncName="reg"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdRegister;
i++;
@ -2232,10 +2228,10 @@ string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int actio
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;
} else if (cmd=="rx_udpport") {
t=RECEIVER_UDP_PORT;
if (!(sscanf(args[1],"%d",&i)))
return ("cannot parse argument") + string(args[1]);
} else return ("unknown network parameter")+cmd;
@ -2814,20 +2810,6 @@ string slsDetectorCommand::cmdDigiTest(int narg, char *args[], int action) {
return string("undefined number");
}
if (cmd=="acqtest") {
if (action==GET_ACTION)
return string("cannot get ")+cmd;
int ival=-1;
if (sscanf(args[1],"%d",&ival)) {
if(ival<1)
return helpDigiTest(narg, args, action);
else {
sprintf(answer,"%x",myDet->testFunction(ival));
return string(answer);
}
} else
return string("undefined number");
}
return string("unknown digital test mode ")+cmd;
@ -2842,8 +2824,7 @@ string slsDetectorCommand::helpDigiTest(int narg, char *args[], int action) {
os << "bustest \t performs test of the bus interface between FPGA and embedded Linux system. Can last up to a few minutes."<< std::endl;
}
if (action==PUT_ACTION || action==HELP_ACTION) {
os << "digibittest i\t sets a variable in the server to be used in configuremac function. i sets/clears the digital test bit."<< std::endl;
os << "acqtest i\t runs start acquisition i number of times."<< std::endl;
os << "digibittest i\t will perform test which will plot the unique channel identifier, instead of data."<< std::endl;
}
return os.str();
}

View File

@ -612,11 +612,6 @@ void slsDetectorUtils::incrementProgress(int i) {
int slsDetectorUtils::testFunction(int times) {
return 0;
}
int slsDetectorUtils::retrieveDetectorSetup(string const fname1, int level){

View File

@ -443,8 +443,6 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
/** temporary test fucntion */
int testFunction(int times=0);
/**
write register
\param addr address

View File

@ -398,8 +398,7 @@ int slsReceiverFuncs::setup_udp(){
strcpy(mess,"Error reading from socket\n");
ret = FAIL;
}
cout<<"args[0]:"<<args[0]<<endl;
cout<<"args[1]:"<<args[1]<<endl;
// execute action if the arguments correctly arrived
#ifdef SLS_RECEIVER_FUNCTION_LIST
if (ret==OK) {
@ -692,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){
@ -710,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++;