diff --git a/src/class_server/src/class_client_example.cpp b/src/class_server/src/class_client_example.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7e93b2c598a282dcd21c52cf36e2c9b7def99853 --- /dev/null +++ b/src/class_server/src/class_client_example.cpp @@ -0,0 +1,70 @@ +/** + * @file class_client_example.cpp + * @author Alfonso Dominguez <alfonso.dominguez@tecnalia.com> + * @date 2020 + * + * Copyright 2020 Tecnalia Research & Innovation. + * Distributed under the GNU GPL v3. + * For full terms see https://www.gnu.org/licenses/gpl.txt + * + * @brief CLASS client for testing purposes + */ + +#include <string> +#include <communication/udp_client.hpp> +#include <iostream> +#include <boost/chrono.hpp> +#include <boost/thread/thread.hpp> + +int main(int argc, char* argv[]) +{ + if (argc != 4) + { + std::cerr << "ERROR: Executable expects 3 arguments (IP and port where the server is listening) and port where the client will wait for server msgs"<< std::endl; + std::cerr << "Usage: ./class_client <server_host> <server_port> <local_port>" << std::endl; + return 1; + } + + UDPClient client(argv[1], argv[2], -1); + + std::string local_port = argv[3]; + + std::stringstream ss; + ss << "connect " << local_port; + std::string msg = ss.str(); + + client.send(msg); + + int numberLoopMax = 10; + int numberLoop = 0; + + std::cout << "Wait for 10 secs and then disconnect" << std::endl; + + client.send("iam DESKTOP\r\n"); + + client.send("firmware ?\r\n"); + + //client.send("device ?\r\n"); + + client.send("acq config *freq 250.0 *channels 2 *type monopolar\r\n"); + + client.send("acq stream on\r\n"); + + client.send("acq on\r\n"); + + while (numberLoop < numberLoopMax) + { + boost::this_thread::sleep_for(boost::chrono::milliseconds(1000)); + numberLoop += 1; + std::cout << numberLoop << " sec(s)" << std::endl; + } + + client.send("acq off\r\n"); + + ss.str(std::string()); + ss << "disconnect " << local_port; + msg = ss.str(); + client.send(msg); + + return 0; +}