started the basics for sending every nth frame from receiver to gui.incomplete and will be implemented later

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@506 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
l_maliakal_d 2013-04-11 12:00:44 +00:00
parent 02376bbc62
commit 778cd97317
12 changed files with 174 additions and 16 deletions

View File

@ -132,7 +132,9 @@ enum {
F_SET_FRAME_INDEX, /**< sets the receiver frame index */
F_CALIBRATE_PEDESTAL /**< starts acquistion, calibrates pedestal and write back to fpga */
F_CALIBRATE_PEDESTAL, /**< starts acquistion, calibrates pedestal and write back to fpga */
F_READ_RECEIVER_FREQUENCY /**< sets the frequency of receiver sending frames to gui */
/* Always append functions hereafter!!! */
};

View File

@ -4610,3 +4610,20 @@ int multiSlsDetector::calibratePedestal(int frames){
return ret;
}
int multiSlsDetector::setReadReceiverFrequency(int i){
int ret=-100, ret1;
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
if (detectors[idet]) {
ret1=detectors[idet]->setReadReceiverFrequency(i);
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
if (ret==-100)
ret=ret1;
else if (ret!=ret1)
ret=-1;
}
}
return ret;
}

View File

@ -1187,6 +1187,12 @@ class multiSlsDetector : public slsDetectorUtils {
*/
int calibratePedestal(int frames = 0);
/** Sets the read receiver frequency
if Receiver read upon gui request, readRxrFrequency=0,
else every nth frame to be sent to gui
/returns read receiver frequency
*/
int setReadReceiverFrequency(int i=-1);
protected:

View File

@ -6015,6 +6015,7 @@ int* slsDetector::readFrameFromReceiver(char* fName, int &fIndex){
n= dataSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned: " << mess << " " << n << std::endl;
delete [] retval;
dataSocket->Disconnect();
return NULL;
} else {
n=dataSocket->ReceiveDataOnly(fName,MAX_STR_LENGTH);
@ -6027,6 +6028,7 @@ int* slsDetector::readFrameFromReceiver(char* fName, int &fIndex){
std::cout<<endl<< "wrong data size received: received " << n << " but expected from receiver " << thisDetector->dataBytes << std::endl;
ret=FAIL;
delete [] retval;
dataSocket->Disconnect();
return NULL;
}
}
@ -6264,3 +6266,23 @@ int64_t slsDetector::clearAllErrorMask(){
}
int slsDetector::setReadReceiverFrequency(int i){
int fnum=F_READ_RECEIVER_FREQUENCY;
int ret = FAIL;
int retval=-1;
int arg = i;
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "Sending read frequency to receiver " << arg << std::endl;
#endif
if (connectData() == OK)
ret=thisReceiver->sendInt(fnum,retval,arg);
if(ret==FAIL)
retval = -1;
if(ret==FORCE_UPDATE)
updateReceiver();
}
return retval;
}

View File

@ -1581,6 +1581,13 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
/** sets the receiver udp port \sa sharedSlsDetector */
int setReceiverUDPPort(int udpport);
/** Sets the variable readRxrFrequency.
if Receiver read upon gui request, readRxrFrequency=0,
else every nth frame to be sent to gui
/returns read receiver frequency
*/
int setReadReceiverFrequency(int i=-1);
protected:

View File

