Skip to content

Commit

Permalink
900: fixed invalid arguments to slsmultireceiver (#1039)
Browse files Browse the repository at this point in the history
* wasnt showing error message for invalid arguments to slsmultireceiver
* allow 0 arguments to act like an slsReceiver with start tcp port 1954 and just 1 receiver
  • Loading branch information
thattil authored Nov 21, 2024
1 parent 0b6d0f9 commit 9a9e25a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
3 changes: 3 additions & 0 deletions RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ This document describes the differences between v9.0.0 and v8.0.2
* [Gotthard I] fixed header stripping fixing segfault.


* Error or help message for invalid arguments to slsMultiReceiver.


Simulator
---------

Expand Down
52 changes: 32 additions & 20 deletions slsReceiverSoftware/src/MultiReceiverApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ void sigInterruptHandler(int p) { sem_post(&semaphore); }
* prints usage of this example program
*/
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");
std::ostringstream os;
os << "\nUsage:\n"
<< "./slsMultiReceiver [start tcp port] [num recevers] [call back option (optional)]\n"
<< "\t - tcp port has to be non-zero and 16 bit\n"
<< "\t - call back option is 0 (disabled) by default, 1 prints frame header for debugging\n";
return os.str();
}

/**
Expand Down Expand Up @@ -159,26 +160,37 @@ int main(int argc, char *argv[]) {

/** - set default values */
int numReceivers = 1;
uint16_t startTCPPort = 1954;
uint16_t startTCPPort = DEFAULT_TCP_RX_PORTNO;
int withCallback = 0;
sem_init(&semaphore, 1, 0);

/** - get number of receivers and start tcp port from command line
* arguments */
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());
if (argc > 1) {
try {
if (argc == 3 || argc == 4) {
startTCPPort = sls::StringTo<uint16_t>(argv[1]);
if (startTCPPort == 0) {
throw std::runtime_error("Invalid start tcp port");
}
numReceivers = std::stoi(argv[2]);
if (numReceivers > 1024) {
cprintf(RED, "Did you mix up the order of the arguments?\n%s\n", getHelpMessage().c_str());
return EXIT_FAILURE;
}
if (numReceivers == 0) {
cprintf(RED, "Invalid number of receivers.\n%s\n", getHelpMessage().c_str());
return EXIT_FAILURE;
}
if (argc == 4) {
withCallback = std::stoi(argv[3]);
}
} else
throw std::runtime_error("Invalid number of arguments");
} catch (const std::exception& e) {
cprintf(RED, "Error: %s\n%s\n", e.what(), getHelpMessage().c_str());
return EXIT_FAILURE;
}
}

cprintf(BLUE, "Parent Process Created [ Tid: %ld ]\n", (long)gettid());
Expand Down

0 comments on commit 9a9e25a

Please sign in to comment.