mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-22 22:40:02 +02:00
add getStatus() method to EigerReceiverImplementation.
implement basic configuration cache for EigerReceiverImplementation adapt eigerReceiverTest to do more checks and make output more readable improve error tests in EigerReceiverImplementation::initialize() git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@789 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
parent
540c3b1971
commit
3ec2a602c2
@ -20,16 +20,63 @@
|
|||||||
#define DEBUG(x)
|
#define DEBUG(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
struct EigerReceiverInitializationConfiguration {
|
||||||
|
|
||||||
|
string detectorHostname;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct EigerReceiverScanConfiguration {
|
||||||
|
|
||||||
|
string fileName;
|
||||||
|
string filePath;
|
||||||
|
int dynamicRange;
|
||||||
|
int scanTag;
|
||||||
|
int numberOfFrames;
|
||||||
|
bool doFileWrite;
|
||||||
|
|
||||||
|
EigerReceiverScanConfiguration():
|
||||||
|
dynamicRange(-1),
|
||||||
|
scanTag(-1),
|
||||||
|
numberOfFrames(-1),
|
||||||
|
doFileWrite(false) {};
|
||||||
|
};
|
||||||
|
|
||||||
class EigerReceiverImplementation: public EigerReceiver {
|
class EigerReceiverImplementation: public EigerReceiver {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void initialize(const char *detectorHostName) {
|
|
||||||
DEBUG("initialize() with: detectorHostName= " << detectorHostName << ".");
|
EigerReceiverImplementation() : isInitialized(false), status(slsDetectorDefs::ERROR) {};
|
||||||
|
|
||||||
|
void initialize(const char *detectorHostname) {
|
||||||
|
|
||||||
|
string name;
|
||||||
|
if (detectorHostname != NULL) {
|
||||||
|
name = detectorHostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name.empty()) {
|
||||||
|
DEBUG("initialize(): can't initialize with empty string or NULL for detectorHostname");
|
||||||
|
} else if (isInitialized == true) {
|
||||||
|
DEBUG("initialize(): already initialized, can't initialize several times");
|
||||||
|
} else {
|
||||||
|
DEBUG("initialize(): initialize() with: detectorHostName=" << name << ".");
|
||||||
|
init_config.detectorHostname = name;
|
||||||
|
isInitialized = true;
|
||||||
|
status = slsDetectorDefs::IDLE;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *getDetectorHostname() const {
|
char *getDetectorHostname() const {
|
||||||
const std::string name = "some_host_name";
|
string name = init_config.detectorHostname;
|
||||||
char *c = new char[name.length()];
|
if (name.empty()) {
|
||||||
|
DEBUG("getDetectorHostname(): Return NULL");
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
char *c = new char[name.length()+1];
|
||||||
name.copy(c, name.length());
|
name.copy(c, name.length());
|
||||||
c[name.length()] = '\0';
|
c[name.length()] = '\0';
|
||||||
DEBUG("getDetectorHostname(): Return " << c << ".");
|
DEBUG("getDetectorHostname(): Return " << c << ".");
|
||||||
@ -37,8 +84,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *getFileName() const {
|
char *getFileName() const {
|
||||||
const std::string name = "some_file_name";
|
string name = scan_config.fileName;
|
||||||
char *c = new char[name.length()];
|
|
||||||
|
char *c = new char[name.length()+1];
|
||||||
name.copy(c, name.length());
|
name.copy(c, name.length());
|
||||||
c[name.length()] = '\0';
|
c[name.length()] = '\0';
|
||||||
DEBUG("getFileName(): Return " << c);
|
DEBUG("getFileName(): Return " << c);
|
||||||
@ -46,8 +94,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *getFilePath() const {
|
char *getFilePath() const {
|
||||||
std::string name = "some_path";
|
string name = scan_config.filePath;
|
||||||
char *c = new char[name.length()];
|
|
||||||
|
char *c = new char[name.length()+1];
|
||||||
name.copy(c, name.length());
|
name.copy(c, name.length());
|
||||||
c[name.length()] = '\0';
|
c[name.length()] = '\0';
|
||||||
DEBUG("getFilePath(): Return " << c);
|
DEBUG("getFilePath(): Return " << c);
|
||||||
@ -55,69 +104,89 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int getDynamicRange() const {
|
int getDynamicRange() const {
|
||||||
DEBUG("getDynamicRange(): Return 16.");
|
DEBUG("getDynamicRange(): Return " << scan_config.dynamicRange);
|
||||||
return(16);
|
return(scan_config.dynamicRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getScanTag() const {
|
int getScanTag() const {
|
||||||
DEBUG("getScanTag(): return 4711.");
|
DEBUG("getScanTag(): returns " << scan_config.scanTag);
|
||||||
return(4711);
|
return(scan_config.scanTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getNumberOfFrames() const {
|
int getNumberOfFrames() const {
|
||||||
DEBUG("getNumberOfFrames(): return 42.");
|
DEBUG("getNumberOfFrames(): return " << scan_config.numberOfFrames);
|
||||||
return(42);
|
return(scan_config.numberOfFrames);
|
||||||
|
}
|
||||||
|
|
||||||
|
int getEnableFileWrite() const {
|
||||||
|
DEBUG("getEnableFileWrite() returns " << scan_config.doFileWrite);
|
||||||
|
return(scan_config.doFileWrite);
|
||||||
|
}
|
||||||
|
|
||||||
|
slsDetectorDefs::runStatus getStatus() const {
|
||||||
|
DEBUG("getStatus(): return " <<status);
|
||||||
|
return(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *setFileName(const char c[]) {
|
char *setFileName(const char c[]) {
|
||||||
DEBUG("setFileName() called with " << c <<".");
|
DEBUG("setFileName() called with " << c <<".");
|
||||||
|
scan_config.fileName = c;
|
||||||
return(this->getFileName());
|
return(this->getFileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
char *setFilePath(const char c[]) {
|
char *setFilePath(const char c[]) {
|
||||||
DEBUG("setFilePath() called with " << c << ".");
|
DEBUG("setFilePath() called with " << c << ".");
|
||||||
|
scan_config.filePath = c;
|
||||||
return(this->getFilePath());
|
return(this->getFilePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
int getEnableFileWrite() const {
|
|
||||||
DEBUG("getEnableFileWrite() returns 1.");
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
int setDynamicRange (const int dr) {
|
int setDynamicRange (const int dr) {
|
||||||
DEBUG("setDynamicRange() called with " << dr << '.');
|
DEBUG("setDynamicRange() called with " << dr << '.');
|
||||||
return(this->getDynamicRange());
|
scan_config.dynamicRange = dr;
|
||||||
|
return(getDynamicRange());
|
||||||
}
|
}
|
||||||
|
|
||||||
int setScanTag (const int tag) {
|
int setScanTag (const int tag) {
|
||||||
DEBUG("setScanTag() called with " << tag);
|
DEBUG("setScanTag() called with " << tag);
|
||||||
return(this->getScanTag());
|
scan_config.scanTag = tag;
|
||||||
|
return(getScanTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
int setNumberOfFrames (const int fnum) {
|
int setNumberOfFrames (const int fnum) {
|
||||||
DEBUG("setNumberOfFrames() called with " << fnum);
|
DEBUG("setNumberOfFrames() called with " << fnum);
|
||||||
return(this->getNumberOfFrames());
|
scan_config.numberOfFrames = fnum;
|
||||||
|
return(getNumberOfFrames());
|
||||||
}
|
}
|
||||||
|
|
||||||
int setEnableFileWrite(const int i) {
|
int setEnableFileWrite(const int i) {
|
||||||
DEBUG("enableFileWrite() called with " << i);
|
DEBUG("enableFileWrite() called with " << i);
|
||||||
return(0);
|
scan_config.doFileWrite = i;
|
||||||
|
return(getEnableFileWrite());
|
||||||
}
|
}
|
||||||
|
|
||||||
int startReceiver(char message[]) {
|
int startReceiver(char message[]) {
|
||||||
DEBUG("startReceiver(): return 0.");
|
DEBUG("startReceiver(): return 0.");
|
||||||
|
status = slsDetectorDefs::RUNNING;
|
||||||
message = NULL;
|
message = NULL;
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int stopReceiver() {
|
int stopReceiver() {
|
||||||
DEBUG("stopReceiver(): return 0.");
|
DEBUG("stopReceiver(): return 0.");
|
||||||
|
status = slsDetectorDefs::IDLE;
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void abort() {
|
void abort() {
|
||||||
DEBUG("abort(): return 0.");
|
DEBUG("abort(): return 0.");
|
||||||
|
status = slsDetectorDefs::IDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
EigerReceiverScanConfiguration scan_config;
|
||||||
|
EigerReceiverInitializationConfiguration init_config;
|
||||||
|
bool isInitialized;
|
||||||
|
slsDetectorDefs::runStatus status;
|
||||||
};
|
};
|
||||||
|
|
||||||
EigerReceiver *EigerReceiver::create(void) {
|
EigerReceiver *EigerReceiver::create(void) {
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
//#ifndef EIGER_RECEIVER
|
||||||
//#define EIGER_RECEIVER
|
//#define EIGER_RECEIVER
|
||||||
|
//#endif
|
||||||
#ifdef EIGER_RECEIVER
|
#ifdef EIGER_RECEIVER
|
||||||
|
|
||||||
#ifndef EIGERRECEIVER_H
|
#ifndef EIGERRECEIVER_H
|
||||||
@ -12,6 +14,8 @@
|
|||||||
* @short does all the functions for a receiver, set/get parameters, start/stop etc.
|
* @short does all the functions for a receiver, set/get parameters, start/stop etc.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "sls_detector_defs.h"
|
||||||
|
|
||||||
class EigerReceiver {
|
class EigerReceiver {
|
||||||
/* abstract class that defines the public interface of an eiger data receiver.
|
/* abstract class that defines the public interface of an eiger data receiver.
|
||||||
*
|
*
|
||||||
@ -76,9 +80,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Returns status of receiver: idle, running or error
|
* Returns status of receiver: idle, running or error
|
||||||
*/
|
*/
|
||||||
/*FIXME: need to implement runStatus getStatus();*/
|
virtual slsDetectorDefs::runStatus getStatus() const = 0;
|
||||||
/* the struct slsDetectorDefs is available in slsDetectorsPackage/slsDetectorSoftware/commonFiles/slsDetectorDefs.h */
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns File Name
|
* Returns File Name
|
||||||
|
@ -10,50 +10,86 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "eigerReceiver.h"
|
#include "eigerReceiver.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
int main(int argc, char *argv[]){
|
int main(int argc, char *argv[]){
|
||||||
|
|
||||||
const char *name = "detectors_host_name";
|
const char *name = "detectors_host_name";
|
||||||
|
const char *empty = "";
|
||||||
std::string prefix = "main: ";
|
std::string prefix = "main: ";
|
||||||
std::cout <<prefix<< "start EigerReceiver tests\n";
|
cout <<prefix<< "start EigerReceiver tests" << endl;
|
||||||
|
|
||||||
|
|
||||||
EigerReceiver *receiver = EigerReceiver::create();
|
EigerReceiver *receiver = EigerReceiver::create();
|
||||||
receiver->initialize(name);
|
|
||||||
|
|
||||||
|
int status = receiver->getStatus();
|
||||||
|
char *c0 = receiver->getDetectorHostname();
|
||||||
|
if (c0 == NULL) {
|
||||||
|
cout <<prefix<< "getDetectorHostname() returned NULL, as expected before initialization." << endl;
|
||||||
|
}
|
||||||
|
delete[] c0;
|
||||||
|
|
||||||
|
cout <<prefix<< "initialize 4 times - only the second should work" << endl;
|
||||||
|
receiver->initialize(empty);
|
||||||
|
status = receiver->getStatus();
|
||||||
|
receiver->initialize(name);
|
||||||
|
status = receiver->getStatus();
|
||||||
|
receiver->initialize(name);
|
||||||
|
status = receiver->getStatus();
|
||||||
|
receiver->initialize((char *)NULL);
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
status = receiver->getStatus();
|
||||||
|
char *c6 = receiver->getDetectorHostname();
|
||||||
|
cout <<prefix<< "got detector hostname " << c6 << " after initialization;" <<endl<<endl;
|
||||||
|
delete[] c6;
|
||||||
|
|
||||||
|
cout <<prefix<< "try get*() methods before set*() - expect default values" <<endl;
|
||||||
char *c1 = receiver->getFileName();
|
char *c1 = receiver->getFileName();
|
||||||
std::cout <<prefix<< "got file name " << c1 << '\n';
|
cout <<prefix<< "got file name <" << c1 <<">." << endl;
|
||||||
delete[] c1;
|
delete[] c1;
|
||||||
|
|
||||||
char *c2 = receiver->getFilePath();
|
char *c2 = receiver->getFilePath();
|
||||||
std::cout <<prefix<< "got path name " << c2 << '\n';
|
cout <<prefix<< "got path name <" << c2 <<">." << endl;
|
||||||
delete[]c2;
|
delete[]c2;
|
||||||
|
|
||||||
int range = receiver->getDynamicRange();
|
int range = receiver->getDynamicRange();
|
||||||
std::cout <<prefix<< "got dynamic range " << range << ".\n";
|
cout <<prefix<< "got dynamic range " << range << endl;
|
||||||
|
|
||||||
int tag = receiver->getScanTag();
|
int tag = receiver->getScanTag();
|
||||||
std::cout <<prefix<< "got scan tag " << tag << ".\n";
|
cout <<prefix<< "got scan tag " << tag << endl;
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
char *c3 = receiver->setFileName( "some_other_name");
|
char *c3 = receiver->setFileName( "some_other_name");
|
||||||
std::cout <<prefix<< "got file name " << c3 << " after setting to <some_other_name>\n";
|
cout <<prefix<< "got file name <" << c3 << "> after setting to <some_other_name>" << endl << endl;
|
||||||
delete[] c3;
|
delete[] c3;
|
||||||
|
|
||||||
char *c4 = receiver->setFilePath( "some_other_path");
|
char *c4 = receiver->setFilePath( "some_other_path");
|
||||||
std::cout <<prefix<< "got file path " << c4 << " after setting to <some_other_path>\n";
|
cout <<prefix<< "got file path <" << c4 << "> after setting to <some_other_path>" << endl << endl;
|
||||||
delete[] c4;
|
delete[] c4;
|
||||||
|
|
||||||
range = receiver->setDynamicRange(8);
|
range = receiver->setDynamicRange(8);
|
||||||
std::cout <<prefix<< "got dynamic range " << range << " after setting it to 8.\n";
|
cout <<prefix<< "got dynamic range " << range << " after setting it to 8." << endl << endl;
|
||||||
|
|
||||||
|
tag = receiver->setScanTag(99);
|
||||||
|
cout << "got scan tag " << tag << " after setting to 99." << endl << endl;
|
||||||
|
|
||||||
int n = receiver->setNumberOfFrames(11);
|
int n = receiver->setNumberOfFrames(11);
|
||||||
|
cout << "got number of frames " << n << " after setting to 11." << endl << endl;
|
||||||
|
|
||||||
int w = receiver->setEnableFileWrite(1);
|
int w = receiver->setEnableFileWrite(1);
|
||||||
|
cout << "got enable file write " << w << " after setting to 1." << endl << endl;
|
||||||
|
|
||||||
char *c5;
|
char *c5;
|
||||||
|
status = receiver->getStatus();
|
||||||
receiver->startReceiver(c5);
|
receiver->startReceiver(c5);
|
||||||
|
status = receiver->getStatus();
|
||||||
receiver->stopReceiver();
|
receiver->stopReceiver();
|
||||||
|
status = receiver->getStatus();
|
||||||
receiver->abort();
|
receiver->abort();
|
||||||
receiver->getEnableFileWrite();
|
status = receiver->getStatus();
|
||||||
char *c6 = receiver->getDetectorHostname();
|
|
||||||
delete[] c6;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user