diff --git a/slsDetectorSoftware/slsReceiver/receiver_defs.h b/slsDetectorSoftware/slsReceiver/receiver_defs.h index 67252144d..c54cd1119 100755 --- a/slsDetectorSoftware/slsReceiver/receiver_defs.h +++ b/slsDetectorSoftware/slsReceiver/receiver_defs.h @@ -8,7 +8,6 @@ #define GOODBYE -200 #define BUFFER_SIZE 1286*2 #define DATABYTES 2560 -#define DEFAULT_UDP_PORT 50001 #define FIFO_SIZE 25000 diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp index fb4f7bbbb..23e6f58a1 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp @@ -41,18 +41,26 @@ slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname): status(IDLE), latestData(NULL), udpSocket(NULL), - server_port(DEFAULT_UDP_PORT), + server_port(DEFAULT_UDP_PORTNO), fifo(NULL) { strcpy(savefilename,""); strcpy(actualfilename,""); strcpy(filePath,""); strcpy(fileName,"run"); + eth = new char[MAX_STR_LENGTH]; + strcpy(eth,""); } +void slsReceiverFunctionList::setEthernetInterface(char* c){ + strcpy(eth,c); +} + + + int slsReceiverFunctionList::getFrameIndex(){ if(startFrameIndex==-1) frameIndex=0; @@ -216,7 +224,11 @@ int slsReceiverFunctionList::startListening(){ // very end of the program. do { - udpSocket = new genericSocket(server_port,genericSocket::UDP); + if(!strlen(eth)){ + cout<<"error:eth is empty:"<getErrorStatus()){ break; } @@ -251,7 +263,7 @@ int slsReceiverFunctionList::startListening(){ if(fifo->isFull()) ;//cout<<"**********************FIFO FULLLLLLLL************************"<buffer=buffer; dataReadFrame->rc=rc; diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h index 1f006f69b..d23cae4fe 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h @@ -32,6 +32,16 @@ public: */ virtual ~slsReceiverFunctionList(){ if(latestData) delete latestData;}; + /** + * Set UDP Port Number + */ + void setUDPPortNo(int p){server_port = p;}; + + /** + * Set Ethernet Interface or IP to listen to + */ + void setEthernetInterface(char* c); + /** * Returns status of receiver: idle, running or error */ @@ -228,14 +238,15 @@ private: /** Server UDP Port*/ int server_port; + /** ethernet interface or IP to listen to */ + char *eth; + /** Element structure to put inside a fifo */ struct dataStruct { char* buffer; int rc; }; - - //dataStruct* dataReadFrame; /** circular fifo to read and write data*/ CircularFifo* fifo; diff --git a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp index 2e985b0ad..68051a290 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp @@ -114,24 +114,25 @@ int slsReceiverFuncs::function_table(){ for (int i=0;iReceiveDataOnly(args,sizeof(args)) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + ret = FAIL; + } +cout<<"args[0]:"<differentClients==1){//necessary??? + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + else if(slsReceiverList->getStatus()==RUNNING){ + ret = FAIL; + strcpy(mess,"cannot set up udp when receiver is running\n"); + } + else{ + //set up udp port + sscanf(args[1],"%d",&udpport); + slsReceiverList->setUDPPortNo(udpport); + + //setup udpip + //get ethernet interface or IP to listen to + temp = genericSocket::ipToName(args[0]); + if(temp=="none"){ + ret = FAIL; + strcpy(mess, "failed to get ethernet interface or IP to listen to\n"); + } + else{ + strcpy(eth,temp.c_str()); + cout<<"eth:"<setEthernetInterface(eth); + //get mac address from ethernet interface + temp = genericSocket::nameToMac(eth); + if(temp=="00:00:00:00:00:00"){ + ret = FAIL; + strcpy(mess,"failed to get mac adddress to listen to\n"); + } + else{ + strcpy(retval,temp.c_str()); + cout<<"mac:"<differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + socket->SendDataOnly(retval,MAX_STR_LENGTH); + + //return ok/fail + return ret; +} + + + + + + int slsReceiverFuncs::start_receiver(){ ret=OK; @@ -630,16 +711,15 @@ int slsReceiverFuncs::read_frame(){ } } -#ifdef VERBOSE strcpy(mess,"could not read frame due to more than 20 mismatched indices\n"); - cout << "same type: index:" << index << "\tindex2:" << index2 << endl;; -#endif usleep(100000); count++; } - if(count==20) + if(count==20){ cout << "same type: index:" << index << "\tindex2:" << index2 << endl; + /**send garbage with -1 index to try again*/ + } arg=((index - startIndex)/2)-1; @@ -649,7 +729,7 @@ int slsReceiverFuncs::read_frame(){ cout << "fName:" << fName << endl; cout << "index:" << arg << endl; #endif - } + }else cout<<"failed to start"<