mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-19 16:27:13 +02:00
works, need to do json header and send dataready
This commit is contained in:
@ -10,7 +10,6 @@
|
||||
#include <cstdlib>
|
||||
#include <math.h>
|
||||
#include "gitInfoLib.h"
|
||||
#include <zmq.h>
|
||||
|
||||
int slsDetector::initSharedMemory(detectorType type, int id) {
|
||||
|
||||
@ -7145,108 +7144,6 @@ int slsDetector::resetFramesCaught(){
|
||||
|
||||
|
||||
|
||||
void slsDetector::readFrameFromReceiver(){
|
||||
|
||||
//determine number of half readouts
|
||||
int numReadout = 1;
|
||||
if(thisDetector->myDetectorType == EIGER) numReadout = 2;
|
||||
int readoutId = detId*numReadout;
|
||||
volatile uint64_t runningMask = 0x0;
|
||||
|
||||
//server details
|
||||
char hostname[numReadout][100];
|
||||
int portno[numReadout];
|
||||
int nel=(thisDetector->dataBytes/numReadout)/sizeof(int);
|
||||
for(int i=0;i<numReadout;++i){
|
||||
portno[i] = DEFAULT_ZMQ_PORTNO + (readoutId+i);
|
||||
sprintf(hostname[i], "%s%d", "tcp://127.0.0.1:",portno[i]);
|
||||
//cout << "ZMQ Client of " << readoutId+i << " at " << hostname[i] << endl;
|
||||
parentDet->slsframe[readoutId+i]=new int[nel];
|
||||
}
|
||||
|
||||
|
||||
//loop though the half readouts to start sockets
|
||||
void *context[numReadout];
|
||||
void *zmqsocket[numReadout];
|
||||
for(int i=0;i<numReadout;++i){
|
||||
context[i] = zmq_ctx_new();
|
||||
zmqsocket[i] = zmq_socket(context[i], ZMQ_SUB);
|
||||
zmq_setsockopt(zmqsocket[i], ZMQ_SUBSCRIBE, "", 0); // an empty string implies receiving any messages
|
||||
zmq_connect(zmqsocket[i], hostname[i]);// connect to publisher,the publisher server does not have to be started
|
||||
runningMask|=(1<<(i));
|
||||
sem_post(&parentDet->sem_multiwait[readoutId+i]); //let multi know socket created
|
||||
}
|
||||
|
||||
//receive msgs and let multi know
|
||||
zmq_msg_t message;
|
||||
int len,idet = 0;
|
||||
int framecount=0;
|
||||
|
||||
//read frame
|
||||
while(true){
|
||||
for(int idet=0; idet<numReadout; ++idet){
|
||||
if((1 << idet) & runningMask){
|
||||
sem_wait(&parentDet->sem_slswait[readoutId+idet]);//wait for it to be copied
|
||||
|
||||
if(!idet) framecount++; //update indices, count only once
|
||||
|
||||
// receive a message, this is a blocking function
|
||||
len = zmq_msg_init (&message); /* is this required? Xiaoqiang didnt have it*/
|
||||
if(len) {cprintf(RED,"Failed to initialize message %d for %d\n",len,readoutId+idet); continue; }//error
|
||||
len = zmq_msg_recv(&message, zmqsocket[idet], 0);
|
||||
|
||||
//end of socket
|
||||
if (len <= 3 ) {
|
||||
if(!len) cprintf(RED,"Received no data in socket for %d\n", readoutId+idet);
|
||||
//cout<<readoutId+idet <<" sls Received end data"<<endl;
|
||||
parentDet->slsframe[readoutId+idet] = NULL;
|
||||
sem_post(&parentDet->sem_slsdone[readoutId+idet]); //let multi know is ready
|
||||
runningMask^=(1<<idet);
|
||||
//cout<<detId<<" " << idet << " finished"<<endl;
|
||||
if(!runningMask){ //all done, get out
|
||||
//cout<<detId<<" all done"<<endl;
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if(zmq_msg_data(&message)==NULL) cprintf(RED,"GOT NULL FROM ZMQ\n"); /*not needed most likely*/
|
||||
|
||||
//cout<<"Received on " << readoutId+idet << " for frame " << framecount << endl;
|
||||
//if(len == thisDetector->dataBytes/numReadout){//hoow to solve this
|
||||
memcpy((char*)(parentDet->slsframe[readoutId+idet]),(char*)zmq_msg_data(&message),thisDetector->dataBytes/numReadout);
|
||||
//check header, if incorrect frame, copy somewhere and assign a blank subframe and also check size
|
||||
|
||||
//jungfrau masking adcval
|
||||
if(thisDetector->myDetectorType == JUNGFRAU){
|
||||
for(unsigned int i=0;i<nel;i++){
|
||||
parentDet->slsframe[readoutId+idet][i] = (parentDet->slsframe[readoutId+idet][i] & 0x3FFF3FFF);
|
||||
}
|
||||
}
|
||||
//}
|
||||
sem_post(&parentDet->sem_slsdone[readoutId+idet]);//let multi know is ready
|
||||
}
|
||||
}//end of for loop
|
||||
|
||||
if(!runningMask){
|
||||
break;
|
||||
}
|
||||
}
|
||||
zmq_msg_close(&message);
|
||||
|
||||
//close socket
|
||||
for(int i=0;i<numReadout;i++){
|
||||
zmq_disconnect(zmqsocket[i], hostname[i]);
|
||||
zmq_close(zmqsocket[i]);
|
||||
zmq_ctx_destroy(context[i]);
|
||||
delete [] parentDet->slsframe[readoutId+i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int slsDetector::lockReceiver(int lock){
|
||||
int fnum=F_LOCK_RECEIVER;
|
||||
|
Reference in New Issue
Block a user