Commit ccbdc8a8 authored by Pavel Vainerman's avatar Pavel Vainerman

Добавил в утилиты тестирования возможность задать количество циклов обмена.

До этого была "безконечно" пока не прервёшь программу.
parent 8171aa11
......@@ -23,13 +23,14 @@ static struct option longopts[] = {
// { "writefile15", required_argument, 0, 'p' },
{ "filetransfer66", required_argument, 0, 'u' },
{ "timeout", required_argument, 0, 't' },
{ "autodetect-slave", no_argument, 0, 'l' },
{ "autodetect-slave", no_argument, 0, 'q' },
{ "autodetect-speed", required_argument, 0, 'n' },
{ "device", required_argument, 0, 'd' },
{ "verbose", no_argument, 0, 'v' },
{ "myaddr", required_argument, 0, 'a' },
{ "speed", required_argument, 0, 's' },
{ "use485F", no_argument, 0, 'y' },
{ "num-cycles", required_argument, 0, 'q' },
{ NULL, 0, 0, 0 }
};
// --------------------------------------------------------------------------
......@@ -61,6 +62,7 @@ static void print_help()
printf("[-a|--myaddr] addr - Modbus address for master. Default: 0x01.\n");
printf("[-s|--speed] speed - 9600,14400,19200,38400,57600,115200. Default: 38400.\n");
printf("[-t|--timeout] msec - Timeout. Default: 2000.\n");
printf("[-l|--num-cycles] num - Number of cycles of exchange. Default: -1 - infinitely.\n");
printf("[-v|--verbose] - Print all messages to stdout\n");
}
// --------------------------------------------------------------------------
......@@ -105,10 +107,11 @@ int main( int argc, char **argv )
DebugStream dlog;
string tofile("");
int use485 = 0;
int ncycles = -1;
try
{
while( (opt = getopt_long(argc, argv, "hva:w:z:m:r:x:c:b:d:s:t:ln:u:y",longopts,&optindex)) != -1 )
while( (opt = getopt_long(argc, argv, "hva:w:z:m:r:x:c:b:d:s:t:qn:u:yl:",longopts,&optindex)) != -1 )
{
switch (opt)
{
......@@ -255,7 +258,7 @@ int main( int argc, char **argv )
verb = 1;
break;
case 'l':
case 'q':
{
if( cmd == cmdNOP )
cmd = cmdDetectSlave;
......@@ -297,6 +300,10 @@ int main( int argc, char **argv )
}
break;
case 'l':
ncycles = uni_atoi(optarg);
break;
case '?':
default:
printf("? argumnet\n");
......@@ -321,7 +328,11 @@ int main( int argc, char **argv )
mb.setSpeed(speed);
mb.setLog(dlog);
while(1)
int nc = 1;
if( ncycles > 0 )
nc = ncycles;
while( nc )
{
try
{
......@@ -579,6 +590,14 @@ int main( int argc, char **argv )
cout << "timeout..." << endl;
}
if( ncycles > 0 )
{
nc--;
if( nc <=0 )
break;
}
msleep(200);
}
}
......
......@@ -23,6 +23,7 @@ static struct option longopts[] = {
{ "myaddr", required_argument, 0, 'a' },
{ "port", required_argument, 0, 'p' },
{ "persistent-connection", no_argument, 0, 'o' },
{ "num-cycles", required_argument, 0, 'l' },
{ NULL, 0, 0, 0 }
};
// --------------------------------------------------------------------------
......@@ -42,6 +43,7 @@ static void print_help()
printf("[-p|--port] port - Modbus server port. Default: 502.\n");
printf("[-t|--timeout] msec - Timeout. Default: 2000.\n");
printf("[-o|--persistent-connection] - Use persistent-connection.\n");
printf("[-l|--num-cycles] num - Number of cycles of exchange. Default: -1 - infinitely.\n");
printf("[-v|--verbose] - Print all messages to stdout\n");
}
// --------------------------------------------------------------------------
......@@ -77,10 +79,11 @@ int main( int argc, char **argv )
ModbusRTU::ModbusAddr slaveaddr = 0x00;
int tout = 2000;
DebugStream dlog;
int ncycles = -1;
try
{
while( (opt = getopt_long(argc, argv, "hva:w:z:r:x:c:b:d:s:t:p:i:o",longopts,&optindex)) != -1 )
while( (opt = getopt_long(argc, argv, "hva:w:z:r:x:c:b:d:s:t:p:i:ol:",longopts,&optindex)) != -1 )
{
switch (opt)
{
......@@ -182,6 +185,10 @@ int main( int argc, char **argv )
persist = true;
break;
case 'l':
ncycles = uni_atoi(optarg);
break;
case '?':
default:
printf("? argumnet\n");
......@@ -216,7 +223,11 @@ int main( int argc, char **argv )
if( count > ModbusRTU::MAXDATALEN && verb )
cout << "Too long packet! Max count=" << ModbusRTU::MAXDATALEN << " (ignore...)" << endl;
while(1)
int nc = 1;
if( ncycles > 0 )
nc = ncycles;
while( nc )
{
try
{
......@@ -406,7 +417,15 @@ int main( int argc, char **argv )
cout << "timeout..." << endl;
}
if( ncycles > 0 )
{
nc--;
if( nc <=0 )
break;
}
msleep(200);
} // end of while
mb.disconnect();
......
......@@ -19,6 +19,7 @@ static struct option longopts[] = {
{ "show-data", no_argument, 0, 'd' },
{ "check-lost", no_argument, 0, 'l' },
{ "verbode", required_argument, 0, 'v' },
{ "num-cycles", required_argument, 0, 'z' },
{ NULL, 0, 0, 0 }
};
// --------------------------------------------------------------------------
......@@ -62,8 +63,9 @@ int main(int argc, char* argv[])
size_t count = 50;
bool lost = false;
bool show = false;
int ncycles = -1;
while( (opt = getopt_long(argc, argv, "hs:c:r:p:n:t:x:blvd",longopts,&optindex)) != -1 )
while( (opt = getopt_long(argc, argv, "hs:c:r:p:n:t:x:blvdz:",longopts,&optindex)) != -1 )
{
switch (opt)
{
......@@ -80,6 +82,7 @@ int main(int argc, char* argv[])
cout << "[-l|--check-lost] - Check the lost packets." << endl;
cout << "[-v|--verbose] - verbose mode." << endl;
cout << "[-d|--show-data] - show receive data." << endl;
cout << "[-z|--num-cycles] num - Number of cycles of exchange. Default: -1 - infinitely." << endl;
cout << endl;
return 0;
......@@ -129,6 +132,10 @@ int main(int argc, char* argv[])
verb = 1;
break;
case 'z':
ncycles = UniSetTypes::uni_atoi(optarg);
break;
case '?':
default:
cerr << "? argumnet" << endl;
......@@ -184,7 +191,11 @@ int main(int argc, char* argv[])
UniSetUDP::UDPPacket buf;
unsigned long prev_num=1;
while(1)
int nc = 1;
if( ncycles > 0 )
nc = ncycles;
while( nc )
{
try
{
......@@ -227,6 +238,13 @@ int main(int argc, char* argv[])
{
cerr << "(recv): catch ..." << endl;
}
if( ncycles > 0 )
{
nc--;
if( nc <=0 )
break;
}
}
}
break;
......@@ -257,7 +275,11 @@ int main(int argc, char* argv[])
UniSetUDP::UDPPacket s_buf;
while(1)
int nc = 1;
if( ncycles > 0 )
nc = ncycles;
while( nc )
{
mypack.num = packetnum++;
if( packetnum > UniSetUDP::MaxPacketNum )
......@@ -287,6 +309,13 @@ int main(int argc, char* argv[])
cerr << "(send): catch ..." << endl;
}
if( ncycles > 0 )
{
nc--;
if( nc <=0 )
break;
}
usleep(usecpause);
}
}
......
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