From 370cac97fb309130e9370b615e46174e4986e7b2 Mon Sep 17 00:00:00 2001 From: Roland Jax Date: Mon, 2 Jun 2014 22:04:08 +0200 Subject: [PATCH] class Appl: addArgs function added. --- src/main.cpp | 2 ++ tools/ebusd_feed.cpp | 4 +++- tools/ebusd_send.cpp | 16 ++++++++++++---- utils/appl.cpp | 14 ++++++++++++-- utils/appl.h | 6 ++++++ utils/tcpsocket.cpp | 2 +- 6 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index eb6f43fe..578e5e6c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -48,6 +48,8 @@ CYCData* cycdata; void define_args() { + A.addArgs("", 0); + A.addItem("p_address", Appl::Param("FF"), "a", "address", "\tebus device address (FF)", Appl::type_string, Appl::opt_mandatory); diff --git a/tools/ebusd_feed.cpp b/tools/ebusd_feed.cpp index 39c787a7..ba479937 100644 --- a/tools/ebusd_feed.cpp +++ b/tools/ebusd_feed.cpp @@ -32,6 +32,8 @@ Appl& A = Appl::Instance(); void define_args() { + A.addArgs("", 0); + A.addItem("p_device", Appl::Param("/dev/ttyUSB60"), "d", "device", "dummy serial device (/dev/ttyUSB60)\n\t\t(hint: socat -d -d pty,raw,echo=0 pty,raw,echo=0)", Appl::type_string, Appl::opt_mandatory); @@ -41,7 +43,7 @@ void define_args() Appl::type_string, Appl::opt_mandatory); A.addItem("p_time", Appl::Param(10000), "t", "time", - "wait time [ms] (10000)", + "wait time [ms] (10000)\n", Appl::type_long, Appl::opt_mandatory); A.addItem("p_help", Appl::Param(false), "h", "help", diff --git a/tools/ebusd_send.cpp b/tools/ebusd_send.cpp index def155d2..60cfdb46 100644 --- a/tools/ebusd_send.cpp +++ b/tools/ebusd_send.cpp @@ -26,12 +26,14 @@ Appl& A = Appl::Instance(); void define_args() { + A.addArgs("type value", 2); + A.addItem("p_server", Appl::Param("localhost"), "s", "server", - "servername or IP (localhost)", + "name or ip (localhost)", Appl::type_string, Appl::opt_mandatory); A.addItem("p_port", Appl::Param(8888), "p", "port", - "\tport (8888)", + "port (8888)\n", Appl::type_int, Appl::opt_mandatory); A.addItem("p_help", Appl::Param(false), "h", "help", @@ -56,11 +58,17 @@ int main(int argc, char* argv[]) exit(EXIT_SUCCESS); } + std::cout << "1: " << A.getArg(1) << std::endl; + std::cout << "2: " << A.getArg(2) << std::endl; + TCPClient* client = new TCPClient(); TCPSocket* socket = client->connect(A.getParam("p_server"), A.getParam("p_port")); - //~ TCPSocket* socket = client->connect(A.getParam("p_server"), A.getParam("p_port")); - delete socket; + if (socket != NULL) { + socket->send("help", 4); + delete socket; + } + delete client; return 0; diff --git a/utils/appl.cpp b/utils/appl.cpp index af6014e1..53e88acc 100644 --- a/utils/appl.cpp +++ b/utils/appl.cpp @@ -34,6 +34,12 @@ Appl::~Appl() m_params.clear(); } +void Appl::addArgs(const std::string argTxt, const int argNum) +{ + m_argTxt = argTxt; + m_argNum = argNum; +} + void Appl::addItem(const char* name, Param param, const char* shortname, const char* longname, const char* description, Datatype datatype, Optiontype optiontype) @@ -56,8 +62,12 @@ void Appl::addItem(const char* name, Param param, const char* shortname, void Appl::printArgs() { std::cerr << std::endl << "Usage:" << std::endl << " " - << m_argv[0].substr(2) << " [Options]" << std::endl - << std::endl << "Options:" << std::endl; + << m_argv[0].substr(2) << " [Options]" ; + + if (m_argTxt.size() != 0) + std::cerr << " " << m_argTxt; + + std::cerr << std::endl << std::endl << "Options:" << std::endl; for (a_it = m_args.begin(); a_it < m_args.end(); a_it++) { const char* c = (strlen(a_it->shortname) == 1) ? a_it->shortname : " "; diff --git a/utils/appl.h b/utils/appl.h index 7f8d4d09..0d7e591b 100644 --- a/utils/appl.h +++ b/utils/appl.h @@ -61,6 +61,9 @@ public: ~Appl(); + void addArgs(const std::string argTxt, const int argNum); + std::string getArg(const int argNum) const { return m_argv[m_argc - 1 - m_argNum + argNum]; } + void addItem(const char* name, Param param, const char* shortname, const char* longname, const char* description, Datatype datatype, Optiontype optiontype); @@ -84,6 +87,9 @@ private: Optiontype optiontype; }; + std::string m_argTxt; + int m_argNum; + int m_argc; std::vector m_argv; diff --git a/utils/tcpsocket.cpp b/utils/tcpsocket.cpp index ed43ac80..9275bd3c 100644 --- a/utils/tcpsocket.cpp +++ b/utils/tcpsocket.cpp @@ -67,7 +67,7 @@ TCPSocket* TCPClient::connect(const std::string& server, const int& port) } address.sin_family = AF_INET; - address.sin_port = port; + address.sin_port = htons(port); int sfd = socket(AF_INET, SOCK_STREAM, 0); if (sfd < 0)