From fd09321fd92e2d39cfab342407f995c0404cee18 Mon Sep 17 00:00:00 2001 From: Radoslaw Karabowicz Date: Mon, 30 May 2016 11:25:47 +0200 Subject: [PATCH] Modified runDDSCommandUI to accept command line argument. If no arguments, it behaves like before. Removed runDDSCommand and replaced calls to it in controlDDS. --- fairmq/CMakeLists.txt | 9 --- fairmq/run/runDDSCommand.cxx | 103 --------------------------------- fairmq/run/runDDSCommandUI.cxx | 10 +++- 3 files changed, 9 insertions(+), 113 deletions(-) delete mode 100644 fairmq/run/runDDSCommand.cxx diff --git a/fairmq/CMakeLists.txt b/fairmq/CMakeLists.txt index a241973d..8fee6731 100644 --- a/fairmq/CMakeLists.txt +++ b/fairmq/CMakeLists.txt @@ -61,13 +61,6 @@ Set(LINK_DIRECTORIES ${Boost_LIBRARY_DIRS} ) -If(DDS_FOUND) - Set(LINK_DIRECTORIES - ${LINK_DIRECTORIES} - DDS_LIBRARY_DIR - ) -EndIf(DDS_FOUND) - Link_Directories(${LINK_DIRECTORIES}) Set(SRCS @@ -176,7 +169,6 @@ If(DDS_FOUND) Set(Exe_Names ${Exe_Names} fairmq-dds-command-ui - fairmq-dds-command ) EndIf(DDS_FOUND) @@ -192,7 +184,6 @@ If(DDS_FOUND) Set(Exe_Source ${Exe_Source} run/runDDSCommandUI.cxx - run/runDDSCommand.cxx ) EndIf(DDS_FOUND) diff --git a/fairmq/run/runDDSCommand.cxx b/fairmq/run/runDDSCommand.cxx deleted file mode 100644 index 7dfb4e01..00000000 --- a/fairmq/run/runDDSCommand.cxx +++ /dev/null @@ -1,103 +0,0 @@ -#include "dds_intercom.h" - -#include // raw mode console input - -#include -#include -#include -#include -#include -#include - -using namespace std; -using namespace dds::intercom_api; - -void PrintControlsHelp() -{ - cout << "To control devices use one of the following arguments:" << endl; - cout << "[c] check states, [h] help, [p] pause, [r] run, [s] stop, [t] reset task, [d] reset device, [q] end, [j] init task, [i] init device" << endl; -} - -int main(int argc, char* argv[]) -{ - try - { - if ( argc != 2 ) { - PrintControlsHelp(); - return EXIT_FAILURE; - } - - CCustomCmd ddsCustomCmd; - - // subscribe to receive messages from DDS - ddsCustomCmd.subscribe([](const string& msg, const string& condition, uint64_t senderId) - { - cout << "Received: \"" << msg << "\"" << endl; - }); - - char c = argv[1][0]; - - int result = 0; // result of the dds send - - switch (c) - { - case 'c': - cout << " > checking state of the devices" << endl; - result = ddsCustomCmd.send("check-state", ""); - break; - case 'i': - cout << " > init devices" << endl; - result = ddsCustomCmd.send("INIT_DEVICE", ""); - break; - case 'j': - cout << " > init tasks" << endl; - result = ddsCustomCmd.send("INIT_TASK", ""); - break; - case 'p': - cout << " > pause devices" << endl; - result = ddsCustomCmd.send("PAUSE", ""); - break; - case 'r': - cout << " > run tasks" << endl; - result = ddsCustomCmd.send("RUN", ""); - break; - case 's': - cout << " > stop devices" << endl; - result = ddsCustomCmd.send("STOP", ""); - break; - case 't': - cout << " > reset tasks" << endl; - result = ddsCustomCmd.send("RESET_TASK", ""); - break; - case 'd': - cout << " > reset devices" << endl; - result = ddsCustomCmd.send("RESET_DEVICE", ""); - break; - case 'h': - cout << " > help" << endl; - PrintControlsHelp(); - break; - case 'q': - cout << " > end" << endl; - result = ddsCustomCmd.send("END", ""); - break; - default: - cout << "Invalid input: [" << c << "]" << endl; - PrintControlsHelp(); - break; - } - - if (result == 1) - { - cout << "Error sending custom command" << endl; - } - usleep(50000); - } - catch (exception& e) - { - cerr << "Error: " << e.what() << endl; - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/fairmq/run/runDDSCommandUI.cxx b/fairmq/run/runDDSCommandUI.cxx index c3f56bdc..d9796a5d 100644 --- a/fairmq/run/runDDSCommandUI.cxx +++ b/fairmq/run/runDDSCommandUI.cxx @@ -7,6 +7,7 @@ #include #include #include +#include using namespace std; using namespace dds::intercom_api; @@ -38,7 +39,10 @@ int main(int argc, char* argv[]) t.c_lflag &= ~ICANON; // disable canonical input tcsetattr(STDIN_FILENO, TCSANOW, &t); // apply the new settings - PrintControlsHelp(); + if ( argc != 2 ) + PrintControlsHelp(); + else + cin.putback(argv[1][0]); while (cin >> c) { @@ -96,6 +100,10 @@ int main(int argc, char* argv[]) { cerr << "Error sending custom command" << endl; } + if ( argc == 2 ) { + usleep(50000); + return EXIT_SUCCESS; + } } // disable raw mode