added load image, changed key find, changed get temp to getADC

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@123 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
l_maliakal_d 2012-02-20 10:05:57 +00:00
parent 44eea027f3
commit c6f61d3663
5 changed files with 378 additions and 151 deletions

View File

@ -1764,7 +1764,6 @@ int slsDetector::readRegister(int addr){
PREAMP, PREAMP,
TEMPERATURE, TEMPERATURE,
HUMIDITY, HUMIDITY,
DETECTOR_BIAS
}{}; }{};
*/ */
@ -4544,7 +4543,52 @@ int slsDetector:: writeAngularConversion(ofstream &ofs) {
} }
int slsDetector::loadImageToDetector(int index,string const fname){
int retval;
int fnum=F_LOAD_IMAGE;
int ret=FAIL;
char mess[100];
short int arg[1280];
#ifdef VERBOSE
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;
}
controlSocket->Disconnect();
if (ret==FORCE_UPDATE)
updateDetector();
}
}
}
if (ret==FAIL) {
std::cout<< "failed " << std::endl;
return -1;
}
return 0;
}

View File

@ -109,6 +109,14 @@ slsDetectorCommand::slsDetectorCommand() {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdThreaded; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdThreaded;
i++; i++;
descrToFuncMap[i].m_pFuncName="darkimage"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdImage;
i++;
descrToFuncMap[i].m_pFuncName="gainimage"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdImage;
i++;
/* trim/cal directories */ /* trim/cal directories */
descrToFuncMap[i].m_pFuncName="trimdir"; //OK descrToFuncMap[i].m_pFuncName="trimdir"; //OK
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettingsDir; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdSettingsDir;
@ -438,12 +446,14 @@ slsDetectorCommand::slsDetectorCommand() {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC;
i++; i++;
/* r/w timers */
descrToFuncMap[i].m_pFuncName="temp_adc"; // descrToFuncMap[i].m_pFuncName="temp_adc"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdADC;
i++; i++;
descrToFuncMap[i].m_pFuncName="temp_fpga"; // descrToFuncMap[i].m_pFuncName="temp_fpga"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDAC; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdADC;
i++; i++;
/* r/w timers */ /* r/w timers */
@ -769,8 +779,10 @@ string slsDetectorCommand::executeLine(int narg, char *args[], int action) {
/* otherwise one could try if truncated key is unique */ /* otherwise one could try if truncated key is unique */
size_t p=(descrToFuncMap[i].m_pFuncName).find(key); // size_t p=(descrToFuncMap[i].m_pFuncName).find();
if (p==0) { // if (p==0) {
if(key==descrToFuncMap[i].m_pFuncName){
#ifdef VERBOSE #ifdef VERBOSE
std::cout<<i << " command="<< descrToFuncMap[i].m_pFuncName<<" key="<<key <<std::endl; std::cout<<i << " command="<< descrToFuncMap[i].m_pFuncName<<" key="<<key <<std::endl;
#endif #endif
@ -1731,6 +1743,42 @@ string slsDetectorCommand::helpThreaded(int narg, char *args[], int action){
string slsDetectorCommand::cmdImage(int narg, char *args[], int action){
string sval;
int retval;
if (action==HELP_ACTION)
return helpImage(narg,args,HELP_ACTION);
else if (action==GET_ACTION)
return string("Cannot get");
sval=string(args[1]);
setOnline(ONLINE_FLAG);
if (string(args[0])==string("darkimage"))
retval=loadImageToDetector(DARK_IMAGE,sval);
else if (string(args[0])==string("gainimage"))
retval=loadImageToDetector(GAIN_IMAGE,sval);
if(!retval)
return string("Image loaded succesfully");
else
return string("Image NOT loaded");
}
string slsDetectorCommand::helpImage(int narg, char *args[], int action){
if (action==PUT_ACTION || action==HELP_ACTION){
if (string(args[0])==string("darkimage"))
return string("darkimage f \t loads the image to detector from file f\n");
else
return string("gainimage f \t loads the image to detector from file f\n");
}
else
return string("Cannot get");
}
string slsDetectorCommand::cmdPositions(int narg, char *args[], int action){ string slsDetectorCommand::cmdPositions(int narg, char *args[], int action){
int ival; int ival;
@ -2553,7 +2601,7 @@ string slsDetectorCommand::helpRegister(int narg, char *args[], int action) {
string slsDetectorCommand::cmdDAC(int narg, char *args[], int action) { string slsDetectorCommand::cmdDAC(int narg, char *args[], int action) {
if (action==HELP_ACTION) if (action==HELP_ACTION)
return helpRegister(narg, args, action); return helpDAC(narg, args, action);
dacIndex dac; dacIndex dac;
float val=-1; float val=-1;
@ -2622,6 +2670,7 @@ string slsDetectorCommand::cmdDAC(int narg, char *args[], int action) {
} }
string slsDetectorCommand::helpDAC(int narg, char *args[], int action) { string slsDetectorCommand::helpDAC(int narg, char *args[], int action) {
ostringstream os; ostringstream os;
@ -2663,7 +2712,6 @@ string slsDetectorCommand::helpDAC(int narg, char *args[], int action) {
} }
if (action==GET_ACTION || action==HELP_ACTION) { if (action==GET_ACTION || action==HELP_ACTION) {
os << "vthreshold \t Gets the detector threshold in dac units (0-1024). The energy is approx 800-15*keV" << std::endl; os << "vthreshold \t Gets the detector threshold in dac units (0-1024). The energy is approx 800-15*keV" << std::endl;
os << std::endl; os << std::endl;
@ -2697,14 +2745,49 @@ string slsDetectorCommand::helpDAC(int narg, char *args[], int action) {
os << "vcasc_out " << "\t gets vcasc_out" << std::endl; os << "vcasc_out " << "\t gets vcasc_out" << std::endl;
os << "vref_comp " << "\t gets vref_comp" << std::endl; os << "vref_comp " << "\t gets vref_comp" << std::endl;
os << "ib_test_c " << "\t gets ib_test_c" << std::endl; os << "ib_test_c " << "\t gets ib_test_c" << std::endl;
os << "temp_adc " << "\t gets the temperature of the adc" << std::endl;
os << "temp_fpga " << "\t gets the temperature of the fpga" << std::endl;
} }
return os.str(); return os.str();
}
string slsDetectorCommand::cmdADC(int narg, char *args[], int action) {
dacIndex adc;
float val=-1;
char answer[1000];
if (action==HELP_ACTION)
return helpADC(narg, args, action);
else if (action==PUT_ACTION)
return string("cannot set ")+cmd;
if (cmd=="temp_adc")
adc=TEMPERATURE_ADC;
else if (cmd=="temp_fpga")
adc=TEMPERATURE_FPGA;
else
return string("cannot decode adc ")+cmd;
setOnline(ONLINE_FLAG);
sprintf(answer,"%f",getADC(adc));
return string(answer);
}
string slsDetectorCommand::helpADC(int narg, char *args[], int action) {
ostringstream os;
if (action==PUT_ACTION || action==HELP_ACTION) {
os << "temp_adc " << "Cannot be set" << std::endl;
os << "temp_fpga " << "Cannot be set" << std::endl;
}
if (action==GET_ACTION || action==HELP_ACTION) {
os << "temp_adc " << "\t gets the temperature of the adc" << std::endl;
os << "temp_fpga " << "\t gets the temperature of the fpga" << std::endl;
}
return os.str();
} }

View File

@ -124,6 +124,9 @@ class slsDetectorCommand;
string cmdThreaded(int narg, char *args[], int action); string cmdThreaded(int narg, char *args[], int action);
static string helpThreaded(int narg, char *args[], int action); static string helpThreaded(int narg, char *args[], int action);
string cmdImage(int narg, char *args[], int action);
static string helpImage(int narg, char *args[], int action);
string cmdPositions(int narg, char *args[], int action); string cmdPositions(int narg, char *args[], int action);
static string helpPositions(int narg, char *args[], int action); static string helpPositions(int narg, char *args[], int action);
@ -179,6 +182,8 @@ class slsDetectorCommand;
string cmdDAC(int narg, char *args[], int action); string cmdDAC(int narg, char *args[], int action);
static string helpDAC(int narg, char *args[], int action); static string helpDAC(int narg, char *args[], int action);
string cmdADC(int narg, char *args[], int action);
static string helpADC(int narg, char *args[], int action);
string cmdTimer(int narg, char *args[], int action); string cmdTimer(int narg, char *args[], int action);
static string helpTimer(int narg, char *args[], int action); static string helpTimer(int narg, char *args[], int action);
@ -324,6 +329,8 @@ class slsDetectorCommand;
virtual int writeConfigurationFile(string const fname)=0; virtual int writeConfigurationFile(string const fname)=0;
virtual int dumpDetectorSetup(string const fname, int level=0)=0; virtual int dumpDetectorSetup(string const fname, int level=0)=0;
virtual int retrieveDetectorSetup(string const fname, int level=0)=0; virtual int retrieveDetectorSetup(string const fname, int level=0)=0;
virtual int loadImageToDetector(int index,string const fname)=0;

View File

@ -929,6 +929,63 @@ int slsDetectorUtils::readDataFile(ifstream &infile, int *data, int nch){
}; };
int slsDetectorUtils::readDataFile(string fname, short int *data, int nch){
ifstream infile;
int ichan, iline=0;
int interrupt=0;
string str;
#ifdef VERBOSE
std::cout<< "Opening file "<< fname << std::endl;
#endif
infile.open(fname.c_str(), ios_base::in);
if (infile.is_open()) {
readDataFile(infile, data, nch);
infile.close();
} else {
std::cout<< "Could not read file " << fname << std::endl;
return -1;
}
return iline;
};
int slsDetectorUtils::readDataFile(ifstream &infile, short int *data, int nch){
int ichan, iline=0;
short int idata;
int interrupt=0;
string str;
while (infile.good() and interrupt==0) {
getline(infile,str);
#ifdef VERBOSE
std::cout<< str << std::endl;
#endif
istringstream ssstr(str);
ssstr >> ichan >> idata;
if (ssstr.fail() || ssstr.bad()) {
interrupt=1;
break;
}
if (ichan!=iline) {
std::cout<< " Expected channel "<< iline <<" but read channel "<< ichan << std::endl;
interrupt=1;
break;
} else {
if (iline<nch) {
data[iline]=idata;
iline++;
} else {
interrupt=1;
break;
}
}
}
return iline;
};
/*writes raw data file */ /*writes raw data file */
@ -990,6 +1047,19 @@ int slsDetectorUtils::readDataFile(ifstream &infile, int *data){
int slsDetectorUtils::readDataFile(string fname, short int *data){
return readDataFile(fname, data, getTotalNumberOfChannels());
};
int slsDetectorUtils::readDataFile(ifstream &infile, short int *data){
return readDataFile(infile, data, getTotalNumberOfChannels());
};
int slsDetectorUtils::readCalibrationFile(string fname, float &gain, float &offset){ int slsDetectorUtils::readCalibrationFile(string fname, float &gain, float &offset){
string str; string str;

View File

@ -204,6 +204,17 @@ class slsDetectorUtils : public slsDetectorCommand {
int readDataFile(string fname, int *data); int readDataFile(string fname, int *data);
int readDataFile(ifstream &infile, int *data); int readDataFile(ifstream &infile, int *data);
/**
reads a data file
\param name of the file to be read
\param data array of data values
\returns OK or FAIL if it could not read the file or data=NULL
\sa mythenDetector::readDataFile
*/
int readDataFile(string fname, short int *data);
int readDataFile(ifstream &infile, short int *data);
/** /**
writes a data file writes a data file
@ -259,6 +270,18 @@ class slsDetectorUtils : public slsDetectorCommand {
*/ */
static int readDataFile(string fname, int *data, int nch); static int readDataFile(string fname, int *data, int nch);
static int readDataFile(ifstream &infile, int *data, int nch); static int readDataFile(ifstream &infile, int *data, int nch);
/**
reads a data file
\param name of the file to be read
\param data array of data values
\returns OK or FAIL if it could not read the file or data=NULL
\sa mythenDetector::readDataFile
*/
static int readDataFile(string fname, short int *data, int nch);
static int readDataFile(ifstream &infile, short int *data, int nch);
/** /**
reads an angular conversion file reads an angular conversion file