commit-gnuradio
[Top][All Lists]
Advanced

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

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


From: jcorgan
Subject: [Commit-gnuradio] r8500 - in usrp2/trunk/host: apps lib
Date: Sun, 25 May 2008 21:13:14 -0600 (MDT)

Author: jcorgan
Date: 2008-05-25 21:13:09 -0600 (Sun, 25 May 2008)
New Revision: 8500

Added:
   usrp2/trunk/host/apps/rx_streaming_samples2.cc
Modified:
   usrp2/trunk/host/apps/
   usrp2/trunk/host/apps/Makefile.am
   usrp2/trunk/host/apps/streaming_fft.py
   usrp2/trunk/host/lib/sample_buffer.cc
   usrp2/trunk/host/lib/sample_buffer.h
   usrp2/trunk/host/lib/usrp2_basic.cc
   usrp2/trunk/host/lib/usrp2_basic.h
Log:
Added rx_streaming_samples2, clean up.


Property changes on: usrp2/trunk/host/apps
___________________________________________________________________
Name: svn:ignore
   - *-stamp
*.a
*.bin
*.dump
*.log
*.rom
.deps
.libs
Makefile
Makefile.in
aclocal.m4
autom4te.cache
blink_leds
blink_leds2
build
compile
config.h
config.h.in
config.log
config.status
configure
depcomp
eth_test
gen_eth_packets
ibs_rx_test
ibs_tx_test
install-sh
libtool
ltmain.sh
missing
py-compile
rcv_eth_packets
run_tests.sh
stamp-h1
test1
test_phy_comm
timer_test
buf_ram_test
buf_ram_zero
hello
find_usrps
rx_samples
tx_samples
gen_const
samples.dat
u2_burn_mac_addr
rx_streaming_samples
tx_samples_at_t

   + *-stamp
*.a
*.bin
*.dump
*.log
*.rom
.deps
.libs
Makefile
Makefile.in
aclocal.m4
autom4te.cache
blink_leds
blink_leds2
build
compile
config.h
config.h.in
config.log
config.status
configure
depcomp
eth_test
gen_eth_packets
ibs_rx_test
ibs_tx_test
install-sh
libtool
ltmain.sh
missing
py-compile
rcv_eth_packets
run_tests.sh
stamp-h1
test1
test_phy_comm
timer_test
buf_ram_test
buf_ram_zero
hello
find_usrps
rx_samples
tx_samples
gen_const
samples.dat
u2_burn_mac_addr
rx_streaming_samples
tx_samples_at_t
rx_streaming_samples2


Modified: usrp2/trunk/host/apps/Makefile.am
===================================================================
--- usrp2/trunk/host/apps/Makefile.am   2008-05-26 02:45:22 UTC (rev 8499)
+++ usrp2/trunk/host/apps/Makefile.am   2008-05-26 03:13:09 UTC (rev 8500)
@@ -26,6 +26,7 @@
 bin_PROGRAMS = \
        find_usrps \
        rx_streaming_samples \
+       rx_streaming_samples2 \
        tx_samples \
        gen_const \
        u2_burn_mac_addr
@@ -33,6 +34,7 @@
 find_usrps_SOURCES = find_usrps.cc
 # rx_samples_SOURCES = rx_samples.cc
 rx_streaming_samples_SOURCES = rx_streaming_samples.cc
+rx_streaming_samples2_SOURCES = rx_streaming_samples2.cc
 tx_samples_SOURCES = tx_samples.cc
 # tx_samples_at_t = tx_samples_at_t.cc
 gen_const_SOURCES = gen_const.cc

