mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-20 08:38:00 +02:00
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:
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user