semaphores , no usleep in receiver

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@660 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
l_maliakal_d 2013-09-04 13:10:14 +00:00
parent 594c6895f8
commit 57d65fd59c
17 changed files with 338 additions and 234 deletions

View File

@ -2,10 +2,10 @@
#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/eigerDetectorServer"
//#define SVNREPPATH ""
#define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3"
//#define SVNREV 0x658
//#define SVNREV 0x659
//#define SVNKIND ""
//#define SVNSCHED ""
#define SVNAUTH "l_maliakal_d"
#define SVNREV 0x658
#define SVNDATE 0x20130827
#define SVNREV 0x659
#define SVNDATE 0x20130829
//

View File

@ -2,10 +2,10 @@
#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/gotthardDetectorServer"
//#define SVNREPPATH ""
#define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3"
//#define SVNREV 0x658
//#define SVNREV 0x659
//#define SVNKIND ""
//#define SVNSCHED ""
#define SVNAUTH "l_maliakal_d"
#define SVNREV 0x658
#define SVNDATE 0x20130827
#define SVNREV 0x659
#define SVNDATE 0x20130829
//

View File

@ -2,10 +2,10 @@
#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/moenchDetectorServer"
//#define SVNREPPATH ""
#define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3"
//#define SVNREV 0x658
//#define SVNREV 0x659
//#define SVNKIND ""
//#define SVNSCHED ""
#define SVNAUTH "l_maliakal_d"
#define SVNREV 0x658
#define SVNDATE 0x20130827
#define SVNREV 0x659
#define SVNDATE 0x20130829
//

View File

