mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-13 05:17:13 +02:00
Dev/fix port size (#805)
* port datatype changing from int to uint16_t * throwing for -1 given for uint16_t ports
This commit is contained in:
@ -23,7 +23,7 @@ void BinaryDataFile::CreateFirstBinaryDataFile(const std::string &fNamePrefix,
|
||||
const uint64_t fIndex,
|
||||
const bool ovEnable,
|
||||
const bool sMode,
|
||||
const uint32_t uPortNumber,
|
||||
const uint16_t uPortNumber,
|
||||
const uint32_t mFramesPerFile) {
|
||||
|
||||
subFileIndex = 0;
|
||||
|
@ -16,7 +16,7 @@ class BinaryDataFile : private virtual slsDetectorDefs, public File {
|
||||
void CloseFile() override;
|
||||
void CreateFirstBinaryDataFile(const std::string &fNamePrefix,
|
||||
const uint64_t fIndex, const bool ovEnable,
|
||||
const bool sMode, const uint32_t uPortNumber,
|
||||
const bool sMode, const uint16_t uPortNumber,
|
||||
const uint32_t mFramesPerFile) override;
|
||||
|
||||
void WriteToFile(char *imageData, sls_receiver_header &header,
|
||||
|
@ -41,10 +41,9 @@ ClientInterface::~ClientInterface() {
|
||||
tcpThread->join();
|
||||
}
|
||||
|
||||
ClientInterface::ClientInterface(int portNumber)
|
||||
: detType(GOTTHARD),
|
||||
portNumber(portNumber > 0 ? portNumber : DEFAULT_TCP_RX_PORTNO),
|
||||
server(portNumber) {
|
||||
ClientInterface::ClientInterface(uint16_t portNumber)
|
||||
: detType(GOTTHARD), portNumber(portNumber), server(portNumber) {
|
||||
validatePortNumber(portNumber);
|
||||
functionTable();
|
||||
parentThreadId = gettid();
|
||||
tcpThread =
|
||||
@ -1064,9 +1063,12 @@ int ClientInterface::get_file_format(Interface &socket) {
|
||||
}
|
||||
|
||||
int ClientInterface::set_streaming_port(Interface &socket) {
|
||||
auto port = socket.Receive<int>();
|
||||
if (port < 0) {
|
||||
throw RuntimeError("Invalid zmq port " + std::to_string(port));
|
||||
auto port = socket.Receive<uint16_t>();
|
||||
try {
|
||||
validatePortNumber(port);
|
||||
} catch (...) {
|
||||
throw RuntimeError(
|
||||
"Could not set streaming (zmq) port number. Invalid value.");
|
||||
}
|
||||
verifyIdle(socket);
|
||||
impl()->setStreamingPort(port);
|
||||
@ -1074,7 +1076,7 @@ int ClientInterface::set_streaming_port(Interface &socket) {
|
||||
}
|
||||
|
||||
int ClientInterface::get_streaming_port(Interface &socket) {
|
||||
int retval = impl()->getStreamingPort();
|
||||
uint16_t retval = impl()->getStreamingPort();
|
||||
LOG(logDEBUG1) << "streaming port:" << retval;
|
||||
return socket.sendResult(retval);
|
||||
}
|
||||
@ -1449,7 +1451,7 @@ int ClientInterface::set_udp_ip2(Interface &socket) {
|
||||
}
|
||||
|
||||
int ClientInterface::set_udp_port(Interface &socket) {
|
||||
auto arg = socket.Receive<int>();
|
||||
auto arg = socket.Receive<uint16_t>();
|
||||
verifyIdle(socket);
|
||||
LOG(logDEBUG1) << "Setting UDP Port:" << arg;
|
||||
impl()->setUDPPortNumber(arg);
|
||||
@ -1457,7 +1459,7 @@ int ClientInterface::set_udp_port(Interface &socket) {
|
||||
}
|
||||
|
||||
int ClientInterface::set_udp_port2(Interface &socket) {
|
||||
auto arg = socket.Receive<int>();
|
||||
auto arg = socket.Receive<uint16_t>();
|
||||
verifyIdle(socket);
|
||||
if (detType != JUNGFRAU && detType != MOENCH && detType != EIGER &&
|
||||
detType != GOTTHARD2) {
|
||||
|
@ -17,7 +17,7 @@ class ServerInterface;
|
||||
class ClientInterface : private virtual slsDetectorDefs {
|
||||
enum numberMode { DEC, HEX };
|
||||
detectorType detType;
|
||||
int portNumber{0};
|
||||
uint16_t portNumber{0};
|
||||
ServerSocket server;
|
||||
std::unique_ptr<Implementation> receiver;
|
||||
std::unique_ptr<std::thread> tcpThread;
|
||||
@ -29,7 +29,7 @@ class ClientInterface : private virtual slsDetectorDefs {
|
||||
|
||||
public:
|
||||
virtual ~ClientInterface();
|
||||
ClientInterface(int portNumber = -1);
|
||||
ClientInterface(uint16_t portNumber = DEFAULT_TCP_RX_PORTNO);
|
||||
std::string getReceiverVersion();
|
||||
|
||||
//***callback functions***
|
||||
|
@ -127,7 +127,7 @@ void DataProcessor::CreateFirstFiles(const std::string &fileNamePrefix,
|
||||
const uint64_t fileIndex,
|
||||
const bool overWriteEnable,
|
||||
const bool silentMode,
|
||||
const uint32_t udpPortNumber,
|
||||
const uint16_t udpPortNumber,
|
||||
const uint64_t numImages,
|
||||
const bool detectorDataStream) {
|
||||
if (dataFile == nullptr) {
|
||||
|
@ -56,7 +56,7 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
|
||||
|
||||
void CreateFirstFiles(const std::string &fileNamePrefix,
|
||||
const uint64_t fileIndex, const bool overWriteEnable,
|
||||
const bool silentMode, const uint32_t udpPortNumber,
|
||||
const bool silentMode, const uint16_t udpPortNumber,
|
||||
const uint64_t numImages,
|
||||
const bool detectorDataStream);
|
||||
#ifdef HDF5C
|
||||
|
@ -84,8 +84,8 @@ void DataStreamer::RecordFirstIndex(uint64_t fnum, size_t firstImageIndex) {
|
||||
<< ", First Streamer Index:" << fnum;
|
||||
}
|
||||
|
||||
void DataStreamer::CreateZmqSockets(uint32_t port, const IpAddr ip, int hwm) {
|
||||
uint32_t portnum = port + index;
|
||||
void DataStreamer::CreateZmqSockets(uint16_t port, const IpAddr ip, int hwm) {
|
||||
uint16_t portnum = port + index;
|
||||
std::string sip = ip.str();
|
||||
try {
|
||||
zmqSocket = new ZmqSocket(portnum, (ip != 0 ? sip.c_str() : nullptr));
|
||||
|
@ -48,7 +48,7 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject {
|
||||
* @param ip streaming source ip
|
||||
* @param hwm streaming high water mark
|
||||
*/
|
||||
void CreateZmqSockets(uint32_t port, const IpAddr ip, int hwm);
|
||||
void CreateZmqSockets(uint16_t port, const IpAddr ip, int hwm);
|
||||
void CloseZmqSocket();
|
||||
void RestreamStop();
|
||||
|
||||
|
@ -58,7 +58,7 @@ class File : private virtual slsDetectorDefs {
|
||||
virtual void CreateFirstHDF5DataFile(
|
||||
const std::string &fileNamePrefix, const uint64_t fileIndex,
|
||||
const bool overWriteEnable, const bool silentMode,
|
||||
const uint32_t udpPortNumber, const uint32_t maxFramesPerFile,
|
||||
const uint16_t udpPortNumber, const uint32_t maxFramesPerFile,
|
||||
const uint64_t numImages, const uint32_t nPixelsX,
|
||||
const uint32_t nPixelsY, const uint32_t dynamicRange) {
|
||||
LOG(logERROR)
|
||||
@ -70,7 +70,7 @@ class File : private virtual slsDetectorDefs {
|
||||
const uint64_t fileIndex,
|
||||
const bool overWriteEnable,
|
||||
const bool silentMode,
|
||||
const uint32_t udpPortNumber,
|
||||
const uint16_t udpPortNumber,
|
||||
const uint32_t maxFramesPerFile) {
|
||||
LOG(logERROR)
|
||||
<< "This is a generic function CreateFirstBinaryDataFile that "
|
||||
|
@ -88,7 +88,7 @@ void HDF5DataFile::CloseFile() {
|
||||
|
||||
void HDF5DataFile::CreateFirstHDF5DataFile(
|
||||
const std::string &fNamePrefix, const uint64_t fIndex, const bool owEnable,
|
||||
const bool sMode, const uint32_t uPortNumber, const uint32_t mFramesPerFile,
|
||||
const bool sMode, const uint16_t uPortNumber, const uint32_t mFramesPerFile,
|
||||
const uint64_t nImages, const uint32_t nX, const uint32_t nY,
|
||||
const uint32_t dr) {
|
||||
|
||||
|
@ -25,7 +25,7 @@ class HDF5DataFile : private virtual slsDetectorDefs, public File {
|
||||
|
||||
void CreateFirstHDF5DataFile(const std::string &fNamePrefix,
|
||||
const uint64_t fIndex, const bool owEnable,
|
||||
const bool sMode, const uint32_t uPortNumber,
|
||||
const bool sMode, const uint16_t uPortNumber,
|
||||
const uint32_t mFramesPerFile,
|
||||
const uint64_t nImages, const uint32_t nX,
|
||||
const uint32_t nY, const uint32_t dr) override;
|
||||
@ -69,7 +69,7 @@ class HDF5DataFile : private virtual slsDetectorDefs, public File {
|
||||
uint64_t fileIndex{0};
|
||||
bool overWriteEnable{false};
|
||||
bool silentMode{false};
|
||||
uint32_t udpPortNumber{0};
|
||||
uint16_t udpPortNumber{0};
|
||||
|
||||
static const int EIGER_NUM_PIXELS{256 * 2 * 256};
|
||||
static const int EIGER_16_BIT_IMAGE_SIZE{EIGER_NUM_PIXELS * 2};
|
||||
|
@ -1140,17 +1140,17 @@ void Implementation::setEthernetInterface2(const std::string &c) {
|
||||
LOG(logINFO) << "Ethernet Interface 2: " << eth[1];
|
||||
}
|
||||
|
||||
uint32_t Implementation::getUDPPortNumber() const { return udpPortNum[0]; }
|
||||
uint16_t Implementation::getUDPPortNumber() const { return udpPortNum[0]; }
|
||||
|
||||
void Implementation::setUDPPortNumber(const uint32_t i) {
|
||||
void Implementation::setUDPPortNumber(const uint16_t i) {
|
||||
udpPortNum[0] = i;
|
||||
listener[0]->SetUdpPortNumber(i);
|
||||
LOG(logINFO) << "UDP Port Number[0]: " << udpPortNum[0];
|
||||
}
|
||||
|
||||
uint32_t Implementation::getUDPPortNumber2() const { return udpPortNum[1]; }
|
||||
uint16_t Implementation::getUDPPortNumber2() const { return udpPortNum[1]; }
|
||||
|
||||
void Implementation::setUDPPortNumber2(const uint32_t i) {
|
||||
void Implementation::setUDPPortNumber2(const uint16_t i) {
|
||||
udpPortNum[1] = i;
|
||||
if (listener.size() > 1) {
|
||||
listener[1]->SetUdpPortNumber(i);
|
||||
@ -1251,9 +1251,9 @@ void Implementation::setStreamingStartingFrameNumber(const uint32_t fnum) {
|
||||
LOG(logINFO) << "Streaming Start Frame num: " << streamingStartFnum;
|
||||
}
|
||||
|
||||
uint32_t Implementation::getStreamingPort() const { return streamingPort; }
|
||||
uint16_t Implementation::getStreamingPort() const { return streamingPort; }
|
||||
|
||||
void Implementation::setStreamingPort(const uint32_t i) {
|
||||
void Implementation::setStreamingPort(const uint16_t i) {
|
||||
streamingPort = i;
|
||||
LOG(logINFO) << "Streaming Port: " << streamingPort;
|
||||
}
|
||||
|
@ -117,11 +117,11 @@ class Implementation : private virtual slsDetectorDefs {
|
||||
std::string getEthernetInterface2() const;
|
||||
/* [Jungfrau][Moench] */
|
||||
void setEthernetInterface2(const std::string &c);
|
||||
uint32_t getUDPPortNumber() const;
|
||||
void setUDPPortNumber(const uint32_t i);
|
||||
uint32_t getUDPPortNumber2() const;
|
||||
uint16_t getUDPPortNumber() const;
|
||||
void setUDPPortNumber(const uint16_t i);
|
||||
uint16_t getUDPPortNumber2() const;
|
||||
/* [Eiger][Jungfrau][Moench] */
|
||||
void setUDPPortNumber2(const uint32_t i);
|
||||
void setUDPPortNumber2(const uint16_t i);
|
||||
int getUDPSocketBufferSize() const;
|
||||
void setUDPSocketBufferSize(const int s);
|
||||
int getActualUDPSocketBufferSize() const;
|
||||
@ -140,8 +140,8 @@ class Implementation : private virtual slsDetectorDefs {
|
||||
void setStreamingTimer(const uint32_t time_in_ms);
|
||||
uint32_t getStreamingStartingFrameNumber() const;
|
||||
void setStreamingStartingFrameNumber(const uint32_t fnum);
|
||||
uint32_t getStreamingPort() const;
|
||||
void setStreamingPort(const uint32_t i);
|
||||
uint16_t getStreamingPort() const;
|
||||
void setStreamingPort(const uint16_t i);
|
||||
IpAddr getStreamingSourceIP() const;
|
||||
void setStreamingSourceIP(const IpAddr ip);
|
||||
int getStreamingHwm() const;
|
||||
@ -336,7 +336,7 @@ class Implementation : private virtual slsDetectorDefs {
|
||||
|
||||
// network configuration (UDP)
|
||||
std::array<std::string, MAX_NUMBER_OF_LISTENING_THREADS> eth;
|
||||
std::array<uint32_t, MAX_NUMBER_OF_LISTENING_THREADS> udpPortNum{
|
||||
std::array<uint16_t, MAX_NUMBER_OF_LISTENING_THREADS> udpPortNum{
|
||||
{DEFAULT_UDP_DST_PORTNO, DEFAULT_UDP_DST_PORTNO + 1}};
|
||||
int actualUDPSocketBufferSize{0};
|
||||
|
||||
@ -345,7 +345,7 @@ class Implementation : private virtual slsDetectorDefs {
|
||||
uint32_t streamingFrequency{1};
|
||||
uint32_t streamingTimerInMs{DEFAULT_STREAMING_TIMER_IN_MS};
|
||||
uint32_t streamingStartFnum{0};
|
||||
uint32_t streamingPort{0};
|
||||
uint16_t streamingPort{0};
|
||||
IpAddr streamingSrcIP = IpAddr{};
|
||||
int streamingHwm{-1};
|
||||
std::map<std::string, std::string> additionalJsonHeader;
|
||||
|
@ -71,7 +71,7 @@ void Listener::SetFifo(Fifo *f) { fifo = f; }
|
||||
|
||||
void Listener::SetGeneralData(GeneralData *g) { generalData = g; }
|
||||
|
||||
void Listener::SetUdpPortNumber(const uint32_t portNumber) {
|
||||
void Listener::SetUdpPortNumber(const uint16_t portNumber) {
|
||||
udpPortNumber = portNumber;
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
|
||||
|
||||
void SetFifo(Fifo *f);
|
||||
void SetGeneralData(GeneralData *g);
|
||||
void SetUdpPortNumber(const uint32_t portNumber);
|
||||
void SetUdpPortNumber(const uint16_t portNumber);
|
||||
void SetEthernetInterface(const std::string e);
|
||||
void SetActivate(bool enable);
|
||||
void SetDetectorDatastream(bool enable);
|
||||
@ -112,7 +112,7 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
|
||||
std::atomic<runStatus> *status;
|
||||
std::unique_ptr<UdpRxSocket> udpSocket{nullptr};
|
||||
|
||||
uint32_t udpPortNumber{0};
|
||||
uint16_t udpPortNumber{0};
|
||||
std::string eth;
|
||||
bool activated{false};
|
||||
bool detectorDataStream{true};
|
||||
|
@ -3,6 +3,7 @@
|
||||
/* Creates the slsMultiReceiver for running multiple receivers form a single
|
||||
* binary */
|
||||
#include "sls/Receiver.h"
|
||||
#include "sls/ToString.h"
|
||||
#include "sls/container_utils.h"
|
||||
#include "sls/logger.h"
|
||||
#include "sls/sls_detector_defs.h"
|
||||
@ -36,14 +37,12 @@ void sigInterruptHandler(int p) { sem_post(&semaphore); }
|
||||
/**
|
||||
* prints usage of this example program
|
||||
*/
|
||||
void printHelp() {
|
||||
cprintf(
|
||||
RESET,
|
||||
"Usage:\n"
|
||||
"./slsMultiReceiver(detReceiver) [start_tcp_port] "
|
||||
"[num_receivers] [optional: 1 for call back (print frame header for "
|
||||
"debugging), 0 for none (default)]\n\n");
|
||||
exit(EXIT_FAILURE);
|
||||
std::string getHelpMessage() {
|
||||
return std::string(
|
||||
"\n\nUsage:\n"
|
||||
"./slsMultiReceiver(detReceiver) [start_tcp_port (non-zero and 16 "
|
||||
"bit)] [num_receivers] [optional: 1 for call back (print frame header "
|
||||
"for debugging), 0 for none (default)]\n\n");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -140,25 +139,31 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
/** - set default values */
|
||||
int numReceivers = 1;
|
||||
int startTCPPort = 1954;
|
||||
uint16_t startTCPPort = 1954;
|
||||
int withCallback = 0;
|
||||
sem_init(&semaphore, 1, 0);
|
||||
|
||||
/** - get number of receivers and start tcp port from command line
|
||||
* arguments */
|
||||
if (argc != 3 && argc != 4)
|
||||
printHelp();
|
||||
if ((argc == 3) && ((!sscanf(argv[1], "%d", &startTCPPort)) ||
|
||||
(!sscanf(argv[2], "%d", &numReceivers))))
|
||||
printHelp();
|
||||
if ((argc == 4) && ((!sscanf(argv[1], "%d", &startTCPPort)) ||
|
||||
(!sscanf(argv[2], "%d", &numReceivers)) ||
|
||||
(!sscanf(argv[3], "%d", &withCallback))))
|
||||
printHelp();
|
||||
try {
|
||||
if (argc == 3 || argc == 4) {
|
||||
startTCPPort = sls::StringTo<uint16_t>(argv[1]);
|
||||
if (startTCPPort == 0) {
|
||||
throw;
|
||||
}
|
||||
numReceivers = std::stoi(argv[2]);
|
||||
if (argc == 4) {
|
||||
withCallback = std::stoi(argv[3]);
|
||||
}
|
||||
} else
|
||||
throw;
|
||||
} catch (...) {
|
||||
throw std::runtime_error(getHelpMessage());
|
||||
}
|
||||
|
||||
cprintf(BLUE, "Parent Process Created [ Tid: %ld ]\n", (long)gettid());
|
||||
cprintf(RESET, "Number of Receivers: %d\n", numReceivers);
|
||||
cprintf(RESET, "Start TCP Port: %d\n", startTCPPort);
|
||||
cprintf(RESET, "Start TCP Port: %hu\n", startTCPPort);
|
||||
cprintf(RESET, "Callback Enable: %d\n", withCallback);
|
||||
|
||||
/** - Catch signal SIGINT to close files and call destructors properly */
|
||||
|
@ -2,6 +2,7 @@
|
||||
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||
#include "sls/Receiver.h"
|
||||
#include "ClientInterface.h"
|
||||
#include "sls/ToString.h"
|
||||
#include "sls/container_utils.h"
|
||||
#include "sls/logger.h"
|
||||
#include "sls/sls_detector_exceptions.h"
|
||||
@ -29,7 +30,7 @@ Receiver::~Receiver() = default;
|
||||
Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) {
|
||||
|
||||
// options
|
||||
int tcpip_port_no = 1954;
|
||||
uint16_t tcpip_port_no = 1954;
|
||||
uid_t userid = -1;
|
||||
|
||||
// parse command line for config
|
||||
@ -51,6 +52,15 @@ Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) {
|
||||
int option_index = 0;
|
||||
int c = 0;
|
||||
|
||||
std::string help_message =
|
||||
"\nUsage: " + std::string(argv[0]) + " [arguments]\n" +
|
||||
"Possible arguments are:\n" +
|
||||
"\t-t, --rx_tcpport <port> : TCP Communication Port with "
|
||||
"client. Non-zero and 16 bit.\n" +
|
||||
"\t-u, --uid <user id> : Set effective user id if receiver "
|
||||
"\n" +
|
||||
"\t started with privileges. \n\n";
|
||||
|
||||
while (c != -1) {
|
||||
c = getopt_long(argc, argv, "hvf:t:u:", long_options, &option_index);
|
||||
|
||||
@ -61,12 +71,18 @@ Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) {
|
||||
switch (c) {
|
||||
|
||||
case 't':
|
||||
sscanf(optarg, "%d", &tcpip_port_no);
|
||||
try {
|
||||
tcpip_port_no = sls::StringTo<uint16_t>(optarg);
|
||||
validatePortNumber(tcpip_port_no);
|
||||
} catch (...) {
|
||||
throw RuntimeError("Could not scan TCP port number." +
|
||||
help_message);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
if (sscanf(optarg, "%u", &userid) != 1) {
|
||||
throw RuntimeError("Could not scan uid");
|
||||
throw RuntimeError("Could not scan uid" + help_message);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -76,19 +92,9 @@ Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) {
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
case 'h':
|
||||
std::cout << help_message << std::endl;
|
||||
exit(EXIT_SUCCESS);
|
||||
default:
|
||||
std::cout << std::endl;
|
||||
|
||||
std::string help_message =
|
||||
"Usage: " + std::string(argv[0]) + " [arguments]\n" +
|
||||
"Possible arguments are:\n" +
|
||||
"\t-t, --rx_tcpport <port> : TCP Communication Port with "
|
||||
"client. \n" +
|
||||
"\t-u, --uid <user id> : Set effective user id if receiver "
|
||||
"\n" +
|
||||
"\t started with privileges. \n\n";
|
||||
|
||||
// std::cout << help_message << std::endl;
|
||||
throw RuntimeError(help_message);
|
||||
}
|
||||
}
|
||||
@ -118,7 +124,7 @@ Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) {
|
||||
tcpipInterface = make_unique<ClientInterface>(tcpip_port_no);
|
||||
}
|
||||
|
||||
Receiver::Receiver(int tcpip_port_no) {
|
||||
Receiver::Receiver(uint16_t tcpip_port_no) {
|
||||
// might throw an exception
|
||||
tcpipInterface = make_unique<ClientInterface>(tcpip_port_no);
|
||||
}
|
||||
|
Reference in New Issue
Block a user