[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r7962 - usrp2/trunk/host/apps
From: |
eb |
Subject: |
[Commit-gnuradio] r7962 - usrp2/trunk/host/apps |
Date: |
Fri, 7 Mar 2008 18:35:42 -0700 (MST) |
Author: eb
Date: 2008-03-07 18:35:41 -0700 (Fri, 07 Mar 2008)
New Revision: 7962
Added:
usrp2/trunk/host/apps/tx_samples_at_time.cc
Modified:
usrp2/trunk/host/apps/Makefile.am
Log:
work-in-progress
Modified: usrp2/trunk/host/apps/Makefile.am
===================================================================
--- usrp2/trunk/host/apps/Makefile.am 2008-03-07 23:49:08 UTC (rev 7961)
+++ usrp2/trunk/host/apps/Makefile.am 2008-03-08 01:35:41 UTC (rev 7962)
@@ -26,6 +26,7 @@
rx_samples \
rx_streaming_samples \
tx_samples \
+ tx_samples_at_t \
gen_const \
u2_burn_mac_addr
@@ -33,6 +34,7 @@
rx_samples_SOURCES = rx_samples.cc
rx_streaming_samples_SOURCES = rx_streaming_samples.cc
tx_samples_SOURCES = tx_samples.cc
+tx_samples_at_t = tx_samples_at_t.cc
gen_const_SOURCES = gen_const.cc
u2_burn_mac_addr = u2_burn_mac_addr.cc
Copied: usrp2/trunk/host/apps/tx_samples_at_time.cc (from rev 7959,
usrp2/trunk/host/apps/tx_samples.cc)
===================================================================
--- usrp2/trunk/host/apps/tx_samples_at_time.cc (rev 0)
+++ usrp2/trunk/host/apps/tx_samples_at_time.cc 2008-03-08 01:35:41 UTC (rev
7962)
@@ -0,0 +1,229 @@
+/* -*- 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 "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;
+
+
+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;
+ int32_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;
+ }
+
+ 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 (1){
+ if (!u2->config_tx(which, freq, interp, scale, scale)){
+ std::cerr << "tx_samples: config_tx failed\n";
+ return 1;
+ }
+ }
+
+
+ // FIXME query usrp2 for it's current idea of time
+ uint32_t t_now = 0;
+
+ 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_off_in_ticks =
+ static_case<uint32_t> (T_off * u2->fpga_master_clock_freq());
+
+
+
+ u2_eth_samples_t pkt;
+ u2p_set_word0(&pkt.hdrs.fixed, U2P_TX_IMMEDIATE | U2P_TX_START_OF_BURST, 0);
+ u2p_set_timestamp(&pkt.hdrs.fixed, T_NOW);
+
+ while (1){
+
+ int r = fread(&pkt.samples, sizeof(uint32_t), samples_per_frame, fp);
+
+ // fprintf(stderr, "fread -> %d\n", r);
+
+ if (r == 0){
+ if (!repeat)
+ break;
+ if (fseek(fp, 0, SEEK_SET) == -1)
+ break;
+ }
+
+ // FIXME if r < 9, pad to 9 for minimum packet size constraint
+
+ if (!u2->write_samples(which, &pkt, r))
+ break;
+ }
+
+ return 0;
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r7962 - usrp2/trunk/host/apps,
eb <=