diff --git a/slsDetectorSoftware/slsReceiver/eigerReceiver.cpp b/slsDetectorSoftware/slsReceiver/eigerReceiver.cpp index 81836d6b1..497ab59f4 100644 --- a/slsDetectorSoftware/slsReceiver/eigerReceiver.cpp +++ b/slsDetectorSoftware/slsReceiver/eigerReceiver.cpp @@ -20,16 +20,63 @@ #define DEBUG(x) #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 { 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 { - const std::string name = "some_host_name"; - char *c = new char[name.length()]; + string name = init_config.detectorHostname; + if (name.empty()) { + DEBUG("getDetectorHostname(): Return NULL"); + return(NULL); + } + char *c = new char[name.length()+1]; name.copy(c, name.length()); c[name.length()] = '\0'; DEBUG("getDetectorHostname(): Return " << c << "."); @@ -37,8 +84,9 @@ public: } char *getFileName() const { - const std::string name = "some_file_name"; - char *c = new char[name.length()]; + string name = scan_config.fileName; + + char *c = new char[name.length()+1]; name.copy(c, name.length()); c[name.length()] = '\0'; DEBUG("getFileName(): Return " << c); @@ -46,8 +94,9 @@ public: } char *getFilePath() const { - std::string name = "some_path"; - char *c = new char[name.length()]; + string name = scan_config.filePath; + + char *c = new char[name.length()+1]; name.copy(c, name.length()); c[name.length()] = '\0'; DEBUG("getFilePath(): Return " << c); @@ -55,69 +104,89 @@ public: } int getDynamicRange() const { - DEBUG("getDynamicRange(): Return 16."); - return(16); + DEBUG("getDynamicRange(): Return " << scan_config.dynamicRange); + return(scan_config.dynamicRange); } int getScanTag() const { - DEBUG("getScanTag(): return 4711."); - return(4711); + DEBUG("getScanTag(): returns " << scan_config.scanTag); + return(scan_config.scanTag); } int getNumberOfFrames() const { - DEBUG("getNumberOfFrames(): return 42."); - return(42); - } - - char * setFileName(const char c[]) { - DEBUG("setFileName() called with " << c <<"."); - return(this->getFileName()); - } - - char * setFilePath(const char c[]) { - DEBUG("setFilePath() called with" << c << "."); - return(this->getFilePath()); + DEBUG("getNumberOfFrames(): return " << scan_config.numberOfFrames); + return(scan_config.numberOfFrames); } int getEnableFileWrite() const { - DEBUG("getEnableFileWrite() returns 1."); - return(1); + DEBUG("getEnableFileWrite() returns " << scan_config.doFileWrite); + return(scan_config.doFileWrite); } + + slsDetectorDefs::runStatus getStatus() const { + DEBUG("getStatus(): return " <getFileName()); + } + + char *setFilePath(const char c[]) { + DEBUG("setFilePath() called with " << c << "."); + scan_config.filePath = c; + return(this->getFilePath()); + } + int setDynamicRange (const int dr) { DEBUG("setDynamicRange() called with " << dr << '.'); - return(this->getDynamicRange()); + scan_config.dynamicRange = dr; + return(getDynamicRange()); } int setScanTag (const int tag) { DEBUG("setScanTag() called with " << tag); - return(this->getScanTag()); + scan_config.scanTag = tag; + return(getScanTag()); } int setNumberOfFrames (const int fnum) { DEBUG("setNumberOfFrames() called with " << fnum); - return(this->getNumberOfFrames()); + scan_config.numberOfFrames = fnum; + return(getNumberOfFrames()); } int setEnableFileWrite(const int i) { DEBUG("enableFileWrite() called with " << i); - return(0); + scan_config.doFileWrite = i; + return(getEnableFileWrite()); } int startReceiver(char message[]) { DEBUG("startReceiver(): return 0."); + status = slsDetectorDefs::RUNNING; message = NULL; return(0); } int stopReceiver() { DEBUG("stopReceiver(): return 0."); + status = slsDetectorDefs::IDLE; return(0); } void abort() { DEBUG("abort(): return 0."); + status = slsDetectorDefs::IDLE; } +private: + EigerReceiverScanConfiguration scan_config; + EigerReceiverInitializationConfiguration init_config; + bool isInitialized; + slsDetectorDefs::runStatus status; }; EigerReceiver *EigerReceiver::create(void) { diff --git a/slsDetectorSoftware/slsReceiver/eigerReceiver.h b/slsDetectorSoftware/slsReceiver/eigerReceiver.h index 32d1ff241..7ffa830b4 100644 --- a/slsDetectorSoftware/slsReceiver/eigerReceiver.h +++ b/slsDetectorSoftware/slsReceiver/eigerReceiver.h @@ -1,4 +1,6 @@ +//#ifndef EIGER_RECEIVER //#define EIGER_RECEIVER +//#endif #ifdef EIGER_RECEIVER #ifndef EIGERRECEIVER_H @@ -12,6 +14,8 @@ * @short does all the functions for a receiver, set/get parameters, start/stop etc. */ +#include "sls_detector_defs.h" + class EigerReceiver { /* 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 */ - /*FIXME: need to implement runStatus getStatus();*/ - /* the struct slsDetectorDefs is available in slsDetectorsPackage/slsDetectorSoftware/commonFiles/slsDetectorDefs.h */ - + virtual slsDetectorDefs::runStatus getStatus() const = 0; /** * Returns File Name diff --git a/slsDetectorSoftware/slsReceiver/eigerReceiverTest.cpp b/slsDetectorSoftware/slsReceiver/eigerReceiverTest.cpp index 474c5312a..bdfcba7a1 100644 --- a/slsDetectorSoftware/slsReceiver/eigerReceiverTest.cpp +++ b/slsDetectorSoftware/slsReceiver/eigerReceiverTest.cpp @@ -10,50 +10,86 @@ #include #include "eigerReceiver.h" +using namespace std; + int main(int argc, char *argv[]){ const char *name = "detectors_host_name"; + const char *empty = ""; std::string prefix = "main: "; - std::cout <initialize(name); + int status = receiver->getStatus(); + char *c0 = receiver->getDetectorHostname(); + if (c0 == NULL) { + cout <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 <getFileName(); - std::cout <." << endl; delete[] c1; char *c2 = receiver->getFilePath(); - std::cout <." << endl; delete[]c2; int range = receiver->getDynamicRange(); - std::cout <getScanTag(); - std::cout <setFileName( "some_other_name"); - std::cout <\n"; + cout < after setting to " << endl << endl; delete[] c3; char *c4 = receiver->setFilePath( "some_other_path"); - std::cout <\n"; + cout < after setting to " << endl << endl; delete[] c4; range = receiver->setDynamicRange(8); - std::cout <setScanTag(99); + cout << "got scan tag " << tag << " after setting to 99." << endl << endl; int n = receiver->setNumberOfFrames(11); + cout << "got number of frames " << n << " after setting to 11." << endl << endl; + int w = receiver->setEnableFileWrite(1); + cout << "got enable file write " << w << " after setting to 1." << endl << endl; char *c5; + status = receiver->getStatus(); receiver->startReceiver(c5); + status = receiver->getStatus(); receiver->stopReceiver(); + status = receiver->getStatus(); receiver->abort(); - receiver->getEnableFileWrite(); - char *c6 = receiver->getDetectorHostname(); - delete[] c6; + status = receiver->getStatus(); + }