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
This commit is contained in:
l_maliakal_d 2012-12-06 14:27:52 +00:00
parent e4d477b53e
commit ac2c4211e2
11 changed files with 294 additions and 173 deletions

View File

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

View File

@ -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, /**<stop port */
DATA_PORT /**< data port */
DATA_PORT /**< receiver tcp port with client*/
};
/** hierarchy in multi-detector structure, if any */

View File

@ -124,7 +124,9 @@ enum {
F_GET_FRAME_INDEX, /**< gets the frame index */
F_RESET_FRAMES_CAUGHT /**< resets the frames caught */
F_RESET_FRAMES_CAUGHT, /**< resets the frames caught */
F_SETUP_UDP /**< sets the receiver udp connection and returns receiver mac address */
/* Always append functions hereafter!!! */

View File

@ -1129,11 +1129,11 @@ int setDACRegister(int idac, int val, int imod) {
int getTemperature(int tempSensor, int imod){
int val;
char cTempSensor[2][100]={"ADCs/ASICs","VRs/FPGAs"};
imod=0;//ignoring more than 1 mod for now
int i,j,repeats=6;
u_int32_t tempVal=0;
#ifdef VERBOSE
char cTempSensor[2][100]={"ADCs/ASICs","VRs/FPGAs"};
printf("Getting Temperature of module:%d for the %s for tempsensor:%d\n",imod,cTempSensor[tempSensor],tempSensor);
#endif
bus_w(TEMP_IN_REG,(T1_CLK_BIT)|(T1_CS_BIT)|(T2_CLK_BIT)|(T2_CS_BIT));//standby
@ -1250,7 +1250,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 configureMAC(int ipad,long long int macad,long long int servermacad,int ival, int adc,int udpport){
//setting daqregister
setDAQRegister(adc);
//setting adc mask
@ -1409,7 +1409,7 @@ int configureMAC(int ipad,long long int macad,long long int servermacad,int ival
//#endif
mac_conf_regs->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));

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

View File

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

View File

@ -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"<<endl;setReceiverTCPSocket("",retval);}
if (dataSocket){cout<<"datasocket now has value"<<endl; s=dataSocket;}
retval=thisDetector->receiverTCPPort;
if(strcmp(thisDetector->receiver_hostname,"none")){
if (s==NULL) setReceiverTCPSocket("",retval);
if (dataSocket)s=dataSocket;
//else {cout<<"datasocket has no value"<<endl; setReceiverTCPSocket("",retval);}
}
online = (thisDetector->receiverOnlineFlag==ONLINE_FLAG);
cout<<"online:"<<online<<endl;
break;
case STOP_PORT:
s=stopSocket;
@ -3548,11 +3550,9 @@ int slsDetector::setPort(portType index, int num){
break;
case DATA_PORT:
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
cout<<"online,ret=ok"<<endl;
thisDetector->receiverPort=retval;
cout<<"first trying to set online:"<<setReceiverOnline(ONLINE_FLAG)<<endl;
cout<<"Setting up Receiver"<<endl;
setReceiverIP(thisDetector->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"<<endl;
thisDetector->receiverPort=retval;
}else{
cout<<"not online,ret=fail"<<endl;
thisDetector->receiverPort=num;
if(strcmp(thisDetector->receiverIP,"none")){
cout<<"ip not none, Setting up Receiver"<<endl;
setReceiverIP(thisDetector->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:"<<arg[0]<<"."<<std::endl;
std::cout<<"receiver udp ip:"<<arg[0]<<"."<<std::endl;
#endif
//converting MACaddress to hex.
sword.assign(arg[1]);
@ -4601,8 +4663,12 @@ int slsDetector::configureMAC(int adc){
while(getline(ssstr,sword,':'))
strcat(arg[2],sword.c_str());
#ifdef VERBOSE
std::cout<<"server mac:"<<arg[2]<<"."<<std::endl;
std::cout<<"detecotor mac:"<<arg[2]<<"."<<std::endl;
#endif
#ifdef VERBOSE
std::cout<<"receiver udp port:"<<arg[3]<<"."<<std::endl;
#endif
//send to server
if (thisDetector->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) {

View File

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

View File

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

View File

@ -1,5 +1,4 @@
#include "receiverInterface.h"
#include "sls_detector_defs.h"
#include <sys/types.h>
@ -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] = "";

View File

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