Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
janekbaraniewski committed Apr 29, 2024
1 parent e745ddd commit f9acc5f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 79 deletions.
39 changes: 3 additions & 36 deletions src/SerialClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)});
Expand All @@ -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<string>()->default_value("127.0.0.1"), "Server IP address")
// ("port,p", value<unsigned short>()->default_value(12345), "Server port")
// ("vsp,v", value<string>()->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<string>();
// unsigned short server_port = vm["port"].as<unsigned short>();
// string vsp_name = vm["vsp"].as<string>();

// 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;
// }
43 changes: 0 additions & 43 deletions src/SerialServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>()->default_value("/dev/ttyUSB0"), "Device name")
// ("baud,b", value<unsigned int>()->default_value(9600), "Baud rate")
// ("port,p", value<unsigned short>()->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<string>();
// unsigned int baud_rate = vm["baud"].as<unsigned int>();
// unsigned short port = vm["port"].as<unsigned short>();

// 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

0 comments on commit f9acc5f

Please sign in to comment.