]> jspc29.x-matter.uni-frankfurt.de Git - trbnettools.git/commitdiff
now ready for RPC calls, improved stderr/stdout reallocation in tcp-mode trbcmd
authorhadaq <hadaq>
Mon, 17 May 2010 23:49:24 +0000 (23:49 +0000)
committerhadaq <hadaq>
Mon, 17 May 2010 23:49:24 +0000 (23:49 +0000)
libtrbnet/trbcmd.c
libtrbnet/trbdhcp.c
libtrbnet/trberror.c
libtrbnet/trbnet.c
libtrbnet/trbnet.h

index ec2227685ca3fd0f11a5604feaae2fc68a46ee1c..b6ed578b068cf5bedc7b4a3b24edcbf6eca38ea6 100644 (file)
 
 static int hexMode = HEXMODE;
 
-static const char trbcmd_version[] = "$Revision: 2.48 $";
+static const char trbcmd_version[] = "$Revision: 2.49 $";
 
 #define BACKLOG 10
 static uint16_t tcp_port = 55555;
 static int tcp_debug = 0;        /* turn to 0 to suppress TCP/IP output */
 
-static FILE* STDOUT = NULL;
-static FILE* STDERR = NULL;
-
 /* ---- User Buffer Size ----------------------------------------------- */
 
 static size_t NUM_ENDPOINTS = 1024;     /* Maximum of 16KByte */
