jungfrau: switching between 2 and 1 interface, implementation for server required when firmware done

This commit is contained in:
2019-03-26 15:00:19 +01:00
parent cd5aea895b
commit 7cd5bc8b2d
26 changed files with 1316 additions and 301 deletions

View File

@@ -1438,6 +1438,28 @@ std::string multiSlsDetector::getDetectorMAC(int detPos) {
return sls::concatenateIfDifferent(r);
}
std::string multiSlsDetector::setDetectorMAC2(const std::string &detectorMAC, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->setDetectorMAC2(detectorMAC);
}
// multi
auto r = parallelCall(&slsDetector::setDetectorMAC2, detectorMAC);
return sls::concatenateIfDifferent(r);
}
std::string multiSlsDetector::getDetectorMAC2(int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->getDetectorMAC2();
}
// multi
auto r = serialCall(&slsDetector::getDetectorMAC2);
return sls::concatenateIfDifferent(r);
}
std::string multiSlsDetector::setDetectorIP(const std::string &detectorIP, int detPos) {
// single
if (detPos >= 0) {
@@ -1460,6 +1482,29 @@ std::string multiSlsDetector::getDetectorIP(int detPos) const {
return sls::concatenateIfDifferent(r);
}
std::string multiSlsDetector::setDetectorIP2(const std::string &detectorIP, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->setDetectorIP2(detectorIP);
}
// multi
auto r = parallelCall(&slsDetector::setDetectorIP2, detectorIP);
return sls::concatenateIfDifferent(r);
}
std::string multiSlsDetector::getDetectorIP2(int detPos) const {
// single
if (detPos >= 0) {
return detectors[detPos]->getDetectorIP2();
}
// multi
auto r = serialCall(&slsDetector::getDetectorIP2);
return sls::concatenateIfDifferent(r);
}
std::string multiSlsDetector::setReceiverHostname(const std::string &receiver, int detPos) {
// single
if (detPos >= 0) {
@@ -1504,6 +1549,28 @@ std::string multiSlsDetector::getReceiverUDPIP(int detPos) const {
return sls::concatenateIfDifferent(r);
}
std::string multiSlsDetector::setReceiverUDPIP2(const std::string &udpip, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->setReceiverUDPIP2(udpip);
}
// multi
auto r = parallelCall(&slsDetector::setReceiverUDPIP2, udpip);
return sls::concatenateIfDifferent(r);
}
std::string multiSlsDetector::getReceiverUDPIP2(int detPos) const {
// single
if (detPos >= 0) {
return detectors[detPos]->getReceiverUDPIP2();
}
// multi
auto r = serialCall(&slsDetector::getReceiverUDPIP2);
return sls::concatenateIfDifferent(r);
}
std::string multiSlsDetector::setReceiverUDPMAC(const std::string &udpmac, int detPos) {
// single
if (detPos >= 0) {
@@ -1526,6 +1593,28 @@ std::string multiSlsDetector::getReceiverUDPMAC(int detPos) const {
return sls::concatenateIfDifferent(r);
}
std::string multiSlsDetector::setReceiverUDPMAC2(const std::string &udpmac, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->setReceiverUDPMAC2(udpmac);
}
// multi
auto r = parallelCall(&slsDetector::setReceiverUDPMAC2, udpmac);
return sls::concatenateIfDifferent(r);
}
std::string multiSlsDetector::getReceiverUDPMAC2(int detPos) const {
// single
if (detPos >= 0) {
return detectors[detPos]->getReceiverUDPMAC2();
}
// multi
auto r = serialCall(&slsDetector::getReceiverUDPMAC2);
return sls::concatenateIfDifferent(r);
}
int multiSlsDetector::setReceiverUDPPort(int udpport, int detPos) {
// single
if (detPos >= 0) {
@@ -1570,6 +1659,71 @@ int multiSlsDetector::getReceiverUDPPort2(int detPos) const {
return sls::minusOneIfDifferent(r);
}
int multiSlsDetector::setNumberofUDPInterfaces(int n, int detPos) {
int previouslyClientStreaming = enableDataStreamingToClient();
int previouslyReceiverStreaming = enableDataStreamingFromReceiver();
// single
int ret = OK;
if (detPos >= 0) {
ret = detectors[detPos]->setNumberofUDPInterfaces(n);
}
// multi
auto r = parallelCall(&slsDetector::setNumberofUDPInterfaces,n);
// redo the zmq sockets
if (previouslyClientStreaming) {
enableDataStreamingToClient(0);
enableDataStreamingToClient(1);
}
if (previouslyReceiverStreaming) {
enableDataStreamingFromReceiver(0);
enableDataStreamingFromReceiver(1);
}
// return single
if (detPos >= 0)
return ret;
// return multi
return sls::minusOneIfDifferent(r);
}
int multiSlsDetector::getNumberofUDPInterfaces(int detPos) const {
// single
if (detPos >= 0) {
return detectors[detPos]->getNumberofUDPInterfaces();
}
// multi
auto r = serialCall(&slsDetector::getNumberofUDPInterfaces);
return sls::minusOneIfDifferent(r);
}
int multiSlsDetector::selectUDPInterface(int n, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->selectUDPInterface(n);
}
// multi
auto r = parallelCall(&slsDetector::selectUDPInterface,n);
return sls::minusOneIfDifferent(r);
}
int multiSlsDetector::getSelectedUDPInterface(int detPos) const {
// single
if (detPos >= 0) {
return detectors[detPos]->getSelectedUDPInterface();
}
// multi
auto r = serialCall(&slsDetector::getSelectedUDPInterface);
return sls::minusOneIfDifferent(r);
}
void multiSlsDetector::setClientDataStreamingInPort(int i, int detPos) {
if (i >= 0) {
int prev_streaming = enableDataStreamingToClient();
@@ -1583,6 +1737,8 @@ void multiSlsDetector::setClientDataStreamingInPort(int i, int detPos) {
// calculate ports individually
int firstPort = i;
int numSockets = (getDetectorTypeAsEnum() == EIGER) ? 2 : 1;
if (getNumberofUDPInterfaces() == 2)
numSockets *= 2;
for (size_t idet = 0; idet < detectors.size(); ++idet) {
auto port = firstPort + (idet * numSockets);
@@ -1621,6 +1777,8 @@ void multiSlsDetector::setReceiverDataStreamingOutPort(int i, int detPos) {
// calculate ports individually
int firstPort = i;
int numSockets = (getDetectorTypeAsEnum() == EIGER) ? 2 : 1;
if (getNumberofUDPInterfaces() == 2)
numSockets *= 2;
for (size_t idet = 0; idet < detectors.size(); ++idet) {
auto port = firstPort + (idet * numSockets);
@@ -2848,6 +3006,9 @@ int multiSlsDetector::createReceivingDataSockets(const bool destroy) {
if (getDetectorTypeAsEnum() == EIGER) {
numSocketsPerDetector = 2;
}
if (getNumberofUDPInterfaces() == 2) {
numSocketsPerDetector = 2;
}
numSockets *= numSocketsPerDetector;
for (size_t iSocket = 0; iSocket < numSockets; ++iSocket) {
@@ -2882,6 +3043,9 @@ void multiSlsDetector::readFrameFromReceiver() {
nX *= 2;
gappixelsenable = detectors[0]->enableGapPixels(-1) >= 1 ? true : false;
}
if (getNumberofUDPInterfaces() == 2) {
nY *= 2;
}
bool runningList[zmqSocket.size()], connectList[zmqSocket.size()];
int numRunning = 0;

View File

@@ -318,9 +318,15 @@ void slsDetector::initializeDetectorStructure(detectorType type) {
detector_shm()->receiverUDPPort = DEFAULT_UDP_PORTNO;
detector_shm()->receiverUDPPort2 = DEFAULT_UDP_PORTNO + 1;
sls::strcpy_safe(detector_shm()->receiverUDPIP, "none");
sls::strcpy_safe(detector_shm()->receiverUDPIP2, "none");
sls::strcpy_safe(detector_shm()->receiverUDPMAC, "none");
sls::strcpy_safe(detector_shm()->receiverUDPMAC2, "none");
sls::strcpy_safe(detector_shm()->detectorMAC, DEFAULT_DET_MAC);
sls::strcpy_safe(detector_shm()->detectorMAC2, DEFAULT_DET_MAC2);
sls::strcpy_safe(detector_shm()->detectorIP, DEFAULT_DET_IP);
sls::strcpy_safe(detector_shm()->detectorIP2, DEFAULT_DET_IP2);
detector_shm()->numUDPInterfaces = 1;
detector_shm()->selectedUDPInterface = 1;
detector_shm()->receiverOnlineFlag = OFFLINE_FLAG;
detector_shm()->tenGigaEnable = 0;
detector_shm()->flippedData[X] = 0;
@@ -1010,38 +1016,73 @@ int slsDetector::writeConfigurationFile(std::ofstream &outfile, multiSlsDetector
names.emplace_back("outdir");
names.emplace_back("lock");
// receiver config
names.emplace_back("detectormac");
names.emplace_back("detectorip");
names.emplace_back("zmqport");
names.emplace_back("rx_zmqport");
names.emplace_back("zmqip");
names.emplace_back("rx_zmqip");
names.emplace_back("rx_tcpport");
names.emplace_back("rx_udpport");
names.emplace_back("rx_udpport2");
names.emplace_back("rx_udpip");
names.emplace_back("rx_hostname");
names.emplace_back("r_readfreq");
// detector specific config
switch (detector_shm()->myDetectorType) {
case GOTTHARD:
names.emplace_back("detectormac");
names.emplace_back("detectorip");
names.emplace_back("rx_udpport");
names.emplace_back("rx_udpip");
names.emplace_back("rx_udpmac");
names.emplace_back("rx_hostname");
names.emplace_back("extsig:0");
names.emplace_back("vhighvoltage");
break;
case EIGER:
names.emplace_back("detectormac");
names.emplace_back("detectorip");
names.emplace_back("rx_udpport");
names.emplace_back("rx_udpport2");
names.emplace_back("rx_udpip");
names.emplace_back("rx_udpmac");
names.emplace_back("rx_hostname");
names.emplace_back("vhighvoltage");
names.emplace_back("trimen");
names.emplace_back("iodelay");
names.emplace_back("tengiga");
break;
case JUNGFRAU:
names.emplace_back("detectormac");
names.emplace_back("detectormac2");
names.emplace_back("detectorip");
names.emplace_back("detectorip2");
names.emplace_back("rx_udpport");
names.emplace_back("rx_udpport2");
names.emplace_back("rx_udpip");
names.emplace_back("rx_udpip2");
names.emplace_back("rx_udpmac");
names.emplace_back("rx_udpmac2");
names.emplace_back("rx_hostname");
names.emplace_back("powerchip");
names.emplace_back("vhighvoltage");
break;
case CHIPTESTBOARD:
names.emplace_back("detectormac");
names.emplace_back("detectorip");
names.emplace_back("rx_udpport");
names.emplace_back("rx_udpip");
names.emplace_back("rx_udpmac");
names.emplace_back("rx_hostname");
names.emplace_back("vhighvoltage");
break;
case MOENCH:
names.emplace_back("detectormac");
names.emplace_back("detectorip");
names.emplace_back("rx_udpport");
names.emplace_back("rx_udpip");
names.emplace_back("rx_udpmac");
names.emplace_back("rx_hostname");
names.emplace_back("powerchip");
names.emplace_back("vhighvoltage");
break;
@@ -1050,6 +1091,10 @@ int slsDetector::writeConfigurationFile(std::ofstream &outfile, multiSlsDetector
std::to_string(detector_shm()->myDetectorType));
}
names.emplace_back("r_readfreq");
names.emplace_back("rx_udpsocksize");
names.emplace_back("rx_realudpsocksize");
auto cmd = slsDetectorCommand(m);
for (auto &name : names) {
char *args[] = {(char *)name.c_str()};
@@ -1516,7 +1561,7 @@ int slsDetector::configureMAC() {
int fnum = F_CONFIGURE_MAC;
int ret = FAIL;
const size_t array_size = 50;
const size_t n_args = 9;
const size_t n_args = 14;
const size_t n_retvals = 2;
char args[n_args][array_size] = {};
char retvals[n_retvals][array_size] = {};
@@ -1538,59 +1583,108 @@ int slsDetector::configureMAC() {
if (sls::ConvertInternetAddresstoIpString(result, detector_shm()->receiverUDPIP,
MAX_STR_LENGTH)) {
sls::strcpy_safe(detector_shm()->receiverUDPIP, "none");
throw RuntimeError("configureMAC: Error. Receiver UDP IP Address not set");
}
}
}
}
// rx_udpip and rx_udpmac is none
if ((!strcmp(detector_shm()->receiverUDPIP, "none")) ||
(!strcmp(detector_shm()->receiverUDPMAC, "none"))) {
throw RuntimeError("configureMAC: Error. IP/MAC Addresses not set");
// rx_udpmac is none
if (!strcmp(detector_shm()->receiverUDPMAC, "none")) {
throw RuntimeError("configureMAC: Error. Receiver UDP MAC Addresses not set");
}
FILE_LOG(logDEBUG1) << "rx_hostname and rx_udpip is valid ";
FILE_LOG(logDEBUG1) << "rx_hostname and rx_udpmac are valid ";
// jungfrau 2 interfaces
// validate for the second interface
if (detector_shm()->numUDPInterfaces == 2) {
// copy from udpip (done here as well if udpconnection avoided (no slsrxr)
if (!strcmp(detector_shm()->receiverUDPIP2, "none")) {
sls::strcpy_safe(detector_shm()->receiverUDPIP2, detector_shm()->receiverUDPIP);
}
// rx_udpmac2 (udpip2 will be copied from udpip if empty)
if (!strcmp(detector_shm()->receiverUDPMAC2, "none")) {
throw RuntimeError("configureMAC: Error. Receiver UDP MAC Addresses 2 not set");
}
FILE_LOG(logDEBUG1) << "rx_udpmac2 are valid ";
}
// copy to args
sls::strcpy_safe(args[0], detector_shm()->receiverUDPIP);
sls::strcpy_safe(args[1], detector_shm()->receiverUDPMAC);
snprintf(args[2], array_size, "%x", detector_shm()->receiverUDPPort);
sls::strcpy_safe(args[3], detector_shm()->detectorMAC);
sls::strcpy_safe(args[4], detector_shm()->detectorIP);
snprintf(args[0], array_size, "%x", detector_shm()->receiverUDPPort);
sls::strcpy_safe(args[1], detector_shm()->receiverUDPIP);
sls::strcpy_safe(args[2], detector_shm()->receiverUDPMAC);
sls::strcpy_safe(args[3], detector_shm()->detectorIP);
sls::strcpy_safe(args[4], detector_shm()->detectorMAC);
snprintf(args[5], array_size, "%x", detector_shm()->receiverUDPPort2);
sls::strcpy_safe(args[6], detector_shm()->receiverUDPIP2);
sls::strcpy_safe(args[7], detector_shm()->receiverUDPMAC2);
sls::strcpy_safe(args[8], detector_shm()->detectorIP2);
sls::strcpy_safe(args[9], detector_shm()->detectorMAC2);
// number of interfaces and which one
snprintf(args[10], array_size, "%x", detector_shm()->numUDPInterfaces);
snprintf(args[11], array_size, "%x", detector_shm()->selectedUDPInterface);
// 2d positions to detector to put into udp header
{
int pos[3] = {0, 0, 0};
int max = detector_shm()->multiSize[1];
int pos[2] = {0, 0};
int max = detector_shm()->multiSize[1] * (detector_shm()->numUDPInterfaces);
// row
pos[0] = (detId % max);
// col for horiz. udp ports
pos[1] = (detId / max) * ((detector_shm()->myDetectorType == EIGER) ? 2 : 1);
// pos[2] (z is reserved)
FILE_LOG(logDEBUG1) << "Detector [" << detId << "] - (" << pos[0] << "," << pos[1] << ")";
snprintf(args[6], array_size, "%x", pos[0]);
snprintf(args[7], array_size, "%x", pos[1]);
snprintf(args[8], array_size, "%x", pos[2]);
snprintf(args[12], array_size, "%x", pos[0]);
snprintf(args[13], array_size, "%x", pos[1]);
}
FILE_LOG(logDEBUG1) << "receiver udp port:" << std::dec << args[0] << "-";
// converting receiverUDPIP to string hex
sls::strcpy_safe(args[0], sls::stringIpToHex(args[0]).c_str());
FILE_LOG(logDEBUG1) << "receiver udp ip:" << args[0] << "-";
sls::strcpy_safe(args[1], sls::stringIpToHex(args[1]).c_str());
FILE_LOG(logDEBUG1) << "receiver udp ip:" << args[1] << "-";
// MAC already in hex removing :
sls::removeChar(args[1], ':');
FILE_LOG(logDEBUG1) << "receiver udp mac:" << args[1] << "-";
FILE_LOG(logDEBUG1) << "receiver udp port:" << args[2] << "-";
// MAC already in hex removing :
sls::removeChar(args[3], ':');
FILE_LOG(logDEBUG1) << "detector udp mac:" << args[3] << "-";
sls::removeChar(args[2], ':');
FILE_LOG(logDEBUG1) << "receiver udp mac:" << args[2] << "-";
// converting detectorIP to string hex
sls::strcpy_safe(args[4], sls::stringIpToHex(args[4]).c_str());
FILE_LOG(logDEBUG1) << "detecotor udp ip:" << args[4] << "-";
sls::strcpy_safe(args[3], sls::stringIpToHex(args[3]).c_str());
FILE_LOG(logDEBUG1) << "detecotor udp ip:" << args[3] << "-";
// MAC already in hex removing :
sls::removeChar(args[4], ':');
FILE_LOG(logDEBUG1) << "detector udp mac:" << args[4] << "-";
FILE_LOG(logDEBUG1) << "receiver udp port2:" << std::dec << args[5] << "-";
if (!strcmp(args[6], "none")) {
sprintf(args[6], "%d", 0);
} else {
sls::strcpy_safe(args[6], sls::stringIpToHex(args[6]).c_str());
}
FILE_LOG(logDEBUG1) << "receiver udp ip2:" << args[6] << "-";
// MAC already in hex removing :
sls::removeChar(args[7], ':');
FILE_LOG(logDEBUG1) << "receiver udp mac2:" << args[7] << "-";
// converting detectorIP to string hex
if (!strcmp(args[8], "none")) {
sprintf(args[8], "%d", 0);
} else {
sls::strcpy_safe(args[8], sls::stringIpToHex(args[8]).c_str());
}
FILE_LOG(logDEBUG1) << "detecotor udp ip2:" << args[8] << "-";
// MAC already in hex removing :
sls::removeChar(args[9], ':');
FILE_LOG(logDEBUG1) << "detector udp mac2:" << args[9] << "-";
FILE_LOG(logDEBUG1) << "number of udp interfaces:" << std::dec << args[10] << "-";
FILE_LOG(logDEBUG1) << "selected udp interface:" << std::dec << args[11] << "-";
FILE_LOG(logDEBUG1) << "row:" << args[12] << "-";
FILE_LOG(logDEBUG1) << "col:" << args[13] << "-";
FILE_LOG(logDEBUG1) << "receiver udp port2:" << args[5] << "-";
FILE_LOG(logDEBUG1) << "row:" << args[6] << "-";
FILE_LOG(logDEBUG1) << "col:" << args[7] << "-";
FILE_LOG(logDEBUG1) << "reserved:" << args[8] << "-";
// send to server
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
@@ -2012,7 +2106,31 @@ std::string slsDetector::setDetectorMAC(const std::string &detectorMAC) {
return std::string(detector_shm()->detectorMAC);
}
std::string slsDetector::getDetectorMAC() { return std::string(detector_shm()->detectorMAC); }
std::string slsDetector::getDetectorMAC() {
return std::string(detector_shm()->detectorMAC);
}
std::string slsDetector::setDetectorMAC2(const std::string &detectorMAC) {
// invalid format
if ((detectorMAC.length() != 17) || (detectorMAC[2] != ':') || (detectorMAC[5] != ':') ||
(detectorMAC[8] != ':') || (detectorMAC[11] != ':') || (detectorMAC[14] != ':')) {
throw RuntimeError("server MAC Address 2 should be in xx:xx:xx:xx:xx:xx format");
}
// valid format
else {
sls::strcpy_safe(detector_shm()->detectorMAC2, detectorMAC.c_str());
if (!strcmp(detector_shm()->receiver_hostname, "none")) {
FILE_LOG(logDEBUG1) << "Receiver hostname not set yet";
} else if (setUDPConnection() == FAIL) {
FILE_LOG(logWARNING) << "UDP connection set up failed";
}
}
return std::string(detector_shm()->detectorMAC2);
}
std::string slsDetector::getDetectorMAC2() {
return std::string(detector_shm()->detectorMAC2);
}
std::string slsDetector::setDetectorIP(const std::string &detectorIP) {
struct sockaddr_in sa;
@@ -2033,7 +2151,32 @@ std::string slsDetector::setDetectorIP(const std::string &detectorIP) {
return std::string(detector_shm()->detectorIP);
}
std::string slsDetector::getDetectorIP() const { return std::string(detector_shm()->detectorIP); }
std::string slsDetector::getDetectorIP() const {
return std::string(detector_shm()->detectorIP);
}
std::string slsDetector::setDetectorIP2(const std::string &detectorIP) {
struct sockaddr_in sa;
if (detectorIP.length() && detectorIP.length() < 16) {
int result = inet_pton(AF_INET, detectorIP.c_str(), &(sa.sin_addr));
if (result == 0) {
throw RuntimeError(
"setDetectorIP: IP Address 2 should be VALID and in xxx.xxx.xxx.xxx format");
} else {
sls::strcpy_safe(detector_shm()->detectorIP2, detectorIP.c_str());
if (!strcmp(detector_shm()->receiver_hostname, "none")) {
FILE_LOG(logDEBUG1) << "Receiver hostname not set yet";
} else if (setUDPConnection() == FAIL) {
FILE_LOG(logWARNING) << "UDP connection set up failed";
}
}
}
return std::string(detector_shm()->detectorIP2);
}
std::string slsDetector::getDetectorIP2() const {
return std::string(detector_shm()->detectorIP2);
}
std::string slsDetector::setReceiverHostname(const std::string &receiverIP) {
FILE_LOG(logDEBUG1) << "Setting up Receiver with " << receiverIP;
@@ -2095,6 +2238,7 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) {
setDetectorId();
setDetectorHostname();
setUDPConnection();
setReceiverUDPSocketBufferSize(0);
setFilePath(detector_shm()->receiver_filePath);
setFileName(detector_shm()->receiver_fileName);
setFileIndex(detector_shm()->receiver_fileIndex);
@@ -2183,6 +2327,29 @@ std::string slsDetector::getReceiverUDPIP() const {
return std::string(detector_shm()->receiverUDPIP);
}
std::string slsDetector::setReceiverUDPIP2(const std::string &udpip) {
struct sockaddr_in sa;
if (udpip.length() && udpip.length() < 16) {
int result = inet_pton(AF_INET, udpip.c_str(), &(sa.sin_addr));
if (result == 0) {
throw ReceiverError(
"setReceiverUDPIP: UDP IP Address 2 should be VALID and in xxx.xxx.xxx.xxx format");
} else {
sls::strcpy_safe(detector_shm()->receiverUDPIP2, udpip.c_str());
if (!strcmp(detector_shm()->receiver_hostname, "none")) {
FILE_LOG(logDEBUG1) << "Receiver hostname not set yet";
} else if (setUDPConnection() == FAIL) {
FILE_LOG(logWARNING) << "UDP connection set up failed";
}
}
}
return std::string(detector_shm()->receiverUDPIP2);
}
std::string slsDetector::getReceiverUDPIP2() const {
return std::string(detector_shm()->receiverUDPIP2);
}
std::string slsDetector::setReceiverUDPMAC(const std::string &udpmac) {
// invalid format
if ((udpmac.length() != 17) || (udpmac[2] != ':') || (udpmac[5] != ':') || (udpmac[8] != ':') ||
@@ -2206,6 +2373,29 @@ std::string slsDetector::getReceiverUDPMAC() const {
return std::string(detector_shm()->receiverUDPMAC);
}
std::string slsDetector::setReceiverUDPMAC2(const std::string &udpmac) {
// invalid format
if ((udpmac.length() != 17) || (udpmac[2] != ':') || (udpmac[5] != ':') || (udpmac[8] != ':') ||
(udpmac[11] != ':') || (udpmac[14] != ':')) {
throw ReceiverError(
"setReceiverUDPMAC: udp MAC Address 2 should be in xx:xx:xx:xx:xx:xx format");
}
// valid format
else {
sls::strcpy_safe(detector_shm()->receiverUDPMAC2, udpmac.c_str());
if (!strcmp(detector_shm()->receiver_hostname, "none")) {
FILE_LOG(logDEBUG1) << "Receiver hostname not set yet";
}
// not doing setUDPConnection as rx_udpmac will get replaced,(must use configuremac)
sls::strcpy_safe(detector_shm()->receiverUDPMAC2, udpmac.c_str());
}
return std::string(detector_shm()->receiverUDPMAC2);
}
std::string slsDetector::getReceiverUDPMAC2() const {
return std::string(detector_shm()->receiverUDPMAC2);
}
int slsDetector::setReceiverUDPPort(int udpport) {
detector_shm()->receiverUDPPort = udpport;
if (!strcmp(detector_shm()->receiver_hostname, "none")) {
@@ -2216,12 +2406,11 @@ int slsDetector::setReceiverUDPPort(int udpport) {
return detector_shm()->receiverUDPPort;
}
int slsDetector::getReceiverUDPPort() const { return detector_shm()->receiverUDPPort; }
int slsDetector::getReceiverUDPPort() const {
return detector_shm()->receiverUDPPort;
}
int slsDetector::setReceiverUDPPort2(int udpport) {
if (detector_shm()->myDetectorType != EIGER) {
return setReceiverUDPPort(udpport);
}
detector_shm()->receiverUDPPort2 = udpport;
if (!strcmp(detector_shm()->receiver_hostname, "none")) {
FILE_LOG(logDEBUG1) << "Receiver hostname not set yet";
@@ -2231,7 +2420,43 @@ int slsDetector::setReceiverUDPPort2(int udpport) {
return detector_shm()->receiverUDPPort2;
}
int slsDetector::getReceiverUDPPort2() const { return detector_shm()->receiverUDPPort2; }
int slsDetector::getReceiverUDPPort2() const {
return detector_shm()->receiverUDPPort2;
}
int slsDetector::setNumberofUDPInterfaces(int n) {
if (detector_shm()->myDetectorType != JUNGFRAU) {
throw RuntimeError("Cannot choose number of interfaces for this detector");
}
detector_shm()->numUDPInterfaces = (n > 1 ? 2 : 1);
if (!strcmp(detector_shm()->receiver_hostname, "none")) {
FILE_LOG(logDEBUG1) << "Receiver hostname not set yet";
} else if (setUDPConnection() == FAIL) {
FILE_LOG(logWARNING) << "UDP connection set up failed";
}
return detector_shm()->numUDPInterfaces;
}
int slsDetector::getNumberofUDPInterfaces() const {
return detector_shm()->numUDPInterfaces;
}
int slsDetector::selectUDPInterface(int n) {
if (detector_shm()->myDetectorType != JUNGFRAU) {
throw RuntimeError("Cannot select an interface for this detector");
}
detector_shm()->selectedUDPInterface = (n > 1 ? 2 : 1);
if (!strcmp(detector_shm()->receiver_hostname, "none")) {
FILE_LOG(logDEBUG1) << "Receiver hostname not set yet";
} else if (setUDPConnection() == FAIL) {
FILE_LOG(logWARNING) << "UDP connection set up failed";
}
return detector_shm()->selectedUDPInterface;
}
int slsDetector::getSelectedUDPInterface() const {
return detector_shm()->selectedUDPInterface;
}
void slsDetector::setClientStreamingPort(int port) { detector_shm()->zmqport = port; }
@@ -2511,8 +2736,8 @@ int64_t slsDetector::getReceiverRealUDPSocketBufferSize() {
int slsDetector::setUDPConnection() {
int fnum = F_SETUP_RECEIVER_UDP;
int ret = FAIL;
char args[3][MAX_STR_LENGTH] = {{}, {}, {}};
char retvals[MAX_STR_LENGTH] = {};
char args[6][MAX_STR_LENGTH] = {{}, {}, {}, {}, {}, {}};
char retvals[2][MAX_STR_LENGTH] = {{}, {}};
FILE_LOG(logDEBUG1) << "Setting UDP Connection";
// called before set up
@@ -2536,15 +2761,32 @@ int slsDetector::setUDPConnection() {
if (sls::ConvertInternetAddresstoIpString(result, detector_shm()->receiverUDPIP,
MAX_STR_LENGTH)) {
sls::strcpy_safe(detector_shm()->receiverUDPIP, "none");
throw RuntimeError("setUDPConnection: Error. Receiver UDP IP Address not set");
}
}
}
}
// jungfrau 2 interfaces or (1 interface and 2nd interface), copy udpip if udpip2 empty
if (detector_shm()->numUDPInterfaces == 2 || detector_shm()->selectedUDPInterface == 2) {
// copy from udpip
if (!strcmp(detector_shm()->receiverUDPIP2, "none")) {
sls::strcpy_safe(detector_shm()->receiverUDPIP2, detector_shm()->receiverUDPIP);
}
}
// copy arguments to args[][]
sls::strcpy_safe(args[0], detector_shm()->receiverUDPIP);
snprintf(args[1], sizeof(args[2]), "%d", detector_shm()->receiverUDPPort);
snprintf(args[2], sizeof(args[2]), "%d", detector_shm()->receiverUDPPort2);
snprintf(args[0], sizeof(args[0]), "%d", detector_shm()->numUDPInterfaces);
snprintf(args[1], sizeof(args[1]), "%d", detector_shm()->selectedUDPInterface);
sls::strcpy_safe(args[2], detector_shm()->receiverUDPIP);
sls::strcpy_safe(args[3], detector_shm()->receiverUDPIP2);
snprintf(args[4], sizeof(args[4]), "%d", detector_shm()->receiverUDPPort);
snprintf(args[5], sizeof(args[5]), "%d", detector_shm()->receiverUDPPort2);
FILE_LOG(logDEBUG1) << "Receiver Number of UDP Interfaces: " << detector_shm()->numUDPInterfaces;
FILE_LOG(logDEBUG1) << "Receiver Selected Interface: " << detector_shm()->selectedUDPInterface;
FILE_LOG(logDEBUG1) << "Receiver udp ip address: " << detector_shm()->receiverUDPIP;
FILE_LOG(logDEBUG1) << "Receiver udp ip address2: " << detector_shm()->receiverUDPIP2;
FILE_LOG(logDEBUG1) << "Receiver udp port: " << detector_shm()->receiverUDPPort;
FILE_LOG(logDEBUG1) << "Receiver udp port2: " << detector_shm()->receiverUDPPort2;
@@ -2552,16 +2794,23 @@ int slsDetector::setUDPConnection() {
auto receiver =
ReceiverSocket(detector_shm()->receiver_hostname, detector_shm()->receiverTCPPort);
ret = receiver.sendCommandThenRead(fnum, args, sizeof(args), retvals, sizeof(retvals));
FILE_LOG(logDEBUG1) << "Receiver UDP MAC returned : " << retvals;
memset(detector_shm()->receiverUDPMAC, 0, MAX_STR_LENGTH);
sls::strcpy_safe(detector_shm()->receiverUDPMAC, retvals);
if (strlen(retvals[0])) {
FILE_LOG(logDEBUG1) << "Receiver UDP MAC returned : " << retvals[0];
memset(detector_shm()->receiverUDPMAC, 0, MAX_STR_LENGTH);
sls::strcpy_safe(detector_shm()->receiverUDPMAC, retvals[0]);
}
if (strlen(retvals[1])) {
FILE_LOG(logDEBUG1) << "Receiver UDP MAC2 returned : " << retvals[1];
memset(detector_shm()->receiverUDPMAC2, 0, MAX_STR_LENGTH);
sls::strcpy_safe(detector_shm()->receiverUDPMAC2, retvals[1]);
}
if (ret == FORCE_UPDATE) {
receiver.close();
ret = updateCachedReceiverVariables();
}
// configure detector with udp details
if (configureMAC() == FAIL) {
setReceiverOnline(OFFLINE_FLAG); // FIXME: Needed??
setReceiverOnline(OFFLINE_FLAG);
}
} else {
throw ReceiverError("setUDPConnection: Receiver is OFFLINE");
@@ -3516,10 +3765,15 @@ int64_t slsDetector::getRateCorrection() {
void slsDetector::printReceiverConfiguration(TLogLevel level) {
FILE_LOG(level) << "#Detector " << detId << ":\n Receiver Hostname:\t" << getReceiverHostname()
<< "\nDetector UDP IP (Source):\t\t" << getDetectorIP()
<< "\nDetector UDP MAC:\t\t" << getDetectorMAC() << "\nReceiver UDP IP:\t"
<< getReceiverUDPIP() << "\nReceiver UDP MAC:\t" << getReceiverUDPMAC()
<< "\nReceiver UDP Port:\t" << getReceiverUDPPort() << "\nReceiver UDP Port2:\t"
<< getReceiverUDPPort2();
<< "\nDetector UDP IP2 (Source):\t\t" << getDetectorIP2()
<< "\nDetector UDP MAC:\t\t" << getDetectorMAC()
<< "\nDetector UDP MAC2:\t\t" << getDetectorMAC2()
<< "\nReceiver UDP IP:\t" << getReceiverUDPIP()
<< "\nReceiver UDP IP2:\t" << getReceiverUDPIP2()
<< "\nReceiver UDP MAC:\t" << getReceiverUDPMAC()
<< "\nReceiver UDP MAC2:\t" << getReceiverUDPMAC2()
<< "\nReceiver UDP Port:\t" << getReceiverUDPPort()
<< "\nReceiver UDP Port2:\t"<< getReceiverUDPPort2();
}
int slsDetector::setReceiverOnline(int value) {

View File

@@ -1535,6 +1535,7 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
descrToFuncMap[i].m_pFuncName = "rx_hostname"; //
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdNetworkParameter;
++i;
/*! \page network
- <b>rx_udpip [ip]</b> sets/gets the ip address of the receiver UDP interface where the data from the detector will be streamed to. Normally used for single detectors (Can be multi-detector). Used if different from eth0. \c Returns \c (string)
*/
@@ -1542,6 +1543,13 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdNetworkParameter;
++i;
/*! \page network
- <b>rx_udpip2 [ip]</b> sets/gets the ip address of the second receiver UDP interface where the data from the bottom half module of the detector will be streamed to. Normally used for single detectors (Can be multi-detector). Used if different from eth0. JUNGFRAU only. \c Returns \c (string)
*/
descrToFuncMap[i].m_pFuncName = "rx_udpip2"; //
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdNetworkParameter;
++i;
/*! \page network
- <b>rx_udpmac [mac]</b> sets/gets the mac address of the receiver UDP interface where the data from the detector will be streamed to. Normally used for single detectors (Can be multi-detector). \c Returns \c (string)
*/
@@ -1549,6 +1557,13 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdNetworkParameter;
++i;
/*! \page network
- <b>rx_udpmac2 [mac]</b> sets/gets the mac address of the second receiver UDP interface where the data from the bottom half module of the detector will be streamed to. Normally used for single detectors (Can be multi-detector). JUNGFRAU only.\c Returns \c (string)
*/
descrToFuncMap[i].m_pFuncName = "rx_udpmac2"; //
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdNetworkParameter;
++i;
/*! \page network
- <b>rx_udpport [port]</b> sets/gets the port of the receiver UDP interface where the data from the detector will be streamed to. Use single-detector command. \c Returns \c (int)
*/
@@ -1557,7 +1572,7 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
++i;
/*! \page network
- <b>rx_udpport2 [port]</b> sets/gets the second port of the receiver UDP interface where the data from the second half of the detector will be streamed to. Use single-detector command. Used for EIGER only. \c Returns \c (int)
- <b>rx_udpport2 [port]</b> sets/gets the second port of the receiver UDP interface where the data from the second half of the detector will be streamed to. Use single-detector command. Used for EIGERand JUNGFRAU only. \c Returns \c (int)
*/
descrToFuncMap[i].m_pFuncName = "rx_udpport2"; //
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdNetworkParameter;
@@ -1585,12 +1600,40 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
++i;
/*! \page network
- <b>detectorip [ip]</b> sets/gets the ip address of the detector UDP interface from where the detector will stream data. Use single-detector command. Keep in same subnet as rx_udpip (if rx_udpip specified). \c Returns \c (string)
- <b>detectormac2 [mac]</b> sets/gets the mac address of the second half of the detector UDP interface from where the bottom half module of the detector will stream data. Use single-detector command. Normally unused. JUNGFRAU only. \c Returns \c (string)
*/
descrToFuncMap[i].m_pFuncName = "detectormac2"; //
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdNetworkParameter;
++i;
/*! \page network
- <b>detectorip [ip]</b> sets/gets the ip address of the detector UDP interface from where the bottom half of the detector will stream data. Use single-detector command. Keep in same subnet as rx_udpip (if rx_udpip specified). \c Returns \c (string)
*/
descrToFuncMap[i].m_pFuncName = "detectorip"; //
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdNetworkParameter;
++i;
/*! \page network
- <b>detectorip2 [ip]</b> sets/gets the ip address of the second half of the detector UDP interface from where the bottom half of the detector will stream data. Use single-detector command. Keep in same subnet as rx_udpip2 (if rx_udpip2 specified). JUNGFRAU only. \c Returns \c (string)
*/
descrToFuncMap[i].m_pFuncName = "detectorip2"; //
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdNetworkParameter;
++i;
/*! \page network
- <b>numinterfaces [n]</b> sets/gets the number of interfaces used to stream out from the detector. Options: 1, 2. JUNGFRAU only. \c Returns \c (int)
*/
descrToFuncMap[i].m_pFuncName = "numinterfaces"; //
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdNetworkParameter;
++i;
/*! \page network
- <b>selinterface [n]</b> sets/gets the 1st or the 2nd interface to use to stream data out of the detector. Options: 1, 2. Effective only when \c numinterfaces is 1. JUNGFRAU only. \c Returns \c (int)
*/
descrToFuncMap[i].m_pFuncName = "selinterface"; //
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdNetworkParameter;
++i;
/*! \page network
- <b>txndelay_left [delay]</b> sets/gets the transmission delay of first packet in an image being streamed out from the detector's left UDP port. Use single-detector command. Used for EIGER only. \c Returns \c (int)
*/
@@ -1606,7 +1649,7 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
++i;
/*! \page network
- <b>txndelay_frame [delay]</b> sets/gets the transmission frame period of entire frame being streamed out from the detector for both ports. Use single-detector command. Used for EIGER only. \c Returns \c (int)
- <b>txndelay_frame [delay]</b> sets/gets the transmission frame period of entire frame being streamed out from the detector for both ports. Use single-detector command. Used for EIGER and JUNGFRAU only. \c Returns \c (int)
*/
descrToFuncMap[i].m_pFuncName = "txndelay_frame"; //
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdNetworkParameter;
@@ -2789,11 +2832,21 @@ std::string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int
myDet->setDetectorMAC(args[1], detPos);
}
return myDet->getDetectorMAC(detPos);
} else if (cmd == "detectormac2") {
if (action == PUT_ACTION) {
myDet->setDetectorMAC2(args[1], detPos);
}
return myDet->getDetectorMAC2(detPos);
} else if (cmd == "detectorip") {
if (action == PUT_ACTION) {
myDet->setDetectorIP(args[1], detPos);
}
return myDet->getDetectorIP(detPos);
if (action == PUT_ACTION) {
myDet->setDetectorIP(args[1], detPos);
}
return myDet->getDetectorIP(detPos);
} else if (cmd == "detectorip2") {
if (action == PUT_ACTION) {
myDet->setDetectorIP2(args[1], detPos);
}
return myDet->getDetectorIP2(detPos);
} else if (cmd == "rx_hostname") {
if (action == PUT_ACTION) {
myDet->setReceiverHostname(args[1], detPos);
@@ -2804,11 +2857,21 @@ std::string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int
myDet->setReceiverUDPIP(args[1], detPos);
}
return myDet->getReceiverUDPIP(detPos);
} else if (cmd == "rx_udpip2") {
if (action == PUT_ACTION) {
myDet->setReceiverUDPIP2(args[1], detPos);
}
return myDet->getReceiverUDPIP(detPos);
} else if (cmd == "rx_udpmac") {
if (action == PUT_ACTION) {
if (action == PUT_ACTION) {
myDet->setReceiverUDPMAC(args[1], detPos);
}
return myDet->getReceiverUDPMAC(detPos);
} else if (cmd == "rx_udpmac2") {
if (action == PUT_ACTION) {
myDet->setReceiverUDPMAC2(args[1], detPos);
}
return myDet->getReceiverUDPMAC(detPos);
} else if (cmd == "rx_udpport") {
if (action == PUT_ACTION) {
if (!(sscanf(args[1], "%d", &i))) {
@@ -2827,6 +2890,24 @@ std::string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int
}
sprintf(ans, "%d", myDet->getReceiverUDPPort2(detPos));
return ans;
} else if (cmd == "numinterfaces") {
if (action == PUT_ACTION) {
if (!(sscanf(args[1], "%d", &i))) {
return ("cannot parse argument") + std::string(args[1]);
}
myDet->setNumberofUDPInterfaces(i, detPos);
}
sprintf(ans, "%d", myDet->getNumberofUDPInterfaces(detPos));
return ans;
} else if (cmd == "selinterface") {
if (action == PUT_ACTION) {
if (!(sscanf(args[1], "%d", &i))) {
return ("cannot parse argument") + std::string(args[1]);
}
myDet->selectUDPInterface(i, detPos);
}
sprintf(ans, "%d", myDet->getSelectedUDPInterface(detPos));
return ans;
} else if (cmd == "rx_udpsocksize") {
if (action == PUT_ACTION) {
int64_t ival = -1;
@@ -2921,12 +3002,18 @@ std::string slsDetectorCommand::helpNetworkParameter(int action) {
std::ostringstream os;
if (action == PUT_ACTION || action == HELP_ACTION) {
os << "detectormac mac \n sets detector mac to mac" << std::endl;
os << "detectormac2 mac \n sets detector mac of 2nd udp interface to mac. Jungfrau only" << std::endl;
os << "detectorip ip \n sets detector ip to ip" << std::endl;
os << "detectorip2 ip \n sets detector ip of 2nd udp interface to ip. Jungfrau only" << std::endl;
os << "rx_hostname name \n sets receiver ip/hostname to name" << std::endl;
os << "rx_udpip ip \n sets receiver udp ip to ip" << std::endl;
os << "rx_udpip2 ip \n sets receiver udp ip of 2nd udp interface to ip. Jungfrau only" << std::endl;
os << "rx_udpmac mac \n sets receiver udp mac to mac" << std::endl;
os << "rx_udpmac2 mac \n sets receiver udp mac of 2nd udp interface to mac. Jungfrau only." << std::endl;
os << "rx_udpport port \n sets receiver udp port to port" << std::endl;
os << "rx_udpport2 port \n sets receiver udp port to port. For Eiger, it is the second half module and for other detectors, same as rx_udpport" << std::endl;
os << "rx_udpport2 port \n sets receiver udp port to port. For Eiger and Jungfrau, it is the second half module and for other detectors, same as rx_udpport" << std::endl;
os << "numinterfaces n \n sets the number of interfaces to n used to stream out from the detector. Options: 1, 2. JUNGFRAU only. " << std::endl;
os << "selinterface n \n sets the 1st or the 2nd interface to use to stream data out of the detector. Options: 1, 2. Effective only when numinterfaces is 1. JUNGFRAU only. " << std::endl;
os << "txndelay_left port \n sets detector transmission delay of the left port" << std::endl;
os << "txndelay_right port \n sets detector transmission delay of the right port" << std::endl;
os << "txndelay_frame port \n sets detector transmission delay of the entire frame" << std::endl;
@@ -2955,11 +3042,18 @@ std::string slsDetectorCommand::helpNetworkParameter(int action) {
}
if (action == GET_ACTION || action == HELP_ACTION) {
os << "detectormac \n gets detector mac " << std::endl;
os << "detectormac2 \n gets detector mac of 2nd udp interface. Jungfrau only" << std::endl;
os << "detectorip \n gets detector ip " << std::endl;
os << "detectorip2 \n gets detector ip of 2nd udp interface. Jungfrau only" << std::endl;
os << "rx_hostname \n gets receiver ip " << std::endl;
os << "rx_udpmac \n gets receiver udp mac " << std::endl;
os << "rx_udpmac2 \n gets receiver udp mac of 2nd udp interface. Jungfrau only" << std::endl;
os << "rx_udpip \n gets receiver udp mac " << std::endl;
os << "rx_udpip2 \n gets receiver udp mac of 2nd udp interface. Jungfrau only" << std::endl;
os << "rx_udpport \n gets receiver udp port " << std::endl;
os << "rx_udpport2 \n gets receiver udp port. For Eiger, it is the second half module and for other detectors, same as rx_udpport" << std::endl;
os << "rx_udpport2 \n gets receiver udp port of 2nd udp interface. For Eiger and Jungfrau, it is the second half module and for other detectors, same as rx_udpport" << std::endl;
os << "numinterfaces \n gets the number of interfaces to n used to stream out from the detector. Options: 1, 2. JUNGFRAU only. " << std::endl;
os << "selinterface \n gets the interface selected to use to stream data out of the detector. Options: 1, 2. Effective only when numinterfaces is 1. JUNGFRAU only. " << std::endl;
os << "txndelay_left \n gets detector transmission delay of the left port" << std::endl;
os << "txndelay_right \n gets detector transmission delay of the right port" << std::endl;
os << "txndelay_frame \n gets detector transmission delay of the entire frame" << std::endl;