mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-06 01:50:40 +02:00
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@370 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
parent
f20e40025b
commit
e4d477b53e
@ -8,7 +8,6 @@
|
||||
#define GOODBYE -200
|
||||
#define BUFFER_SIZE 1286*2
|
||||
#define DATABYTES 2560
|
||||
#define DEFAULT_UDP_PORT 50001
|
||||
#define FIFO_SIZE 25000
|
||||
|
||||
|
||||
|
@ -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:"<<eth<<endl;
|
||||
break;
|
||||
}
|
||||
udpSocket = new genericSocket(server_port,genericSocket::UDP,eth);
|
||||
if (udpSocket->getErrorStatus()){
|
||||
break;
|
||||
}
|
||||
@ -251,7 +263,7 @@ int slsReceiverFunctionList::startListening(){
|
||||
if(fifo->isFull())
|
||||
;//cout<<"**********************FIFO FULLLLLLLL************************"<<endl;
|
||||
else{
|
||||
cout<<"read index:"<<(int)(*(int*)buffer)<<endl;
|
||||
//cout<<"read index:"<<(int)(*(int*)buffer)<<endl;
|
||||
dataReadFrame = new dataStruct;
|
||||
dataReadFrame->buffer=buffer;
|
||||
dataReadFrame->rc=rc;
|
||||
|
@ -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<dataStruct,FIFO_SIZE>* fifo;
|
||||
|
||||
|
@ -117,6 +117,7 @@ int slsReceiverFuncs::function_table(){
|
||||
flist[F_SET_FILE_NAME] = &slsReceiverFuncs::set_file_name;
|
||||
flist[F_SET_FILE_PATH] = &slsReceiverFuncs::set_file_dir;
|
||||
flist[F_SET_FILE_INDEX] = &slsReceiverFuncs::set_file_index;
|
||||
flist[F_SETUP_UDP] = &slsReceiverFuncs::setup_udp;
|
||||
flist[F_START_RECEIVER] = &slsReceiverFuncs::start_receiver;
|
||||
flist[F_STOP_RECEIVER] = &slsReceiverFuncs::stop_receiver;
|
||||
flist[F_GET_RECEIVER_STATUS] = &slsReceiverFuncs::get_status;
|
||||
@ -329,8 +330,6 @@ int slsReceiverFuncs::set_file_dir() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int slsReceiverFuncs::set_file_index() {
|
||||
ret=OK;
|
||||
int retval=-1;
|
||||
@ -381,6 +380,88 @@ int slsReceiverFuncs::set_file_index() {
|
||||
|
||||
|
||||
|
||||
|
||||
int slsReceiverFuncs::setup_udp(){
|
||||
ret=OK;
|
||||
strcpy(mess,"could not set up udp connection");
|
||||
char retval[MAX_STR_LENGTH]="";
|
||||
char args[2][MAX_STR_LENGTH];
|
||||
|
||||
string temp;
|
||||
int udpport;
|
||||
char eth[MAX_STR_LENGTH];
|
||||
|
||||
|
||||
// receive arguments
|
||||
|
||||
if(socket->ReceiveDataOnly(args,sizeof(args)) < 0 ){
|
||||
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) {
|
||||
if (lockStatus==1 && socket->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:"<<eth<<endl;
|
||||
slsReceiverList->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:"<<retval<<endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if(ret==OK && socket->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"<<endl;
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -50,6 +50,9 @@ public:
|
||||
/** Set File path */
|
||||
int set_file_dir();
|
||||
|
||||
/** Set up UDP Details */
|
||||
int setup_udp();
|
||||
|
||||
/** Set File index */
|
||||
int set_file_index();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user