@ -4346,7 +4346,32 @@ int multiSlsDetector::stopReceiver(){
}
slsDetectorDefs::runStatus multiSlsDetector::startReceiverReadout(){
runStatus s,s1;
if (thisMultiDetector->masterPosition>=0)
if (detectors[thisMultiDetector->masterPosition]){
s = detectors[thisMultiDetector->masterPosition]->startReceiverReadout();
if(detectors[thisMultiDetector->masterPosition]->getErrorMask())
setErrorMask(getErrorMask()|(1<<thisMultiDetector->masterPosition));
return s;
}
if (detectors[0]) s=detectors[0]->startReceiverReadout();
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
s1=detectors[i]->startReceiverReadout();
if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i));
if (s1==ERROR)
s=ERROR;
if (s1==IDLE && s!=IDLE)
s=ERROR;
}
return s;
}
slsDetectorDefs::runStatus multiSlsDetector::getReceiverStatus(){

View File

@ -1110,6 +1110,12 @@ class multiSlsDetector : public slsDetectorUtils {
*/
int stopReceiver();
/** Sets the receiver to start any readout remaining in the fifo and
* change status to transmitting.
* The status changes to run_finished when fifo is empty
*/
runStatus startReceiverReadout();
/** gets the status of the listening mode of receiver
\returns status
*/

View File

@ -2,10 +2,10 @@
#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/mythenDetectorServer"
//#define SVNREPPATH ""
#define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3"
//#define SVNREV 0x658
//#define SVNREV 0x659
//#define SVNKIND ""
//#define SVNSCHED ""
#define SVNAUTH "l_maliakal_d"
#define SVNREV 0x658
#define SVNDATE 0x20130827
#define SVNREV 0x659
#define SVNDATE 0x20130829
//

View File

@ -5990,6 +5990,29 @@ int slsDetector::stopReceiver(){
slsDetectorDefs::runStatus slsDetector::startReceiverReadout(){
int fnum=F_START_READOUT;
int ret = FAIL;
int retval=-1;
runStatus s=ERROR;
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
#ifdef VERBOSE
std::cout << "Starting Receiver Readout" << std::endl;
#endif
if (connectData() == OK)
ret=thisReceiver->getInt(fnum,retval);
if(retval!=-1)
s=(runStatus)retval;
if(ret==FORCE_UPDATE)
ret=updateReceiver();
}
return s;
}
int slsDetector::detectorSendToReceiver(bool set){
int fnum;
if(set) fnum=F_START_RECEIVER;

View File

@ -1474,6 +1474,12 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
*/
int stopReceiver();
/** Sets the receiver to start any readout remaining in the fifo and
* change status to transmitting.
* The status changes to run_finished when fifo is empty
*/
runStatus startReceiverReadout();
/** Sets(false) or Resets(true) the CPU bit in detector
\returns OK or FAIL
*/

View File

@ -485,6 +485,12 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef
*/
virtual int setReadReceiverFrequency(int getFromReceiver, int i=-1)=0;
/** Sets the receiver to start any readout remaining in the fifo and
* change status to transmitting.
* The status changes to run_finished when fifo is empty
*/
virtual runStatus startReceiverReadout()=0;
/** returns detector type string from detector type index
\param t string can be Mythen, Pilatus, Eiger, Gotthard, Agipd, Unknown

View File

@ -311,8 +311,9 @@ void slsDetectorUtils::acquire(int delflag){
break;
pthread_mutex_lock(&mg);
if(setReceiverOnline()==OFFLINE_FLAG){
pthread_mutex_lock(&mg);
// wait until data processing thread has finished the data
#ifdef VERBOSE
@ -329,11 +330,21 @@ void slsDetectorUtils::acquire(int delflag){
if((*correctionMask)&(1<<WRITE_FILE))
closeDataFile();
}
}else
stopReceiver();
pthread_mutex_unlock(&mg);
}else{
pthread_mutex_lock(&mg);
if(startReceiverReadout() == TRANSMITTING){
while(getReceiverStatus() != RUN_FINISHED){
pthread_mutex_unlock(&mg);
usleep(50000);
pthread_mutex_lock(&mg);
}
}
stopReceiver();
pthread_mutex_unlock(&mg);
}

View File

@ -2,10 +2,10 @@
#define SVNURLLIB "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware"
//#define SVNREPPATH ""
#define SVNREPUUIDLIB "951219d9-93cf-4727-9268-0efd64621fa3"
//#define SVNREV 0x658
//#define SVNREV 0x659
//#define SVNKIND ""
//#define SVNSCHED ""
#define SVNAUTHLIB "l_maliakal_d"
#define SVNREVLIB 0x658
#define SVNDATELIB 0x20130827
#define SVNREVLIB 0x659
#define SVNDATELIB 0x20130829
//

View File

@ -422,7 +422,8 @@ void* postProcessing::processData(int delflag) {
int prevCaught=-1;
int caught=0;
int caught = 0;
int prog = 0;
bool newData=false;
char currentfName[MAX_STR_LENGTH]="";
int currentfIndex=0;
@ -451,11 +452,11 @@ void* postProcessing::processData(int delflag) {
//get progress
pthread_mutex_lock(&mg);
if(setReceiverOnline()==ONLINE_FLAG)
caught=getReceiverCurrentFrameIndex();
prog=getFramesCaughtByReceiver();//caught=getReceiverCurrentFrameIndex();
pthread_mutex_unlock(&mg);
if(setReceiverOnline()==OFFLINE_FLAG)
caught=prevCaught;
setCurrentProgress(caught);
prog=prevCaught;
setCurrentProgress(prog);
if (checkJoinThread()) break;
@ -463,8 +464,9 @@ void* postProcessing::processData(int delflag) {
if (dataReady){
// determine if new Data for random read
// new Data? for random read
if (!read_freq){
caught = prog;
if (caught > prevCaught)
newData=true;
else
@ -485,6 +487,8 @@ void* postProcessing::processData(int delflag) {
pthread_mutex_lock(&mg);
int* receiverData = readFrameFromReceiver(currentfName,currentfIndex);//if(currentfIndex!=-1)cout<<"--currentfIndex:"<<currentfIndex<<endl;
pthread_mutex_unlock(&mg);
//if detector returned null
if(setReceiverOnline()==OFFLINE_FLAG)
receiverData = NULL;
if(receiverData == NULL){
@ -494,13 +498,14 @@ void* postProcessing::processData(int delflag) {
// determine if new Data for nth frame read
if (read_freq){
caught = currentfIndex;
#ifdef VERBOSE
std::cout << "caught:" << caught << " prevcaught:" << prevCaught << std::endl;
#endif
//delete if not new data
if((caught == prevCaught) || (caught == -1))
currentfIndex = -1;
else if (currentfIndex!=-1)
else
prevCaught=caught;
}

View File

@ -24,47 +24,48 @@ FILE* slsReceiverFunctionList::sfilefd(NULL);
int slsReceiverFunctionList::receiver_threads_running(0);
slsReceiverFunctionList::slsReceiverFunctionList(detectorType det,bool moenchwithGotthardTest):
myDetectorType(det),
maxFramesPerFile(MAX_FRAMES_PER_FILE),
enableFileWrite(1),
fileIndex(0),
frameIndexNeeded(0),
framesCaught(0),
acqStarted(false),
measurementStarted(false),
startFrameIndex(0),
frameIndex(0),
totalFramesCaught(0),
startAcquisitionIndex(0),
acquisitionIndex(0),
framesInFile(0),
prevframenum(0),
listening_thread_running(0),
writing_thread_running(0),
status(IDLE),
latestData(NULL),
udpSocket(NULL),
server_port(DEFAULT_UDP_PORTNO),
fifo(NULL),
fifofree(NULL),
fifosize(GOTTHARD_FIFO_SIZE),
shortFrame(-1),
bufferSize(GOTTHARD_BUFFER_SIZE),
packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME),
guiDataReady(0),
guiData(NULL),
guiFileName(NULL),
currframenum(0),
nFrameToGui(0),
startAcquisitionCallBack(NULL),
pStartAcquisition(NULL),
acquisitionFinishedCallBack(NULL),
pAcquisitionFinished(NULL),
rawDataReadyCallBack(NULL),
pRawDataReady(NULL),
withGotthard(moenchwithGotthardTest),
frameIndexMask(GOTTHARD_FRAME_INDEX_MASK),
frameIndexOffset(GOTTHARD_FRAME_INDEX_OFFSET)
myDetectorType(det),
maxFramesPerFile(MAX_FRAMES_PER_FILE),
enableFileWrite(1),
fileIndex(0),
frameIndexNeeded(0),
framesCaught(0),
acqStarted(false),
measurementStarted(false),
startFrameIndex(0),
frameIndex(0),
totalFramesCaught(0),
startAcquisitionIndex(0),
acquisitionIndex(0),
framesInFile(0),
prevframenum(0),
listening_thread_running(0),
writing_thread_running(0),
status(IDLE),
latestData(NULL),
udpSocket(NULL),
server_port(DEFAULT_UDP_PORTNO),
fifo(NULL),
fifofree(NULL),
fifosize(GOTTHARD_FIFO_SIZE),
shortFrame(-1),
bufferSize(GOTTHARD_BUFFER_SIZE),
packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME),
guiDataReady(0),
guiData(NULL),
guiFileName(NULL),
currframenum(0),
nFrameToGui(0),
startAcquisitionCallBack(NULL),
pStartAcquisition(NULL),
acquisitionFinishedCallBack(NULL),
pAcquisitionFinished(NULL),
rawDataReadyCallBack(NULL),
pRawDataReady(NULL),
withGotthard(moenchwithGotthardTest),
frameIndexMask(GOTTHARD_FRAME_INDEX_MASK),
frameIndexOffset(GOTTHARD_FRAME_INDEX_OFFSET)
{
int aligned_frame_size = GOTTHARD_ALIGNED_FRAME_SIZE;
@ -110,6 +111,7 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det,bool moenchwit
pthread_mutex_init(&status_mutex,NULL);
pthread_mutex_init(&dataReadyMutex,NULL);
}
@ -216,30 +218,24 @@ int slsReceiverFunctionList::startReceiver(char message[]){
cout << "Starting new acquisition threadddd ...." << endl;
#endif
//change status
while(1){
if(!pthread_mutex_trylock(&(status_mutex))){
status = IDLE;
listening_thread_running = 0;
writing_thread_running = 0;
receiver_threads_running = 1;
pthread_mutex_unlock(&(status_mutex));
break;
}
}
pthread_mutex_lock(&status_mutex);
status = IDLE;
listening_thread_running = 0;
writing_thread_running = 0;
receiver_threads_running = 1;
pthread_mutex_unlock(&(status_mutex));
// creating listening thread----------
err = pthread_create(&listening_thread, NULL,startListeningThread, (void*) this);
if(err){
//change status
while(1){
if(!pthread_mutex_trylock(&(status_mutex))){
status = IDLE;
listening_thread_running = 0;
receiver_threads_running = 0;
pthread_mutex_unlock(&(status_mutex));
break;
}
}
pthread_mutex_lock(&status_mutex);
status = IDLE;
listening_thread_running = 0;
receiver_threads_running = 0;
pthread_mutex_unlock(&(status_mutex));
sprintf(message,"Cant create listening thread. Status:%d\n",status);
cout << endl << message << endl;
return FAIL;
@ -251,7 +247,7 @@ int slsReceiverFunctionList::startReceiver(char message[]){
return FAIL;
}
#ifdef VERBOSE
cout << "Listening thread created successfully." << endl;
cout << "Listening thread created successfully." << endl;
#endif
// creating writing thread----------
@ -259,15 +255,12 @@ int slsReceiverFunctionList::startReceiver(char message[]){
err = pthread_create(&writing_thread, NULL,startWritingThread, (void*) this);
if(err){
//change status
while(1){
if(!pthread_mutex_trylock(&(status_mutex))){
status = IDLE;
writing_thread_running = 0;
receiver_threads_running = 0;
pthread_mutex_unlock(&(status_mutex));
break;
}
}
pthread_mutex_lock(&status_mutex);
status = IDLE;
writing_thread_running = 0;
receiver_threads_running = 0;
pthread_mutex_unlock(&(status_mutex));
//stop listening thread
pthread_join(listening_thread,NULL);
sprintf(message,"Cant create writing thread. Status:%d\n",status);
@ -286,13 +279,9 @@ int slsReceiverFunctionList::startReceiver(char message[]){
//change status----------
while(1){
if(!pthread_mutex_trylock(&(status_mutex))){
status = RUNNING;
pthread_mutex_unlock(&(status_mutex));
break;
}
}
pthread_mutex_lock(&status_mutex);
status = RUNNING;
pthread_mutex_unlock(&(status_mutex));
cout << "Threads created successfully." << endl;
@ -319,6 +308,9 @@ int slsReceiverFunctionList::startReceiver(char message[]){
}
//initialize semaphore
sem_init(&smp,0,1);
return OK;
}
@ -337,25 +329,24 @@ int slsReceiverFunctionList::stopReceiver(){
cout << "Stopping new acquisition threadddd ...." << endl;
#endif
//stop listening thread
while(1){
if(!pthread_mutex_trylock(&(status_mutex))){
receiver_threads_running=0;
pthread_mutex_unlock(&(status_mutex));
break;
}
}
pthread_mutex_lock(&status_mutex);
receiver_threads_running=0;
pthread_mutex_unlock(&(status_mutex));
if(udpSocket) udpSocket->ShutDownSocket();
pthread_join(listening_thread,NULL);
pthread_join(writing_thread,NULL);
}
//change status
while(1){
if(!pthread_mutex_trylock(&(status_mutex))){
status = IDLE;
pthread_mutex_unlock(&(status_mutex));
break;
}
}
pthread_mutex_lock(&status_mutex);
status = IDLE;
pthread_mutex_unlock(&(status_mutex));
//semaphore destroy
sem_post(&smp);
sem_destroy(&smp);
cout << "Receiver Stopped.\nStatus:" << status << endl;
return OK;
}
@ -404,7 +395,7 @@ int slsReceiverFunctionList::startListening(){
// from the manual
sysctl -w net.core.rmem_max=16777216
sysctl -w net.core.netdev_max_backlog=250000
*/
*/
//creating udp socket
if (strchr(eth,'.')!=NULL) strcpy(eth,"");
@ -423,26 +414,19 @@ int slsReceiverFunctionList::startListening(){
#ifdef VERBOSE
std::cout<< "Could not create UDP socket "<< server_port << std::endl;
#endif
while(1){
if(!pthread_mutex_trylock(&(status_mutex))){
listening_thread_running = -1;
pthread_mutex_unlock(&(status_mutex));
break;
}
}
pthread_mutex_lock(&status_mutex);
listening_thread_running = -1;
pthread_mutex_unlock(&status_mutex);
break;
}
while (receiver_threads_running) {
while(1){
if(!pthread_mutex_trylock(&(status_mutex))){
listening_thread_running = 1;
pthread_mutex_unlock(&(status_mutex));
break;
}
}
pthread_mutex_lock(&status_mutex);
listening_thread_running = 1;
pthread_mutex_unlock(&(status_mutex));
if (!fifofree->isEmpty()) {
fifofree->pop(buffer);
@ -455,9 +439,9 @@ int slsReceiverFunctionList::startListening(){
//start for each scan
if(!measurementStarted){
if(!frameIndexOffset)
startFrameIndex = ((uint32_t)(*((uint32_t*)buffer)));
startFrameIndex = ((uint32_t)(*((uint32_t*)buffer)));
else
startFrameIndex = ((((uint32_t)(*((uint32_t*)buffer))) & (frameIndexMask)) >> frameIndexOffset);
startFrameIndex = ((((uint32_t)(*((uint32_t*)buffer))) & (frameIndexMask)) >> frameIndexOffset);
cout<<"startFrameIndex:"<<startFrameIndex<<endl;
prevframenum=startFrameIndex;
@ -490,14 +474,11 @@ int slsReceiverFunctionList::startListening(){
}
}
} while (receiver_threads_running);
while(1){
if(!pthread_mutex_trylock(&(status_mutex))){
receiver_threads_running=0;
status = IDLE;
pthread_mutex_unlock(&(status_mutex));
break;
}
}
pthread_mutex_lock(&status_mutex);
receiver_threads_running=0;
status = IDLE;
pthread_mutex_unlock(&status_mutex);
//Close down any open socket descriptors
udpSocket->Disconnect();
@ -539,6 +520,8 @@ int slsReceiverFunctionList::startWriting(){
if(sfilefd) sfilefd=NULL;
strcpy(savefilename,"");
//reset this before each acq or you send old data
guiData = NULL;
guiDataReady=0;
@ -563,6 +546,7 @@ int slsReceiverFunctionList::startWriting(){
cout << "Ready!" << endl;
//will always run till acquisition over and then runs till fifo is empty
while(receiver_threads_running || (!fifo->isEmpty())){
//start a new file
@ -581,13 +565,9 @@ int slsReceiverFunctionList::startWriting(){
if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){
cout << "Error: Could not create file " << savefilename << endl;
while(1){
if(!pthread_mutex_trylock(&(status_mutex))){
writing_thread_running = -1;
pthread_mutex_unlock(&(status_mutex));
break;
}
}
pthread_mutex_lock(&status_mutex);
writing_thread_running = -1;
pthread_mutex_unlock(&(status_mutex));
break;
}
@ -612,13 +592,10 @@ int slsReceiverFunctionList::startWriting(){
}
}
while(1){
if(!pthread_mutex_trylock(&(status_mutex))){
writing_thread_running = 1;
pthread_mutex_unlock(&(status_mutex));
break;
}
}
pthread_mutex_lock(&status_mutex);
writing_thread_running = 1;
pthread_mutex_unlock(&(status_mutex));
//if(prevframenum != 0){
if(framesCaught){
@ -628,99 +605,93 @@ int slsReceiverFunctionList::startWriting(){
}
//pop fifo
if(!fifo->isEmpty()){
if(fifo->pop(wbuf)){
framesCaught++;
totalFramesCaught++;
if(!frameIndexOffset)
currframenum = (uint32_t)(*((uint32_t*)wbuf));
else
currframenum = (((uint32_t)(*((uint32_t*)wbuf))) & (frameIndexMask)) >> frameIndexOffset;
framesCaught++;
totalFramesCaught++;
if(!frameIndexOffset)
currframenum = (uint32_t)(*((uint32_t*)wbuf));
else
currframenum = (((uint32_t)(*((uint32_t*)wbuf))) & (frameIndexMask)) >> frameIndexOffset;
//cout<<"**************curreframenm:"<<currframenum<<endl;
//cout<<"currframenum:"<<currframenum<<endl;
//write data call back
if (cbAction < DO_EVERYTHING) {
rawDataReadyCallBack(currframenum, wbuf, bufferSize, sfilefd, guiData,pRawDataReady);
}
//default writing to file
else if(enableFileWrite){
if(sfilefd)
fwrite(wbuf, 1, bufferSize, sfilefd);
else{
cout << "You do not have permissions to overwrite: " << savefilename << endl;
usleep(50000);
}
}
//does not read every frame
if(!nFrameToGui){
if(guiData){
memcpy(latestData,wbuf,bufferSize);
strcpy(guiFileName,savefilename);
guiDataReady=1;
}else
guiDataReady=0;
}
//reads every nth frame
//write data call back
if (cbAction < DO_EVERYTHING) {
rawDataReadyCallBack(currframenum, wbuf, bufferSize, sfilefd, guiData,pRawDataReady);
}
//default writing to file
else if(enableFileWrite){
if(sfilefd)
fwrite(wbuf, 1, bufferSize, sfilefd);
else{
if(frameFactor){
frameFactor--;
}else{
frameFactor = nFrameToGui-1;
//catch nth frame: gui ready to copy data
while(guiData==NULL){
if(!receiver_threads_running)
break;
usleep(10000);
guiDataReady=0;
}
//copies gui data and sets/resets guiDataReady
memcpy(latestData,wbuf,bufferSize);
strcpy(guiFileName,savefilename);
guiDataReady=1;
//catch nth frame: wait for gui to take data
while(guiData==latestData){
if(!receiver_threads_running)
break;
usleep(100000);
}
guiDataReady=0;
}
cout << "You do not have permissions to overwrite: " << savefilename << endl;
usleep(50000);
}
}
//does not read every frame
if(!nFrameToGui){
if(guiData){
memcpy(latestData,wbuf,bufferSize);
strcpy(guiFileName,savefilename);
pthread_mutex_lock(&dataReadyMutex);
guiDataReady=1;
pthread_mutex_unlock(&dataReadyMutex);
}else{
pthread_mutex_lock(&dataReadyMutex);
guiDataReady=0;
pthread_mutex_unlock(&dataReadyMutex);
}
}
//reads every nth frame
else{
if(frameFactor){
frameFactor--;
}else{
frameFactor = nFrameToGui-1;
//block current process if the guireader hasnt read it yet
sem_wait(&smp);
//copy data and set guidataready
memcpy(latestData,wbuf,bufferSize);
strcpy(guiFileName,savefilename);
pthread_mutex_lock(&dataReadyMutex);
guiDataReady = 1;
pthread_mutex_unlock(&dataReadyMutex);
framesInFile++;
fifofree->push(wbuf);
}
}
framesInFile++;
fifofree->push(wbuf);
}
}
else{//cout<<"************************fifo empty**********************************"<<endl;
sleepnumber++;
usleep(50000);
//change status to idle if the fifo is empty and status is transmitting
if(status == TRANSMITTING){
pthread_mutex_lock(&status_mutex);
status = RUN_FINISHED;
pthread_mutex_unlock(&(status_mutex));
cout << "Status: Run Finished" << endl;
}else{
sleepnumber++;
usleep(50000);
}
}
}
while(1){
if(!pthread_mutex_trylock(&(status_mutex))){
receiver_threads_running=0;
pthread_mutex_unlock(&(status_mutex));
break;
}
}
pthread_mutex_lock(&status_mutex);
receiver_threads_running=0;
pthread_mutex_unlock(&status_mutex);
cout << "RealTime Frames Caught:" << framesCaught << endl;
cout << "Total Frames Caught:"<< totalFramesCaught << endl;
if(sfilefd){
#ifdef VERBOSE
cout << "sfield:" << (int)sfilefd << endl;
cout << "sfield:" << (int)sfilefd << endl;
#endif
fclose(sfilefd);
sfilefd = NULL;
@ -741,14 +712,11 @@ int slsReceiverFunctionList::startWriting(){
void slsReceiverFunctionList::readFrame(char* c,char** raw){
//point to gui data
if (guiData == NULL)
guiData = latestData;
//copy data and filename
strcpy(c,guiFileName);
//could not get gui data
if(!guiDataReady){
*raw = NULL;
@ -757,6 +725,13 @@ void slsReceiverFunctionList::readFrame(char* c,char** raw){
else{
*raw = guiData;
guiData = NULL;
pthread_mutex_lock(&dataReadyMutex);
guiDataReady = 0;
pthread_mutex_unlock(&dataReadyMutex);
if((nFrameToGui) && (receiver_threads_running)){
//release after getting data
sem_post(&smp);
}
}
}
@ -781,5 +756,13 @@ int slsReceiverFunctionList::setShortFrame(int i){
}
void slsReceiverFunctionList::startReadout(){
pthread_mutex_lock(&status_mutex);
status = TRANSMITTING;
pthread_mutex_unlock(&status_mutex);
cout << "Status: Transmitting" << endl;
}
#endif

View File

@ -17,6 +17,7 @@
#include <string.h>
#include <pthread.h>
#include <stdio.h>
#include <semaphore.h>
/**
@ -202,6 +203,10 @@ public:
*/
int setNFrameToGui(int i){if(i>=0) nFrameToGui = i; return nFrameToGui;};
/** set status to transmitting and
* when fifo is empty later, sets status to run_finished */
void startReadout();
private:
/** detector type */
@ -385,8 +390,11 @@ private:
/** frame index offset */
int frameIndexOffset;
/** semaphore to synchronize writer and guireader threads */
sem_t smp;
/** guiDataReady mutex */
pthread_mutex_t dataReadyMutex;
public:

View File

@ -285,6 +285,7 @@ int slsReceiverFuncs::function_table(){
flist[F_ENABLE_FILE_WRITE] = &slsReceiverFuncs::enable_file_write;
flist[F_GET_ID] = &slsReceiverFuncs::get_version;
flist[F_CONFIGURE_MAC] = &slsReceiverFuncs::set_short_frame;
flist[F_START_READOUT] = &slsReceiverFuncs::start_readout;
//General Functions
flist[F_LOCK_SERVER] = &slsReceiverFuncs::lock_receiver;
@ -1374,7 +1375,33 @@ int slsReceiverFuncs::get_version(){
int slsReceiverFuncs::start_readout(){
ret=OK;
enum runStatus retval;
// execute action if the arguments correctly arrived
#ifdef SLS_RECEIVER_FUNCTION_LIST
slsReceiverList->startReadout();
retval = slsReceiverList->getStatus();
if((retval == TRANSMITTING) || (retval == RUN_FINISHED))
ret = OK;
else
ret = FAIL;
#endif
if(socket->differentClients){
cout << "Force update" << endl;
ret=FORCE_UPDATE;
}
// send answer
socket->SendDataOnly(&ret,sizeof(ret));
socket->SendDataOnly(&retval,sizeof(retval));
//return ok/fail
return ret;
}

View File

@ -143,6 +143,10 @@ public:
/** Get Version */
int get_version();
/** set status to transmitting and
* when fifo is empty later, sets status to run_finished */
int start_readout();
//General Functions
/** Locks Receiver */

View File

@ -2,10 +2,10 @@
#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/slsReceiver"
//#define SVNREPPATH ""
#define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3"
//#define SVNREV 0x658
//#define SVNREV 0x659
//#define SVNKIND ""
//#define SVNSCHED ""
#define SVNAUTH "l_maliakal_d"
#define SVNREV 0x658
#define SVNDATE 0x20130827
#define SVNREV 0x659
#define SVNDATE 0x20130829
//