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:
l_maliakal_d 2012-11-22 10:25:42 +00:00
parent 2580c29886
commit 6a74fda3ed
6 changed files with 181 additions and 143 deletions

View File

@ -3490,8 +3490,6 @@ int slsDetector::setPort(portType index, int num){
cout << thisDetector->controlPort<< " " << " " << thisDetector->stopPort << endl;
#endif
setTCPSocket("",retval);
}
online = (thisDetector->onlineFlag==ONLINE_FLAG);
@ -3500,11 +3498,12 @@ int slsDetector::setPort(portType index, int num){
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);
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;
@ -3516,8 +3515,10 @@ int slsDetector::setPort(portType index, int num){
break;
default:
s=NULL;
break;
}
//send to current port to change port
if (online) {
if (s) {
if (s->Connect()>=0) {
@ -3535,23 +3536,27 @@ int slsDetector::setPort(portType index, int num){
}
}
}
if (ret!=FAIL) {
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
@ -3562,17 +3567,23 @@ int slsDetector::setPort(portType index, int num){
thisDetector->controlPort=num;
break;
case DATA_PORT:
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG)
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
cout<<"online,ret=fail"<<endl;
thisDetector->receiverPort=retval;
else
}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;
}
}
}
@ -3588,9 +3599,9 @@ int slsDetector::setPort(portType index, int num){
break;
default:
retval=-1;
break;
}
// setTCPSocket();
#ifdef VERBOSE

View File

@ -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;

View File

@ -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;
}

View File

@ -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];

View File

@ -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;
}

View File

@ -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(){};