commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r7141 - in usrp2/trunk: firmware/apps host host/lib


From: eb
Subject: [Commit-gnuradio] r7141 - in usrp2/trunk: firmware/apps host host/lib
Date: Wed, 12 Dec 2007 21:41:18 -0700 (MST)

Author: eb
Date: 2007-12-12 21:41:17 -0700 (Wed, 12 Dec 2007)
New Revision: 7141

Modified:
   usrp2/trunk/firmware/apps/rx_only.c
   usrp2/trunk/host/configure.ac
   usrp2/trunk/host/lib/gri_ethernet.cc
   usrp2/trunk/host/lib/gri_ethernet.h
   usrp2/trunk/host/lib/usrp2_basic.cc
Log:
working work-in-progress ;)

Modified: usrp2/trunk/firmware/apps/rx_only.c
===================================================================
--- usrp2/trunk/firmware/apps/rx_only.c 2007-12-13 03:34:21 UTC (rev 7140)
+++ usrp2/trunk/firmware/apps/rx_only.c 2007-12-13 04:41:17 UTC (rev 7141)
@@ -86,6 +86,7 @@
   static unsigned char reply[sizeof(u2_eth_packet_t) + sizeof(u2_subpkt_t)] 
_AL4;
   unsigned char *s = &reply[sizeof(u2_eth_packet_t)];
   size_t reply_len = 0;
+  int   i;
 
   // copy 512 bytes of payload into stack buffer
 
@@ -111,7 +112,9 @@
       r->rid_mbz = 0;          // FIXME
       memcpy(r->mac_addr, eth_mac_addr(), 6);
       r->hw_rev = 0x0000;      // FIXME
-      // r->serial_no = ;      // FIXME
+      for (i = 0; i < sizeof(r->serial_no); i++)
+       r->serial_no[i] = '0';  // FIXME
+
       // r->fpga_md5sum = ;    // FIXME
       // r->sw_md5sum = ;      // FIXME
     }

Modified: usrp2/trunk/host/configure.ac
===================================================================
--- usrp2/trunk/host/configure.ac       2007-12-13 03:34:21 UTC (rev 7140)
+++ usrp2/trunk/host/configure.ac       2007-12-13 04:41:17 UTC (rev 7141)
@@ -115,7 +115,7 @@
 dnl AC_CHECK_HEADERS(linux/ppdev.h sys/mman.h sys/select.h sys/types.h)
 dnl AC_CHECK_HEADERS(sys/resource.h stdint.h sched.h signal.h sys/syscall.h)
 
-AC_CHECK_HEADERS(arpa/inet.h netinet/in.h byteswap.h)
+AC_CHECK_HEADERS(arpa/inet.h netinet/in.h byteswap.h sys/select.h)
 
 dnl Checks for typedefs, structures, and compiler characteristics.
 AC_C_CONST

Modified: usrp2/trunk/host/lib/gri_ethernet.cc
===================================================================
--- usrp2/trunk/host/lib/gri_ethernet.cc        2007-12-13 03:34:21 UTC (rev 
7140)
+++ usrp2/trunk/host/lib/gri_ethernet.cc        2007-12-13 04:41:17 UTC (rev 
7141)
@@ -157,6 +157,18 @@
 }
 
 int
