summaryrefslogtreecommitdiff
path: root/gr-msdd6000
diff options
context:
space:
mode:
Diffstat (limited to 'gr-msdd6000')
-rw-r--r--gr-msdd6000/src/.gitignore2
-rw-r--r--gr-msdd6000/src/Makefile.am26
-rw-r--r--gr-msdd6000/src/Makefile.swig.gen193
-rw-r--r--gr-msdd6000/src/msdd6000_rs.cc286
-rw-r--r--gr-msdd6000/src/msdd6000_rs.h66
-rw-r--r--gr-msdd6000/src/msdd_rs.i93
-rw-r--r--gr-msdd6000/src/msdd_rs_source_simple.cc237
-rw-r--r--gr-msdd6000/src/msdd_rs_source_simple.h87
-rwxr-xr-xgr-msdd6000/src/python-examples/msdd_rs_spec_an.py350
9 files changed, 1333 insertions, 7 deletions
diff --git a/gr-msdd6000/src/.gitignore b/gr-msdd6000/src/.gitignore
index 33061d3ab..ca4a54fb0 100644
--- a/gr-msdd6000/src/.gitignore
+++ b/gr-msdd6000/src/.gitignore
@@ -4,3 +4,5 @@
/.deps
/msdd.cc
/msdd.py
+/msdd_rs.cc
+/msdd_rs.py
diff --git a/gr-msdd6000/src/Makefile.am b/gr-msdd6000/src/Makefile.am
index 0865d40de..9ae4efb0a 100644
--- a/gr-msdd6000/src/Makefile.am
+++ b/gr-msdd6000/src/Makefile.am
@@ -28,26 +28,40 @@ AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(PYTHON_CPPFLAGS) \
grinclude_HEADERS = \
msdd_source_simple.h \
msdd_buffer_copy_behaviors.h \
- msdd6000.h
+ msdd6000.h \
+ msdd_rs_source_simple.h \
+ msdd6000_rs.h
-lib_LTLIBRARIES = libgnuradio-msdd6000.la
+lib_LTLIBRARIES = libgnuradio-msdd6000.la \
+ libgnuradio-msdd6000_rs.la
libgnuradio_msdd6000_la_SOURCES = \
msdd_source_simple.cc \
msdd6000.cc
+
+libgnuradio_msdd6000_rs_la_SOURCES = \
+ msdd_rs_source_simple.cc \
+ msdd6000_rs.cc
+
libgnuradio_msdd6000_la_LIBADD = \
$(GNURADIO_CORE_LA)
libgnuradio_msdd6000_la_LDFLAGS = \
$(NO_UNDEFINED)
+libgnuradio_msdd6000_rs_la_LIBADD = \
+ $(GNURADIO_CORE_LA)
+
+libgnuradio_msdd6000_rs_la_LDFLAGS = \
+ $(NO_UNDEFINED)
+
if PYTHON
#################################
# SWIG interface and library
TOP_SWIG_IFILES = \
- msdd.i
+ msdd.i msdd_rs.i
# Install so that they end up available as:
# import gnuradio.msdd
@@ -56,10 +70,16 @@ TOP_SWIG_IFILES = \
msdd_pythondir_category = \
gnuradio
+msdd_rs_pythondir_category = \
+ gnuradio
+
# additional libraries for linking with the SWIG-generated library
msdd_la_swig_libadd = \
libgnuradio-msdd6000.la
+msdd_rs_la_swig_libadd = \
+ libgnuradio-msdd6000_rs.la
+
include $(top_srcdir)/Makefile.swig
# add some of the variables generated inside the Makefile.swig.gen
diff --git a/gr-msdd6000/src/Makefile.swig.gen b/gr-msdd6000/src/Makefile.swig.gen
index 5c2920230..ced3979f7 100644
--- a/gr-msdd6000/src/Makefile.swig.gen
+++ b/gr-msdd6000/src/Makefile.swig.gen
@@ -33,14 +33,21 @@
## this has to be done in the including Makefile.am -before-
## Makefile.swig is included.
+
msdd_pythondir_category ?= gnuradio/msdd
msdd_pylibdir_category ?= $(msdd_pythondir_category)
msdd_pythondir = $(pythondir)/$(msdd_pythondir_category)
msdd_pylibdir = $(pyexecdir)/$(msdd_pylibdir_category)
+msdd_rs_pythondir_category ?= gnuradio/msdd_rs
+msdd_rs_pylibdir_category ?= $(msdd_rs_pythondir_category)
+msdd_rs_pythondir = $(pythondir)/$(msdd_rs_pythondir_category)
+msdd_rs_pylibdir = $(pyexecdir)/$(msdd_rs_pylibdir_category)
+
## SWIG headers are always installed into the same directory.
msdd_swigincludedir = $(swigincludedir)
+msdd_rs_swigincludedir = $(swigincludedir)
## This is a template file for a "generated" Makefile addition (in
## this case, "Makefile.swig.gen"). By including the top-level
@@ -63,6 +70,7 @@ msdd_swigincludedir = $(swigincludedir)
## the SWIG-generated files will be removed from the distribution.
STAMPS += $(DEPDIR)/msdd-generate-*
+STAMPS += $(DEPDIR)/msdd_rs-generate-*
## Other cleaned files: dependency files generated by SWIG or this Makefile
@@ -72,27 +80,40 @@ MOSTLYCLEANFILES += $(DEPDIR)/*.S*
## .h file is sometimes built, but not always ... so that one has to
## be added manually by the including Makefile.am .
-swig_built_sources += msdd.py msdd.cc
+swig_built_sources += msdd.py msdd_rs.py msdd.cc msdd_rs.cc
## Various SWIG variables. These can be overloaded in the including
## Makefile.am by setting the variable value there, then including
## Makefile.swig .
msdd_swiginclude_HEADERS = \
- msdd.i \
+ msdd.i \
+ msdd_rs.i \
$(msdd_swiginclude_headers)
msdd_pylib_LTLIBRARIES = \
_msdd.la
+msdd_rs_pylib_LTLIBRARIES = \
+ _msdd_rs.la
+
_msdd_la_SOURCES = \
- msdd.cc \
+ msdd.cc \
$(msdd_la_swig_sources)
+_msdd_rs_la_SOURCES = \
+ msdd_rs.cc \
+ $(msdd_la_swig_sources)
+
+
_msdd_la_LIBADD = \
$(STD_SWIG_LA_LIB_ADD) \
$(msdd_la_swig_libadd)
+_msdd_rs_la_LIBADD = \
+ $(STD_SWIG_LA_LIB_ADD) \
+ $(msdd_rs_la_swig_libadd)
+
_msdd_la_LDFLAGS = \
$(STD_SWIG_LA_LD_FLAGS) \
$(msdd_la_swig_ldflags)
@@ -101,10 +122,22 @@ _msdd_la_CXXFLAGS = \
$(STD_SWIG_CXX_FLAGS) \
$(msdd_la_swig_cxxflags)
+_msdd_rs_la_LDFLAGS = \
+ $(STD_SWIG_LA_LD_FLAGS) \
+ $(msdd_rs_la_swig_ldflags)
+
+_msdd_rs_la_CXXFLAGS = \
+ $(STD_SWIG_CXX_FLAGS) \
+ $(msdd_rs_la_swig_cxxflags)
+
msdd_python_PYTHON = \
- msdd.py \
+ msdd.py \
$(msdd_python)
+msdd_rs_python_PYTHON = \
+ msdd_rs.py \
+ $(msdd_rs_python)
+
## Entry rule for running SWIG
msdd.h msdd.py msdd.cc: msdd.i
@@ -251,9 +284,161 @@ $(DEPDIR)/msdd-generate-stamp:
##
touch $(DEPDIR)/msdd-generate-stamp
+
+
+
+
+
+msdd_rs.h msdd_rs.py msdd_rs.cc: msdd_rs.i
+## This rule will get called only when MAKE decides that one of the
+## targets needs to be created or re-created, because:
+##
+## * The .i file is newer than any or all of the generated files;
+##
+## * Any or all of the .cc, .h, or .py files does not exist and is
+## needed (in the case this file is not needed, the rule for it is
+## ignored); or
+##
+## * Some SWIG-based dependecy of the .cc file isn't met and hence the
+## .cc file needs be be regenerated. Explanation: Because MAKE
+## knows how to handle dependencies for .cc files (regardless of
+## their name or extension), then the .cc file is used as a target
+## instead of the .i file -- but with the dependencies of the .i
+## file. It is this last reason why the line:
+##
+## if test -f $@; then :; else
+##
+## cannot be used in this case: If a .i file dependecy is not met,
+## then the .cc file needs to be rebuilt. But if the stamp is newer
+## than the .cc file, and the .cc file exists, then in the original
+## version (with the 'test' above) the internal MAKE call will not
+## be issued and hence the .cc file will not be rebuilt.
+##
+## Once execution gets to here, it should always proceed no matter the
+## state of a stamp (as discussed in link above). The
+## $(DEPDIR)/msdd-generate stuff is used to allow for parallel
+## builds to "do the right thing". The stamp has no relationship with
+## either the target files or dependency file; it is used solely for
+## the protection of multiple builds during a given call to MAKE.
+##
+## Catch signals SIGHUP (1), SIGINT (2), SIGPIPE (13), and SIGTERM
+## (15). At a caught signal, the quoted command will be issued before
+## exiting. In this case, remove any stamp, whether temporary of not.
+## The trap is valid until the process exits; the process includes all
+## commands appended via "\"s.
+##
+ trap 'rm -rf $(DEPDIR)/msdd_rs-generate-*' 1 2 13 15; \
+##
+## Create a temporary directory, which acts as a lock. The first
+## process to create the directory will succeed and issue the MAKE
+## command to do the actual work, while all subsequent processes will
+## fail -- leading them to wait for the first process to finish.
+##
+ if mkdir $(DEPDIR)/msdd_rs-generate-lock 2>/dev/null; then \
+##
+## This code is being executed by the first process to succeed in
+## creating the directory lock.
+##
+## Remove the stamp associated with this filename.
+##
+ rm -f $(DEPDIR)/msdd_rs-generate-stamp; \
+##
+## Tell MAKE to run the rule for creating this stamp.
+##
+ $(MAKE) $(AM_MAKEFLAGS) $(DEPDIR)/msdd_rs-generate-stamp WHAT=$<; \
+##
+## Now that the .cc, .h, and .py files have been (re)created from the
+## .i file, future checking of this rule during the same MAKE
+## execution will come back that the rule doesn't need to be executed
+## because none of the conditions mentioned at the start of this rule
+## will be positive. Remove the the directory lock, which frees up
+## any waiting process(es) to continue.
+##
+ rmdir $(DEPDIR)/msdd_rs-generate-lock; \
+ else \
+##
+## This code is being executed by any follower processes while the
+## directory lock is in place.
+##
+## Wait until the first process is done, testing once per second.
+##
+ while test -d $(DEPDIR)/msdd_rs-generate-lock; do \
+ sleep 1; \
+ done; \
+##
+## Succeed if and only if the first process succeeded; exit this
+## process returning the status of the generated stamp.
+##
+ test -f $(DEPDIR)/msdd_rs-generate-stamp; \
+ exit $$?; \
+ fi;
+
+$(DEPDIR)/msdd_rs-generate-stamp:
+## This rule will be called only by the first process issuing the
+## above rule to succeed in creating the lock directory, after
+## removing the actual stamp file in order to guarantee that MAKE will
+## execute this rule.
+##
+## Call SWIG to generate the various output files; special
+## post-processing on 'mingw32' host OS for the dependency file.
+##
+ if $(SWIG) $(STD_SWIG_PYTHON_ARGS) $(msdd_rs_swig_args) \
+ -MD -MF $(DEPDIR)/msdd_rs.Std \
+ -module msdd_rs -o msdd_rs.cc $(WHAT); then \
+ if test $(host_os) = mingw32; then \
+ $(RM) $(DEPDIR)/msdd_rs.Sd; \
+ $(SED) 's,\\\\,/,g' < $(DEPDIR)/msdd_rs.Std \
+ > $(DEPDIR)/msdd_rs.Sd; \
+ $(RM) $(DEPDIR)/msdd_rs.Std; \
+ $(MV) $(DEPDIR)/msdd_rs.Sd $(DEPDIR)/msdd_rs.Std; \
+ fi; \
+ else \
+ $(RM) $(DEPDIR)/msdd_rs.S*; exit 1; \
+ fi;
+##
+## Mess with the SWIG output .Std dependency file, to create a
+## dependecy file valid for the input .i file: Basically, simulate the
+## dependency file created for libraries by GNU's libtool for C++,
+## where all of the dependencies for the target are first listed, then
+## each individual dependency is listed as a target with no further
+## dependencies.
+##
+## (1) remove the current dependency file
+##
+ $(RM) $(DEPDIR)/msdd_rs.d
+##
+## (2) Copy the whole SWIG file:
+##
+ cp $(DEPDIR)/msdd_rs.Std $(DEPDIR)/msdd_rs.d
+##
+## (3) all a carriage return to the end of the dependency file.
+##
+ echo "" >> $(DEPDIR)/msdd_rs.d
+##
+## (4) from the SWIG file, remove the first line (the target); remove
+## trailing " \" and " " from each line. Append ":" to each line,
+## followed by 2 carriage returns, then append this to the end of
+## the dependency file.
+##
+ $(SED) -e '1d;s, \\,,g;s, ,,g' < $(DEPDIR)/msdd_rs.Std | \
+ awk '{ printf "%s:\n\n", $$0 }' >> $(DEPDIR)/msdd_rs.d
+##
+## (5) remove the SWIG-generated file
+##
+ $(RM) $(DEPDIR)/msdd_rs.Std
+##
+## Create the stamp for this filename generation, to signal success in
+## executing this rule; allows other threads waiting on this process
+## to continue.
+##
+ touch $(DEPDIR)/msdd_rs-generate-stamp
+
# KLUDGE: Force runtime include of a SWIG dependency file. This is
# not guaranteed to be portable, but will probably work. If it works,
# we have accurate dependencies for our swig stuff, which is good.
+
@am__include@ @am__quote@./$(DEPDIR)/msdd.d@am__quote@
+@am__include@ @am__quote@./$(DEPDIR)/msdd_rs.d@am__quote@
+
diff --git a/gr-msdd6000/src/msdd6000_rs.cc b/gr-msdd6000/src/msdd6000_rs.cc
new file mode 100644
index 000000000..d78f2b4da
--- /dev/null
+++ b/gr-msdd6000/src/msdd6000_rs.cc
@@ -0,0 +1,286 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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, or (at your option)
+ * any later version.
+ *
+ * GNU Radio 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <msdd6000_rs.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+
+#define DEBUG(A) printf("=debug=> %s\n", A)
+
+static void
+optimize_socket(int socket);
+
+/*
+ * Holds types that need autoconf help. They're here and not in the .h file because
+ * here we've got access to config.h
+ */
+class MSDD6000_RS::detail {
+public:
+ struct sockaddr_in d_sockaddr;
+};
+
+
+MSDD6000_RS::MSDD6000_RS(char* addr)
+ : d_detail(new MSDD6000_RS::detail())
+{
+ d_sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
+
+ optimize_socket(d_sock);
+
+
+ // set up remote sockaddr
+// int s = inet_aton(addr, &d_adx);
+ d_detail->d_sockaddr.sin_family = AF_INET;
+ d_detail->d_sockaddr.sin_port = htons(10000);
+ int s = inet_aton(addr, &d_detail->d_sockaddr.sin_addr);
+
+ // set up local sockaddr
+ struct in_addr d_myadx;
+ struct sockaddr_in d_mysockaddr;
+ short int port = 10010;
+ d_myadx.s_addr = INADDR_ANY;
+ d_mysockaddr.sin_family = AF_INET;
+ d_mysockaddr.sin_port = htons(port);
+ memcpy(&d_mysockaddr.sin_addr.s_addr, &d_myadx.s_addr, sizeof(in_addr));
+ //d_sockaddr.sin_addr = INADDR_ANY;
+ s = bind(d_sock, (const sockaddr*) &d_mysockaddr, sizeof(d_mysockaddr));
+
+ // set default values
+ //d_decim = 2;
+ d_ddc_gain = 2;
+ d_rf_attn = 0;
+ d_fc_mhz = 3500;
+ d_offset_hz = 0;
+ d_ddc_gain = 0;
+ d_ddc_sample_rate_khz = 25600;
+ d_ddc_bw_khz = 25600;
+ d_start = 0;
+ d_state = STATE_STOPPED;
+}
+
+MSDD6000_RS::~MSDD6000_RS()
+{
+ //printf("MSDD6000_RS::Destructing\n");
+ close(d_sock);
+}
+
+
+static void
+optimize_socket(int socket){
+#define BANDWIDTH 1000000000/8
+#define DELAY 0.5
+ int ret;
+
+ int sock_buf_size = static_cast<int>(2*BANDWIDTH*DELAY);
+ char textbuf[512];
+ snprintf(textbuf, sizeof(textbuf), "%d", sock_buf_size);
+ printf("sock_buf_size = %d\n", sock_buf_size);
+
+ ret = setsockopt(socket, SOL_SOCKET, SO_SNDBUF,
+ &sock_buf_size, sizeof(sock_buf_size));
+
+ ret = setsockopt(socket, SOL_SOCKET, SO_RCVBUF,
+ &sock_buf_size, sizeof(sock_buf_size));
+
+ int uid = getuid();
+ if(uid!=0){
+ printf(" ****** COULD NOT OPTIMIZE SYSTEM NETWORK PARAMETERS BECAUSE YOU ARE NOT RUNNING AS ROOT *******\n ****** YOUR MSDD6000_RS RECIEVER PERFORMANCE IS GOING TO BE TERRIBLE *******\n");
+ return;
+ }
+
+
+ // SET UP SOME SYSTEM WIDE TCP SOCKET PARAMETERS
+ // FIXME seems like kind of a big hammer. Are you sure you need this?
+ FILE* fd = fopen("/proc/sys/net/core/netdev_max_backlog", "w");
+ if (fd){
+ fwrite("10000", 1, strlen("10000"), fd);
+ fclose(fd);
+ }
+
+ fd = fopen("/proc/sys/net/core/rmem_max", "w");
+ if (fd){
+ fwrite(textbuf, 1, strlen(textbuf), fd);
+ fclose(fd);
+ }
+
+ fd = fopen("/proc/sys/net/core/wmem_max", "w");
+ if (fd){
+ fwrite(textbuf, 1, strlen(textbuf), fd);
+ fclose(fd);
+ }
+
+ // just incase these were rejected before because of max sizes...
+
+ ret = setsockopt( socket, SOL_SOCKET, SO_SNDBUF,
+ (char *)&sock_buf_size, sizeof(sock_buf_size) );
+
+ ret = setsockopt( socket, SOL_SOCKET, SO_RCVBUF,
+ (char *)&sock_buf_size, sizeof(sock_buf_size) );
+
+}
+
+
+//void MSDD6000_RS::set_decim(int decim_pow2){
+// DEBUG("SETTING NEW DECIM");
+// d_decim = decim_pow2;
+//
+// if(d_state==STATE_STARTED)
+// send_request(d_fc_mhz, d_rf_attn, d_ddc_gain, d_decim, d_offset_hz);
+//}
+
+void MSDD6000_RS::set_rf_attn(int attn){
+ DEBUG("SETTING NEW RF ATTN");
+ d_rf_attn = attn;
+ if(d_state==STATE_STARTED)
+ send_request(d_fc_mhz, d_rf_attn, d_ddc_gain, d_offset_hz, d_ddc_sample_rate_khz, d_ddc_bw_khz, d_start);
+}
+
+void MSDD6000_RS::set_ddc_gain(int gain){
+ DEBUG("SETTING NEW DDC GAIN");
+ d_ddc_gain = gain;
+ if(d_state==STATE_STARTED)
+ send_request(d_fc_mhz, d_rf_attn, d_ddc_gain, d_offset_hz, d_ddc_sample_rate_khz, d_ddc_bw_khz, d_start);
+}
+
+void MSDD6000_RS::set_fc(int center_mhz, int offset_hz){
+ DEBUG("SETTING NEW FC");
+ d_fc_mhz = center_mhz;
+ d_offset_hz = offset_hz;
+
+ send_request(d_fc_mhz, d_rf_attn, d_ddc_gain, d_offset_hz, d_ddc_sample_rate_khz, d_ddc_bw_khz, d_start);
+// if(d_state==STATE_STARTED)
+// send_request(d_fc_mhz, d_rf_attn, d_ddc_gain, d_decim, d_offset_hz);
+// send_request(d_fc_mhz, d_rf_attn, d_ddc_gain, d_ddc_sample_rate_khz, d_ddc_bw_khz, d_start);
+//
+}
+
+void MSDD6000_RS::set_ddc_samp_rate(float sample_rate_khz){
+ DEBUG("SETTING NEW SAMPLE RATE");
+ d_ddc_sample_rate_khz = sample_rate_khz;
+ send_request(d_fc_mhz, d_rf_attn, d_ddc_gain, d_offset_hz, d_ddc_sample_rate_khz, d_ddc_bw_khz, d_start);
+}
+
+void MSDD6000_RS::set_ddc_bw(float bw_khz){
+ DEBUG("SETTING NEW DDC BW");
+ d_ddc_bw_khz = bw_khz;
+ send_request(d_fc_mhz, d_rf_attn, d_ddc_gain, d_offset_hz, d_ddc_sample_rate_khz, d_ddc_bw_khz, d_start);
+}
+
+void MSDD6000_RS::start(){
+ send_request(d_fc_mhz, d_rf_attn, d_ddc_gain, d_offset_hz, d_ddc_sample_rate_khz, d_ddc_bw_khz, d_start);
+ return;
+}
+
+void MSDD6000_RS::stop(){
+ // new request with 0 decim tells it to halt
+ stop_data();
+}
+
+
+int MSDD6000_RS::start_data(){
+ d_start = 1;
+ send_request(d_fc_mhz, d_rf_attn, d_ddc_gain, d_offset_hz, d_ddc_sample_rate_khz, d_ddc_bw_khz, d_start);
+ d_state = STATE_STARTED;
+ return 0;
+ }
+
+
+int MSDD6000_RS::stop_data(){
+ // new request with 0 decim tells it to halt
+ d_start = 0;
+ send_request(d_fc_mhz, d_rf_attn, d_ddc_gain, d_offset_hz, d_ddc_sample_rate_khz, d_ddc_bw_khz, d_start);
+ d_state = STATE_STOPPED;
+ return 0;
+ }
+
+/* Query functions */
+float MSDD6000_RS::pull_ddc_samp_rate(){
+ return d_ddc_sample_rate_khz;
+}
+float MSDD6000_RS::pull_ddc_bw(){
+ return d_ddc_bw_khz;
+}
+
+float MSDD6000_RS::pull_rx_freq(){
+ return d_fc_mhz;
+}
+int MSDD6000_RS::pull_ddc_gain(){
+ return d_ddc_gain;
+}
+
+int MSDD6000_RS::pull_rf_atten(){
+ return d_rf_attn;
+}
+
+
+void MSDD6000_RS::send_request(float freq_mhz, float rf_attn, float ddc_gain, float ddc_offset_hz, float ddc_samp_rate_khz, float ddc_input_bw_khz, float ddc_start){
+ static char buff[512];
+ // Send MSDD6000_RS control frame.
+ sprintf(buff, "%f %f %f %f %f %f %f\n",freq_mhz, rf_attn, ddc_gain, ddc_offset_hz, ddc_samp_rate_khz, ddc_input_bw_khz, ddc_start); //ddc_dec, ddc_offset_hz);
+ printf("sending: %s\n", buff);
+ int flags = 0;
+ sendto( d_sock, buff, strlen(buff)+1, flags,
+ (const sockaddr*)&(d_detail->d_sockaddr), sizeof(d_detail->d_sockaddr));
+ }
+
+
+int MSDD6000_RS::read(char* buf, int size){
+ int flags = 0;
+ return recv(d_sock, buf, size, flags);
+ }
+
+int MSDD6000_RS::parse_control(char* buf, int size){
+ //packet_len = sprintf(&txbuff[6], "%f %f %f %f %f %f %f",downsamp,ddc_dec_rate,ddc_step_int,ddc_step_frac,ddc_samp_rate_khz,ddc_input_bw_khz,ddc_start);
+
+ float downsamp;
+ float ddc_dec_rate;
+ float ddc_step_int;
+ float ddc_step_frac;
+ float ddc_samp_rate_khz;
+ float ddc_input_bw_khz;
+ float ddc_start;
+
+ sscanf(&buf[6],"%f %f %f %f %f %f %f",&downsamp,&ddc_dec_rate,&ddc_step_int,&ddc_step_frac,&ddc_samp_rate_khz,&ddc_input_bw_khz,&ddc_start);
+
+ // pull off sample rate
+ d_ddc_sample_rate_khz = ddc_samp_rate_khz;
+ printf("Sample Rate %f\n",d_ddc_sample_rate_khz);
+ // pull off bw
+ d_ddc_bw_khz = ddc_input_bw_khz;
+ printf("BW %f\n", d_ddc_bw_khz);
+ return 0;
+}
+
+
diff --git a/gr-msdd6000/src/msdd6000_rs.h b/gr-msdd6000/src/msdd6000_rs.h
new file mode 100644
index 000000000..4be4624be
--- /dev/null
+++ b/gr-msdd6000/src/msdd6000_rs.h
@@ -0,0 +1,66 @@
+#ifndef MSDD_RS__RS_6000_H
+#define MSDD_RS__RS_6000_H
+
+#include <boost/scoped_ptr.hpp>
+
+class MSDD6000_RS {
+ class detail;
+
+ //! holds objects with system dependent types
+ boost::scoped_ptr<detail> d_detail;
+
+public:
+
+ enum state {
+ STATE_STOPPED, STATE_STARTED
+ };
+
+ MSDD6000_RS(char* ip_addr);
+ ~MSDD6000_RS();
+
+ /* set functions -- sets digitizer parameters */
+
+ // void set_output(int mode, void* arg);
+
+ void set_rf_attn(int attn);
+ void set_ddc_gain(int gain);
+ void set_fc(int center_mhz, int offset_hz);
+ void set_ddc_samp_rate(float sample_rate_khz);
+ void set_ddc_bw(float bw_khz);
+
+ void start();
+ void stop();
+
+ /* function starts the flow of data from the digitizer */
+ int start_data();
+ /* function stops the flow of data from the digitizer */
+ int stop_data();
+
+ /* query functions -- queries digitizer 'actual' parameters */
+ float pull_ddc_samp_rate();
+ float pull_ddc_bw();
+ float pull_rx_freq();
+ int pull_ddc_gain();
+ int pull_rf_atten();
+
+ void send_request(float,float,float,float,float,float,float);
+ int read(char*, int);
+
+ int parse_control(char*, int);
+
+private:
+ // parameters for a receiver object.
+ int d_fc_mhz;
+ int d_offset_hz;
+ int d_rf_attn;
+ int d_ddc_gain;
+ float d_ddc_sample_rate_khz;
+ float d_ddc_bw_khz;
+ int d_start;
+ int d_sock;
+ state d_state;
+
+};
+
+
+#endif
diff --git a/gr-msdd6000/src/msdd_rs.i b/gr-msdd6000/src/msdd_rs.i
new file mode 100644
index 000000000..16a1bec1a
--- /dev/null
+++ b/gr-msdd6000/src/msdd_rs.i
@@ -0,0 +1,93 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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, or (at your option)
+ * any later version.
+ *
+ * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+%include "gnuradio.i" // the common stuff
+
+%{
+#include "msdd_rs_source_simple.h"
+%}
+
+
+GR_SWIG_BLOCK_MAGIC(msdd_rs,source_simple)
+
+msdd_rs_source_simple_sptr
+msdd_rs_make_source_simple (
+ const char *src,
+ unsigned short port_src
+ );
+
+class msdd_rs_source_simple : public gr_sync_block {
+ protected:
+ msdd_rs_source_simple(
+ const char *src,
+ unsigned short port_src
+ );
+
+ public:
+ ~msdd_rs_source_c();
+ int work (int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+
+ bool start();
+ bool stop();
+
+ /* function starts the flow of data */
+ int start_data();
+
+ /* function stops the flow of data */
+ int stop_data();
+
+ long pull_adc_freq();
+ /* Request the current ddc sample rate */
+ float pull_ddc_samp_rate();
+ /* Request the current ddc bandwidth */
+ float pull_ddc_bw();
+ /* Request the current rx freq */
+ float pull_rx_freq();
+ /* Request current ddc gain */
+ int pull_ddc_gain();
+ /* Request current RF attenuation */
+ int pull_rf_atten();
+
+
+ /* int decim_rate(); */
+ gr_vector_int gain_range();
+ gr_vector_float freq_range();
+
+ /* Set Functions */
+ /* bool set_decim_rate(unsigned int); */
+ bool set_rx_freq(double); /* set_rx_freq(int,double); */
+ /* bool set_pga(int,double); */
+
+ bool set_ddc_gain(double);
+ /* Set desired sample rate of MSDD6000 -- Note bounds checking is
+ done by the module and it will return the value actually used in the hardware. */
+ bool set_ddc_samp_rate(double);
+ /* Set desired input BW of MSDD6000 -- Note bounds checking is
+ // done by the module and it will return the value actually used in the hardware. */
+ bool set_ddc_bw(double);
+
+ bool set_rf_atten(double);
+
+
+ };
diff --git a/gr-msdd6000/src/msdd_rs_source_simple.cc b/gr-msdd6000/src/msdd_rs_source_simple.cc
new file mode 100644
index 000000000..2ffc64240
--- /dev/null
+++ b/gr-msdd6000/src/msdd_rs_source_simple.cc
@@ -0,0 +1,237 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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, or (at your option)
+ * any later version.
+ *
+ * GNU Radio 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <msdd_rs_source_simple.h>
+#include <gr_io_signature.h>
+#include <string.h>
+#include <cstdio>
+
+
+msdd_rs_source_simple_sptr
+msdd_rs_make_source_simple ( const char *src, unsigned short port_src)
+{
+ return msdd_rs_source_simple_sptr (new msdd_rs_source_simple ( src, port_src));
+}
+
+
+msdd_rs_source_simple::msdd_rs_source_simple (
+ const char *src,
+ unsigned short port_src)
+ : gr_sync_block("MSDD_RS_SOURCE_SIMPLE",
+ gr_make_io_signature (0,0,0),
+ gr_make_io_signature (1, 1, sizeof (short))),
+ rcv(new MSDD6000_RS((char*) src)), d_lastseq(0)
+{
+}
+
+msdd_rs_source_simple::~msdd_rs_source_simple ()
+{
+}
+
+
+int
+msdd_rs_source_simple::work (int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+
+#define BUF_LEN (366*sizeof(short)*2 + 6)
+
+ float* out1 =(float*) output_items[0];
+
+ char buffer[BUF_LEN];
+ /* Read a buffer out -- looking at UDP payload at this point.*/
+ rcv->read( &buffer[0], BUF_LEN );
+
+ int seq = *((int*) &buffer[2]);
+ char type = buffer[0];
+ //printf("Sequence %d\n",seq);
+
+ // FIXME get rid of these magic 366's!
+ if(d_lastseq == -366)
+ {
+ if (type != 0){
+ /* Received control packet -- parse and update locally stored parameters */
+ printf("Parsing control Packet\n");
+ rcv->parse_control(&buffer[0], seq);
+ }
+ else{
+ // not started case
+ if(seq == 0){
+ d_lastseq = 0;
+ }
+ else
+ {
+ // THROW AWAY SAMPLES WE ARE NOT STARTED YET!
+ return 0;
+ }
+ }
+ }
+ // Started case
+ else
+ {
+ if (type != 0){
+ /* Received control packet -- parse and update locally stored parameters */
+ printf("Parsing control Packet\n");
+ rcv->parse_control(&buffer[0], seq);
+ }
+
+ else {
+ int samples_missed = seq - d_lastseq - 366;
+ if(samples_missed > 0)
+ {
+ printf("dropped %d samples.\n", samples_missed);
+ }
+ d_lastseq = seq;
+ }
+ }
+
+ if(noutput_items< 366*2){
+ printf("NOT ENOUGH SPACE IN OUTPUT BUFFER!!! >:-(\n");
+ }
+
+ memcpy(&out1[0], &buffer[6], BUF_LEN - 6);
+
+// for(int i = 0; i < 366*2; i++){
+// out1[i] = (float) (*((short*) &buffer[6+2*i]) );
+// }
+
+ return 366*2;
+}
+
+//bool msdd_rs_source_simple::set_decim_rate(unsigned int rate)
+//{
+// // FIXME seems buggy. How about a floor or ceil?
+// rcv->set_decim((int) log2(rate));
+// return true;
+//}
+
+bool msdd_rs_source_simple::set_rx_freq(double freq)
+{
+ long new_fc = (long)freq;
+ rcv->set_fc( new_fc/1000000, new_fc%1000000);
+ return true;
+}
+
+
+bool msdd_rs_source_simple::set_ddc_gain(double gain)
+{
+ if(gain < 0 || gain > 7){ // only 3 bits available.
+ printf("GAIN IS OUTSIDE ACCEPTABLE RANGE!\n");
+ return false;
+ }
+ //decimation gain
+ rcv->set_ddc_gain((int)gain);
+ return true;
+}
+
+// Set desired sample rate of MSDD6000 -- Note bounds checking is
+// done by the module and it will return the value actually used in the hardware.
+bool msdd_rs_source_simple::set_ddc_samp_rate(double rate)
+{
+ rcv->set_ddc_samp_rate((float) rate);
+ return true;
+}
+
+// Set desired input BW of MSDD6000 -- Note bounds checking is
+// done by the module and it will return the value actually used in the hardware.
+bool msdd_rs_source_simple::set_ddc_bw(double bw)
+{
+ rcv->set_ddc_bw((float) bw);
+ return true;
+}
+
+bool msdd_rs_source_simple::set_rf_atten(double rf_atten)
+{
+ rcv->set_rf_attn((int) rf_atten);
+ return true;
+}
+
+bool msdd_rs_source_simple::start()
+{
+ rcv->start();
+ rcv->stop_data();
+ return true;
+}
+
+bool msdd_rs_source_simple::stop()
+{
+ rcv->stop();
+ return true;
+}
+
+int msdd_rs_source_simple::start_data()
+{
+ return rcv->start_data();
+}
+
+int msdd_rs_source_simple::stop_data()
+{
+ return rcv->stop_data();
+}
+
+/* Query functions */
+long msdd_rs_source_simple::pull_adc_freq(){
+ return 102400000;
+}
+
+/* Request the current ddc sample rate */
+float msdd_rs_source_simple::pull_ddc_samp_rate(){
+ return(rcv->pull_ddc_samp_rate());
+}
+
+/* Request the current ddc bandwidth */
+float msdd_rs_source_simple::pull_ddc_bw(){
+ return(rcv->pull_ddc_bw());
+
+}
+
+/* Request the current rx freq */
+float msdd_rs_source_simple::pull_rx_freq(){
+ return(rcv->pull_rx_freq());
+}
+
+/* Request current ddc gain */
+int msdd_rs_source_simple::pull_ddc_gain(){
+ return(rcv->pull_ddc_gain());
+}
+
+/* Request current RF attenuation */
+int msdd_rs_source_simple::pull_rf_atten(){
+ return(rcv->pull_rf_atten());
+}
+
+std::vector<int> msdd_rs_source_simple::gain_range(){
+ static std::vector<int> r;
+ r.push_back(0);
+ r.push_back(12);
+ return r;
+}
+
+std::vector<float> msdd_rs_source_simple::freq_range(){
+ std::vector<float> r;
+ r.push_back(30.0*1000*1000);
+ r.push_back(6.0*1000*1000*1000);
+ return r;
+}
diff --git a/gr-msdd6000/src/msdd_rs_source_simple.h b/gr-msdd6000/src/msdd_rs_source_simple.h
new file mode 100644
index 000000000..f320cbb4d
--- /dev/null
+++ b/gr-msdd6000/src/msdd_rs_source_simple.h
@@ -0,0 +1,87 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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, or (at your option)
+ * any later version.
+ *
+ * GNU Radio 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef INCLUDED_MSDD_RS_SOURCE_SIMPLE_H
+#define INCLUDED_MSDD_RS_SOURCE_SIMPLE_H
+
+#include <gr_sync_block.h>
+#include <msdd6000_rs.h>
+#include <boost/scoped_ptr.hpp>
+
+class msdd_rs_source_simple;
+typedef boost::shared_ptr<msdd_rs_source_simple> msdd_rs_source_simple_sptr;
+
+
+// public shared_ptr constructor
+
+msdd_rs_source_simple_sptr msdd_rs_make_source_simple ( const char *src, unsigned short port_src);
+
+
+class msdd_rs_source_simple : public gr_sync_block {
+ private:
+ friend msdd_rs_source_simple_sptr
+ msdd_rs_make_source_simple ( const char *src, unsigned short port_src);
+
+ boost::scoped_ptr<MSDD6000_RS> rcv;
+ int d_lastseq;
+
+ protected:
+ msdd_rs_source_simple (const char *src, unsigned short port_src);
+
+ public:
+ ~msdd_rs_source_simple ();
+ bool stop();
+ bool start();
+
+ /* function starts the flow of data from the digitizer */
+ int start_data();
+ /* function stops the flow of data from the digitizer */
+ int stop_data();
+
+ // Do not need this //
+// bool set_decim_rate(unsigned int);
+ /* Adding functions for setting the sample rate and
+ * receiver bandwidth
+ */
+
+ /* hardware commands -- change current state of digitizer */
+ bool set_ddc_samp_rate(double);
+ bool set_ddc_bw(double);
+
+ bool set_rx_freq(double);
+ bool set_ddc_gain(double);
+ bool set_rf_atten(double);
+
+ int work(int, gr_vector_const_void_star&, gr_vector_void_star&);
+
+ /* Query methods -- query current state of digitizer */
+ long pull_adc_freq();
+ float pull_ddc_samp_rate();
+ float pull_ddc_bw();
+ float pull_rx_freq();
+ int pull_ddc_gain();
+ int pull_rf_atten();
+
+ /* Pulling back gain and frequency ranges */
+ std::vector<int> gain_range();
+ std::vector<float> freq_range();
+};
+
+#endif /* INCLUDED_MSDD_RS__RS__SOURCE_C_H */
diff --git a/gr-msdd6000/src/python-examples/msdd_rs_spec_an.py b/gr-msdd6000/src/python-examples/msdd_rs_spec_an.py
new file mode 100755
index 000000000..4855375b8
--- /dev/null
+++ b/gr-msdd6000/src/python-examples/msdd_rs_spec_an.py
@@ -0,0 +1,350 @@
+#!/usr/bin/env python
+#
+# Copyright 2009 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio 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, or (at your option)
+# any later version.
+#
+# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
+
+from gnuradio import gr
+from gnuradio import msdd_rs
+from gnuradio import eng_notation
+from gnuradio.eng_option import eng_option
+from gnuradio.qtgui import qtgui
+from optparse import OptionParser
+import sys,time
+
+try:
+ from gnuradio.qtgui import qtgui
+ from PyQt4 import QtGui, QtCore
+ import sip
+except ImportError:
+ print "Please install gr-qtgui."
+ sys.exit(1)
+
+try:
+ from msdd_display_qtgui import Ui_MainWindow
+except ImportError:
+ print "Error: could not find msdd_display_qtgui.py:"
+ print "\t\"pyuic4 msdd_display_qtgui.ui -o msdd_display_qtgui.py\""
+ sys.exit(1)
+
+
+# ////////////////////////////////////////////////////////////////////
+# Define the QT Interface and Control Dialog
+# ////////////////////////////////////////////////////////////////////
+
+
+class main_window(QtGui.QMainWindow):
+ def __init__(self, snk, fg, parent=None):
+
+ QtGui.QWidget.__init__(self, parent)
+ self.gui = Ui_MainWindow()
+ self.gui.setupUi(self)
+
+ self.fg = fg
+
+ # Add the qtsnk widgets to the layout box
+ self.gui.sinkLayout.addWidget(snk)
+
+ self.gui.dcGainEdit.setText(QtCore.QString("%1").arg(0.001))
+
+ # Connect up some signals
+ self.connect(self.gui.pauseButton, QtCore.SIGNAL("clicked()"),
+ self.pauseFg)
+ self.connect(self.gui.frequencyEdit, QtCore.SIGNAL("editingFinished()"),
+ self.frequencyEditText)
+ self.connect(self.gui.gainEdit, QtCore.SIGNAL("editingFinished()"),
+ self.gainEditText)
+ self.connect(self.gui.bandwidthEdit, QtCore.SIGNAL("editingFinished()"),
+ self.bandwidthEditText)
+ self.connect(self.gui.amplifierEdit, QtCore.SIGNAL("editingFinished()"),
+ self.amplifierEditText)
+
+ self.connect(self.gui.actionSaveData, QtCore.SIGNAL("activated()"),
+ self.saveData)
+ self.gui.actionSaveData.setShortcut(QtGui.QKeySequence.Save)
+
+ self.connect(self.gui.dcGainEdit, QtCore.SIGNAL("editingFinished()"),
+ self.dcGainEditText)
+ self.connect(self.gui.dcCancelCheckBox, QtCore.SIGNAL("clicked(bool)"),
+ self.dcCancelClicked)
+
+ def pauseFg(self):
+ if(self.gui.pauseButton.text() == "Pause"):
+ self.fg.stop()
+ self.fg.wait()
+ self.fg.stop_data()
+ self.gui.pauseButton.setText("Unpause")
+ else:
+ self.fg.start()
+ self.fg.start_data()
+ self.gui.pauseButton.setText("Pause")
+
+
+ # Functions to set the values in the GUI
+ def set_frequency(self, freq):
+ self.freq = freq
+ sfreq = eng_notation.num_to_str(self.freq)
+ self.gui.frequencyEdit.setText(QtCore.QString("%1").arg(sfreq))
+
+ def set_gain(self, gain):
+ self.gain = gain
+ self.gui.gainEdit.setText(QtCore.QString("%1").arg(self.gain))
+
+ def set_bandwidth(self, bw):
+ self.bw = bw
+ sbw = eng_notation.num_to_str(self.bw)
+ self.gui.bandwidthEdit.setText(QtCore.QString("%1").arg(sbw))
+
+ def set_amplifier(self, amp):
+ self.amp = amp
+ self.gui.amplifierEdit.setText(QtCore.QString("%1").arg(self.amp))
+
+
+ # Functions called when signals are triggered in the GUI
+ def frequencyEditText(self):
+ try:
+ freq = eng_notation.str_to_num(self.gui.frequencyEdit.text().toAscii())
+ self.fg.set_frequency(freq)
+ self.freq = freq
+ except RuntimeError:
+ pass
+
+ def gainEditText(self):
+ try:
+ gain = float(self.gui.gainEdit.text())
+ self.fg.set_gain(gain)
+ self.gain = gain
+ except ValueError:
+ pass
+
+ def bandwidthEditText(self):
+ try:
+ bw = eng_notation.str_to_num(self.gui.bandwidthEdit.text().toAscii())
+ self.fg.set_bandwidth(bw)
+ self.bw = bw
+ except ValueError:
+ pass
+
+ def amplifierEditText(self):
+ try:
+ amp = float(self.gui.amplifierEdit.text())
+ self.fg.set_amplifier_gain(amp)
+ self.amp = amp
+ except ValueError:
+ pass
+
+ def saveData(self):
+ fileName = QtGui.QFileDialog.getSaveFileName(self, "Save data to file", ".");
+ if(len(fileName)):
+ self.fg.save_to_file(str(fileName))
+
+ def dcGainEditText(self):
+ gain = float(self.gui.dcGainEdit.text())
+ self.fg.set_dc_gain(gain)
+
+ def dcCancelClicked(self, state):
+ self.dcGainEditText()
+ self.fg.cancel_dc(state)
+
+
+
+class my_top_block(gr.top_block):
+ def __init__(self):
+ gr.top_block.__init__(self)
+
+ parser = OptionParser(option_class=eng_option)
+ parser.add_option("-e", "--interface", type="string", default="eth0",
+ help="select Ethernet interface, default is eth0")
+ parser.add_option("-m", "--mac-addr", type="string", default="",
+ help="select USRP by MAC address, default is auto-select")
+ parser.add_option("-W", "--bw", type="float", default=1e6,
+ help="set bandwidth of receiver [default=%default]")
+ parser.add_option("-f", "--freq", type="eng_float", default="2.4G",
+ help="set frequency to FREQ", metavar="FREQ")
+ parser.add_option("-g", "--gain", type="eng_float", default=None,
+ help="set gain in dB (default is midpoint)")
+ parser.add_option("--fft-size", type="int", default=2048,
+ help="Set number of FFT bins [default=%default]")
+ (options, args) = parser.parse_args()
+
+ if len(args) != 0:
+ parser.print_help()
+ sys.exit(1)
+ self.options = options
+ self.show_debug_info = True
+
+ self.qapp = QtGui.QApplication(sys.argv)
+
+# self.u = usrp2.source_32fc(options.interface, options.mac_addr)
+ self.u = msdd_rs.source_simple("192.168.1.20", 10000);
+ self.conv = gr.interleaved_short_to_complex();
+ self._adc_rate = self.u.pull_adc_freq()
+ self.set_bandwidth(options.bw)
+
+ if options.gain is None:
+ # if no gain was specified, use the mid-point in dB
+# g = self.u.gain_range()
+ g = [0, 10]
+ #options.gain = float(g[0]+g[1])/2
+ options.gain = float(0)
+ self.set_gain(options.gain)
+
+ if options.freq is None:
+ options.freq = 2.4e9;
+# # if no frequency was specified, use the mid-point of the subdev
+# f = self.u.freq_range()
+# options.freq = float(f[0]+f[1])/2
+
+ self.set_frequency(options.freq)
+
+ self._fftsize = options.fft_size
+
+
+ self._freq = options.freq;
+ self._bandwidth = 400;
+
+ self.set_bandwidth(self._bandwidth);
+
+ self.snk = qtgui.sink_c(options.fft_size, gr.firdes.WIN_BLACKMAN_hARRIS,
+ self._freq, self._bandwidth,
+ "USRP2 Display",
+ True, True, False, True, False)
+
+ # Set up internal amplifier
+ self.amp = gr.multiply_const_cc(0.0)
+ self.set_amplifier_gain(0.01)
+
+ # Create a single-pole IIR filter to remove DC
+ # but don't connect it yet
+ self.dc_gain = 0.001
+ self.dc = gr.single_pole_iir_filter_cc(self.dc_gain)
+ self.dc_sub = gr.sub_cc()
+
+ self.agc = gr.agc2_cc(1e-3, 1e-5, 0.01, 0.01, 10);
+
+ self.connect(self.u, self.conv, self.snk)
+ #self.connect(self.u, self.conv, self.amp, self.snk)
+
+ if self.show_debug_info:
+ print "Decimation rate: ", self._decim
+ print "Bandwidth: ", self._bandwidth
+# print "D'board: ", self.u.daughterboard_id()
+
+ # Get the reference pointer to the SpectrumDisplayForm QWidget
+ # Wrap the pointer as a PyQt SIP object
+ # This can now be manipulated as a PyQt4.QtGui.QWidget
+ self.pysink = sip.wrapinstance(self.snk.pyqwidget(), QtGui.QWidget)
+
+ self.main_win = main_window(self.pysink, self)
+
+ self.main_win.set_frequency(self._freq)
+ self.main_win.set_gain(self._gain)
+ self.main_win.set_bandwidth(self._bandwidth)
+ self.main_win.set_amplifier(self._amp_value)
+
+ self.main_win.show()
+
+
+ def save_to_file(self, name):
+ self.lock()
+
+ # Add file sink to save data
+ self.file_sink = gr.file_sink(gr.sizeof_gr_complex, name)
+ self.connect(self.conv, self.file_sink)
+
+ self.unlock()
+
+ def set_gain(self, gain):
+ self._gain = gain
+ self.u.set_ddc_gain(self._gain)
+
+ def set_frequency(self, freq):
+ self._freq = freq
+ r = self.u.set_rx_freq(freq)
+
+ try:
+ self.snk.set_frequency_range(self._freq, self._bandwidth)
+ except:
+ pass
+
+ def set_bandwidth(self, bw):
+ self._bandwidth = bw
+ self._decim = int(self._adc_rate / self._bandwidth)
+# self.u.set_decim_rate(self._decim)
+ r1 = self.u.set_ddc_samp_rate( bw );
+ r2 = self.u.set_ddc_bw( bw );
+ self.u.start_data();
+
+ print r1
+ print r2;
+
+ time.sleep(0.05);
+ bw = self.u.pull_ddc_bw();
+ sr = self.u.pull_ddc_samp_rate();
+ fc = self.u.pull_rx_freq();
+
+ #self.snk.d_bandwidth = sr;
+
+ print bw;
+ print sr;
+ print fc;
+
+# sys.exit(-1);
+
+ try:
+ self.snk.set_frequency_range(self._freq, self._bandwidth)
+ except:
+ pass
+
+ def set_amplifier_gain(self, amp):
+ self._amp_value = amp
+ self.amp.set_k(self._amp_value)
+
+ def set_dc_gain(self, gain):
+ self.dc.set_taps(gain)
+
+ def cancel_dc(self, state):
+ self.lock()
+
+ if(state):
+ self.disconnect(self.u, self.amp)
+ self.connect(self.u, (self.dc_sub,0))
+ self.connect(self.u, self.dc, (self.dc_sub,1))
+ self.connect(self.dc_sub, self.amp)
+ else:
+ self.disconnect(self.dc_sub, self.amp)
+ self.disconnect(self.dc, (self.dc_sub,1))
+ self.disconnect(self.u, self.dc)
+ self.disconnect(self.u, (self.dc_sub,0))
+ self.connect(self.u, self.amp)
+
+ self.unlock()
+
+def main ():
+ tb = my_top_block()
+ tb.start()
+ tb.u.start_data();
+ tb.snk.exec_();
+
+if __name__ == '__main__':
+ try:
+ main ()
+ except KeyboardInterrupt:
+ pass
+