commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r7965 - usrp2/trunk/host/apps


From: eb
Subject: [Commit-gnuradio] r7965 - usrp2/trunk/host/apps
Date: Fri, 7 Mar 2008 20:04:15 -0700 (MST)

Author: eb
Date: 2008-03-07 20:04:14 -0700 (Fri, 07 Mar 2008)
New Revision: 7965

Added:
   usrp2/trunk/host/apps/tx_samples_at_t.cc
Removed:
   usrp2/trunk/host/apps/tx_samples_at_time.cc
Modified:
   usrp2/trunk/host/apps/
Log:
test code for tx @ time


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

   + *-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


Copied: usrp2/trunk/host/apps/tx_samples_at_t.cc (from rev 7962, 
usrp2/trunk/host/apps/tx_samples_at_time.cc)
===================================================================
--- usrp2/trunk/host/apps/tx_samples_at_t.cc                            (rev 0)
+++ usrp2/trunk/host/apps/tx_samples_at_t.cc    2008-03-08 03:04:14 UTC (rev 
7965)
@@ -0,0 +1,277 @@
+/* -*- 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/>.
+ */
+
+/*
+ * Send Ton seconds of samples, then wait for Toff seconds, and repeat
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include "usrp2_basic.h"
+#include <iostream>
+#include <complex>
+#include <getopt.h>
+#include <boost/scoped_ptr.hpp>
+#include "strtod_si.h"
+
+
+static const double T_on  = 1.0;               // seconds of data
+static const double T_off = 0.5;               // seconds of waiting
+
+
+typedef std::complex<float> fcomplex;
+
+size_t 
+my_fread(void *ptr, size_t size, size_t nmemb, FILE *stream, bool repeat)
+{
+ try_again:
+
+  size_t r = fread(ptr, size, nmemb, stream);
+  if (r == 0){
+    if (!repeat)
+      return 0;
+    if (fseek(stream, 0, SEEK_SET) == -1)
+      return 0;
+    goto try_again;
+  }
+  return r;
+}
+
+static const char *
+prettify_progname(const char *progname)                // that's probably 
almost a word ;)
+{
+  const char *p = strrchr(progname, '/');      // drop leading directory path
+  if (p)
+    p++;
+
+  if (strncmp(p, "lt-", 3) == 0)               // drop lt- libtool prefix
+    p += 3;
+
+  return p;
+}
+
+static void
+usage(const char *progname)
+{
+  fprintf(stderr, "Usage: %s [options]\n\n", prettify_progname(progname));
+  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, "  -I INPUT_FILE        set input filename 
[default=stdin]\n");
+  fprintf(stderr, "  -r                   repeat.  When EOF of input file is 
reached, seek to beginning\n");
+  fprintf(stderr, "  -f FREQ              set frequency to FREQ 
[default=0]\n");
+  fprintf(stderr, "  -i INTERP            set interpolation rate to INTERP 
[default=32]\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)
+{
+  const char *interface = "eth0";
+  const char *input_filename = 0;
+  bool repeat = false;
+  const char *mac_addr_str = 0;
+  double freq = 0;
+  int32_t interp = 32;
+  uint32_t samples_per_frame = 371;
+  int32_t scale = 256;
+  
+  int    ch;
+  double tmp;
+  u2_mac_addr_t mac_addr;
+
+  while ((ch = getopt(argc, argv, "he:m:I:rf:i:F:S")) != 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]);
+       return 1;
+      }
+      break;
+
+    case 'I':
+      input_filename = optarg;
+      break;
+      
+    case 'r':
+      repeat = true;
+      break;
+      
+    case 'f':
+      if (!strtod_si(optarg, &freq)){
+       std::cerr << "invalid number: " << optarg << std::endl;
+       usage(argv[0]);
+       return 1;
+      }
+      break;
+
+    case 'F':
+      samples_per_frame = strtol(optarg, 0, 0);
+      break;
+
+    case 'i':
+      interp = strtol(optarg, 0, 0);
+      break;
+
+    case 'S':
+      if (!strtod_si(optarg, &tmp)){
+       std::cerr << "invalid number: " << optarg << std::endl;
+       usage(argv[0]);
+       return 1;
+      }
+      scale = static_cast<int32_t>(tmp);
+      break;
+      
+    case 'h':
+    default:
+      usage(argv[0]);
+      return 1;
+    }
+  }
+  
+  if (argc - optind != 0){
+    usage(argv[0]);
+    return 1;
+  }
+  
+  FILE *fp = 0;
+  if (input_filename == 0)
+    fp = stdin;
+  else {
+    fp = fopen(input_filename, "rb");
+    if (fp == 0){
+      perror(input_filename);
+      return 1;
+    }
+  }
+
+  if (samples_per_frame < 9 || samples_per_frame > 506){
+    std::cerr << prettify_progname(argv[0])
+             << ": samples_per_frame is out of range.  Must be in [9, 506].\n";
+    usage(argv[0]);
+    return 1;
+  }
+
+  boost::scoped_ptr<usrp2_basic> u2(new usrp2_basic());
+
+  if (!u2->open(interface)){
+    std::cerr << "couldn't open " << interface << std::endl;
+    return 1;
+  }
+
+  std::vector<op_id_reply_t> r = u2->find_usrps();
+
+  for (size_t i = 0; i < r.size(); i++){
+    std::cout << r[i] << std::endl;
+  }
+
+  if (r.size() == 0){
+    std::cerr << "No USRP2 found.\n";
+    return 1;
+  }
+
+  u2_mac_addr_t which = r[0].addr;     // pick the first one
+
+
+  if (!u2->config_tx(which, freq, interp, scale, scale)){
+    std::cerr << "tx_samples: config_tx failed\n";
+    return 1;
+  }
+
+  // ------------------------------------------------------------------------
+
+  double baseband_rate = (double) u2->dac_rate() / interp;
+  uint32_t t_on_in_samples = static_cast<uint32_t>(T_on * baseband_rate);
+  uint32_t t_on_in_ticks =
+    static_cast<uint32_t> (T_on * u2->fpga_master_clock_freq());
+  uint32_t t_off_in_ticks =
+    static_cast<uint32_t> (T_off * u2->fpga_master_clock_freq());
+
+
+  // FIXME query u2 for it's current idea of time
+  uint32_t t_now = 0;
+
+  // start 0.5 second in the future
+  t_now += static_cast<uint32_t>(u2->fpga_master_clock_freq() * 0.5);
+  
+
+  while (1){
+
+    // send a burst
+
+    uint32_t samples_per_burst = t_on_in_samples;
+    uint32_t nsamples_sent = 0;
+    bool start_of_burst = true;
+    bool end_of_burst = false;
+
+    u2_eth_samples_t   pkt;
+
+    while (1){         // send frames of the burst
+      
+      memset(&pkt, 0, sizeof(pkt));
+
+      uint32_t n = std::min(samples_per_burst - nsamples_sent, 
samples_per_frame);
+      size_t r = my_fread(&pkt.samples, sizeof(uint32_t), n, fp, repeat);
+      if (r == 0)              // end of file
+       goto done;
+    
+      if (n == (samples_per_burst - nsamples_sent) || r < n)
+       end_of_burst = true;
+      
+      int start_of_burst_flag =
+       start_of_burst ? U2P_TX_START_OF_BURST : U2P_TX_IMMEDIATE;
+
+      int end_of_burst_flag =
+       end_of_burst ? U2P_TX_END_OF_BURST : 0;
+      
+      u2p_set_word0(&pkt.hdrs.fixed, start_of_burst_flag | end_of_burst_flag, 
0);
+
+      if (start_of_burst){
+       u2p_set_timestamp(&pkt.hdrs.fixed, t_now);
+       t_now += t_on_in_ticks + t_off_in_ticks;
+       start_of_burst = false;
+      }
+      else
+       u2p_set_timestamp(&pkt.hdrs.fixed, 0);
+
+      // pad to 9 for minimum packet size constraint
+      if (!u2->write_samples(which, &pkt, std::max((size_t) 9, r)))
+       break;
+    
+      nsamples_sent += r;
+
+      if (end_of_burst)
+       break;
+
+    }  // frame loop
+  }    // burst loop
+
+ done:
+
+  return 0;
+}

Deleted: usrp2/trunk/host/apps/tx_samples_at_time.cc





reply via email to

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