]> jspc29.x-matter.uni-frankfurt.de Git - trbnettools.git/commitdiff
multiple UDP Buffer suport added
authorhadaq <hadaq>
Fri, 8 Jun 2012 18:30:39 +0000 (18:30 +0000)
committerhadaq <hadaq>
Fri, 8 Jun 2012 18:30:39 +0000 (18:30 +0000)
libtrbnet/trbnet.c

index 2a7ceb6790dc4e1ab24f8f84f244ebef55e4bec3..752c2eb25a20678c75f4576d91ece2fc153273af 100644 (file)
@@ -1,4 +1,4 @@
-const char trbnet_version[] = "$Revision: 4.21 $  Local";
+const char trbnet_version[] = "$Revision: 4.22 $  Local";
 
 #include <stdlib.h>
 #include <signal.h>
@@ -168,8 +168,11 @@ static sigset_t blockSetOld;
 
 /* Semaphore handling */
 static int semid = -1;
-/* static const key_t sem_key = 0x545242;*/
-static const key_t sem_key = 0x545245;
+#if defined TRB3 
+static const key_t sem_key = 0x747262;
+#else
+static const key_t sem_key = 0x545242;
+#endif
 
 unsigned int trb_debug = 0;
 
@@ -369,24 +372,11 @@ static inline void com_reset_FPGA()
 
 #ifdef TRB3
 
-static int sendTrbPackage(size_t size)
+static int getUDPPackage()
 {
   int status;
   int i;
   
-  /* Adjust endianess ... */
-  for (i = 0; i < size; i++) {
-    if (trb_debug > 2) {
-      fprintf(stderr, "%d  0x%04x\n", i, udpBuffer[i]);
-    }
-    udpBuffer[i] = htons(udpBuffer[i]);
-  }
-  
-  if (send(trb3_sockfd, (void*)udpBuffer, size * 2, MSG_CONFIRM) == -1) {
-    trb_errno = TRB_TRB3_SOCKET_ERROR;
-    return -1;
-  }
-  
   /* GetData */
   status = recv(trb3_sockfd_in, (void*)dataBuffer, 1500, 0);
   if (status == -1) {
@@ -404,8 +394,32 @@ static int sendTrbPackage(size_t size)
     if (trb_debug > 2) {
       fprintf(stderr, "%d  0x%04x\n", i, dataBuffer[i]);
     }
+  } 
+
+  return status;
+}
+
+static int sendTrbPackage(size_t size)
+{
+  int status;
+  int i;
+  
+  /* Adjust endianess ... */
+  for (i = 0; i < size; i++) {
+    if (trb_debug > 2) {
+      fprintf(stderr, "%d  0x%04x\n", i, udpBuffer[i]);
+    }
+    udpBuffer[i] = htons(udpBuffer[i]);
   }
   
+  if (send(trb3_sockfd, (void*)udpBuffer, size * 2, MSG_CONFIRM) == -1) {
+    trb_errno = TRB_TRB3_SOCKET_ERROR;
+    return -1;
+  }
+  
+  /* GetData */
+  status = getUDPPackage();
+  
   return status;
 }
 #endif /* TRB3 */
@@ -1214,13 +1228,21 @@ int trb_fifo_read(uint8_t channel,
       trb_errno = TRB_FIFO_TIMEOUT;
       return -1;
     }
-#else
+#elif defined PEXOR
     if (tmp - dataBuffer >= dataBufferSize) {
       trb_errno = TRB_PEXOR_DATA_ERROR;
       return -1;
     }
     tmp++;
-#endif
+#else
+    if (tmp - dataBuffer >= dataBufferSize) {
+      /* Get next UDP BUffer */
+      if (getUDPPackage() <= 0) {
+        return -1;
+      }
+    }      
+    tmp = dataBuffer;
+#endif    
   } /* end while () */
 
   /* Copy StatusBits and Sequenze of TerminationPackage */