]> jspc29.x-matter.uni-frankfurt.de Git - trbnettools.git/commitdiff
added sleep function to -n mode
authorhadaq <hadaq>
Thu, 18 Aug 2011 21:03:37 +0000 (21:03 +0000)
committerhadaq <hadaq>
Thu, 18 Aug 2011 21:03:37 +0000 (21:03 +0000)
libtrbnet/trbcmd.c

index 9a72f7f3522568b3bcdd4c65c598972914824e78..e16a7b00abd1e8e118bc9cfe9ba5d25b7673a426 100644 (file)
@@ -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] <COMMAND>\n", progName);
+  fprintf(stdout, "Usage: %s [-h] [-f script-file] [-n number] [-s time] "
+          "[-d level] [-H] [-V] <COMMAND>\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 */