mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-12 12:57:13 +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 */
|
/** get flag form most functions */
|
||||||
#define GET_FLAG -1
|
#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};
|
enum {startScript, scriptBefore, headerBefore, headerAfter,scriptAfter, stopScript, enCalLog, angCalLog, MAX_ACTIONS};
|
||||||
@ -526,11 +536,19 @@ enum angleConversionParameter {
|
|||||||
//} angleConversionConstant;
|
//} angleConversionConstant;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
protected:
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef MYROOT
|
#ifndef MYROOT
|
||||||
#include "sls_detector_funcs.h"
|
#include "sls_detector_funcs.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
};
|
||||||
|
#endif
|
||||||
;
|
;
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
|
@ -399,7 +399,12 @@ class slsDetectorUsers
|
|||||||
|
|
||||||
void registerRawDataCallback(int( *userCallback)(double* p, int n, void*), void *pArg);
|
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
|
@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++
|
CC = g++
|
||||||
CLAGS += -DSLS_RECEIVER_FUNCTION_LIST -DGOTTHARDD
|
CLAGS += -DSLS_RECEIVER_FUNCTION_LIST -DGOTTHARDD #-DTESTWRITE
|
||||||
LDLIBS += -lm -lstdc++ -lpthread
|
LDLIBS += -lm -lstdc++ -lpthread
|
||||||
|
|
||||||
INCLUDES = -I ../MySocketTCP -I ../commonFiles -I .
|
INCLUDES = -I ../MySocketTCP -I ../commonFiles -I ../usersFunctions -I ../slsDetectorAnalysis -I .
|
||||||
SRC_CLNT = slsReceiver.cpp ../MySocketTCP/MySocketTCP.cpp slsReceiver_funcs.cpp slsReceiverFunctionList.cpp
|
SRC_CLNT = slsReceiver.cpp ../MySocketTCP/MySocketTCP.cpp slsReceiver_funcs.cpp slsReceiverFunctionList.cpp ../usersFunctions/usersFunctions.cpp
|
||||||
|
|
||||||
PROGS = slsReceiver
|
PROGS = slsReceiver
|
||||||
DESTDIR ?= bin
|
DESTDIR ?= bin
|
||||||
|
@ -7,7 +7,9 @@
|
|||||||
|
|
||||||
#include "slsReceiverFunctionList.h"
|
#include "slsReceiverFunctionList.h"
|
||||||
|
|
||||||
|
#ifdef TESTWRITE
|
||||||
|
#include "usersFunctions.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <signal.h> // SIGINT
|
#include <signal.h> // SIGINT
|
||||||
#include <sys/stat.h> // stat
|
#include <sys/stat.h> // stat
|
||||||
@ -49,7 +51,9 @@ slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname):
|
|||||||
bufferSize(BUFFER_SIZE),
|
bufferSize(BUFFER_SIZE),
|
||||||
packetsPerFrame(2),
|
packetsPerFrame(2),
|
||||||
guiRequiresData(0),
|
guiRequiresData(0),
|
||||||
currframenum(0)
|
currframenum(0),
|
||||||
|
writeReceiverData(0),
|
||||||
|
pwriteReceiverDataArg(0)
|
||||||
{
|
{
|
||||||
strcpy(savefilename,"");
|
strcpy(savefilename,"");
|
||||||
strcpy(actualfilename,"");
|
strcpy(actualfilename,"");
|
||||||
@ -67,21 +71,19 @@ slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname):
|
|||||||
|
|
||||||
mem0=(char*)malloc(4096*FIFO_SIZE);
|
mem0=(char*)malloc(4096*FIFO_SIZE);
|
||||||
if (mem0==NULL) {
|
if (mem0==NULL) {
|
||||||
cout<<"++++++++++++++++++++++ COULD NON ALLOCATE MEMORY!!!!!!!+++++++++++++++++++++" << endl;
|
cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY!!!!!!!+++++++++++++++++++++" << endl;
|
||||||
}
|
}
|
||||||
buffer=mem0;
|
buffer=mem0;
|
||||||
while (buffer<(mem0+4096*(FIFO_SIZE-1))) {
|
while (buffer<(mem0+4096*(FIFO_SIZE-1))) {
|
||||||
fifofree->push(buffer);
|
fifofree->push(buffer);
|
||||||
buffer+=4096;
|
buffer+=4096;
|
||||||
}
|
}
|
||||||
// cout<<"DEFAULT BUFFER SIZE IS "<< BUFFER_SIZE << endl;
|
|
||||||
|
|
||||||
|
#ifdef TESTWRITE
|
||||||
// buffer=mem0;
|
//to test write receiver data call back
|
||||||
|
registerWriteReceiverDataCallback(&defaultWriteReceiverDataFunc, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -386,7 +388,11 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
strcpy(savefilename,"");
|
strcpy(savefilename,"");
|
||||||
strcpy(actualfilename,"");
|
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;
|
cout << "Ready!" << endl;
|
||||||
|
|
||||||
|
|
||||||
@ -400,8 +406,10 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
else sprintf(actualfilename, "%s/%s_%d_%09d.raw", filePath,fileName,fileIndex, 0);
|
else sprintf(actualfilename, "%s/%s_%d_%09d.raw", filePath,fileName,fileIndex, 0);
|
||||||
|
|
||||||
//start writing
|
//start writing
|
||||||
sfilefd = fopen((const char *) (actualfilename), "w");
|
if (!writeReceiverData){
|
||||||
cout << "Saving to " << actualfilename << endl;
|
sfilefd = fopen((const char *) (actualfilename), "w");
|
||||||
|
cout << "Saving to " << actualfilename << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -409,7 +417,7 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
while(listening_thread_running){
|
while(listening_thread_running){
|
||||||
|
|
||||||
//when it reaches maxFramesPerFile,start writing new file
|
//when it reaches maxFramesPerFile,start writing new file
|
||||||
if (framesInFile == maxFramesPerFile) {
|
if ((!writeReceiverData)&& (framesInFile == maxFramesPerFile)) {
|
||||||
|
|
||||||
if(enableFileWrite){
|
if(enableFileWrite){
|
||||||
fclose(sfilefd);
|
fclose(sfilefd);
|
||||||
@ -428,7 +436,7 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
//currframenum=(int)(*((int*)latestData));
|
//currframenum=(int)(*((int*)latestData));
|
||||||
cout << "packet loss " << fixed << setprecision(4) << ((currframenum-prevframenum-(packetsPerFrame*framesInFile))/(double)(packetsPerFrame*framesInFile))*100.000 << "%\t\t"
|
cout << "packet 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 << " sleep:" << sleepnumber << endl;
|
"p " << prevframenum << endl;
|
||||||
|
|
||||||
prevframenum=currframenum;
|
prevframenum=currframenum;
|
||||||
framesInFile = 0;
|
framesInFile = 0;
|
||||||
@ -449,8 +457,12 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
guiRequiresData=0;
|
guiRequiresData=0;
|
||||||
}
|
}
|
||||||
//cout<<"write index:"<<(int)(*(int*)latestData)<<endl;
|
//cout<<"write index:"<<(int)(*(int*)latestData)<<endl;
|
||||||
if(enableFileWrite)
|
if(enableFileWrite){
|
||||||
fwrite(dataWriteFrame->buffer, 1, dataWriteFrame->rc, sfilefd);
|
if (writeReceiverData)
|
||||||
|
writeReceiverData(dataWriteFrame->buffer,dataWriteFrame->rc, pwriteReceiverDataArg);
|
||||||
|
else
|
||||||
|
fwrite(dataWriteFrame->buffer, 1, dataWriteFrame->rc, sfilefd);
|
||||||
|
}
|
||||||
framesInFile++;
|
framesInFile++;
|
||||||
///ANNA?!?!??!
|
///ANNA?!?!??!
|
||||||
// delete [] dataWriteFrame->buffer;
|
// delete [] dataWriteFrame->buffer;
|
||||||
@ -458,9 +470,10 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
}
|
}
|
||||||
delete dataWriteFrame;
|
delete dataWriteFrame;
|
||||||
}
|
}
|
||||||
else{sleepnumber++;sleepnumber++;sleepnumber++;//cout<<"fifo empty, usleep"<<endl;
|
else{
|
||||||
|
sleepnumber++;
|
||||||
usleep(50000);
|
usleep(50000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "Total Frames Caught:"<< totalFramesCaught << endl;
|
cout << "Total Frames Caught:"<< totalFramesCaught << endl;
|
||||||
|
@ -181,7 +181,10 @@ public:
|
|||||||
*/
|
*/
|
||||||
int setShortFrame(int i);
|
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:
|
private:
|
||||||
|
|
||||||
@ -294,6 +297,11 @@ private:
|
|||||||
|
|
||||||
/** current frame number */
|
/** current frame number */
|
||||||
int currframenum;
|
int currframenum;
|
||||||
|
|
||||||
|
/** register for call back to get data */
|
||||||
|
int (*writeReceiverData)(char*,int,void*);
|
||||||
|
void *pwriteReceiverDataArg;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** File Descriptor */
|
/** File Descriptor */
|
||||||
static FILE *sfilefd;
|
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 defaultDataReadyFunc(detectorData* d, int i, void* p);
|
||||||
int defaultRawDataReadyFunc(double* d, int np, void* p);
|
int defaultRawDataReadyFunc(double* d, int np, void* p);
|
||||||
|
|
||||||
|
int defaultWriteReceiverDataFunc(char* d, int np, void* p);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user