removing unnecessary printouts, ensuring lost packets are 0xff

This commit is contained in:
Dhanya Maliakal 2017-06-21 17:05:47 +02:00
parent df71899244
commit fe73e09aa4
2 changed files with 60 additions and 143 deletions

View File

@ -41,7 +41,9 @@ int multiSlsDetector::freeSharedMemory() {
perror("shmdt failed\n");
return FAIL;
}
#ifdef VERBOSE
printf("Shared memory %d detached\n", shmId);
#endif
// remove shared memory
if (shmctl(shmId, IPC_RMID, 0) == -1) {
perror("shmctl(IPC_RMID) failed\n");
@ -414,9 +416,9 @@ int multiSlsDetector::addSlsDetector(int id, int pos) {
void multiSlsDetector::updateOffsets(){
#ifdef VERBOSE
cout << endl << "Updating Multi-Detector Offsets" << endl;
#endif
int offsetX=0, offsetY=0, numX=0, numY=0, maxX=0, maxY=0;
int maxChanX = thisMultiDetector->maxNumberOfChannelsPerDetector[X];
int maxChanY = thisMultiDetector->maxNumberOfChannelsPerDetector[Y];
@ -432,7 +434,9 @@ void multiSlsDetector::updateOffsets(){
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
if (detectors[i]) {
#ifdef VERBOSE
cout<<"offsetX:"<<offsetX<<" prevChanX:"<<prevChanX<<" offsetY:"<<offsetY<<" prevChanY:"<<prevChanY<<endl;
#endif
//cout<<" totalchan:"<< detectors[i]->getTotalNumberOfChannels(Y) <<" maxChanY:"<<maxChanY<<endl;
//incrementing in both direction
if(firstTime){
@ -448,7 +452,9 @@ void multiSlsDetector::updateOffsets(){
numY += detectors[i]->getTotalNumberOfChannels(Y);
maxX += detectors[i]->getMaxNumberOfChannels(X);
maxY += detectors[i]->getMaxNumberOfChannels(Y);
#ifdef VERBOSE
cout<<"incrementing in both direction"<<endl;
#endif
}
//incrementing in y direction
@ -457,7 +463,9 @@ void multiSlsDetector::updateOffsets(){
prevChanY = detectors[i]->getTotalNumberOfChannels(Y);
numY += detectors[i]->getTotalNumberOfChannels(Y);
maxY += detectors[i]->getMaxNumberOfChannels(Y);
#ifdef VERBOSE
cout<<"incrementing in y direction"<<endl;
#endif
}
//incrementing in x direction
@ -472,13 +480,16 @@ void multiSlsDetector::updateOffsets(){
prevChanX = detectors[i]->getTotalNumberOfChannels(X);
numX += detectors[i]->getTotalNumberOfChannels(X);
maxX += detectors[i]->getMaxNumberOfChannels(X);
#ifdef VERBOSE
cout<<"incrementing in x direction"<<endl;
#endif
}
thisMultiDetector->offsetX[i] = offsetX;
thisMultiDetector->offsetY[i] = offsetY;
#ifdef VERBOSE
cout << "Detector[" << i << "] has offsets (" << thisMultiDetector->offsetX[i] << ", " << thisMultiDetector->offsetY[i] << ")" << endl;
#endif
//offsetY has been reset sometimes and offsetX the first time, but remember the highest values
if(numX > thisMultiDetector->numberOfChannel[X])
thisMultiDetector->numberOfChannel[X] = numX;
@ -490,9 +501,10 @@ void multiSlsDetector::updateOffsets(){
thisMultiDetector->maxNumberOfChannel[Y] = maxY;
}
}
#ifdef VERBOSE
cout << "Number of Channels in X direction:" << thisMultiDetector->numberOfChannel[X] << endl;
cout << "Number of Channels in Y direction:" << thisMultiDetector->numberOfChannel[Y] << endl << endl;
#endif
}
string multiSlsDetector::setHostname(const char* name, int pos){
@ -560,7 +572,6 @@ string multiSlsDetector::ssetDetectorsType(string name, int pos) {
}
string multiSlsDetector::getHostname(int pos) {
string s=string("");
#ifdef VERBOSE
cout << "returning hostname" << pos << endl;
@ -577,8 +588,8 @@ string multiSlsDetector::getHostname(int pos) {
s+=detectors[ip]->getHostname();
s+=string("+");
}
cout << s <<endl;
#ifdef VERBOSE
cout << s <<endl;
cout << "hostname " << s << endl;
#endif
}
@ -5253,6 +5264,7 @@ void multiSlsDetector::readFrameFromReceiver(){
slsmaxX = detectors[0]->getTotalNumberOfChannels(X);
slsmaxY = detectors[0]->getTotalNumberOfChannels(Y);
}
//getting multi values
nx = getTotalNumberOfChannels(slsDetectorDefs::X);
ny = getTotalNumberOfChannels(slsDetectorDefs::Y);
@ -5282,132 +5294,6 @@ void multiSlsDetector::readFrameFromReceiver(){
int* multiframe=new int[nel]();
int nch;
/*
//left shift can be done to a maximum of 32 bits (so using 3 x 32 bits, instead of 2 x 64 bits)
volatile uint32_t dataThreadMask1 = 0x0;
volatile uint32_t dataThreadMask2 = 0x0;
volatile uint32_t dataThreadMask3 = 0x0;
if(numSockets >= 96) {
cprintf(BG_RED,"Error: Too many sockets %d for gui to process. Goodbye!", numSockets);
createReceivingDataSockets(true);
exit(EXIT_FAILURE);
}
//wait for real time acquisition to start
bool running = true;
sem_wait(&sem_newRTAcquisition);
if(checkJoinThread())
running = false;
for(int i = 0; i < numSockets; ++i) {
if(i < 32)
dataThreadMask1 |=(1<<i);
else if (i < 64)
dataThreadMask2 |=(1<<(i-32));
else
dataThreadMask3 |=(1<<(i-64));
}
//exit when last message for each socket received
while(running){
printf("datathreadmask1:0x%08x datathreadmask2:0x%08x datathreadmask2:0x%08x\n",dataThreadMask1,dataThreadMask2,dataThreadMask3);
//memset(((char*)multiframe),0xFF,slsdatabytes*thisMultiDetector->numberOfDetectors); //reset frame memory
//get each frame
for(int isocket=0; isocket<numSockets; ++isocket){
cout<<"isocket:"<<isocket<<endl;
//if running
if (((isocket < 32) && ((1 << isocket) & dataThreadMask1)) || //first 32 sockets
((isocket >= 32) && (isocket < 64) &&((1 << (isocket-32)) & dataThreadMask2)) || //next 32 sockets
((isocket >= 64) && ((1 << (isocket-64)) & dataThreadMask3))) { //next set of sockets
//if((1 << isocket) & dataThreadMask){
cout<<"isocket running"<<endl;
//get individual images
if(FAIL == getData(isocket, jungfrau, image, expectedslssize, currentAcquisitionIndex,currentFrameIndex,currentSubFrameIndex,currentFileName)){
if(isocket < 32)
dataThreadMask1^=(1<<isocket);
else if (isocket < 64)
dataThreadMask2^=(1<<(isocket-32));
else
dataThreadMask3^=(1<<(isocket-64));
printf("changed to datathreadmask1:0x%08x datathreadmask2:0x%08x datathreadmask2:0x%08x\n",dataThreadMask1,dataThreadMask2,dataThreadMask3);
continue;
}
//assemble data with interleaving
if(maxX){
//bottom
if(bottom[isocket]){
//if((((isocket/numSocketsPerSLSDetector)+1)%2) == 0){
for(int i=0;i<slsmaxY;++i){
memcpy(((char*)multiframe) + offsetY[isocket] + offsetX[isocket] + (int)((slsmaxY-1-i)*maxX*bytesperchannel),
(char*)image+ (int)(i*(slsmaxX/numSocketsPerSLSDetector)*bytesperchannel),
(int)(slsmaxX/numSocketsPerSLSDetector)*bytesperchannel);
}
}
//top
else{
for(int i=0;i<slsmaxY;++i){
memcpy(((char*)multiframe) + offsetY[isocket] + offsetX[isocket] + (int)(i*maxX*bytesperchannel),
(char*)image+ (int)(i*(slsmaxX/numSocketsPerSLSDetector)*bytesperchannel),
(int)(slsmaxX/numSocketsPerSLSDetector)*bytesperchannel);
}
}
}
//assemble data with no interleaving, assumed detectors appended vertically
else{
memcpy((char*)multiframe+slsdatabytes*isocket,(char*)image,slsdatabytes);
}
}
}
//all done
if(!dataThreadMask1 && !dataThreadMask2 && !dataThreadMask3){
cout<<"doneeeeeeeeeeeeeeeeeeeeeee!\n"<<endl;
sem_wait(&sem_newRTAcquisition);
//done with complete acquisition
if(checkJoinThread())
break;
else{
//starting a new scan/measurement
for(int i = 0; i < numSockets; ++i) {
if(i < 32)
dataThreadMask1 |=(1<<i);
else if (i < 64)
dataThreadMask2 |=(1<<(i-32));
else
dataThreadMask3 |=(1<<(i-64));
}
running = false;
}
}
//send data to callback
if(running){
fdata = decodeData(multiframe,nch);
if ((fdata) && (dataReady)){
thisData = new detectorData(fdata,NULL,NULL,getCurrentProgress(),currentFileName.c_str(),nx,ny);
dataReady(thisData, currentFrameIndex, currentSubFrameIndex, pCallbackArg);
delete thisData;
fdata = NULL;
//cout<<"Send frame #"<< currentFrameIndex << " to gui"<<endl;
}
setCurrentProgress(currentAcquisitionIndex+1);
}
//setting it back for each scan/measurement
running = true;
}
*/
bool runningList[numSockets];
int numRunning = 0;
@ -5424,14 +5310,13 @@ void multiSlsDetector::readFrameFromReceiver(){
//exit when last message for each socket received
while(running){
//memset(((char*)multiframe),0xFF,slsdatabytes*thisMultiDetector->numberOfDetectors); //reset frame memory
memset(((char*)multiframe),0xFF,slsdatabytes*thisMultiDetector->numberOfDetectors); //reset frame memory
//get each frame
for(int isocket=0; isocket<numSockets; ++isocket){
//if running
if (runningList[isocket]) {
//if((1 << isocket) & dataThreadMask){
//get individual images
if(FAIL == getData(isocket, jungfrau, image, expectedslssize, currentAcquisitionIndex,currentFrameIndex,currentSubFrameIndex,currentFileName)){
runningList[isocket] = false;
@ -5448,7 +5333,7 @@ void multiSlsDetector::readFrameFromReceiver(){
for(int i=0;i<slsmaxY;++i){
memcpy(((char*)multiframe) + offsetY[isocket] + offsetX[isocket] + (int)((slsmaxY-1-i)*maxX*bytesperchannel),
(char*)image+ (int)(i*(slsmaxX/numSocketsPerSLSDetector)*bytesperchannel),
(int)(slsmaxX/numSocketsPerSLSDetector)*bytesperchannel);
(int)((slsmaxX/numSocketsPerSLSDetector)*bytesperchannel));
}
}
//top
@ -5456,7 +5341,7 @@ void multiSlsDetector::readFrameFromReceiver(){
for(int i=0;i<slsmaxY;++i){
memcpy(((char*)multiframe) + offsetY[isocket] + offsetX[isocket] + (int)(i*maxX*bytesperchannel),
(char*)image+ (int)(i*(slsmaxX/numSocketsPerSLSDetector)*bytesperchannel),
(int)(slsmaxX/numSocketsPerSLSDetector)*bytesperchannel);
(int)((slsmaxX/numSocketsPerSLSDetector)*bytesperchannel));
}
}
}

View File

@ -144,7 +144,9 @@ int slsDetector::freeSharedMemory() {
perror("shmdt failed\n");
return FAIL;
}
#ifdef VERBOSE
printf("Shared memory %d detached\n", shmId);
#endif
// remove shared memory
if (shmctl(shmId, IPC_RMID, 0) == -1) {
perror("shmctl(IPC_RMID) failed\n");
@ -247,7 +249,9 @@ slsDetector::slsDetector(int pos, detectorType type, int id, multiSlsDetector *p
/**Initializes the detector stucture \sa initializeDetectorSize
*/
#ifdef VERBOSE
cout << "init det size"<< endl;
#endif
initializeDetectorSize(type);
@ -261,9 +265,11 @@ slsDetector::~slsDetector(){
if (shmdt(thisDetector) == -1) {
perror("shmdt failed\n");
printf("Could not detach shared memory %d\n", shmId);
} else
}
#ifdef VERBOSE
else
printf("Shared memory %d detached\n", shmId);
#endif
delete thisReceiver;
};
@ -5900,7 +5906,11 @@ string slsDetector::setDetectorMAC(string detectorMAC){
(detectorMAC[11]==':')&&(detectorMAC[14]==':')){
strcpy(thisDetector->detectorMAC,detectorMAC.c_str());
if(!strcmp(thisDetector->receiver_hostname,"none"))
#ifdef VERBOSE
std::cout << "Warning: Receiver hostname not set yet." << endl;
#else
;
#endif
else if(setUDPConnection()==FAIL)
std::cout<< "Warning: UDP connection set up failed" << std::endl;
}else{
@ -5927,7 +5937,11 @@ string slsDetector::setDetectorIP(string detectorIP){
if(result!=0){
strcpy(thisDetector->detectorIP,detectorIP.c_str());
if(!strcmp(thisDetector->receiver_hostname,"none"))
#ifdef VERBOSE
std::cout << "Warning: Receiver hostname not set yet." << endl;
#else
;
#endif
else if(setUDPConnection()==FAIL)
std::cout<< "Warning: UDP connection set up failed" << std::endl;
}else{
@ -6030,7 +6044,11 @@ string slsDetector::setReceiverUDPIP(string udpip){
}else{
strcpy(thisDetector->receiverUDPIP,udpip.c_str());
if(!strcmp(thisDetector->receiver_hostname,"none")) {
#ifdef VERBOSE
std::cout << "Warning: Receiver hostname not set yet." << endl;
#else
;
#endif
}
else if(setUDPConnection()==FAIL){
std::cout<< "Warning: UDP connection set up failed" << std::endl;
@ -6054,7 +6072,11 @@ string slsDetector::setReceiverUDPMAC(string udpmac){
(udpmac[11]==':')&&(udpmac[14]==':')){
strcpy(thisDetector->receiverUDPMAC,udpmac.c_str());
if(!strcmp(thisDetector->receiver_hostname,"none"))
#ifdef VERBOSE
std::cout << "Warning: Receiver hostname not set yet." << endl;
#else
;
#endif
else if(setUDPConnection()==FAIL){
std::cout<< "Warning: UDP connection set up failed" << std::endl;
}
@ -6073,7 +6095,11 @@ string slsDetector::setReceiverUDPMAC(string udpmac){
int slsDetector::setReceiverUDPPort(int udpport){
thisDetector->receiverUDPPort = udpport;
if(!strcmp(thisDetector->receiver_hostname,"none"))
std::cout << "Warning: Receiver hostname not set yet." << endl;
#ifdef VERBOSE
std::cout << "Warning: Receiver hostname not set yet." << endl;
#else
;
#endif
else if(setUDPConnection()==FAIL){
std::cout<< "Warning: UDP connection set up failed" << std::endl;
}
@ -6083,7 +6109,11 @@ int slsDetector::setReceiverUDPPort(int udpport){
int slsDetector::setReceiverUDPPort2(int udpport){
thisDetector->receiverUDPPort2 = udpport;
if(!strcmp(thisDetector->receiver_hostname,"none"))
std::cout << "Warning: Receiver hostname not set yet." << endl;
#ifdef VERBOSE
std::cout << "Warning: Receiver hostname not set yet." << endl;
#else
;
#endif
else if(setUDPConnection()==FAIL){
std::cout<< "Warning: UDP connection set up failed" << std::endl;
}
@ -6137,7 +6167,9 @@ int slsDetector::setUDPConnection(){
//called before set up
if(!strcmp(thisDetector->receiver_hostname,"none")){
std::cout << "Warning: Receiver hostname not set yet." << endl;
#ifdef VERBOSE
std::cout << "Warning: Receiver hostname not set yet." << endl;
#endif
return FAIL;
}
@ -6195,9 +6227,9 @@ int slsDetector::setUDPConnection(){
}
}else
ret=FAIL;
#ifdef VERBOSE
printReceiverConfiguration();
#endif
return ret;
}