@@ -53,74 +50,74 @@ static size_t USER_BUFFER_SIZE = 0;
 
 void usage(const char *progName)
 {
-  fprintf(STDOUT, "Usage: %s [-h] [-f script-file] [-n number] [-d level] "
+  fprintf(stdout, "Usage: %s [-h] [-f script-file] [-n number] [-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,
+  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,
           "  -M    turn on HighMemoryMode (maximum usage is 20MByte, default: "
           "3MByte)\n");
-  fprintf(STDOUT, "  -d    turn on Debugging Information\n");
-  fprintf(STDOUT, "        level 1: TRB_Package debugging\n");
-  fprintf(STDOUT, "        level 2: +FIFO debugging\n");
-  fprintf(STDOUT, "  -D    FIFO DMA-Mode\n");
-  fprintf(STDOUT,
+  fprintf(stdout, "  -d    turn on Debugging Information\n");
+  fprintf(stdout, "        level 1: TRB_Package debugging\n");
+  fprintf(stdout, "        level 2: +FIFO debugging\n");
+  fprintf(stdout, "  -D    FIFO DMA-Mode\n");
+  fprintf(stdout,
           "  -H    hex-mode: all arguments will be interpreted "
           "as hexadecimal-numbers\n");
-  fprintf(STDOUT, "  -V    version number\n");
-  fprintf(STDOUT, "\nCommands:\n");
-  fprintf(STDOUT, "   r <trbaddress> <register>                        -> "
+  fprintf(stdout, "  -V    version number\n");
+  fprintf(stdout, "\nCommands:\n");
+  fprintf(stdout, "   r <trbaddress> <register>                        -> "
           "read register\n");
-  fprintf(STDOUT, "   w <trbaddress> <register> <data>                 -> "
+  fprintf(stdout, "   w <trbaddress> <register> <data>                 -> "
           "write register\n");
-  fprintf(STDOUT, "   rm <trbaddress> <register> <size> <mode>         -> "
+  fprintf(stdout, "   rm <trbaddress> <register> <size> <mode>         -> "
           "read register-memory\n");
-  fprintf(STDOUT, "   wm <trbaddress> <register> <mode> <file>         -> "
+  fprintf(stdout, "   wm <trbaddress> <register> <mode> <file>         -> "
           "write to register-memory\n"
           "                                                       "
           "from ASCII-file\n"
           "                                                       "
           "('-' = stdin)\n");
-  fprintf(STDOUT, "   i <trbaddress>                                   -> "
+  fprintf(stdout, "   i <trbaddress>                                   -> "
           "read unique ID\n");
-  fprintf(STDOUT, "   s <uid> <endpoint> <trbaddress>                  -> "
+  fprintf(stdout, "   s <uid> <endpoint> <trbaddress>                  -> "
           "set trb-address\n");
-  fprintf(STDOUT, "   T <type> <random> <info> <number|%cctr>           -> "
+  fprintf(stdout, "   T <type> <random> <info> <number|%cctr>           -> "
           "send trigger\n", '%');
-  fprintf(STDOUT, "   TR <input> <type> <random> <info> <number|%cctr>  -> "
+  fprintf(stdout, "   TR <input> <type> <random> <info> <number|%cctr>  -> "
           "send trigger to RICH only\n", '%');
-  fprintf(STDOUT, "   I <type> <random> <info> <number|%cctr>           -> "
+  fprintf(stdout, "   I <type> <random> <info> <number|%cctr>           -> "
           "read IPU data\n", '%');
-  fprintf(STDOUT, "   reload <trbaddress>                              -> "
+  fprintf(stdout, "   reload <trbaddress>                              -> "
           "reload FPGA\n");
-  fprintf(STDOUT, "   reset                                            -> "
+  fprintf(stdout, "   reset                                            -> "
           "reset TRBNetwork\n");
-  fprintf(STDOUT, "   comreset                                         -> "
+  fprintf(stdout, "   comreset                                         -> "
           "reset Etrax-FIFO Logic\n");
-  fprintf(STDOUT, "   f <channel>                                      -> "
+  fprintf(stdout, "   f <channel>                                      -> "
           "flush FIFO of channel\n");
-  fprintf(STDOUT, "   R <register>                                     -> "
+  fprintf(stdout, "   R <register>                                     -> "
           "read register of the FPGA\n");
-  fprintf(STDOUT, "   W <register> <value>                             -> "
+  fprintf(stdout, "   W <register> <value>                             -> "
           "write to register of the\n"
           "                                                       "
           "FPGA\n");
-  fprintf(STDOUT, "   exit/quit                                        -> "
+  fprintf(stdout, "   exit/quit                                        -> "
           "disconnect from server\n"
           "                                                       "
           "(tcp-server mode only)\n\n");
 
-  fprintf(STDOUT, "Start as TCP/IP-Server:\n");
-  fprintf(STDOUT, "Usage: %s [-h] [-d] [-p portnumber] [-b] [-V] tcp\n",
+  fprintf(stdout, "Start as TCP/IP-Server:\n");
+  fprintf(stdout, "Usage: %s [-h] [-d] [-p portnumber] [-b] [-V] tcp\n",
           progName);
-  fprintf(STDOUT, "Options:\n");
-  fprintf(STDOUT, "  -h    give this help\n");
-  fprintf(STDOUT, "  -p    tcp port number (default: 55555)\n");
-  fprintf(STDOUT, "  -b    run in background as daemon\n");
-  fprintf(STDOUT, "  -d    turn on debugging informations (default: off)\n");
-  fprintf(STDOUT, "  -V    version number\n");
+  fprintf(stdout, "Options:\n");
+  fprintf(stdout, "  -h    give this help\n");
+  fprintf(stdout, "  -p    tcp port number (default: 55555)\n");
+  fprintf(stdout, "  -b    run in background as daemon\n");
+  fprintf(stdout, "  -d    turn on debugging informations (default: off)\n");
+  fprintf(stdout, "  -V    version number\n");
 }
 
 #define CMD_SIZE 256
@@ -194,11 +191,11 @@ int start(int argc, char **argv)
   if (strlen(scriptFileName) > 0) {
     if (strncmp(scriptFileName, "-", 256) == 0) {
       scriptFile = stdin;
-      fprintf(STDERR, "name: %s\n", "STDIN");
+      fprintf(stderr, "name: %s\n", "STDIN");
     } else {
       scriptFile = fopen(scriptFileName, "r");
       if (scriptFile == NULL) {
-        fprintf(STDERR, "Error opening ScriptFile '%s':  %s\n",
+        fprintf(stderr, "Error opening ScriptFile '%s':  %s\n",
                 scriptFileName, strerror(errno));
         return -1;
       }
@@ -239,7 +236,7 @@ int start(int argc, char **argv)
             continue;
           } else {
             /* Error reading line */
-            fprintf(STDERR, "Error reading script-file\n");
+            fprintf(stderr, "Error reading script-file\n");
             return -1;
           }
         }
@@ -268,7 +265,7 @@ int start(int argc, char **argv)
         }
 
         if (scriptFile != NULL) {
-          fprintf(STDOUT, "#Line %d:  %s\n", lineCtr, cmdLine);
+          fprintf(stdout, "#Line %d:  %s\n", lineCtr, cmdLine);
         }
       }
 
@@ -282,7 +279,7 @@ int start(int argc, char **argv)
 
         if (cmdLen != 4) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: Invalid command\n", lineCtr);
+            fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
           } else {
             usage(basename(argv[0]));
           }
@@ -295,14 +292,14 @@ int start(int argc, char **argv)
 
         /* DEBUG Info */
         if (trb_debug > 0) {
-          fprintf(STDERR,
+          fprintf(stderr,
                   "Command: WRITE: trb_address: 0x%04x, reg_address: 0x%04x, "
                   "value: 0x%08x\n", trb_address, reg_address, value);
         }
 
         if (trb_register_write(trb_address, reg_address, value) == -1) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: ", lineCtr);
+            fprintf(stderr, "Line #%d: ", lineCtr);
           }
           trb_error("write_register failed");
           if (trb_errno != TRB_ENDPOINT_NOT_REACHED) {
@@ -313,9 +310,9 @@ int start(int argc, char **argv)
           if ((trb_term.status_common != 0x01) ||
               (trb_term.status_channel != 0)) {
             if (scriptFile != NULL) {
-              fprintf(STDERR, "Line #%d: ", lineCtr);
+              fprintf(stderr, "Line #%d: ", lineCtr);
             }
-            fprintf(STDERR, "WARNING Status-Bits:\n%s\n",
+            fprintf(stderr, "WARNING Status-Bits:\n%s\n",
                     trb_strterm(trb_term));
           }
         }
@@ -332,7 +329,7 @@ int start(int argc, char **argv)
 
         if (cmdLen != 3) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: Invalid command\n", lineCtr);
+            fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
           } else {
             usage(basename(argv[0]));
           }
@@ -344,7 +341,7 @@ int start(int argc, char **argv)
 
         /* DEBUG Info */
         if (trb_debug > 0) {
-          fprintf(STDERR,
+          fprintf(stderr,
                   "Command: READ: trb_address: 0x%04x, "
                   "reg_address: 0x%04x\n", trb_address, reg_address);
         }
@@ -357,7 +354,7 @@ int start(int argc, char **argv)
                                    data, NUM_ENDPOINTS * 2);
         if (status == -1) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: ", lineCtr);
+            fprintf(stderr, "Line #%d: ", lineCtr);
           }
           trb_error("read_register failed");
           if (trb_errno != TRB_ENDPOINT_NOT_REACHED) {
@@ -365,16 +362,16 @@ int start(int argc, char **argv)
           }
         } else {
           for (i = 0; i < status; i += 2) {
-            fprintf(STDOUT, "0x%04x  0x%08x\n", data[i], data[i + 1]);
+            fprintf(stdout, "0x%04x  0x%08x\n", data[i], data[i + 1]);
           }
 
           /* Check Status-Bits */
           if ((trb_term.status_common != 0x01) ||
               (trb_term.status_channel != 0)) {
             if (scriptFile != NULL) {
-              fprintf(STDERR, "Line #%d: ", lineCtr);
+              fprintf(stderr, "Line #%d: ", lineCtr);
             }
-            fprintf(STDERR, "WARNING Status-Bits:\n%s\n",
+            fprintf(stderr, "WARNING Status-Bits:\n%s\n",
                     trb_strterm(trb_term));
           }
         }
@@ -397,7 +394,7 @@ int start(int argc, char **argv)
 
         if (cmdLen != 5) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: Invalid command\n", lineCtr);
+            fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
           } else {
             usage(basename(argv[0]));
           }
@@ -411,7 +408,7 @@ int start(int argc, char **argv)
 
         /* DEBUG Info */
         if (trb_debug > 0) {
-          fprintf(STDERR,
+          fprintf(stderr,
                   "Command: READ_MEM: "
                   "trb_address: 0x%04x, "
                   "reg_address: 0x%04x, "
@@ -427,7 +424,7 @@ int start(int argc, char **argv)
                                        size, data, USER_BUFFER_SIZE);
         if (status == -1) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: ", lineCtr);
+            fprintf(stderr, "Line #%d: ", lineCtr);
           }
           trb_error("read_register_mem failed");
           if (trb_errno != TRB_ENDPOINT_NOT_REACHED) {
@@ -439,9 +436,9 @@ int start(int argc, char **argv)
           end = p + status;
           while (p < end) {
             len = (*p >> 16) & 0xffff;
-            fprintf(STDOUT, "H: 0x%04x  0x%04x\n", (*p++) & 0xffff, len);
+            fprintf(stdout, "H: 0x%04x  0x%04x\n", (*p++) & 0xffff, len);
             for (i = 0; (i < len) && (p < end); i++) {
-              fprintf(STDOUT, "0x%04x  0x%08x\n",
+              fprintf(stdout, "0x%04x  0x%08x\n",
                       (option == 0 ? reg_address + i : i),
                       *p++);
             }
@@ -450,9 +447,9 @@ int start(int argc, char **argv)
           if ((trb_term.status_common != 0x01) ||
               (trb_term.status_channel != 0)) {
             if (scriptFile != NULL) {
-              fprintf(STDERR, "Line #%d: ", lineCtr);
+              fprintf(stderr, "Line #%d: ", lineCtr);
             }
-            fprintf(STDERR, "WARNING Status-Bits:\n%s\n",
+            fprintf(stderr, "WARNING Status-Bits:\n%s\n",
                     trb_strterm(trb_term));
           }
         }
@@ -476,7 +473,7 @@ int start(int argc, char **argv)
 
         if (cmdLen != 5) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: Invalid command\n", lineCtr);
+            fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
           } else {
             usage(basename(argv[0]));
           }
@@ -494,7 +491,7 @@ int start(int argc, char **argv)
         } else {
           file = fopen(fileName, "r");
           if (file == NULL) {
-            fprintf(STDERR, "Error opening file '%s': %s\n",
+            fprintf(stderr, "Error opening file '%s': %s\n",
                     fileName, strerror(errno));
             return -1;
           }
@@ -517,7 +514,7 @@ int start(int argc, char **argv)
 
         /* DEBUG Info */
         if (trb_debug > 0) {
-          fprintf(STDERR,
+          fprintf(stderr,
                   "Command: WRITE_MEM: trb_address: 0x%04x, "
                   "reg_address: 0x%04x, "
                   "option: %d, "
@@ -530,7 +527,7 @@ int start(int argc, char **argv)
                                         data, size);
         if (status == -1) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: ", lineCtr);
+            fprintf(stderr, "Line #%d: ", lineCtr);
           }
           trb_error("write_register_memory failed");
           if (trb_errno != TRB_ENDPOINT_NOT_REACHED) {
@@ -541,9 +538,9 @@ int start(int argc, char **argv)
           if ((trb_term.status_common != 0x01) ||
               (trb_term.status_channel != 0)) {
             if (scriptFile != NULL) {
-              fprintf(STDERR, "Line #%d: ", lineCtr);
+              fprintf(stderr, "Line #%d: ", lineCtr);
             }
-            fprintf(STDERR, "WARNING Status-Bits:\n%s\n",
+            fprintf(stderr, "WARNING Status-Bits:\n%s\n",
                     trb_strterm(trb_term));
           }
         }
@@ -562,7 +559,7 @@ int start(int argc, char **argv)
 
         if (cmdLen != 2) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: Invalid command\n", lineCtr);
+            fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
           } else {
             usage(basename(argv[0]));
           }
@@ -573,7 +570,7 @@ int start(int argc, char **argv)
 
         /* DEBUG Info */
         if (trb_debug > 0) {
-          fprintf(STDERR,
+          fprintf(stderr,
                   "Command: READ_UID: trb_address: 0x%04x\n", trb_address);
         }
 
@@ -584,7 +581,7 @@ int start(int argc, char **argv)
         status = trb_read_uid(trb_address, uidBuffer, NUM_ENDPOINTS * 4);
         if (status == -1) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: ", lineCtr);
+            fprintf(stderr, "Line #%d: ", lineCtr);
           }
           trb_error("read_uid failed");
           if (trb_errno != TRB_ENDPOINT_NOT_REACHED) {
@@ -594,7 +591,7 @@ int start(int argc, char **argv)
           for (i = 0; 
                ((i < (unsigned int)status) && (i < NUM_ENDPOINTS * 4));
                i += 4) {
-            fprintf(STDOUT, "0x%04x  0x%08x%08x  0x%02x\n",
+            fprintf(stdout, "0x%04x  0x%08x%08x  0x%02x\n",
                     uidBuffer[i + 3],
                     uidBuffer[i], uidBuffer[i + 1], uidBuffer[i + 2]);
           }
@@ -602,9 +599,9 @@ int start(int argc, char **argv)
           if ((trb_term.status_common != 0x01) ||
               (trb_term.status_channel != 0)) {
             if (scriptFile != NULL) {
-              fprintf(STDERR, "Line #%d: ", lineCtr);
+              fprintf(stderr, "Line #%d: ", lineCtr);
             }
-            fprintf(STDERR, "WARNING Status-Bits:\n%s\n",
+            fprintf(stderr, "WARNING Status-Bits:\n%s\n",
                     trb_strterm(trb_term));
           }
         }
@@ -623,7 +620,7 @@ int start(int argc, char **argv)
 
         if (cmdLen != 4) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: Invalid command\n", lineCtr);
+            fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
           } else {
             usage(basename(argv[0]));
           }
@@ -636,7 +633,7 @@ int start(int argc, char **argv)
 
         /* DEBUG Info */
         if (trb_debug > 0) {
-          fprintf(STDERR,
+          fprintf(stderr,
                   "Command: SET_ADDRESS: "
                   "uid: 0x%016llx, "
                   "endpoint: 0x%02x, "
@@ -645,7 +642,7 @@ int start(int argc, char **argv)
 
         if (trb_set_address(uid, endpoint, trb_address) == -1) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: ", lineCtr);
+            fprintf(stderr, "Line #%d: ", lineCtr);
           }
           trb_error("set_address failed");
           if (trb_errno != TRB_ENDPOINT_NOT_REACHED) {
@@ -656,9 +653,9 @@ int start(int argc, char **argv)
           if ((trb_term.status_common != 0x01) ||
               (trb_term.status_channel != 0)) {
             if (scriptFile != NULL) {
-              fprintf(STDERR, "Line #%d: ", lineCtr);
+              fprintf(stderr, "Line #%d: ", lineCtr);
             }
-            fprintf(STDERR, "WARNING Status-Bits:\n%s\n",
+            fprintf(stderr, "WARNING Status-Bits:\n%s\n",
                     trb_strterm(trb_term));
           }
         }
@@ -676,7 +673,7 @@ int start(int argc, char **argv)
 
         if (cmdLen != 5) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: Invalid command\n", lineCtr);
+            fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
           } else {
             usage(basename(argv[0]));
           }
@@ -698,7 +695,7 @@ int start(int argc, char **argv)
 
         /* DEBUG Info */
         if (trb_debug > 0) {
-          fprintf(STDERR,
+          fprintf(stderr,
                   "Command: SEND_TRIGGER: "
                   "type: 0x%01x, "
                   "random: 0x%02x, "
@@ -708,7 +705,7 @@ int start(int argc, char **argv)
 
         if (trb_send_trigger(type, info, random, number) == -1) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: ", lineCtr);
+            fprintf(stderr, "Line #%d: ", lineCtr);
           }
           trb_error("send_trigger failed");
           if (trb_errno != TRB_ENDPOINT_NOT_REACHED) {
@@ -719,9 +716,9 @@ int start(int argc, char **argv)
           if ((trb_term.status_common != 0x01) ||
               (trb_term.status_channel != 0)) {
             if (scriptFile != NULL) {
-              fprintf(STDERR, "Line #%d: ", lineCtr);
+              fprintf(stderr, "Line #%d: ", lineCtr);
             }
-            fprintf(STDERR, "WARNING Status-Bits:\n%s\n",
+            fprintf(stderr, "WARNING Status-Bits:\n%s\n",
                     trb_strterm(trb_term));
           }
         }
@@ -734,7 +731,7 @@ int start(int argc, char **argv)
 
         if (cmdLen != 1) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: Invalid command\n", lineCtr);
+            fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
           } else {
             usage(basename(argv[0]));
           }
@@ -743,12 +740,12 @@ int start(int argc, char **argv)
 
         /* DEBUG Info */
         if (trb_debug > 0) {
-          fprintf(STDERR, "Command: RESET:\n");
+          fprintf(stderr, "Command: RESET:\n");
         }
 
         if (network_reset() == -1) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: ", lineCtr);
+            fprintf(stderr, "Line #%d: ", lineCtr);
           }
           trb_error("TRBNet RESET failed");
           return -1;
@@ -762,7 +759,7 @@ int start(int argc, char **argv)
 
         if (cmdLen != 1) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: Invalid command\n", lineCtr);
+            fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
           } else {
             usage(basename(argv[0]));
           }
@@ -771,12 +768,12 @@ int start(int argc, char **argv)
 
         /* DEBUG Info */
         if (trb_debug > 0) {
-          fprintf(STDERR, "Command: COMRESET:\n");
+          fprintf(stderr, "Command: COMRESET:\n");
         }
 
         if (com_reset() == -1) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: ", lineCtr);
+            fprintf(stderr, "Line #%d: ", lineCtr);
           }
           trb_error("Etrax RESET failed");
           return -1;
@@ -790,7 +787,7 @@ int start(int argc, char **argv)
 
         if (cmdLen != 2) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: Invalid command\n", lineCtr);
+            fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
           } else {
             usage(basename(argv[0]));
           }
@@ -801,13 +798,13 @@ int start(int argc, char **argv)
 
         /* DEBUG Info */
         if (trb_debug > 0) {
-          fprintf(STDERR,
+          fprintf(stderr,
                   "Command: RELOAD: trb_address: 0x%04x\n", trb_address);
         }
 
         if (trb_register_write(trb_address, 0x0020, 0x8000) == -1) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: ", lineCtr);
+            fprintf(stderr, "Line #%d: ", lineCtr);
           }
           trb_error("FPGA reload failed");
           if (trb_errno != TRB_ENDPOINT_NOT_REACHED) {
@@ -818,9 +815,9 @@ int start(int argc, char **argv)
           if ((trb_term.status_common != 0x01) ||
               (trb_term.status_channel != 0)) {
             if (scriptFile != NULL) {
-              fprintf(STDERR, "Line #%d: ", lineCtr);
+              fprintf(stderr, "Line #%d: ", lineCtr);
             }
-            fprintf(STDERR, "WARNING Status-Bits:\n%s\n",
+            fprintf(stderr, "WARNING Status-Bits:\n%s\n",
                     trb_strterm(trb_term));
           }
         }
@@ -839,7 +836,7 @@ int start(int argc, char **argv)
 
         if (cmdLen != 6) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: Invalid command\n", lineCtr);
+            fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
           } else {
             usage(basename(argv[0]));
           }
@@ -863,7 +860,7 @@ int start(int argc, char **argv)
 
         /* DEBUG Info */
         if (trb_debug > 0) {
-          fprintf(STDERR,
+          fprintf(stderr,
                   "Command: SEND_TRIGGER: "
                   "input: 0x%01x, "
                   "type: 0x%01x, "
@@ -874,7 +871,7 @@ int start(int argc, char **argv)
 
         if (trb_send_trigger_rich(input, type, info, random, number) == -1) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: ", lineCtr);
+            fprintf(stderr, "Line #%d: ", lineCtr);
           }
           trb_error("send_trigger failed");
           if (trb_errno != TRB_ENDPOINT_NOT_REACHED) {
@@ -885,9 +882,9 @@ int start(int argc, char **argv)
           if ((trb_term.status_common != 0x01) ||
               (trb_term.status_channel != 0)) {
             if (scriptFile != NULL) {
-              fprintf(STDERR, "Line #%d: ", lineCtr);
+              fprintf(stderr, "Line #%d: ", lineCtr);
             }
-            fprintf(STDERR, "WARNING Status-Bits:\n%s\n",
+            fprintf(stderr, "WARNING Status-Bits:\n%s\n",
                     trb_strterm(trb_term));
           }
         }
@@ -908,7 +905,7 @@ int start(int argc, char **argv)
 
         if (cmdLen != 5) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: Invalid command\n", lineCtr);
+            fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
           } else {
             usage(basename(argv[0]));
           }
@@ -930,7 +927,7 @@ int start(int argc, char **argv)
 
         /* DEBUG Info */
         if (trb_debug > 0) {
-          fprintf(STDERR,
+          fprintf(stderr,
                   "Command: READ_IPU_DATA: "
                   "type: 0x%01x, "
                   "random: 0x%02x, "
@@ -946,7 +943,7 @@ int start(int argc, char **argv)
                                    buffer, USER_BUFFER_SIZE);
         if (status == -1) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: ", lineCtr);
+            fprintf(stderr, "Line #%d: ", lineCtr);
           }
           trb_error("read_ipu_data failed");
           if (trb_errno != TRB_ENDPOINT_NOT_REACHED) {
@@ -954,16 +951,16 @@ int start(int argc, char **argv)
           }
         } else {
           for (i = 0; i < status; i++) {
-            fprintf(STDOUT, "0x%08x\n", buffer[i]);
+            fprintf(stdout, "0x%08x\n", buffer[i]);
           }
 
           /* Check Status-Bits */
           if ((trb_term.status_common != 0x01) ||
               (trb_term.status_channel != 0)) {
             if (scriptFile != NULL) {
-              fprintf(STDERR, "Line #%d: ", lineCtr);
+              fprintf(stderr, "Line #%d: ", lineCtr);
             }
-            fprintf(STDERR, "WARNING Status-Bits:\n%s\n",
+            fprintf(stderr, "WARNING Status-Bits:\n%s\n",
                     trb_strterm(trb_term));
           }
         }
@@ -980,7 +977,7 @@ int start(int argc, char **argv)
 
         if (cmdLen != 2) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: Invalid command\n", lineCtr);
+            fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
           } else {
             usage(basename(argv[0]));
           }
@@ -989,12 +986,12 @@ int start(int argc, char **argv)
 
         channel = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0);
         if (trb_debug > 0) {
-          fprintf(STDERR, "Command: FIFO_FLUSH_CHANNEL #%d\n", channel);
+          fprintf(stderr, "Command: FIFO_FLUSH_CHANNEL #%d\n", channel);
         }
 
         if (trb_fifo_flush(channel) == -1) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: ", lineCtr);
+            fprintf(stderr, "Line #%d: ", lineCtr);
           }
           trb_error("trb_fifo_flush failed");
           return -1;
@@ -1011,7 +1008,7 @@ int start(int argc, char **argv)
 
         if (cmdLen != 2) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: Invalid command\n", lineCtr);
+            fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
           } else {
             usage(basename(argv[0]));
           }
@@ -1021,19 +1018,19 @@ int start(int argc, char **argv)
         reg_address = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0);
 
         if (trb_debug > 0) {
-          fprintf(STDERR,
+          fprintf(stderr,
                   "Command: READ_FIFO_REGISTER:"
                   "reg_address: 0x%04x\n", reg_address);
         }
 
         if (fpga_register_read(reg_address, &value) == -1) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: ", lineCtr);
+            fprintf(stderr, "Line #%d: ", lineCtr);
           }
           trb_error("fpga_register_read failed");
           return -1;
         } else {
-          fprintf(STDOUT, "0x%04x  0x%08x\n", reg_address, value);
+          fprintf(stdout, "0x%04x  0x%08x\n", reg_address, value);
         }
 
       } else if (strncmp(cmd[0], "W", CMD_SIZE) == 0) {
@@ -1047,7 +1044,7 @@ int start(int argc, char **argv)
 
         if (cmdLen != 3) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: Invalid command\n", lineCtr);
+            fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
           } else {
             usage(basename(argv[0]));
           }
@@ -1058,7 +1055,7 @@ int start(int argc, char **argv)
         value = strtoul(cmd[2], NULL, hexMode == 1 ? 16 : 0);
 
         if (trb_debug > 0) {
-          fprintf(STDERR,
+          fprintf(stderr,
                   "Command: WRITE_FIFO_REGISTER:"
                   "reg_address: 0x%04x, "
                   "value: 0x%08x\n", reg_address, value);
@@ -1066,7 +1063,7 @@ int start(int argc, char **argv)
 
         if (fpga_register_write(reg_address, value) == -1) {
           if (scriptFile != NULL) {
-            fprintf(STDERR, "Line #%d: ", lineCtr);
+            fprintf(stderr, "Line #%d: ", lineCtr);
           }
           trb_error("fpga_register_write failed");
           return -1;
@@ -1079,7 +1076,7 @@ int start(int argc, char **argv)
         /*******************************************/
 
         if (scriptFile != NULL) {
-          fprintf(STDERR, "Line #%d: Invalid command\n", lineCtr);
+          fprintf(stderr, "Line #%d: Invalid command\n", lineCtr);
         } else {
           usage(basename(argv[0]));
         }
@@ -1128,12 +1125,17 @@ int main(int argc, char **argv)
 {
   unsigned int i;
 
-  STDOUT = stdout;
-  STDERR = stderr;
+  stdout = stdout;
+  stderr = stderr;
 
   if (strcmp(argv[argc - 1], "tcp") != 0) {
     /* Run normal TRBCMD */
+#ifndef TRB_RPC
     init_ports();
+#else
+    trb_connect(NULL);
+#endif
+
     if (start(argc, argv) == 0) {
       exit(EXIT_SUCCESS);
     }
@@ -1270,12 +1272,19 @@ int main(int argc, char **argv)
         myPid = getpid();
         write(myFd, "\n", 1);
         atexit(atexit0);
+#ifndef TRB_RPC
         init_ports();
+#else
+        trb_connect(NULL);
+#endif     
         clientout = fdopen(myFd, "a");
-        STDOUT = clientout;
-        STDERR = clientout;
-        trb_stderr = clientout;
-
+        
+        /* redirect output */
+        fclose(stdout);
+        fclose(stderr);
+        stdout = clientout;
+        stderr = clientout;
+        
         while (1) {
           msgLen = recv(myFd, (void *)command, 256, 0);
           if (msgLen == -1) {
index 8f626d217c1dbdd0f5a998ccac768af0c7b1adf7..ef1f559dca63629192cb9559ce41c8a33afeaa34 100644 (file)
@@ -10,7 +10,7 @@
 #include <trbnet.h>
 #include <trberror.h>
 
-static const char trbdhcp_version[] = "$Revision: 1.2 $";
+static const char trbdhcp_version[] = "$Revision: 1.3 $";
 
 typedef struct {
   uint16_t address;
@@ -172,7 +172,11 @@ int main(int argc, char ** argv)
   }
   
   /* Open ports */
-  init_ports();  
+#ifndef TRB_RPC
+  init_ports();
+#else
+  trb_connect(NULL);
+#endif  
   
   /* Read present UIDs */
   status = trb_read_uid(trbAddress, trbBuffer,
index 9f61348e4138bec223470b81e027ca30cc60ad8e..2e8bf6051ad36f4fced19b2e2cb796d675c84a44 100644 (file)
@@ -2,7 +2,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "trbnet.h"
 #include "trberror.h"
 
 /* Error Handling */
@@ -14,14 +13,14 @@ TRB_TERM trb_term = {0, 0, 0, 0};
 void trb_error(const char *s)
 {
   if (s != NULL) {
-    fprintf(trb_stderr, "%s: %s\n", s, trb_strerror(trb_errno));
+    fprintf(stderr, "%s: %s\n", s, trb_strerror(trb_errno));
   } else {
     fprintf(stderr, "%s\n", trb_strerror(trb_errno));
   }
   
   /* Print Statusbits */
   if (trb_errno == TRB_STATUS_ERROR) {
-    fprintf(trb_stderr, "%s\n", trb_strterm(trb_term));
+    fprintf(stderr, "%s\n", trb_strterm(trb_term));
   }
 }
 
index 01b5c4b37d73683625c89bc9799c11a50d89a721..6e491280b4d114c6f0507004b0528bb0cf0795e5 100644 (file)
@@ -1,4 +1,4 @@
-const char trbnet_version[] = "$Revision: 2.61 $";
+const char trbnet_version[] = "$Revision: 2.62 $";
 
 #include <stdlib.h>
 #include <signal.h>
@@ -143,7 +143,6 @@ static const key_t sem_key = 0x545242;
 
 unsigned int trb_debug = 0;
 unsigned int trb_dma = 0;
-FILE* trb_stderr = NULL;
 
 /* Declaration of a TRB-Package */
 
@@ -284,101 +283,101 @@ static void TRB_Package_dump(const TRB_Package* pkg)
 {
   switch ((pkg->H0 & MASK_HEADER_TYPE) >> SHIFT_HEADER_TYPE) {
   case HEADER_DAT:
-    fprintf(trb_stderr, "H0: 0x%04x --> DATA    channel: %01d reply: %01d\n",
+    fprintf(stderr, "H0: 0x%04x --> DATA    channel: %01d reply: %01d\n",
             pkg->H0,
             (pkg->H0 & MASK_HEADER_CHANNEL) >> SHIFT_HEADER_CHANNEL,
             (pkg->H0 & MASK_HEADER_REPLY) >> SHIFT_HEADER_REPLY);
-    fprintf(trb_stderr, "F0: 0x%04x --> data0\n", pkg->F0);
-    fprintf(trb_stderr, "F1: 0x%04x --> data1\n", pkg->F1);
-    fprintf(trb_stderr, "F2: 0x%04x --> data2\n", pkg->F2);
-    fprintf(trb_stderr, "F3: 0x%04x --> data3\n", pkg->F3);
+    fprintf(stderr, "F0: 0x%04x --> data0\n", pkg->F0);
+    fprintf(stderr, "F1: 0x%04x --> data1\n", pkg->F1);
+    fprintf(stderr, "F2: 0x%04x --> data2\n", pkg->F2);
+    fprintf(stderr, "F3: 0x%04x --> data3\n", pkg->F3);
     break;
 
   case HEADER_HDR:
-    fprintf(trb_stderr, "H0: 0x%04x --> HEADER  channel: %01d reply: %01d\n",
+    fprintf(stderr, "H0: 0x%04x --> HEADER  channel: %01d reply: %01d\n",
             pkg->H0,
             (pkg->H0 & MASK_HEADER_CHANNEL) >> SHIFT_HEADER_CHANNEL,
             (pkg->H0 & MASK_HEADER_REPLY) >> SHIFT_HEADER_REPLY);
-    fprintf(trb_stderr, "F0: 0x%04x --> source address\n", pkg->F0);
-    fprintf(trb_stderr, "F1: 0x%04x --> target address\n", pkg->F1);
-    fprintf(trb_stderr, "F2: 0x%04x --> length\n", pkg->F2);
-    fprintf(trb_stderr, "F3: 0x%04x --> sequence: 0x%02x datatype: 0x%01x\n",
+    fprintf(stderr, "F0: 0x%04x --> source address\n", pkg->F0);
+    fprintf(stderr, "F1: 0x%04x --> target address\n", pkg->F1);
+    fprintf(stderr, "F2: 0x%04x --> length\n", pkg->F2);
+    fprintf(stderr, "F3: 0x%04x --> sequence: 0x%02x datatype: 0x%01x\n",
             pkg->F3,
             (pkg->F3 & MASK_SEQNR) >> SHIFT_SEQNR,
             (pkg->F3 & MASK_DATATYPE) >> SHIFT_DATATYPE);
     break;
 
   case HEADER_EOB:
-    fprintf(trb_stderr, "H0: 0x%04x --> EOB     channel: %01d reply: %01d\n",
+    fprintf(stderr, "H0: 0x%04x --> EOB     channel: %01d reply: %01d\n",
             pkg->H0,
             (pkg->H0 & MASK_HEADER_CHANNEL) >> SHIFT_HEADER_CHANNEL,
             (pkg->H0 & MASK_HEADER_REPLY) >> SHIFT_HEADER_REPLY);
-    fprintf(trb_stderr, "F0: 0x%04x --> checksum\n", pkg->F0);
-    fprintf(trb_stderr, "F1: 0x%04x --> reseved\n", pkg->F1);
-    fprintf(trb_stderr, "F2: 0x%04x --> data count\n", pkg->F2);
-    fprintf(trb_stderr, "F3: 0x%04x --> buffer number\n", pkg->F3);
+    fprintf(stderr, "F0: 0x%04x --> checksum\n", pkg->F0);
+    fprintf(stderr, "F1: 0x%04x --> reseved\n", pkg->F1);
+    fprintf(stderr, "F2: 0x%04x --> data count\n", pkg->F2);
+    fprintf(stderr, "F3: 0x%04x --> buffer number\n", pkg->F3);
     break;
 
   case HEADER_TRM:
-    fprintf(trb_stderr, "H0: 0x%04x --> TERM    channel: %01d reply: %01d\n",
+    fprintf(stderr, "H0: 0x%04x --> TERM    channel: %01d reply: %01d\n",
             pkg->H0,
             (pkg->H0 & MASK_HEADER_CHANNEL) >> SHIFT_HEADER_CHANNEL,
             (pkg->H0 & MASK_HEADER_REPLY) >> SHIFT_HEADER_REPLY);
-    fprintf(trb_stderr, "F0: 0x%04x --> checksum\n", pkg->F0);
-    fprintf(trb_stderr, "F1: 0x%04x --> statusbits channel\n", pkg->F1);
-    fprintf(trb_stderr, "F2: 0x%04x --> statusbits common\n", pkg->F2);
-    fprintf(trb_stderr, "F3: 0x%04x --> sequence: 0x%02x datatype: 0x%01x\n",
+    fprintf(stderr, "F0: 0x%04x --> checksum\n", pkg->F0);
+    fprintf(stderr, "F1: 0x%04x --> statusbits channel\n", pkg->F1);
+    fprintf(stderr, "F2: 0x%04x --> statusbits common\n", pkg->F2);
+    fprintf(stderr, "F3: 0x%04x --> sequence: 0x%02x datatype: 0x%01x\n",
             pkg->F3,
             (pkg->F3 & MASK_SEQNR) >> SHIFT_SEQNR,
             (pkg->F3 & MASK_DATATYPE) >> SHIFT_DATATYPE);
     break;
 
   case HEADER_EXT:
-    fprintf(trb_stderr, "H0: 0x%04x --> EXT     channel: %01d reply: %01d\n",
+    fprintf(stderr, "H0: 0x%04x --> EXT     channel: %01d reply: %01d\n",
             pkg->H0,
             (pkg->H0 & MASK_HEADER_CHANNEL) >> SHIFT_HEADER_CHANNEL,
             (pkg->H0 & MASK_HEADER_REPLY) >> SHIFT_HEADER_REPLY);
-    fprintf(trb_stderr, "F0: 0x%04x --> reserved\n", pkg->F0);
-    fprintf(trb_stderr, "F1: 0x%04x --> reserved\n", pkg->F1);
-    fprintf(trb_stderr, "F2: 0x%04x --> reserved\n", pkg->F2);
-    fprintf(trb_stderr, "F2: 0x%04x --> reserved\n", pkg->F3);
+    fprintf(stderr, "F0: 0x%04x --> reserved\n", pkg->F0);
+    fprintf(stderr, "F1: 0x%04x --> reserved\n", pkg->F1);
+    fprintf(stderr, "F2: 0x%04x --> reserved\n", pkg->F2);
+    fprintf(stderr, "F2: 0x%04x --> reserved\n", pkg->F3);
     break;
 
   case HEADER_ACK:
-    fprintf(trb_stderr, "H0: 0x%04x --> ACK     channel: %01d reply: %01d\n",
+    fprintf(stderr, "H0: 0x%04x --> ACK     channel: %01d reply: %01d\n",
             pkg->H0,
             (pkg->H0 & MASK_HEADER_CHANNEL) >> SHIFT_HEADER_CHANNEL,
             (pkg->H0 & MASK_HEADER_REPLY) >> SHIFT_HEADER_REPLY);
-    fprintf(trb_stderr, "F0: 0x%04x --> reserved\n", pkg->F0);
-    fprintf(trb_stderr, "F1: 0x%04x --> lenght of buffer\n", pkg->F1);
-    fprintf(trb_stderr, "F2: 0x%04x --> reserved\n", pkg->F2);
-    fprintf(trb_stderr, "F2: 0x%04x --> buffer number\n", pkg->F3);
+    fprintf(stderr, "F0: 0x%04x --> reserved\n", pkg->F0);
+    fprintf(stderr, "F1: 0x%04x --> lenght of buffer\n", pkg->F1);
+    fprintf(stderr, "F2: 0x%04x --> reserved\n", pkg->F2);
+    fprintf(stderr, "F2: 0x%04x --> buffer number\n", pkg->F3);
     break;
 
   case HEADER_SIG:
-    fprintf(trb_stderr, "H0: 0x%04x --> SIGNAL  channel: %01d reply: %01d\n",
+    fprintf(stderr, "H0: 0x%04x --> SIGNAL  channel: %01d reply: %01d\n",
             pkg->H0,
             (pkg->H0 & MASK_HEADER_CHANNEL) >> SHIFT_HEADER_CHANNEL,
             (pkg->H0 & MASK_HEADER_REPLY) >> SHIFT_HEADER_REPLY);
-    fprintf(trb_stderr, "F0: 0x%04x --> reserved\n", pkg->F0);
-    fprintf(trb_stderr, "F1: 0x%04x --> reserved\n", pkg->F1);
-    fprintf(trb_stderr, "F2: 0x%04x --> reserved\n", pkg->F2);
-    fprintf(trb_stderr, "F2: 0x%04x --> reserved\n", pkg->F3);
+    fprintf(stderr, "F0: 0x%04x --> reserved\n", pkg->F0);
+    fprintf(stderr, "F1: 0x%04x --> reserved\n", pkg->F1);
+    fprintf(stderr, "F2: 0x%04x --> reserved\n", pkg->F2);
+    fprintf(stderr, "F2: 0x%04x --> reserved\n", pkg->F3);
     break;
 
   case HEADER_ILL:
-    fprintf(trb_stderr, "H0: 0x%04x --> ILLEGAL channel: %01d reply: %01d\n",
+    fprintf(stderr, "H0: 0x%04x --> ILLEGAL channel: %01d reply: %01d\n",
             pkg->H0,
             (pkg->H0 & MASK_HEADER_CHANNEL) >> SHIFT_HEADER_CHANNEL,
             (pkg->H0 & MASK_HEADER_REPLY) >> SHIFT_HEADER_REPLY);
-    fprintf(trb_stderr, "F0: 0x%04x --> ignore\n", pkg->F0);
-    fprintf(trb_stderr, "F1: 0x%04x --> ignore\n", pkg->F1);
-    fprintf(trb_stderr, "F2: 0x%04x --> ignore\n", pkg->F2);
-    fprintf(trb_stderr, "F2: 0x%04x --> ignore\n", pkg->F3);
+    fprintf(stderr, "F0: 0x%04x --> ignore\n", pkg->F0);
+    fprintf(stderr, "F1: 0x%04x --> ignore\n", pkg->F1);
+    fprintf(stderr, "F2: 0x%04x --> ignore\n", pkg->F2);
+    fprintf(stderr, "F2: 0x%04x --> ignore\n", pkg->F3);
     break;
 
   default:
-    fprintf(trb_stderr, "INVALID\n");
+    fprintf(stderr, "INVALID\n");
   }
 }
 
@@ -393,7 +392,7 @@ static void fifo_flush(uint8_t channel)
     read32_from_FPGA(fifoAddress, &tmp);
     /* DEBUG INFO */
     if ((trb_debug > 1) && ((tmp & MASK_FIFO_VALID) != 0)) {
-      fprintf(trb_stderr, "FLUSH_FIFO_%03d:  0x%08x\n", counter, tmp);
+      fprintf(stderr, "FLUSH_FIFO_%03d:  0x%08x\n", counter, tmp);
       counter++;
     }
   } while ((tmp & MASK_FIFO_VALID) != 0);
@@ -517,7 +516,7 @@ static int trb_fifo_read(uint8_t channel,
       if ((counter % 5) == 0) {
         /* New Package begins */
         if (trb_debug > 0) {
-          fprintf(trb_stderr,
+          fprintf(stderr,
                   "-------------------------------------------------\n");
         }
         packageCtr++;
@@ -525,7 +524,7 @@ static int trb_fifo_read(uint8_t channel,
 
         /* DEBUG INFO */
         if (trb_debug > 1) {
-          fprintf(trb_stderr, "FIFO_%03d:  0x%08x\n",
+          fprintf(stderr, "FIFO_%03d:  0x%08x\n",
                   fifoDebugCtr, *tmp);
         }
       } else {
@@ -533,7 +532,7 @@ static int trb_fifo_read(uint8_t channel,
 
         /* DEBUG INFO */
         if (trb_debug > 1) {
-          fprintf(trb_stderr, "FIFO_%03d:  0x%08x\n",
+          fprintf(stderr, "FIFO_%03d:  0x%08x\n",
                   fifoDebugCtr, *tmp);
         }
 
@@ -546,7 +545,7 @@ static int trb_fifo_read(uint8_t channel,
 
       /* DEBUG INFO */
       if (trb_debug > 1) {
-        fprintf(trb_stderr, "FIFO_%03d:  0x%08x\n",
+        fprintf(stderr, "FIFO_%03d:  0x%08x\n",
                 fifoDebugCtr, *tmp);
       }
 
@@ -590,7 +589,7 @@ static int trb_fifo_read(uint8_t channel,
       /* DEBUG INFO */
       if (trb_debug > 0) {
         TRB_Package_dump(&package);
-        fprintf(trb_stderr,
+        fprintf(stderr,
                 "-------------------------------------------------\n");
       }
 
@@ -643,7 +642,7 @@ static int trb_fifo_read(uint8_t channel,
           if (dataCtr < dsize) {
             data[dataCtr++] = (uint32_t)package.F0;
 #ifdef TRB_DEBUGGER
-            fprintf(trb_stderr, "D: 0x%04x  ", data[dataCtr - 1]);
+            fprintf(stderr, "D: 0x%04x  ", data[dataCtr - 1]);
 #endif
           } else {
             fifo_flush(channel);
@@ -662,7 +661,7 @@ static int trb_fifo_read(uint8_t channel,
             data[dataCtr++] = (((uint32_t)package.F1 << 16) |
                                ((uint32_t)package.F2));
 #ifdef TRB_DEBUGGER
-            fprintf(trb_stderr, "0x%08x\n", data[dataCtr - 1]); 
+            fprintf(stderr, "0x%08x\n", data[dataCtr - 1]); 
 #endif
             endPointCtr++;
           } else {
@@ -698,7 +697,7 @@ static int trb_fifo_read(uint8_t channel,
               lastHeader = &data[dataCtr];
               data[dataCtr++] = (uint32_t)package.F0;
 #ifdef TRB_DEBUGGER
-              fprintf(trb_stderr, "D: H: 0x%04x\n", data[dataCtr - 1]);
+              fprintf(stderr, "D: H: 0x%04x\n", data[dataCtr - 1]);
 #endif
             } else {
               fifo_flush(channel);
@@ -713,7 +712,7 @@ static int trb_fifo_read(uint8_t channel,
               data[dataCtr++] = (((uint32_t)package.F1 << 16) |
                                  ((uint32_t)package.F2));
 #ifdef TRB_DEBUGGER
-              fprintf(trb_stderr,
+              fprintf(stderr,
                       "D: 0x%04x  0x%08x\n", memLen, data[dataCtr - 1]); 
 #endif
               memLen++;
@@ -776,7 +775,7 @@ static int trb_fifo_read(uint8_t channel,
                   : (((uint32_t)package.F2 << 16) |
                      ((uint32_t)package.F3));
 #ifdef TRB_DEBUGGER   
-                fprintf(trb_stderr, "D: 0x%08x\n", data[dataCtr - 1]);
+                fprintf(stderr, "D: 0x%08x\n", data[dataCtr - 1]);
 #endif
               } else {
                 fifo_flush(channel);
@@ -828,7 +827,7 @@ static int trb_fifo_read(uint8_t channel,
                 data[dataCtr++] = (uint32_t)sourceAddress;
                 endPointCtr++;
 #ifdef TRB_DEBUGGER
-                fprintf(trb_stderr, "D: 0x%04x  0x%08x%08x  0x%02x\n",
+                fprintf(stderr, "D: 0x%04x  0x%08x%08x  0x%02x\n",
                         (uint32_t)sourceAddress,
                         uidLow, uidHigh, 
                         (uint32_t)package.F0);
@@ -993,9 +992,6 @@ int init_ports()
   int memfd;
   uint32_t *mem = NULL;
   
-  /* set default stderr */
-  trb_stderr = stderr;
-
   /* Set signal mask for blocking */
   sigemptyset(&blockSet);
   sigaddset(&blockSet, SIGINT);
@@ -1097,7 +1093,7 @@ int trb_fifo_flush(uint8_t channel)
 
   /* DEBUG INFO */
   if (trb_debug > 1) {
-    fprintf(trb_stderr, "Flushing FIFO of channel# %d\n", channel);
+    fprintf(stderr, "Flushing FIFO of channel# %d\n", channel);
   }
 
   if (lockPorts() == -1) return -1;
@@ -1128,7 +1124,7 @@ int trb_register_read(uint16_t trb_address,
 
   /* DEBUG INFO */
   if (trb_debug > 0) {
-    fprintf(trb_stderr, "Init_Transfer done.\n");
+    fprintf(stderr, "Init_Transfer done.\n");
   }
 
   /* Build up package and start transfer */
@@ -1142,7 +1138,7 @@ int trb_register_read(uint16_t trb_address,
 
   /* DEBUG INFO */
   if (trb_debug > 0) {
-    fprintf(trb_stderr, "CMD_REGISTER_READ started.\n");
+    fprintf(stderr, "CMD_REGISTER_READ started.\n");
   }
 
   status = trb_fifo_read(3, FIFO_MODE_REG_READ, data, dsize);
@@ -1189,7 +1185,7 @@ int trb_register_read_mem(uint16_t trb_address,
 
   /* DEBUG INFO */
   if (trb_debug > 0) {
-    fprintf(trb_stderr, "Init_Tranfer done.\n");
+    fprintf(stderr, "Init_Tranfer done.\n");
   }
 
   /* Build up package and start transfer */
@@ -1203,7 +1199,7 @@ int trb_register_read_mem(uint16_t trb_address,
 
   /* DEBUG INFO */
   if (trb_debug > 0) {
-    fprintf(trb_stderr, "CMD_REGISTER_READ_MEM started.\n");
+    fprintf(stderr, "CMD_REGISTER_READ_MEM started.\n");
   }
 
   status = trb_fifo_read(3, FIFO_MODE_REG_READ_MEM, data, dsize);
@@ -1246,7 +1242,7 @@ int trb_register_write(uint16_t trb_address,
 
   /* DEBUG INFO */
   if (trb_debug > 0) {
-    fprintf(trb_stderr, "Init_Transfer done.\n");
+    fprintf(stderr, "Init_Transfer done.\n");
   }
 
   /* Build up package */
@@ -1260,7 +1256,7 @@ int trb_register_write(uint16_t trb_address,
 
   /* DEBUG INFO */
   if (trb_debug > 0) {
-    fprintf(trb_stderr, "CMD_REGISTER_WRITE started.\n");
+    fprintf(stderr, "CMD_REGISTER_WRITE started.\n");
   }
 
   status = trb_fifo_read(3, FIFO_MODE_REG_WRITE, NULL, 0);
@@ -1304,7 +1300,7 @@ int trb_register_write_mem(uint16_t trb_address,
     
     /* DEBUG INFO */
     if (trb_debug > 0) {
-      fprintf(trb_stderr, "Init_Transfer done.\n");
+      fprintf(stderr, "Init_Transfer done.\n");
     }
     
     /* Build up package */
@@ -1328,7 +1324,7 @@ int trb_register_write_mem(uint16_t trb_address,
     
     /* DEBUG INFO */
     if (trb_debug > 0) {
-      fprintf(trb_stderr, "CMD_REGISTER_WRITE_MEM started %d.\n", len);
+      fprintf(stderr, "CMD_REGISTER_WRITE_MEM started %d.\n", len);
     }
     
     status = trb_fifo_read(3, FIFO_MODE_REG_WRITE, NULL, 0);
@@ -1357,7 +1353,7 @@ int trb_read_uid(uint16_t trb_address,
 
   /* DEBUG INFO */
   if (trb_debug > 0) {
-    fprintf(trb_stderr, "Init_Transfer done.\n");
+    fprintf(stderr, "Init_Transfer done.\n");
   }
 
   /* Build up package and start transfer */
@@ -1371,7 +1367,7 @@ int trb_read_uid(uint16_t trb_address,
 
   /* DEBUG INFO */
   if (trb_debug > 0) {
-    fprintf(trb_stderr, "CMD_READ_UNIQUE_ID started.\n");
+    fprintf(stderr, "CMD_READ_UNIQUE_ID started.\n");
   }
 
   status = trb_fifo_read(3, FIFO_MODE_UID, (uint32_t*)data, dsize);
@@ -1411,7 +1407,7 @@ int trb_set_address(uint64_t uid,
 
   /* DEBUG INFO */
   if (trb_debug > 0) {
-    fprintf(trb_stderr, "Init_Transfer done.\n");
+    fprintf(stderr, "Init_Transfer done.\n");
   }
 
   /* Build up package and start transfer */
@@ -1429,7 +1425,7 @@ int trb_set_address(uint64_t uid,
 
   /* DEBUG INFO */
   if (trb_debug > 0) {
-    fprintf(trb_stderr, "CMD_SETADDRESS started.\n");
+    fprintf(stderr, "CMD_SETADDRESS started.\n");
   }
 
   status = trb_fifo_read(3, FIFO_MODE_SET_ADDRESS, NULL, 0);
@@ -1468,7 +1464,7 @@ int trb_ipu_data_read(uint8_t type,
 
   /* DEBUG INFO */
   if (trb_debug > 0) {
-    fprintf(trb_stderr, "Init_Transfer done.\n");
+    fprintf(stderr, "Init_Transfer done.\n");
   }
 
   /* Prepare IPU channel */
@@ -1481,7 +1477,7 @@ int trb_ipu_data_read(uint8_t type,
 
   /* DEBUG INFO */
   if (trb_debug > 0) {
-    fprintf(trb_stderr, "CMD_IPU_DATA_READ started.\n");
+    fprintf(stderr, "CMD_IPU_DATA_READ started.\n");
   }
 
   status = trb_fifo_read(1, FIFO_MODE_IPU_DATA, data, dsize);
@@ -1511,7 +1507,7 @@ int trb_send_trigger(uint8_t type,
 
   /* DEBUG INFO */
   if (trb_debug > 0) {
-    fprintf(trb_stderr, "Init_Transfer done.\n");
+    fprintf(stderr, "Init_Transfer done.\n");
   }
 
   /* Prepare trigger channel */
@@ -1529,7 +1525,7 @@ int trb_send_trigger(uint8_t type,
                   SHORT_TRANSFER | (uint32_t)(type & 0x0f));
 
   if (trb_debug > 0) {
-    fprintf(trb_stderr, "trigger started.\n");
+    fprintf(stderr, "trigger started.\n");
   }
 
   /* Check for replay packets (trigger) */
@@ -1572,7 +1568,7 @@ int trb_send_trigger_rich(uint8_t trg_input,
 
   /* DEBUG INFO */
   if (trb_debug > 0) {
-    fprintf(trb_stderr, "Init_Transfer done.\n");
+    fprintf(stderr, "Init_Transfer done.\n");
   }
 
   /* Prepare trigger channel */
@@ -1598,7 +1594,7 @@ int trb_send_trigger_rich(uint8_t trg_input,
                   SHORT_TRANSFER | (uint32_t)(type & 0x0f));
 
   if (trb_debug > 0) {
-    fprintf(trb_stderr, "trigger started.\n");
+    fprintf(stderr, "trigger started.\n");
   }
 
   /* Check for replay packets (slowcontrol) */
@@ -1627,7 +1623,7 @@ int fpga_register_read(uint16_t reg_address, uint32_t* value)
 
   /* DEBUG INFO */
   if (trb_debug > 0) {
-    fprintf(trb_stderr, "fpga_register_read started.\n");
+    fprintf(stderr, "fpga_register_read started.\n");
   }
 
   read32_from_FPGA(reg_address, value);
@@ -1645,7 +1641,7 @@ int fpga_register_write(uint16_t reg_address, uint32_t value)
 
   /* DEBUG INFO */
   if (trb_debug > 0) {
-    fprintf(trb_stderr, "fpga_register_write started.\n");
+    fprintf(stderr, "fpga_register_write started.\n");
   }
 
   write32_to_FPGA(reg_address, value);
@@ -1663,7 +1659,7 @@ int network_reset()
 
   /* DEBUG INFO */
   if (trb_debug > 0) {
-    fprintf(trb_stderr, "network_reset started.\n");
+    fprintf(stderr, "network_reset started.\n");
   }
 
   write32_to_FPGA(0x10, 0x0000);  
@@ -1683,7 +1679,7 @@ int com_reset()
 
   /* DEBUG INFO */
   if (trb_debug > 0) {
-    fprintf(trb_stderr, "com_reset started.\n");
+    fprintf(stderr, "com_reset started.\n");
   }
   
   setbitsPC(0x30000);
index afa1c06dbd2e4e7a2ca321cafe4d0fd7e9edacdc..f298b1f070852258c51bb7df4d3d49d224cf0600 100644 (file)
@@ -8,7 +8,6 @@ extern const char trbnet_version[];
 
 extern unsigned int trb_debug;
 extern unsigned int trb_dma;
-extern FILE* trb_stderr;
 
 #ifdef __cplusplus
 extern "C" {