[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8861 - in usrp2/trunk/host: apps gr-usrp2 lib
From: |
eb |
Subject: |
[Commit-gnuradio] r8861 - in usrp2/trunk/host: apps gr-usrp2 lib |
Date: |
Thu, 10 Jul 2008 18:07:02 -0600 (MDT) |
Author: eb
Date: 2008-07-10 18:07:01 -0600 (Thu, 10 Jul 2008)
New Revision: 8861
Removed:
usrp2/trunk/host/apps/rx_streaming_samples2.cc
usrp2/trunk/host/gr-usrp2/usrp2_source_raw.cc
usrp2/trunk/host/gr-usrp2/usrp2_source_raw.h
usrp2/trunk/host/gr-usrp2/usrp2_table.cc
usrp2/trunk/host/gr-usrp2/usrp2_table.h
usrp2/trunk/host/lib/ring_buffer.h
usrp2/trunk/host/lib/sample_buffer.cc
usrp2/trunk/host/lib/sample_buffer.h
usrp2/trunk/host/lib/usrp2_basic_thread.cc
usrp2/trunk/host/lib/usrp2_basic_thread.h
usrp2/trunk/host/lib/usrp2_tune_result.h
Modified:
usrp2/trunk/host/apps/
usrp2/trunk/host/apps/Makefile.am
usrp2/trunk/host/apps/rx_streaming_samples.cc
usrp2/trunk/host/apps/streaming_fft.py
usrp2/trunk/host/apps/tx_samples.cc
usrp2/trunk/host/apps/u2_burn_mac_addr.cc
usrp2/trunk/host/gr-usrp2/Makefile.am
usrp2/trunk/host/gr-usrp2/usrp2.i
usrp2/trunk/host/gr-usrp2/usrp2_sink_base.cc
usrp2/trunk/host/gr-usrp2/usrp2_sink_base.h
usrp2/trunk/host/gr-usrp2/usrp2_sink_c.cc
usrp2/trunk/host/gr-usrp2/usrp2_sink_c.h
usrp2/trunk/host/gr-usrp2/usrp2_source_base.cc
usrp2/trunk/host/gr-usrp2/usrp2_source_base.h
usrp2/trunk/host/gr-usrp2/usrp2_source_c.cc
usrp2/trunk/host/gr-usrp2/usrp2_source_c.h
usrp2/trunk/host/lib/Makefile.am
usrp2/trunk/host/lib/usrp2_basic.cc
usrp2/trunk/host/lib/usrp2_basic.h
Log:
Merged eb/roll-back-host-code -r 8849:8860 into u2-trunk. This backed
out the abandoned host code that was still lurking in u2-trunk/host.
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
rx_streaming_samples2
+ *-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
Modified: usrp2/trunk/host/apps/Makefile.am
===================================================================
--- usrp2/trunk/host/apps/Makefile.am 2008-07-10 22:01:34 UTC (rev 8860)
+++ usrp2/trunk/host/apps/Makefile.am 2008-07-11 00:07:01 UTC (rev 8861)
@@ -26,7 +26,6 @@
bin_PROGRAMS = \
find_usrps \
rx_streaming_samples \
- rx_streaming_samples2 \
tx_samples \
gen_const \
u2_burn_mac_addr
@@ -34,7 +33,6 @@
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
Modified: usrp2/trunk/host/apps/rx_streaming_samples.cc
===================================================================
--- usrp2/trunk/host/apps/rx_streaming_samples.cc 2008-07-10 22:01:34 UTC
(rev 8860)
+++ usrp2/trunk/host/apps/rx_streaming_samples.cc 2008-07-11 00:07:01 UTC
(rev 8861)
@@ -220,8 +220,7 @@
int ch;
double tmp;
u2_mac_addr_t mac_addr;
- bool default_mac = true;
-
+
// setvbuf(stdout, 0, _IOFBF, 64 * 1024); // make stdout fully buffered
while ((ch = getopt(argc, argv, "he:m:o:f:d:N:F:S:g:")) != EOF){
@@ -238,7 +237,6 @@
usage(argv[0]);
exit(1);
}
- default_mac = false;
break;
case 'o':
@@ -314,49 +312,64 @@
}
}
- 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 *u2 = new usrp2_basic();
+
+ if (!u2->open(interface)){
+ std::cerr << "couldn't open " << interface << std::endl;
+ return 0;
}
-
- usrp2_basic_sptr u2 = usrp2_make_basic(interface, mac_addr);
+
+ install_sig_handler(SIGINT, sig_handler);
- install_sig_handler(SIGINT, sig_handler);
+ std::vector<op_id_reply_t> r = u2->find_usrps();
+
+ for (size_t i = 0; i < r.size(); i++){
+ std::cerr << 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
+
+
gr_rt_status_t rt = gr_enable_realtime_scheduling();
if (rt != RT_OK)
std::cerr << "failed to enable realtime scheduling\n";
+
// create writer thread
class file_writer *writer = new file_writer(ofd, rb);
writer->start_undetached();
+
+ usrp2_tune_result tune_result;
+
if (gain != GAIN_NOT_SET){
- if (!u2->set_rx_gain(gain)){
+ if (!u2->set_rx_gain(which, gain)){
std::cerr << "set_rx_gain failed\n";
return 1;
}
}
- if (!(u2->set_rx_freq(freq, NULL))){
+ if (!u2->set_rx_freq(which, freq, &tune_result)){
std::cerr << "set_rx_freq failed\n";
- //return 1;
+ return 1;
}
- if (!u2->set_rx_decim(decim)){
+ if (!u2->set_rx_decim(which, decim)){
std::cerr << "set_rx_decim failed\n";
return 1;
}
- if (!u2->set_rx_scale_iq(scale, scale)){
+ if (!u2->set_rx_scale_iq(which, scale, scale)){
std::cerr << "set_rx_scale_iq failed\n";
return 1;
}
- if (!u2->start_rx_streaming(samples_per_frame)){
+ if (!u2->start_rx_streaming(which, samples_per_frame)){
std::cerr << "start_rx_streaming failed\n";
return 1;
}
@@ -370,7 +383,7 @@
u2_eth_samples_t pkt;
// read samples
- int n = u2->read_samples(&pkt);
+ int n = u2->read_samples(which, &pkt);
if (n <= 0)
break;
@@ -401,7 +414,7 @@
// smp_wmb()
rb->d_not_empty.post(); // wake up file writer
- if (!u2->stop_rx()){
+ if (!u2->stop_rx(which)){
std::cerr << "stop_rx failed\n";
return 1;
}
Deleted: usrp2/trunk/host/apps/rx_streaming_samples2.cc
Modified: usrp2/trunk/host/apps/streaming_fft.py
===================================================================
--- usrp2/trunk/host/apps/streaming_fft.py 2008-07-10 22:01:34 UTC (rev
8860)
+++ usrp2/trunk/host/apps/streaming_fft.py 2008-07-11 00:07:01 UTC (rev
8861)
@@ -63,7 +63,7 @@
if options.gain:
gain_clause = '-g ' + options.gain
- 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" % (
+ 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" % (
path, options.eth, options.freq, options.decim,
options.samples_per_frame, gain_clause,
path, display_type, options.freq, options.decim)
Modified: usrp2/trunk/host/apps/tx_samples.cc
===================================================================
--- usrp2/trunk/host/apps/tx_samples.cc 2008-07-10 22:01:34 UTC (rev 8860)
+++ usrp2/trunk/host/apps/tx_samples.cc 2008-07-11 00:07:01 UTC (rev 8861)
@@ -78,8 +78,7 @@
int ch;
double tmp;
u2_mac_addr_t mac_addr;
- bool default_mac = true;
-
+
while ((ch = getopt(argc, argv, "he:m:I:rf:i:F:S:g:")) != EOF){
switch (ch){
@@ -94,7 +93,6 @@
usage(argv[0]);
return 1;
}
- default_mac = false;
break;
case 'I':
@@ -162,36 +160,47 @@
return 1;
}
- if (default_mac == true) {
- op_id_reply_t r;
- if (!usrp2_basic::pick_default_usrp(interface, &r)) {
- std::cerr << "Unable to find USRP2." << std::endl;
- return 1;
- }
- mac_addr = r.addr;
+ usrp2_basic *u2 = new usrp2_basic();
+
+ if (!u2->open(interface)){
+ std::cerr << "couldn't open " << interface << std::endl;
+ return 1;
}
-
- usrp2_basic_sptr u2 = usrp2_make_basic(interface, mac_addr);
+
+ 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
+
+
usrp2_tune_result tune_result;
if (gain != GAIN_NOT_SET){
- if (!u2->set_tx_gain(gain)){
+ if (!u2->set_tx_gain(which, gain)){
std::cerr << "set_tx_gain failed\n";
return 1;
}
}
- if (!u2->set_tx_freq(freq, &tune_result)){
+ if (!u2->set_tx_freq(which, freq, &tune_result)){
std::cerr << "set_tx_freq failed\n";
return 1;
}
- if (!u2->set_tx_interp(interp)){
+ if (!u2->set_tx_interp(which, interp)){
std::cerr << "set_tx_interp failed\n";
return 1;
}
- if (!u2->set_tx_scale_iq(scale, scale)){
+ if (!u2->set_tx_scale_iq(which, scale, scale)){
std::cerr << "set_tx_scale_iq failed\n";
return 1;
}
@@ -216,7 +225,7 @@
// FIXME if r < 9, pad to 9 for minimum packet size constraint
- if (!u2->write_samples(&pkt, r))
+ if (!u2->write_samples(which, &pkt, r))
break;
}
Modified: usrp2/trunk/host/apps/u2_burn_mac_addr.cc
===================================================================
--- usrp2/trunk/host/apps/u2_burn_mac_addr.cc 2008-07-10 22:01:34 UTC (rev
8860)
+++ usrp2/trunk/host/apps/u2_burn_mac_addr.cc 2008-07-11 00:07:01 UTC (rev
8861)
@@ -77,9 +77,22 @@
fprintf(stderr, "invalid mac address: %s\n", new_mac_addr_str);
exit(1);
}
+
- usrp2_basic_sptr u2 = usrp2_make_basic(interface, old_mac_addr);
- if (!u2->burn_mac_addr(new_mac_addr)){
+ usrp2_basic *u2 = new usrp2_basic();
+
+ if (!u2->open(interface)){
+ std::cerr << "couldn't open " << interface << std::endl;
+ return 0;
+ }
+
+ if (!u2->find_usrp_by_mac(old_mac_addr, 0)){
+ std::cerr << "No USRP2 with address "
+ << old_mac_addr << " found.\n";
+ return 1;
+ }
+
+ if (!u2->burn_mac_addr(old_mac_addr, new_mac_addr)){
std::cerr << "Failed to burn mac address\n";
return 1;
}
@@ -90,9 +103,8 @@
ts.tv_nsec = 250000000;
nanosleep(&ts, 0);
-
// Now see if we can find it using it's new address
- if (!usrp2_basic::find_usrp(interface, new_mac_addr, 0)){
+ if (!u2->find_usrp_by_mac(new_mac_addr, 0)){
std::cerr << "Failed to find USRP2 using new address "
<< new_mac_addr << ".\n";
return 1;
Modified: usrp2/trunk/host/gr-usrp2/Makefile.am
===================================================================
--- usrp2/trunk/host/gr-usrp2/Makefile.am 2008-07-10 22:01:34 UTC (rev
8860)
+++ usrp2/trunk/host/gr-usrp2/Makefile.am 2008-07-11 00:07:01 UTC (rev
8861)
@@ -26,9 +26,7 @@
usrp2_sink_base.cc \
usrp2_sink_c.cc \
usrp2_source_base.cc \
- usrp2_source_c.cc \
- usrp2_source_raw.cc \
- usrp2_table.cc
+ usrp2_source_c.cc
libgr_usrp2_la_LIBADD = \
../lib/libusrp2.la
@@ -37,11 +35,7 @@
usrp2_sink_base.h \
usrp2_sink_c.h \
usrp2_source_base.h \
- usrp2_source_c.h \
- usrp2_source_raw.h
-
-noinst_HEADERS = \
- usrp2_table.h
+ usrp2_source_c.h
# Export C++ GNU Radio driver to Python via SWIG
ourpythondir = $(grpythondir)
Modified: usrp2/trunk/host/gr-usrp2/usrp2.i
===================================================================
--- usrp2/trunk/host/gr-usrp2/usrp2.i 2008-07-10 22:01:34 UTC (rev 8860)
+++ usrp2/trunk/host/gr-usrp2/usrp2.i 2008-07-11 00:07:01 UTC (rev 8861)
@@ -29,92 +29,69 @@
#include "gnuradio_swig_bug_workaround.h" // mandatory bug fix
#include "usrp2_sink_c.h"
#include "usrp2_source_c.h"
-#include "usrp2_source_raw.h"
%}
// ----------------------------------------------------------------
-class usrp2_source_base : public gr_sync_block {
+class usrp2_sink_base : public gr_sync_block {
protected:
- usrp2_source_base(const std::string &name, gr_io_signature_sptr
output_signature)
+ usrp2_sink_base(const std::string &name,
+ gr_io_signature_sptr input_signature)
throw (std::runtime_error);
public:
- ~usrp2_source_base();
+ ~usrp2_sink_base();
- bool set_gain(double gain);
- bool set_freq(double frequency, usrp2_tune_result *result);
- bool set_decim(int decimation_factor);
- bool set_scale_iq(int scale_i, int scale_q);
-
- float adc_rate() const;
- int decim_rate() const;
};
// ----------------------------------------------------------------
-GR_SWIG_BLOCK_MAGIC(usrp2,source_c)
+class usrp2_source_base : public gr_sync_block {
-usrp2_source_c_sptr
-usrp2_make_source_c(const std::string &ifc="eth0", const std::string &mac="")
- throw (std::runtime_error);
-
-class usrp2_source_c : public usrp2_source_base {
-
protected:
- usrp2_source_c(const std::string &ifc, const std::string &mac);
+ usrp2_source_base(const std::string &name,
+ gr_io_signature_sptr output_signature)
+ throw (std::runtime_error);
public:
- ~usrp2_source_c();
+ ~usrp2_source_base();
};
// ----------------------------------------------------------------
-GR_SWIG_BLOCK_MAGIC(usrp2,source_raw)
+GR_SWIG_BLOCK_MAGIC(usrp2,sink_c)
-usrp2_source_raw_sptr
-usrp2_make_source_raw(const std::string &ifc="eth0", const std::string
&mac="")
- throw (std::runtime_error);
+usrp2_sink_c_sptr
+usrp2_make_sink_c() throw (std::runtime_error);
-class usrp2_source_raw : public usrp2_source_base {
+class usrp2_sink_c : public usrp2_sink_base {
protected:
- usrp2_source_raw(const std::string &ifc, const std::string &mac);
+ usrp2_sink_c();
public:
- ~usrp2_source_raw();
+ ~usrp2_sink_c();
};
// ----------------------------------------------------------------
-class usrp2_sink_base : public gr_sync_block {
+GR_SWIG_BLOCK_MAGIC(usrp2,source_c)
-protected:
- usrp2_sink_base(const std::string &name, gr_io_signature_sptr
input_signature)
- throw (std::runtime_error);
-
-public:
- ~usrp2_sink_base();
-
-};
-
-// ----------------------------------------------------------------
-
-GR_SWIG_BLOCK_MAGIC(usrp2,sink_c)
-
-usrp2_sink_c_sptr
-usrp2_make_sink_c(const std::string &ifc="eth0", const std::string &mac="")
+usrp2_source_c_sptr
+usrp2_make_source_c(const std::string &ifc="eth0",
+ const std::string &mac="")
throw (std::runtime_error);
-class usrp2_sink_c : public usrp2_sink_base {
+class usrp2_source_c : public usrp2_source_base {
protected:
- usrp2_sink_c(const std::string &ifc, const std::string &mac);
+ usrp2_source_c(const std::string &ifc,
+ const std::string &mac);
public:
- ~usrp2_sink_c();
+ ~usrp2_source_c();
};
Modified: usrp2/trunk/host/gr-usrp2/usrp2_sink_base.cc
===================================================================
--- usrp2/trunk/host/gr-usrp2/usrp2_sink_base.cc 2008-07-10 22:01:34 UTC
(rev 8860)
+++ usrp2/trunk/host/gr-usrp2/usrp2_sink_base.cc 2008-07-11 00:07:01 UTC
(rev 8861)
@@ -25,68 +25,21 @@
#endif
#include <usrp2_sink_base.h>
-#include <usrp2_table.h>
#include <gr_io_signature.h>
-#include <iostream>
-#define USRP2_SINK_BASE_DEBUG 1
-
usrp2_sink_base::usrp2_sink_base(const std::string &name,
- gr_io_signature_sptr input_signature,
- const std::string &ifc,
- const std::string &mac)
+ gr_io_signature_sptr input_signature)
throw (std::runtime_error)
: gr_sync_block(name,
input_signature,
- gr_make_io_signature(0, 0, 0)),
- d_u2(usrp2_basic_sptr())
+ gr_make_io_signature(0, 0, 0))
{
- op_id_reply_t id;
-
- if (mac == "") {
- if (!usrp2_basic::pick_default_usrp(ifc, &id))
- throw std::runtime_error("Unable to pick default USRP2");
- }
- else {
- u2_mac_addr_t addr;
- if (!usrp2_basic::parse_mac_addr(mac, &addr))
- throw std::runtime_error("Invalid MAC address");
-
- if (!usrp2_basic::find_usrp(ifc, addr, &id))
- throw std::runtime_error("Unable to find specified USRP2.");
- }
-
- if (USRP2_SINK_BASE_DEBUG)
- std::cout << "usrp2_sink_base: using ifc=" << ifc
- << " mac=" << id.addr
- << " hw_rev=" << id.hw_rev << std::endl;
-
- if (!(d_u2 = find_or_create_usrp2_basic(ifc, id.addr)))
- throw std::runtime_error("Unable to create usrp2_basic!");
}
-bool
-usrp2_sink_base::start()
+usrp2_sink_base::~usrp2_sink_base ()
{
- if (USRP2_SINK_BASE_DEBUG)
- std::cout << "usrp2_sink_base: start" << std::endl;
-
- return true;
}
-bool
-usrp2_sink_base::stop()
-{
- if (USRP2_SINK_BASE_DEBUG)
- std::cout << "usrp2_sink_base: stop" << std::endl;
-
- return true;
-}
-
-usrp2_sink_base::~usrp2_sink_base()
-{
-}
-
int
usrp2_sink_base::work(int noutput_items,
gr_vector_const_void_star &input_items,
Modified: usrp2/trunk/host/gr-usrp2/usrp2_sink_base.h
===================================================================
--- usrp2/trunk/host/gr-usrp2/usrp2_sink_base.h 2008-07-10 22:01:34 UTC (rev
8860)
+++ usrp2/trunk/host/gr-usrp2/usrp2_sink_base.h 2008-07-11 00:07:01 UTC (rev
8861)
@@ -24,26 +24,20 @@
#define INCLUDED_USRP2_SINK_BASE_H
#include <gr_sync_block.h>
-#include <usrp2_basic.h>
#include <stdexcept>
class usrp2_sink_base : public gr_sync_block {
+private:
+
protected:
usrp2_sink_base(const std::string &name,
- gr_io_signature_sptr input_signature,
- const std::string &ifc = "eth0",
- const std::string &mac = "")
+ gr_io_signature_sptr input_signature)
throw (std::runtime_error);
- usrp2_basic_sptr d_u2;
-
public:
~usrp2_sink_base();
- virtual bool start();
- virtual bool stop();
-
int work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
Modified: usrp2/trunk/host/gr-usrp2/usrp2_sink_c.cc
===================================================================
--- usrp2/trunk/host/gr-usrp2/usrp2_sink_c.cc 2008-07-10 22:01:34 UTC (rev
8860)
+++ usrp2/trunk/host/gr-usrp2/usrp2_sink_c.cc 2008-07-11 00:07:01 UTC (rev
8861)
@@ -26,19 +26,18 @@
#include <usrp2_sink_c.h>
#include <gr_io_signature.h>
+#include <usrp_standard.h>
+#include <usrp_bytesex.h>
usrp2_sink_c_sptr
-usrp2_make_sink_c(const std::string &ifc, const std::string &mac)
- throw (std::runtime_error)
+usrp2_make_sink_c() throw (std::runtime_error)
{
- return usrp2_sink_c_sptr(new usrp2_sink_c(ifc, mac));
+ return usrp2_sink_c_sptr(new usrp2_sink_c());
}
-usrp2_sink_c::usrp2_sink_c(const std::string &ifc, const std::string &mac)
- throw (std::runtime_error)
+usrp2_sink_c::usrp2_sink_c() throw (std::runtime_error)
: usrp2_sink_base("usrp2_sink_c",
- gr_make_io_signature(1, 1, sizeof(gr_complex)),
- ifc, mac)
+ gr_make_io_signature(1, 1, sizeof(gr_complex)))
{
}
Modified: usrp2/trunk/host/gr-usrp2/usrp2_sink_c.h
===================================================================
--- usrp2/trunk/host/gr-usrp2/usrp2_sink_c.h 2008-07-10 22:01:34 UTC (rev
8860)
+++ usrp2/trunk/host/gr-usrp2/usrp2_sink_c.h 2008-07-11 00:07:01 UTC (rev
8861)
@@ -29,19 +29,16 @@
typedef boost::shared_ptr<usrp2_sink_c> usrp2_sink_c_sptr;
usrp2_sink_c_sptr
-usrp2_make_sink_c(const std::string &ifc="eth0", const std::string &mac="")
- throw (std::runtime_error);
+usrp2_make_sink_c() throw (std::runtime_error);
class usrp2_sink_c : public usrp2_sink_base {
-
private:
+
friend usrp2_sink_c_sptr
- usrp2_make_sink_c(const std::string &ifc, const std::string &mac)
- throw (std::runtime_error);
+ usrp2_make_sink_c() throw (std::runtime_error);
protected:
- usrp2_sink_c(const std::string &ifc="eth0", const std::string &mac="")
- throw (std::runtime_error);
+ usrp2_sink_c() throw (std::runtime_error);
public:
~usrp2_sink_c();
Modified: usrp2/trunk/host/gr-usrp2/usrp2_source_base.cc
===================================================================
--- usrp2/trunk/host/gr-usrp2/usrp2_source_base.cc 2008-07-10 22:01:34 UTC
(rev 8860)
+++ usrp2/trunk/host/gr-usrp2/usrp2_source_base.cc 2008-07-11 00:07:01 UTC
(rev 8861)
@@ -25,14 +25,11 @@
#endif
#include <usrp2_source_base.h>
-#include <usrp2_table.h>
#include <gr_io_signature.h>
#include <iostream>
-#define USRP2_SOURCE_BASE_DEBUG 0
+#define USRP2_SOURCE_BASE_DEBUG 1
-#define SAMPLES_PER_PACKET 250
-
usrp2_source_base::usrp2_source_base(const std::string &name,
gr_io_signature_sptr output_signature,
const std::string &ifc,
@@ -41,88 +38,43 @@
: gr_sync_block(name,
gr_make_io_signature(0, 0, 0),
output_signature),
- d_u2(usrp2_basic_sptr())
+ d_u2(0), d_addr()
{
- op_id_reply_t id;
+ std::vector<op_id_reply_t> r = usrp2_basic::find_usrps(ifc);
+ if (r.size() == 0)
+ throw std::runtime_error("No USRP2s found on interface.");
if (mac == "") {
- if (!usrp2_basic::pick_default_usrp(ifc, &id))
- throw std::runtime_error("Unable to pick default USRP2");
+ if (r.size() > 1)
+ throw std::runtime_error("Must supply USRP2 MAC address when multiple
devices are present");
+ d_addr = r[0].addr;
}
else {
u2_mac_addr_t addr;
if (!usrp2_basic::parse_mac_addr(mac, &addr))
throw std::runtime_error("Invalid MAC address");
- if (!usrp2_basic::find_usrp(ifc, addr, &id))
+ unsigned int i;
+ for (i = 0; i < r.size(); i++)
+ if (r[i].addr == addr) {
+ d_addr = addr;
+ break;
+ }
+
+ if (i == r.size())
throw std::runtime_error("Unable to find specified USRP2.");
}
if (USRP2_SOURCE_BASE_DEBUG)
- std::cout << "usrp2_source_base: using ifc=" << ifc
- << " mac=" << id.addr
- << " hw_rev=" << id.hw_rev << std::endl;
+ std::cout << "usrp2_source_base: using ifc=" << ifc << " mac=" << d_addr
<< std::endl;
- if (!(d_u2 = find_or_create_usrp2_basic(ifc, id.addr)))
- throw std::runtime_error("Unable to create usrp2_basic!");
+ // Now retrieve or make and return usrp2_basic object for MAC address in
d_addr
}
-bool
-usrp2_source_base::set_gain(double gain)
-{
- return d_u2->set_rx_gain(gain);
-}
-
-bool
-usrp2_source_base::set_freq(double frequency, usrp2_tune_result *result)
-{
- return d_u2->set_rx_freq(frequency, result);
-}
-
-bool
-usrp2_source_base::set_decim(int decimation_factor)
-{
- return d_u2->set_rx_decim(decimation_factor);
-}
-
-bool
-usrp2_source_base::set_scale_iq(int scale_i, int scale_q)
-{
- return d_u2->set_rx_scale_iq(scale_i, scale_q);
-}
-
-float
-usrp2_source_base::adc_rate() const
-{
- return d_u2->adc_rate();
-}
-
-int
-usrp2_source_base::decim_rate() const
-{
- return d_u2->rx_decim_rate();
-}
-
-bool
-usrp2_source_base::start()
-{
- if (USRP2_SOURCE_BASE_DEBUG)
- std::cout << "usrp2_source_base: start" << std::endl;
-
- return d_u2->start_rx_streaming(SAMPLES_PER_PACKET);
-}
-
-bool
-usrp2_source_base::stop()
-{
- if (USRP2_SOURCE_BASE_DEBUG)
- std::cout << "usrp2_source_base: stop" << std::endl;
-
- return d_u2->stop_rx();
-}
-
usrp2_source_base::~usrp2_source_base ()
{
+ if (d_u2)
+ delete d_u2;
}
int
@@ -130,14 +82,5 @@
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
- if (USRP2_SOURCE_BASE_DEBUG)
- ::write(1, "w", 1);
-
- uint32_t buffer[SAMPLES_PER_PACKET];
- uint32_t flags = 0; // In the streaming mode that gr-usrp2 uses, these are
ignored
-
- int n = d_u2->rx_samples(std::min(noutput_items, SAMPLES_PER_PACKET),
buffer, &flags);
- copy_from_usrp2_buffer(buffer, output_items[0], n);
-
- return n;
+ return noutput_items;
}
Modified: usrp2/trunk/host/gr-usrp2/usrp2_source_base.h
===================================================================
--- usrp2/trunk/host/gr-usrp2/usrp2_source_base.h 2008-07-10 22:01:34 UTC
(rev 8860)
+++ usrp2/trunk/host/gr-usrp2/usrp2_source_base.h 2008-07-11 00:07:01 UTC
(rev 8861)
@@ -36,27 +36,15 @@
const std::string &mac = "")
throw (std::runtime_error);
- usrp2_basic_sptr d_u2;
-
+ usrp2_basic *d_u2;
+ u2_mac_addr_t d_addr;
+
public:
~usrp2_source_base();
- virtual bool start();
- virtual bool stop();
-
- bool set_gain(double gain);
- bool set_freq(double frequency, usrp2_tune_result *result);
- bool set_decim(int decimation_factor);
- bool set_scale_iq(int scale_i, int scale_q);
-
- float adc_rate() const;
- int decim_rate() const;
-
int work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
-
- virtual void copy_from_usrp2_buffer(uint32_t *src, void *dst, int nsamples)
= 0;
};
#endif /* INCLUDED_USRP2_SOURCE_BASE_H */
Modified: usrp2/trunk/host/gr-usrp2/usrp2_source_c.cc
===================================================================
--- usrp2/trunk/host/gr-usrp2/usrp2_source_c.cc 2008-07-10 22:01:34 UTC (rev
8860)
+++ usrp2/trunk/host/gr-usrp2/usrp2_source_c.cc 2008-07-11 00:07:01 UTC (rev
8861)
@@ -26,10 +26,7 @@
#include <usrp2_source_c.h>
#include <gr_io_signature.h>
-#include <iostream>
-#define USRP2_SOURCE_C_DEBUG 1
-
usrp2_source_c_sptr
usrp2_make_source_c(const std::string &ifc,
const std::string &mac)
@@ -50,14 +47,3 @@
usrp2_source_c::~usrp2_source_c()
{
}
-
-void
-usrp2_source_c::copy_from_usrp2_buffer(uint32_t *src, void *dst, int nsamples)
-{
- gr_complex *out = (gr_complex *)dst;
- for (int i = 0; i < nsamples; i++) {
- float re = (int16_t)(src[i] >> 16);
- float im = (int16_t)(src[i] & 0xFFFF);
- *out++ = gr_complex(re, im);
- }
-}
Modified: usrp2/trunk/host/gr-usrp2/usrp2_source_c.h
===================================================================
--- usrp2/trunk/host/gr-usrp2/usrp2_source_c.h 2008-07-10 22:01:34 UTC (rev
8860)
+++ usrp2/trunk/host/gr-usrp2/usrp2_source_c.h 2008-07-11 00:07:01 UTC (rev
8861)
@@ -46,8 +46,6 @@
public:
~usrp2_source_c();
-
- virtual void copy_from_usrp2_buffer(uint32_t *src, void *dst, int nsamples);
};
#endif /* INCLUDED_USRP2_SOURCE_C_H */
Deleted: usrp2/trunk/host/gr-usrp2/usrp2_source_raw.cc
Deleted: usrp2/trunk/host/gr-usrp2/usrp2_source_raw.h
Deleted: usrp2/trunk/host/gr-usrp2/usrp2_table.cc
Deleted: usrp2/trunk/host/gr-usrp2/usrp2_table.h
Modified: usrp2/trunk/host/lib/Makefile.am
===================================================================
--- usrp2/trunk/host/lib/Makefile.am 2008-07-10 22:01:34 UTC (rev 8860)
+++ usrp2/trunk/host/lib/Makefile.am 2008-07-11 00:07:01 UTC (rev 8861)
@@ -26,10 +26,8 @@
gri_ethernet.cc \
gri_if_stats.cc \
gri_pktfilter.cc \
- sample_buffer.cc \
strtod_si.c \
- usrp2_basic.cc \
- usrp2_basic_thread.cc
+ usrp2_basic.cc
libusrp2_la_LIBADD = \
$(GR_OMNITHREAD_LIBS)
@@ -38,11 +36,6 @@
gri_ethernet.h \
gri_if_stats.h \
gri_pktfilter.h \
- ring_buffer.h \
- sample_buffer.h \
strtod_si.h \
- usrp2_tune_result.h \
- usrp2_basic.h \
- usrp2_basic_thread.h
+ usrp2_basic.h
-MOSTLYCLEANFILES = *~ *.loT
Deleted: usrp2/trunk/host/lib/ring_buffer.h
Deleted: usrp2/trunk/host/lib/sample_buffer.cc
Deleted: usrp2/trunk/host/lib/sample_buffer.h
Modified: usrp2/trunk/host/lib/usrp2_basic.cc
===================================================================
--- usrp2/trunk/host/lib/usrp2_basic.cc 2008-07-10 22:01:34 UTC (rev 8860)
+++ usrp2/trunk/host/lib/usrp2_basic.cc 2008-07-11 00:07:01 UTC (rev 8861)
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2007,2008 Free Software Foundation, Inc.
+ * Copyright 2007 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
@@ -20,16 +20,12 @@
#include "config.h"
#endif
#include "usrp2_basic.h"
-#include "usrp2_basic_thread.h"
#include "gri_ethernet.h"
#include "gri_pktfilter.h"
#include <usrp2_types.h>
-#include <usrp2_eth_packet.h>
#include <iostream>
-#include <stdexcept>
#include <math.h>
-#include <time.h>
-#include <errno.h>
+#include <time.h> // debug
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
@@ -39,22 +35,7 @@
#include <unistd.h>
#endif
-static void
-udelay(long usecs)
-{
- struct timeval t;
- t.tv_sec = 0;
- t.tv_usec = usecs;
- select(0, 0, 0, 0, &t);
-}
-#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
* enough implemented to check out the h/w. We will probably
@@ -70,60 +51,57 @@
#define MAX_PKTLEN 1512 // biggest thing USRP2 can swallow
// (14-byte ethernet hdr + 1500 byte payload)
-usrp2_tune_result::~usrp2_tune_result()
+
+usrp2_basic::usrp2_basic()
+ : d_ethernet(new GRI_ETHERNET()), d_pf(0), d_seqno(0), d_next_rid(0)
{
+ assert(sizeof(u2_eth_samples_t) == (size_t) MAX_PKTLEN);
}
-usrp2_basic_sptr
-usrp2_make_basic(const std::string &ifc, const u2_mac_addr_t &addr)
+usrp2_basic::~usrp2_basic()
{
- return usrp2_basic_sptr(new usrp2_basic(ifc, addr));
+ delete d_pf;
+ delete d_ethernet;
}
-usrp2_basic::usrp2_basic(const std::string &ifc, const u2_mac_addr_t &addr)
- : d_ethernet(new gri_ethernet()), d_pf(0), d_seqno(0), d_next_rid(0),
- d_rx_active(false), d_tx_active(false), d_thread(0),
- d_rx_samples(256 * (1<<10), 1000), d_tx_samples(256 * (1<<10), 1000)
+bool
+usrp2_basic::open(std::string ifname)
{
- if (USRP2_BASIC_DEBUG)
- std::cerr << "usrp2_basic: constructor" << std::endl;
+ if (!d_ethernet->open(ifname, htons(U2_ETHERTYPE)))
+ return false;
- op_id_reply_t r;
- if (!usrp2_basic::find_usrp(ifc, addr, &r))
- throw std::runtime_error("Unable to find specified USRP2.");
+ if (d_pf)
+ delete d_pf;
- d_ethernet->open(ifc, htons(U2_ETHERTYPE));
- d_pf = gri_pktfilter::make_ethertype_inbound(U2_ETHERTYPE,
d_ethernet->mac());
- if (!d_ethernet->attach_pktfilter(d_pf))
- throw std::runtime_error("Unable to attach packet filter.");
- d_addr = addr;
+ if (1){
+ d_pf = gri_pktfilter::make_ethertype_inbound(U2_ETHERTYPE,
d_ethernet->mac());
+ if (!d_ethernet->attach_pktfilter(d_pf))
+ return false;
+ }
- d_thread = new usrp2_basic_thread(this);
- d_thread->start();
-
- udelay(1000); // block for 1ms to allow thread to start
+ return true;
}
-usrp2_basic::~usrp2_basic()
+bool
+usrp2_basic::close()
{
- if (USRP2_BASIC_DEBUG)
- std::cerr << "usrp2_basic: destructor" << std::endl;
-
- delete d_pf;
-
- d_ethernet->close();
- delete d_ethernet;
-
- d_thread->stop();
- d_thread = 0; // pthread derived objects delete themselves
+ return d_ethernet->close();
}
// ------------------------------------------------------------------------
-// static
std::vector<op_id_reply_t>
-usrp2_basic::find_usrps(const std::string &ifc)
+usrp2_basic::find_usrps()
{
+ static u2_mac_addr_t broadcast_mac_addr =
+ {{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }};
+
+ 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;
@@ -134,64 +112,39 @@
op_id_reply_t op_id_reply;
};
- int r, len;
- command *c = 0;
- std::vector<op_id_reply_t> result;
- gri_ethernet *enet = 0;
- gri_pktfilter *pf = 0;
-
- enet = new gri_ethernet();
- if (!enet->open(ifc, htons(U2_ETHERTYPE)))
- goto bail;
+ command *c = (command *) pktbuf;
+ init_etf_hdrs(&c->h, broadcast_mac_addr, 0, CONTROL_CHAN, -1);
- pf = gri_pktfilter::make_ethertype_inbound(U2_ETHERTYPE, enet->mac());
- if (!enet->attach_pktfilter(pf))
- goto bail;
-
- static u2_mac_addr_t broadcast_mac_addr =
- {{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }};
-
- uint8_t pktbuf[MAX_PKTLEN];
- memset(pktbuf, 0, sizeof(pktbuf));
-
- c = (command *)pktbuf;
- c->h.ehdr.ethertype = htons(U2_ETHERTYPE);
- c->h.ehdr.dst = broadcast_mac_addr;
- memcpy(&c->h.ehdr.src, enet->mac(), 6);
- c->h.thdr.flags = 0;
- c->h.thdr.seqno = 0;
- c->h.thdr.ack = 0;
- u2p_set_word0(&c->h.fixed, 0, CONTROL_CHAN);
- u2p_set_timestamp(&c->h.fixed, -1);
c->op_id.opcode = OP_ID;
c->op_id.len = sizeof(op_id_t);
- len = std::max((size_t) MIN_PKTLEN, sizeof(command));
- if (enet->write_packet(c, len) != len)
+ int len = std::max((size_t) MIN_PKTLEN, sizeof(command));
+ if (d_ethernet->write_packet(c, len) != len){
goto bail;
+ }
/*
* Wait no longer than 10ms and read all packets available.
*/
fd_set read_fds;
FD_ZERO(&read_fds);
- FD_SET(enet->fd(), &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(enet->fd()+1, &read_fds, 0, 0, &timeout);
+ r = select(d_ethernet->fd()+1, &read_fds, 0, 0, &timeout);
- while(1) {
+ while(1){
memset(pktbuf, 0, sizeof(pktbuf));
- len = enet->read_packet_dont_block(pktbuf, sizeof(pktbuf));
+ int len = d_ethernet->read_packet_dont_block(pktbuf, sizeof(pktbuf));
if (len < 0){
perror("usrp2_basic: read_packet_dont_block");
- goto bail;
+ return result;
}
if (len == 0)
break;
- reply *rp = (reply *)pktbuf;
+ reply *rp = (reply *) pktbuf;
if (u2p_chan(&rp->h.fixed) != CONTROL_CHAN) // ignore
continue;
if (rp->op_id_reply.opcode != OP_ID_REPLY) // ignore
@@ -200,33 +153,29 @@
result.push_back(rp->op_id_reply);
}
-bail:
- if (enet)
- delete enet;
- if (pf)
- delete pf;
+ bail:
return result;
}
// static
-bool
-usrp2_basic::pick_default_usrp(const std::string &ifc, op_id_reply_t *id)
+std::vector<op_id_reply_t>
+usrp2_basic::find_usrps(const std::string &ifc)
{
- std::vector<op_id_reply_t> r = usrp2_basic::find_usrps(ifc);
- if (r.size() != 1)
- return false;
+ usrp2_basic *u2 = new usrp2_basic();
+ if (!u2 || !u2->open(ifc)) {
+ std::cerr << "Unable to open network interface: " << ifc << std::endl;
+ return std::vector<op_id_reply_t>(0);
+ }
- if (id)
- *id = r[0];
-
- return true;
+ std::vector<op_id_reply_t> r = u2->find_usrps();
+ delete u2;
+ return r;
}
-// static
bool
-usrp2_basic::find_usrp(const std::string &ifc, const u2_mac_addr_t &addr,
op_id_reply_t *u)
+usrp2_basic::find_usrp_by_mac(const u2_mac_addr_t &addr, op_id_reply_t *u)
{
- std::vector<op_id_reply_t> r = usrp2_basic::find_usrps(ifc);
+ std::vector<op_id_reply_t> r = find_usrps();
for (unsigned i = 0; i < r.size(); i++){
if (r[i].addr == addr){
if (u)
@@ -234,7 +183,6 @@
return true;
}
}
-
return false;
}
@@ -245,7 +193,7 @@
*/
bool
-usrp2_basic::set_rx_gain(double gain)
+usrp2_basic::set_rx_gain(const u2_mac_addr_t &which, double gain)
{
uint8_t pktbuf[MAX_PKTLEN];
memset(pktbuf, 0, sizeof(pktbuf));
@@ -257,7 +205,7 @@
};
command *c = (command *) pktbuf;
- init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+ init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
c->op.opcode = OP_CONFIG_RX_V2;
c->op.len = sizeof(op_config_rx_v2_t);
@@ -279,7 +227,8 @@
}
bool
-usrp2_basic::set_rx_freq(double freq, usrp2_tune_result *result)
+usrp2_basic::set_rx_freq(const u2_mac_addr_t &which, double freq,
+ usrp2_tune_result *result)
{
uint8_t pktbuf[MAX_PKTLEN];
memset(pktbuf, 0, sizeof(pktbuf));
@@ -291,7 +240,7 @@
};
command *c = (command *) pktbuf;
- init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+ init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
c->op.opcode = OP_CONFIG_RX_V2;
c->op.len = sizeof(op_config_rx_v2_t);
@@ -306,15 +255,19 @@
c->eop.len = sizeof(op_eop_t);
int len = std::max((size_t) MIN_PKTLEN, sizeof(command));
- if (d_ethernet->write_packet(c, len) == len) {
- // FIXME: wait for corresponding reply, set tune result members
- }
+ if (d_ethernet->write_packet(c, len) != len)
+ return false;
+ // FIXME wait for corresponding reply, etc.
+
+ if (result)
+ memset(result, 0, sizeof(*result));
+
return true;
}
bool
-usrp2_basic::set_rx_decim(int decimation_factor)
+usrp2_basic::set_rx_decim(const u2_mac_addr_t &which, int decimation_factor)
{
uint8_t pktbuf[MAX_PKTLEN];
memset(pktbuf, 0, sizeof(pktbuf));
@@ -326,7 +279,7 @@
};
command *c = (command *) pktbuf;
- init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+ init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
c->op.opcode = OP_CONFIG_RX_V2;
c->op.len = sizeof(op_config_rx_v2_t);
@@ -344,12 +297,11 @@
// FIXME wait for corresponding reply, etc.
- d_rx_decim = decimation_factor;
return true;
}
bool
-usrp2_basic::set_rx_scale_iq(int scale_i, int scale_q)
+usrp2_basic::set_rx_scale_iq(const u2_mac_addr_t &which, int scale_i, int
scale_q)
{
uint8_t pktbuf[MAX_PKTLEN];
memset(pktbuf, 0, sizeof(pktbuf));
@@ -361,7 +313,7 @@
};
command *c = (command *) pktbuf;
- init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+ init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
c->op.opcode = OP_CONFIG_RX_V2;
c->op.len = sizeof(op_config_rx_v2_t);
@@ -383,7 +335,7 @@
}
bool
-usrp2_basic::start_rx_streaming(unsigned int items_per_frame)
+usrp2_basic::start_rx_streaming(const u2_mac_addr_t &which, unsigned int
items_per_frame)
{
if (items_per_frame == 0) // provide our default
items_per_frame = 250;
@@ -398,7 +350,7 @@
};
command *c = (command *) pktbuf;
- init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+ init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
c->op.opcode = OP_START_RX_STREAMING;
c->op.len = sizeof(op_start_rx_streaming_t);
@@ -411,12 +363,11 @@
if (d_ethernet->write_packet(c, len) != len)
return false;
- d_rx_active = true;
return true;
}
bool
-usrp2_basic::stop_rx()
+usrp2_basic::stop_rx(const u2_mac_addr_t &which)
{
uint8_t pktbuf[MAX_PKTLEN];
memset(pktbuf, 0, sizeof(pktbuf));
@@ -427,7 +378,7 @@
};
command *c = (command *) pktbuf;
- init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+ init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
c->op_stop_rx.opcode = OP_STOP_RX;
c->op_stop_rx.len = sizeof(op_stop_rx_t);
@@ -435,7 +386,6 @@
if (d_ethernet->write_packet(c, len) != len)
return false;
- d_rx_active = false;
return true;
}
@@ -446,7 +396,7 @@
*/
bool
-usrp2_basic::set_tx_gain(double gain)
+usrp2_basic::set_tx_gain(const u2_mac_addr_t &which, double gain)
{
uint8_t pktbuf[MAX_PKTLEN];
memset(pktbuf, 0, sizeof(pktbuf));
@@ -458,7 +408,7 @@
};
command *c = (command *) pktbuf;
- init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+ init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
c->op.opcode = OP_CONFIG_TX_V2;
c->op.len = sizeof(op_config_tx_v2_t);
@@ -480,7 +430,8 @@
}
bool
-usrp2_basic::set_tx_freq(double freq, usrp2_tune_result *result)
+usrp2_basic::set_tx_freq(const u2_mac_addr_t &which, double freq,
+ usrp2_tune_result *result)
{
uint8_t pktbuf[MAX_PKTLEN];
memset(pktbuf, 0, sizeof(pktbuf));
@@ -492,7 +443,7 @@
};
command *c = (command *) pktbuf;
- init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+ init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
c->op.opcode = OP_CONFIG_TX_V2;
c->op.len = sizeof(op_config_tx_v2_t);
@@ -519,7 +470,7 @@
}
bool
-usrp2_basic::set_tx_interp(int interpolation_factor)
+usrp2_basic::set_tx_interp(const u2_mac_addr_t &which, int
interpolation_factor)
{
uint8_t pktbuf[MAX_PKTLEN];
memset(pktbuf, 0, sizeof(pktbuf));
@@ -531,7 +482,7 @@
};
command *c = (command *) pktbuf;
- init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+ init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
c->op.opcode = OP_CONFIG_TX_V2;
c->op.len = sizeof(op_config_tx_v2_t);
@@ -553,7 +504,7 @@
}
bool
-usrp2_basic::set_tx_scale_iq(int scale_i, int scale_q)
+usrp2_basic::set_tx_scale_iq(const u2_mac_addr_t &which, int scale_i, int
scale_q)
{
uint8_t pktbuf[MAX_PKTLEN];
memset(pktbuf, 0, sizeof(pktbuf));
@@ -565,7 +516,7 @@
};
command *c = (command *) pktbuf;
- init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+ init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
c->op.opcode = OP_CONFIG_TX_V2;
c->op.len = sizeof(op_config_tx_v2_t);
@@ -597,33 +548,33 @@
}
int
-usrp2_basic::read_raw_samples(u2_eth_samples_t *pkt, int nmax)
+usrp2_basic::read_raw_samples(const u2_mac_addr_t &which,
+ u2_eth_samples_t *pkt)
{
- int nmaxbytes = (nmax == -1) ? sizeof(*pkt) : nmax*sizeof(uint32_t) +
sizeof(u2_eth_packet_t);
- int readsize = std::min(int(sizeof(*pkt)), nmaxbytes);
- int len = d_ethernet->read_packet(pkt, readsize);
+ int len = d_ethernet->read_packet(pkt, sizeof(*pkt));
+ // printf("read_packet = %d\n", len);
if (len <= 0)
return len;
// FIXME check channel
- if ((size_t) len < sizeof(u2_eth_packet_t)) {
- fprintf(stderr, "usrp2_basic::read_raw_samples: short read, len=%d\n",
len);
+
+ // shouldn't happen
+ if ((size_t) len < sizeof(u2_eth_packet_t))
return 0;
- }
+ // convert to samples
int r = (len - sizeof(u2_eth_packet_t)) / sizeof(uint32_t);
- if (USRP2_BASIC_DEBUG)
- fprintf(stderr, "usrp2_basic::read_raw_samples: nmax=%d nmaxbytes=%d
readsize=%d len=%d r=%d\n",
- nmax, nmaxbytes, readsize, len, r);
+ // printf("read_raw_samples = %d\n", r);
return r;
}
int
-usrp2_basic::read_samples(u2_eth_samples_t *pkt, int nmax)
+usrp2_basic::read_samples(const u2_mac_addr_t &which,
+ u2_eth_samples_t *pkt)
{
- int r = read_raw_samples(pkt, nmax);
+ int r = read_raw_samples(which, pkt);
#ifndef WORDS_BIGENDIAN
for (int i = 0; i < r; i++)
@@ -636,12 +587,13 @@
// ------------------------------------------------------------------------
bool
-usrp2_basic::write_raw_samples(u2_eth_samples_t *pkt, size_t nsamples)
+usrp2_basic::write_raw_samples(const u2_mac_addr_t &which,
+ u2_eth_samples_t *pkt, size_t nsamples)
{
if (nsamples > U2_MAX_SAMPLES)
return false;
- init_et_hdrs(&pkt->hdrs, d_addr);
+ init_et_hdrs(&pkt->hdrs, which);
size_t len = sizeof(u2_eth_packet_t) + nsamples * sizeof(uint32_t);
int n = d_ethernet->write_packet(pkt, len);
@@ -655,19 +607,21 @@
}
bool
-usrp2_basic::write_samples(u2_eth_samples_t *pkt, size_t nsamples)
+usrp2_basic::write_samples(const u2_mac_addr_t &which,
+ u2_eth_samples_t *pkt, size_t nsamples)
{
#ifndef WORDS_BIGENDIAN
for (size_t i = 0; i < nsamples; i++)
pkt->samples[i] = htonl(pkt->samples[i]);
#endif
- return write_raw_samples(pkt, nsamples);
+ return write_raw_samples(which, pkt, nsamples);
}
bool
-usrp2_basic::burn_mac_addr(const u2_mac_addr_t &new_addr)
+usrp2_basic::burn_mac_addr(const u2_mac_addr_t &which,
+ const u2_mac_addr_t &new_addr)
{
uint8_t pktbuf[MAX_PKTLEN];
memset(pktbuf, 0, sizeof(pktbuf));
@@ -678,7 +632,7 @@
};
command *c = (command *) pktbuf;
- init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+ init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
c->op.opcode = OP_BURN_MAC_ADDR;
c->op.len = sizeof(op_burn_mac_addr_t);
@@ -746,7 +700,7 @@
bool
-usrp2_basic::read_time(uint32_t *time)
+usrp2_basic::read_time(const u2_mac_addr_t &which, uint32_t *time)
{
*time = 0;
@@ -759,7 +713,7 @@
};
command *c = (command *) pktbuf;
- init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+ init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
c->op.opcode = OP_READ_TIME;
c->op.len = sizeof(op_read_time_t);
@@ -836,97 +790,3 @@
return memcmp(&a, &b, sizeof(u2_mac_addr_t)) == 0;
}
-void usrp2_basic::loop_body()
-{
- fd_set read_fds, write_fds;
- FD_ZERO(&read_fds);
- FD_ZERO(&write_fds);
-
- FD_SET(d_ethernet->fd(), &read_fds);
-
- if (d_tx_active)
- FD_SET(d_ethernet->fd(), &write_fds);
-
- struct timeval timeout;
- timeout.tv_sec = 0;
- timeout.tv_usec = 100 * 1000; // 100 ms
-
- 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)) {
- DEBUG_LOG("r"); // data to read()
- rx_frames();
- }
-
- if (FD_ISSET(d_ethernet->fd(), &write_fds)) {
- DEBUG_LOG("w"); // can write()
- tx_frames();
- }
- }
- else if (r == 0) {
- DEBUG_LOG("T"); // socket timeout
- return;
- }
- else {
- if (errno == EINTR)
- DEBUG_LOG("I"); // interrupted system call
- else
- DEBUG_LOG("!"); // error on socket
- return;
- }
-}
-
-void
-usrp2_basic::rx_frames()
-{
- uint8_t pktbuf[MAX_PKTLEN];
- memset(pktbuf, 0, sizeof(pktbuf));
-
- int len;
- while (1) {
- len = d_ethernet->read_packet_dont_block(pktbuf, sizeof(pktbuf));
-
- if (len < 0) {
- DEBUG_LOG("!"); // error
- return;
- }
- else if (len == 0) {
- DEBUG_LOG("|"); // no more frames
- return;
- }
- else if ((size_t)len < sizeof(u2_eth_packet_t)) {
- DEBUG_LOG("<"); // short frame
- }
- else
- DEBUG_LOG("R"); // rx ok
-
- u2_eth_packet_t *p = (u2_eth_packet_t *)pktbuf;
- if (u2p_chan(&p->fixed) == CONTROL_CHAN) {
- DEBUG_LOG("-"); // ignore (FIXME: multiple channels, control channel)
- continue;
- }
-
- if (!d_rx_active)
- 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(2, "uO", 2); // overrun
- return;
- }
-
- d_rx_samples.write(plen, &s->samples[0], 0);
- }
-}
-
-void
-usrp2_basic::tx_frames()
-{
-}
-
-size_t usrp2_basic::rx_samples(size_t nmax, uint32_t *samples, uint32_t *flags)
-{
- return d_rx_samples.read(nmax, samples, flags);
-}
Modified: usrp2/trunk/host/lib/usrp2_basic.h
===================================================================
--- usrp2/trunk/host/lib/usrp2_basic.h 2008-07-10 22:01:34 UTC (rev 8860)
+++ usrp2/trunk/host/lib/usrp2_basic.h 2008-07-11 00:07:01 UTC (rev 8861)
@@ -23,79 +23,78 @@
#include <boost/shared_ptr.hpp>
#include <vector>
#include "usrp2_eth_packet.h"
-#include "usrp2_tune_result.h"
-#include "sample_buffer.h"
class gri_ethernet;
+class gri_ethernet_pfring;
class gri_pktfilter;
-class usrp2_basic;
-typedef boost::shared_ptr<usrp2_basic> usrp2_basic_sptr;
+#define GRI_ETHERNET gri_ethernet
-class usrp2_basic_thread;
+//! Provides detailed result of tuning request
-usrp2_basic_sptr usrp2_make_basic(const std::string &ifc, const u2_mac_addr_t
&addr);
+struct usrp2_tune_result
+{
+ // RF frequency that corresponds to DC in the IF
+ double baseband_freq;
+ // frequency programmed into the DDC/DUC
+ double dxc_freq;
+
+ // residual frequency (typically < 0.01 Hz)
+ double residual_freq;
+
+ // is the spectrum inverted?
+ bool spectrum_inverted;
+
+ usrp2_tune_result()
+ : baseband_freq(0), dxc_freq(0), residual_freq(0),
spectrum_inverted(false) {}
+};
+
+
class usrp2_basic : public boost::noncopyable
{
-private:
- friend usrp2_basic_sptr usrp2_make_basic(const std::string &ifc, const
u2_mac_addr_t &addr);
- friend class usrp2_basic_thread;
- usrp2_basic(const std::string &ifc, const u2_mac_addr_t &addr);
-
- gri_ethernet *d_ethernet;
+ GRI_ETHERNET *d_ethernet;
gri_pktfilter *d_pf;
int d_seqno;
int d_next_rid;
- u2_mac_addr_t d_addr;
- int d_rx_decim;
- bool d_rx_active;
- bool d_tx_active;
-
- usrp2_basic_thread *d_thread;
- sample_buffer d_rx_samples;
- sample_buffer d_tx_samples;
-
+
void init_et_hdrs(u2_eth_packet_t *p, const u2_mac_addr_t &dst);
void init_etf_hdrs(u2_eth_packet_t *p,
const u2_mac_addr_t &dst,
int word0_flags, int chan, uint32_t timestamp);
- void loop_body();
- void rx_frames();
- void tx_frames();
-
public:
- // ---- Static methods ----
+ usrp2_basic();
+ ~usrp2_basic();
/*!
- * \brief Return a vector that describes all usrps found on an interface.
- * \param[in] ifc interface name, e.g., "eth0"
+ * \param ifname interface name, e.g., "eth0"
*/
+ bool open(std::string ifname = "eth0");
+ bool close();
+
+ /*!
+ * Return a vector that describes all usrps found on already open'd interface
+ */
+ std::vector<op_id_reply_t> find_usrps();
+
+ /*!
+ * Return a vector that describes all usrps found on a specified interface.
+ */
static std::vector<op_id_reply_t> find_usrps(const std::string &ifc);
/*!
- * \brief Find usrp by interface and mac address
+ * \brief Find usrp by mac address
*
- * \param[in] ifc interface name, e.g., "eth0"
* \param[in] addr is the mac address of the USRP to look for
* \param[out] u if not 0, is filled in with USRP info if found
*
* \returns true iff the specified usrp was found
*/
- static bool find_usrp(const std::string &ifc, const u2_mac_addr_t &addr,
op_id_reply_t *u);
+ bool find_usrp_by_mac(const u2_mac_addr_t &addr, op_id_reply_t *u);
/*!
- * \brief Find a default USRP2 on an interface
- * \param[in] ifc interface name, e.g., "eth0"
- * \param[out] id if not 0, is filled in with ID reply information if found
- *
- * \returns true iff a single USRP2 is enumerated on the bus
- */
- static bool pick_default_usrp(const std::string &ifc, op_id_reply_t *id);
-
- /*!
* \brief Parse short or long format mac address.
*
* \param[in] s must be either HH:HH or HH:HH:HH:HH:HH:HH.
@@ -105,41 +104,60 @@
*/
static bool parse_mac_addr(const std::string &s, u2_mac_addr_t *p);
- // ---- Instance methods ----
- ~usrp2_basic();
-
/*
* Rx configuration and control
*/
- bool set_rx_gain(double gain);
- bool set_rx_freq(double frequency, usrp2_tune_result *result);
- bool set_rx_decim(int decimation_factor);
- bool set_rx_scale_iq(int scale_i, int scale_q);
+ bool set_rx_gain(const u2_mac_addr_t &which, double gain);
+ bool set_rx_freq(const u2_mac_addr_t &which, double frequency,
usrp2_tune_result *result);
+ bool set_rx_decim(const u2_mac_addr_t &which, int decimation_factor);
+ bool set_rx_scale_iq(const u2_mac_addr_t &which, int scale_i, int scale_q);
//! start streaming Rx samples
- bool start_rx_streaming(unsigned int items_per_frame=0);
+ bool start_rx_streaming(const u2_mac_addr_t &which, unsigned int
items_per_frame=0);
//! stop streaming Rx samples
- bool stop_rx();
+ bool stop_rx(const u2_mac_addr_t &which);
- int rx_decim_rate() const { return d_rx_decim; }
-
+
/*
* Tx configuration and control
*/
- bool set_tx_gain(double gain);
- bool set_tx_freq(double frequency, usrp2_tune_result *result);
- bool set_tx_interp(int interpolation_factor);
- bool set_tx_scale_iq(int scale_i, int scale_q);
+ bool set_tx_gain(const u2_mac_addr_t &which, double gain);
+ bool set_tx_freq(const u2_mac_addr_t &which, double frequency,
usrp2_tune_result *result);
+ bool set_tx_interp(const u2_mac_addr_t &which, int interpolation_factor);
+ bool set_tx_scale_iq(const u2_mac_addr_t &which, int scale_i, int scale_q);
+
+#if 0
+ bool start_rx(const u2_mac_addr_t &which,
+ double freq,
+ unsigned int decim,
+ unsigned int total_samples, // 0 to begin streaming, or [9,
2**21 - 1]
+ unsigned int samples_per_frame, // [9, 372] or [9, 506] if
MTU==2034
+ int scale_i, // 16.0 fixed point format
+ int scale_q, // 16.0 fixed point format
+ bool rx_now = true, // if true begin receiving now
+ uint32_t rx_time = -1 // otherwise begin receiving at
rx_time
+ );
+
+
+ bool config_tx(const u2_mac_addr_t &which,
+ double freq,
+ unsigned int interp,
+ int scale_i, // 16.0 fixed point format
+ int scale_q // 16.0 fixed point format
+ );
+#endif
+
/*!
* \brief Read raw samples from USRP2.
*
* \param pkt contains the raw (non-endian corrected) samples
* \returns number of valid samples in pkt.
*/
- int read_raw_samples(u2_eth_samples_t *pkt, int nmax = -1);
+ int read_raw_samples(const u2_mac_addr_t &which,
+ u2_eth_samples_t *pkt);
/*!
* \brief Read native-endian samples from USRP2.
@@ -147,7 +165,8 @@
* \param pkt contains native-endian samples.
* \returns number of valid samples in pkt.
*/
- int read_samples(u2_eth_samples_t *pkt, int nmax = -1);
+ int read_samples(const u2_mac_addr_t &which,
+ u2_eth_samples_t *pkt);
/*!
* \brief Write raw samples to USRP2.
@@ -160,7 +179,8 @@
*
* \returns true iff successful
*/
- bool write_raw_samples(u2_eth_samples_t *pkt, size_t nsamples);
+ bool write_raw_samples(const u2_mac_addr_t &which,
+ u2_eth_samples_t *pkt, size_t nsamples);
/*!
* \brief Write native-endian samples to USRP2.
@@ -173,43 +193,32 @@
*
* \returns true iff successful
*/
- bool write_samples(u2_eth_samples_t *pkt, size_t nsamples);
+ bool write_samples(const u2_mac_addr_t &which,
+ u2_eth_samples_t *pkt, size_t nsamples);
/*!
- * Receive at most nmax samples. Returns number of samples actually read,
- * and places the OR of the sample ranges into the flags variable.
- *
- * FIXME: multiple channels
- */
- 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.
* We're using it now for testing only.
*/
- bool read_time(uint32_t *time);
+ bool read_time(const u2_mac_addr_t &which, uint32_t *time);
- bool burn_mac_addr(const u2_mac_addr_t &new_addr);
+ bool burn_mac_addr(const u2_mac_addr_t &which,
+ const u2_mac_addr_t &new_addr);
//! Return frequency of master oscillator on USRP2.
- long fpga_master_clock_freq () const { return 100000000; } // 100e6
+ long fpga_master_clock_freq () const { return 100000000; } // 100e6
//! Return A/D sample rate
long adc_rate() const { return fpga_master_clock_freq(); }
//! Return D/A sample rate
long dac_rate() const { return fpga_master_clock_freq(); }
+
};
std::ostream& operator<<(std::ostream &os, const op_id_reply_t &x);
Deleted: usrp2/trunk/host/lib/usrp2_basic_thread.cc
Deleted: usrp2/trunk/host/lib/usrp2_basic_thread.h
Deleted: usrp2/trunk/host/lib/usrp2_tune_result.h
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8861 - in usrp2/trunk/host: apps gr-usrp2 lib,
eb <=