@ -707,6 +707,9 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdLastClient;
i++;
descrToFuncMap[i].m_pFuncName="r_readfreq"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdReceiver;
i++;
numberOfCommands=i;
@ -3634,6 +3637,7 @@ string slsDetectorCommand::helpConfiguration(int narg, char *args[], int action)
string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) {
char answer[100];
int ival = -1;
if (action==HELP_ACTION)
return helpReceiver(narg, args, action);
@ -3670,10 +3674,20 @@ string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) {
sprintf(answer,"%d",myDet->getReceiverCurrentFrameIndex());
return string(answer);
}
}
else if(cmd=="r_readfreq"){
if (action==PUT_ACTION){
if (!sscanf(args[1],"%d",&ival))
return string("Could not scan read frequency mode ")+string(args[1]);
if(ival>=0)
myDet->setReadReceiverFrequency(ival);
}
sprintf(answer,"%d",myDet->setReadReceiverFrequency());
return string(answer);
}
else
return string("could not decode command");
}
@ -3685,10 +3699,12 @@ string slsDetectorCommand::helpReceiver(int narg, char *args[], int action) {
ostringstream os;
if (action==PUT_ACTION || action==HELP_ACTION)
os << "receiver [status] \t starts/stops the receiver to listen to detector packets. - can be start or stop" << std::endl;
os << "r_readfreq \t sets the gui read frequency of the receiver, 0 if gui requests frame, >0 if receiver sends every nth frame to gui" << std::endl;
if (action==GET_ACTION || action==HELP_ACTION){
os << "receiver \t returns the status of receiver - can be running or idle" << std::endl;
os << "framescaught \t returns the number of frames caught by receiver(average for multi)" << std::endl;
os << "frameindex \t returns the current frame index of receiver(average for multi)" << std::endl;
os << "r_readfreq \t returns the gui read frequency of the receiver" << std::endl;
}
return os.str();

View File

@ -672,6 +672,14 @@ virtual int setROI(int n=-1,ROI roiLimits[]=NULL)=0;
*/
virtual ROI* getROI(int &n)=0;
/** Sets the variable readRxrFrequency.
if Receiver read upon gui request, readRxrFrequency=0,
else every nth frame to be sent to gui
/returns read receiver frequency
*/
virtual int setReadReceiverFrequency(int i=-1)=0;
protected:

View File

@ -398,11 +398,14 @@ void* postProcessing::processData(int delflag) {
if (checkJoinThread()) break;
usleep(200000);
}
*/
*/
/*if(setReadReceiverFrequency()>0)) ******Not implemented yet ********
* else
*/
pthread_mutex_lock(&mg);
pthread_mutex_lock(&mg);
int prevCaught=getReceiverCurrentFrameIndex();
pthread_mutex_unlock(&mg);
pthread_mutex_unlock(&mg);
int caught=0;
bool newData=false;
@ -446,10 +449,11 @@ void* postProcessing::processData(int delflag) {
}
}
else{
cout<<"****Detector returned mismatched indeices***"<<endl;
cout<<"****Detector returned mismatched indices/garbage. Trying again.***"<<endl;
}
}
}
}
return 0;

View File

@ -56,6 +56,7 @@ slsReceiverFunctionList::slsReceiverFunctionList():
guiData(NULL),
guiFileName(NULL),
currframenum(0),
nFrameToGui(0),
writeReceiverData(0),
pwriteReceiverDataArg(0),
startAcquisitionCallBack(NULL),
@ -410,6 +411,9 @@ int slsReceiverFunctionList::startWriting(){
cout << "Max Frames Per File:" << maxFramesPerFile << endl;
if (writeReceiverData)
cout << "Note: Data Write has been defined exernally" << endl;
if(nFrameToGui)
cout << " Not implemented yet: Sending every " << nFrameToGui << "th frame to gui" << endl;
cout << "Ready!" << endl;
//by default, we read/write everything
@ -485,12 +489,15 @@ int slsReceiverFunctionList::startWriting(){
} else {
if(sfilefd)
fwrite(wbuf, 1, bufferSize, sfilefd);
else
else{
cout << "You do not have permissions to overwrite: " << savefilename << endl;
usleep(50000);
}
}
}
//copies gui data and sets/resets guiDataReady
if(guiData){
//if (cbAction>=2)
@ -501,6 +508,7 @@ int slsReceiverFunctionList::startWriting(){
guiDataReady=0;
framesInFile++;
// delete [] dataWriteFrame->buffer;
fifofree->push(wbuf);

View File

@ -13,10 +13,12 @@
#include "genericSocket.h"
#include "circularFifo.h"
#include <string.h>
#include <pthread.h>
#include <stdio.h>
/**
* @short does all the functions for a receiver, set/get parameters, start/stop etc.
*/
@ -185,6 +187,12 @@ public:
*/
int setShortFrame(int i);
/**
* Set the variable to send every nth frame to gui
* or if 0,send frame only upon gui request
*/
int setNFrameToGui(int i){if(i>=0) nFrameToGui = i; return nFrameToGui;};
/**
* Register call back function to write receiver data
*/
@ -298,6 +306,11 @@ private:
/** current frame number */
int currframenum;
/** send every nth frame to gui or only upon gui request*/
int nFrameToGui;
/** register for call back to get data */
int (*writeReceiverData)(char*,int,FILE*,void*);
void *pwriteReceiverDataArg;
@ -343,6 +356,9 @@ private:
* 2 we open, close, write file, callback does not do anything */
int cbAction;
public:
/** File Descriptor */
static FILE *sfilefd;
@ -350,6 +366,7 @@ public:
/** if the listening thread is running*/
static int listening_thread_running;
/**
callback arguments are
filepath
@ -365,7 +382,6 @@ public:
*/
void registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg){startAcquisitionCallBack=func; pStartAcquisition=arg;};
/**
callback argument is
toatal frames caught
@ -373,8 +389,6 @@ public:
*/
void registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg){acquisitionFinishedCallBack=func; pAcquisitionFinished=arg;};
/**
args to raw data ready callback are
framenum
@ -383,10 +397,6 @@ public:
guidatapointer (NULL, no data required)
*/
void registerCallBackRawDataReady(void (*func)(int, char*, FILE*, char*, void*),void *arg){rawDataReadyCallBack=func; pRawDataReady=arg;};
};

