some changes for jctb

This commit is contained in:
2016-12-19 12:05:59 +01:00
76 changed files with 6375 additions and 6445 deletions

View File

@ -1,11 +1,11 @@
//#define SVNPATH ""
#define SVNURLLIB "git@git.psi.ch:sls_detectors_software/sls_detector_software.git"
//#define SVNREPPATH ""
#define SVNREPUUIDLIB "e9878a26ffb7e57c6e6724215e46ae5634871e64"
//#define SVNREV 0x1149
#define SVNREPUUIDLIB "a10faa8aa60e206c4a0a25ae366e9c1e6f024cbc"
//#define SVNREV 0x1297
//#define SVNKIND ""
//#define SVNSCHED ""
#define SVNAUTHLIB "Dhanya_Maliakal"
#define SVNREVLIB 0x1149
#define SVNDATELIB 0x20160824
#define SVNREVLIB 0x1297
#define SVNDATELIB 0x20161108
//

View File

@ -11,7 +11,6 @@
#include <math.h>
#include "gitInfoLib.h"
int slsDetector::initSharedMemory(detectorType type, int id) {
@ -24,7 +23,9 @@ int slsDetector::initSharedMemory(detectorType type, int id) {
int sz;
//shmId=-1;
#ifdef VERBOSE
cout << "init shm"<< endl;
#endif
switch(type) {
case MYTHEN:
nch=128; // complete mythen system
@ -124,7 +125,9 @@ int slsDetector::initSharedMemory(detectorType type, int id) {
std::cout<<"*** shmat error (server) ***" << std::endl;
return shm_id;
}
#ifdef VERBOSE
cout <<"shm done"<<endl;
#endif
/**
shm_id returns -1 is shared memory initialization fails
@ -1282,6 +1285,13 @@ int slsDetector::activate(int const enable){
int arg = enable;
char mess[MAX_STR_LENGTH]="";
int ret = OK;
if(thisDetector->myDetectorType != EIGER){
std::cout<< "Not implemented for this detector" << std::endl;
setErrorMask((getErrorMask())|(DETECTOR_ACTIVATE));
return -1;
}
#ifdef VERBOSE
if(!enable)
std::cout<< "Deactivating Detector" << std::endl;
@ -1308,11 +1318,36 @@ int slsDetector::activate(int const enable){
}
}
#ifdef VERBOSE
if(retval)
if(retval==1)
std::cout << "Detector Activated" << std::endl;
else
else if(retval==0)
std::cout << "Detector Deactivated" << std::endl;
else
std::cout << "Detector Activation unknown:" << retval << std::endl;
#endif
if(ret!=FAIL){
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "Activating/Deactivating Receiver: " << retval << std::endl;
#endif
if (connectData() == OK)
ret=thisReceiver->sendInt(fnum,retval,retval);
disconnectData();
if(ret==FAIL)
setErrorMask((getErrorMask())|(RECEIVER_ACTIVATE));
}
}
#ifdef VERBOSE
if(retval==1)
std::cout << "Receiver Activated" << std::endl;
else if(retval==0)
std::cout << "Receiver Deactivated" << std::endl;
else
std::cout << "Receiver Activation unknown:" << retval << std::endl;
#endif
return retval;
}
@ -1760,7 +1795,7 @@ int slsDetector::setNumberOfModules(int n, dimension d){
thisDetector->nModMax[Y]=thisDetector->nMod[Y];
int dr=thisDetector->dynamicRange;
if (dr==24)
if ((thisDetector->myDetectorType==MYTHEN) && (dr==24))
dr=32;
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*dr/8;
@ -3678,7 +3713,6 @@ int slsDetector::startAcquisition(){
};
int slsDetector::stopAcquisition(){
int fnum=F_STOP_ACQUISITION;
int ret=FAIL;
char mess[MAX_STR_LENGTH]="";
@ -4019,7 +4053,6 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
int fnum=F_SET_TIMER,fnum2=F_SET_RECEIVER_TIMER;
int64_t retval = -1;
int64_t ut = -2;
char mess[MAX_STR_LENGTH]="";
int ret=OK;
int n=0;
@ -4027,9 +4060,9 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
if (index!=MEASUREMENTS_NUMBER) {
//#ifdef VERBOSE
#ifdef VERBOSE
std::cout<< "Setting timer "<< index << " to " << t << "ns/value" << std::endl;
//#endif
#endif
if (thisDetector->onlineFlag==ONLINE_FLAG) {
if (connectControl() == OK){
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
@ -4056,7 +4089,7 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
} else {
//std::cout<< "offline " << std::endl;
if (t>=0)
thisDetector->timerValue[index]=t;
thisDetector->timerValue[index]=t;
if((thisDetector->myDetectorType==GOTTHARD)||
(thisDetector->myDetectorType==PROPIX)||
(thisDetector->myDetectorType==JUNGFRAU)||
@ -4066,10 +4099,11 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
getTotalNumberOfChannels();
// thisDetector->dataBytes=getTotalNumberOfChannels()*thisDetector->dynamicRange/8*thisDetector->timerValue[SAMPLES_JCTB];
}
}
} else {
if (t>=0)
thisDetector->timerValue[index]=t;
if (t>=0)
thisDetector->timerValue[index]=t;
}
#ifdef VERBOSE
std::cout<< "Timer " << index << " set to "<< thisDetector->timerValue[index] << "ns" << std::endl;
@ -4089,58 +4123,88 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
setTotalProgress();
}
double r;
if((index == SUBFRAME_ACQUISITION_TIME) && (thisDetector->myDetectorType == EIGER) && (t>=0) && getRateCorrection(r)){
setRateCorrection(r);
if(t!=-1){
if ((thisDetector->myDetectorType==MYTHEN)&&(index==PROBES_NUMBER)) {
setDynamicRange();
//cout << "Changing probes: data size = " << thisDetector->dataBytes <<endl;
}
/* set progress */
if ((index==FRAME_NUMBER) || (index==CYCLES_NUMBER)) {
setTotalProgress();
}
//if eiger, rate corr on, a put statement, dr=32 &setting subexp or dr =16 & setting exptime, set ratecorr to update table
double r;
if( (thisDetector->myDetectorType == EIGER) &&
getRateCorrection(r) &&
(t>=0) &&
(((index == SUBFRAME_ACQUISITION_TIME) && (thisDetector->dynamicRange == 32))||
((index == ACQUISITION_TIME) && (thisDetector->dynamicRange == 16)))
&& (t>=0) && getRateCorrection(r)){
setRateCorrection(r);
}
}
//send acquisiton period/frame number to receiver
if((index==FRAME_NUMBER)||(index==FRAME_PERIOD)||(index==CYCLES_NUMBER)){
if(ret != FAIL){
retval = thisDetector->timerValue[index];
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
int64_t args[2];
args[1] = retval;
if((t == -1) && (ret!= FORCE_UPDATE)) args[1] = -1;
if((index==FRAME_NUMBER)||(index==CYCLES_NUMBER)){
#ifdef VERBOSE
std::cout << "Setting/Getting number of frames " << index <<" to/from receiver " << args[1] << std::endl;
#endif
args[0] = FRAME_NUMBER;
retval = abs(thisDetector->timerValue[FRAME_NUMBER]*thisDetector->timerValue[CYCLES_NUMBER]);
if(args[1] != -1) args[1]=retval;
}else{
#ifdef VERBOSE
std::cout << "Setting/Getting acquisition period " << index << " to/from receiver " << args[1] << std::endl;
#endif
args[0] = FRAME_PERIOD;
//if acquisition period is zero, then #frames/buffer depends on exposure time and not acq period
if(!retval) args[1] = timerValue[ACQUISITION_TIME];
}
if(ret != FAIL){
int64_t args[2];
retval = -1;
args[0] = index;
args[1] = thisDetector->timerValue[index];
if (connectData() == OK)
ret=thisReceiver->sendIntArray(fnum2,ut,args);
disconnectData();
if((ut != retval)|| (ret==FAIL)){
ret = FAIL;
if(index==FRAME_PERIOD){
//exptime sent if acq period = 0
if(retval){
cout << "ERROR:Acquisition Period in receiver set incorrectly to " << ut << " instead of " << thisDetector->timerValue[index] << endl;
setErrorMask((getErrorMask())|(RECEIVER_ACQ_PERIOD_NOT_SET));
}
}else{
cout << "ERROR:Number of Frames (* Number of cycles) in receiver set incorrectly to " << ut << " instead of " << thisDetector->timerValue[index] << endl;
setErrorMask((getErrorMask())|(RECEIVER_FRAME_NUM_NOT_SET));
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
//set #frames, #cycles
if((index==FRAME_NUMBER)||(index==CYCLES_NUMBER)){
#ifdef VERBOSE
std::cout << "Setting/Getting number of frames " << index <<" to/from receiver " << args[1] << std::endl;
#endif
if(thisDetector->timerValue[CYCLES_NUMBER]==0)
args[1] = thisDetector->timerValue[FRAME_NUMBER];
else
args[1] = thisDetector->timerValue[FRAME_NUMBER]*thisDetector->timerValue[CYCLES_NUMBER];
}
//set period
else{
#ifdef VERBOSE
std::cout << "Setting/Getting acquisition period " << index << " to/from receiver " << args[1] << std::endl;
#endif
//if acquisition period is zero, then #frames/buffer depends on exposure time and not acq period
if(!args[1])
args[1] = timerValue[ACQUISITION_TIME];
}
char mess[MAX_STR_LENGTH]="";
if (connectData() == OK)
ret=thisReceiver->sendIntArray(fnum2,retval,args,mess);
disconnectData();
if((args[1] != retval)|| (ret==FAIL)){
ret = FAIL;
if(index==FRAME_PERIOD){
//exptime sent if acq period = 0
if(retval){
if(strstr(mess,"receiver not idle")==NULL)
cout << "ERROR:Acquisition Period in receiver set incorrectly to " << retval << " instead of " << args[1] << endl;
setErrorMask((getErrorMask())|(RECEIVER_ACQ_PERIOD_NOT_SET));
}
}else{
if(strstr(mess,"receiver not idle")==NULL)
cout << "ERROR:Number of Frames (* Number of cycles) in receiver set incorrectly to " << retval << " instead of " << args[1] << endl;
setErrorMask((getErrorMask())|(RECEIVER_FRAME_NUM_NOT_SET));
}
}
if(ret==FORCE_UPDATE)
updateReceiver();
}
}
}
if(ret==FORCE_UPDATE)
updateReceiver();
}
}
}
return thisDetector->timerValue[index];
};
@ -4580,7 +4644,7 @@ int slsDetector::setDynamicRange(int n){
#ifdef VERBOSE
std::cout<< "Setting dynamic range to "<< n << std::endl;
#endif
if (n==24)
if ((thisDetector->myDetectorType == MYTHEN) &&(n==24))
n=32;
@ -4595,8 +4659,12 @@ int slsDetector::setDynamicRange(int n){
if (rateret==FAIL) {
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
if(strstr(mess,"Rate Correction")!=NULL)
setErrorMask((getErrorMask())|(RATE_CORRECTION_NOT_32BIT));
if(strstr(mess,"Rate Correction")!=NULL){
if(strstr(mess,"32")!=NULL)
setErrorMask((getErrorMask())|(RATE_CORRECTION_NOT_32or16BIT));
else
setErrorMask((getErrorMask())|(COULD_NOT_SET_RATE_CORRECTION));
}
}
}
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
@ -5198,7 +5266,7 @@ int slsDetector::setRateCorrection(double t){
if(strstr(mess,"default tau")!=NULL)
setErrorMask((getErrorMask())|(RATE_CORRECTION_NO_TAU_PROVIDED));
if(strstr(mess,"32")!=NULL)
setErrorMask((getErrorMask())|(RATE_CORRECTION_NOT_32BIT));
setErrorMask((getErrorMask())|(RATE_CORRECTION_NOT_32or16BIT));
else
setErrorMask((getErrorMask())|(COULD_NOT_SET_RATE_CORRECTION));
}
@ -5554,7 +5622,7 @@ char* slsDetector::setDetectorMAC(string detectorMAC){
(detectorMAC[11]==':')&&(detectorMAC[14]==':')){
strcpy(thisDetector->detectorMAC,detectorMAC.c_str());
if(!strcmp(thisDetector->receiver_hostname,"none"))
std::cout << "Warning: UDP Set up failed. Receiver hostname not set." << endl;
std::cout << "Warning: Receiver hostname not set yet." << endl;
else if(setUDPConnection()==FAIL)
std::cout<< "Warning: UDP connection set up failed" << std::endl;
}else{
@ -5581,7 +5649,7 @@ char* slsDetector::setDetectorIP(string detectorIP){
if(result!=0){
strcpy(thisDetector->detectorIP,detectorIP.c_str());
if(!strcmp(thisDetector->receiver_hostname,"none"))
std::cout << "Warning: UDP Set up failed. Receiver hostname not set." << endl;
std::cout << "Warning: Receiver hostname not set yet." << endl;
else if(setUDPConnection()==FAIL)
std::cout<< "Warning: UDP connection set up failed" << std::endl;
}else{
@ -5600,6 +5668,7 @@ char* slsDetector::setReceiver(string receiverIP){
cprintf(RED,"Acquisition already running, Stopping it.\n");
stopAcquisition();
}
updateDetector();
strcpy(thisDetector->receiver_hostname,receiverIP.c_str());
@ -5620,6 +5689,7 @@ char* slsDetector::setReceiver(string receiverIP){
std::cout << "frame number:" << thisDetector->timerValue[FRAME_NUMBER] << endl;
std::cout << "dynamic range:" << thisDetector->dynamicRange << endl << endl;
std::cout << "10GbE:" << thisDetector->tenGigaEnable << endl << endl;
//std::cout << "dataStreaming:" << enableDataStreamingFromReceiver(-1) << endl << endl;
/** enable compresison, */
#endif
if(setDetectorType()!= GENERIC){
@ -5643,6 +5713,10 @@ char* slsDetector::setReceiver(string receiverIP){
setTimer(FRAME_PERIOD,thisDetector->timerValue[FRAME_PERIOD]);
setTimer(FRAME_NUMBER,thisDetector->timerValue[FRAME_NUMBER]);
setDynamicRange(thisDetector->dynamicRange);
if(thisDetector->myDetectorType == EIGER)
activate(-1);
//std::cout << "***********************************dataStreaming:" << parentDet->enableDataStreamingFromReceiver(-1) << endl << endl;
//parentDet->enableDataStreamingFromReceiver(parentDet->enableDataStreamingFromReceiver(-1));
//set scan tag
setUDPConnection();
if(thisDetector->myDetectorType == EIGER)
@ -5668,7 +5742,7 @@ char* slsDetector::setReceiverUDPIP(string udpip){
}else{
strcpy(thisDetector->receiverUDPIP,udpip.c_str());
if(!strcmp(thisDetector->receiver_hostname,"none"))
std::cout << "Warning: UDP Set up failed. Receiver hostname not set." << endl;
std::cout << "Warning: Receiver hostname not set yet." << endl;
else if(setUDPConnection()==FAIL){
std::cout<< "Warning: UDP connection set up failed" << std::endl;
}
@ -5691,7 +5765,7 @@ char* slsDetector::setReceiverUDPMAC(string udpmac){
(udpmac[11]==':')&&(udpmac[14]==':')){
strcpy(thisDetector->receiverUDPMAC,udpmac.c_str());
if(!strcmp(thisDetector->receiver_hostname,"none"))
std::cout << "Warning: UDP Set up failed. Receiver hostname not set." << endl;
std::cout << "Warning: Receiver hostname not set yet." << endl;
else if(setUDPConnection()==FAIL){
std::cout<< "Warning: UDP connection set up failed" << std::endl;
}
@ -5710,7 +5784,7 @@ char* slsDetector::setReceiverUDPMAC(string udpmac){
int slsDetector::setReceiverUDPPort(int udpport){
thisDetector->receiverUDPPort = udpport;
if(!strcmp(thisDetector->receiver_hostname,"none"))
std::cout << "Warning: UDP Set up failed. Receiver hostname not set." << endl;
std::cout << "Warning: Receiver hostname not set yet." << endl;
else if(setUDPConnection()==FAIL){
std::cout<< "Warning: UDP connection set up failed" << std::endl;
}
@ -5720,7 +5794,7 @@ int slsDetector::setReceiverUDPPort(int udpport){
int slsDetector::setReceiverUDPPort2(int udpport){
thisDetector->receiverUDPPort2 = udpport;
if(!strcmp(thisDetector->receiver_hostname,"none"))
std::cout << "Warning: UDP Set up failed. Receiver hostname not set." << endl;
std::cout << "Warning: Receiver hostname not set yet." << endl;
else if(setUDPConnection()==FAIL){
std::cout<< "Warning: UDP connection set up failed" << std::endl;
}
@ -5774,7 +5848,7 @@ int slsDetector::setUDPConnection(){
//called before set up
if(!strcmp(thisDetector->receiver_hostname,"none")){
std::cout << "Warning: UDP Set up failed. Receiver hostname not set." << endl;
std::cout << "Warning: Receiver hostname not set yet." << endl;
return FAIL;
}
@ -6478,6 +6552,260 @@ int slsDetector::writeSettingsFile(string fname, int imod, int* iodelay){
int slsDetector::programFPGA(string fname){
int ret=FAIL;
int fnum=F_PROGRAM_FPGA;
char mess[MAX_STR_LENGTH]="";
int64_t retval = -1;
size_t filesize=0;
char* fpgasrc = NULL;
if(thisDetector->myDetectorType != JUNGFRAU){
std::cout << "Not implemented for this detector" << std::endl;
return FAIL;
}
//check if it exists
struct stat st;
if(stat(fname.c_str(),&st)){
std::cout << "Programming file does not exist" << endl;
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
return FAIL;
}
//create destination file name,replaces original filename with Jungfrau.rawbin
string destfname;
size_t found = fname.find_last_of("/\\");
if(found == string::npos)
destfname = "";
else
destfname = fname.substr(0,found+1);
destfname.append("Jungfrau_MCB.rawbin");
#ifdef VERBOSE
std::cout << "Converting " << fname << " to " << destfname << std::endl;
#endif
int filepos,x,y,i;
FILE* src = fopen(fname.c_str(),"rb");
FILE* dst = fopen(destfname.c_str(),"wb");
// Remove header (0...11C)
for (filepos=0; filepos < 0x11C; filepos++)
fgetc(src);
// Write 0x80 times 0xFF (0...7F)
for (filepos=0; filepos < 0x80; filepos++)
fputc(0xFF,dst);
// Swap bits and write to file
for (filepos=0x80; filepos < 0x1000000; filepos++) {
x = fgetc(src);
if (x < 0) break;
y=0;
for (i=0; i < 8; i++)
y=y| ( (( x & (1<<i) ) >> i) << (7-i) ); // This swaps the bits
fputc(y,dst);
}
if (filepos < 0x1000000){
std::cout << "Could not convert programming file. EOF before end of flash" << std::endl;
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
return FAIL;
}
#ifdef VERBOSE
std::cout << "File has been converted to " << destfname << std::endl;
#endif
//loading file to memory
FILE* fp = fopen(destfname.c_str(),"r");
if(fp == NULL){
std::cout << "Could not open rawbin file" << std::endl;
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
return FAIL;
}
if(fseek(fp,0,SEEK_END)){
std::cout << "Seek error in rawbin file" << std::endl;
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
return FAIL;
}
filesize = ftell(fp);
if(filesize <= 0){
std::cout << "Could not get length of rawbin file" << std::endl;
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
return FAIL;
}
rewind(fp);
fpgasrc = (char*)malloc(filesize+1);
if(fpgasrc == NULL){
std::cout << "Could not allocate size of program" << std::endl;
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
return FAIL;
}
if(fread(fpgasrc, sizeof(char), filesize, fp) != filesize){
std::cout << "Could not read rawbin file" << std::endl;
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
return FAIL;
}
if(fclose(fp)){
std::cout << "Could not close rawbin file" << std::endl;
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
return FAIL;
}
#ifdef VERBOSE
std::cout << "Successfully loaded the rawbin file to program memory" << std::endl;
#endif
#ifdef VERBOSE
std::cout<< "Sending programming binary to detector " << endl;
#endif
if (setOnline(ONLINE_FLAG)==ONLINE_FLAG) {
if (connectControl() == OK){
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
controlSocket->SendDataOnly(&filesize,sizeof(filesize));
//check opening error
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret==FAIL) {
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
filesize = 0;
}
//erasing flash
if(ret!=FAIL){
std::cout<< "This can take awhile. Please be patient..." << endl;
printf("Erasing Flash:%d%%\r",0);
std::cout << flush;
//erasing takes 65 seconds, printing here (otherwise need threads in server-unnecessary)
int count = 66;
while(count>0){
usleep(1 * 1000 * 1000);
count--;
printf("Erasing Flash:%d%%\r",(int) (((double)(65-count)/65)*100));
std::cout << flush;
}
std::cout<<std::endl;
printf("Writing to Flash:%d%%\r",0);
std::cout << flush;
}
//sending program in parts of 2mb each
size_t unitprogramsize = 0;
int currentPointer = 0;
size_t totalsize= filesize;
while(ret != FAIL && (filesize > 0)){
unitprogramsize = MAX_FPGAPROGRAMSIZE; //2mb
if(unitprogramsize > filesize) //less than 2mb
unitprogramsize = filesize;
#ifdef VERBOSE
std::cout << "unitprogramsize:" << unitprogramsize << "\t filesize:" << filesize << std::endl;
#endif
controlSocket->SendDataOnly(fpgasrc+currentPointer,unitprogramsize);
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret!=FAIL) {
filesize-=unitprogramsize;
currentPointer+=unitprogramsize;
//print progress
printf("Writing to Flash:%d%%\r",(int) (((double)(totalsize-filesize)/totalsize)*100));
std::cout << flush;
}else{
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
}
}
std::cout<<std::endl;
//check ending error
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret==FAIL) {
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
setErrorMask((getErrorMask())|(PROGRAMMING_ERROR));
}
disconnectControl();
if (ret==FORCE_UPDATE)
updateDetector();
}
}
//free resources
if(fpgasrc != NULL)
free(fpgasrc);
return ret;
}
int slsDetector::resetFPGA(){
int ret=FAIL;
int fnum=F_RESET_FPGA;
char mess[MAX_STR_LENGTH]="";
if(thisDetector->myDetectorType != JUNGFRAU){
std::cout << "Not implemented for this detector" << std::endl;
return FAIL;
}
#ifdef VERBOSE
std::cout<< "Sending reset to FPGA " << endl;
#endif
if (setOnline(ONLINE_FLAG)==ONLINE_FLAG) {
if (connectControl() == OK){
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
//check opening error
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret==FAIL) {
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
setErrorMask((getErrorMask())|(RESET_ERROR));
}
disconnectControl();
if (ret==FORCE_UPDATE)
updateDetector();
}
}
return ret;
}
int slsDetector::powerChip(int ival){
int ret=FAIL;
int fnum=F_POWER_CHIP;
char mess[MAX_STR_LENGTH]="";
int retval=-1;
if(thisDetector->myDetectorType != JUNGFRAU && thisDetector->myDetectorType != JUNGFRAUCTB ){
std::cout << "Not implemented for this detector" << std::endl;
return FAIL;
}
#ifdef VERBOSE
std::cout<< "Sending power on/off/get to the chip " << endl;
#endif
if (setOnline(ONLINE_FLAG)==ONLINE_FLAG) {
if (connectControl() == OK){
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
controlSocket->SendDataOnly(&ival,sizeof(ival));
//check opening error
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret==FAIL) {
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned error: " << mess << std::endl;
setErrorMask((getErrorMask())|(POWER_CHIP));
}else
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
disconnectControl();
if (ret==FORCE_UPDATE)
updateDetector();
}
}
return retval;
}
int slsDetector::loadSettingsFile(string fname, int imod) {
sls_detector_module *myMod=NULL;
@ -6933,8 +7261,11 @@ string slsDetector::setFilePath(string s) {
if(stat(s.c_str(),&st)){
std::cout << "path does not exist" << endl;
setErrorMask((getErrorMask())|(FILE_PATH_DOES_NOT_EXIST));
}else
}else{
pthread_mutex_lock(&ms);
fileIO::setFilePath(s);
pthread_mutex_unlock(&ms);
}
}
}
@ -6946,8 +7277,11 @@ string slsDetector::setFilePath(string s) {
if (connectData() == OK)
ret=thisReceiver->sendString(fnum,retval,arg);
disconnectData();
if(ret!=FAIL)
if(ret!=FAIL){
pthread_mutex_lock(&ms);
fileIO::setFilePath(string(retval));
pthread_mutex_unlock(&ms);
}
else if(!s.empty()){
std::cout << "path does not exist" << endl;
setErrorMask((getErrorMask())|(FILE_PATH_DOES_NOT_EXIST));
@ -6956,7 +7290,11 @@ string slsDetector::setFilePath(string s) {
updateReceiver();
}
return fileIO::getFilePath();
pthread_mutex_lock(&ms);
s = fileIO::getFilePath();
pthread_mutex_unlock(&ms);
return s;
}
@ -7001,7 +7339,11 @@ string slsDetector::setFileName(string s) {
}
}
return fileIO::getFileName();
pthread_mutex_lock(&ms);
s = fileIO::getFileName();
pthread_mutex_unlock(&ms);
return s;
}
@ -7252,65 +7594,54 @@ int slsDetector::resetFramesCaught(){
}
int* slsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex){
int fnum=F_READ_RECEIVER_FRAME;
int nel=thisDetector->dataBytes/sizeof(int);
int* retval=new int[nel];
int ret=FAIL;
int n;
char mess[MAX_STR_LENGTH]="Nothing";
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
#ifdef VERBOSE
std::cout<< "slsDetector: Reading frame from receiver "<< thisDetector->dataBytes << " " <<nel <<std::endl;
#endif
if (connectData() == OK){
dataSocket->SendDataOnly(&fnum,sizeof(fnum));
dataSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret==FAIL) {
n= dataSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned: " << mess << " " << n << std::endl;
delete [] retval;
disconnectData();
return NULL;
} else {
n=dataSocket->ReceiveDataOnly(fName,MAX_STR_LENGTH);
n=dataSocket->ReceiveDataOnly(&acquisitionIndex,sizeof(acquisitionIndex));
n=dataSocket->ReceiveDataOnly(&frameIndex,sizeof(frameIndex));
if(thisDetector->myDetectorType == EIGER)
n=dataSocket->ReceiveDataOnly(&subFrameIndex,sizeof(subFrameIndex));
n=dataSocket->ReceiveDataOnly(retval,thisDetector->dataBytes);
#ifdef VERBOSE
std::cout<< "Received "<< n << " data bytes" << std::endl;
#endif
if (n!=thisDetector->dataBytes) {
std::cout<<endl<< "wrong data size received: received " << n << " but expected from receiver " << thisDetector->dataBytes << std::endl;
ret=FAIL;
delete [] retval;
disconnectData();
return NULL;
}
//jungfrau masking adcval
if(thisDetector->myDetectorType == JUNGFRAU){
for(unsigned int i=0;i<nel;i++){
retval[i] = (retval[i] & 0x3FFF3FFF);
}
}
}
disconnectData();
}
}
return retval;
};
int* slsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex){
int fnum=F_READ_RECEIVER_FRAME;
int nel=thisDetector->dataBytes/sizeof(int);
int* retval=new int[nel];
int ret=FAIL;
int n;
char mess[MAX_STR_LENGTH]="Nothing";
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
#ifdef VERBOSE
std::cout<< "slsDetector: Reading frame from receiver "<< thisDetector->dataBytes << " " <<nel <<std::endl;
#endif
if (connectData() == OK){
dataSocket->SendDataOnly(&fnum,sizeof(fnum));
dataSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret==FAIL) {
n= dataSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned: " << mess << " " << n << std::endl;
delete [] retval;
disconnectData();
return NULL;
} else {
n=dataSocket->ReceiveDataOnly(fName,MAX_STR_LENGTH);
n=dataSocket->ReceiveDataOnly(&acquisitionIndex,sizeof(acquisitionIndex));
n=dataSocket->ReceiveDataOnly(&frameIndex,sizeof(frameIndex));
if(thisDetector->myDetectorType == EIGER)
n=dataSocket->ReceiveDataOnly(&subFrameIndex,sizeof(subFrameIndex));
n=dataSocket->ReceiveDataOnly(retval,thisDetector->dataBytes);
#ifdef VERBOSE
std::cout<< "Received "<< n << " data bytes" << std::endl;
#endif
if (n!=thisDetector->dataBytes) {
std::cout<<endl<< "wrong data size received: received " << n << " but expected from receiver " << thisDetector->dataBytes << std::endl;
ret=FAIL;
delete [] retval;
disconnectData();
return NULL; }
//jungfrau masking adcval
if(thisDetector->myDetectorType == JUNGFRAU){
for(unsigned int i=0;i<nel;i++){
retval[i] = (retval[i] & 0x3FFF3FFF);
}
}
}
disconnectData();
}
}
return retval;
};
@ -7373,16 +7704,22 @@ int slsDetector::updateReceiverNoWait() {
#ifdef VERBOSE
cout << "Updating receiver last modified by " << lastClientIP << std::endl;
#endif
n = dataSocket->ReceiveDataOnly(&ind,sizeof(ind));
pthread_mutex_lock(&ms);
fileIO::setFileIndex(ind);
pthread_mutex_unlock(&ms);
n = dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH);
pthread_mutex_lock(&ms);
fileIO::setFilePath(path);
pthread_mutex_unlock(&ms);
n = dataSocket->ReceiveDataOnly(path,MAX_STR_LENGTH);
pthread_mutex_lock(&ms);
fileIO::setFileName(path);
pthread_mutex_unlock(&ms);
return OK;
}
@ -7533,7 +7870,9 @@ int slsDetector::setFrameIndex(int index){
int arg = index;
if(thisDetector->receiverOnlineFlag==OFFLINE_FLAG){
fileIO::setFrameIndex(index);
pthread_mutex_lock(&ms);
fileIO::setFrameIndex(index);
pthread_mutex_unlock(&ms);
}
else if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
@ -7542,14 +7881,20 @@ int slsDetector::setFrameIndex(int index){
#endif
if (connectData() == OK)
ret=thisReceiver->sendInt(fnum,retval,arg);
disconnectData();
if(ret!=FAIL)
disconnectData();
if(ret!=FAIL){
pthread_mutex_lock(&ms);
fileIO::setFrameIndex(retval);
pthread_mutex_unlock(&ms);
}
if(ret==FORCE_UPDATE)
updateReceiver();
}
pthread_mutex_lock(&ms);
retval = fileIO::getFrameIndex();
pthread_mutex_unlock(&ms);
return fileIO::getFrameIndex();
return retval;
}
@ -7600,18 +7945,18 @@ int64_t slsDetector::clearAllErrorMask(){
int slsDetector::setReadReceiverFrequency(int getFromReceiver,int i){
int slsDetector::setReadReceiverFrequency(int getFromReceiver, int freq){
int fnum=F_READ_RECEIVER_FREQUENCY;
int ret = FAIL;
int retval=-1;
int arg = i;
int arg = freq;
if(!getFromReceiver)
return retval;
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "Sending read frequency to receiver " << arg << std::endl;
std::cout << "Sending read frequency to receiver " << arg << std::endl;
#endif
if (connectData() == OK)
ret=thisReceiver->sendInt(fnum,retval,arg);
@ -7622,14 +7967,44 @@ int slsDetector::setReadReceiverFrequency(int getFromReceiver,int i){
updateReceiver();
}
if ((i > 0) && (retval != i)){
cout << "could not set receiver read frequency:" << retval << endl;
if ((freq > 0) && (retval != freq)){
cout << "could not set receiver read frequency to " << freq <<" Returned:" << retval << endl;
setErrorMask((getErrorMask())|(RECEIVER_READ_FREQUENCY));
}
return retval;
}
int slsDetector::enableDataStreamingFromReceiver(int enable){
int fnum=F_STREAM_DATA_FROM_RECEIVER;
int ret = FAIL;
int retval=-1;
int arg = enable;
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
#ifdef VERBOSE
std::cout << "***************Sending Data Streaming in Receiver " << arg << std::endl;
#endif
if (connectData() == OK)
ret=thisReceiver->sendInt(fnum,retval,arg);
disconnectData();
if(ret==FAIL)
retval = -1;
if(ret==FORCE_UPDATE)
updateReceiver();
}
if ((enable > 0) && (retval != enable)){
cout << "could not set data streaming in receiver to " << enable <<" Returned:" << retval << endl;
setErrorMask((getErrorMask())|(DATA_STREAMING));
}
return retval;
}
int slsDetector::enableReceiverCompression(int i){
int fnum=F_ENABLE_RECEIVER_COMPRESSION;
int ret = FAIL;

View File

@ -522,7 +522,24 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
};
/** programs FPGA with pof file
\param fname file name
\returns OK or FAIL
*/
int programFPGA(string fname);
/** resets FPGA
\returns OK or FAIL
*/
int resetFPGA();
/** power on/off the chip
\param ival on is 1, off is 0, -1 to get
\returns OK or FAIL
*/
int powerChip(int ival= -1);
/** loads the modules settings/trimbits reading from a file
\param fname file name . If not specified, extension is automatically generated!
\param imod module number, -1 means all modules
@ -1580,15 +1597,18 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
int resetFramesCaught();
/**
* Reads a frame from receiver
* @param fName file name of current frame()
* @param acquisitionIndex current acquisition index
* @param frameIndex current frame index (for each scan)
* @param subFrameIndex current sub frame index (for 32 bit mode for eiger)
/returns a frame read from recever
*/
int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex);
* Create Receiving Data Threads
* @param destroy is true to destroy all the threads
* @return OK or FAIL
*/
int createReceivingDataThreads(bool destroy = false){return 0;};
/** Reads frames from receiver through a constant socket
*/
//void readFrameFromReceiver(){};
int* readFrameFromReceiver(char*, int&, int&, int&);
/** Locks/Unlocks the connection to the receiver
/param lock sets (1), usets (0), gets (-1) the lock
/returns lock status of the receiver
@ -1688,14 +1708,20 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
char* setDetectorNetworkParameter(networkParameter index, int delay);
/** Sets the read receiver frequency
if Receiver read upon gui request, readRxrFrequency=0,
if data required from receiver randomly readRxrFrequency=0,
else every nth frame to be sent to gui
@param getFromReceiver is 1 if it should ask the receiver,
0 if it can get it from multislsdetecter
@param i is the receiver read frequency
0 if it can get it from multi structure
@param freq is the receiver read frequency
/returns read receiver frequency
*/
int setReadReceiverFrequency(int getFromReceiver, int i=-1);
int setReadReceiverFrequency(int getFromReceiver, int freq=-1);
/** Enable or disable streaming data from receiver to client
* @param enable 0 to disable 1 to enable -1 to only get the value
* @returns data streaming
*/
int enableDataStreamingFromReceiver(int enable=-1);
/** enable/disable or get data compression in receiver
* @param i is -1 to get, 0 to disable and 1 to enable

View File

@ -146,6 +146,7 @@ int slsDetectorActions::getActionMode(int iaction){
int slsDetectorActions::setScan(int iscan, string script, int nvalues, double *values, string par, int precision) {
if (iscan>=0 && iscan<MAX_SCAN_LEVELS) {
// cout << "settings script to " << script <<endl;
if (script=="") {
scanMode[iscan]=noScan;
} else {
@ -160,6 +161,8 @@ int slsDetectorActions::setScan(int iscan, string script, int nvalues, double *v
scanMode[iscan]=trimbitsScan;
} else if (script=="position") {
scanMode[iscan]=positionScan;
} else if (script=="dac") {
scanMode[iscan]=dacScan;
} else {
scanMode[iscan]=scriptScan;
}
@ -202,15 +205,6 @@ int slsDetectorActions::setScan(int iscan, string script, int nvalues, double *v
setTotalProgress();
return scanMode[iscan];
} else
return -1;
@ -233,6 +227,8 @@ int slsDetectorActions::setScanScript(int iscan, string script) {
scanMode[iscan]=trimbitsScan;
} else if (script=="position") {
scanMode[iscan]=positionScan;
} else if (script=="dac") {
scanMode[iscan]=dacScan;
} else {
scanMode[iscan]=scriptScan;
}
@ -425,6 +421,9 @@ int slsDetectorActions::executeScan(int level, int istep) {
case thresholdScan:
setDAC((dacs_t)currentScanVariable[level],THRESHOLD,0); // threshold scan
break;
case dacScan:
setDAC((dacs_t)currentScanVariable[level],(slsDetectorDefs::dacIndex)atoi(getScanParameter(level).c_str()),0);
break;
case trimbitsScan:
trimbit=(int)currentScanVariable[level];
if(getDetectorsType() == EIGER)

View File

@ -25,7 +25,7 @@ class slsDetectorActions : public virtual slsDetectorBase
{
public :
enum {noScan, energyScan, thresholdScan, trimbitsScan, positionScan, scriptScan };
enum {noScan, energyScan, thresholdScan, trimbitsScan, positionScan, scriptScan, dacScan };
/** default constructor */

View File

@ -506,26 +506,20 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef
virtual int lockReceiver(int lock=-1)=0;
/**
* Reads a frame from receiver
* @param fName file name of current frame()
* @param acquisitionIndex current acquisition index
* @param frameIndex current frame index (for each scan)
* @param subFrameIndex current sub frame index (for 32 bit mode for eiger)
/returns a frame read from recever
/** Reads frames from receiver through a constant socket
*/
virtual int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex)=0;
/** Sets the read receiver frequency
if Receiver read upon gui request, readRxrFrequency=0,
if data required from receiver randomly readRxrFrequency=0,
else every nth frame to be sent to gui
@param getFromReceiver is 1 if it should ask the receiver,
0 if it can get it from multislsdetecter
@param i is the receiver read frequency
0 if it can get it from multi structure
@param freq is the receiver read frequency
/returns read receiver frequency
*/
virtual int setReadReceiverFrequency(int getFromReceiver, int i=-1)=0;
virtual int setReadReceiverFrequency(int getFromReceiver, int freq=-1)=0;
/** Sets the receiver to start any readout remaining in the fifo and
* change status to transmitting.

View File

@ -37,6 +37,9 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdStatus;
i++;
descrToFuncMap[i].m_pFuncName="datastream"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDataStream;
i++;
/* Detector structure configuration and debugging commands */
@ -441,6 +444,23 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAdvanced;
i++;
/* fpga */
descrToFuncMap[i].m_pFuncName="programfpga";
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAdvanced;
i++;
descrToFuncMap[i].m_pFuncName="resetfpga";
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAdvanced;
i++;
/* chip */
descrToFuncMap[i].m_pFuncName="powerchip";
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdAdvanced;
i++;
/* versions/ serial numbers getId */
descrToFuncMap[i].m_pFuncName="moduleversion"; //
@ -791,10 +811,19 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdADC;
i++;
descrToFuncMap[i].m_pFuncName="adc"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdADC;
i++;
descrToFuncMap[i].m_pFuncName="temp_fpgafl"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdADC;
i++;
descrToFuncMap[i].m_pFuncName="temp_fpgafr"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdADC;
i++;
/* r/w timers */
@ -929,6 +958,20 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
i++;
descrToFuncMap[i].m_pFuncName="dbitclk"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSpeed;
i++;
descrToFuncMap[i].m_pFuncName="dbitphase"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSpeed;
i++;
descrToFuncMap[i].m_pFuncName="dbitpipeline"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSpeed;
i++;
/* settings dump/retrieve */
descrToFuncMap[i].m_pFuncName="config";
@ -1339,6 +1382,43 @@ string slsDetectorCommand::helpStatus(int narg, char *args[], int action) {
}
string slsDetectorCommand::cmdDataStream(int narg, char *args[], int action) {
#ifdef VERBOSE
cout << string("Executing command ")+string(args[0])+string(" ( ")+cmd+string(" )\n");
#endif
int ival=-1;
char ans[100]="";
myDet->setOnline(ONLINE_FLAG);
myDet->setReceiverOnline(ONLINE_FLAG);
if (action==HELP_ACTION)
return helpStatus(narg,args,HELP_ACTION);
if (action==PUT_ACTION) {
if (!sscanf(args[1],"%d",&ival))
return string ("cannot scan datastream mode");
myDet->enableDataStreamingFromReceiver(ival);
}
sprintf(ans,"%d",myDet->enableDataStreamingFromReceiver());
return string(ans);
}
string slsDetectorCommand::helpDataStream(int narg, char *args[], int action) {
ostringstream os;
if (action==GET_ACTION || action==HELP_ACTION)
os << string("datastream \t gets if zmq data stream from receiver is enabled. \n");
if (action==PUT_ACTION || action==HELP_ACTION)
os << string("datastream i\t enables/disables the zmq data stream from receiver. \n");
return os.str();
}
string slsDetectorCommand::cmdFree(int narg, char *args[], int action) {
#ifdef VERBOSE
@ -3894,6 +3974,10 @@ string slsDetectorCommand::cmdADC(int narg, char *args[], int action) {
adc=TEMPERATURE_SODL;
else if (cmd=="temp_sodr")
adc=TEMPERATURE_SODR;
else if (cmd=="temp_fpgafl")
adc=TEMPERATURE_FPGA2;
else if (cmd=="temp_fpgafr")
adc=TEMPERATURE_FPGA3;
else
return string("cannot decode adc ")+cmd;
@ -3926,6 +4010,8 @@ string slsDetectorCommand::helpADC(int narg, char *args[], int action) {
os << "temp_dcdc " << "Cannot be set" << std::endl;
os << "temp_sodl " << "Cannot be set" << std::endl;
os << "temp_sodr " << "Cannot be set" << std::endl;
os << "temp_fpgafl " << "Cannot be set" << std::endl;
os << "temp_fpgafr " << "Cannot be set" << std::endl;
}
if (action==GET_ACTION || action==HELP_ACTION) {
os << "temp_adc " << "\t gets the temperature of the adc" << std::endl;
@ -3935,6 +4021,8 @@ string slsDetectorCommand::helpADC(int narg, char *args[], int action) {
os << "temp_dcdc " << "\t gets the temperature close to the dc dc converter" << std::endl;
os << "temp_sodl " << "\t gets the temperature close to the left so-dimm memory" << std::endl;
os << "temp_sodr " << "\t gets the temperature close to the right so-dimm memory" << std::endl;
os << "temp_fpgafl " << "\t gets the temperature of the left front end board fpga" << std::endl;
os << "temp_fpgafr " << "\t gets the temperature of the left front end board fpga" << std::endl;
}
return os.str();
}
@ -4201,6 +4289,13 @@ string slsDetectorCommand::cmdSpeed(int narg, char *args[], int action) {
index=ADC_CLOCK;
else if (cmd=="adcphase") {
index=ADC_PHASE;
t=100000;
} else if (cmd=="adcpipeline")
index=ADC_PIPELINE;
else if (cmd=="dbitclk")
index=DBIT_CLOCK;
else if (cmd=="dbitphase") {
index=DBIT_PHASE;
t=100000;
} else if (cmd=="adcpipeline")
index=ADC_PIPELINE;
@ -4268,15 +4363,16 @@ string slsDetectorCommand::helpSpeed(int narg, char *args[], int action) {
string slsDetectorCommand::cmdAdvanced(int narg, char *args[], int action) {
int retval;
char answer[1000]="";
int retval;
char answer[1000]="";
if (action==HELP_ACTION)
return helpAdvanced(narg, args, action);
if (cmd=="flags") {
if (action==HELP_ACTION)
return helpAdvanced(narg, args, action);
if (cmd=="flags") {
readOutFlags flag=GET_READOUT_FLAGS;
readOutFlags flag=GET_READOUT_FLAGS;
if (action==PUT_ACTION) {
string sval=string(args[1]);
@ -4302,9 +4398,7 @@ char answer[1000]="";
return string("could not scan flag ")+string(args[1]);
}
myDet->setOnline(ONLINE_FLAG);
myDet->setOnline(ONLINE_FLAG);
retval = myDet->setReadOutFlags(flag);
// cout << hex << flag << " " << retval << endl;
@ -4333,25 +4427,67 @@ char answer[1000]="";
return string("unknown");
} else if (cmd=="extsig") {
externalSignalFlag flag=GET_EXTERNAL_SIGNAL_FLAG;
int is=-1;
if (sscanf(args[0],"extsig:%d",&is))
;
else
return string("could not scan signal number ")+string(args[0]);
if (action==PUT_ACTION) {
flag=myDet->externalSignalType(args[1]);
if (flag==GET_EXTERNAL_SIGNAL_FLAG)
return string("could not scan external signal mode ")+string(args[1]);
}
myDet->setOnline(ONLINE_FLAG);
return myDet->externalSignalType(myDet->setExternalSignalFlags(flag,is));
} else if (cmd=="extsig") {
externalSignalFlag flag=GET_EXTERNAL_SIGNAL_FLAG;
int is=-1;
if (sscanf(args[0],"extsig:%d",&is))
;
else
return string("could not scan signal number ")+string(args[0]);
} else
return string("could not decode flag ")+cmd;
if (action==PUT_ACTION) {
flag=myDet->externalSignalType(args[1]);
if (flag==GET_EXTERNAL_SIGNAL_FLAG)
return string("could not scan external signal mode ")+string(args[1]);
}
myDet->setOnline(ONLINE_FLAG);
return myDet->externalSignalType(myDet->setExternalSignalFlags(flag,is));
} else if (cmd=="programfpga") {
if (action==GET_ACTION)
return string("cannot get");
if(strstr(args[1],".pof")==NULL)
return string("wrong usage: programming file should have .pof extension");
string sval=string(args[1]);
#ifdef VERBOSE
std::cout<< " programming file " << sval << std::endl;
#endif
myDet->setOnline(ONLINE_FLAG);
if(myDet->programFPGA(sval) == OK)
return string("successful");
return string("unsuccessful");
}
else if (cmd=="resetfpga") {
if (action==GET_ACTION)
return string("cannot get");
#ifdef VERBOSE
std::cout<< " resetting fpga " << sval << std::endl;
#endif
myDet->setOnline(ONLINE_FLAG);
if(myDet->resetFPGA() == OK)
return string("successful");
return string("unsuccessful");
}
else if (cmd=="powerchip") {
char ans[100];
myDet->setOnline(ONLINE_FLAG);
if (action==PUT_ACTION){
int ival = -1;
if (!sscanf(args[1],"%d",&ival))
return string("could not scan powerchip parameter " + string(args[1]));
myDet->powerChip(ival);
}
sprintf(ans,"%d",myDet->powerChip());
return string(ans);
}
else
return string("unknown command ")+cmd;
}
@ -4363,7 +4499,9 @@ string slsDetectorCommand::helpAdvanced(int narg, char *args[], int action) {
os << "extsig:i mode \t sets the mode of the external signal i. can be \n \t \t \t off, \n \t \t \t gate_in_active_high, \n \t \t \t gate_in_active_low, \n \t \t \t trigger_in_rising_edge, \n \t \t \t trigger_in_falling_edge, \n \t \t \t ro_trigger_in_rising_edge, \n \t \t \t ro_trigger_in_falling_edge, \n \t \t \t gate_out_active_high, \n \t \t \t gate_out_active_low, \n \t \t \t trigger_out_rising_edge, \n \t \t \t trigger_out_falling_edge, \n \t \t \t ro_trigger_out_rising_edge, \n \t \t \t ro_trigger_out_falling_edge" << std::endl;
os << "flags mode \t sets the readout flags to mode. can be none, storeinram, tot, continous, parallel, nonparallel, safe, digital, analog_digital, unknown" << std::endl;
os << "programfpga f \t programs the fpga with file f (with .pof extension)." << std::endl;
os << "resetfpga f \t resets fpga, f can be any value" << std::endl;
}
if (action==GET_ACTION || action==HELP_ACTION) {
@ -4482,7 +4620,8 @@ string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) {
if(!strcasecmp(args[1],"start"))
myDet->startReceiver();
else if(!strcasecmp(args[1],"stop")){
myDet->startReceiverReadout();
//myDet->stopReceiver();
// myDet->startReceiverReadout();
/*runStatus s = myDet->getReceiverStatus();
while(s != RUN_FINISHED){
usleep(50000);

View File

@ -38,6 +38,7 @@ class slsDetectorCommand : public virtual slsDetectorDefs {
static string helpData(int narg, char *args[], int action);
static string helpFrame(int narg, char *args[], int action);
static string helpStatus(int narg, char *args[], int action);
static string helpDataStream(int narg, char *args[], int action);
static string helpFree(int narg, char *args[], int action);
static string helpAdd(int narg, char *args[], int action);
static string helpRemove(int narg, char *args[], int action);
@ -109,6 +110,7 @@ class slsDetectorCommand : public virtual slsDetectorDefs {
string cmdData(int narg, char *args[], int action);
string cmdFrame(int narg, char *args[], int action);
string cmdStatus(int narg, char *args[], int action);
string cmdDataStream(int narg, char *args[], int action);
string cmdFree(int narg, char *args[], int action);
string cmdAdd(int narg, char *args[], int action);
string cmdRemove(int narg, char *args[], int action);

View File

@ -240,7 +240,9 @@ int slsDetectorUsers::setReceiverMode(int n){
return myDetector->setReadReceiverFrequency(1,n);
}
int slsDetectorUsers::enableDataStreamingFromReceiver(int i){
return myDetector->enableDataStreamingFromReceiver(i);
}
int64_t slsDetectorUsers::getModuleFirmwareVersion(){

View File

@ -450,6 +450,15 @@ class slsDetectorUsers
virtual void finalizeDataset(double *a, double *v, double *e, int &np);
/**
Enable data streaming from receiver (zmq)
\param i 1 to set, 0 to reset and -1 to get
\returns data streaming enable
*/
int enableDataStreamingFromReceiver(int i=-1);
/**
get get Module Firmware Version
\returns id

View File

@ -8,7 +8,7 @@
#include <cstdlib>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <time.h> //clock()
using namespace std;
slsDetectorUtils::slsDetectorUtils() {
@ -42,6 +42,8 @@ slsDetectorUtils::slsDetectorUtils() {
int slsDetectorUtils::acquire(int delflag){
struct timespec begin,end;
clock_gettime(CLOCK_REALTIME, &begin);
//ensure acquire isnt started multiple times by same client
if(getAcquiringFlag() == false)
@ -58,11 +60,15 @@ int slsDetectorUtils::acquire(int delflag){
}else{
//put receiver read frequency to random if no gui
int ret = setReadReceiverFrequency(0);
if(ret>0 && (acquisition_finished == NULL)){
std::cout << "Error: receiver read frequency is set to " << ret << " but should be > 0 only when using gui." << std::endl;
if(ret>0 && (dataReady == NULL)){
ret = setReadReceiverFrequency(1,0);
std::cout << "Current receiver read frequency: " << ret << std::endl;
std::cout << "No Data call back and hence receiver read frequency reset to " << ret <<" (Random)" << std::endl;
}
//start/stop data streaming threads if threads in client enabled/disabled
ret = enableDataStreamingFromReceiver(-1);
// cout<<"getting datastream:"<<ret<<endl;
// cout<<"result of enabledatastream:"<<enableDataStreamingFromReceiver(ret)<<endl;
}
int nc=setTimer(CYCLES_NUMBER,-1);
@ -72,10 +78,6 @@ int slsDetectorUtils::acquire(int delflag){
int multiframe = nc*nf;
pthread_mutex_lock(&mg);
acquiringDone = 0;
pthread_mutex_unlock(&mg);
// setTotalProgress();
//moved these 2 here for measurement change
progressIndex=0;
@ -144,36 +146,34 @@ int slsDetectorUtils::acquire(int delflag){
}
if(receiver){
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
if(getReceiverStatus()!=IDLE)
stopReceiver();
if(setReceiverOnline()==OFFLINE_FLAG)
*stoppedFlag=1;
//multi detectors shouldnt have different receiver read frequencies enabled/disabled
if(setReadReceiverFrequency(0) < 0){
std::cout << "Error: The receiver read frequency is invalid:" << setReadReceiverFrequency(0) << std::endl;
*stoppedFlag=1;
*stoppedFlag=1;
}
if(setReceiverOnline()==OFFLINE_FLAG)
*stoppedFlag=1;
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
}
if (*threadedProcessing) {
sem_init(&sem_queue,0,0);
startThread(delflag);
}
if (*threadedProcessing)
startThread(delflag);
#ifdef VERBOSE
cout << " starting thread " << endl;
#endif
//resets frames caught in receiver
if(receiver){
resetFramesCaught();
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
resetFramesCaught();
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
}
for(int im=0;im<nm;im++) {
#ifdef VERBOSE
@ -271,7 +271,7 @@ int slsDetectorUtils::acquire(int delflag){
setCurrentFrameIndex(0);
if(receiver)
pthread_mutex_lock(&mg);
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
if (multiframe>1)
setFrameIndex(0);
else
@ -279,34 +279,36 @@ int slsDetectorUtils::acquire(int delflag){
if(receiver){
pthread_mutex_unlock(&mg);//unlock previous
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
pthread_mutex_lock(&mp);
createFileName();
pthread_mutex_unlock(&mp);
//send receiver file name
pthread_mutex_lock(&mg);
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
setFileName(fileIO::getFileName());
if(setReceiverOnline()==OFFLINE_FLAG){
stopReceiver();
*stoppedFlag=1;
pthread_mutex_unlock(&mg);
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
break;
}
//start receiver
if(startReceiver() == FAIL) {
cout << "Start receiver failed " << endl;
stopReceiver();
*stoppedFlag=1;
pthread_mutex_unlock(&mg);
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
break;
}
pthread_mutex_unlock(&mg);
cout << "Receiver started " << endl;
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
}
#ifdef VERBOSE
cout << "Acquiring " << endl;
#endif
startAndReadAll();
cout << "detector finished " << endl;
#ifdef VERBOSE
cout << "finished " << endl;
cout << "returned! " << endl;
#endif
@ -339,56 +341,23 @@ int slsDetectorUtils::acquire(int delflag){
break;
// cout << "mglock " << endl;;
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
// cout << "done " << endl;;
//offline
if(setReceiverOnline()==OFFLINE_FLAG){
// wait until data processing thread has finished the data
pthread_mutex_lock(&mg);
acquiringDone = 1;
pthread_mutex_unlock(&mg);
if (*threadedProcessing) {
sem_wait(&sem_queue);
pthread_mutex_lock(&mg);
acquiringDone = 0;
pthread_mutex_unlock(&mg);
if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH) || (getDetectorsType()==JUNGFRAU)|| (getDetectorsType()==JUNGFRAUCTB) ){
if((*correctionMask)&(1<<WRITE_FILE))
closeDataFile();
}
#ifdef VERBOSE
cout << "check data queue size " << endl;
#endif
/*while (dataQueueSize()){
//#ifdef VERBOSE
cout << "AAAAAAAAA check data queue size " << endl;
//#endif
usleep(100000);
}*/
if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH) || (getDetectorsType()==JUNGFRAU) ){
if((*correctionMask)&(1<<WRITE_FILE))
closeDataFile();
}
}
//online
else{
pthread_mutex_lock(&mg);
acquiringDone = 1;
pthread_mutex_unlock(&mg);
// wait until data processing thread has taken the last frame
if (*threadedProcessing) {
sem_wait(&sem_queue);
pthread_mutex_lock(&mg);
acquiringDone = 0;
pthread_mutex_unlock(&mg);
}
pthread_mutex_lock(&mg);
cout << "Stopping receiver " << endl;;
stopReceiver();
pthread_mutex_unlock(&mg);
cout<<"***********receiver stopped"<<endl;
}
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
@ -466,9 +435,9 @@ int slsDetectorUtils::acquire(int delflag){
#endif
if(*correctionMask&(1<<WRITE_FILE))
IncrementFileIndex();
pthread_mutex_lock(&mg);
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
setFileIndex(fileIO::getFileIndex());
pthread_mutex_unlock(&mg);
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
break;
}
@ -479,15 +448,14 @@ int slsDetectorUtils::acquire(int delflag){
#endif
if(*correctionMask&(1<<WRITE_FILE))
IncrementFileIndex();
pthread_mutex_lock(&mg);
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
setFileIndex(fileIO::getFileIndex());
pthread_mutex_unlock(&mg);
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
if (measurement_finished){
pthread_mutex_lock(&mg);
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
measurement_finished(im,*fileIndex,measFinished_p);
pthread_mutex_unlock(&mg);
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
}
if (*stoppedFlag) {
@ -506,7 +474,6 @@ int slsDetectorUtils::acquire(int delflag){
#endif
setJoinThread(1);
pthread_join(dataProcessingThread, &status);
sem_destroy(&sem_queue);
#ifdef VERBOSE
cout << "data processing thread joined" << endl;
#endif
@ -537,6 +504,10 @@ int slsDetectorUtils::acquire(int delflag){
#endif
setAcquiringFlag(false);
clock_gettime(CLOCK_REALTIME, &end);
cout << "Elapsed time for acquisition:" << (( end.tv_sec - begin.tv_sec ) + ( end.tv_nsec - begin.tv_nsec ) / 1000000000.0) << " seconds" << endl;
return OK;
}

View File

@ -29,7 +29,7 @@ extern "C" {
#include <sstream>
#include <queue>
#include <math.h>
#include <semaphore.h>
using namespace std;
@ -491,7 +491,22 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
*/
virtual int loadSettingsFile(string fname, int imod=-1)=0;
/** programs FPGA with pof file
\param fname file name
\returns OK or FAIL
*/
virtual int programFPGA(string fname)=0;
/** resets FPGA
\returns OK or FAIL
*/
virtual int resetFPGA()=0;
/** power on/off the chip
\param ival on is 1, off is 0, -1 to get
\returns OK or FAIL
*/
virtual int powerChip(int ival= -1)=0;
/** saves the modules settings/trimbits writing to a file
\param fname file name . Axtension is automatically generated!
@ -641,16 +656,17 @@ virtual int getReceiverCurrentFrameIndex()=0;
virtual int resetFramesCaught()=0;
/**
* Reads a frame from receiver
* @param fName file name of current frame()
* @param acquisitionIndex current acquisition index
* @param frameIndex current frame index (for each scan)
* @param subFrameIndex current sub frame index (for 32 bit mode for eiger)
/returns a frame read from recever
* Create Receiving Data Threads
* @param destroy is true to destroy all the threads
* @return OK or FAIL
*/
virtual int createReceivingDataThreads(bool destroy = false)=0;
/** Reads frames from receiver through a constant socket
*/
virtual int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex)=0;
//virtual void readFrameFromReceiver()=0;
virtual int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex)=0;
/**
Turns off the receiver server!
*/
@ -693,14 +709,20 @@ virtual int setROI(int n=-1,ROI roiLimits[]=NULL)=0;
virtual ROI* getROI(int &n)=0;
/** Sets the read receiver frequency
if Receiver read upon gui request, readRxrFrequency=0,
if data required from receiver randomly readRxrFrequency=0,
else every nth frame to be sent to gui
@param getFromReceiver is 1 if it should ask the receiver,
0 if it can get it from multislsdetecter
@param i is the receiver read frequency
0 if it can get it from multi structure
@param freq is the receiver read frequency
/returns read receiver frequency
*/
virtual int setReadReceiverFrequency(int getFromReceiver, int i=-1)=0;
virtual int setReadReceiverFrequency(int getFromReceiver, int freq=-1)=0;
/** Enable or disable streaming of data from receiver to client
* @param enable 0 to disable 1 to enable -1 to only get the value
* @returns data streaming
*/
virtual int enableDataStreamingFromReceiver(int enable=-1)=0;
/** enable/disable or get data compression in receiver
@ -824,7 +846,6 @@ virtual int setReceiverFifoDepth(int i = -1)=0;
//protected:
int *stoppedFlag;
int64_t *timerValue;
detectorSettings *currentSettings;
int *currentThresholdEV;
@ -850,6 +871,8 @@ virtual int setReceiverFifoDepth(int i = -1)=0;
int (*progress_call)(double,void*);
void *pProgressCallArg;
};