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 GOODBYE -200
|
||||||
#define BUFFER_SIZE 1286*2
|
#define BUFFER_SIZE 1286*2
|
||||||
#define DATABYTES 2560
|
#define DATABYTES 2560
|
||||||
#define DEFAULT_UDP_PORT 50001
|
|
||||||
#define FIFO_SIZE 25000
|
#define FIFO_SIZE 25000
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,18 +41,26 @@ slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname):
|
|||||||
status(IDLE),
|
status(IDLE),
|
||||||
latestData(NULL),
|
latestData(NULL),
|
||||||
udpSocket(NULL),
|
udpSocket(NULL),
|
||||||
server_port(DEFAULT_UDP_PORT),
|
server_port(DEFAULT_UDP_PORTNO),
|
||||||
fifo(NULL)
|
fifo(NULL)
|
||||||
{
|
{
|
||||||
strcpy(savefilename,"");
|
strcpy(savefilename,"");
|
||||||
strcpy(actualfilename,"");
|
strcpy(actualfilename,"");
|
||||||
strcpy(filePath,"");
|
strcpy(filePath,"");
|
||||||
strcpy(fileName,"run");
|
strcpy(fileName,"run");
|
||||||
|
eth = new char[MAX_STR_LENGTH];
|
||||||
|
strcpy(eth,"");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void slsReceiverFunctionList::setEthernetInterface(char* c){
|
||||||
|
strcpy(eth,c);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int slsReceiverFunctionList::getFrameIndex(){
|
int slsReceiverFunctionList::getFrameIndex(){
|
||||||
if(startFrameIndex==-1)
|
if(startFrameIndex==-1)
|
||||||
frameIndex=0;
|
frameIndex=0;
|
||||||
@ -216,7 +224,11 @@ int slsReceiverFunctionList::startListening(){
|
|||||||
// very end of the program.
|
// very end of the program.
|
||||||
do {
|
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()){
|
if (udpSocket->getErrorStatus()){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -251,7 +263,7 @@ int slsReceiverFunctionList::startListening(){
|
|||||||
if(fifo->isFull())
|
if(fifo->isFull())
|
||||||
;//cout<<"**********************FIFO FULLLLLLLL************************"<<endl;
|
;//cout<<"**********************FIFO FULLLLLLLL************************"<<endl;
|
||||||
else{
|
else{
|
||||||
cout<<"read index:"<<(int)(*(int*)buffer)<<endl;
|
//cout<<"read index:"<<(int)(*(int*)buffer)<<endl;
|
||||||
dataReadFrame = new dataStruct;
|
dataReadFrame = new dataStruct;
|
||||||
dataReadFrame->buffer=buffer;
|
dataReadFrame->buffer=buffer;
|
||||||
dataReadFrame->rc=rc;
|
dataReadFrame->rc=rc;
|
||||||
|
@ -32,6 +32,16 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual ~slsReceiverFunctionList(){ if(latestData) delete latestData;};
|
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
|
* Returns status of receiver: idle, running or error
|
||||||
*/
|
*/
|
||||||
@ -228,14 +238,15 @@ private:
|
|||||||
/** Server UDP Port*/
|
/** Server UDP Port*/
|
||||||
int server_port;
|
int server_port;
|
||||||
|
|
||||||
|
/** ethernet interface or IP to listen to */
|
||||||
|
char *eth;
|
||||||
|
|
||||||
/** Element structure to put inside a fifo */
|
/** Element structure to put inside a fifo */
|
||||||
struct dataStruct {
|
struct dataStruct {
|
||||||
char* buffer;
|
char* buffer;
|
||||||
int rc;
|
int rc;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//dataStruct* dataReadFrame;
|
|
||||||
/** circular fifo to read and write data*/
|
/** circular fifo to read and write data*/
|
||||||
CircularFifo<dataStruct,FIFO_SIZE>* fifo;
|
CircularFifo<dataStruct,FIFO_SIZE>* fifo;
|
||||||
|
|
||||||
|
@ -114,24 +114,25 @@ int slsReceiverFuncs::function_table(){
|
|||||||
for (int i=0;i<numberOfFunctions;i++)
|
for (int i=0;i<numberOfFunctions;i++)
|
||||||
flist[i]=&slsReceiverFuncs::M_nofunc;
|
flist[i]=&slsReceiverFuncs::M_nofunc;
|
||||||
|
|
||||||
flist[F_SET_FILE_NAME] = &slsReceiverFuncs::set_file_name;
|
flist[F_SET_FILE_NAME] = &slsReceiverFuncs::set_file_name;
|
||||||
flist[F_SET_FILE_PATH] = &slsReceiverFuncs::set_file_dir;
|
flist[F_SET_FILE_PATH] = &slsReceiverFuncs::set_file_dir;
|
||||||
flist[F_SET_FILE_INDEX] = &slsReceiverFuncs::set_file_index;
|
flist[F_SET_FILE_INDEX] = &slsReceiverFuncs::set_file_index;
|
||||||
flist[F_START_RECEIVER] = &slsReceiverFuncs::start_receiver;
|
flist[F_SETUP_UDP] = &slsReceiverFuncs::setup_udp;
|
||||||
flist[F_STOP_RECEIVER] = &slsReceiverFuncs::stop_receiver;
|
flist[F_START_RECEIVER] = &slsReceiverFuncs::start_receiver;
|
||||||
flist[F_GET_RECEIVER_STATUS]= &slsReceiverFuncs::get_status;
|
flist[F_STOP_RECEIVER] = &slsReceiverFuncs::stop_receiver;
|
||||||
flist[F_GET_FRAMES_CAUGHT] = &slsReceiverFuncs::get_frames_caught;
|
flist[F_GET_RECEIVER_STATUS] = &slsReceiverFuncs::get_status;
|
||||||
flist[F_GET_FRAME_INDEX] = &slsReceiverFuncs::get_frame_index;
|
flist[F_GET_FRAMES_CAUGHT] = &slsReceiverFuncs::get_frames_caught;
|
||||||
flist[F_RESET_FRAMES_CAUGHT]= &slsReceiverFuncs::reset_frames_caught;
|
flist[F_GET_FRAME_INDEX] = &slsReceiverFuncs::get_frame_index;
|
||||||
flist[F_READ_FRAME] = &slsReceiverFuncs::read_frame;
|
flist[F_RESET_FRAMES_CAUGHT] = &slsReceiverFuncs::reset_frames_caught;
|
||||||
|
flist[F_READ_FRAME] = &slsReceiverFuncs::read_frame;
|
||||||
|
|
||||||
//General Functions
|
//General Functions
|
||||||
flist[F_LOCK_SERVER] = &slsReceiverFuncs::lock_receiver;
|
flist[F_LOCK_SERVER] = &slsReceiverFuncs::lock_receiver;
|
||||||
flist[F_SET_PORT] = &slsReceiverFuncs::set_port;
|
flist[F_SET_PORT] = &slsReceiverFuncs::set_port;
|
||||||
flist[F_GET_LAST_CLIENT_IP] = &slsReceiverFuncs::get_last_client_ip;
|
flist[F_GET_LAST_CLIENT_IP] = &slsReceiverFuncs::get_last_client_ip;
|
||||||
flist[F_UPDATE_CLIENT] = &slsReceiverFuncs::update_client;
|
flist[F_UPDATE_CLIENT] = &slsReceiverFuncs::update_client;
|
||||||
flist[F_EXIT_SERVER] = &slsReceiverFuncs::exit_server; //not implemented in client
|
flist[F_EXIT_SERVER] = &slsReceiverFuncs::exit_server; //not implemented in client
|
||||||
flist[F_EXEC_COMMAND] = &slsReceiverFuncs::exec_command; //not implemented in client
|
flist[F_EXEC_COMMAND] = &slsReceiverFuncs::exec_command; //not implemented in client
|
||||||
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
@ -329,8 +330,6 @@ int slsReceiverFuncs::set_file_dir() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int slsReceiverFuncs::set_file_index() {
|
int slsReceiverFuncs::set_file_index() {
|
||||||
ret=OK;
|
ret=OK;
|
||||||
int retval=-1;
|
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(){
|
int slsReceiverFuncs::start_receiver(){
|
||||||
ret=OK;
|
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");
|
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);
|
usleep(100000);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(count==20)
|
if(count==20){
|
||||||
cout << "same type: index:" << index << "\tindex2:" << index2 << endl;
|
cout << "same type: index:" << index << "\tindex2:" << index2 << endl;
|
||||||
|
/**send garbage with -1 index to try again*/
|
||||||
|
}
|
||||||
|
|
||||||
arg=((index - startIndex)/2)-1;
|
arg=((index - startIndex)/2)-1;
|
||||||
|
|
||||||
@ -649,7 +729,7 @@ int slsReceiverFuncs::read_frame(){
|
|||||||
cout << "fName:" << fName << endl;
|
cout << "fName:" << fName << endl;
|
||||||
cout << "index:" << arg << endl;
|
cout << "index:" << arg << endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}else cout<<"failed to start"<<endl;
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -50,6 +50,9 @@ public:
|
|||||||
/** Set File path */
|
/** Set File path */
|
||||||
int set_file_dir();
|
int set_file_dir();
|
||||||
|
|
||||||
|
/** Set up UDP Details */
|
||||||
|
int setup_udp();
|
||||||
|
|
||||||
/** Set File index */
|
/** Set File index */
|
||||||
int set_file_index();
|
int set_file_index();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user