mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-10 12:00:43 +02:00
defined a default and register call back function to write receiver data
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@473 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
@ -60,6 +60,16 @@ $Revision: 464 $
|
||||
/** get flag form most functions */
|
||||
#define GET_FLAG -1
|
||||
|
||||
#ifdef MYROOT
|
||||
|
||||
/** @short class containing all the structures, constants and enum definitions */
|
||||
class slsDetectorDefs {
|
||||
|
||||
public:
|
||||
|
||||
slsDetectorDefs(){};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, enCalLog, angCalLog, MAX_ACTIONS};
|
||||
@ -526,11 +536,19 @@ enum angleConversionParameter {
|
||||
//} angleConversionConstant;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
protected:
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifndef MYROOT
|
||||
#include "sls_detector_funcs.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
;
|
||||
#endif
|
||||
;
|
||||
|
@ -399,7 +399,12 @@ class slsDetectorUsers
|
||||
|
||||
void registerRawDataCallback(int( *userCallback)(double* p, int n, void*), void *pArg);
|
||||
|
||||
|
||||
/**
|
||||
@short register callback for writing receiver data - if the rawDataCallback is registered, no receiver data writing will be carried on automatically by the software - the receiver data are deleted by the software
|
||||
\param userCallback function for writing the receiver data - p is the pointer to the data, n is the number of bytes to write
|
||||
*/
|
||||
|
||||
void registerWriteReceiverDataCallback(int( *userCallback)(char* p, int n, void*), void *pArg);
|
||||
|
||||
/**
|
||||
@short function to initalize a set of measurements (reset binning if angular conversion, reset summing otherwise) - can be overcome by the user's functions thanks to the virtual property
|
||||
|
@ -1,9 +1,9 @@
|
||||
CC = g++
|
||||
CLAGS += -DSLS_RECEIVER_FUNCTION_LIST -DGOTTHARDD
|
||||
CLAGS += -DSLS_RECEIVER_FUNCTION_LIST -DGOTTHARDD #-DTESTWRITE
|
||||
LDLIBS += -lm -lstdc++ -lpthread
|
||||
|
||||
INCLUDES = -I ../MySocketTCP -I ../commonFiles -I .
|
||||
SRC_CLNT = slsReceiver.cpp ../MySocketTCP/MySocketTCP.cpp slsReceiver_funcs.cpp slsReceiverFunctionList.cpp
|
||||
INCLUDES = -I ../MySocketTCP -I ../commonFiles -I ../usersFunctions -I ../slsDetectorAnalysis -I .
|
||||
SRC_CLNT = slsReceiver.cpp ../MySocketTCP/MySocketTCP.cpp slsReceiver_funcs.cpp slsReceiverFunctionList.cpp ../usersFunctions/usersFunctions.cpp
|
||||
|
||||
PROGS = slsReceiver
|
||||
DESTDIR ?= bin
|
||||
|
@ -7,7 +7,9 @@
|
||||
|
||||
#include "slsReceiverFunctionList.h"
|
||||
|
||||
|
||||
#ifdef TESTWRITE
|
||||
#include "usersFunctions.h"
|
||||
#endif
|
||||
|
||||
#include <signal.h> // SIGINT
|
||||
#include <sys/stat.h> // stat
|
||||
@ -49,7 +51,9 @@ slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname):
|
||||
bufferSize(BUFFER_SIZE),
|
||||
packetsPerFrame(2),
|
||||
guiRequiresData(0),
|
||||
currframenum(0)
|
||||
currframenum(0),
|
||||
writeReceiverData(0),
|
||||
pwriteReceiverDataArg(0)
|
||||
{
|
||||
strcpy(savefilename,"");
|
||||
strcpy(actualfilename,"");
|
||||
@ -67,21 +71,19 @@ slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname):
|
||||
|
||||
mem0=(char*)malloc(4096*FIFO_SIZE);
|
||||
if (mem0==NULL) {
|
||||
cout<<"++++++++++++++++++++++ COULD NON ALLOCATE MEMORY!!!!!!!+++++++++++++++++++++" << endl;
|
||||
cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY!!!!!!!+++++++++++++++++++++" << endl;
|
||||
}
|
||||
buffer=mem0;
|
||||
while (buffer<(mem0+4096*(FIFO_SIZE-1))) {
|
||||
fifofree->push(buffer);
|
||||
buffer+=4096;
|
||||
}
|
||||
// cout<<"DEFAULT BUFFER SIZE IS "<< BUFFER_SIZE << endl;
|
||||
|
||||
|
||||
|
||||
// buffer=mem0;
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef TESTWRITE
|
||||
//to test write receiver data call back
|
||||
registerWriteReceiverDataCallback(&defaultWriteReceiverDataFunc, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -386,7 +388,11 @@ int slsReceiverFunctionList::startWriting(){
|
||||
strcpy(savefilename,"");
|
||||
strcpy(actualfilename,"");
|
||||
|
||||
cout << "Max Frames Per File:" << maxFramesPerFile << endl;
|
||||
if (!writeReceiverData)
|
||||
cout << "Max Frames Per File:" << maxFramesPerFile << endl;
|
||||
else
|
||||
cout << "Note: Writing Data has been defined exernally" << endl;
|
||||
|
||||
cout << "Ready!" << endl;
|
||||
|
||||
|
||||
@ -400,8 +406,10 @@ int slsReceiverFunctionList::startWriting(){
|
||||
else sprintf(actualfilename, "%s/%s_%d_%09d.raw", filePath,fileName,fileIndex, 0);
|
||||
|
||||
//start writing
|
||||
sfilefd = fopen((const char *) (actualfilename), "w");
|
||||
cout << "Saving to " << actualfilename << endl;
|
||||
if (!writeReceiverData){
|
||||
sfilefd = fopen((const char *) (actualfilename), "w");
|
||||
cout << "Saving to " << actualfilename << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -409,7 +417,7 @@ int slsReceiverFunctionList::startWriting(){
|
||||
while(listening_thread_running){
|
||||
|
||||
//when it reaches maxFramesPerFile,start writing new file
|
||||
if (framesInFile == maxFramesPerFile) {
|
||||
if ((!writeReceiverData)&& (framesInFile == maxFramesPerFile)) {
|
||||
|
||||
if(enableFileWrite){
|
||||
fclose(sfilefd);
|
||||
@ -428,7 +436,7 @@ int slsReceiverFunctionList::startWriting(){
|
||||
//currframenum=(int)(*((int*)latestData));
|
||||
cout << "packet loss " << fixed << setprecision(4) << ((currframenum-prevframenum-(packetsPerFrame*framesInFile))/(double)(packetsPerFrame*framesInFile))*100.000 << "%\t\t"
|
||||
"framenum " << currframenum << "\t\t"
|
||||
"p " << prevframenum << " sleep:" << sleepnumber << endl;
|
||||
"p " << prevframenum << endl;
|
||||
|
||||
prevframenum=currframenum;
|
||||
framesInFile = 0;
|
||||
@ -449,8 +457,12 @@ int slsReceiverFunctionList::startWriting(){
|
||||
guiRequiresData=0;
|
||||
}
|
||||
//cout<<"write index:"<<(int)(*(int*)latestData)<<endl;
|
||||
if(enableFileWrite)
|
||||
fwrite(dataWriteFrame->buffer, 1, dataWriteFrame->rc, sfilefd);
|
||||
if(enableFileWrite){
|
||||
if (writeReceiverData)
|
||||
writeReceiverData(dataWriteFrame->buffer,dataWriteFrame->rc, pwriteReceiverDataArg);
|
||||
else
|
||||
fwrite(dataWriteFrame->buffer, 1, dataWriteFrame->rc, sfilefd);
|
||||
}
|
||||
framesInFile++;
|
||||
///ANNA?!?!??!
|
||||
// delete [] dataWriteFrame->buffer;
|
||||
@ -458,9 +470,10 @@ int slsReceiverFunctionList::startWriting(){
|
||||
}
|
||||
delete dataWriteFrame;
|
||||
}
|
||||
else{sleepnumber++;sleepnumber++;sleepnumber++;//cout<<"fifo empty, usleep"<<endl;
|
||||
else{
|
||||
sleepnumber++;
|
||||
usleep(50000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Total Frames Caught:"<< totalFramesCaught << endl;
|
||||
|
@ -181,7 +181,10 @@ public:
|
||||
*/
|
||||
int setShortFrame(int i);
|
||||
|
||||
|
||||
/**
|
||||
* Register call back function to write receiver data
|
||||
*/
|
||||
void registerWriteReceiverDataCallback(int( *userCallback)(char*, int, void*), void *pArg) {writeReceiverData = userCallback; pwriteReceiverDataArg = pArg;};
|
||||
|
||||
private:
|
||||
|
||||
@ -294,6 +297,11 @@ private:
|
||||
|
||||
/** current frame number */
|
||||
int currframenum;
|
||||
|
||||
/** register for call back to get data */
|
||||
int (*writeReceiverData)(char*,int,void*);
|
||||
void *pwriteReceiverDataArg;
|
||||
|
||||
public:
|
||||
/** File Descriptor */
|
||||
static FILE *sfilefd;
|
||||
|
@ -336,4 +336,17 @@ int defaultRawDataReadyFunc(double* d, int np, void* p) {
|
||||
|
||||
|
||||
|
||||
int defaultWriteReceiverDataFunc(char* d, int np, void* p){
|
||||
//#ifdef VERBOSE
|
||||
printf("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU Receiver Data received \n");
|
||||
if (d==NULL)
|
||||
printf("no data received\n");
|
||||
else{
|
||||
printf("received %d bytes of data\n",np);
|
||||
printf("index:%d\n",(int)(*(int*)d));
|
||||
}
|
||||
|
||||
printf("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU Finished \n");
|
||||
//#endif
|
||||
return 0;
|
||||
}
|
||||
|
@ -40,6 +40,8 @@ extern "C" {
|
||||
int defaultDataReadyFunc(detectorData* d, int i, void* p);
|
||||
int defaultRawDataReadyFunc(double* d, int np, void* p);
|
||||
|
||||
int defaultWriteReceiverDataFunc(char* d, int np, void* p);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
|
Reference in New Issue
Block a user