mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-21 19:30:03 +02:00
closeDataFile is only for gotthard and included lock for socket while using receiver
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@338 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
parent
8f7872d056
commit
bf7da5f493
@ -89,6 +89,10 @@ enum communicationProtocol{
|
||||
genericSocket(const char* const host_ip_or_name, unsigned short int const port_number, communicationProtocol p) :
|
||||
portno(port_number), protocol(p), is_a_server(0), socketDescriptor(-1),file_des(-1), packet_size(DEFAULT_PACKET_SIZE)// sender (client): where to? ip
|
||||
{
|
||||
pthread_mutex_t mp1 = PTHREAD_MUTEX_INITIALIZER;
|
||||
mp=mp1;
|
||||
pthread_mutex_init(&mp, NULL);
|
||||
|
||||
strcpy(hostname,host_ip_or_name);
|
||||
struct hostent *hostInfo = gethostbyname(host_ip_or_name);
|
||||
if (hostInfo == NULL){
|
||||
@ -237,7 +241,7 @@ enum communicationProtocol{
|
||||
/** @short etablishes connection; disconnect should always follow
|
||||
\returns 1 if error
|
||||
*/
|
||||
int Connect(){
|
||||
int Connect(){//cout<<"connect"<<endl;
|
||||
|
||||
if(file_des>0) return file_des;
|
||||
|
||||
@ -316,8 +320,12 @@ enum communicationProtocol{
|
||||
if(connect(socketDescriptor,(struct sockaddr *) &serverAddress,sizeof(serverAddress))<0){
|
||||
cerr << "Can not connect to socket "<<endl;
|
||||
file_des = -1;
|
||||
} else
|
||||
} else{
|
||||
file_des = socketDescriptor;
|
||||
/*cout<<"locking"<<endl;
|
||||
pthread_mutex_lock(&mp);
|
||||
cout<<"locked"<<endl;*/
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -340,6 +348,9 @@ enum communicationProtocol{
|
||||
socketDescriptor=-1;
|
||||
}
|
||||
file_des=-1;
|
||||
/*cout<<"unlocking"<<endl;
|
||||
pthread_mutex_unlock(&mp);
|
||||
cout<<"unlocked"<<endl;*/
|
||||
}
|
||||
};
|
||||
|
||||
@ -580,6 +591,6 @@ enum communicationProtocol{
|
||||
|
||||
int file_des;
|
||||
|
||||
|
||||
pthread_mutex_t mp;
|
||||
};
|
||||
#endif
|
||||
|
@ -5715,7 +5715,7 @@ int* slsDetector::readFrameFromReceiver(){
|
||||
std::cout<< "Received "<< n << " data bytes" << std::endl;
|
||||
#endif
|
||||
if (n!=thisDetector->dataBytes+HEADERLENGTH) {
|
||||
std::cout<<endl<< "wrong data size received: received " << n << " but expected " << thisDetector->dataBytes+HEADERLENGTH << std::endl;
|
||||
std::cout<<endl<< "wrong data size received: received " << n << " but expected from receiver " << thisDetector->dataBytes+HEADERLENGTH << std::endl;
|
||||
ret=FAIL;
|
||||
delete [] origVal;
|
||||
delete [] retval;
|
||||
|
@ -244,17 +244,22 @@ void slsDetectorUtils::acquire(int delflag){
|
||||
pthread_mutex_lock(&mp);
|
||||
createFileName();
|
||||
pthread_mutex_unlock(&mp);
|
||||
|
||||
pthread_mutex_lock(&mg);
|
||||
setFileName(fileIO::getFileName());
|
||||
if(setReceiverOnline()==OFFLINE_FLAG){
|
||||
stopReceiver();
|
||||
pthread_mutex_unlock(&mg);
|
||||
break;
|
||||
}
|
||||
//start receiver
|
||||
startReceiver();
|
||||
if(setReceiverOnline()==OFFLINE_FLAG){
|
||||
stopReceiver();
|
||||
pthread_mutex_unlock(&mg);
|
||||
break;
|
||||
}
|
||||
pthread_mutex_unlock(&mg);
|
||||
}
|
||||
|
||||
startAndReadAll();
|
||||
@ -290,6 +295,8 @@ void slsDetectorUtils::acquire(int delflag){
|
||||
} else
|
||||
break;
|
||||
|
||||
|
||||
pthread_mutex_lock(&mg);
|
||||
if(setReceiverOnline()==OFFLINE_FLAG){
|
||||
// wait until data processing thread has finished the data
|
||||
|
||||
@ -303,12 +310,16 @@ void slsDetectorUtils::acquire(int delflag){
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
if (getDetectorsType()==GOTTHARD)
|
||||
if((*correctionMask)&(1<<WRITE_FILE))
|
||||
closeDataFile();
|
||||
|
||||
}else{
|
||||
while(stopReceiver()!=OK);
|
||||
}
|
||||
pthread_mutex_unlock(&mg);
|
||||
|
||||
|
||||
|
||||
pthread_mutex_lock(&mp);
|
||||
if (*stoppedFlag==0) {
|
||||
@ -382,14 +393,14 @@ void slsDetectorUtils::acquire(int delflag){
|
||||
|
||||
|
||||
|
||||
|
||||
pthread_mutex_lock(&mg);
|
||||
#ifdef VERBOSE
|
||||
cout << "findex incremented " << endl;
|
||||
#endif
|
||||
if(*correctionMask&(1<<WRITE_FILE))
|
||||
IncrementFileIndex();
|
||||
setFileIndex(fileIO::getFileIndex());
|
||||
|
||||
pthread_mutex_unlock(&mg);
|
||||
|
||||
|
||||
if (measurement_finished)
|
||||
|
@ -119,10 +119,10 @@ return 0;
|
||||
|
||||
|
||||
|
||||
int fileIO::closeDataFile() {fflush(stdout);
|
||||
int fileIO::closeDataFile() {cout<<"closing datafile: filfd:"<<filefd<<endl;
|
||||
if (filefd)
|
||||
fclose(filefd);
|
||||
filefd=NULL;
|
||||
filefd=NULL; cout<<"closed data file"<<endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -13,8 +13,8 @@ postProcessing::postProcessing(): expTime(NULL), ang(NULL), val(NULL), err(NULL)
|
||||
pthread_mutex_t mp1 = PTHREAD_MUTEX_INITIALIZER;
|
||||
mp=mp1;
|
||||
pthread_mutex_init(&mp, NULL);
|
||||
// mg=mp1;
|
||||
// pthread_mutex_init(&mg, NULL);
|
||||
mg=mp1;
|
||||
pthread_mutex_init(&mg, NULL);
|
||||
//cout << "reg callback "<< endl;
|
||||
dataReady = 0;
|
||||
pCallbackArg = 0;
|
||||
@ -99,10 +99,10 @@ void postProcessing::processFrame(int *myData, int delflag) {
|
||||
cout << "writing raw data " << endl;
|
||||
|
||||
#endif
|
||||
if (getDetectorsType()==MYTHEN){
|
||||
if (getDetectorsType()==MYTHEN){cout<<"gonna write datafile"<<endl;
|
||||
// if (fdata) {
|
||||
//uses static function?!?!?!?
|
||||
writeDataFile (fname+string(".raw"),fdata, NULL, NULL, 'i');
|
||||
writeDataFile (fname+string(".raw"),fdata, NULL, NULL, 'i');cout<<"finished writing datafile"<<endl;
|
||||
} else {
|
||||
writeDataFile ((void*)myData, frameIndex);
|
||||
}
|
||||
@ -375,19 +375,28 @@ void* postProcessing::processData(int delflag) {
|
||||
}
|
||||
//receiver
|
||||
else{
|
||||
pthread_mutex_lock(&mg);
|
||||
int prevCaught=getCurrentFrameIndex();
|
||||
pthread_mutex_unlock(&mg);
|
||||
|
||||
int caught=0;
|
||||
while(1){
|
||||
if (checkJoinThread()) break;
|
||||
usleep(200000);
|
||||
|
||||
pthread_mutex_lock(&mg);
|
||||
caught=getCurrentFrameIndex();
|
||||
pthread_mutex_unlock(&mg);
|
||||
|
||||
incrementProgress(caught-prevCaught);
|
||||
prevCaught=caught;
|
||||
if (checkJoinThread()) break;
|
||||
//if(progress_call)
|
||||
// progress_call(getCurrentProgress(),pProgressCallArg);
|
||||
|
||||
pthread_mutex_lock(&mg);
|
||||
int* receiverData = readFrameFromReceiver();
|
||||
pthread_mutex_unlock(&mg);
|
||||
|
||||
if(!receiverData)
|
||||
return 0;
|
||||
fdata=decodeData(receiverData);
|
||||
|
@ -398,7 +398,7 @@ char* readFrame(){
|
||||
|
||||
// memcpy(sendbuffer,buffer ,sizeof(buffer));
|
||||
|
||||
while (((int)*((int*)buffer))%2==0) ;//usleep(20000);
|
||||
while (((int)*((int*)buffer))%2==0) {printf("checking\n");fflush(stdout);}//usleep(20000);
|
||||
|
||||
// memcpy(sendbuffer,buffer ,sizeof(buffer));
|
||||
|
||||
|
@ -449,7 +449,7 @@ int get_frames_caught(int file_des) {
|
||||
|
||||
|
||||
|
||||
int get_frame_index(int file_des) {printf("Getting frame Index\n");fflush(stdout);
|
||||
int get_frame_index(int file_des) {
|
||||
int ret=OK;
|
||||
int n=0;
|
||||
int retval=-1;
|
||||
@ -467,7 +467,6 @@ int get_frame_index(int file_des) {printf("Getting frame Index\n");fflush(stdout
|
||||
/* send answer */
|
||||
n = sendDataOnly(file_des,&ret,sizeof(ret));
|
||||
n = sendDataOnly(file_des,&retval,sizeof(retval));
|
||||
printf("returnrdf:%d\n",retval);
|
||||
/*return ok/fail*/
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user