From fe1844b2848547c935bba65ff4ed99aaa797713d Mon Sep 17 00:00:00 2001 From: hadaq Date: Thu, 18 Aug 2011 21:03:37 +0000 Subject: [PATCH] added sleep function to -n mode --- libtrbnet/trbcmd.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/libtrbnet/trbcmd.c b/libtrbnet/trbcmd.c index 9a72f7f..e16a7b0 100644 --- a/libtrbnet/trbcmd.c +++ b/libtrbnet/trbcmd.c @@ -25,7 +25,7 @@ static int hexMode = HEXMODE; -static const char trbcmd_version[] = "$Revision: 2.68 $"; +static const char trbcmd_version[] = "$Revision: 2.69 $"; #define BACKLOG 10 static uint16_t tcp_port = 55555; @@ -90,12 +90,15 @@ static void logError(int type, const char* format, ...) void usage(const char *progName) { - fprintf(stdout, "Usage: %s [-h] [-f script-file] [-n number] [-d level] " - "[-H] [-V] \n", progName); + fprintf(stdout, "Usage: %s [-h] [-f script-file] [-n number] [-s time] " + "[-d level] [-H] [-V] \n", progName); fprintf(stdout, "Options:\n"); fprintf(stdout, " -h give this help\n"); fprintf(stdout, " -f execute commands given in script-file\n"); fprintf(stdout, " -n repeat COMMAND number times, -1 = endless loop\n"); + fprintf(stdout, + " -s only if running in -n mode, " + "sleep time in useconds (usleep)\n"); fprintf(stdout, " -M turn on HighMemoryMode (maximum usage is 20MByte, default: " "3MByte)\n"); @@ -186,6 +189,7 @@ int start(int argc, char **argv) uint16_t trb_address = 0; uint16_t reg_address = 0; int loop = 1; + int sleepTime = 0; int loopCtr = 0; uint16_t trgCtr = 0; /* counter for the %ctr option */ int opt; @@ -218,6 +222,9 @@ int start(int argc, char **argv) case 'n': loop = strtol(optarg, NULL, 0); break; + case 's': + sleepTime = strtol(optarg, NULL, 0); + break; case 'd': trb_debug = strtoul(optarg, NULL, 0); break; @@ -1259,6 +1266,10 @@ int start(int argc, char **argv) } /* End script-file-loop */ trgCtr++; + + if (sleepTime > 0) { + usleep(sleepTime); + } } /* End repeat-loop */ /* Cleanup */ -- 2.43.0