Commit dd5e3175 authored by Pavel Vainerman's avatar Pavel Vainerman

(modbudtcptester): добавил функцию check - проверка соединения..

parent 0911007f
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
#include <string>
#include <getopt.h>
#include "Debug.h"
......@@ -29,6 +28,7 @@ static struct option longopts[] =
{ "persistent-connection", no_argument, 0, 'o' },
{ "num-cycles", required_argument, 0, 'l' },
{ "sleep-msec", required_argument, 0, 's' },
{ "check", no_argument, 0, 'n' },
{ NULL, 0, 0, 0 }
};
......@@ -60,6 +60,7 @@ static void print_help()
printf("[-l|--num-cycles] num - Number of cycles of exchange. Default: -1 - infinitely.\n");
printf("[-v|--verbose] - Print all messages to stdout\n");
printf("[-s|--sleep-msec] - send pause. Default: 200 msec\n");
printf("[-n|--check] - Check connection for (-i)ip (-p)port\n");
}
// --------------------------------------------------------------------------
enum Command
......@@ -75,12 +76,11 @@ enum Command
cmdWrite06,
cmdWrite0F,
cmdWrite10,
cmdDiag
cmdDiag,
cmdCheck
};
// --------------------------------------------------------------------------
static char* checkArg( int ind, int argc, char* argv[] );
// --------------------------------------------------------------------------
int main( int argc, char** argv )
{
// std::ios::sync_with_stdio(false);
......@@ -121,7 +121,7 @@ int main( int argc, char** argv )
try
{
while( (opt = getopt_long(argc, argv, "hva:w:z:r:x:c:b:d:s:t:p:i:ol:d:e:u:", longopts, &optindex)) != -1 )
while( (opt = getopt_long(argc, argv, "hvna:w:z:r:x:c:b:d:s:t:p:i:ol:d:e:u:", longopts, &optindex)) != -1 )
{
switch (opt)
{
......@@ -137,6 +137,7 @@ int main( int argc, char** argv )
if( cmd == cmdNOP )
cmd = cmdRead02;
case 'r':
if( cmd == cmdNOP )
cmd = cmdRead03;
......@@ -162,6 +163,10 @@ int main( int argc, char** argv )
}
break;
case 'n':
cmd = cmdCheck;
break;
case 'e':
{
if( cmd == cmdNOP )
......@@ -601,6 +606,13 @@ int main( int argc, char** argv )
}
}
break;
case cmdCheck:
{
bool res = ModbusTCPMaster::checkConnection(iaddr,port,tout);
cout << iaddr << ":" << port << " connection " << (res ? "OK" : "FAIL") << endl;
}
break;
case cmdNOP:
default:
......@@ -662,3 +674,8 @@ char* checkArg( int i, int argc, char* argv[] )
return 0;
}
// --------------------------------------------------------------------------
void ping( const std::string& iaddr, int port )
{
cerr << "ping2: check connection " << ModbusTCPMaster::checkConnection(iaddr,port,1000) << endl;
}
// --------------------------------------------------------------------------
......@@ -13,7 +13,7 @@
Name: libuniset2
Version: 2.1
Release: alt15.3
Release: alt16
Summary: UniSet - library for building distributed industrial control systems
......@@ -456,6 +456,9 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
# ..
%changelog
* Thu Aug 20 2015 Pavel Vainerman <pv@altlinux.ru> 2.1-alt16
- (modbustcptest): add 'check' for connection
* Tue Aug 18 2015 Pavel Vainerman <pv@altlinux.ru> 2.1-alt15.3
- minor build
......
......@@ -41,7 +41,10 @@ int ModbusTCPMaster::getNextData( unsigned char* buf, int len )
void ModbusTCPMaster::setChannelTimeout( timeout_t msec )
{
if( tcp )
{
tcp->setTimeout(msec);
tcp->setKeepAliveParams((msec > 1000 ? msec/1000 : 1));
}
}
// -------------------------------------------------------------------------
mbErrCode ModbusTCPMaster::sendData( unsigned char* buf, int len )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment