diff --git a/fairmq/CMakeLists.txt b/fairmq/CMakeLists.txt index 1b497a0f..a241973d 100644 --- a/fairmq/CMakeLists.txt +++ b/fairmq/CMakeLists.txt @@ -176,6 +176,7 @@ If(DDS_FOUND) Set(Exe_Names ${Exe_Names} fairmq-dds-command-ui + fairmq-dds-command ) EndIf(DDS_FOUND) @@ -191,6 +192,7 @@ 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 new file mode 100644 index 00000000..7dfb4e01 --- /dev/null +++ b/fairmq/run/runDDSCommand.cxx @@ -0,0 +1,103 @@ +#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; +}