mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-17 15:27:13 +02:00
Added startAcquisition, acquisitionFinished and rawDataReady callbacks to receiver
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@480 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
@ -2,8 +2,6 @@
|
|||||||
The port number is passed as an argument */
|
The port number is passed as an argument */
|
||||||
|
|
||||||
#include "sls_detector_defs.h"
|
#include "sls_detector_defs.h"
|
||||||
#include "receiver_defs.h"
|
|
||||||
#include "MySocketTCP.h"
|
|
||||||
#include "slsReceiver_funcs.h"
|
#include "slsReceiver_funcs.h"
|
||||||
|
|
||||||
|
|
||||||
@ -13,79 +11,80 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
//static MySocketTCP *mysocket = NULL;
|
|
||||||
|
|
||||||
void closeFile(int p){cout<<"in closefile in receiver"<<endl;
|
void closeFile(int p){
|
||||||
slsReceiverFuncs::closeFile(p);
|
cout<<"close file in receiver"<<endl;
|
||||||
//mysocket->Disconnect();
|
slsReceiverFuncs::closeFile(p);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[]) {
|
||||||
{
|
int ret = slsDetectorDefs::OK;
|
||||||
int ret = slsDetectorDefs::OK;
|
|
||||||
MySocketTCP *mysocket = NULL;
|
slsReceiverFuncs *receiver = new slsReceiverFuncs(argc, argv, ret);
|
||||||
string fname = "";
|
|
||||||
bool shortfname = false;
|
if(ret==slsDetectorDefs::FAIL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
|
||||||
|
//Catch signal SIGINT to close files properly
|
||||||
|
signal(SIGINT,closeFile);
|
||||||
|
|
||||||
|
//register callbacks
|
||||||
|
|
||||||
//parse command line for config
|
|
||||||
for(int iarg=1;iarg<argc;iarg++){
|
/**
|
||||||
if((!strcasecmp(argv[iarg],"-config"))||(!strcasecmp(argv[iarg],"-f"))){
|
callback arguments are
|
||||||
if(iarg+1==argc){
|
filepath
|
||||||
cout << "no config file name given. Exiting." << endl;
|
filename
|
||||||
return -1;
|
fileindex
|
||||||
}
|
datasize
|
||||||
fname.assign(argv[iarg+1]);
|
|
||||||
}
|
return value is
|
||||||
if(!strcasecmp(argv[iarg],"-shortfname"))
|
0 raw data ready callback takes care of open,close,write file
|
||||||
shortfname = true;
|
1 callback writes file, we have to open, close it
|
||||||
}
|
2 we open, close, write file, callback does not do anything
|
||||||
|
|
||||||
|
|
||||||
|
registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg);
|
||||||
|
*/
|
||||||
|
|
||||||
|
//receiver->registerCallBackStartAcquisition(func,arg);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
callback argument is
|
||||||
|
total farmes caught
|
||||||
|
registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
//receiver->registerCallBackAcquisitionFinished(func,arg);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
args to raw data ready callback are
|
||||||
|
framenum
|
||||||
|
datapointer
|
||||||
|
file descriptor
|
||||||
|
guidatapointer (NULL, no data required)
|
||||||
|
|
||||||
|
NEVER DELETE THE DATA POINTER
|
||||||
|
REMEMBER THAT THE CALLBACK IS BLOCKING
|
||||||
|
|
||||||
|
registerCallBackRawDataReady(void (*func)(int, char*, FILE*, char*, void*),void *arg);
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
//receiver->registerCallBackRawDataReady(func,arg);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//reads config file, creates socket, assigns function table
|
|
||||||
slsReceiverFuncs *receiver = new slsReceiverFuncs(mysocket,fname,ret, shortfname);
|
|
||||||
if(ret==slsDetectorDefs::FAIL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
|
receiver->start();
|
||||||
//Catch signal SIGINT to close files properly
|
|
||||||
signal(SIGINT,closeFile);
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
#ifdef VERBOSE
|
|
||||||
cout << "Function table assigned." << endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
cout << " Ready..." << endl;
|
|
||||||
//waits for connection
|
|
||||||
while(ret!=GOODBYE) {
|
|
||||||
#ifdef VERBOSE
|
|
||||||
cout<< endl;
|
|
||||||
#endif
|
|
||||||
#ifdef VERY_VERBOSE
|
|
||||||
cout << "Waiting for client call" << endl;
|
|
||||||
#endif
|
|
||||||
if(mysocket->Connect()>=0){
|
|
||||||
#ifdef VERY_VERBOSE
|
|
||||||
cout << "Conenction accepted" << endl;
|
|
||||||
#endif
|
|
||||||
ret = receiver->decode_function();
|
|
||||||
#ifdef VERY_VERBOSE
|
|
||||||
cout << "function executed" << endl;
|
|
||||||
#endif
|
|
||||||
mysocket->Disconnect();
|
|
||||||
#ifdef VERY_VERBOSE
|
|
||||||
cout << "connection closed" << endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
slsReceiverFuncs::closeFile(0);
|
|
||||||
cout << "Goodbye!" << endl;
|
|
||||||
delete mysocket;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,14 @@ slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname):
|
|||||||
guiRequiresData(0),
|
guiRequiresData(0),
|
||||||
currframenum(0),
|
currframenum(0),
|
||||||
writeReceiverData(0),
|
writeReceiverData(0),
|
||||||
pwriteReceiverDataArg(0)
|
pwriteReceiverDataArg(0),
|
||||||
|
startAcquisitionCallBack(NULL),
|
||||||
|
pStartAcquisition(NULL),
|
||||||
|
acquisitionFinishedCallBack(NULL),
|
||||||
|
pAcquisitionFinished(NULL),
|
||||||
|
rawDataReadyCallBack(NULL),
|
||||||
|
pRawDataReady(NULL)
|
||||||
|
|
||||||
{
|
{
|
||||||
strcpy(savefilename,"");
|
strcpy(savefilename,"");
|
||||||
strcpy(actualfilename,"");
|
strcpy(actualfilename,"");
|
||||||
@ -387,7 +394,7 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
// Variable and structure definitions
|
// Variable and structure definitions
|
||||||
int ret,sleepnumber=0;//currframenum,ret;
|
int ret,sleepnumber=0;//currframenum,ret;
|
||||||
// dataStruct *dataWriteFrame;
|
// dataStruct *dataWriteFrame;
|
||||||
|
char *guiData;
|
||||||
//reset variables for each acquisition
|
//reset variables for each acquisition
|
||||||
framesInFile=0;
|
framesInFile=0;
|
||||||
framesCaught=0;
|
framesCaught=0;
|
||||||
@ -401,19 +408,38 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
cout << "Note: Data Write has been defined exernally" << endl;
|
cout << "Note: Data Write has been defined exernally" << endl;
|
||||||
cout << "Ready!" << endl;
|
cout << "Ready!" << endl;
|
||||||
|
|
||||||
if(!enableFileWrite)
|
cbAction=2;
|
||||||
|
|
||||||
|
if (startAcquisitionCallBack)
|
||||||
|
cbAction=startAcquisitionCallBack(filePath,fileName,fileIndex,bufferSize,pStartAcquisition);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(enableFileWrite==0 || cbAction==0)
|
||||||
cout << endl << "Note: Data will not be saved" << endl;
|
cout << endl << "Note: Data will not be saved" << endl;
|
||||||
|
|
||||||
//create file name
|
//create file name
|
||||||
if(frameIndexNeeded==-1) sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex);
|
if(frameIndexNeeded==-1)
|
||||||
else sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,framesCaught,fileIndex);
|
sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex);
|
||||||
|
else
|
||||||
|
sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,framesCaught,fileIndex);
|
||||||
|
|
||||||
//for sebastian
|
//for sebastian
|
||||||
if(!shortFileName) strcpy(actualfilename,savefilename);
|
if(!shortFileName)
|
||||||
else sprintf(actualfilename, "%s/%s_%d_%09d.raw", filePath,fileName,fileIndex, 0);
|
strcpy(actualfilename,savefilename);
|
||||||
|
else
|
||||||
|
sprintf(actualfilename, "%s/%s_%d_%09d.raw", filePath,fileName,fileIndex, 0);
|
||||||
|
|
||||||
//start writing
|
//start writing
|
||||||
if(enableFileWrite){
|
if(enableFileWrite || cbAction>0){
|
||||||
sfilefd = fopen((const char *) (actualfilename), "w");
|
sfilefd = fopen((const char *) (actualfilename), "w");
|
||||||
cout << actualfilename << endl;
|
cout << actualfilename << endl;
|
||||||
}
|
}
|
||||||
@ -426,26 +452,26 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
if (framesInFile == maxFramesPerFile) {
|
if (framesInFile == maxFramesPerFile) {
|
||||||
|
|
||||||
//create file name
|
//create file name
|
||||||
if(frameIndexNeeded==-1) sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex);
|
if(frameIndexNeeded==-1) sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex);
|
||||||
else sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,framesCaught,fileIndex);
|
else sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,framesCaught,fileIndex);
|
||||||
//for sebastian
|
//for sebastian
|
||||||
if(!shortFileName) strcpy(actualfilename,savefilename);
|
if(!shortFileName) strcpy(actualfilename,savefilename);
|
||||||
else sprintf(actualfilename, "%s/%s_%d_%09d.raw", filePath,fileName,fileIndex, shortFileNameIndex);
|
else sprintf(actualfilename, "%s/%s_%d_%09d.raw", filePath,fileName,fileIndex, shortFileNameIndex);
|
||||||
shortFileNameIndex++;
|
shortFileNameIndex++;
|
||||||
|
|
||||||
//start writing in new file
|
//start writing in new file
|
||||||
if(enableFileWrite){
|
if(enableFileWrite || cbAction>0){
|
||||||
fclose(sfilefd);
|
fclose(sfilefd);
|
||||||
sfilefd = fopen((const char *) (actualfilename), "w");
|
sfilefd = fopen((const char *) (actualfilename), "w");
|
||||||
}
|
}
|
||||||
|
|
||||||
//currframenum=(int)(*((int*)latestData));
|
//currframenum=(int)(*((int*)latestData));
|
||||||
cout << actualfilename << "\tpacket loss " << fixed << setprecision(4) << ((currframenum-prevframenum-(packetsPerFrame*framesInFile))/(double)(packetsPerFrame*framesInFile))*100.000 << "%\t\t"
|
cout << actualfilename << "\tpacket loss " << fixed << setprecision(4) << ((currframenum-prevframenum-(packetsPerFrame*framesInFile))/(double)(packetsPerFrame*framesInFile))*100.000 << "%\t\t"
|
||||||
"framenum " << currframenum << "\t\t"
|
"framenum " << currframenum << "\t\t"
|
||||||
"p " << prevframenum << endl;
|
"p " << prevframenum << endl;
|
||||||
|
|
||||||
prevframenum=currframenum;
|
prevframenum=currframenum;
|
||||||
framesInFile = 0;
|
framesInFile = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -459,12 +485,21 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
totalFramesCaught++;
|
totalFramesCaught++;
|
||||||
currframenum = (int)(*((int*)dataWriteFrame->buffer));
|
currframenum = (int)(*((int*)dataWriteFrame->buffer));
|
||||||
|
|
||||||
|
if(guiRequiresData)
|
||||||
|
guiData=latestData;
|
||||||
|
else
|
||||||
|
guiData=NULL;
|
||||||
|
|
||||||
if(enableFileWrite){
|
if(enableFileWrite){
|
||||||
if (writeReceiverData)
|
if (writeReceiverData)
|
||||||
writeReceiverData(dataWriteFrame->buffer,dataWriteFrame->rc, sfilefd, pwriteReceiverDataArg);
|
writeReceiverData(dataWriteFrame->buffer,dataWriteFrame->rc, sfilefd, pwriteReceiverDataArg);
|
||||||
else
|
if (cbAction<2) {
|
||||||
fwrite(dataWriteFrame->buffer, 1, dataWriteFrame->rc, sfilefd);
|
rawDataReadyCallBack(currframenum, dataWriteFrame->buffer,sfilefd, guiData,pRawDataReady);
|
||||||
|
} else {
|
||||||
|
fwrite(dataWriteFrame->buffer, 1, dataWriteFrame->rc, sfilefd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(guiRequiresData){
|
if(guiRequiresData){
|
||||||
memcpy(latestData,dataWriteFrame->buffer,bufferSize);
|
memcpy(latestData,dataWriteFrame->buffer,bufferSize);
|
||||||
guiRequiresData=0;
|
guiRequiresData=0;
|
||||||
@ -485,11 +520,17 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
|
|
||||||
cout << "Total Frames Caught:"<< totalFramesCaught << endl;
|
cout << "Total Frames Caught:"<< totalFramesCaught << endl;
|
||||||
//close file
|
//close file
|
||||||
|
|
||||||
|
|
||||||
if(sfilefd) fclose(sfilefd);
|
if(sfilefd) fclose(sfilefd);
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "sfield:" << (int)sfilefd << endl;
|
cout << "sfield:" << (int)sfilefd << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (acquisitionFinishedCallBack)
|
||||||
|
acquisitionFinishedCallBack(totalFramesCaught, pAcquisitionFinished);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||||
|
#ifndef SLS_RECEIVER_FUNCTION_LIST_H
|
||||||
|
#define SLS_RECEIVER_FUNCTION_LIST_H
|
||||||
/********************************************//**
|
/********************************************//**
|
||||||
* @file slsReceiverFunctionList.h
|
* @file slsReceiverFunctionList.h
|
||||||
* @short does all the functions for a receiver, set/get parameters, start/stop etc.
|
* @short does all the functions for a receiver, set/get parameters, start/stop etc.
|
||||||
@ -299,6 +301,50 @@ private:
|
|||||||
int (*writeReceiverData)(char*,int,FILE*,void*);
|
int (*writeReceiverData)(char*,int,FILE*,void*);
|
||||||
void *pwriteReceiverDataArg;
|
void *pwriteReceiverDataArg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
callback arguments are
|
||||||
|
filepath
|
||||||
|
filename
|
||||||
|
fileindex
|
||||||
|
data size
|
||||||
|
|
||||||
|
return value is
|
||||||
|
0 callback takes care of open,close,write file
|
||||||
|
1 callback writes file, we have to open, close it
|
||||||
|
2 we open, close, write file, callback does not do anything
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
int (*startAcquisitionCallBack)(char*, char*,int, int, void*);
|
||||||
|
void *pStartAcquisition;
|
||||||
|
|
||||||
|
/**
|
||||||
|
args to acquisition finished callback
|
||||||
|
total frames caught
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
void (*acquisitionFinishedCallBack)(int, void*);
|
||||||
|
void *pAcquisitionFinished;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
args to raw data ready callback are
|
||||||
|
framenum
|
||||||
|
datapointer
|
||||||
|
file descriptor
|
||||||
|
guidatapointer (NULL, no data required)
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
void (*rawDataReadyCallBack)(int, char*, FILE*, char*, void*);
|
||||||
|
void *pRawDataReady;
|
||||||
|
|
||||||
|
|
||||||
|
int cbAction;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** File Descriptor */
|
/** File Descriptor */
|
||||||
static FILE *sfilefd;
|
static FILE *sfilefd;
|
||||||
@ -308,7 +354,59 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
dataStruct *dataWriteFrame;
|
dataStruct *dataWriteFrame;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
callback arguments are
|
||||||
|
filepath
|
||||||
|
filename
|
||||||
|
fileindex
|
||||||
|
datasize
|
||||||
|
|
||||||
|
return value is
|
||||||
|
0 callback takes care of open,close,wrie file
|
||||||
|
1 callback writes file, we have to open, close it
|
||||||
|
2 we open, close, write file, callback does not do anything
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){startAcquisitionCallBack=func; pStartAcquisition=arg;};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
callback argument is
|
||||||
|
toatal frames caught
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
int registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){acquisitionFinishedCallBack=func; pAcquisitionFinished=arg;};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
args to raw data ready callback are
|
||||||
|
framenum
|
||||||
|
datapointer
|
||||||
|
file descriptor
|
||||||
|
guidatapointer (NULL, no data required)
|
||||||
|
*/
|
||||||
|
|
||||||
|
int registerCallBackRawDataReady(void (*func)(int, char*, FILE*, char*, void*),void *arg){rawDataReadyCallBack=func; pRawDataReady=arg;};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -19,8 +19,18 @@ using namespace std;
|
|||||||
int slsReceiverFuncs::file_des(-1);
|
int slsReceiverFuncs::file_des(-1);
|
||||||
int slsReceiverFuncs::socketDescriptor(-1);
|
int slsReceiverFuncs::socketDescriptor(-1);
|
||||||
|
|
||||||
slsReceiverFuncs::slsReceiverFuncs(MySocketTCP *&mySocket,string const fname,int &success, bool shortfname):
|
|
||||||
socket(mySocket),
|
slsReceiverFuncs::~slsReceiverFuncs() {
|
||||||
|
|
||||||
|
slsReceiverFuncs::closeFile(0);
|
||||||
|
cout << "Goodbye!" << endl;
|
||||||
|
delete socket;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success):
|
||||||
|
socket(NULL),
|
||||||
ret(OK),
|
ret(OK),
|
||||||
lockStatus(0),
|
lockStatus(0),
|
||||||
shortFrame(-1),
|
shortFrame(-1),
|
||||||
@ -31,6 +41,23 @@ slsReceiverFuncs::slsReceiverFuncs(MySocketTCP *&mySocket,string const fname,int
|
|||||||
string sLine,sargname;
|
string sLine,sargname;
|
||||||
int iline = 0;
|
int iline = 0;
|
||||||
|
|
||||||
|
success=slsDetectorDefs::OK;
|
||||||
|
|
||||||
|
string fname = "";
|
||||||
|
bool shortfname = false;
|
||||||
|
|
||||||
|
//parse command line for config
|
||||||
|
for(int iarg=1;iarg<argc;iarg++){
|
||||||
|
if((!strcasecmp(argv[iarg],"-config"))||(!strcasecmp(argv[iarg],"-f"))){
|
||||||
|
if(iarg+1==argc){
|
||||||
|
cout << "no config file name given. Exiting." << endl;
|
||||||
|
success=slsDetectorDefs::FAIL;
|
||||||
|
}
|
||||||
|
fname.assign(argv[iarg+1]);
|
||||||
|
}
|
||||||
|
if(!strcasecmp(argv[iarg],"-shortfname"))
|
||||||
|
shortfname = true;
|
||||||
|
}
|
||||||
|
|
||||||
if(!fname.empty()){
|
if(!fname.empty()){
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
@ -84,14 +111,12 @@ slsReceiverFuncs::slsReceiverFuncs(MySocketTCP *&mySocket,string const fname,int
|
|||||||
|
|
||||||
if(success == OK){
|
if(success == OK){
|
||||||
//create socket
|
//create socket
|
||||||
MySocketTCP* mySocket = new MySocketTCP(port_no);
|
socket = new MySocketTCP(port_no);
|
||||||
if (mySocket->getErrorStatus())
|
if (socket->getErrorStatus()) {
|
||||||
success = FAIL;
|
success = FAIL;
|
||||||
else{
|
|
||||||
|
|
||||||
delete socket;
|
delete socket;
|
||||||
socket = mySocket;
|
socket=NULL;
|
||||||
|
} else {
|
||||||
//initialize variables
|
//initialize variables
|
||||||
strcpy(socket->lastClientIP,"none");
|
strcpy(socket->lastClientIP,"none");
|
||||||
strcpy(socket->thisClientIP,"none1");
|
strcpy(socket->thisClientIP,"none1");
|
||||||
@ -100,16 +125,47 @@ slsReceiverFuncs::slsReceiverFuncs(MySocketTCP *&mySocket,string const fname,int
|
|||||||
function_table();
|
function_table();
|
||||||
slsReceiverList = new slsReceiverFunctionList(shortfname);
|
slsReceiverList = new slsReceiverFunctionList(shortfname);
|
||||||
|
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "Function table assigned." << endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
file_des=socket->getFileDes();
|
file_des=socket->getFileDes();
|
||||||
socketDescriptor=socket->getsocketDescriptor();
|
socketDescriptor=socket->getsocketDescriptor();
|
||||||
|
|
||||||
success = OK;
|
//success = OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void slsReceiverFuncs::start(){
|
||||||
|
|
||||||
|
int v=slsDetectorDefs::OK;
|
||||||
|
|
||||||
|
while(v!=GOODBYE) {
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout<< endl;
|
||||||
|
#endif
|
||||||
|
#ifdef VERY_VERBOSE
|
||||||
|
cout << "Waiting for client call" << endl;
|
||||||
|
#endif
|
||||||
|
if(socket->Connect()>=0){
|
||||||
|
#ifdef VERY_VERBOSE
|
||||||
|
cout << "Conenction accepted" << endl;
|
||||||
|
#endif
|
||||||
|
v = decode_function();
|
||||||
|
#ifdef VERY_VERBOSE
|
||||||
|
cout << "function executed" << endl;
|
||||||
|
#endif
|
||||||
|
socket->Disconnect();
|
||||||
|
#ifdef VERY_VERBOSE
|
||||||
|
cout << "connection closed" << endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int slsReceiverFuncs::function_table(){
|
int slsReceiverFuncs::function_table(){
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "sls_detector_defs.h"
|
#include "sls_detector_defs.h"
|
||||||
#include "receiver_defs.h"
|
#include "receiver_defs.h"
|
||||||
#include "MySocketTCP.h"
|
#include "MySocketTCP.h"
|
||||||
|
#include "slsReceiverFunctionList.h"
|
||||||
|
|
||||||
class slsReceiverFunctionList;
|
class slsReceiverFunctionList;
|
||||||
|
|
||||||
@ -22,16 +23,63 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* reads config file, creates socket, assigns function table
|
* reads config file, creates socket, assigns function table
|
||||||
* @param mySocket tcp socket connecting receiver and client
|
* @param argc from command line
|
||||||
* @param fname name of config file
|
* @param argv from command line
|
||||||
* @param success if socket creation was successfull
|
* @param succecc socket creation was successfull
|
||||||
* @param shortfname true if short file name required
|
|
||||||
*/
|
*/
|
||||||
slsReceiverFuncs(MySocketTCP *&mySocket,string const fname,int &success, bool shortfname);
|
slsReceiverFuncs(int argc, char *argv[], int &success);
|
||||||
|
|
||||||
|
/** starts listening on the TCP port for client comminication */
|
||||||
|
|
||||||
|
void start();
|
||||||
|
|
||||||
/** Destructor */
|
/** Destructor */
|
||||||
virtual ~slsReceiverFuncs(){};
|
virtual ~slsReceiverFuncs();
|
||||||
|
|
||||||
|
/** Close File */
|
||||||
|
static void closeFile(int p);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
callback arguments are
|
||||||
|
filepath
|
||||||
|
filename
|
||||||
|
fileindex
|
||||||
|
data size
|
||||||
|
|
||||||
|
return value is
|
||||||
|
0 callback takes care of open,close,wrie file
|
||||||
|
1 callback writes file, we have to open, close it
|
||||||
|
2 we open, close, write file, callback does not do anything
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){slsReceiverList->registerCallBackStartAcquisition(func,arg);};;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
callback argument is
|
||||||
|
toatal farmes caught
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
int registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){slsReceiverList->registerCallBackAcquisitionFinished(func,arg);};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
args to raw data ready callback are
|
||||||
|
framenum
|
||||||
|
datapointer
|
||||||
|
file descriptor
|
||||||
|
guidatapointer (NULL, no data required)
|
||||||
|
*/
|
||||||
|
|
||||||
|
int registerCallBackRawDataReady(void (*func)(int, char*, FILE*, char*, void*),void *arg){slsReceiverList->registerCallBackRawDataReady(func,arg);};
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
/** assigns functions to the fnum enum */
|
/** assigns functions to the fnum enum */
|
||||||
int function_table();
|
int function_table();
|
||||||
|
|
||||||
@ -41,9 +89,6 @@ public:
|
|||||||
/** Unrecognized Function */
|
/** Unrecognized Function */
|
||||||
int M_nofunc();
|
int M_nofunc();
|
||||||
|
|
||||||
/** Close File */
|
|
||||||
static void closeFile(int p);
|
|
||||||
|
|
||||||
/** Set File name without frame index, file index and extension */
|
/** Set File name without frame index, file index and extension */
|
||||||
int set_file_name();
|
int set_file_name();
|
||||||
|
|
||||||
@ -111,13 +156,7 @@ public:
|
|||||||
/** Execute command */
|
/** Execute command */
|
||||||
int exec_command();
|
int exec_command();
|
||||||
|
|
||||||
|
//private:
|
||||||
|
|
||||||
//private:
|
|
||||||
|
|
||||||
/** Socket */
|
|
||||||
MySocketTCP*& socket;
|
|
||||||
private:
|
|
||||||
/** slsReceiverFunctionList object */
|
/** slsReceiverFunctionList object */
|
||||||
slsReceiverFunctionList *slsReceiverList;
|
slsReceiverFunctionList *slsReceiverList;
|
||||||
|
|
||||||
@ -145,6 +184,10 @@ private:
|
|||||||
static int file_des;
|
static int file_des;
|
||||||
static int socketDescriptor;
|
static int socketDescriptor;
|
||||||
|
|
||||||
|
//private:
|
||||||
|
protected:
|
||||||
|
/** Socket */
|
||||||
|
MySocketTCP* socket;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user