diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorServer.c b/slsDetectorServers/slsDetectorServer/slsDetectorServer.c index 669009059..46ede3893 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorServer.c +++ b/slsDetectorServers/slsDetectorServer/slsDetectorServer.c @@ -47,7 +47,7 @@ int main(int argc, char *argv[]){ FILE_LOG(logINFO, ("SLS Detector Server %s (0x%x)\n", GITBRANCH, version)); } - int portno = DEFAULT_PORTNO; + int portno = DEFAULT_PORTNO; int retval = OK; int fd = 0; @@ -67,6 +67,17 @@ int main(int argc, char *argv[]){ FILE_LOG(logINFO, ("Detected developer mode\n")); debugflag = 1; } + else if(!strcasecmp(argv[i],"--port")){ + if ((i + 1) >= argc) { + FILE_LOG(logERROR, ("no port value given. Exiting.\n")); + return -1; + } + if (sscanf(argv[i + 1], "%d", &portno) == 0) { + FILE_LOG(logERROR, ("cannot decode port value %s. Exiting.\n", argv[i + 1])); + return -1; + } + FILE_LOG(logINFO, ("Detected port: %d\n", portno)); + } #ifdef GOTTHARDD else if(!strcasecmp(argv[i],"-phaseshift")){ if ((i + 1) >= argc) { @@ -88,20 +99,18 @@ int main(int argc, char *argv[]){ memset(cmd, 0, 100); #endif if (isControlServer) { - portno = DEFAULT_PORTNO; FILE_LOG(logINFO, ("Opening control server on port %d \n", portno)); #ifdef STOP_SERVER { int i; for (i = 0; i < argc; ++i) sprintf(cmd, "%s %s", cmd, argv[i]); - sprintf(cmd,"%s -stopserver&", cmd); + sprintf(cmd,"%s -stopserver --port %d &", cmd, portno + 1); FILE_LOG(logDEBUG1, ("Command to start stop server:%s\n", cmd)); system(cmd); } #endif } else { - portno = DEFAULT_PORTNO + 1; FILE_LOG(logINFO,("Opening stop server on port %d \n", portno)); } diff --git a/slsDetectorSoftware/src/multiSlsDetector.cpp b/slsDetectorSoftware/src/multiSlsDetector.cpp index cb0106d8f..2564dd221 100755 --- a/slsDetectorSoftware/src/multiSlsDetector.cpp +++ b/slsDetectorSoftware/src/multiSlsDetector.cpp @@ -404,25 +404,37 @@ void multiSlsDetector::addMultipleDetectors(const char *name) { void multiSlsDetector::addSlsDetector(const std::string &hostname) { FILE_LOG(logDEBUG1) << "Adding detector " << hostname; + + int port = DEFAULT_PORTNO; + std::string host = hostname; + auto res = sls::split(hostname, ':'); + if (res.size() > 1) { + host = res[0]; + port = std::stoi(res[1]); + } - for (auto &d : detectors) { - if (d->getHostname() == hostname) { - FILE_LOG(logWARNING) - << "Detector " << hostname - << "already part of the multiDetector!" << std::endl - << "Remove it before adding it back in a new position!"; - return; + if (host != "localhost") { + for (auto &d : detectors) { + if (d->getHostname() == host) { + FILE_LOG(logWARNING) + << "Detector " << host + << "already part of the multiDetector!" << std::endl + << "Remove it before adding it back in a new position!"; + return; + } } } // get type by connecting detectorType type = - slsDetector::getTypeFromDetector(hostname, DEFAULT_PORTNO); + slsDetector::getTypeFromDetector(host, port); int pos = (int)detectors.size(); detectors.push_back( sls::make_unique(type, multiId, pos, false)); multi_shm()->numberOfDetectors = detectors.size(); - detectors[pos]->setHostname(hostname); + detectors[pos]->setControlPort(port); + detectors[pos]->setStopPort(port + 1); + detectors[pos]->setHostname(host); multi_shm()->multiDetectorType = getDetectorTypeAsEnum(-1);// -1 needed here } diff --git a/slsDetectorSoftware/src/slsDetector.cpp b/slsDetectorSoftware/src/slsDetector.cpp index 0c6cae087..226f31fc4 100755 --- a/slsDetectorSoftware/src/slsDetector.cpp +++ b/slsDetectorSoftware/src/slsDetector.cpp @@ -23,13 +23,11 @@ using namespace sls; -#define DEFAULT_HOSTNAME "localhost" +// create shm slsDetector::slsDetector(detectorType type, int multi_id, int det_id, bool verify) : detId(det_id), shm(multi_id, det_id) { - /* called from put hostname command, - * so sls shared memory will be created */ // ensure shared memory was not created before if (shm.IsExisting()) { @@ -42,10 +40,9 @@ slsDetector::slsDetector(detectorType type, int multi_id, int det_id, initSharedMemory(type, multi_id, verify); } +// pick up from shm slsDetector::slsDetector(int multi_id, int det_id, bool verify) : detId(det_id), shm(multi_id, det_id) { - /* called from multi constructor to populate structure, - * so sls shared memory will be opened, not created */ // getDetectorType From shm will check if it was already existing detectorType type = getDetectorTypeFromShm(multi_id, verify); @@ -305,8 +302,7 @@ void slsDetector::initSharedMemory(detectorType type, int multi_id, void slsDetector::initializeDetectorStructure(detectorType type) { shm()->shmversion = SLS_SHMVERSION; - shm()->controlPort = DEFAULT_PORTNO; - sls::strcpy_safe(shm()->hostname, DEFAULT_HOSTNAME); + memset(shm()->hostname, 0, MAX_STR_LENGTH); shm()->myDetectorType = type; shm()->multiSize.x = 0; shm()->multiSize.y = 0; @@ -644,9 +640,13 @@ int slsDetector::setControlPort(int port_number) { int retval = -1; FILE_LOG(logDEBUG1) << "Setting control port to " << port_number; if (port_number >= 0 && port_number != shm()->controlPort) { - sendToDetector(F_SET_PORT, port_number, retval); - shm()->controlPort = retval; - FILE_LOG(logDEBUG1) << "Control port: " << retval; + if (strlen(shm()->hostname) > 0) { + sendToDetector(F_SET_PORT, port_number, retval); + shm()->controlPort = retval; + FILE_LOG(logDEBUG1) << "Control port: " << retval; + } else { + shm()->controlPort = port_number; + } } return shm()->controlPort; } @@ -655,9 +655,13 @@ int slsDetector::setStopPort(int port_number) { int retval = -1; FILE_LOG(logDEBUG1) << "Setting stop port to " << port_number; if (port_number >= 0 && port_number != shm()->stopPort) { - sendToDetectorStop(F_SET_PORT, port_number, retval); - shm()->stopPort = retval; - FILE_LOG(logDEBUG1) << "Stop port: " << retval; + if (strlen(shm()->hostname) > 0) { + sendToDetectorStop(F_SET_PORT, port_number, retval); + shm()->stopPort = retval; + FILE_LOG(logDEBUG1) << "Stop port: " << retval; + } else { + shm()->stopPort = port_number; + } } return shm()->stopPort; } diff --git a/slsSupportLib/include/versionAPI.h b/slsSupportLib/include/versionAPI.h index 42e28a900..6da66f7d4 100644 --- a/slsSupportLib/include/versionAPI.h +++ b/slsSupportLib/include/versionAPI.h @@ -4,7 +4,7 @@ #define APILIB 0x190723 #define APIRECEIVER 0x190722 #define APIGUI 0x190723 -#define APIEIGER 0x190816 #define APIGOTTHARD 0x190816 #define APIJUNGFRAU 0x190816 #define APIMOENCH 0x190816 +#define APIEIGER 0x190816