Added: usrp2/trunk/host/apps/rx_streaming_samples2.cc
===================================================================
--- usrp2/trunk/host/apps/rx_streaming_samples2.cc                              
(rev 0)
+++ usrp2/trunk/host/apps/rx_streaming_samples2.cc      2008-05-26 03:13:09 UTC 
(rev 8500)
@@ -0,0 +1,249 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007,2008 Free Software Foundation, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "usrp2_basic.h"
+#include <gr_realtime.h>
+
+#include <iostream>
+#include <getopt.h>
+#include <signal.h>
+#include "strtod_si.h"
+#include <stdexcept>
+#include <fcntl.h>
+
+#define GAIN_NOT_SET (-1000)
+
+static volatile bool signaled = false;
+
+static void 
+sig_handler(int sig)
+{
+  signaled = true;
+}
+
+static void
+install_sig_handler(int signum,
+                   void (*new_handler)(int))
+{
+  struct sigaction new_action;
+  memset (&new_action, 0, sizeof (new_action));
+
+  new_action.sa_handler = new_handler;
+  sigemptyset (&new_action.sa_mask);
+  new_action.sa_flags = 0;
+
+  if (sigaction (signum, &new_action, 0) < 0){
+    perror ("sigaction (install new)");
+    throw std::runtime_error ("sigaction");
+  }
+}
+
+static void
+usage(const char *progname)
+{
+  const char *p = strrchr(progname, '/');      // drop leading directory path
+  if (p)
+    p++;
+
+  if (strncmp(p, "lt-", 3) == 0)               // drop lt- libtool prefix
+    p += 3;
+  
+  fprintf(stderr, "Usage: %s [options]\n\n", p);
+  fprintf(stderr, "Options:\n");
+  fprintf(stderr, "  -h                   show this message and exit\n");
+  fprintf(stderr, "  -e ETH_INTERFACE     specify ethernet interface 
[default=eth0]\n");
+  fprintf(stderr, "  -m MAC_ADDR          mac address of USRP2 HH:HH 
[default=first one found]\n");
+  fprintf(stderr, "  -o OUTPUT_FILE       set output filename 
[default=samples.dat]\n");
+  fprintf(stderr, "  -f FREQ              set frequency to FREQ 
[default=0]\n");
+  fprintf(stderr, "  -d DECIM             set decimation rate to DECIM 
[default=32]\n");
+  fprintf(stderr, "  -g gain              rx gain [default=0dB]\n");
+  fprintf(stderr, "  -N NSAMPLES          total number of samples to receive 
[default=infinite]\n");
+  fprintf(stderr, "  -F SAMPLES_PER_FRAME number of samples in each frame 
[default=371]\n");
+  fprintf(stderr, "  -S SCALE             fpga scaling factor for I & Q 
[default=256]\n");
+}
+
+int
+main(int argc, char **argv)
+{
+
+  // options and their defaults
+  const char *interface = "eth0";
+  const char *mac_addr_str = 0;
+  const char *output_filename = "samples.dat";
+  double freq = 0;
+  int32_t decim = 32;
+  uint64_t nsamples = ~0;
+  int32_t samples_per_frame = 250;
+  int32_t scale = 1024;
+  double gain = GAIN_NOT_SET;
+
+  int    ch;
+  double tmp;
+  u2_mac_addr_t mac_addr;
+  bool default_mac = true;
+  
+  while ((ch = getopt(argc, argv, "he:m:o:f:d:N:F:S:g:")) != EOF){
+    switch (ch){
+
+    case 'e':
+      interface = optarg;
+      break;
+      
+    case 'm':
+      mac_addr_str = optarg;
+      if (!usrp2_basic::parse_mac_addr(optarg, &mac_addr)){
+       std::cerr << "invalid mac addr: " << optarg << std::endl;
+       usage(argv[0]);
+       exit(1);
+      }
+      default_mac = false;
+      break;
+
+    case 'o':
+      output_filename = optarg;
+      break;
+      
+    case 'f':
+      if (!strtod_si(optarg, &freq)){
+       std::cerr << "invalid number: " << optarg << std::endl;
+       usage(argv[0]);
+       exit(1);
+      }
+      break;
+
+    case 'N':
+      if (!strtod_si(optarg, &tmp)){
+       std::cerr << "invalid number: " << optarg << std::endl;
+       usage(argv[0]);
+       exit(1);
+      }
+      nsamples = static_cast<uint64_t>(tmp);
+      break;
+
+    case 'F':
+      samples_per_frame = strtol(optarg, 0, 0);
+      break;
+
+    case 'd':
+      decim = strtol(optarg, 0, 0);
+      break;
+
+    case 'S':
+      if (!strtod_si(optarg, &tmp)){
+       std::cerr << "invalid number: " << optarg << std::endl;
+       usage(argv[0]);
+       exit(1);
+      }
+      scale = static_cast<int32_t>(tmp);
+      break;
+      
+    case 'g':
+      if (!strtod_si(optarg, &gain)){
+       std::cerr << "invalid number: " << optarg << std::endl;
+       usage(argv[0]);
+       exit(1);
+      }
+      break;
+
+    case 'h':
+    default:
+      usage(argv[0]);
+      exit(1);
+    }
+  }
+  
+  if (argc - optind != 0){
+    usage(argv[0]);
+    exit(1);
+  }
+
+  int ofd = 1;                 // stdout
+  if (output_filename){
+    ofd = ::open(output_filename, O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, 
0664);
+    if (ofd == -1){
+      perror(output_filename);
+      exit (1);
+    }
+  }
+
+  if (default_mac == true) {
+    op_id_reply_t r;
+    if (!usrp2_basic::pick_default_usrp(interface, &r)) {
+      std::cerr << "No default USRP2 found.\n";
+      return 1;
+    }
+    mac_addr = r.addr;
+  }
+    
+  usrp2_basic_sptr u2 = usrp2_make_basic(interface, mac_addr);
+  
+  install_sig_handler(SIGINT, sig_handler);
+  gr_rt_status_t rt = gr_enable_realtime_scheduling();
+  if (rt != RT_OK)
+    std::cerr << "failed to enable realtime scheduling\n";
+
+  usrp2_tune_result_sptr tune_result;
+  
+  if (gain != GAIN_NOT_SET){
+    if (!u2->set_rx_gain(gain)){
+      std::cerr << "set_rx_gain failed\n";
+      return 1;
+    }
+  }
+
+  if (!(tune_result = u2->set_rx_freq(freq))){
+    std::cerr << "set_rx_freq failed\n";
+    //return 1;
+  }
+
+  if (!u2->set_rx_decim(decim)){
+    std::cerr << "set_rx_decim failed\n";
+    return 1;
+  }
+
+  if (!u2->set_rx_scale_iq(scale, scale)){
+    std::cerr << "set_rx_scale_iq failed\n";
+    return 1;
+  }
+
+  if (!u2->start_rx_streaming(samples_per_frame)){
+    std::cerr << "start_rx_streaming failed\n";
+    return 1;
+  }
+  
+  uint64_t total_samples_recvd = 0;
+
+  while (!signaled && total_samples_recvd < nsamples){
+    uint32_t samples[250];
+    int n = u2->rx_samples(250, samples, NULL);
+    total_samples_recvd += n;
+
+    ::write(ofd, samples, n*sizeof(uint32_t));
+  }
+  
+  if (!u2->stop_rx()){
+    std::cerr << "stop_rx failed\n";
+    return 1;
+  }
+
+  return 0;
+}

Modified: usrp2/trunk/host/apps/streaming_fft.py
===================================================================
--- usrp2/trunk/host/apps/streaming_fft.py      2008-05-26 02:45:22 UTC (rev 
8499)
+++ usrp2/trunk/host/apps/streaming_fft.py      2008-05-26 03:13:09 UTC (rev 
8500)
@@ -63,7 +63,7 @@
     if options.gain:
         gain_clause = '-g ' + options.gain
 
-    cmd = "sudo %s/rx_streaming_samples -e %s -f %g -d %d -F %d %s -o 
/proc/self/fd/1 | %s/stdin_int32_fft.py %s -f %g -d %d" % (
+    cmd = "sudo %s/rx_streaming_samples2 -e %s -f %g -d %d -F %d %s -o 
/proc/self/fd/1 | %s/stdin_int32_fft.py %s -f %g -d %d" % (
         path, options.eth, options.freq, options.decim, 
options.samples_per_frame, gain_clause,
         path, display_type, options.freq, options.decim)
 

Modified: usrp2/trunk/host/lib/sample_buffer.cc
===================================================================
--- usrp2/trunk/host/lib/sample_buffer.cc       2008-05-26 02:45:22 UTC (rev 
8499)
+++ usrp2/trunk/host/lib/sample_buffer.cc       2008-05-26 03:13:09 UTC (rev 
8500)
@@ -26,6 +26,11 @@
 #include <cassert>
 
 #define SAMPLE_BUFFER_DEBUG 0
+#if SAMPLE_BUFFER_DEBUG
+#define DEBUG_LOG(x) ::write(2, x, 1)
+#else
+#define DEBUG_LOG(x)
+#endif
 
 sample_buffer::sample_buffer(size_t nsamples, size_t ndescs)
   : d_samples(nsamples), 
@@ -50,7 +55,7 @@
   d_descs.write(1, &desc);
   d_samples.write(nsamples, samples);
 
-  ::write(1, "e", 1); // enqueued
+  DEBUG_LOG("e"); // enqueued
   d_not_empty.signal();
 }
 
@@ -68,7 +73,7 @@
     if (d_rx_remainder > 0) {
       n = std::min(d_rx_remainder, nmax-count);
       d_rx_remainder -= n;
-      ::write(1, "p", 1); // partial read
+      DEBUG_LOG("p"); // partial read
     }
     else {
       // Grab a descriptor out of the queue
@@ -78,7 +83,7 @@
       d_rx_remainder = desc.nsamples-n;
       if (flags)
         *flags |= desc.flags;
-      ::write(1, "d", 1); // dequeue
+      DEBUG_LOG("d"); // dequeue
     }
     
     d_samples.read(n, &samples[count]);

Modified: usrp2/trunk/host/lib/sample_buffer.h
===================================================================
--- usrp2/trunk/host/lib/sample_buffer.h        2008-05-26 02:45:22 UTC (rev 
8499)
+++ usrp2/trunk/host/lib/sample_buffer.h        2008-05-26 03:13:09 UTC (rev 
8500)
@@ -81,6 +81,11 @@
    * Returns sample space available if not full.
    */
   size_t space_available() const { return is_full_p() ? 0 : 
d_samples.space_available(); }
+
+  /*!
+   * Returns items available for reading
+   */
+  size_t items_available() const { return d_samples.items_available(); }
 }
 sample_buffer_t;
 

Modified: usrp2/trunk/host/lib/usrp2_basic.cc
===================================================================
--- usrp2/trunk/host/lib/usrp2_basic.cc 2008-05-26 02:45:22 UTC (rev 8499)
+++ usrp2/trunk/host/lib/usrp2_basic.cc 2008-05-26 03:13:09 UTC (rev 8500)
@@ -39,7 +39,12 @@
 #include <unistd.h>
 #endif
 
-#define USRP2_BASIC_DEBUG 1
+#define USRP2_BASIC_DEBUG 0
+#if USRP2_BASIC_DEBUG
+#define DEBUG_LOG(x) ::write(2, x, 1)
+#else
+#define DEBUG_LOG(x)
+#endif
 
 /*
  * Note, this should be considered a first cut at getting
@@ -849,28 +854,28 @@
   timeout.tv_sec = 0;
   timeout.tv_usec = 100 * 1000;        // 100 ms
 
-  ::write(1, "S", 1); // select
+  DEBUG_LOG("S"); // select
   int r = select(d_ethernet->fd()+1, &read_fds, &write_fds, 0, &timeout);
   if (r > 0) {       // Socket available for read or for write
     if (FD_ISSET(d_ethernet->fd(), &read_fds)) {
-      ::write(1, "r", 1); // data to read()
+      DEBUG_LOG("r"); // data to read()
       rx_frames();
     }
     
     if (FD_ISSET(d_ethernet->fd(), &write_fds)) {
-      ::write(1, "r", 1); // data to write()
+      DEBUG_LOG("w"); // can write()
       tx_frames();
     }
   }
   else if (r == 0) { 
-    ::write(1, "T", 1);   // socket timeout
+    DEBUG_LOG("T");   // socket timeout
     return;
   }
   else {         
     if (errno == EINTR)
-      ::write(1, "I", 1); // interrupted system call
+      DEBUG_LOG("I"); // interrupted system call
     else
-      ::write(1, "!", 1); // error on socket
+      DEBUG_LOG("!"); // error on socket
     return;
   }
 }
@@ -885,29 +890,29 @@
   while (1) {
     len = d_ethernet->read_packet_dont_block(pktbuf, sizeof(pktbuf));
     if (len < 0) {
-      ::write(1, "!", 1); // error
+      DEBUG_LOG("!"); // error
       return;
     } 
     else if (len == 0) {
-      ::write(1, "|", 1); // no more frames
+      DEBUG_LOG("|"); // no more frames
       return;
     }
     else if ((size_t)len < sizeof(u2_eth_packet_t)) {
-      ::write(1, "<", 1); // short frame
+      DEBUG_LOG("<"); // short frame
     }
     else
-      ::write(1, "R", 1); // rx ok
+      DEBUG_LOG("R"); // rx ok
 
     u2_eth_packet_t *p = (u2_eth_packet_t *)pktbuf;
     if (u2p_chan(&p->fixed) == CONTROL_CHAN) {
-      ::write(1, "-", 1); // ignore (FIXME: multiple channels, control channel)
+      DEBUG_LOG("-"); // ignore (FIXME: multiple channels, control channel)
       continue;
     }    
 
     u2_eth_samples_t *s = (u2_eth_samples_t *)pktbuf;
     size_t plen = (len-sizeof(s->hdrs))/sizeof(uint32_t);
     if (d_rx_samples.space_available() < plen) {
-      ::write(1, "uO", 2); // overrun
+      ::write(2, "uO", 2); // overrun
       return;
     }
 

Modified: usrp2/trunk/host/lib/usrp2_basic.h
===================================================================
--- usrp2/trunk/host/lib/usrp2_basic.h  2008-05-26 02:45:22 UTC (rev 8499)
+++ usrp2/trunk/host/lib/usrp2_basic.h  2008-05-26 03:13:09 UTC (rev 8500)
@@ -195,6 +195,12 @@
   size_t rx_samples(size_t nmax, uint32_t *samples, uint32_t *flags);
 
   /*!
+   * Returns number of samples available for reading by rx_samples()
+   *
+   */
+  size_t items_available() const { return d_rx_samples.items_available(); }
+
+  /*!
    * \brief Read FPGA's idea of time
    *
    * N.B., this interface will probably change.





reply via email to

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