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 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) {
|
if (num>1024) {
|
||||||
case CONTROL_PORT:
|
|
||||||
s=controlSocket;
|
switch(index) {
|
||||||
retval=thisDetector->controlPort;
|
case CONTROL_PORT:
|
||||||
|
s=controlSocket;
|
||||||
|
retval=thisDetector->controlPort;
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "s="<< s<< endl;
|
cout << "s="<< s<< endl;
|
||||||
cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort << endl;
|
cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort << endl;
|
||||||
#endif
|
#endif
|
||||||
if (s==NULL) {
|
if (s==NULL) {
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "s=NULL"<< endl;
|
cout << "s=NULL"<< endl;
|
||||||
cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort << endl;
|
cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort << endl;
|
||||||
#endif
|
#endif
|
||||||
setTCPSocket("",DEFAULT_PORTNO);
|
setTCPSocket("",DEFAULT_PORTNO);
|
||||||
}
|
}
|
||||||
if (controlSocket) {
|
if (controlSocket) {
|
||||||
s=controlSocket;
|
s=controlSocket;
|
||||||
} else {
|
} else {
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "still cannot connect!"<< endl;
|
cout << "still cannot connect!"<< endl;
|
||||||
cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort << endl;
|
cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort << endl;
|
||||||
#endif
|
#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);
|
//send to current port to change port
|
||||||
}
|
if (online) {
|
||||||
online = (thisDetector->onlineFlag==ONLINE_FLAG);
|
if (s) {
|
||||||
break;
|
if (s->Connect()>=0) {
|
||||||
case DATA_PORT:
|
s->SendDataOnly(&fnum,sizeof(fnum));
|
||||||
s=dataSocket;
|
s->SendDataOnly(&index,sizeof(index));
|
||||||
retval=thisDetector->receiverPort;
|
s->SendDataOnly(&num,sizeof(num));
|
||||||
if(strcmp(thisDetector->receiverIP,"none")){
|
s->ReceiveDataOnly(&ret,sizeof(ret));
|
||||||
if (s==NULL) setReceiverTCPSocket("",DEFAULT_PORTNO+2);
|
if (ret==FAIL) {
|
||||||
if (dataSocket) s=dataSocket;
|
s->ReceiveDataOnly(mess,sizeof(mess));
|
||||||
else setReceiverTCPSocket("",retval);
|
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||||
online = (thisDetector->receiverOnlineFlag==ONLINE_FLAG);
|
} else {
|
||||||
}
|
s->ReceiveDataOnly(&retval,sizeof(retval));
|
||||||
break;
|
}
|
||||||
case STOP_PORT:
|
s->Disconnect();
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (online) {
|
if (ret!=FAIL) {
|
||||||
if (s) {
|
switch(index) {
|
||||||
if (s->Connect()>=0) {
|
case CONTROL_PORT:
|
||||||
s->SendDataOnly(&fnum,sizeof(fnum));
|
thisDetector->controlPort=retval;
|
||||||
s->SendDataOnly(&index,sizeof(index));
|
break;
|
||||||
s->SendDataOnly(&num,sizeof(num));
|
case DATA_PORT:
|
||||||
s->ReceiveDataOnly(&ret,sizeof(ret));
|
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
|
||||||
if (ret==FAIL) {
|
cout<<"online,ret=ok"<<endl;
|
||||||
s->ReceiveDataOnly(mess,sizeof(mess));
|
thisDetector->receiverPort=retval;
|
||||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
cout<<"first trying to set online:"<<setReceiverOnline(ONLINE_FLAG)<<endl;
|
||||||
} else {
|
cout<<"Setting up Receiver"<<endl;
|
||||||
s->ReceiveDataOnly(&retval,sizeof(retval));
|
setReceiverIP(thisDetector->receiverIP);
|
||||||
}
|
}
|
||||||
s->Disconnect();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
switch(index) {
|
||||||
}
|
case CONTROL_PORT:
|
||||||
if (ret!=FAIL) {
|
retval=thisDetector->controlPort;
|
||||||
|
break;
|
||||||
switch(index) {
|
case DATA_PORT:
|
||||||
case CONTROL_PORT:
|
retval=thisDetector->receiverPort;
|
||||||
thisDetector->controlPort=retval;
|
break;
|
||||||
break;
|
case STOP_PORT:
|
||||||
case DATA_PORT:
|
retval=thisDetector->stopPort;
|
||||||
thisDetector->receiverPort=retval;
|
break;
|
||||||
break;
|
default:
|
||||||
case STOP_PORT:
|
retval=-1;
|
||||||
thisDetector->stopPort=retval;
|
break;
|
||||||
break;
|
}
|
||||||
default:
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "ret is ok" << endl;
|
cout << thisDetector->controlPort<< " " << thisDetector->receiverPort << " " << thisDetector->stopPort << endl;
|
||||||
#endif
|
#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;
|
int ret = slsDetectorDefs::OK;
|
||||||
MySocketTCP *socket = NULL;
|
MySocketTCP *socket = NULL;
|
||||||
string fname = "";
|
string fname = "";
|
||||||
|
bool shortfname = false;
|
||||||
|
|
||||||
//parse command line for config
|
//parse command line for config
|
||||||
for(int iarg=2;iarg<argc;iarg++)
|
for(int iarg=1;iarg<argc;iarg++){
|
||||||
if(!strcasecmp(argv[iarg-1],"-config"))
|
if(!strcasecmp(argv[iarg],"-config")){
|
||||||
|
if(iarg+1==argc){
|
||||||
|
cout << "no config file name given. Exiting." << endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
fname.assign(argv[iarg]);
|
fname.assign(argv[iarg]);
|
||||||
|
}
|
||||||
|
if(!strcasecmp(argv[iarg],"-shortfname"))
|
||||||
|
shortfname = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//reads config file, creates socket, assigns function table
|
//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)
|
if(ret==slsDetectorDefs::FAIL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -23,7 +23,8 @@ using namespace std;
|
|||||||
FILE* slsReceiverFunctionList::sfilefd(NULL);
|
FILE* slsReceiverFunctionList::sfilefd(NULL);
|
||||||
int slsReceiverFunctionList::listening_thread_running(0);
|
int slsReceiverFunctionList::listening_thread_running(0);
|
||||||
|
|
||||||
slsReceiverFunctionList::slsReceiverFunctionList():
|
slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname):
|
||||||
|
shortFileName(shortfname),
|
||||||
fileIndex(0),
|
fileIndex(0),
|
||||||
frameIndexNeeded(true),
|
frameIndexNeeded(true),
|
||||||
framesCaught(0),
|
framesCaught(0),
|
||||||
@ -38,6 +39,7 @@ slsReceiverFunctionList::slsReceiverFunctionList():
|
|||||||
server_port(DEFAULT_UDP_PORT)
|
server_port(DEFAULT_UDP_PORT)
|
||||||
{
|
{
|
||||||
strcpy(savefilename,"");
|
strcpy(savefilename,"");
|
||||||
|
strcpy(actualfilename,"");
|
||||||
strcpy(filePath,"");
|
strcpy(filePath,"");
|
||||||
strcpy(fileName,"run");
|
strcpy(fileName,"run");
|
||||||
strcpy(buffer,"");
|
strcpy(buffer,"");
|
||||||
@ -195,6 +197,10 @@ int slsReceiverFunctionList::startListening(){
|
|||||||
else
|
else
|
||||||
sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,framesCaught,fileIndex);
|
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
|
// 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
|
// close() of each of the socket descriptors is only done once at the
|
||||||
@ -206,8 +212,8 @@ int slsReceiverFunctionList::startListening(){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
sfilefd = fopen((const char *) (savefilename), "w");
|
sfilefd = fopen((const char *) (actualfilename), "w");
|
||||||
cout << "Saving to " << savefilename << ". Ready! " << endl;
|
cout << "Saving to " << actualfilename << ". Ready! " << endl;
|
||||||
|
|
||||||
while (listening_thread_running) {
|
while (listening_thread_running) {
|
||||||
|
|
||||||
@ -221,10 +227,15 @@ int slsReceiverFunctionList::startListening(){
|
|||||||
else
|
else
|
||||||
sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,framesCaught,fileIndex);
|
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"
|
"packet loss " << ((currframenum-prevframenum-(2*framesInFile))/(double)(2*framesInFile))*100.000 << "%\t\t"
|
||||||
"framenum " << currframenum << endl;
|
"framenum " << currframenum << endl;
|
||||||
sfilefd = fopen((const char *) (savefilename), "w");
|
sfilefd = fopen((const char *) (actualfilename), "w");
|
||||||
prevframenum=currframenum;
|
prevframenum=currframenum;
|
||||||
framesInFile = 0;
|
framesInFile = 0;
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,9 @@ class slsReceiverFunctionList : private virtual slsDetectorDefs {
|
|||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
* @param shortfname true if short file name required
|
||||||
*/
|
*/
|
||||||
slsReceiverFunctionList();
|
slsReceiverFunctionList(bool shortfname);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor
|
* Destructor
|
||||||
@ -142,6 +143,12 @@ private:
|
|||||||
/** Complete File name */
|
/** Complete File name */
|
||||||
char savefilename[MAX_STR_LENGTH];
|
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*/
|
/** File Name without frame index, file index and extension*/
|
||||||
char fileName[MAX_STR_LENGTH];
|
char fileName[MAX_STR_LENGTH];
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
using namespace std;
|
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),
|
socket(mySocket),
|
||||||
ret(OK),
|
ret(OK),
|
||||||
lockStatus(0){
|
lockStatus(0){
|
||||||
@ -89,7 +89,7 @@ slsReceiverFuncs::slsReceiverFuncs(MySocketTCP *&mySocket,string const fname,int
|
|||||||
strcpy(mess,"dummy message");
|
strcpy(mess,"dummy message");
|
||||||
|
|
||||||
function_table();
|
function_table();
|
||||||
slsReceiverList = new slsReceiverFunctionList();
|
slsReceiverList = new slsReceiverFunctionList(shortfname);
|
||||||
|
|
||||||
success = OK;
|
success = OK;
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,9 @@ public:
|
|||||||
* @param mySocket tcp socket connecting receiver and client
|
* @param mySocket tcp socket connecting receiver and client
|
||||||
* @param fname name of config file
|
* @param fname name of config file
|
||||||
* @param success if socket creation was successfull
|
* @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 */
|
/** Destructor */
|
||||||
virtual ~slsReceiverFuncs(){};
|
virtual ~slsReceiverFuncs(){};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user