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 SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/eigerDetectorServer"
//#define SVNREPPATH "" //#define SVNREPPATH ""
#define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3" #define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3"
//#define SVNREV 0x658 //#define SVNREV 0x659
//#define SVNKIND "" //#define SVNKIND ""
//#define SVNSCHED "" //#define SVNSCHED ""
#define SVNAUTH "l_maliakal_d" #define SVNAUTH "l_maliakal_d"
#define SVNREV 0x658 #define SVNREV 0x659
#define SVNDATE 0x20130827 #define SVNDATE 0x20130829
// //

View File

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

View File

@ -2,10 +2,10 @@
#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/moenchDetectorServer" #define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/moenchDetectorServer"
//#define SVNREPPATH "" //#define SVNREPPATH ""
#define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3" #define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3"
//#define SVNREV 0x658 //#define SVNREV 0x659
//#define SVNKIND "" //#define SVNKIND ""
//#define SVNSCHED "" //#define SVNSCHED ""
#define SVNAUTH "l_maliakal_d" #define SVNAUTH "l_maliakal_d"
#define SVNREV 0x658 #define SVNREV 0x659
#define SVNDATE 0x20130827 #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(){ slsDetectorDefs::runStatus multiSlsDetector::getReceiverStatus(){

View File

@ -1110,6 +1110,12 @@ class multiSlsDetector : public slsDetectorUtils {
*/ */
int stopReceiver(); 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 /** gets the status of the listening mode of receiver
\returns status \returns status
*/ */

View File

@ -2,10 +2,10 @@
#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/mythenDetectorServer" #define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware/mythenDetectorServer"
//#define SVNREPPATH "" //#define SVNREPPATH ""
#define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3" #define SVNREPUUID "951219d9-93cf-4727-9268-0efd64621fa3"
//#define SVNREV 0x658 //#define SVNREV 0x659
//#define SVNKIND "" //#define SVNKIND ""
//#define SVNSCHED "" //#define SVNSCHED ""
#define SVNAUTH "l_maliakal_d" #define SVNAUTH "l_maliakal_d"
#define SVNREV 0x658 #define SVNREV 0x659
#define SVNDATE 0x20130827 #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 slsDetector::detectorSendToReceiver(bool set){
int fnum; int fnum;
if(set) fnum=F_START_RECEIVER; if(set) fnum=F_START_RECEIVER;

View File

@ -1474,6 +1474,12 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
*/ */
int stopReceiver(); 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 /** Sets(false) or Resets(true) the CPU bit in detector
\returns OK or FAIL \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; 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 /** returns detector type string from detector type index
\param t string can be Mythen, Pilatus, Eiger, Gotthard, Agipd, Unknown \param t string can be Mythen, Pilatus, Eiger, Gotthard, Agipd, Unknown

View File

@ -311,8 +311,9 @@ void slsDetectorUtils::acquire(int delflag){
break; break;
pthread_mutex_lock(&mg);
if(setReceiverOnline()==OFFLINE_FLAG){ if(setReceiverOnline()==OFFLINE_FLAG){
pthread_mutex_lock(&mg);
// wait until data processing thread has finished the data // wait until data processing thread has finished the data
#ifdef VERBOSE #ifdef VERBOSE
@ -329,11 +330,21 @@ void slsDetectorUtils::acquire(int delflag){
if((*correctionMask)&(1<<WRITE_FILE)) if((*correctionMask)&(1<<WRITE_FILE))
closeDataFile(); closeDataFile();
} }
}else
stopReceiver();
pthread_mutex_unlock(&mg); 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 SVNURLLIB "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware"
//#define SVNREPPATH "" //#define SVNREPPATH ""
#define SVNREPUUIDLIB "951219d9-93cf-4727-9268-0efd64621fa3" #define SVNREPUUIDLIB "951219d9-93cf-4727-9268-0efd64621fa3"
//#define SVNREV 0x658 //#define SVNREV 0x659
//#define SVNKIND "" //#define SVNKIND ""
//#define SVNSCHED "" //#define SVNSCHED ""
#define SVNAUTHLIB "l_maliakal_d" #define SVNAUTHLIB "l_maliakal_d"
#define SVNREVLIB 0x658 #define SVNREVLIB 0x659
#define SVNDATELIB 0x20130827 #define SVNDATELIB 0x20130829
// //

View File

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

View File

@ -66,6 +66,7 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det,bool moenchwit
frameIndexMask(GOTTHARD_FRAME_INDEX_MASK), frameIndexMask(GOTTHARD_FRAME_INDEX_MASK),
frameIndexOffset(GOTTHARD_FRAME_INDEX_OFFSET) frameIndexOffset(GOTTHARD_FRAME_INDEX_OFFSET)
{ {
int aligned_frame_size = GOTTHARD_ALIGNED_FRAME_SIZE; 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(&status_mutex,NULL);
pthread_mutex_init(&dataReadyMutex,NULL);
} }
@ -216,30 +218,24 @@ int slsReceiverFunctionList::startReceiver(char message[]){
cout << "Starting new acquisition threadddd ...." << endl; cout << "Starting new acquisition threadddd ...." << endl;
#endif #endif
//change status //change status
while(1){ pthread_mutex_lock(&status_mutex);
if(!pthread_mutex_trylock(&(status_mutex))){
status = IDLE; status = IDLE;
listening_thread_running = 0; listening_thread_running = 0;
writing_thread_running = 0; writing_thread_running = 0;
receiver_threads_running = 1; receiver_threads_running = 1;
pthread_mutex_unlock(&(status_mutex)); pthread_mutex_unlock(&(status_mutex));
break;
}
}
// creating listening thread---------- // creating listening thread----------
err = pthread_create(&listening_thread, NULL,startListeningThread, (void*) this); err = pthread_create(&listening_thread, NULL,startListeningThread, (void*) this);
if(err){ if(err){
//change status //change status
while(1){ pthread_mutex_lock(&status_mutex);
if(!pthread_mutex_trylock(&(status_mutex))){
status = IDLE; status = IDLE;
listening_thread_running = 0; listening_thread_running = 0;
receiver_threads_running = 0; receiver_threads_running = 0;
pthread_mutex_unlock(&(status_mutex)); pthread_mutex_unlock(&(status_mutex));
break;
}
}
sprintf(message,"Cant create listening thread. Status:%d\n",status); sprintf(message,"Cant create listening thread. Status:%d\n",status);
cout << endl << message << endl; cout << endl << message << endl;
return FAIL; return FAIL;
@ -259,15 +255,12 @@ int slsReceiverFunctionList::startReceiver(char message[]){
err = pthread_create(&writing_thread, NULL,startWritingThread, (void*) this); err = pthread_create(&writing_thread, NULL,startWritingThread, (void*) this);
if(err){ if(err){
//change status //change status
while(1){ pthread_mutex_lock(&status_mutex);
if(!pthread_mutex_trylock(&(status_mutex))){
status = IDLE; status = IDLE;
writing_thread_running = 0; writing_thread_running = 0;
receiver_threads_running = 0; receiver_threads_running = 0;
pthread_mutex_unlock(&(status_mutex)); pthread_mutex_unlock(&(status_mutex));
break;
}
}
//stop listening thread //stop listening thread
pthread_join(listening_thread,NULL); pthread_join(listening_thread,NULL);
sprintf(message,"Cant create writing thread. Status:%d\n",status); sprintf(message,"Cant create writing thread. Status:%d\n",status);
@ -286,13 +279,9 @@ int slsReceiverFunctionList::startReceiver(char message[]){
//change status---------- //change status----------
while(1){ pthread_mutex_lock(&status_mutex);
if(!pthread_mutex_trylock(&(status_mutex))){
status = RUNNING; status = RUNNING;
pthread_mutex_unlock(&(status_mutex)); pthread_mutex_unlock(&(status_mutex));
break;
}
}
cout << "Threads created successfully." << endl; cout << "Threads created successfully." << endl;
@ -319,6 +308,9 @@ int slsReceiverFunctionList::startReceiver(char message[]){
} }
//initialize semaphore
sem_init(&smp,0,1);
return OK; return OK;
} }
@ -337,25 +329,24 @@ int slsReceiverFunctionList::stopReceiver(){
cout << "Stopping new acquisition threadddd ...." << endl; cout << "Stopping new acquisition threadddd ...." << endl;
#endif #endif
//stop listening thread //stop listening thread
while(1){ pthread_mutex_lock(&status_mutex);
if(!pthread_mutex_trylock(&(status_mutex))){
receiver_threads_running=0; receiver_threads_running=0;
pthread_mutex_unlock(&(status_mutex)); pthread_mutex_unlock(&(status_mutex));
break;
}
}
if(udpSocket) udpSocket->ShutDownSocket(); if(udpSocket) udpSocket->ShutDownSocket();
pthread_join(listening_thread,NULL); pthread_join(listening_thread,NULL);
pthread_join(writing_thread,NULL); pthread_join(writing_thread,NULL);
} }
//change status //change status
while(1){ pthread_mutex_lock(&status_mutex);
if(!pthread_mutex_trylock(&(status_mutex))){
status = IDLE; status = IDLE;
pthread_mutex_unlock(&(status_mutex)); pthread_mutex_unlock(&(status_mutex));
break;
} //semaphore destroy
} sem_post(&smp);
sem_destroy(&smp);
cout << "Receiver Stopped.\nStatus:" << status << endl; cout << "Receiver Stopped.\nStatus:" << status << endl;
return OK; return OK;
} }
@ -423,26 +414,19 @@ int slsReceiverFunctionList::startListening(){
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "Could not create UDP socket "<< server_port << std::endl; std::cout<< "Could not create UDP socket "<< server_port << std::endl;
#endif #endif
while(1){ pthread_mutex_lock(&status_mutex);
if(!pthread_mutex_trylock(&(status_mutex))){
listening_thread_running = -1; listening_thread_running = -1;
pthread_mutex_unlock(&(status_mutex)); pthread_mutex_unlock(&status_mutex);
break;
}
}
break; break;
} }
while (receiver_threads_running) { while (receiver_threads_running) {
while(1){ pthread_mutex_lock(&status_mutex);
if(!pthread_mutex_trylock(&(status_mutex))){
listening_thread_running = 1; listening_thread_running = 1;
pthread_mutex_unlock(&(status_mutex)); pthread_mutex_unlock(&(status_mutex));
break;
}
}
if (!fifofree->isEmpty()) { if (!fifofree->isEmpty()) {
fifofree->pop(buffer); fifofree->pop(buffer);
@ -490,14 +474,11 @@ int slsReceiverFunctionList::startListening(){
} }
} }
} while (receiver_threads_running); } while (receiver_threads_running);
while(1){ pthread_mutex_lock(&status_mutex);
if(!pthread_mutex_trylock(&(status_mutex))){
receiver_threads_running=0; receiver_threads_running=0;
status = IDLE; status = IDLE;
pthread_mutex_unlock(&(status_mutex)); pthread_mutex_unlock(&status_mutex);
break;
}
}
//Close down any open socket descriptors //Close down any open socket descriptors
udpSocket->Disconnect(); udpSocket->Disconnect();
@ -539,6 +520,8 @@ int slsReceiverFunctionList::startWriting(){
if(sfilefd) sfilefd=NULL; if(sfilefd) sfilefd=NULL;
strcpy(savefilename,""); strcpy(savefilename,"");
//reset this before each acq or you send old data //reset this before each acq or you send old data
guiData = NULL; guiData = NULL;
guiDataReady=0; guiDataReady=0;
@ -563,6 +546,7 @@ int slsReceiverFunctionList::startWriting(){
cout << "Ready!" << endl; cout << "Ready!" << endl;
//will always run till acquisition over and then runs till fifo is empty
while(receiver_threads_running || (!fifo->isEmpty())){ while(receiver_threads_running || (!fifo->isEmpty())){
//start a new file //start a new file
@ -581,15 +565,11 @@ int slsReceiverFunctionList::startWriting(){
if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){ if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){
cout << "Error: Could not create file " << savefilename << endl; cout << "Error: Could not create file " << savefilename << endl;
while(1){ pthread_mutex_lock(&status_mutex);
if(!pthread_mutex_trylock(&(status_mutex))){
writing_thread_running = -1; writing_thread_running = -1;
pthread_mutex_unlock(&(status_mutex)); pthread_mutex_unlock(&(status_mutex));
break; break;
} }
}
break;
}
//setting buffer //setting buffer
setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE);
@ -612,13 +592,10 @@ int slsReceiverFunctionList::startWriting(){
} }
} }
while(1){ pthread_mutex_lock(&status_mutex);
if(!pthread_mutex_trylock(&(status_mutex))){
writing_thread_running = 1; writing_thread_running = 1;
pthread_mutex_unlock(&(status_mutex)); pthread_mutex_unlock(&(status_mutex));
break;
}
}
//if(prevframenum != 0){ //if(prevframenum != 0){
if(framesCaught){ if(framesCaught){
@ -628,7 +605,6 @@ int slsReceiverFunctionList::startWriting(){
} }
//pop fifo //pop fifo
if(!fifo->isEmpty()){ if(!fifo->isEmpty()){
@ -640,7 +616,7 @@ int slsReceiverFunctionList::startWriting(){
else else
currframenum = (((uint32_t)(*((uint32_t*)wbuf))) & (frameIndexMask)) >> frameIndexOffset; currframenum = (((uint32_t)(*((uint32_t*)wbuf))) & (frameIndexMask)) >> frameIndexOffset;
//cout<<"**************curreframenm:"<<currframenum<<endl; //cout<<"currframenum:"<<currframenum<<endl;
//write data call back //write data call back
if (cbAction < DO_EVERYTHING) { if (cbAction < DO_EVERYTHING) {
@ -661,59 +637,54 @@ int slsReceiverFunctionList::startWriting(){
if(guiData){ if(guiData){
memcpy(latestData,wbuf,bufferSize); memcpy(latestData,wbuf,bufferSize);
strcpy(guiFileName,savefilename); strcpy(guiFileName,savefilename);
pthread_mutex_lock(&dataReadyMutex);
guiDataReady=1; guiDataReady=1;
}else pthread_mutex_unlock(&dataReadyMutex);
}else{
pthread_mutex_lock(&dataReadyMutex);
guiDataReady=0; guiDataReady=0;
pthread_mutex_unlock(&dataReadyMutex);
}
} }
//reads every nth frame //reads every nth frame
else{ else{
if(frameFactor){ if(frameFactor){
frameFactor--; frameFactor--;
}else{ }else{
frameFactor = nFrameToGui-1; frameFactor = nFrameToGui-1;
//catch nth frame: gui ready to copy data //block current process if the guireader hasnt read it yet
while(guiData==NULL){ sem_wait(&smp);
if(!receiver_threads_running) //copy data and set guidataready
break;
usleep(10000);
guiDataReady=0;
}
//copies gui data and sets/resets guiDataReady
memcpy(latestData,wbuf,bufferSize); memcpy(latestData,wbuf,bufferSize);
strcpy(guiFileName,savefilename); strcpy(guiFileName,savefilename);
guiDataReady=1; pthread_mutex_lock(&dataReadyMutex);
guiDataReady = 1;
pthread_mutex_unlock(&dataReadyMutex);
//catch nth frame: wait for gui to take data
while(guiData==latestData){
if(!receiver_threads_running)
break;
usleep(100000);
}
guiDataReady=0;
} }
} }
framesInFile++; framesInFile++;
fifofree->push(wbuf); fifofree->push(wbuf);
} }
} }
else{//cout<<"************************fifo empty**********************************"<<endl; else{//cout<<"************************fifo empty**********************************"<<endl;
//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++; sleepnumber++;
usleep(50000); usleep(50000);
} }
} }
}
while(1){ pthread_mutex_lock(&status_mutex);
if(!pthread_mutex_trylock(&(status_mutex))){
receiver_threads_running=0; receiver_threads_running=0;
pthread_mutex_unlock(&(status_mutex)); pthread_mutex_unlock(&status_mutex);
break;
}
}
cout << "RealTime Frames Caught:" << framesCaught << endl; cout << "RealTime Frames Caught:" << framesCaught << endl;
cout << "Total Frames Caught:"<< totalFramesCaught << endl; cout << "Total Frames Caught:"<< totalFramesCaught << endl;
@ -741,14 +712,11 @@ int slsReceiverFunctionList::startWriting(){
void slsReceiverFunctionList::readFrame(char* c,char** raw){ void slsReceiverFunctionList::readFrame(char* c,char** raw){
//point to gui data //point to gui data
if (guiData == NULL) if (guiData == NULL)
guiData = latestData; guiData = latestData;
//copy data and filename //copy data and filename
strcpy(c,guiFileName); strcpy(c,guiFileName);
//could not get gui data //could not get gui data
if(!guiDataReady){ if(!guiDataReady){
*raw = NULL; *raw = NULL;
@ -757,6 +725,13 @@ void slsReceiverFunctionList::readFrame(char* c,char** raw){
else{ else{
*raw = guiData; *raw = guiData;
guiData = NULL; 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 #endif

View File

@ -17,6 +17,7 @@
#include <string.h> #include <string.h>
#include <pthread.h> #include <pthread.h>
#include <stdio.h> #include <stdio.h>
#include <semaphore.h>
/** /**
@ -202,6 +203,10 @@ public:
*/ */
int setNFrameToGui(int i){if(i>=0) nFrameToGui = i; return nFrameToGui;}; 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: private:
/** detector type */ /** detector type */
@ -385,8 +390,11 @@ private:
/** frame index offset */ /** frame index offset */
int frameIndexOffset; int frameIndexOffset;
/** semaphore to synchronize writer and guireader threads */
sem_t smp;
/** guiDataReady mutex */
pthread_mutex_t dataReadyMutex;
public: public:

View File

@ -285,6 +285,7 @@ int slsReceiverFuncs::function_table(){
flist[F_ENABLE_FILE_WRITE] = &slsReceiverFuncs::enable_file_write; flist[F_ENABLE_FILE_WRITE] = &slsReceiverFuncs::enable_file_write;
flist[F_GET_ID] = &slsReceiverFuncs::get_version; flist[F_GET_ID] = &slsReceiverFuncs::get_version;
flist[F_CONFIGURE_MAC] = &slsReceiverFuncs::set_short_frame; flist[F_CONFIGURE_MAC] = &slsReceiverFuncs::set_short_frame;
flist[F_START_READOUT] = &slsReceiverFuncs::start_readout;
//General Functions //General Functions
flist[F_LOCK_SERVER] = &slsReceiverFuncs::lock_receiver; 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 */ /** Get Version */
int 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 //General Functions
/** Locks Receiver */ /** Locks Receiver */

View File

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