diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 4a833d93f..8a0448476 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -2,7 +2,6 @@ #include "usersFunctions.h" #include "slsDetectorCommand.h" #include -#include #include #include #include @@ -3005,56 +3004,60 @@ int* slsDetector::readFrame(){ return retval; }; + + + int* slsDetector::getDataFromDetector(){ - - int nel=thisDetector->dataBytes/sizeof(int); - int n; - int* retval=new int[nel]; - int ret=FAIL; - char mess[100]="Nothing"; -#ifdef VERY_VERBOSE - int i; -#endif + int nel=thisDetector->dataBytes/sizeof(int); + int n; + int* retval=new int[nel]; + int ret=FAIL; + char mess[100]="Nothing"; #ifdef VERBOSE - std::cout<< "getting data "<< thisDetector->dataBytes << " " << nel<< std::endl; + std::cout<< "getting data "<< thisDetector->dataBytes << " " << nel<< std::endl; #endif - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); #ifdef VERBOSE - cout << "ret=" << ret << endl; + cout << "ret=" << ret << endl; #endif - if (ret!=OK) { - n= controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - if (ret==FAIL) { - thisDetector->stoppedFlag=1; - std::cout<< "Detector returned: " << mess << " " << n << std::endl; - } else { - ; + if (ret!=OK) { + n= controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + if (ret==FAIL) { + thisDetector->stoppedFlag=1; + std::cout<< "Detector returned: " << mess << " " << n << std::endl; + } else { + ; #ifdef VERBOSE - std::cout<< "Detector successfully returned: " << mess << " " << n << std::endl; + std::cout<< "Detector successfully returned: " << mess << " " << n << std::endl; #endif - } - delete [] retval; - retval=NULL; - } else { - n=controlSocket->ReceiveDataOnly(retval,thisDetector->dataBytes); - + } + delete [] retval; + retval=NULL; + } else { + n=controlSocket->ReceiveDataOnly(retval,thisDetector->dataBytes); + #ifdef VERBOSE - std::cout<< "Received "<< n << " data bytes" << std::endl; + std::cout<< "Received "<< n << " data bytes" << std::endl; #endif - if (n!=thisDetector->dataBytes) { - std::cout<< "wrong data size received: received " << n << " but expected " << thisDetector->dataBytes << std::endl; - thisDetector->stoppedFlag=1; - ret=FAIL; - delete [] retval; - retval=NULL; - } - } - return retval; + if (n!=thisDetector->dataBytes) { + std::cout<< "wrong data size received: received " << n << " but expected " << thisDetector->dataBytes << std::endl; + thisDetector->stoppedFlag=1; + ret=FAIL; + delete [] retval; + retval=NULL; + } + } + + return retval; + }; + + + int* slsDetector::readAll(){ int fnum=F_READ_ALL; @@ -3068,6 +3071,7 @@ int* slsDetector::readAll(){ if (controlSocket) { if (controlSocket->Connect()>=0) { controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + while ((retval=getDataFromDetector())){ i++; #ifdef VERBOSE @@ -3084,7 +3088,7 @@ int* slsDetector::readAll(){ #ifdef VERBOSE std::cout<< "received "<< i<< " frames" << std::endl; #else - std::cout << std::endl; + std::cout << std::endl; #endif return dataQueue.front(); // check what we return! @@ -4579,51 +4583,33 @@ int slsDetector:: writeAngularConversion(ofstream &ofs) { } + + + + + + + int slsDetector::loadImageToDetector(imageType index,string const fname){ - int retval; - int fnum=F_LOAD_IMAGE; - int ret=FAIL; - char mess[100]; - short int arg[1280]; - + + int ret=FAIL; + short int arg[thisDetector->nChans*thisDetector->nChips]; + #ifdef VERBOSE - std::cout<< std::endl<< "Loading "; - if(!index) - std::cout<<"Dark"; - else - std::cout<<"Gain"; - std::cout<<" image from file " << fname << std::endl; + std::cout<< std::endl<< "Loading "; + if(!index) + std::cout<<"Dark"; + else + std::cout<<"Gain"; + std::cout<<" image from file " << fname << std::endl; #endif - - if(readDataFile(fname,arg)){ - std::cout<< "Could not open file "<< fname << std::endl; - return -1; - } - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (controlSocket) { - if (controlSocket->Connect()>=0) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&index,sizeof(index)); - controlSocket->SendDataOnly(arg,sizeof(arg)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; + + if(readDataFile(fname,arg)){ + std::cout<< "Could not open file "<< fname << std::endl; + return ret; } - controlSocket->Disconnect(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - - } - } - if (ret==FAIL) { - std::cout<< "failed " << std::endl; - return -1; - } - return 0; + ret = sendImageToDetector(index,arg); + return ret; } @@ -4634,25 +4620,43 @@ int slsDetector::loadImageToDetector(imageType index,string const fname){ +int slsDetector::sendImageToDetector(imageType index,short int arg[]){ + int ret=FAIL; + int retval; + int fnum=F_LOAD_IMAGE; + char mess[100]; +#ifdef VERBOSE + std::cout<< std::endl<< "Sending image to detector " << std::endl; +#endif + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (controlSocket) { + if (controlSocket->Connect()>=0) { + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&index,sizeof(index)); + controlSocket->SendDataOnly(arg,sizeof(arg)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + controlSocket->Disconnect(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + } + if (ret==FAIL) { + std::cout<< "failed " << std::endl; + } - - - - - - - - - - - - - - + return ret; +} @@ -4822,10 +4826,10 @@ int slsDetector::writeConfigurationFile(ofstream &outfile){ switch (thisDetector->myDetectorType) { case GOTTHARD: - names[3]="outdir"; - names[4]="clientip"; - names[5]="clientmac"; - names[6]="servermac"; + names[6]="outdir"; + names[7]="clientip"; + names[8]="clientmac"; + names[9]="servermac"; nvar=10; break; default: @@ -5434,47 +5438,63 @@ int slsDetector::saveSettingsFile(string fname, int imod) { int slsDetector::testFunction(int times) { - int val = 0,i,oldval=0; - runStatus s; - - - for(i=0;inChans*thisDetector->nChips]; + for(i=0;inChans*thisDetector->nChips);j++) + cout<<"\t"<ReceiveDataOnly(&retval,sizeof(retval)); + system("rm ~/wORKSPACE/scratch/run* "); + //system("more ~/wORKSPACE/scratch/run* "); + usleep(1000000); + + setFileIndex(0); + readAll(); + processData(1); + + + if(readDataFile("/home/l_maliakal_d/wORKSPACE/scratch/run_1.raw",dataVals)){ + std::cout<< "Could not open file "<< std::endl; + exit(-1); + } + + for(int j=1277;j< (thisDetector->nChans*thisDetector->nChips);j++) + cout<<"\t"<Disconnect(); if (ret==FORCE_UPDATE) diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 500b49798..79391a953 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -1321,7 +1321,21 @@ typedef struct sharedSlsDetector { */ masterFlags setMaster(masterFlags flag); + /** + Loads dark image or gain image from a file and sends it to the detector + \param index is 0 for dark image and 1 for gain image + \param fname file name to load data from + */ + int loadImageToDetector(imageType index,string const fname); + + /** + Called from loadImageToDetector to send the image to detector + \param index is 0 for dark image and 1 for gain image + \param arg image + + */ + int sendImageToDetector(imageType index,short int arg[]); /** Sets/gets the synchronization mode of the various detectors @@ -1330,9 +1344,6 @@ typedef struct sharedSlsDetector { */ synchronizationMode setSynchronization(synchronizationMode sync=GET_SYNCHRONIZATION_MODE); - int loadImageToDetector(imageType index,string const fname); - - protected: