Commit ccbdc8a8 authored by Pavel Vainerman's avatar Pavel Vainerman

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

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