mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-13 21:37:13 +02:00
Removeudpcache (#65)
* WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * solved eiger 1-10g issue * some fixes for remove udp cache to work * bug fix virtual * removed special handling of rx_udpip
This commit is contained in:
@ -21,7 +21,7 @@ const std::string Listener::TypeName = "Listener";
|
||||
|
||||
|
||||
Listener::Listener(int ind, detectorType dtype, Fifo* f, std::atomic<runStatus>* s,
|
||||
uint32_t* portno, char* e, uint64_t* nf, uint32_t* dr,
|
||||
uint32_t* portno, std::string* e, uint64_t* nf, uint32_t* dr,
|
||||
int64_t* us, int64_t* as, uint32_t* fpf,
|
||||
frameDiscardPolicy* fdp, bool* act, bool* depaden, bool* sm) :
|
||||
ThreadObject(ind),
|
||||
@ -187,10 +187,10 @@ int Listener::CreateUDPSockets() {
|
||||
}
|
||||
|
||||
//if eth is mistaken with ip address
|
||||
if (strchr(eth,'.') != nullptr){
|
||||
memset(eth, 0, MAX_STR_LENGTH);
|
||||
if ((*eth).find('.') != std::string::npos) {
|
||||
(*eth) = "";
|
||||
}
|
||||
if(!strlen(eth)){
|
||||
if (!(*eth).length()) {
|
||||
FILE_LOG(logWARNING) << "eth is empty. Listening to all";
|
||||
}
|
||||
|
||||
@ -198,7 +198,7 @@ int Listener::CreateUDPSockets() {
|
||||
|
||||
try{
|
||||
udpSocket = sls::make_unique<genericSocket>(*udpPortNumber, genericSocket::UDP,
|
||||
generalData->packetSize, (strlen(eth)?eth:nullptr), generalData->headerPacketSize,
|
||||
generalData->packetSize, ((*eth).length() ? (*eth).c_str() : nullptr), generalData->headerPacketSize,
|
||||
*udpSocketBufferSize);
|
||||
FILE_LOG(logINFO) << index << ": UDP port opened at port " << *udpPortNumber;
|
||||
} catch (...) {
|
||||
@ -244,14 +244,14 @@ int Listener::CreateDummySocketForUDPSocketBufferSize(int64_t s) {
|
||||
*udpSocketBufferSize = s;
|
||||
|
||||
//if eth is mistaken with ip address
|
||||
if (strchr(eth,'.') != nullptr){
|
||||
memset(eth, 0, MAX_STR_LENGTH);
|
||||
}
|
||||
if ((*eth).find('.') != std::string::npos) {
|
||||
(*eth) = "";
|
||||
}
|
||||
|
||||
//create dummy socket
|
||||
try {
|
||||
genericSocket g(*udpPortNumber, genericSocket::UDP,
|
||||
generalData->packetSize, (strlen(eth)?eth:nullptr), generalData->headerPacketSize,
|
||||
generalData->packetSize, ((*eth).length() ? (*eth).c_str() : nullptr), generalData->headerPacketSize,
|
||||
*udpSocketBufferSize);
|
||||
|
||||
// doubled due to kernel bookkeeping (could also be less due to permissions)
|
||||
|
@ -86,8 +86,8 @@ void slsReceiverImplementation::InitializeMembers() {
|
||||
|
||||
//***connection parameters***
|
||||
numUDPInterfaces = 1;
|
||||
eth.resize(MAX_NUMBER_OF_LISTENING_THREADS);
|
||||
for (int i = 0; i < MAX_NUMBER_OF_LISTENING_THREADS; i++) {
|
||||
strcpy(eth[i], "");
|
||||
udpPortNum[i] = DEFAULT_UDP_PORTNO + i;
|
||||
}
|
||||
udpSocketBufferSize = 0;
|
||||
@ -285,12 +285,12 @@ uint32_t slsReceiverImplementation::getUDPPortNumber2() const {
|
||||
|
||||
std::string slsReceiverImplementation::getEthernetInterface() const {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
return std::string(eth[0]);
|
||||
return eth[0];
|
||||
}
|
||||
|
||||
std::string slsReceiverImplementation::getEthernetInterface2() const {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
return std::string(eth[1]);
|
||||
return eth[1];
|
||||
}
|
||||
|
||||
int slsReceiverImplementation::getNumberofUDPInterfaces() const {
|
||||
@ -677,17 +677,17 @@ void slsReceiverImplementation::setUDPPortNumber2(const uint32_t i) {
|
||||
FILE_LOG(logINFO) << "UDP Port Number[1]: " << udpPortNum[1];
|
||||
}
|
||||
|
||||
void slsReceiverImplementation::setEthernetInterface(const char *c) {
|
||||
void slsReceiverImplementation::setEthernetInterface(const std::string &c) {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
|
||||
strcpy(eth[0], c);
|
||||
eth[0] = c;
|
||||
FILE_LOG(logINFO) << "Ethernet Interface: " << eth[0];
|
||||
}
|
||||
|
||||
void slsReceiverImplementation::setEthernetInterface2(const char *c) {
|
||||
void slsReceiverImplementation::setEthernetInterface2(const std::string &c) {
|
||||
FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
|
||||
strcpy(eth[1], c);
|
||||
eth[1] = c;
|
||||
FILE_LOG(logINFO) << "Ethernet Interface 2: " << eth[1];
|
||||
}
|
||||
|
||||
@ -725,7 +725,7 @@ int slsReceiverImplementation::setNumberofUDPInterfaces(const int n) {
|
||||
auto fifo_ptr = fifo[i].get();
|
||||
listener.push_back(sls::make_unique<Listener>(
|
||||
i, myDetectorType, fifo_ptr, &status, &udpPortNum[i],
|
||||
eth[i], &numberOfFrames, &dynamicRange,
|
||||
ð[i], &numberOfFrames, &dynamicRange,
|
||||
&udpSocketBufferSize, &actualUDPSocketBufferSize,
|
||||
&framesPerFile, &frameDiscardMode, &activated,
|
||||
&deactivatedPaddingEnable, &silentMode));
|
||||
@ -1167,7 +1167,7 @@ int slsReceiverImplementation::setDetectorType(const detectorType d) {
|
||||
try {
|
||||
auto fifo_ptr = fifo[i].get();
|
||||
listener.push_back(sls::make_unique<Listener>(
|
||||
i, myDetectorType, fifo_ptr, &status, &udpPortNum[i], eth[i],
|
||||
i, myDetectorType, fifo_ptr, &status, &udpPortNum[i], ð[i],
|
||||
&numberOfFrames, &dynamicRange, &udpSocketBufferSize,
|
||||
&actualUDPSocketBufferSize, &framesPerFile, &frameDiscardMode,
|
||||
&activated, &deactivatedPaddingEnable, &silentMode));
|
||||
|
@ -156,7 +156,6 @@ int slsReceiverTCPIPInterface::function_table(){
|
||||
flist[F_GET_RECEIVER_TYPE] = &slsReceiverTCPIPInterface::set_detector_type;
|
||||
flist[F_SEND_RECEIVER_DETHOSTNAME] = &slsReceiverTCPIPInterface::set_detector_hostname;
|
||||
flist[F_RECEIVER_SET_ROI] = &slsReceiverTCPIPInterface::set_roi;
|
||||
flist[F_SETUP_RECEIVER_UDP] = &slsReceiverTCPIPInterface::setup_udp;
|
||||
flist[F_SET_RECEIVER_TIMER] = &slsReceiverTCPIPInterface::set_timer;
|
||||
flist[F_SET_RECEIVER_DYNAMIC_RANGE] = &slsReceiverTCPIPInterface::set_dynamic_range;
|
||||
flist[F_RECEIVER_STREAMING_FREQUENCY] = &slsReceiverTCPIPInterface::set_streaming_frequency;
|
||||
@ -202,6 +201,11 @@ int slsReceiverTCPIPInterface::function_table(){
|
||||
flist[F_RECEIVER_DBIT_OFFSET] = &slsReceiverTCPIPInterface::set_dbit_offset;
|
||||
flist[F_SET_RECEIVER_QUAD] = &slsReceiverTCPIPInterface::set_quad_type;
|
||||
flist[F_SET_RECEIVER_READ_N_LINES] = &slsReceiverTCPIPInterface::set_read_n_lines;
|
||||
flist[F_SET_RECEIVER_UDP_IP] = &slsReceiverTCPIPInterface::set_udp_ip;
|
||||
flist[F_SET_RECEIVER_UDP_IP2] = &slsReceiverTCPIPInterface::set_udp_ip2;
|
||||
flist[F_SET_RECEIVER_UDP_PORT] = &slsReceiverTCPIPInterface::set_udp_port;
|
||||
flist[F_SET_RECEIVER_UDP_PORT2] = &slsReceiverTCPIPInterface::set_udp_port2;
|
||||
flist[F_SET_RECEIVER_NUM_INTERFACES] = &slsReceiverTCPIPInterface::set_num_interfaces;
|
||||
|
||||
for (int i = NUM_DET_FUNCTIONS + 1; i < NUM_REC_FUNCTIONS ; i++) {
|
||||
FILE_LOG(logDEBUG1) << "function fnum: " << i << " (" <<
|
||||
@ -524,102 +528,6 @@ int slsReceiverTCPIPInterface::set_roi(Interface &socket) {
|
||||
return socket.Send(OK);
|
||||
}
|
||||
|
||||
int slsReceiverTCPIPInterface::setup_udp(Interface &socket) {
|
||||
ret = OK;
|
||||
char args[5][MAX_STR_LENGTH]{};
|
||||
char retvals[2][MAX_STR_LENGTH]{};
|
||||
socket.Receive(args);
|
||||
VerifyIdle(socket);
|
||||
|
||||
// setup interfaces count
|
||||
int numInterfaces = atoi(args[0]) > 1 ? 2 : 1;
|
||||
char *ip1 = args[1];
|
||||
char *ip2 = args[2];
|
||||
uint32_t port1 = atoi(args[3]);
|
||||
uint32_t port2 = atoi(args[4]);
|
||||
|
||||
// 1st interface
|
||||
impl()->setUDPPortNumber(port1);
|
||||
if (myDetectorType == EIGER) {
|
||||
impl()->setUDPPortNumber2(port2);
|
||||
}
|
||||
FILE_LOG(logINFO) << "Receiver UDP IP: " << ip1;
|
||||
// get eth
|
||||
std::string temp = sls::IpToInterfaceName(ip1);
|
||||
if (temp == "none") {
|
||||
throw RuntimeError("Failed to get ethernet interface or IP");
|
||||
} else {
|
||||
char eth[MAX_STR_LENGTH]{};
|
||||
sls::strcpy_safe(eth, temp.c_str());
|
||||
// if there is a dot in eth name
|
||||
if (strchr(eth, '.') != nullptr) {
|
||||
sls::strcpy_safe(eth, "");
|
||||
FILE_LOG(logERROR)
|
||||
<< "Failed to get ethernet interface from IP. Got " << temp
|
||||
<< '\n';
|
||||
}
|
||||
impl()->setEthernetInterface(eth);
|
||||
if (myDetectorType == EIGER) {
|
||||
impl()->setEthernetInterface2(eth);
|
||||
}
|
||||
// get mac address
|
||||
if (ret != FAIL) {
|
||||
temp = sls::InterfaceNameToMac(eth).str();
|
||||
if (temp == "00:00:00:00:00:00") {
|
||||
throw RuntimeError("failed to get mac adddress to listen to\n");
|
||||
} else {
|
||||
sls::strcpy_safe(retvals[0], temp.c_str());
|
||||
FILE_LOG(logINFO) << "Receiver MAC Address: " << retvals[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2nd interface
|
||||
if (myDetectorType == JUNGFRAU && numInterfaces == 2) {
|
||||
impl()->setUDPPortNumber2(port2);
|
||||
FILE_LOG(logINFO) << "Receiver UDP IP 2: " << ip2;
|
||||
// get eth
|
||||
temp = sls::IpToInterfaceName(ip2);
|
||||
if (temp == "none") {
|
||||
throw RuntimeError("Failed to get 2nd ethernet interface or IP");
|
||||
} else {
|
||||
char eth[MAX_STR_LENGTH]{};
|
||||
memset(eth, 0, MAX_STR_LENGTH);
|
||||
sls::strcpy_safe(eth, temp.c_str());
|
||||
// if there is a dot in eth name
|
||||
if (strchr(eth, '.') != nullptr) {
|
||||
sls::strcpy_safe(eth, "");
|
||||
FILE_LOG(logERROR)
|
||||
<< "Failed to get 2nd ethernet interface from IP. Got "
|
||||
<< temp << '\n';
|
||||
}
|
||||
impl()->setEthernetInterface2(eth);
|
||||
|
||||
// get mac address
|
||||
if (ret != FAIL) {
|
||||
temp = sls::InterfaceNameToMac(eth).str();
|
||||
if (temp == "00:00:00:00:00:00") {
|
||||
throw RuntimeError(
|
||||
"failed to get 2nd mac adddress to listen to");
|
||||
FILE_LOG(logERROR) << mess;
|
||||
} else {
|
||||
sls::strcpy_safe(retvals[1], temp.c_str());
|
||||
FILE_LOG(logINFO)
|
||||
<< "Receiver MAC Address 2: " << retvals[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set the number of udp interfaces (changes number of threads and many
|
||||
// others)
|
||||
if (myDetectorType == JUNGFRAU &&
|
||||
impl()->setNumberofUDPInterfaces(numInterfaces) == FAIL) {
|
||||
throw RuntimeError("Failed to set number of interfaces");
|
||||
}
|
||||
return socket.sendResult(ret, retvals, sizeof(retvals), mess);
|
||||
}
|
||||
|
||||
int slsReceiverTCPIPInterface::set_timer(Interface &socket) {
|
||||
auto index = socket.Receive<int64_t>();
|
||||
auto value = socket.Receive<int64_t>();
|
||||
@ -1324,4 +1232,92 @@ int slsReceiverTCPIPInterface::set_read_n_lines(Interface &socket) {
|
||||
validate(arg, retval, "set read n lines", DEC);
|
||||
FILE_LOG(logDEBUG1) << "read n lines retval:" << retval;
|
||||
return socket.Send(OK);
|
||||
}
|
||||
|
||||
|
||||
int slsReceiverTCPIPInterface::set_udp_ip(Interface &socket) {
|
||||
auto arg = socket.Receive<sls::IpAddr>();
|
||||
VerifyIdle(socket);
|
||||
FILE_LOG(logINFO) << "Received UDP IP: " << arg;
|
||||
// getting eth
|
||||
std::string eth = sls::IpToInterfaceName(arg.str());
|
||||
if (eth == "none") {
|
||||
throw RuntimeError("Failed to get udp ethernet interface from IP " + arg.str());
|
||||
}
|
||||
if (eth.find('.') != std::string::npos) {
|
||||
eth = "";
|
||||
FILE_LOG(logERROR) << "Failed to get udp ethernet interface from IP " << arg << ". Got " << eth;
|
||||
}
|
||||
impl()->setEthernetInterface(eth);
|
||||
if (myDetectorType == EIGER) {
|
||||
impl()->setEthernetInterface2(eth);
|
||||
}
|
||||
// get mac address
|
||||
auto retval = sls::InterfaceNameToMac(eth);
|
||||
if (retval == 0) {
|
||||
throw RuntimeError("Failed to get udp mac adddress to listen to\n");
|
||||
}
|
||||
FILE_LOG(logINFO) << "Receiver MAC Address: " << retval;
|
||||
return socket.sendResult(retval);
|
||||
}
|
||||
|
||||
|
||||
int slsReceiverTCPIPInterface::set_udp_ip2(Interface &socket) {
|
||||
auto arg = socket.Receive<sls::IpAddr>();
|
||||
VerifyIdle(socket);
|
||||
if (myDetectorType != JUNGFRAU) {
|
||||
throw RuntimeError("UDP Destination IP2 not implemented for this detector");
|
||||
}
|
||||
FILE_LOG(logINFO) << "Received UDP IP2: " << arg;
|
||||
// getting eth
|
||||
std::string eth = sls::IpToInterfaceName(arg.str());
|
||||
if (eth == "none") {
|
||||
throw RuntimeError("Failed to get udp ethernet interface2 from IP " + arg.str());
|
||||
}
|
||||
if (eth.find('.') != std::string::npos) {
|
||||
eth = "";
|
||||
FILE_LOG(logERROR) << "Failed to get udp ethernet interface2 from IP " << arg << ". Got " << eth;
|
||||
}
|
||||
impl()->setEthernetInterface2(eth);
|
||||
|
||||
// get mac address
|
||||
auto retval = sls::InterfaceNameToMac(eth);
|
||||
if (retval == 0) {
|
||||
throw RuntimeError("Failed to get udp mac adddress2 to listen to\n");
|
||||
}
|
||||
FILE_LOG(logINFO) << "Receiver MAC Address2: " << retval;
|
||||
return socket.sendResult(retval);
|
||||
}
|
||||
|
||||
int slsReceiverTCPIPInterface::set_udp_port(Interface &socket) {
|
||||
auto arg = socket.Receive<int>();
|
||||
VerifyIdle(socket);
|
||||
FILE_LOG(logDEBUG1) << "Setting UDP Port:" << arg;
|
||||
impl()->setUDPPortNumber(arg);
|
||||
return socket.Send(OK);
|
||||
}
|
||||
|
||||
int slsReceiverTCPIPInterface::set_udp_port2(Interface &socket) {
|
||||
auto arg = socket.Receive<int>();
|
||||
VerifyIdle(socket);
|
||||
if (myDetectorType != JUNGFRAU && myDetectorType != EIGER) {
|
||||
throw RuntimeError("UDP Destination Port2 not implemented for this detector");
|
||||
}
|
||||
FILE_LOG(logDEBUG1) << "Setting UDP Port:" << arg;
|
||||
impl()->setUDPPortNumber2(arg);
|
||||
return socket.Send(OK);
|
||||
}
|
||||
|
||||
int slsReceiverTCPIPInterface::set_num_interfaces(Interface &socket) {
|
||||
auto arg = socket.Receive<int>();
|
||||
arg = (arg > 1 ? 2 : 1);
|
||||
VerifyIdle(socket);
|
||||
if (myDetectorType != JUNGFRAU) {
|
||||
throw RuntimeError("Number of interfaces not implemented for this detector");
|
||||
}
|
||||
FILE_LOG(logDEBUG1) << "Setting Number of UDP Interfaces:" << arg;
|
||||
if (impl()->setNumberofUDPInterfaces(arg) == FAIL) {
|
||||
throw RuntimeError("Failed to set number of interfaces");
|
||||
}
|
||||
return socket.Send(OK);
|
||||
}
|
Reference in New Issue
Block a user