#include <csignal>
#include <thread>
#include <iostream>
#include <modbuspp.h>
#include <modbuspp/popl.h>
using namespace std;
void
sighandler (int sig) {
cout << "everything was closed." << endl << "Have a nice day !" << endl;
}
int main (int argc, char **argv) {
string host;
string port;
string serial;
string settings;
popl::OptionParser CmdLine ("Allowed options");
auto help_option = CmdLine.add<popl::Switch> ("h", "help", "produce help message");
CmdLine.add<popl::Value<string>> ("H", "host", "listening address of the server", "127.0.0.1", &host);
CmdLine.add<popl::Value<string>> ("p", "port", "server listening port", "1502", &port);
CmdLine.add<popl::Value<string>> ("P", "serial", "serial port", "/dev/ttyUSB0", &serial);
CmdLine.add<popl::Value<string>> ("s", "settings", "serial port settings", "38400E1", &settings);
auto rs485_option = CmdLine.add<popl::Switch> ("R", "rs485", "RS-485 mode (/RTS on (0) after sending)");
cout << "--- Modbus Router ---" << endl;
signal (SIGINT, sighandler);
signal (SIGTERM, sighandler);
cout << "Press CTRL+C to stop... " << endl;
try {
CmdLine.parse (argc, argv);
if (help_option->count() == 1) {
cout << CmdLine << endl;
exit (EXIT_SUCCESS);
}
if (rs485_option->count() == 1) {
}
cout << "Listening server on " <<
<< endl << endl;
std::this_thread::sleep_for (std::chrono::milliseconds (200));
}
}
}
catch (std::exception & e) {
cerr << "Error: " << e.what() << endl;
}
catch (...) {
cerr << "Unattended exception !" << endl;
}
return EXIT_FAILURE;
}