View File

@ -181,6 +181,8 @@ int slsReceiverFuncs::function_table(){
flist[F_GET_FRAME_INDEX] = &slsReceiverFuncs::get_frame_index;
flist[F_RESET_FRAMES_CAUGHT] = &slsReceiverFuncs::reset_frames_caught;
flist[F_READ_FRAME] = &slsReceiverFuncs::read_frame;
flist[F_READ_ALL] = &slsReceiverFuncs::read_all;
flist[F_READ_RECEIVER_FREQUENCY]= &slsReceiverFuncs::set_read_frequency;
flist[F_ENABLE_FILE_WRITE] = &slsReceiverFuncs::enable_file_write;
flist[F_GET_ID] = &slsReceiverFuncs::get_version;
flist[F_CONFIGURE_MAC] = &slsReceiverFuncs::set_short_frame;
@ -860,8 +862,8 @@ int slsReceiverFuncs::read_frame(){
count++;
}
if ((count==20) || (count == -1)){
if (count == -20)
if ((count==10) || (count == -1)){
if (count == -10)
cout << "same type: index:" << index << "\tindex2:" << index2 << endl;
else
cout << "no data to read for gui" << endl;
@ -914,6 +916,56 @@ int slsReceiverFuncs::read_frame(){
int slsReceiverFuncs::set_read_frequency(){
ret=OK;
int retval=-1;
int index;
strcpy(mess,"Could not set receiver read frequency\n");
// receive arguments
if(socket->ReceiveDataOnly(&index,sizeof(index)) < 0 ){
strcpy(mess,"Error reading from socket\n");
ret = FAIL;
}
// execute action if the arguments correctly arrived
#ifdef SLS_RECEIVER_FUNCTION_LIST
if (ret==OK) {
if (lockStatus==1 && socket->differentClients==1){//necessary???
sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP);
ret=FAIL;
}
else
retval=slsReceiverList->setNFrameToGui(index);
}
#endif
if(ret==OK && socket->differentClients){
cout << "Force update" << endl;
ret=FORCE_UPDATE;
}
// send answer
socket->SendDataOnly(&ret,sizeof(ret));
if(ret==FAIL)
socket->SendDataOnly(mess,sizeof(mess));
socket->SendDataOnly(&retval,sizeof(retval));
//return ok/fail
return ret;
}
/**needs to be implemented */
int slsReceiverFuncs::read_all(){
return ret;
}

View File

@ -124,6 +124,12 @@ public:
/** Reads Frame/ buffer */
int read_frame();
/** Sets the receiver to send every nth frame to gui, or only upon gui request */
int set_read_frequency();
/** Reads every nth frame, sends them to gui without closing socket */
int read_all();
/** Enable File Write*/
int enable_file_write();