mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-27 00:30:03 +02:00
Merge branch 'address' into refactor, including minor change in formal argument name
This commit is contained in:
commit
59a0f5fac9
@ -2,5 +2,5 @@ BasedOnStyle: LLVM
|
|||||||
IndentWidth: 4
|
IndentWidth: 4
|
||||||
|
|
||||||
UseTab: Never
|
UseTab: Never
|
||||||
ColumnLimit: 100
|
ColumnLimit: 80
|
||||||
AlignConsecutiveAssignments: false
|
AlignConsecutiveAssignments: false
|
@ -4,6 +4,7 @@
|
|||||||
#include "ClientSocket.h"
|
#include "ClientSocket.h"
|
||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "network_utils.h"
|
||||||
#include "slsDetector.h"
|
#include "slsDetector.h"
|
||||||
#include "sls_detector_defs.h"
|
#include "sls_detector_defs.h"
|
||||||
#include "sls_detector_exceptions.h"
|
#include "sls_detector_exceptions.h"
|
||||||
@ -11,124 +12,22 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <arpa/inet.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#define VERBOSE
|
#include "network_utils.h"
|
||||||
|
|
||||||
using sls::RuntimeError;
|
using namespace sls;
|
||||||
using sls::SharedMemoryError;
|
|
||||||
using sls::SocketError;
|
|
||||||
using sls::DetectorError;
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
|
IpAddr a("129.129.205.242");
|
||||||
|
IpAddr b(4073554305);
|
||||||
|
|
||||||
std::string hostname;
|
std::vector<IpAddr> vec;
|
||||||
std::cout << "Enter hostname: ";
|
vec.push_back(a);
|
||||||
std::cin >> hostname;
|
|
||||||
|
|
||||||
struct addrinfo hints, *result;
|
|
||||||
memset(&hints, 0, sizeof(hints));
|
|
||||||
hints.ai_family = AF_INET;
|
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
|
||||||
hints.ai_flags |= AI_CANONNAME;
|
|
||||||
|
|
||||||
struct sockaddr_in serverAddr {};
|
|
||||||
// std::cout << "sizeof(result):" << sizeof(hints) << '\n';
|
|
||||||
// std::cout << "sizeof(serverAddr):" << sizeof(serverAddr) << '\n';
|
|
||||||
|
|
||||||
int port = 1952;
|
|
||||||
|
|
||||||
if (getaddrinfo(hostname.c_str(), NULL, &hints, &result) != 0) {
|
|
||||||
std::string msg = "ClientSocket cannot decode host:" + hostname + " on port " +
|
|
||||||
std::to_string(port) + "\n";
|
|
||||||
throw 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
serverAddr.sin_family = AF_INET;
|
|
||||||
serverAddr.sin_port = htons(port);
|
|
||||||
memcpy(&serverAddr.sin_addr.s_addr, &((struct sockaddr_in *)result->ai_addr)->sin_addr,
|
|
||||||
sizeof(in_addr_t));
|
|
||||||
freeaddrinfo(result);
|
|
||||||
|
|
||||||
char address[INET_ADDRSTRLEN];
|
|
||||||
inet_ntop(AF_INET, &serverAddr.sin_addr, address, INET_ADDRSTRLEN);
|
|
||||||
std::cout << "ip of host is: " << address << '\n';
|
|
||||||
|
|
||||||
sls::ClientSocket(false, serverAddr);
|
|
||||||
|
|
||||||
// const std::string hostname = "beb083";
|
|
||||||
// auto type = slsDetector::getTypeFromDetector(hostname);
|
|
||||||
// slsDetector d(type);
|
|
||||||
// d.setHostname(hostname);
|
|
||||||
// d.setOnline(true);
|
|
||||||
// std::cout << "hostname: " << d.getHostname() << '\n';
|
|
||||||
// d.setThresholdTemperature(50);
|
|
||||||
// try{
|
|
||||||
// d.setThresholdTemperature(50);
|
|
||||||
// }catch(const DetectorError &e){
|
|
||||||
// std::cout << "Caught: " << e.what() << '\n';
|
|
||||||
// }
|
|
||||||
// std::cout << "hostname: " << d.getHostname() << '\n';
|
|
||||||
// std::cout << "exptime: " << d.setDAC(-1, slsDetectorDefs::E_Vrf, 0) << '\n';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// slsDetector d2(type);
|
|
||||||
// std::cout << "Online: " << d2.getOnlineFlag() << '\n';
|
|
||||||
// d2.setHostname("beb55555");
|
|
||||||
// d2.setOnline(true);
|
|
||||||
// std::cout << "Online: " << d2.getOnlineFlag() << '\n';
|
|
||||||
// std::cout << "hostname: " << d2.getHostname() << '\n';
|
|
||||||
|
|
||||||
// std::cout << "port: " << d.getControlPort() << '\n';
|
|
||||||
// d.setOnline(true);
|
|
||||||
// d.setReceiverOnline(true);
|
|
||||||
// std::cout << "reciver version: " << std::hex << d.getReceiverVersion() << '\n';
|
|
||||||
// // std::cout << "version: " << d.getId(slsDetectorDefs::CLIENT_RECEIVER_API_VERSION) << '\n';
|
|
||||||
// d.freeSharedMemory();
|
|
||||||
// //Catch exception
|
|
||||||
// try {
|
|
||||||
// throw RuntimeError("something went wrong");
|
|
||||||
// } catch (RuntimeError &e) {
|
|
||||||
// std::cout << "Caught RuntimeError with message : " << e.what() << '\n';
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //Catch base class
|
|
||||||
// try {
|
|
||||||
// throw SharedMemoryError("Could not create shared memory");
|
|
||||||
// } catch (RuntimeError &e) {
|
|
||||||
// std::cout << "Caught: " << e.what() << '\n';
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //Catch base class after looking for something else
|
|
||||||
// try {
|
|
||||||
// throw SharedMemoryError("Could not create shared memory");
|
|
||||||
// } catch (SocketError &e) {
|
|
||||||
|
|
||||||
// std::cout << "Caught Socket error: " << e.what() << '\n';
|
|
||||||
|
|
||||||
// } catch (RuntimeError &e) {
|
|
||||||
// std::cout << "Caught base class: " << e.what() << '\n';
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //Catch any after looking for something else
|
|
||||||
// try {
|
|
||||||
// throw SharedMemoryError("Could not create shared memory");
|
|
||||||
// } catch (SocketError &e) {
|
|
||||||
|
|
||||||
// std::cout << "Caught Socket error: " << e.what() << '\n';
|
|
||||||
|
|
||||||
// } catch (...) {
|
|
||||||
// std::cout << "Caught Something else probably should have let me crash\n";
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// throw RuntimeError("This one we missed");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "error_defs.h"
|
#include "error_defs.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "sls_detector_defs.h"
|
#include "sls_detector_defs.h"
|
||||||
|
#include "network_utils.h"
|
||||||
class ClientInterface;
|
class ClientInterface;
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
@ -101,10 +102,6 @@ struct sharedSlsDetector {
|
|||||||
/** size of the data that are transfered from the detector */
|
/** size of the data that are transfered from the detector */
|
||||||
int dataBytes;
|
int dataBytes;
|
||||||
|
|
||||||
/** threaded processing flag
|
|
||||||
* (i.e. if data are processed in a separate thread) */
|
|
||||||
// int threadedProcessing;
|
|
||||||
|
|
||||||
/** number of rois defined */
|
/** number of rois defined */
|
||||||
int nROI;
|
int nROI;
|
||||||
|
|
||||||
@ -137,28 +134,28 @@ struct sharedSlsDetector {
|
|||||||
int receiverUDPPort2;
|
int receiverUDPPort2;
|
||||||
|
|
||||||
/** ip address of the receiver for the detector to send packets to**/
|
/** ip address of the receiver for the detector to send packets to**/
|
||||||
char receiverUDPIP[MAX_STR_LENGTH];
|
sls::IpAddr receiverUDPIP;
|
||||||
|
|
||||||
/** ip address of the receiver for the 2nd interface of the detector to send packets to**/
|
/** ip address of the receiver for the 2nd interface of the detector to send packets to**/
|
||||||
char receiverUDPIP2[MAX_STR_LENGTH];
|
sls::IpAddr receiverUDPIP2;
|
||||||
|
|
||||||
/** mac address of receiver for the detector to send packets to **/
|
/** mac address of receiver for the detector to send packets to **/
|
||||||
char receiverUDPMAC[MAX_STR_LENGTH];
|
sls::MacAddr receiverUDPMAC;
|
||||||
|
|
||||||
/** mac address of receiver for the 2nd interface of the detector to send packets to **/
|
/** mac address of receiver for the 2nd interface of the detector to send packets to **/
|
||||||
char receiverUDPMAC2[MAX_STR_LENGTH];
|
sls::MacAddr receiverUDPMAC2;
|
||||||
|
|
||||||
/** mac address of the detector **/
|
/** mac address of the detector **/
|
||||||
char detectorMAC[MAX_STR_LENGTH];
|
sls::MacAddr detectorMAC;
|
||||||
|
|
||||||
/** mac address of the 2nd interface of the detector **/
|
/** mac address of the 2nd interface of the detector **/
|
||||||
char detectorMAC2[MAX_STR_LENGTH];
|
sls::MacAddr detectorMAC2;
|
||||||
|
|
||||||
/** ip address of the detector **/
|
/** ip address of the detector **/
|
||||||
char detectorIP[MAX_STR_LENGTH];
|
sls::IpAddr detectorIP;
|
||||||
|
|
||||||
/** ip address of the 2nd interface of the detector **/
|
/** ip address of the 2nd interface of the detector **/
|
||||||
char detectorIP2[MAX_STR_LENGTH];
|
sls::IpAddr detectorIP2;
|
||||||
|
|
||||||
/** number of udp interface */
|
/** number of udp interface */
|
||||||
int numUDPInterfaces;
|
int numUDPInterfaces;
|
||||||
@ -797,7 +794,7 @@ class slsDetector : public virtual slsDetectorDefs{
|
|||||||
* Returns the detector MAC address\sa sharedSlsDetector
|
* Returns the detector MAC address\sa sharedSlsDetector
|
||||||
* @returns the detector MAC address
|
* @returns the detector MAC address
|
||||||
*/
|
*/
|
||||||
std::string getDetectorMAC();
|
sls::MacAddr getDetectorMAC();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the format of the detector MAC address (bottom half) and sets it (Jungfrau only)
|
* Validates the format of the detector MAC address (bottom half) and sets it (Jungfrau only)
|
||||||
@ -810,7 +807,7 @@ class slsDetector : public virtual slsDetectorDefs{
|
|||||||
* Returns the detector MAC address (bottom half) Jungfrau only
|
* Returns the detector MAC address (bottom half) Jungfrau only
|
||||||
* @returns the detector MAC address (bottom half)
|
* @returns the detector MAC address (bottom half)
|
||||||
*/
|
*/
|
||||||
std::string getDetectorMAC2();
|
sls::MacAddr getDetectorMAC2();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the format of the detector IP address and sets it \sa sharedSlsDetector
|
* Validates the format of the detector IP address and sets it \sa sharedSlsDetector
|
||||||
@ -823,7 +820,7 @@ class slsDetector : public virtual slsDetectorDefs{
|
|||||||
* Returns the detector IP address\sa sharedSlsDetector
|
* Returns the detector IP address\sa sharedSlsDetector
|
||||||
* @returns the detector IP address
|
* @returns the detector IP address
|
||||||
*/
|
*/
|
||||||
std::string getDetectorIP() const;
|
sls::IpAddr getDetectorIP() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the format of the detector IP address (bottom half) and sets it (Jungfrau only)
|
* Validates the format of the detector IP address (bottom half) and sets it (Jungfrau only)
|
||||||
@ -836,7 +833,7 @@ class slsDetector : public virtual slsDetectorDefs{
|
|||||||
* Returns the detector IP address (bottom half) Jungfrau only
|
* Returns the detector IP address (bottom half) Jungfrau only
|
||||||
* @returns the detector IP address (bottom half)
|
* @returns the detector IP address (bottom half)
|
||||||
*/
|
*/
|
||||||
std::string getDetectorIP2() const;
|
sls::IpAddr getDetectorIP2() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates and sets the receiver.
|
* Validates and sets the receiver.
|
||||||
@ -864,7 +861,7 @@ class slsDetector : public virtual slsDetectorDefs{
|
|||||||
* Returns the receiver UDP IP address\sa sharedSlsDetector
|
* Returns the receiver UDP IP address\sa sharedSlsDetector
|
||||||
* @returns the receiver UDP IP address
|
* @returns the receiver UDP IP address
|
||||||
*/
|
*/
|
||||||
std::string getReceiverUDPIP() const;
|
sls::IpAddr getReceiverUDPIP() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the format of the receiver UDP IP address (bottom half) and sets it(Jungfrau only)
|
* Validates the format of the receiver UDP IP address (bottom half) and sets it(Jungfrau only)
|
||||||
@ -877,7 +874,7 @@ class slsDetector : public virtual slsDetectorDefs{
|
|||||||
* Returns the receiver UDP IP address (bottom half) Jungfrau only
|
* Returns the receiver UDP IP address (bottom half) Jungfrau only
|
||||||
* @returns the receiver UDP IP address (bottom half)
|
* @returns the receiver UDP IP address (bottom half)
|
||||||
*/
|
*/
|
||||||
std::string getReceiverUDPIP2() const;
|
sls::IpAddr getReceiverUDPIP2() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the format of the receiver UDP MAC address and sets it \sa sharedSlsDetector
|
* Validates the format of the receiver UDP MAC address and sets it \sa sharedSlsDetector
|
||||||
@ -890,7 +887,7 @@ class slsDetector : public virtual slsDetectorDefs{
|
|||||||
* Returns the receiver UDP MAC address\sa sharedSlsDetector
|
* Returns the receiver UDP MAC address\sa sharedSlsDetector
|
||||||
* @returns the receiver UDP MAC address
|
* @returns the receiver UDP MAC address
|
||||||
*/
|
*/
|
||||||
std::string getReceiverUDPMAC() const;
|
sls::MacAddr getReceiverUDPMAC() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the format of the receiver UDP MAC address (bottom half) and sets it (Jungfrau only)
|
* Validates the format of the receiver UDP MAC address (bottom half) and sets it (Jungfrau only)
|
||||||
@ -903,7 +900,7 @@ class slsDetector : public virtual slsDetectorDefs{
|
|||||||
* Returns the receiver UDP MAC address (bottom half) Jungfrau only
|
* Returns the receiver UDP MAC address (bottom half) Jungfrau only
|
||||||
* @returns the receiver UDP MAC address (bottom half)
|
* @returns the receiver UDP MAC address (bottom half)
|
||||||
*/
|
*/
|
||||||
std::string getReceiverUDPMAC2() const;
|
sls::MacAddr getReceiverUDPMAC2() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the receiver UDP port\sa sharedSlsDetector
|
* Sets the receiver UDP port\sa sharedSlsDetector
|
||||||
|
@ -9,7 +9,10 @@
|
|||||||
#include "slsDetectorCommand.h"
|
#include "slsDetectorCommand.h"
|
||||||
#include "sls_detector_exceptions.h"
|
#include "sls_detector_exceptions.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "container_utils.h"
|
||||||
#include "string_utils.h"
|
#include "string_utils.h"
|
||||||
|
#include "network_utils.h"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
@ -19,17 +22,14 @@
|
|||||||
#include <sys/ipc.h>
|
#include <sys/ipc.h>
|
||||||
#include <sys/shm.h>
|
#include <sys/shm.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
//#include <time.h> //clock()
|
|
||||||
|
|
||||||
#include "container_utils.h"
|
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <future>
|
#include <future>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using sls::NotImplementedError;
|
using namespace sls;
|
||||||
using sls::RuntimeError;
|
|
||||||
using sls::SharedMemory;
|
|
||||||
using sls::SharedMemoryError;
|
|
||||||
|
|
||||||
multiSlsDetector::multiSlsDetector(int multi_id, bool verify, bool update)
|
multiSlsDetector::multiSlsDetector(int multi_id, bool verify, bool update)
|
||||||
: multiId(multi_id), multi_shm(multi_id, -1) {
|
: multiId(multi_id), multi_shm(multi_id, -1) {
|
||||||
@ -1457,7 +1457,7 @@ std::string multiSlsDetector::setDetectorMAC(const std::string &detectorMAC, int
|
|||||||
std::string multiSlsDetector::getDetectorMAC(int detPos) {
|
std::string multiSlsDetector::getDetectorMAC(int detPos) {
|
||||||
// single
|
// single
|
||||||
if (detPos >= 0) {
|
if (detPos >= 0) {
|
||||||
return detectors[detPos]->getDetectorMAC();
|
return detectors[detPos]->getDetectorMAC().str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// multi
|
// multi
|
||||||
@ -1479,7 +1479,7 @@ std::string multiSlsDetector::setDetectorMAC2(const std::string &detectorMAC, in
|
|||||||
std::string multiSlsDetector::getDetectorMAC2(int detPos) {
|
std::string multiSlsDetector::getDetectorMAC2(int detPos) {
|
||||||
// single
|
// single
|
||||||
if (detPos >= 0) {
|
if (detPos >= 0) {
|
||||||
return detectors[detPos]->getDetectorMAC2();
|
return detectors[detPos]->getDetectorMAC2().str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// multi
|
// multi
|
||||||
@ -1501,7 +1501,7 @@ std::string multiSlsDetector::setDetectorIP(const std::string &detectorIP, int d
|
|||||||
std::string multiSlsDetector::getDetectorIP(int detPos) const {
|
std::string multiSlsDetector::getDetectorIP(int detPos) const {
|
||||||
// single
|
// single
|
||||||
if (detPos >= 0) {
|
if (detPos >= 0) {
|
||||||
return detectors[detPos]->getDetectorIP();
|
return detectors[detPos]->getDetectorIP().str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// multi
|
// multi
|
||||||
@ -1523,7 +1523,7 @@ std::string multiSlsDetector::setDetectorIP2(const std::string &detectorIP, int
|
|||||||
std::string multiSlsDetector::getDetectorIP2(int detPos) const {
|
std::string multiSlsDetector::getDetectorIP2(int detPos) const {
|
||||||
// single
|
// single
|
||||||
if (detPos >= 0) {
|
if (detPos >= 0) {
|
||||||
return detectors[detPos]->getDetectorIP2();
|
return detectors[detPos]->getDetectorIP2().str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// multi
|
// multi
|
||||||
@ -1568,7 +1568,7 @@ std::string multiSlsDetector::setReceiverUDPIP(const std::string &udpip, int det
|
|||||||
std::string multiSlsDetector::getReceiverUDPIP(int detPos) const {
|
std::string multiSlsDetector::getReceiverUDPIP(int detPos) const {
|
||||||
// single
|
// single
|
||||||
if (detPos >= 0) {
|
if (detPos >= 0) {
|
||||||
return detectors[detPos]->getReceiverUDPIP();
|
return detectors[detPos]->getReceiverUDPIP().str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// multi
|
// multi
|
||||||
@ -1590,7 +1590,7 @@ std::string multiSlsDetector::setReceiverUDPIP2(const std::string &udpip, int de
|
|||||||
std::string multiSlsDetector::getReceiverUDPIP2(int detPos) const {
|
std::string multiSlsDetector::getReceiverUDPIP2(int detPos) const {
|
||||||
// single
|
// single
|
||||||
if (detPos >= 0) {
|
if (detPos >= 0) {
|
||||||
return detectors[detPos]->getReceiverUDPIP2();
|
return detectors[detPos]->getReceiverUDPIP2().str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// multi
|
// multi
|
||||||
@ -1612,7 +1612,7 @@ std::string multiSlsDetector::setReceiverUDPMAC(const std::string &udpmac, int d
|
|||||||
std::string multiSlsDetector::getReceiverUDPMAC(int detPos) const {
|
std::string multiSlsDetector::getReceiverUDPMAC(int detPos) const {
|
||||||
// single
|
// single
|
||||||
if (detPos >= 0) {
|
if (detPos >= 0) {
|
||||||
return detectors[detPos]->getReceiverUDPMAC();
|
return detectors[detPos]->getReceiverUDPMAC().str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// multi
|
// multi
|
||||||
@ -1634,7 +1634,7 @@ std::string multiSlsDetector::setReceiverUDPMAC2(const std::string &udpmac, int
|
|||||||
std::string multiSlsDetector::getReceiverUDPMAC2(int detPos) const {
|
std::string multiSlsDetector::getReceiverUDPMAC2(int detPos) const {
|
||||||
// single
|
// single
|
||||||
if (detPos >= 0) {
|
if (detPos >= 0) {
|
||||||
return detectors[detPos]->getReceiverUDPMAC2();
|
return detectors[detPos]->getReceiverUDPMAC2().str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// multi
|
// multi
|
||||||
|
@ -7,11 +7,11 @@
|
|||||||
#include "file_utils.h"
|
#include "file_utils.h"
|
||||||
#include "gitInfoLib.h"
|
#include "gitInfoLib.h"
|
||||||
#include "multiSlsDetector.h"
|
#include "multiSlsDetector.h"
|
||||||
|
#include "network_utils.h"
|
||||||
#include "slsDetectorCommand.h"
|
#include "slsDetectorCommand.h"
|
||||||
#include "sls_detector_exceptions.h"
|
#include "sls_detector_exceptions.h"
|
||||||
#include "string_utils.h"
|
#include "string_utils.h"
|
||||||
#include "versionAPI.h"
|
#include "versionAPI.h"
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
@ -24,14 +24,7 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
using sls::DetectorError;
|
using namespace sls;
|
||||||
using sls::DetectorSocket;
|
|
||||||
using sls::NotImplementedError;
|
|
||||||
using sls::ReceiverError;
|
|
||||||
using sls::ReceiverSocket;
|
|
||||||
using sls::RuntimeError;
|
|
||||||
using sls::SharedMemory;
|
|
||||||
using sls::SharedMemoryError;
|
|
||||||
|
|
||||||
#define DEFAULT_HOSTNAME "localhost"
|
#define DEFAULT_HOSTNAME "localhost"
|
||||||
|
|
||||||
@ -317,14 +310,17 @@ void slsDetector::initializeDetectorStructure(detectorType type) {
|
|||||||
detector_shm()->receiverTCPPort = DEFAULT_PORTNO + 2;
|
detector_shm()->receiverTCPPort = DEFAULT_PORTNO + 2;
|
||||||
detector_shm()->receiverUDPPort = DEFAULT_UDP_PORTNO;
|
detector_shm()->receiverUDPPort = DEFAULT_UDP_PORTNO;
|
||||||
detector_shm()->receiverUDPPort2 = DEFAULT_UDP_PORTNO + 1;
|
detector_shm()->receiverUDPPort2 = DEFAULT_UDP_PORTNO + 1;
|
||||||
sls::strcpy_safe(detector_shm()->receiverUDPIP, "none");
|
|
||||||
sls::strcpy_safe(detector_shm()->receiverUDPIP2, "none");
|
detector_shm()->receiverUDPIP = 0u;
|
||||||
sls::strcpy_safe(detector_shm()->receiverUDPMAC, "none");
|
detector_shm()->receiverUDPIP2 = 0u;
|
||||||
sls::strcpy_safe(detector_shm()->receiverUDPMAC2, "none");
|
detector_shm()->receiverUDPMAC = 0ul;
|
||||||
sls::strcpy_safe(detector_shm()->detectorMAC, DEFAULT_DET_MAC);
|
detector_shm()->receiverUDPMAC2 = 0ul;
|
||||||
sls::strcpy_safe(detector_shm()->detectorMAC2, DEFAULT_DET_MAC2);
|
|
||||||
sls::strcpy_safe(detector_shm()->detectorIP, DEFAULT_DET_IP);
|
detector_shm()->detectorMAC = DEFAULT_DET_MAC;
|
||||||
sls::strcpy_safe(detector_shm()->detectorIP2, DEFAULT_DET_IP2);
|
detector_shm()->detectorMAC2 = DEFAULT_DET_MAC2;
|
||||||
|
detector_shm()->detectorIP = DEFAULT_DET_MAC;
|
||||||
|
detector_shm()->detectorIP2 = DEFAULT_DET_MAC2;
|
||||||
|
|
||||||
detector_shm()->numUDPInterfaces = 1;
|
detector_shm()->numUDPInterfaces = 1;
|
||||||
detector_shm()->selectedUDPInterface = 1;
|
detector_shm()->selectedUDPInterface = 1;
|
||||||
detector_shm()->receiverOnlineFlag = OFFLINE_FLAG;
|
detector_shm()->receiverOnlineFlag = OFFLINE_FLAG;
|
||||||
@ -401,7 +397,8 @@ void slsDetector::initializeDetectorStructure(detectorType type) {
|
|||||||
detector_shm()->gappixels * detector_shm()->nGappixels[Y]) *
|
detector_shm()->gappixels * detector_shm()->nGappixels[Y]) *
|
||||||
detector_shm()->dynamicRange / 8;
|
detector_shm()->dynamicRange / 8;
|
||||||
|
|
||||||
// update #nchans and databytes, as it depends on #samples, roi, readoutflags (ctb only)
|
// update #nchans and databytes, as it depends on #samples, roi,
|
||||||
|
// readoutflags (ctb only)
|
||||||
if (detector_shm()->myDetectorType == CHIPTESTBOARD ||
|
if (detector_shm()->myDetectorType == CHIPTESTBOARD ||
|
||||||
detector_shm()->myDetectorType == MOENCH) {
|
detector_shm()->myDetectorType == MOENCH) {
|
||||||
updateTotalNumberOfChannels();
|
updateTotalNumberOfChannels();
|
||||||
@ -519,9 +516,9 @@ int slsDetector::receiveModule(sls_detector_module *myMod, sls::ClientSocket &cl
|
|||||||
|
|
||||||
slsDetectorDefs::detectorType slsDetector::getDetectorTypeFromShm(int multi_id, bool verify) {
|
slsDetectorDefs::detectorType slsDetector::getDetectorTypeFromShm(int multi_id, bool verify) {
|
||||||
if (!detector_shm.IsExisting()) {
|
if (!detector_shm.IsExisting()) {
|
||||||
throw SharedMemoryError(
|
throw SharedMemoryError("Shared memory " + detector_shm.GetName() +
|
||||||
"Shared memory " + detector_shm.GetName() +
|
"does not exist.\n Corrupted Multi Shared "
|
||||||
"does not exist.\n Corrupted Multi Shared memory. Please free shared memory.");
|
"memory. Please free shared memory.");
|
||||||
}
|
}
|
||||||
|
|
||||||
detector_shm.OpenSharedMemory();
|
detector_shm.OpenSharedMemory();
|
||||||
@ -961,7 +958,8 @@ int slsDetector::updateDetectorNoWait(sls::ClientSocket &client) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// update #nchans and databytes, as it depends on #samples, roi, readoutflags (ctb only)
|
// update #nchans and databytes, as it depends on #samples, roi,
|
||||||
|
// readoutflags (ctb only)
|
||||||
if (detector_shm()->myDetectorType == CHIPTESTBOARD ||
|
if (detector_shm()->myDetectorType == CHIPTESTBOARD ||
|
||||||
detector_shm()->myDetectorType == MOENCH) {
|
detector_shm()->myDetectorType == MOENCH) {
|
||||||
updateTotalNumberOfChannels();
|
updateTotalNumberOfChannels();
|
||||||
@ -1134,7 +1132,8 @@ slsDetectorDefs::detectorSettings slsDetector::setSettings(detectorSettings iset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// others: send only the settings, detector server will update dac values already in server
|
// others: send only the settings, detector server will update dac values
|
||||||
|
// already in server
|
||||||
return sendSettingsOnly(isettings);
|
return sendSettingsOnly(isettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1158,7 +1157,8 @@ slsDetectorDefs::detectorSettings slsDetector::sendSettingsOnly(detectorSettings
|
|||||||
}
|
}
|
||||||
|
|
||||||
int slsDetector::getThresholdEnergy() {
|
int slsDetector::getThresholdEnergy() {
|
||||||
// moench - get threshold energy from processor (due to different clients, diff shm)
|
// moench - get threshold energy from processor (due to different clients,
|
||||||
|
// diff shm)
|
||||||
if (detector_shm()->myDetectorType == MOENCH) {
|
if (detector_shm()->myDetectorType == MOENCH) {
|
||||||
// get json from rxr, parse for threshold and update shm
|
// get json from rxr, parse for threshold and update shm
|
||||||
getAdditionalJsonHeader();
|
getAdditionalJsonHeader();
|
||||||
@ -1275,7 +1275,8 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isetti
|
|||||||
FILE_LOG(logDEBUG1) << "Settings File is " << settingsfname;
|
FILE_LOG(logDEBUG1) << "Settings File is " << settingsfname;
|
||||||
|
|
||||||
// read the files
|
// read the files
|
||||||
// myMod = createModule(); // readSettings also checks if create module is null
|
// myMod = createModule(); // readSettings also checks if create module
|
||||||
|
// is null
|
||||||
if (nullptr == readSettingsFile(settingsfname, myMod, tb)) {
|
if (nullptr == readSettingsFile(settingsfname, myMod, tb)) {
|
||||||
if (myMod) {
|
if (myMod) {
|
||||||
deleteModule(myMod);
|
deleteModule(myMod);
|
||||||
@ -1325,8 +1326,8 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isetti
|
|||||||
if (myMod1->iodelay != myMod2->iodelay) {
|
if (myMod1->iodelay != myMod2->iodelay) {
|
||||||
deleteModule(myMod1);
|
deleteModule(myMod1);
|
||||||
deleteModule(myMod2);
|
deleteModule(myMod2);
|
||||||
throw RuntimeError(
|
throw RuntimeError("setThresholdEnergyAndSettings: Iodelays do not "
|
||||||
"setThresholdEnergyAndSettings: Iodelays do not match between files");
|
"match between files");
|
||||||
}
|
}
|
||||||
|
|
||||||
// interpolate module
|
// interpolate module
|
||||||
@ -1334,7 +1335,8 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isetti
|
|||||||
if (myMod == nullptr) {
|
if (myMod == nullptr) {
|
||||||
deleteModule(myMod1);
|
deleteModule(myMod1);
|
||||||
deleteModule(myMod2);
|
deleteModule(myMod2);
|
||||||
throw RuntimeError("setThresholdEnergyAndSettings: Could not interpolate, different "
|
throw RuntimeError("setThresholdEnergyAndSettings: Could not "
|
||||||
|
"interpolate, different "
|
||||||
"dac values in files");
|
"dac values in files");
|
||||||
}
|
}
|
||||||
// interpolate tau
|
// interpolate tau
|
||||||
@ -1351,7 +1353,8 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isetti
|
|||||||
setModule(*myMod, tb);
|
setModule(*myMod, tb);
|
||||||
deleteModule(myMod);
|
deleteModule(myMod);
|
||||||
if (getSettings() != is) {
|
if (getSettings() != is) {
|
||||||
throw RuntimeError("setThresholdEnergyAndSettings: Could not set settings in detector");
|
throw RuntimeError("setThresholdEnergyAndSettings: Could not set "
|
||||||
|
"settings in detector");
|
||||||
}
|
}
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@ -1518,7 +1521,8 @@ int slsDetector::startAndReadAll() {
|
|||||||
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
||||||
auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort);
|
auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort);
|
||||||
ret = client.sendCommandThenRead(fnum, nullptr, 0, nullptr, 0);
|
ret = client.sendCommandThenRead(fnum, nullptr, 0, nullptr, 0);
|
||||||
// TODO! how to we hande this? ret == FAIL --> detector_shm()->stoppedFlag = 1;
|
// TODO! how to we hande this? ret == FAIL -->
|
||||||
|
// detector_shm()->stoppedFlag = 1;
|
||||||
FILE_LOG(logDEBUG1) << "Detector successfully finished acquisition";
|
FILE_LOG(logDEBUG1) << "Detector successfully finished acquisition";
|
||||||
}
|
}
|
||||||
if (ret == FORCE_UPDATE) {
|
if (ret == FORCE_UPDATE) {
|
||||||
@ -1550,7 +1554,8 @@ int slsDetector::readAll() {
|
|||||||
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
||||||
auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort);
|
auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort);
|
||||||
ret = client.sendCommandThenRead(fnum, nullptr, 0, nullptr, 0);
|
ret = client.sendCommandThenRead(fnum, nullptr, 0, nullptr, 0);
|
||||||
// TODO! how to we hande this? ret == FAIL --> detector_shm()->stoppedFlag = 1;
|
// TODO! how to we hande this? ret == FAIL -->
|
||||||
|
// detector_shm()->stoppedFlag = 1;
|
||||||
FILE_LOG(logDEBUG1) << "Detector successfully finished reading all frames";
|
FILE_LOG(logDEBUG1) << "Detector successfully finished reading all frames";
|
||||||
}
|
}
|
||||||
if (ret == FORCE_UPDATE) {
|
if (ret == FORCE_UPDATE) {
|
||||||
@ -1565,67 +1570,44 @@ int slsDetector::configureMAC() {
|
|||||||
const size_t array_size = 50;
|
const size_t array_size = 50;
|
||||||
const size_t n_args = 14;
|
const size_t n_args = 14;
|
||||||
const size_t n_retvals = 2;
|
const size_t n_retvals = 2;
|
||||||
char args[n_args][array_size] = {};
|
char args[n_args][array_size]{};
|
||||||
char retvals[n_retvals][array_size] = {};
|
char retvals[n_retvals][array_size]{};
|
||||||
FILE_LOG(logDEBUG1) << "Configuring MAC";
|
FILE_LOG(logDEBUG1) << "Configuring MAC";
|
||||||
|
if (detector_shm()->receiverUDPIP == 0) {
|
||||||
// if rx_udpip is none
|
// If hostname is valid ip use that, oterwise lookup hostname
|
||||||
if (!(strcmp(detector_shm()->receiverUDPIP, "none"))) {
|
detector_shm()->receiverUDPIP = detector_shm()->receiver_hostname;
|
||||||
// hostname is an ip address
|
if (detector_shm()->receiverUDPIP == 0) {
|
||||||
if (strchr(detector_shm()->receiver_hostname, '.') != nullptr) {
|
detector_shm()->receiverUDPIP = HostnameToIp(detector_shm()->receiver_hostname);
|
||||||
sls::strcpy_safe(detector_shm()->receiverUDPIP, detector_shm()->receiver_hostname);
|
|
||||||
// if hostname not ip, convert it to ip
|
|
||||||
} else {
|
|
||||||
struct addrinfo *result;
|
|
||||||
if (sls::ConvertHostnameToInternetAddress(detector_shm()->receiver_hostname, &result) ==
|
|
||||||
0) {
|
|
||||||
// on success
|
|
||||||
memset(detector_shm()->receiverUDPIP, 0, MAX_STR_LENGTH);
|
|
||||||
// on failure, back to none
|
|
||||||
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_udpmac is none
|
if (detector_shm()->receiverUDPMAC == 0) {
|
||||||
if (!strcmp(detector_shm()->receiverUDPMAC, "none")) {
|
|
||||||
throw RuntimeError("configureMAC: Error. Receiver UDP MAC Addresses not set");
|
throw RuntimeError("configureMAC: Error. Receiver UDP MAC Addresses not set");
|
||||||
}
|
}
|
||||||
FILE_LOG(logDEBUG1) << "rx_hostname and rx_udpmac are valid ";
|
FILE_LOG(logDEBUG1) << "rx_hostname and rx_udpmac are valid ";
|
||||||
|
|
||||||
// jungfrau 2 interfaces
|
// Jungfrau second interface
|
||||||
// validate for the second interface
|
|
||||||
if (detector_shm()->numUDPInterfaces == 2) {
|
if (detector_shm()->numUDPInterfaces == 2) {
|
||||||
// copy from udpip (done here as well if udpconnection avoided (no slsrxr)
|
if (detector_shm()->receiverUDPIP2 == 0) {
|
||||||
if (!strcmp(detector_shm()->receiverUDPIP2, "none")) {
|
detector_shm()->receiverUDPIP2 = detector_shm()->receiverUDPIP;
|
||||||
sls::strcpy_safe(detector_shm()->receiverUDPIP2, detector_shm()->receiverUDPIP);
|
|
||||||
}
|
}
|
||||||
// rx_udpmac2 (udpip2 will be copied from udpip if empty)
|
if (detector_shm()->receiverUDPMAC2 == 0) {
|
||||||
if (!strcmp(detector_shm()->receiverUDPMAC2, "none")) {
|
|
||||||
throw RuntimeError("configureMAC: Error. Receiver UDP MAC Addresses 2 not set");
|
throw RuntimeError("configureMAC: Error. Receiver UDP MAC Addresses 2 not set");
|
||||||
}
|
}
|
||||||
FILE_LOG(logDEBUG1) << "rx_udpmac2 are valid ";
|
FILE_LOG(logDEBUG1) << "rx_udpmac2 is valid ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// copy to args and convert to hex
|
||||||
// copy to args
|
|
||||||
snprintf(args[0], array_size, "%x", detector_shm()->receiverUDPPort);
|
snprintf(args[0], array_size, "%x", detector_shm()->receiverUDPPort);
|
||||||
sls::strcpy_safe(args[1], detector_shm()->receiverUDPIP);
|
sls::strcpy_safe(args[1], getReceiverUDPIP().hex());
|
||||||
sls::strcpy_safe(args[2], detector_shm()->receiverUDPMAC);
|
sls::strcpy_safe(args[2], getReceiverUDPMAC().hex());
|
||||||
sls::strcpy_safe(args[3], detector_shm()->detectorIP);
|
sls::strcpy_safe(args[3], getDetectorIP().hex());
|
||||||
sls::strcpy_safe(args[4], detector_shm()->detectorMAC);
|
sls::strcpy_safe(args[4], getDetectorMAC().hex());
|
||||||
|
|
||||||
snprintf(args[5], array_size, "%x", detector_shm()->receiverUDPPort2);
|
snprintf(args[5], array_size, "%x", detector_shm()->receiverUDPPort2);
|
||||||
sls::strcpy_safe(args[6], detector_shm()->receiverUDPIP2);
|
sls::strcpy_safe(args[6], getReceiverUDPIP2().hex());
|
||||||
sls::strcpy_safe(args[7], detector_shm()->receiverUDPMAC2);
|
sls::strcpy_safe(args[7], getReceiverUDPMAC2().hex());
|
||||||
sls::strcpy_safe(args[8], detector_shm()->detectorIP2);
|
sls::strcpy_safe(args[8], getDetectorIP2().hex());
|
||||||
sls::strcpy_safe(args[9], detector_shm()->detectorMAC2);
|
sls::strcpy_safe(args[9], getDetectorMAC2().hex());
|
||||||
|
|
||||||
// number of interfaces and which one
|
|
||||||
snprintf(args[10], array_size, "%x", detector_shm()->numUDPInterfaces);
|
snprintf(args[10], array_size, "%x", detector_shm()->numUDPInterfaces);
|
||||||
snprintf(args[11], array_size, "%x", detector_shm()->selectedUDPInterface);
|
snprintf(args[11], array_size, "%x", detector_shm()->selectedUDPInterface);
|
||||||
|
|
||||||
@ -1643,80 +1625,40 @@ int slsDetector::configureMAC() {
|
|||||||
snprintf(args[13], array_size, "%x", pos[1]);
|
snprintf(args[13], array_size, "%x", pos[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FILE_LOG(logDEBUG1) << "receiver udp port:" << std::dec << args[0] << "-";
|
FILE_LOG(logDEBUG1) << "receiver udp port:" << std::dec << args[0] << "-";
|
||||||
// converting receiverUDPIP to string hex
|
|
||||||
sls::strcpy_safe(args[1], sls::stringIpToHex(args[1]).c_str());
|
|
||||||
FILE_LOG(logDEBUG1) << "receiver udp ip:" << args[1] << "-";
|
FILE_LOG(logDEBUG1) << "receiver udp ip:" << args[1] << "-";
|
||||||
// MAC already in hex removing :
|
|
||||||
sls::removeChar(args[2], ':');
|
|
||||||
FILE_LOG(logDEBUG1) << "receiver udp mac:" << args[2] << "-";
|
FILE_LOG(logDEBUG1) << "receiver udp mac:" << args[2] << "-";
|
||||||
// converting detectorIP to string hex
|
|
||||||
sls::strcpy_safe(args[3], sls::stringIpToHex(args[3]).c_str());
|
|
||||||
FILE_LOG(logDEBUG1) << "detecotor udp ip:" << args[3] << "-";
|
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) << "detector udp mac:" << args[4] << "-";
|
||||||
|
|
||||||
|
|
||||||
FILE_LOG(logDEBUG1) << "receiver udp port2:" << std::dec << args[5] << "-";
|
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] << "-";
|
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] << "-";
|
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] << "-";
|
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) << "detector udp mac2:" << args[9] << "-";
|
||||||
|
|
||||||
|
|
||||||
FILE_LOG(logDEBUG1) << "number of udp interfaces:" << std::dec << args[10] << "-";
|
FILE_LOG(logDEBUG1) << "number of udp interfaces:" << std::dec << args[10] << "-";
|
||||||
FILE_LOG(logDEBUG1) << "selected udp interface:" << std::dec << args[11] << "-";
|
FILE_LOG(logDEBUG1) << "selected udp interface:" << std::dec << args[11] << "-";
|
||||||
|
|
||||||
FILE_LOG(logDEBUG1) << "row:" << args[12] << "-";
|
FILE_LOG(logDEBUG1) << "row:" << args[12] << "-";
|
||||||
FILE_LOG(logDEBUG1) << "col:" << args[13] << "-";
|
FILE_LOG(logDEBUG1) << "col:" << args[13] << "-";
|
||||||
|
|
||||||
|
|
||||||
// send to server
|
// send to server
|
||||||
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
||||||
auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort);
|
auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort);
|
||||||
ret = client.sendCommandThenRead(fnum, args, sizeof(args), retvals, sizeof(retvals));
|
ret = client.sendCommandThenRead(fnum, args, sizeof(args), retvals, sizeof(retvals));
|
||||||
// get detectormac, detector ip
|
|
||||||
uint64_t idetectormac = 0;
|
uint64_t detector_mac = 0;
|
||||||
uint32_t idetectorip = 0;
|
uint32_t detector_ip = 0;
|
||||||
sscanf(retvals[0], "%lx", &idetectormac);
|
sscanf(retvals[0], "%lx", &detector_mac); // TODO! (Erik) send mac and ip as int
|
||||||
sscanf(retvals[1], "%x", &idetectorip);
|
sscanf(retvals[1], "%x", &detector_ip);
|
||||||
snprintf(retvals[0], sizeof(retvals[0]), "%02x:%02x:%02x:%02x:%02x:%02x",
|
detector_ip = __builtin_bswap32(detector_ip);
|
||||||
(unsigned int)((idetectormac >> 40) & 0xFF),
|
|
||||||
(unsigned int)((idetectormac >> 32) & 0xFF),
|
if (detector_shm()->detectorMAC != detector_mac) {
|
||||||
(unsigned int)((idetectormac >> 24) & 0xFF),
|
detector_shm()->detectorMAC = detector_mac;
|
||||||
(unsigned int)((idetectormac >> 16) & 0xFF),
|
FILE_LOG(logINFO) << detId << ": Detector MAC updated to " << getDetectorMAC();
|
||||||
(unsigned int)((idetectormac >> 8) & 0xFF),
|
|
||||||
(unsigned int)((idetectormac >> 0) & 0xFF));
|
|
||||||
snprintf(retvals[1], sizeof(retvals[1]), "%d.%d.%d.%d", (idetectorip >> 24) & 0xff,
|
|
||||||
(idetectorip >> 16) & 0xff, (idetectorip >> 8) & 0xff, (idetectorip)&0xff);
|
|
||||||
// update if different
|
|
||||||
if (strcasecmp(retvals[0], detector_shm()->detectorMAC)) {
|
|
||||||
// memset(detector_shm()->detectorMAC, 0, MAX_STR_LENGTH);
|
|
||||||
sls::strcpy_safe(detector_shm()->detectorMAC, retvals[0]);
|
|
||||||
FILE_LOG(logINFO) << detId << ": Detector MAC updated to "
|
|
||||||
<< detector_shm()->detectorMAC;
|
|
||||||
}
|
}
|
||||||
if (strcasecmp(retvals[1], detector_shm()->detectorIP)) {
|
|
||||||
// memset(detector_shm()->detectorIP, 0, MAX_STR_LENGTH);
|
if (detector_shm()->detectorIP != detector_ip) {
|
||||||
sls::strcpy_safe(detector_shm()->detectorIP, retvals[1]);
|
detector_shm()->detectorIP = detector_ip;
|
||||||
FILE_LOG(logINFO) << detId << ": Detector IP updated to " << detector_shm()->detectorIP;
|
FILE_LOG(logINFO) << detId << ": Detector IP updated to " << getDetectorIP();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ret == FORCE_UPDATE) {
|
if (ret == FORCE_UPDATE) {
|
||||||
@ -1748,7 +1690,8 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t) {
|
|||||||
ret = client.sendCommandThenRead(fnum, args, sizeof(args), &retval, sizeof(retval));
|
ret = client.sendCommandThenRead(fnum, args, sizeof(args), &retval, sizeof(retval));
|
||||||
FILE_LOG(logDEBUG1) << getTimerType(index) << ": " << retval;
|
FILE_LOG(logDEBUG1) << getTimerType(index) << ": " << retval;
|
||||||
detector_shm()->timerValue[index] = retval;
|
detector_shm()->timerValue[index] = retval;
|
||||||
// update #nchans and databytes, as it depends on #samples, roi, readoutflags (ctb only)
|
// update #nchans and databytes, as it depends on #samples, roi,
|
||||||
|
// readoutflags (ctb only)
|
||||||
if (index == SAMPLES && (detector_shm()->myDetectorType == CHIPTESTBOARD ||
|
if (index == SAMPLES && (detector_shm()->myDetectorType == CHIPTESTBOARD ||
|
||||||
detector_shm()->myDetectorType == MOENCH)) {
|
detector_shm()->myDetectorType == MOENCH)) {
|
||||||
updateTotalNumberOfChannels();
|
updateTotalNumberOfChannels();
|
||||||
@ -2002,7 +1945,8 @@ int slsDetector::setReadOutFlags(readOutFlags flag) {
|
|||||||
ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval, sizeof(retval));
|
ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval, sizeof(retval));
|
||||||
FILE_LOG(logDEBUG1) << "Readout flag: " << retval;
|
FILE_LOG(logDEBUG1) << "Readout flag: " << retval;
|
||||||
detector_shm()->roFlags = (readOutFlags)retval;
|
detector_shm()->roFlags = (readOutFlags)retval;
|
||||||
// update #nchans and databytes, as it depends on #samples, roi, readoutflags (ctb only)
|
// update #nchans and databytes, as it depends on #samples, roi,
|
||||||
|
// readoutflags (ctb only)
|
||||||
if (detector_shm()->myDetectorType == CHIPTESTBOARD) {
|
if (detector_shm()->myDetectorType == CHIPTESTBOARD) {
|
||||||
updateTotalNumberOfChannels();
|
updateTotalNumberOfChannels();
|
||||||
}
|
}
|
||||||
@ -2091,94 +2035,71 @@ uint32_t slsDetector::clearBit(uint32_t addr, int n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string slsDetector::setDetectorMAC(const std::string &detectorMAC) {
|
std::string slsDetector::setDetectorMAC(const std::string &detectorMAC) {
|
||||||
// invalid format
|
auto addr = MacAddr(detectorMAC);
|
||||||
if ((detectorMAC.length() != 17) || (detectorMAC[2] != ':') || (detectorMAC[5] != ':') ||
|
if (addr == 0) {
|
||||||
(detectorMAC[8] != ':') || (detectorMAC[11] != ':') || (detectorMAC[14] != ':')) {
|
|
||||||
throw RuntimeError("server MAC Address should be in xx:xx:xx:xx:xx:xx format");
|
throw RuntimeError("server MAC Address should be in xx:xx:xx:xx:xx:xx format");
|
||||||
}
|
}
|
||||||
// valid format
|
detector_shm()->detectorMAC = addr;
|
||||||
else {
|
|
||||||
sls::strcpy_safe(detector_shm()->detectorMAC, detectorMAC.c_str());
|
|
||||||
if (!strcmp(detector_shm()->receiver_hostname, "none")) {
|
if (!strcmp(detector_shm()->receiver_hostname, "none")) {
|
||||||
FILE_LOG(logDEBUG1) << "Receiver hostname not set yet";
|
FILE_LOG(logDEBUG1) << "Receiver hostname not set yet";
|
||||||
} else if (setUDPConnection() == FAIL) {
|
} else if (setUDPConnection() == FAIL) {
|
||||||
FILE_LOG(logWARNING) << "UDP connection set up failed";
|
FILE_LOG(logWARNING) << "UDP connection set up failed";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return std::string(detector_shm()->detectorMAC);
|
return getDetectorMAC().str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string slsDetector::getDetectorMAC() {
|
MacAddr slsDetector::getDetectorMAC() { return detector_shm()->detectorMAC; }
|
||||||
return std::string(detector_shm()->detectorMAC);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string slsDetector::setDetectorMAC2(const std::string &detectorMAC) {
|
std::string slsDetector::setDetectorMAC2(const std::string &detectorMAC) {
|
||||||
// invalid format
|
auto addr = MacAddr(detectorMAC);
|
||||||
if ((detectorMAC.length() != 17) || (detectorMAC[2] != ':') || (detectorMAC[5] != ':') ||
|
if (addr == 0) {
|
||||||
(detectorMAC[8] != ':') || (detectorMAC[11] != ':') || (detectorMAC[14] != ':')) {
|
|
||||||
throw RuntimeError("server MAC Address 2 should be in xx:xx:xx:xx:xx:xx format");
|
throw RuntimeError("server MAC Address 2 should be in xx:xx:xx:xx:xx:xx format");
|
||||||
}
|
}
|
||||||
// valid format
|
detector_shm()->detectorMAC2 = addr;
|
||||||
else {
|
|
||||||
sls::strcpy_safe(detector_shm()->detectorMAC2, detectorMAC.c_str());
|
|
||||||
if (!strcmp(detector_shm()->receiver_hostname, "none")) {
|
if (!strcmp(detector_shm()->receiver_hostname, "none")) {
|
||||||
FILE_LOG(logDEBUG1) << "Receiver hostname not set yet";
|
FILE_LOG(logDEBUG1) << "Receiver hostname not set yet";
|
||||||
} else if (setUDPConnection() == FAIL) {
|
} else if (setUDPConnection() == FAIL) {
|
||||||
FILE_LOG(logWARNING) << "UDP connection set up failed";
|
FILE_LOG(logWARNING) << "UDP connection set up failed";
|
||||||
}
|
}
|
||||||
}
|
return getDetectorMAC2().str();
|
||||||
return std::string(detector_shm()->detectorMAC2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string slsDetector::getDetectorMAC2() {
|
MacAddr slsDetector::getDetectorMAC2() { return detector_shm()->detectorMAC2; }
|
||||||
return std::string(detector_shm()->detectorMAC2);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string slsDetector::setDetectorIP(const std::string &detectorIP) {
|
std::string slsDetector::setDetectorIP(const std::string &ip) {
|
||||||
struct sockaddr_in sa;
|
auto addr = IpAddr(ip);
|
||||||
if (detectorIP.length() && detectorIP.length() < 16) {
|
if (addr == 0) {
|
||||||
int result = inet_pton(AF_INET, detectorIP.c_str(), &(sa.sin_addr));
|
throw RuntimeError("setDetectorIP: IP Address should be VALID and "
|
||||||
if (result == 0) {
|
"in xxx.xxx.xxx.xxx format");
|
||||||
throw RuntimeError(
|
}
|
||||||
"setDetectorIP: IP Address should be VALID and in xxx.xxx.xxx.xxx format");
|
detector_shm()->detectorIP = ip;
|
||||||
} else {
|
|
||||||
sls::strcpy_safe(detector_shm()->detectorIP, detectorIP.c_str());
|
|
||||||
if (!strcmp(detector_shm()->receiver_hostname, "none")) {
|
if (!strcmp(detector_shm()->receiver_hostname, "none")) {
|
||||||
FILE_LOG(logDEBUG1) << "Receiver hostname not set yet";
|
FILE_LOG(logDEBUG1) << "Receiver hostname not set yet";
|
||||||
} else if (setUDPConnection() == FAIL) {
|
} else if (setUDPConnection() == FAIL) {
|
||||||
FILE_LOG(logWARNING) << "UDP connection set up failed";
|
FILE_LOG(logWARNING) << "UDP connection set up failed";
|
||||||
}
|
}
|
||||||
}
|
return getDetectorIP().str();
|
||||||
}
|
|
||||||
return std::string(detector_shm()->detectorIP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string slsDetector::getDetectorIP() const {
|
IpAddr slsDetector::getDetectorIP() const { return detector_shm()->detectorIP; }
|
||||||
return std::string(detector_shm()->detectorIP);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string slsDetector::setDetectorIP2(const std::string &detectorIP) {
|
std::string slsDetector::setDetectorIP2(const std::string &ip) {
|
||||||
struct sockaddr_in sa;
|
auto addr = IpAddr(ip);
|
||||||
if (detectorIP.length() && detectorIP.length() < 16) {
|
if (addr == 0) {
|
||||||
int result = inet_pton(AF_INET, detectorIP.c_str(), &(sa.sin_addr));
|
throw RuntimeError("setDetectorIP: IP2 Address should be VALID and "
|
||||||
if (result == 0) {
|
"in xxx.xxx.xxx.xxx format");
|
||||||
throw RuntimeError(
|
}
|
||||||
"setDetectorIP: IP Address 2 should be VALID and in xxx.xxx.xxx.xxx format");
|
detector_shm()->detectorIP2 = ip;
|
||||||
} else {
|
|
||||||
sls::strcpy_safe(detector_shm()->detectorIP2, detectorIP.c_str());
|
|
||||||
if (!strcmp(detector_shm()->receiver_hostname, "none")) {
|
if (!strcmp(detector_shm()->receiver_hostname, "none")) {
|
||||||
FILE_LOG(logDEBUG1) << "Receiver hostname not set yet";
|
FILE_LOG(logDEBUG1) << "Receiver hostname not set yet";
|
||||||
} else if (setUDPConnection() == FAIL) {
|
} else if (setUDPConnection() == FAIL) {
|
||||||
FILE_LOG(logWARNING) << "UDP connection set up failed";
|
FILE_LOG(logWARNING) << "UDP connection set up failed";
|
||||||
}
|
}
|
||||||
}
|
return getDetectorIP().str();
|
||||||
}
|
|
||||||
return std::string(detector_shm()->detectorIP2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string slsDetector::getDetectorIP2() const {
|
IpAddr slsDetector::getDetectorIP2() const { return detector_shm()->detectorIP2; }
|
||||||
return std::string(detector_shm()->detectorIP2);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string slsDetector::setReceiverHostname(const std::string &receiverIP) {
|
std::string slsDetector::setReceiverHostname(const std::string &receiverIP) {
|
||||||
FILE_LOG(logDEBUG1) << "Setting up Receiver with " << receiverIP;
|
FILE_LOG(logDEBUG1) << "Setting up Receiver with " << receiverIP;
|
||||||
@ -2307,96 +2228,60 @@ std::string slsDetector::getReceiverHostname() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string slsDetector::setReceiverUDPIP(const std::string &udpip) {
|
std::string slsDetector::setReceiverUDPIP(const std::string &udpip) {
|
||||||
struct sockaddr_in sa;
|
auto ip = IpAddr(udpip);
|
||||||
if (udpip.length() && udpip.length() < 16) {
|
if (ip == 0) {
|
||||||
int result = inet_pton(AF_INET, udpip.c_str(), &(sa.sin_addr));
|
throw ReceiverError("setReceiverUDPIP: UDP IP Address should be "
|
||||||
if (result == 0) {
|
"VALID and in xxx.xxx.xxx.xxx format");
|
||||||
throw ReceiverError(
|
}
|
||||||
"setReceiverUDPIP: UDP IP Address should be VALID and in xxx.xxx.xxx.xxx format");
|
detector_shm()->receiverUDPIP = ip;
|
||||||
} else {
|
|
||||||
sls::strcpy_safe(detector_shm()->receiverUDPIP, udpip.c_str());
|
|
||||||
if (!strcmp(detector_shm()->receiver_hostname, "none")) {
|
if (!strcmp(detector_shm()->receiver_hostname, "none")) {
|
||||||
FILE_LOG(logDEBUG1) << "Receiver hostname not set yet";
|
FILE_LOG(logDEBUG1) << "Receiver hostname not set yet";
|
||||||
} else if (setUDPConnection() == FAIL) {
|
} else if (setUDPConnection() == FAIL) {
|
||||||
FILE_LOG(logWARNING) << "UDP connection set up failed";
|
FILE_LOG(logWARNING) << "UDP connection set up failed";
|
||||||
}
|
}
|
||||||
}
|
return getReceiverUDPIP().str();
|
||||||
}
|
|
||||||
return std::string(detector_shm()->receiverUDPIP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string slsDetector::getReceiverUDPIP() const {
|
sls::IpAddr slsDetector::getReceiverUDPIP() const { return detector_shm()->receiverUDPIP; }
|
||||||
return std::string(detector_shm()->receiverUDPIP);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string slsDetector::setReceiverUDPIP2(const std::string &udpip) {
|
std::string slsDetector::setReceiverUDPIP2(const std::string &udpip) {
|
||||||
struct sockaddr_in sa;
|
auto ip = IpAddr(udpip);
|
||||||
if (udpip.length() && udpip.length() < 16) {
|
if (ip == 0) {
|
||||||
int result = inet_pton(AF_INET, udpip.c_str(), &(sa.sin_addr));
|
throw ReceiverError("setReceiverUDPIP: UDP IP Address 2 should be "
|
||||||
if (result == 0) {
|
"VALID and in xxx.xxx.xxx.xxx format");
|
||||||
throw ReceiverError(
|
}
|
||||||
"setReceiverUDPIP: UDP IP Address 2 should be VALID and in xxx.xxx.xxx.xxx format");
|
detector_shm()->receiverUDPIP2 = ip;
|
||||||
} else {
|
|
||||||
sls::strcpy_safe(detector_shm()->receiverUDPIP2, udpip.c_str());
|
|
||||||
if (!strcmp(detector_shm()->receiver_hostname, "none")) {
|
if (!strcmp(detector_shm()->receiver_hostname, "none")) {
|
||||||
FILE_LOG(logDEBUG1) << "Receiver hostname not set yet";
|
FILE_LOG(logDEBUG1) << "Receiver hostname not set yet";
|
||||||
} else if (setUDPConnection() == FAIL) {
|
} else if (setUDPConnection() == FAIL) {
|
||||||
FILE_LOG(logWARNING) << "UDP connection set up failed";
|
FILE_LOG(logWARNING) << "UDP connection set up failed";
|
||||||
}
|
}
|
||||||
}
|
return getReceiverUDPIP2().str();
|
||||||
}
|
|
||||||
return std::string(detector_shm()->receiverUDPIP2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string slsDetector::getReceiverUDPIP2() const {
|
sls::IpAddr slsDetector::getReceiverUDPIP2() const { return detector_shm()->receiverUDPIP2; }
|
||||||
return std::string(detector_shm()->receiverUDPIP2);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string slsDetector::setReceiverUDPMAC(const std::string &udpmac) {
|
std::string slsDetector::setReceiverUDPMAC(const std::string &udpmac) {
|
||||||
// invalid format
|
auto mac = MacAddr(udpmac);
|
||||||
if ((udpmac.length() != 17) || (udpmac[2] != ':') || (udpmac[5] != ':') || (udpmac[8] != ':') ||
|
if (mac == 0) {
|
||||||
(udpmac[11] != ':') || (udpmac[14] != ':')) {
|
throw ReceiverError("Could not decode UDPMAC from: " + udpmac);
|
||||||
throw ReceiverError(
|
|
||||||
"setReceiverUDPMAC: udp MAC Address should be in xx:xx:xx:xx:xx:xx format");
|
|
||||||
}
|
}
|
||||||
// valid format
|
detector_shm()->receiverUDPMAC = mac;
|
||||||
else {
|
return getReceiverUDPMAC().str();
|
||||||
sls::strcpy_safe(detector_shm()->receiverUDPMAC, 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()->receiverUDPMAC, udpmac.c_str());
|
|
||||||
}
|
|
||||||
return std::string(detector_shm()->receiverUDPMAC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string slsDetector::getReceiverUDPMAC() const {
|
MacAddr slsDetector::getReceiverUDPMAC() const { return detector_shm()->receiverUDPMAC; }
|
||||||
return std::string(detector_shm()->receiverUDPMAC);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string slsDetector::setReceiverUDPMAC2(const std::string &udpmac) {
|
std::string slsDetector::setReceiverUDPMAC2(const std::string &udpmac) {
|
||||||
// invalid format
|
auto mac = MacAddr(udpmac);
|
||||||
if ((udpmac.length() != 17) || (udpmac[2] != ':') || (udpmac[5] != ':') || (udpmac[8] != ':') ||
|
if (mac == 0) {
|
||||||
(udpmac[11] != ':') || (udpmac[14] != ':')) {
|
throw ReceiverError("Could not decode UDPMA2C from: " + udpmac);
|
||||||
throw ReceiverError(
|
|
||||||
"setReceiverUDPMAC: udp MAC Address 2 should be in xx:xx:xx:xx:xx:xx format");
|
|
||||||
}
|
}
|
||||||
// valid format
|
detector_shm()->receiverUDPMAC2 = mac;
|
||||||
else {
|
return getReceiverUDPMAC2().str();
|
||||||
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 {
|
MacAddr slsDetector::getReceiverUDPMAC2() const { return detector_shm()->receiverUDPMAC2; }
|
||||||
return std::string(detector_shm()->receiverUDPMAC2);
|
|
||||||
}
|
|
||||||
|
|
||||||
int slsDetector::setReceiverUDPPort(int udpport) {
|
int slsDetector::setReceiverUDPPort(int udpport) {
|
||||||
detector_shm()->receiverUDPPort = udpport;
|
detector_shm()->receiverUDPPort = udpport;
|
||||||
@ -2408,9 +2293,7 @@ int slsDetector::setReceiverUDPPort(int udpport) {
|
|||||||
return detector_shm()->receiverUDPPort;
|
return detector_shm()->receiverUDPPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
int slsDetector::getReceiverUDPPort() const {
|
int slsDetector::getReceiverUDPPort() const { return detector_shm()->receiverUDPPort; }
|
||||||
return detector_shm()->receiverUDPPort;
|
|
||||||
}
|
|
||||||
|
|
||||||
int slsDetector::setReceiverUDPPort2(int udpport) {
|
int slsDetector::setReceiverUDPPort2(int udpport) {
|
||||||
detector_shm()->receiverUDPPort2 = udpport;
|
detector_shm()->receiverUDPPort2 = udpport;
|
||||||
@ -2422,9 +2305,7 @@ int slsDetector::setReceiverUDPPort2(int udpport) {
|
|||||||
return detector_shm()->receiverUDPPort2;
|
return detector_shm()->receiverUDPPort2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int slsDetector::getReceiverUDPPort2() const {
|
int slsDetector::getReceiverUDPPort2() const { return detector_shm()->receiverUDPPort2; }
|
||||||
return detector_shm()->receiverUDPPort2;
|
|
||||||
}
|
|
||||||
|
|
||||||
int slsDetector::setNumberofUDPInterfaces(int n) {
|
int slsDetector::setNumberofUDPInterfaces(int n) {
|
||||||
if (detector_shm()->myDetectorType != JUNGFRAU) {
|
if (detector_shm()->myDetectorType != JUNGFRAU) {
|
||||||
@ -2439,9 +2320,7 @@ int slsDetector::setNumberofUDPInterfaces(int n) {
|
|||||||
return detector_shm()->numUDPInterfaces;
|
return detector_shm()->numUDPInterfaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
int slsDetector::getNumberofUDPInterfaces() const {
|
int slsDetector::getNumberofUDPInterfaces() const { return detector_shm()->numUDPInterfaces; }
|
||||||
return detector_shm()->numUDPInterfaces;
|
|
||||||
}
|
|
||||||
|
|
||||||
int slsDetector::selectUDPInterface(int n) {
|
int slsDetector::selectUDPInterface(int n) {
|
||||||
if (detector_shm()->myDetectorType != JUNGFRAU) {
|
if (detector_shm()->myDetectorType != JUNGFRAU) {
|
||||||
@ -2456,9 +2335,7 @@ int slsDetector::selectUDPInterface(int n) {
|
|||||||
return detector_shm()->selectedUDPInterface;
|
return detector_shm()->selectedUDPInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
int slsDetector::getSelectedUDPInterface() const {
|
int slsDetector::getSelectedUDPInterface() const { return detector_shm()->selectedUDPInterface; }
|
||||||
return detector_shm()->selectedUDPInterface;
|
|
||||||
}
|
|
||||||
|
|
||||||
void slsDetector::setClientStreamingPort(int port) { detector_shm()->zmqport = port; }
|
void slsDetector::setClientStreamingPort(int port) { detector_shm()->zmqport = port; }
|
||||||
|
|
||||||
@ -2511,7 +2388,8 @@ void slsDetector::setReceiverStreamingIP(std::string sourceIP) {
|
|||||||
// if empty, give rx_hostname
|
// if empty, give rx_hostname
|
||||||
if (sourceIP.empty()) {
|
if (sourceIP.empty()) {
|
||||||
if (!strcmp(detector_shm()->receiver_hostname, "none")) {
|
if (!strcmp(detector_shm()->receiver_hostname, "none")) {
|
||||||
throw RuntimeError("Receiver hostname not set yet. Cannot create rx_zmqip from none");
|
throw RuntimeError("Receiver hostname not set yet. Cannot create "
|
||||||
|
"rx_zmqip from none");
|
||||||
}
|
}
|
||||||
sourceIP.assign(detector_shm()->receiver_hostname);
|
sourceIP.assign(detector_shm()->receiver_hostname);
|
||||||
}
|
}
|
||||||
@ -2621,18 +2499,20 @@ std::string slsDetector::setAdditionalJsonParameter(const std::string &key,
|
|||||||
const std::string &value) {
|
const std::string &value) {
|
||||||
// validation (value or key is empty)
|
// validation (value or key is empty)
|
||||||
if (!key.length() || !value.length()) {
|
if (!key.length() || !value.length()) {
|
||||||
throw("Could not set additional json header parameter as the key or value is empty");
|
throw("Could not set additional json header parameter as the key or "
|
||||||
|
"value is empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
// validation (ignore if key or value has , : ")
|
// validation (ignore if key or value has , : ")
|
||||||
if (key.find_first_of(",\":") != std::string::npos ||
|
if (key.find_first_of(",\":") != std::string::npos ||
|
||||||
value.find_first_of(",\":") != std::string::npos) {
|
value.find_first_of(",\":") != std::string::npos) {
|
||||||
throw RuntimeError("Could not set additional json header parameter as the key or value has "
|
throw RuntimeError("Could not set additional json header parameter as "
|
||||||
|
"the key or value has "
|
||||||
"illegal characters (,\":)");
|
"illegal characters (,\":)");
|
||||||
}
|
}
|
||||||
|
|
||||||
// create actual key to search for and actual value to put, (key has additional ':' as value
|
// create actual key to search for and actual value to put, (key has
|
||||||
// could exist the same way)
|
// additional ':' as value could exist the same way)
|
||||||
std::string keyLiteral(std::string("\"") + key + std::string("\":"));
|
std::string keyLiteral(std::string("\"") + key + std::string("\":"));
|
||||||
std::string valueLiteral(value);
|
std::string valueLiteral(value);
|
||||||
// add quotations to value only if it is a string
|
// add quotations to value only if it is a string
|
||||||
@ -2651,7 +2531,8 @@ std::string slsDetector::setAdditionalJsonParameter(const std::string &key,
|
|||||||
if (keyPos != std::string::npos) {
|
if (keyPos != std::string::npos) {
|
||||||
size_t valueStartPos = header.find(std::string(":"), keyPos) + 1;
|
size_t valueStartPos = header.find(std::string(":"), keyPos) + 1;
|
||||||
size_t valueEndPos = header.find(std::string(","), valueStartPos) - 1;
|
size_t valueEndPos = header.find(std::string(","), valueStartPos) - 1;
|
||||||
// if valueEndPos doesnt find comma (end of string), it goes anyway to end of line
|
// if valueEndPos doesnt find comma (end of string), it goes anyway to
|
||||||
|
// end of line
|
||||||
header.replace(valueStartPos, valueEndPos - valueStartPos + 1, valueLiteral);
|
header.replace(valueStartPos, valueEndPos - valueStartPos + 1, valueLiteral);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2747,45 +2628,31 @@ int slsDetector::setUDPConnection() {
|
|||||||
FILE_LOG(logDEBUG1) << "Receiver hostname not set yet.";
|
FILE_LOG(logDEBUG1) << "Receiver hostname not set yet.";
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
// if no udp ip given, use hostname
|
|
||||||
if (!strcmp(detector_shm()->receiverUDPIP, "none")) {
|
|
||||||
// hostname is an ip address
|
|
||||||
if (strchr(detector_shm()->receiver_hostname, '.') != nullptr) {
|
|
||||||
sls::strcpy_safe(detector_shm()->receiverUDPIP, detector_shm()->receiver_hostname);
|
|
||||||
// if hostname not ip, convert it to ip
|
|
||||||
} else {
|
|
||||||
struct addrinfo *result;
|
|
||||||
if (sls::ConvertHostnameToInternetAddress(detector_shm()->receiver_hostname, &result) ==
|
|
||||||
0) {
|
|
||||||
// on success
|
|
||||||
memset(detector_shm()->receiverUDPIP, 0, MAX_STR_LENGTH);
|
|
||||||
// on failure, back to none
|
|
||||||
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()->receiverUDPIP == 0) {
|
||||||
|
// Hostname could be ip try to decode otherwise look up the hostname
|
||||||
|
detector_shm()->receiverUDPIP = detector_shm()->receiver_hostname;
|
||||||
|
if (detector_shm()->receiverUDPIP == 0) {
|
||||||
|
detector_shm()->receiverUDPIP = HostnameToIp(detector_shm()->receiver_hostname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// jungfrau 2 interfaces or (1 interface and 2nd interface), copy udpip if
|
||||||
|
// udpip2 empty
|
||||||
if (detector_shm()->numUDPInterfaces == 2 || detector_shm()->selectedUDPInterface == 2) {
|
if (detector_shm()->numUDPInterfaces == 2 || detector_shm()->selectedUDPInterface == 2) {
|
||||||
// copy from udpip
|
if (detector_shm()->receiverUDPIP2 == 0) {
|
||||||
if (!strcmp(detector_shm()->receiverUDPIP2, "none")) {
|
detector_shm()->receiverUDPIP2 = detector_shm()->receiverUDPIP;
|
||||||
sls::strcpy_safe(detector_shm()->receiverUDPIP2, detector_shm()->receiverUDPIP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy arguments to args[][]
|
// copy arguments to args[][]
|
||||||
snprintf(args[0], sizeof(args[0]), "%d", detector_shm()->numUDPInterfaces);
|
snprintf(args[0], sizeof(args[0]), "%d", detector_shm()->numUDPInterfaces);
|
||||||
snprintf(args[1], sizeof(args[1]), "%d", detector_shm()->selectedUDPInterface);
|
snprintf(args[1], sizeof(args[1]), "%d", detector_shm()->selectedUDPInterface);
|
||||||
sls::strcpy_safe(args[2], detector_shm()->receiverUDPIP);
|
sls::strcpy_safe(args[2], getReceiverUDPIP().str());
|
||||||
sls::strcpy_safe(args[3], detector_shm()->receiverUDPIP2);
|
sls::strcpy_safe(args[3], getReceiverUDPIP2().str());
|
||||||
snprintf(args[4], sizeof(args[4]), "%d", detector_shm()->receiverUDPPort);
|
snprintf(args[4], sizeof(args[4]), "%d", detector_shm()->receiverUDPPort);
|
||||||
snprintf(args[5], sizeof(args[5]), "%d", detector_shm()->receiverUDPPort2);
|
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 Number of UDP Interfaces: "
|
||||||
|
<< detector_shm()->numUDPInterfaces;
|
||||||
FILE_LOG(logDEBUG1) << "Receiver Selected Interface: " << detector_shm()->selectedUDPInterface;
|
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 address: " << detector_shm()->receiverUDPIP;
|
||||||
FILE_LOG(logDEBUG1) << "Receiver udp ip address2: " << detector_shm()->receiverUDPIP2;
|
FILE_LOG(logDEBUG1) << "Receiver udp ip address2: " << detector_shm()->receiverUDPIP2;
|
||||||
@ -2798,13 +2665,11 @@ int slsDetector::setUDPConnection() {
|
|||||||
ret = receiver.sendCommandThenRead(fnum, args, sizeof(args), retvals, sizeof(retvals));
|
ret = receiver.sendCommandThenRead(fnum, args, sizeof(args), retvals, sizeof(retvals));
|
||||||
if (strlen(retvals[0])) {
|
if (strlen(retvals[0])) {
|
||||||
FILE_LOG(logDEBUG1) << "Receiver UDP MAC returned : " << retvals[0];
|
FILE_LOG(logDEBUG1) << "Receiver UDP MAC returned : " << retvals[0];
|
||||||
memset(detector_shm()->receiverUDPMAC, 0, MAX_STR_LENGTH);
|
detector_shm()->receiverUDPMAC = retvals[0];
|
||||||
sls::strcpy_safe(detector_shm()->receiverUDPMAC, retvals[0]);
|
|
||||||
}
|
}
|
||||||
if (strlen(retvals[1])) {
|
if (strlen(retvals[1])) {
|
||||||
FILE_LOG(logDEBUG1) << "Receiver UDP MAC2 returned : " << retvals[1];
|
FILE_LOG(logDEBUG1) << "Receiver UDP MAC2 returned : " << retvals[1];
|
||||||
memset(detector_shm()->receiverUDPMAC2, 0, MAX_STR_LENGTH);
|
detector_shm()->receiverUDPMAC2 = retvals[1];
|
||||||
sls::strcpy_safe(detector_shm()->receiverUDPMAC2, retvals[1]);
|
|
||||||
}
|
}
|
||||||
if (ret == FORCE_UPDATE) {
|
if (ret == FORCE_UPDATE) {
|
||||||
receiver.close();
|
receiver.close();
|
||||||
@ -2982,7 +2847,8 @@ int slsDetector::setROI(int n, ROI roiLimits[]) {
|
|||||||
if (detector_shm()->myDetectorType == MOENCH) {
|
if (detector_shm()->myDetectorType == MOENCH) {
|
||||||
sendROIToProcessor();
|
sendROIToProcessor();
|
||||||
}
|
}
|
||||||
// update #nchans and databytes, as it depends on #samples, roi, readoutflags (ctb only)
|
// update #nchans and databytes, as it depends on #samples, roi,
|
||||||
|
// readoutflags (ctb only)
|
||||||
if (detector_shm()->myDetectorType == CHIPTESTBOARD ||
|
if (detector_shm()->myDetectorType == CHIPTESTBOARD ||
|
||||||
detector_shm()->myDetectorType == MOENCH) {
|
detector_shm()->myDetectorType == MOENCH) {
|
||||||
updateTotalNumberOfChannels();
|
updateTotalNumberOfChannels();
|
||||||
@ -2993,12 +2859,13 @@ int slsDetector::setROI(int n, ROI roiLimits[]) {
|
|||||||
slsDetectorDefs::ROI *slsDetector::getROI(int &n) {
|
slsDetectorDefs::ROI *slsDetector::getROI(int &n) {
|
||||||
sendROI(-1, nullptr);
|
sendROI(-1, nullptr);
|
||||||
n = detector_shm()->nROI;
|
n = detector_shm()->nROI;
|
||||||
// moench - get json header(due to different clients, diff shm) (get roi is from detector:
|
// moench - get json header(due to different clients, diff shm) (get roi is
|
||||||
// updated anyway)
|
// from detector: updated anyway)
|
||||||
if (detector_shm()->myDetectorType == MOENCH) {
|
if (detector_shm()->myDetectorType == MOENCH) {
|
||||||
getAdditionalJsonHeader();
|
getAdditionalJsonHeader();
|
||||||
}
|
}
|
||||||
// update #nchans and databytes, as it depends on #samples, roi, readoutflags (ctb only)
|
// update #nchans and databytes, as it depends on #samples, roi,
|
||||||
|
// readoutflags (ctb only)
|
||||||
if (detector_shm()->myDetectorType == CHIPTESTBOARD ||
|
if (detector_shm()->myDetectorType == CHIPTESTBOARD ||
|
||||||
detector_shm()->myDetectorType == MOENCH) {
|
detector_shm()->myDetectorType == MOENCH) {
|
||||||
updateTotalNumberOfChannels();
|
updateTotalNumberOfChannels();
|
||||||
@ -3188,7 +3055,8 @@ int slsDetector::setFlippedData(dimension d, int value) {
|
|||||||
throw RuntimeError("Flipped across Y axis is not implemented");
|
throw RuntimeError("Flipped across Y axis is not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace get with shm value (write to shm right away as it is a det value, not rx value)
|
// replace get with shm value (write to shm right away as it is a det value,
|
||||||
|
// not rx value)
|
||||||
if (value > -1) {
|
if (value > -1) {
|
||||||
detector_shm()->flippedData[d] = (value > 0) ? 1 : 0;
|
detector_shm()->flippedData[d] = (value > 0) ? 1 : 0;
|
||||||
}
|
}
|
||||||
@ -3677,14 +3545,12 @@ void slsDetector::printReceiverConfiguration(TLogLevel level) {
|
|||||||
FILE_LOG(level) << "#Detector " << detId << ":\n Receiver Hostname:\t" << getReceiverHostname()
|
FILE_LOG(level) << "#Detector " << detId << ":\n Receiver Hostname:\t" << getReceiverHostname()
|
||||||
<< "\nDetector UDP IP (Source):\t\t" << getDetectorIP()
|
<< "\nDetector UDP IP (Source):\t\t" << getDetectorIP()
|
||||||
<< "\nDetector UDP IP2 (Source):\t\t" << getDetectorIP2()
|
<< "\nDetector UDP IP2 (Source):\t\t" << getDetectorIP2()
|
||||||
<< "\nDetector UDP MAC:\t\t" << getDetectorMAC()
|
<< "\nDetector UDP MAC:\t\t" << getDetectorMAC() << "\nDetector UDP MAC2:\t\t"
|
||||||
<< "\nDetector UDP MAC2:\t\t" << getDetectorMAC2()
|
<< getDetectorMAC2() << "\nReceiver UDP IP:\t" << getReceiverUDPIP()
|
||||||
<< "\nReceiver UDP IP:\t" << getReceiverUDPIP()
|
<< "\nReceiver UDP IP2:\t" << getReceiverUDPIP2() << "\nReceiver UDP MAC:\t"
|
||||||
<< "\nReceiver UDP IP2:\t" << getReceiverUDPIP2()
|
<< getReceiverUDPMAC() << "\nReceiver UDP MAC2:\t" << getReceiverUDPMAC2()
|
||||||
<< "\nReceiver UDP MAC:\t" << getReceiverUDPMAC()
|
<< "\nReceiver UDP Port:\t" << getReceiverUDPPort() << "\nReceiver UDP Port2:\t"
|
||||||
<< "\nReceiver UDP MAC2:\t" << getReceiverUDPMAC2()
|
<< getReceiverUDPPort2();
|
||||||
<< "\nReceiver UDP Port:\t" << getReceiverUDPPort()
|
|
||||||
<< "\nReceiver UDP Port2:\t"<< getReceiverUDPPort2();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int slsDetector::setReceiverOnline(int value) {
|
int slsDetector::setReceiverOnline(int value) {
|
||||||
@ -3703,7 +3569,6 @@ int slsDetector::setReceiverOnline(int value) {
|
|||||||
detector_shm()->receiverTCPPort);
|
detector_shm()->receiverTCPPort);
|
||||||
receiver.close();
|
receiver.close();
|
||||||
detector_shm()->receiverOnlineFlag = ONLINE_FLAG;
|
detector_shm()->receiverOnlineFlag = ONLINE_FLAG;
|
||||||
|
|
||||||
// check for version compatibility
|
// check for version compatibility
|
||||||
if (detector_shm()->receiverAPIVersion == 0) {
|
if (detector_shm()->receiverAPIVersion == 0) {
|
||||||
checkReceiverVersionCompatibility();
|
checkReceiverVersionCompatibility();
|
||||||
@ -4429,7 +4294,8 @@ int slsDetector::setPattern(const std::string &fname) {
|
|||||||
FILE *fd = fopen(fname.c_str(), "r");
|
FILE *fd = fopen(fname.c_str(), "r");
|
||||||
if (fd != nullptr) {
|
if (fd != nullptr) {
|
||||||
while (fread(&word, sizeof(word), 1, fd)) {
|
while (fread(&word, sizeof(word), 1, fd)) {
|
||||||
setPatternWord(addr, word); // TODO! (Erik) do we need to send pattern in 64bit chunks?
|
setPatternWord(addr, word); // TODO! (Erik) do we need to send
|
||||||
|
// pattern in 64bit chunks?
|
||||||
++addr;
|
++addr;
|
||||||
}
|
}
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
@ -4780,7 +4646,8 @@ slsDetector::readSettingsFile(const std::string &fname, sls_detector_module *myM
|
|||||||
deleteModule(myMod);
|
deleteModule(myMod);
|
||||||
}
|
}
|
||||||
infile.close();
|
infile.close();
|
||||||
throw RuntimeError("readSettingsFile: Could not load all values for settings for " +
|
throw RuntimeError("readSettingsFile: Could not load all values "
|
||||||
|
"for settings for " +
|
||||||
fname);
|
fname);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < myMod->ndac; ++i) {
|
for (int i = 0; i < myMod->ndac; ++i) {
|
||||||
|
@ -7,6 +7,7 @@ set(SOURCES
|
|||||||
src/DataSocket.cpp
|
src/DataSocket.cpp
|
||||||
src/ServerSocket.cpp
|
src/ServerSocket.cpp
|
||||||
src/ServerInterface.cpp
|
src/ServerInterface.cpp
|
||||||
|
src/network_utils.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(HEADERS
|
set(HEADERS
|
||||||
@ -30,6 +31,7 @@ set(PUBLICHEADERS
|
|||||||
include/DataSocket.h
|
include/DataSocket.h
|
||||||
include/ServerSocket.h
|
include/ServerSocket.h
|
||||||
include/ServerInterface.h
|
include/ServerInterface.h
|
||||||
|
include/network_utils.h
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(slsSupportLib SHARED
|
add_library(slsSupportLib SHARED
|
||||||
|
45
slsSupportLib/include/network_utils.h
Normal file
45
slsSupportLib/include/network_utils.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
|
uint32_t HostnameToIp(const char *hostname);
|
||||||
|
|
||||||
|
class IpAddr {
|
||||||
|
private:
|
||||||
|
uint32_t addr_{0};
|
||||||
|
|
||||||
|
public:
|
||||||
|
constexpr IpAddr(uint32_t address) noexcept : addr_{address} {}
|
||||||
|
IpAddr(const std::string &address);
|
||||||
|
IpAddr(const char *address);
|
||||||
|
std::string str() const;
|
||||||
|
std::string hex() const;
|
||||||
|
constexpr bool operator==(const IpAddr &other) const noexcept { return addr_ == other.addr_; }
|
||||||
|
constexpr bool operator!=(const IpAddr &other) const noexcept { return addr_ != other.addr_; }
|
||||||
|
constexpr bool operator==(const uint32_t other) const noexcept { return addr_ == other; }
|
||||||
|
constexpr bool operator!=(const uint32_t other) const noexcept { return addr_ != other; }
|
||||||
|
};
|
||||||
|
|
||||||
|
class MacAddr {
|
||||||
|
private:
|
||||||
|
uint64_t addr_{0};
|
||||||
|
std::string to_hex(const char delimiter = 0) const;
|
||||||
|
|
||||||
|
public:
|
||||||
|
constexpr MacAddr(uint64_t mac) noexcept : addr_{mac} {}
|
||||||
|
MacAddr(std::string mac);
|
||||||
|
MacAddr(const char *address);
|
||||||
|
std::string str() const;
|
||||||
|
std::string hex() const;
|
||||||
|
constexpr bool operator==(const MacAddr &other) const noexcept { return addr_ == other.addr_; }
|
||||||
|
constexpr bool operator!=(const MacAddr &other) const noexcept { return addr_ != other.addr_; }
|
||||||
|
constexpr bool operator==(const uint64_t other) const noexcept { return addr_ == other; }
|
||||||
|
constexpr bool operator!=(const uint64_t other) const noexcept { return addr_ != other; }
|
||||||
|
};
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &out, const IpAddr &addr);
|
||||||
|
std::ostream &operator<<(std::ostream &out, const MacAddr &addr);
|
||||||
|
|
||||||
|
} // namespace sls
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <cassert>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
namespace sls {
|
namespace sls {
|
||||||
|
|
||||||
@ -14,10 +16,18 @@ Still this is better than strcpy and a buffer overflow...
|
|||||||
*/
|
*/
|
||||||
template <size_t array_size>
|
template <size_t array_size>
|
||||||
void strcpy_safe(char (&destination)[array_size], const char *source) {
|
void strcpy_safe(char (&destination)[array_size], const char *source) {
|
||||||
|
assert(array_size > strlen(source));
|
||||||
strncpy(destination, source, array_size-1);
|
strncpy(destination, source, array_size-1);
|
||||||
destination[array_size - 1] = '\0';
|
destination[array_size - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <size_t array_size>
|
||||||
|
void strcpy_safe(char (&destination)[array_size], const std::string& source) {
|
||||||
|
assert(array_size > source.size());
|
||||||
|
strncpy(destination, source.c_str(), array_size-1);
|
||||||
|
destination[array_size - 1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Removes all occurrences of the specified char from a c string
|
Removes all occurrences of the specified char from a c string
|
||||||
Templated on array size to ensure no access after buffer limits.
|
Templated on array size to ensure no access after buffer limits.
|
||||||
@ -51,6 +61,12 @@ Concatenate strings using + if the strings are different
|
|||||||
*/
|
*/
|
||||||
std::string concatenateIfDifferent(const std::vector<std::string> &container);
|
std::string concatenateIfDifferent(const std::vector<std::string> &container);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Concatenate vector of things with str method using + if the strings are different
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
std::string concatenateIfDifferent(const std::vector<T> &container);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Convert an ip address string to a string in hex format. (removing dots)
|
Convert an ip address string to a string in hex format. (removing dots)
|
||||||
*/
|
*/
|
||||||
|
@ -81,7 +81,7 @@ void DataSocket::close() {
|
|||||||
if(::close(socketId_)){
|
if(::close(socketId_)){
|
||||||
throw SocketError("could not close socket");
|
throw SocketError("could not close socket");
|
||||||
}
|
}
|
||||||
socketId_ = 0;
|
socketId_ = -1;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw std::runtime_error("Socket ERROR: close called on bad socket\n");
|
throw std::runtime_error("Socket ERROR: close called on bad socket\n");
|
||||||
|
94
slsSupportLib/src/network_utils.cpp
Normal file
94
slsSupportLib/src/network_utils.cpp
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
#include "sls_detector_exceptions.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cassert>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "network_utils.h"
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
|
IpAddr::IpAddr(const std::string &address) {
|
||||||
|
inet_pton(AF_INET, address.c_str(), &addr_);
|
||||||
|
}
|
||||||
|
|
||||||
|
IpAddr::IpAddr(const char *address) {
|
||||||
|
inet_pton(AF_INET, address, &addr_);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string IpAddr::str() const {
|
||||||
|
char ipstring[INET_ADDRSTRLEN]{};
|
||||||
|
inet_ntop(AF_INET, &addr_, ipstring, INET_ADDRSTRLEN);
|
||||||
|
return ipstring;
|
||||||
|
}
|
||||||
|
std::string IpAddr::hex() const {
|
||||||
|
std::ostringstream ss;
|
||||||
|
ss << std::hex << std::setfill('0') << std::setw(2);
|
||||||
|
for (int i = 0; i != 4; ++i) {
|
||||||
|
ss << ((addr_ >> i * 8) & 0xFF);
|
||||||
|
}
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
MacAddr::MacAddr(std::string mac) {
|
||||||
|
if ((mac.length() != 17) || (mac[2] != ':') || (mac[5] != ':') ||
|
||||||
|
(mac[8] != ':') || (mac[11] != ':') || (mac[14] != ':')) {
|
||||||
|
addr_ = 0;
|
||||||
|
} else {
|
||||||
|
mac.erase(std::remove(mac.begin(), mac.end(), ':'), mac.end());
|
||||||
|
addr_ = std::strtoul(mac.c_str(), nullptr, 16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MacAddr::MacAddr(const char *address) : MacAddr(std::string(address)) {}
|
||||||
|
|
||||||
|
std::string MacAddr::to_hex(const char delimiter) const {
|
||||||
|
std::ostringstream ss;
|
||||||
|
ss << std::hex << std::setfill('0') << std::setw(2);
|
||||||
|
ss << ((addr_ >> 40) & 0xFF);
|
||||||
|
for (int i = 32; i >= 0; i -= 8) {
|
||||||
|
if (delimiter)
|
||||||
|
ss << delimiter;
|
||||||
|
ss << ((addr_ >> i) & 0xFF);
|
||||||
|
}
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string MacAddr::str() const {
|
||||||
|
return to_hex(':');
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string MacAddr::hex() const {
|
||||||
|
return to_hex();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &out, const IpAddr &addr) {
|
||||||
|
return out << addr.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &out, const MacAddr &addr) {
|
||||||
|
return out << addr.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t HostnameToIp(const char *hostname) {
|
||||||
|
struct addrinfo hints, *result;
|
||||||
|
memset(&hints, 0, sizeof(hints));
|
||||||
|
hints.ai_family = AF_INET;
|
||||||
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
if (getaddrinfo(hostname, NULL, &hints, &result)) {
|
||||||
|
freeaddrinfo(result);
|
||||||
|
throw RuntimeError("Could not convert hostname to ip");
|
||||||
|
}
|
||||||
|
uint32_t ip = ((struct sockaddr_in *)result->ai_addr)->sin_addr.s_addr;
|
||||||
|
freeaddrinfo(result);
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace sls
|
@ -1,14 +1,13 @@
|
|||||||
|
|
||||||
#include "string_utils.h"
|
#include "string_utils.h"
|
||||||
#include "container_utils.h"
|
#include "container_utils.h"
|
||||||
#include <sstream>
|
#include "network_utils.h"
|
||||||
#include <iomanip>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <sstream>
|
||||||
namespace sls {
|
namespace sls {
|
||||||
|
|
||||||
|
std::vector<std::string> split(const std::string &strToSplit, char delimeter) {
|
||||||
std::vector<std::string> split(const std::string& strToSplit, char delimeter)
|
|
||||||
{
|
|
||||||
std::stringstream ss(strToSplit);
|
std::stringstream ss(strToSplit);
|
||||||
std::string item;
|
std::string item;
|
||||||
std::vector<std::string> splittedStrings;
|
std::vector<std::string> splittedStrings;
|
||||||
@ -18,7 +17,6 @@ std::vector<std::string> split(const std::string& strToSplit, char delimeter)
|
|||||||
return splittedStrings;
|
return splittedStrings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string concatenateNonEmptyStrings(const std::vector<std::string> &vec) {
|
std::string concatenateNonEmptyStrings(const std::vector<std::string> &vec) {
|
||||||
std::string ret;
|
std::string ret;
|
||||||
for (const auto &s : vec)
|
for (const auto &s : vec)
|
||||||
@ -27,8 +25,7 @@ std::string concatenateNonEmptyStrings(const std::vector<std::string>& vec){
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string concatenateIfDifferent(const std::vector<std::string>& container)
|
std::string concatenateIfDifferent(const std::vector<std::string> &container) {
|
||||||
{
|
|
||||||
if (allEqual(container)) {
|
if (allEqual(container)) {
|
||||||
return container.front();
|
return container.front();
|
||||||
} else {
|
} else {
|
||||||
@ -38,19 +35,29 @@ std::string concatenateIfDifferent(const std::vector<std::string>& container)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
template <typename T>
|
||||||
|
std::string concatenateIfDifferent(const std::vector<T> &container) {
|
||||||
|
if (allEqual(container)) {
|
||||||
|
return container.front().str();
|
||||||
|
} else {
|
||||||
|
std::string result;
|
||||||
|
for (const auto &s : container)
|
||||||
|
result += s.str() + '+';
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string stringIpToHex(const std::string& ip)
|
template std::string concatenateIfDifferent(const std::vector<IpAddr> &);
|
||||||
{
|
template std::string concatenateIfDifferent(const std::vector<MacAddr> &);
|
||||||
|
|
||||||
|
std::string stringIpToHex(const std::string &ip) {
|
||||||
std::istringstream iss(ip);
|
std::istringstream iss(ip);
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
std::string item;
|
std::string item;
|
||||||
while (std::getline(iss, item, '.'))
|
while (std::getline(iss, item, '.')) {
|
||||||
{
|
|
||||||
oss << std::setw(2) << std::setfill('0') << std::hex << std::stoi(item);
|
oss << std::setw(2) << std::setfill('0') << std::hex << std::stoi(item);
|
||||||
}
|
}
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}; // namespace sls
|
}; // namespace sls
|
@ -10,6 +10,7 @@ set(SOURCES
|
|||||||
test-ClientInterface.cpp
|
test-ClientInterface.cpp
|
||||||
test-CmdLineParser.cpp
|
test-CmdLineParser.cpp
|
||||||
test-container_utils.cpp
|
test-container_utils.cpp
|
||||||
|
test-network_utils.cpp
|
||||||
test-string_utils.cpp
|
test-string_utils.cpp
|
||||||
test-Timer.cpp
|
test-Timer.cpp
|
||||||
)
|
)
|
||||||
|
51
slsSupportLib/tests/test-network_utils.cpp
Normal file
51
slsSupportLib/tests/test-network_utils.cpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
|
||||||
|
#include "catch.hpp"
|
||||||
|
#include "network_utils.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "string_utils.h"
|
||||||
|
|
||||||
|
using namespace sls;
|
||||||
|
|
||||||
|
|
||||||
|
TEST_CASE("Convert mac address using classes") {
|
||||||
|
|
||||||
|
std::vector<uint64_t> vec_addr{346856806822, 346856806852, 262027939863028};
|
||||||
|
std::vector<std::string> vec_ans{"00:50:c2:46:d9:a6", "00:50:c2:46:d9:c4", "ee:50:22:46:d9:f4"};
|
||||||
|
for (int i = 0; i != vec_addr.size(); ++i) {
|
||||||
|
auto mac0 = MacAddr(vec_addr[i]);
|
||||||
|
auto mac1 = MacAddr(vec_ans[i]);
|
||||||
|
|
||||||
|
CHECK(mac0 == vec_addr[i]);
|
||||||
|
CHECK(mac1 == vec_addr[i]);
|
||||||
|
CHECK(mac0 == vec_ans[i]);
|
||||||
|
CHECK(mac1 == vec_ans[i]);
|
||||||
|
CHECK(mac0.str() == vec_ans[i]);
|
||||||
|
CHECK(mac1.str() == vec_ans[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST_CASE("Convert IP using classes ") {
|
||||||
|
std::vector<uint32_t> vec_addr{4073554305, 2747957633, 2697625985};
|
||||||
|
std::vector<std::string> vec_ans{"129.129.205.242", "129.129.202.163", "129.129.202.160"};
|
||||||
|
|
||||||
|
for (int i = 0; i != vec_addr.size(); ++i) {
|
||||||
|
auto ip0 = IpAddr(vec_addr[i]);
|
||||||
|
auto ip1 = IpAddr(vec_ans[i]);
|
||||||
|
|
||||||
|
CHECK(ip0 == ip1);
|
||||||
|
CHECK(ip0 == vec_addr[i]);
|
||||||
|
CHECK(ip1 == vec_addr[i]);
|
||||||
|
CHECK(ip0 == vec_ans[i]);
|
||||||
|
CHECK(ip1 == vec_ans[i]);
|
||||||
|
CHECK(ip0.str() == vec_ans[i]);
|
||||||
|
CHECK(ip1.str() == vec_ans[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Strange input gives 0"){
|
||||||
|
CHECK(IpAddr("hej")== 0);
|
||||||
|
CHECK(MacAddr("hej")== 0);
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
#include "MySocketTCP.h"
|
#include "MySocketTCP.h"
|
||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
// #include "multiSlsDetector.h"
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -23,6 +22,9 @@ TEST_CASE("copy a string") {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef NDEBUG
|
||||||
|
//This test can only run in release since we assert on the length of the string
|
||||||
TEST_CASE("copy a long string"){
|
TEST_CASE("copy a long string"){
|
||||||
auto src = "some very very long sting that does not fit";
|
auto src = "some very very long sting that does not fit";
|
||||||
char dst[3];
|
char dst[3];
|
||||||
@ -32,7 +34,7 @@ TEST_CASE("copy a long string"){
|
|||||||
REQUIRE(dst[2]=='\0');
|
REQUIRE(dst[2]=='\0');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
TEST_CASE("Concat") {
|
TEST_CASE("Concat") {
|
||||||
std::vector<std::string> v{"one", "one", "one"};
|
std::vector<std::string> v{"one", "one", "one"};
|
||||||
std::vector<std::string> v2{"one", "one", "one"};
|
std::vector<std::string> v2{"one", "one", "one"};
|
||||||
@ -111,3 +113,5 @@ TEST_CASE("Many characters in a row"){
|
|||||||
sls::removeChar(str, 'l');
|
sls::removeChar(str, 'l');
|
||||||
REQUIRE(std::string(str) == "someeequite::ongstring");
|
REQUIRE(std::string(str) == "someeequite::ongstring");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TEST_CASE("concat things not being strings")
|
Loading…
x
Reference in New Issue
Block a user