+gri_ethernet::read_packet_dont_block (void *buf, int buflen, struct 
sockaddr_ll *sa)
+{
+  socklen_t    fromlen = sizeof (*sa);
+  int len = recvfrom (d_fd, buf, buflen, MSG_DONTWAIT,
+                     (sockaddr *) sa, &fromlen);
+  if (len == -1 && errno == EAGAIN)
+    return 0;
+  
+  return len;
+}
+
+int
 gri_ethernet::write_packet (const void *buf, int buflen)
 {
   int retval = send (d_fd, buf, buflen, 0);

Modified: usrp2/trunk/host/lib/gri_ethernet.h
===================================================================
--- usrp2/trunk/host/lib/gri_ethernet.h 2007-12-13 03:34:21 UTC (rev 7140)
+++ usrp2/trunk/host/lib/gri_ethernet.h 2007-12-13 04:41:17 UTC (rev 7141)
@@ -73,6 +73,19 @@
    */
   int read_packet (void *buf, int buflen, struct sockaddr_ll *sa);
 
+  /*!
+   * \brief Read packet from interface, but don't block waiting
+   *
+   * \param buf                where to put the packet
+   * \param buflen     maximum length of packet in bytes (should be >= 1528)
+   * \param sa         returned sockaddr
+   *
+   * \returns number of bytes read, -1 if trouble or 0 if nothing available.
+   *
+   * Returned packet includes 14-byte ethhdr
+   */
+  int read_packet_dont_block (void *buf, int buflen, struct sockaddr_ll *sa);
+
   /*
    * \brief Write ethernet packet to interface.
    *

Modified: usrp2/trunk/host/lib/usrp2_basic.cc
===================================================================
--- usrp2/trunk/host/lib/usrp2_basic.cc 2007-12-13 03:34:21 UTC (rev 7140)
+++ usrp2/trunk/host/lib/usrp2_basic.cc 2007-12-13 04:41:17 UTC (rev 7141)
@@ -22,10 +22,21 @@
 #include "usrp2_basic.h"
 #include "gri_ethernet.h"
 #include "gri_pktfilter.h"
-#include <arpa/inet.h>
 #include <time.h>      // debug
 
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#else
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+#endif
 
+
+#define        MIN_PKTLEN   64         // per ethernet spec
+#define MAX_PKTLEN 2048                // biggest thing USRP2 can swallow
+
+
 usrp2_basic::usrp2_basic()
   : d_ethernet(new gri_ethernet()), d_pf(0)
 {
@@ -65,8 +76,12 @@
   static const uint8_t broadcast_mac_addr[6] =
     { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 
-  std::vector<op_id_reply_t> r;
+  std::vector<op_id_reply_t> result;
+  int  r;
 
+  uint8_t      pktbuf[MAX_PKTLEN];
+  memset(pktbuf, 0, sizeof(pktbuf));
+
   struct command {
     u2_eth_packet_t    h;
     op_id_t            op_id;
@@ -77,11 +92,7 @@
     op_id_reply_t      op_id_reply;
   };
 
-  uint8_t      buf[128];  // FIXME clean this up
-  memset(buf, 0, sizeof(buf));
-  
-  command      *c = (command *) buf;
-  memset(c, 0, sizeof(command));
+  command      *c = (command *) pktbuf;
   c->h.ehdr.ethertype = htons(U2_ETHERTYPE);
   c->h.ehdr._pad = time(0);
   memcpy(c->h.ehdr.dst_addr, broadcast_mac_addr, 6);
@@ -91,18 +102,44 @@
 
   c->op_id.opcode = OP_ID;
   c->op_id.len = sizeof(op_id_t);
-  int len = std::max(sizeof(buf), sizeof(command));
+  int len = std::max((size_t) MIN_PKTLEN, sizeof(command));
   if (d_ethernet->write_packet(c, len) != len){
     goto bail;
   }
 
-  reply                reply;
-  memset(&reply, 0, sizeof(reply));
+  /*
+   * Wait no longer than 10ms and read all packets available.
+   */
+  fd_set read_fds;
+  FD_ZERO(&read_fds);
+  FD_SET(d_ethernet->fd(), &read_fds);
+  struct timeval timeout;
+  timeout.tv_sec = 0;
+  timeout.tv_usec = 10 * 1000; // 10 ms
+  
+  r = select(d_ethernet->fd()+1, &read_fds, 0, 0, &timeout);
 
-  // FIXME read some packets
+  while(1){
+    memset(pktbuf, 0, sizeof(pktbuf));
+    int len = d_ethernet->read_packet_dont_block(pktbuf, sizeof(pktbuf), 0);
+    if (len < 0){
+      perror("usrp2_basic: read_packet_dont_block");
+      return result;
+    }
+    if (len == 0)
+      break;
 
+    reply *rp = (reply *) pktbuf;
+    if (u2p_chan(&rp->h.fixed) != CONTROL_CHAN)  // ignore
+      continue;
+    if (rp->op_id_reply.opcode != OP_ID_REPLY) // ignore
+      continue;
+
+    result.push_back(rp->op_id_reply);
+  }
+
  bail:
-  return r;
+  return result;
 }
 
 std::ostream& operator<<(std::ostream &os, const op_id_reply_t &r)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]