mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-25 15:50:03 +02:00
modified receiver to save a simpler file name for sebastian, set receiver port modified
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@355 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
parent
2580c29886
commit
6a74fda3ed
@ -3454,153 +3454,164 @@ string slsDetector::getLastClientIP() {
|
||||
|
||||
|
||||
int slsDetector::setPort(portType index, int num){
|
||||
|
||||
|
||||
int fnum=F_SET_PORT;
|
||||
int retval;
|
||||
// uint64_t ut;
|
||||
char mess[100];
|
||||
int ret=FAIL;
|
||||
bool online=false;
|
||||
MySocketTCP *s;
|
||||
|
||||
if (num>1024) {
|
||||
int fnum=F_SET_PORT;
|
||||
int retval;
|
||||
// uint64_t ut;
|
||||
char mess[100];
|
||||
int ret=FAIL;
|
||||
bool online=false;
|
||||
MySocketTCP *s;
|
||||
|
||||
switch(index) {
|
||||
case CONTROL_PORT:
|
||||
s=controlSocket;
|
||||
retval=thisDetector->controlPort;
|
||||
if (num>1024) {
|
||||
|
||||
switch(index) {
|
||||
case CONTROL_PORT:
|
||||
s=controlSocket;
|
||||
retval=thisDetector->controlPort;
|
||||
#ifdef VERBOSE
|
||||
cout << "s="<< s<< endl;
|
||||
cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort << endl;
|
||||
cout << "s="<< s<< endl;
|
||||
cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort << endl;
|
||||
#endif
|
||||
if (s==NULL) {
|
||||
|
||||
if (s==NULL) {
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "s=NULL"<< endl;
|
||||
cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort << endl;
|
||||
cout << "s=NULL"<< endl;
|
||||
cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort << endl;
|
||||
#endif
|
||||
setTCPSocket("",DEFAULT_PORTNO);
|
||||
}
|
||||
if (controlSocket) {
|
||||
s=controlSocket;
|
||||
} else {
|
||||
setTCPSocket("",DEFAULT_PORTNO);
|
||||
}
|
||||
if (controlSocket) {
|
||||
s=controlSocket;
|
||||
} else {
|
||||
#ifdef VERBOSE
|
||||
cout << "still cannot connect!"<< endl;
|
||||
cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort << endl;
|
||||
cout << "still cannot connect!"<< endl;
|
||||
cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort << endl;
|
||||
#endif
|
||||
|
||||
|
||||
setTCPSocket("",retval);
|
||||
}
|
||||
online = (thisDetector->onlineFlag==ONLINE_FLAG);
|
||||
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;}
|
||||
//else {cout<<"datasocket has no value"<<endl; setReceiverTCPSocket("",retval);}
|
||||
}
|
||||
online = (thisDetector->receiverOnlineFlag==ONLINE_FLAG);
|
||||
cout<<"online:"<<online<<endl;
|
||||
break;
|
||||
case STOP_PORT:
|
||||
s=stopSocket;
|
||||
retval=thisDetector->stopPort;
|
||||
if (s==NULL) setTCPSocket("",-1,DEFAULT_PORTNO+1);
|
||||
if (stopSocket) s=stopSocket;
|
||||
else setTCPSocket("",-1,retval);
|
||||
online = (thisDetector->onlineFlag==ONLINE_FLAG);
|
||||
break;
|
||||
default:
|
||||
s=NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
setTCPSocket("",retval);
|
||||
}
|
||||
online = (thisDetector->onlineFlag==ONLINE_FLAG);
|
||||
break;
|
||||
case DATA_PORT:
|
||||
s=dataSocket;
|
||||
retval=thisDetector->receiverPort;
|
||||
if(strcmp(thisDetector->receiverIP,"none")){
|
||||
if (s==NULL) setReceiverTCPSocket("",DEFAULT_PORTNO+2);
|
||||
if (dataSocket) s=dataSocket;
|
||||
else setReceiverTCPSocket("",retval);
|
||||
online = (thisDetector->receiverOnlineFlag==ONLINE_FLAG);
|
||||
}
|
||||
break;
|
||||
case STOP_PORT:
|
||||
s=stopSocket;
|
||||
retval=thisDetector->stopPort;
|
||||
if (s==NULL) setTCPSocket("",-1,DEFAULT_PORTNO+1);
|
||||
if (stopSocket) s=stopSocket;
|
||||
else setTCPSocket("",-1,retval);
|
||||
online = (thisDetector->onlineFlag==ONLINE_FLAG);
|
||||
break;
|
||||
default:
|
||||
s=NULL;
|
||||
}
|
||||
//send to current port to change port
|
||||
if (online) {
|
||||
if (s) {
|
||||
if (s->Connect()>=0) {
|
||||
s->SendDataOnly(&fnum,sizeof(fnum));
|
||||
s->SendDataOnly(&index,sizeof(index));
|
||||
s->SendDataOnly(&num,sizeof(num));
|
||||
s->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret==FAIL) {
|
||||
s->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
} else {
|
||||
s->ReceiveDataOnly(&retval,sizeof(retval));
|
||||
}
|
||||
s->Disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (online) {
|
||||
if (s) {
|
||||
if (s->Connect()>=0) {
|
||||
s->SendDataOnly(&fnum,sizeof(fnum));
|
||||
s->SendDataOnly(&index,sizeof(index));
|
||||
s->SendDataOnly(&num,sizeof(num));
|
||||
s->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret==FAIL) {
|
||||
s->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
} else {
|
||||
s->ReceiveDataOnly(&retval,sizeof(retval));
|
||||
}
|
||||
s->Disconnect();
|
||||
if (ret!=FAIL) {
|
||||
switch(index) {
|
||||
case CONTROL_PORT:
|
||||
thisDetector->controlPort=retval;
|
||||
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);
|
||||
}
|
||||
break;
|
||||
case STOP_PORT:
|
||||
thisDetector->stopPort=retval;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
cout << "ret is ok" << endl;
|
||||
#endif
|
||||
|
||||
} else {
|
||||
switch(index) {
|
||||
case CONTROL_PORT:
|
||||
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);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case STOP_PORT:
|
||||
thisDetector->stopPort=num;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ret!=FAIL) {
|
||||
|
||||
switch(index) {
|
||||
case CONTROL_PORT:
|
||||
thisDetector->controlPort=retval;
|
||||
break;
|
||||
case DATA_PORT:
|
||||
thisDetector->receiverPort=retval;
|
||||
break;
|
||||
case STOP_PORT:
|
||||
thisDetector->stopPort=retval;
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
switch(index) {
|
||||
case CONTROL_PORT:
|
||||
retval=thisDetector->controlPort;
|
||||
break;
|
||||
case DATA_PORT:
|
||||
retval=thisDetector->receiverPort;
|
||||
break;
|
||||
case STOP_PORT:
|
||||
retval=thisDetector->stopPort;
|
||||
break;
|
||||
default:
|
||||
retval=-1;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "ret is ok" << endl;
|
||||
cout << thisDetector->controlPort<< " " << thisDetector->receiverPort << " " << thisDetector->stopPort << endl;
|
||||
#endif
|
||||
|
||||
} else {
|
||||
switch(index) {
|
||||
case CONTROL_PORT:
|
||||
thisDetector->controlPort=num;
|
||||
break;
|
||||
case DATA_PORT:
|
||||
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG)
|
||||
thisDetector->receiverPort=retval;
|
||||
else
|
||||
thisDetector->receiverPort=num;
|
||||
|
||||
break;
|
||||
case STOP_PORT:
|
||||
thisDetector->stopPort=num;
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch(index) {
|
||||
case CONTROL_PORT:
|
||||
retval=thisDetector->controlPort;
|
||||
break;
|
||||
case DATA_PORT:
|
||||
retval=thisDetector->receiverPort;
|
||||
break;
|
||||
case STOP_PORT:
|
||||
retval=thisDetector->stopPort;
|
||||
break;
|
||||
default:
|
||||
retval=-1;
|
||||
}
|
||||
|
||||
// setTCPSocket();
|
||||
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << thisDetector->controlPort<< " " << thisDetector->receiverPort << " " << thisDetector->stopPort << endl;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
return retval;
|
||||
|
||||
|
||||
return retval;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -15,16 +15,24 @@ int main(int argc, char *argv[])
|
||||
int ret = slsDetectorDefs::OK;
|
||||
MySocketTCP *socket = NULL;
|
||||
string fname = "";
|
||||
bool shortfname = false;
|
||||
|
||||
//parse command line for config
|
||||
for(int iarg=2;iarg<argc;iarg++)
|
||||
if(!strcasecmp(argv[iarg-1],"-config"))
|
||||
for(int iarg=1;iarg<argc;iarg++){
|
||||
if(!strcasecmp(argv[iarg],"-config")){
|
||||
if(iarg+1==argc){
|
||||
cout << "no config file name given. Exiting." << endl;
|
||||
return -1;
|
||||
}
|
||||
fname.assign(argv[iarg]);
|
||||
|
||||
}
|
||||
if(!strcasecmp(argv[iarg],"-shortfname"))
|
||||
shortfname = true;
|
||||
}
|
||||
|
||||
|
||||
//reads config file, creates socket, assigns function table
|
||||
slsReceiverFuncs *receiver = new slsReceiverFuncs(socket,fname,ret);
|
||||
slsReceiverFuncs *receiver = new slsReceiverFuncs(socket,fname,ret, shortfname);
|
||||
if(ret==slsDetectorDefs::FAIL)
|
||||
return -1;
|
||||
|
||||
|
@ -23,7 +23,8 @@ using namespace std;
|
||||
FILE* slsReceiverFunctionList::sfilefd(NULL);
|
||||
int slsReceiverFunctionList::listening_thread_running(0);
|
||||
|
||||
slsReceiverFunctionList::slsReceiverFunctionList():
|
||||
slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname):
|
||||
shortFileName(shortfname),
|
||||
fileIndex(0),
|
||||
frameIndexNeeded(true),
|
||||
framesCaught(0),
|
||||
@ -38,6 +39,7 @@ slsReceiverFunctionList::slsReceiverFunctionList():
|
||||
server_port(DEFAULT_UDP_PORT)
|
||||
{
|
||||
strcpy(savefilename,"");
|
||||
strcpy(actualfilename,"");
|
||||
strcpy(filePath,"");
|
||||
strcpy(fileName,"run");
|
||||
strcpy(buffer,"");
|
||||
@ -195,6 +197,10 @@ int slsReceiverFunctionList::startListening(){
|
||||
else
|
||||
sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,framesCaught,fileIndex);
|
||||
|
||||
if(!shortFileName)
|
||||
strcpy(actualfilename,savefilename);
|
||||
else
|
||||
sprintf(actualfilename, "%s/%s_%d_%012d.raw", filePath,fileName,fileIndex, framesCaught);
|
||||
|
||||
// A do/while(FALSE) loop is used to make error cleanup easier. The
|
||||
// close() of each of the socket descriptors is only done once at the
|
||||
@ -206,8 +212,8 @@ int slsReceiverFunctionList::startListening(){
|
||||
break;
|
||||
}
|
||||
|
||||
sfilefd = fopen((const char *) (savefilename), "w");
|
||||
cout << "Saving to " << savefilename << ". Ready! " << endl;
|
||||
sfilefd = fopen((const char *) (actualfilename), "w");
|
||||
cout << "Saving to " << actualfilename << ". Ready! " << endl;
|
||||
|
||||
while (listening_thread_running) {
|
||||
|
||||
@ -221,10 +227,15 @@ int slsReceiverFunctionList::startListening(){
|
||||
else
|
||||
sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,framesCaught,fileIndex);
|
||||
|
||||
cout << "saving to " << savefilename << "\t\t"
|
||||
if(!shortFileName)
|
||||
strcpy(actualfilename,savefilename);
|
||||
else
|
||||
sprintf(actualfilename, "%s/%s_%d_%012d.raw", filePath,fileName,fileIndex, framesCaught);
|
||||
|
||||
cout << "saving to " << actualfilename << "\t\t"
|
||||
"packet loss " << ((currframenum-prevframenum-(2*framesInFile))/(double)(2*framesInFile))*100.000 << "%\t\t"
|
||||
"framenum " << currframenum << endl;
|
||||
sfilefd = fopen((const char *) (savefilename), "w");
|
||||
sfilefd = fopen((const char *) (actualfilename), "w");
|
||||
prevframenum=currframenum;
|
||||
framesInFile = 0;
|
||||
}
|
||||
|
@ -21,8 +21,9 @@ class slsReceiverFunctionList : private virtual slsDetectorDefs {
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
* @param shortfname true if short file name required
|
||||
*/
|
||||
slsReceiverFunctionList();
|
||||
slsReceiverFunctionList(bool shortfname);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
@ -142,6 +143,12 @@ private:
|
||||
/** Complete File name */
|
||||
char savefilename[MAX_STR_LENGTH];
|
||||
|
||||
/** Actual Complete File name. This is used if you need a simple filename */
|
||||
char actualfilename[MAX_STR_LENGTH];
|
||||
|
||||
/** if short file name is needed*/
|
||||
bool shortFileName;
|
||||
|
||||
/** File Name without frame index, file index and extension*/
|
||||
char fileName[MAX_STR_LENGTH];
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
using namespace std;
|
||||
|
||||
|
||||
slsReceiverFuncs::slsReceiverFuncs(MySocketTCP *&mySocket,string const fname,int &success):
|
||||
slsReceiverFuncs::slsReceiverFuncs(MySocketTCP *&mySocket,string const fname,int &success, bool shortfname):
|
||||
socket(mySocket),
|
||||
ret(OK),
|
||||
lockStatus(0){
|
||||
@ -89,7 +89,7 @@ slsReceiverFuncs::slsReceiverFuncs(MySocketTCP *&mySocket,string const fname,int
|
||||
strcpy(mess,"dummy message");
|
||||
|
||||
function_table();
|
||||
slsReceiverList = new slsReceiverFunctionList();
|
||||
slsReceiverList = new slsReceiverFunctionList(shortfname);
|
||||
|
||||
success = OK;
|
||||
}
|
||||
|
@ -25,8 +25,9 @@ public:
|
||||
* @param mySocket tcp socket connecting receiver and client
|
||||
* @param fname name of config file
|
||||
* @param success if socket creation was successfull
|
||||
* @param shortfname true if short file name required
|
||||
*/
|
||||
slsReceiverFuncs(MySocketTCP *&mySocket,string const fname,int &success);
|
||||
slsReceiverFuncs(MySocketTCP *&mySocket,string const fname,int &success, bool shortfname);
|
||||
|
||||
/** Destructor */
|
||||
virtual ~slsReceiverFuncs(){};
|
||||
|
Loading…
x
Reference in New Issue
Block a user