From f9acc5fb9b31d5e0f10ad728f52397dfeeedbef8 Mon Sep 17 00:00:00 2001 From: Jan Baraniewski Date: Mon, 29 Apr 2024 13:54:26 +0200 Subject: [PATCH] Cleanup --- src/SerialClient.cpp | 39 +++------------------------------------ src/SerialServer.cpp | 43 ------------------------------------------- 2 files changed, 3 insertions(+), 79 deletions(-) diff --git a/src/SerialClient.cpp b/src/SerialClient.cpp index 14cdad2..7ed7448 100644 --- a/src/SerialClient.cpp +++ b/src/SerialClient.cpp @@ -9,7 +9,7 @@ using std::cerr; using std::endl; SerialClient::SerialClient(boost::asio::io_service& io_service, const std::string& server_ip, unsigned short server_port, const std::string& vsp_name) - : io_service_(io_service), socket_(io_service), vsp_(vsp_name) { // Initialize vsp_ here + : io_service_(io_service), socket_(io_service), vsp_(vsp_name) { BOOST_LOG_TRIVIAL(info) << "Initializing client..."; boost::asio::ip::tcp::resolver resolver(io_service); auto endpoint_iterator = resolver.resolve({server_ip, std::to_string(server_port)}); @@ -30,47 +30,14 @@ void SerialClient::do_read_write() { if (!ec) { std::string data(buffer_.begin(), buffer_.begin() + length); BOOST_LOG_TRIVIAL(info) << "Received data: " << data; - if (vsp_.write(data)) { // Use vsp_ to write data + if (vsp_.write(data)) { BOOST_LOG_TRIVIAL(info) << "Data written to virtual serial port."; } else { BOOST_LOG_TRIVIAL(error) << "Failed to write to virtual serial port."; } - do_read_write(); // Continue reading + do_read_write(); } else { BOOST_LOG_TRIVIAL(error) << "Read error: " << ec.message(); } }); } - -// int main(int argc, char* argv[]) { -// init_logging(); - -// try { -// options_description desc{"Options"}; -// desc.add_options() -// ("help,h", "Help screen") -// ("server,s", value()->default_value("127.0.0.1"), "Server IP address") -// ("port,p", value()->default_value(12345), "Server port") -// ("vsp,v", value()->required(), "Virtual serial port name"); - -// variables_map vm; -// store(parse_command_line(argc, argv, desc), vm); -// notify(vm); - -// if (vm.count("help")) { -// cout << desc << endl; -// return 0; -// } - -// string server_ip = vm["server"].as(); -// unsigned short server_port = vm["port"].as(); -// string vsp_name = vm["vsp"].as(); - -// SerialClient client(server_ip, server_port, vsp_name); -// client.run(); -// } catch (const std::exception& e) { -// BOOST_LOG_TRIVIAL(error) << "Exception: " << e.what(); -// cerr << "Exception: " << e.what() << endl; -// } -// return 0; -// } diff --git a/src/SerialServer.cpp b/src/SerialServer.cpp index 19474b7..27f25ee 100644 --- a/src/SerialServer.cpp +++ b/src/SerialServer.cpp @@ -46,46 +46,3 @@ void SerialServer::do_read_write() { } }); } - -// #ifndef UNIT_TEST -// int main(int argc, char* argv[]) { -// init_logging(); -// io_service io; -// tcp::acceptor acceptor(io, tcp::endpoint(tcp::v4(), 12345)); -// RealSerialPort realSerial(io); - -// try { -// options_description desc{"Options"}; -// desc.add_options() -// ("help,h", "Help screen") -// ("device,d", value()->default_value("/dev/ttyUSB0"), "Device name") -// ("baud,b", value()->default_value(9600), "Baud rate") -// ("port,p", value()->default_value(12345), "Port number"); - -// variables_map vm; -// store(parse_command_line(argc, argv, desc), vm); -// notify(vm); - -// if (vm.count("help")) { -// std::cout << desc << std::endl; -// return 0; -// } - -// string dev_name = vm["device"].as(); -// unsigned int baud_rate = vm["baud"].as(); -// unsigned short port = vm["port"].as(); - -// realSerial.open(dev_name); -// realSerial.set_option(serial_port_base::baud_rate(baud_rate)); - -// SerialServer server(io, realSerial, acceptor); -// server.run(); -// } catch (const std::exception& e) { -// BOOST_LOG_TRIVIAL(error) << "Exception: " << e.what(); -// return 1; -// } -// return 0; -// } -// #else -// #error "UNIT_TEST is defined!" -// #endif