class Appl: addArgs function added.
This commit is contained in:
@@ -48,6 +48,8 @@ CYCData* cycdata;
|
|||||||
|
|
||||||
void define_args()
|
void define_args()
|
||||||
{
|
{
|
||||||
|
A.addArgs("", 0);
|
||||||
|
|
||||||
A.addItem("p_address", Appl::Param("FF"), "a", "address",
|
A.addItem("p_address", Appl::Param("FF"), "a", "address",
|
||||||
"\tebus device address (FF)",
|
"\tebus device address (FF)",
|
||||||
Appl::type_string, Appl::opt_mandatory);
|
Appl::type_string, Appl::opt_mandatory);
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ Appl& A = Appl::Instance();
|
|||||||
|
|
||||||
void define_args()
|
void define_args()
|
||||||
{
|
{
|
||||||
|
A.addArgs("", 0);
|
||||||
|
|
||||||
A.addItem("p_device", Appl::Param("/dev/ttyUSB60"), "d", "device",
|
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)",
|
"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);
|
Appl::type_string, Appl::opt_mandatory);
|
||||||
@@ -41,7 +43,7 @@ void define_args()
|
|||||||
Appl::type_string, Appl::opt_mandatory);
|
Appl::type_string, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_time", Appl::Param(10000), "t", "time",
|
A.addItem("p_time", Appl::Param(10000), "t", "time",
|
||||||
"wait time [ms] (10000)",
|
"wait time [ms] (10000)\n",
|
||||||
Appl::type_long, Appl::opt_mandatory);
|
Appl::type_long, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_help", Appl::Param(false), "h", "help",
|
A.addItem("p_help", Appl::Param(false), "h", "help",
|
||||||
|
|||||||
+12
-4
@@ -26,12 +26,14 @@ Appl& A = Appl::Instance();
|
|||||||
|
|
||||||
void define_args()
|
void define_args()
|
||||||
{
|
{
|
||||||
|
A.addArgs("type value", 2);
|
||||||
|
|
||||||
A.addItem("p_server", Appl::Param("localhost"), "s", "server",
|
A.addItem("p_server", Appl::Param("localhost"), "s", "server",
|
||||||
"servername or IP (localhost)",
|
"name or ip (localhost)",
|
||||||
Appl::type_string, Appl::opt_mandatory);
|
Appl::type_string, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_port", Appl::Param(8888), "p", "port",
|
A.addItem("p_port", Appl::Param(8888), "p", "port",
|
||||||
"\tport (8888)",
|
"port (8888)\n",
|
||||||
Appl::type_int, Appl::opt_mandatory);
|
Appl::type_int, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_help", Appl::Param(false), "h", "help",
|
A.addItem("p_help", Appl::Param(false), "h", "help",
|
||||||
@@ -56,11 +58,17 @@ int main(int argc, char* argv[])
|
|||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cout << "1: " << A.getArg(1) << std::endl;
|
||||||
|
std::cout << "2: " << A.getArg(2) << std::endl;
|
||||||
|
|
||||||
TCPClient* client = new TCPClient();
|
TCPClient* client = new TCPClient();
|
||||||
TCPSocket* socket = client->connect(A.getParam<const char*>("p_server"), A.getParam<int>("p_port"));
|
TCPSocket* socket = client->connect(A.getParam<const char*>("p_server"), A.getParam<int>("p_port"));
|
||||||
//~ TCPSocket* socket = client->connect(A.getParam<const char*>("p_server"), A.getParam<int>("p_port"));
|
|
||||||
|
|
||||||
delete socket;
|
if (socket != NULL) {
|
||||||
|
socket->send("help", 4);
|
||||||
|
delete socket;
|
||||||
|
}
|
||||||
|
|
||||||
delete client;
|
delete client;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+12
-2
@@ -34,6 +34,12 @@ Appl::~Appl()
|
|||||||
m_params.clear();
|
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,
|
void Appl::addItem(const char* name, Param param, const char* shortname,
|
||||||
const char* longname, const char* description,
|
const char* longname, const char* description,
|
||||||
Datatype datatype, Optiontype optiontype)
|
Datatype datatype, Optiontype optiontype)
|
||||||
@@ -56,8 +62,12 @@ void Appl::addItem(const char* name, Param param, const char* shortname,
|
|||||||
void Appl::printArgs()
|
void Appl::printArgs()
|
||||||
{
|
{
|
||||||
std::cerr << std::endl << "Usage:" << std::endl << " "
|
std::cerr << std::endl << "Usage:" << std::endl << " "
|
||||||
<< m_argv[0].substr(2) << " [Options]" << std::endl
|
<< m_argv[0].substr(2) << " [Options]" ;
|
||||||
<< std::endl << "Options:" << std::endl;
|
|
||||||
|
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++) {
|
for (a_it = m_args.begin(); a_it < m_args.end(); a_it++) {
|
||||||
const char* c = (strlen(a_it->shortname) == 1) ? a_it->shortname : " ";
|
const char* c = (strlen(a_it->shortname) == 1) ? a_it->shortname : " ";
|
||||||
|
|||||||
@@ -61,6 +61,9 @@ public:
|
|||||||
|
|
||||||
~Appl();
|
~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,
|
void addItem(const char* name, Param param, const char* shortname,
|
||||||
const char* longname, const char* description,
|
const char* longname, const char* description,
|
||||||
Datatype datatype, Optiontype optiontype);
|
Datatype datatype, Optiontype optiontype);
|
||||||
@@ -84,6 +87,9 @@ private:
|
|||||||
Optiontype optiontype;
|
Optiontype optiontype;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::string m_argTxt;
|
||||||
|
int m_argNum;
|
||||||
|
|
||||||
int m_argc;
|
int m_argc;
|
||||||
std::vector<std::string> m_argv;
|
std::vector<std::string> m_argv;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -67,7 +67,7 @@ TCPSocket* TCPClient::connect(const std::string& server, const int& port)
|
|||||||
}
|
}
|
||||||
|
|
||||||
address.sin_family = AF_INET;
|
address.sin_family = AF_INET;
|
||||||
address.sin_port = port;
|
address.sin_port = htons(port);
|
||||||
|
|
||||||
int sfd = socket(AF_INET, SOCK_STREAM, 0);
|
int sfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (sfd < 0)
|
if (sfd < 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user