summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohnathan Corgan2012-04-01 10:46:01 -0700
committerJohnathan Corgan2012-04-01 10:46:01 -0700
commit86321b24cff6df788e12436ca62bde22effdb4c2 (patch)
treec8aa5ca48f2ba5f208eb69491f4464c18183f6e1
parent1aecf53489a4fa76f6a818c170941faa1d02c43a (diff)
parentc39f8485e2f018363403336154ee30ea904e79a6 (diff)
downloadgnuradio-86321b24cff6df788e12436ca62bde22effdb4c2.tar.gz
gnuradio-86321b24cff6df788e12436ca62bde22effdb4c2.tar.bz2
gnuradio-86321b24cff6df788e12436ca62bde22effdb4c2.zip
Merge remote branch 'jcorgan/gr-fcd'
-rw-r--r--gr-fcd/include/fcd/fcd_source_c.h33
-rw-r--r--gr-fcd/lib/CMakeLists.txt2
-rw-r--r--gr-fcd/lib/Makefile.am4
-rw-r--r--gr-fcd/lib/fcd_source_c.cc236
-rw-r--r--gr-fcd/lib/fcd_source_c_impl.cc222
-rw-r--r--gr-fcd/lib/fcd_source_c_impl.h49
6 files changed, 284 insertions, 262 deletions
diff --git a/gr-fcd/include/fcd/fcd_source_c.h b/gr-fcd/include/fcd/fcd_source_c.h
index 1649d0862..31393418f 100644
--- a/gr-fcd/include/fcd/fcd_source_c.h
+++ b/gr-fcd/include/fcd/fcd_source_c.h
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2011 Free Software Foundation, Inc.
+ * Copyright 2011-2012 Free Software Foundation, Inc.
*
* 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
@@ -23,14 +23,11 @@
#include <fcd_api.h>
#include <gr_hier_block2.h>
-#include <gr_audio_source.h>
class fcd_source_c;
-
typedef boost::shared_ptr<fcd_source_c> fcd_source_c_sptr;
-
/*!
* \brief Return a shared_ptr to a new instance of fcd_source_c.
*
@@ -50,12 +47,9 @@ FCD_API fcd_source_c_sptr fcd_make_source_c(const std::string device_name = "");
* interface to work properly. As of early 2011, FCDs still come with firmware
* 18b. You can use qthid 2.2 (not 3) to upgrade the firmware: http://qthid.sf.net
*/
-class FCD_API fcd_source_c : public gr_hier_block2
+class FCD_API fcd_source_c : virtual public gr_hier_block2
{
-
public:
- ~fcd_source_c();
-
/*! \brief Set frequency with Hz resolution.
* \param freq The frequency in Hz
*
@@ -64,7 +58,7 @@ public:
*
* \see set_freq_khz()
*/
- void set_freq(int freq);
+ virtual void set_freq(int freq) = 0;
/*! \brief Set frequency with Hz resolution.
* \param freq The frequency in Hz
@@ -74,7 +68,7 @@ public:
*
* \see set_freq_khz()
*/
- void set_freq(float freq);
+ virtual void set_freq(float freq) = 0;
/*! \brief Set frequency with kHz resolution.
* \param freq The frequency in kHz
@@ -84,7 +78,7 @@ public:
*
* \see set_freq()
*/
- void set_freq_khz(int freq);
+ virtual void set_freq_khz(int freq) = 0;
/*! \brief Set LNA gain.
* \param gain The new gain in dB.
@@ -97,7 +91,7 @@ public:
* By default the FCD is set to 20 dB and this is a good value for most
* cases. In noisy areas you may try to reduce the gain.
*/
- void set_lna_gain(float gain);
+ virtual void set_lna_gain(float gain) = 0;
/*! \brief Set new frequency correction.
* \param ppm The new frequency correction in parts per million
@@ -107,7 +101,7 @@ public:
*
* Ref: http://www.funcubedongle.com/?p=617
*/
- void set_freq_corr(int ppm);
+ virtual void set_freq_corr(int ppm) = 0;
/*! \brief Set DC offset correction.
* \param _dci DC correction for I component (-1.0 to 1.0)
@@ -115,7 +109,7 @@ public:
*
* Set DC offset correction in the device. Default is 0.0.
*/
- void set_dc_corr(double _dci, double _dcq);
+ virtual void set_dc_corr(double _dci, double _dcq) = 0;
/*! \brief Set IQ phase and gain balance.
* \param _gain The gain correction (-1.0 to 1.0)
@@ -124,16 +118,7 @@ public:
* Set IQ phase and gain balance in the device. The default values
* are 0.0 for phase and 1.0 for gain.
*/
- void set_iq_corr(double _gain, double _phase);
-
-private:
- fcd_source_c(const std::string device_name = "");
- friend FCD_API fcd_source_c_sptr
- fcd_make_source_c(const std::string device_name);
-
- audio_source::sptr fcd; /*!< The audio input source */
- int d_freq_corr; /*!< The frequency correction in ppm */
- int d_freq_req; /*!< The latest requested frequency in Hz */
+ virtual void set_iq_corr(double _gain, double _phase) = 0;
};
#endif /* INCLUDED_FCD_SOURCE_C_H */
diff --git a/gr-fcd/lib/CMakeLists.txt b/gr-fcd/lib/CMakeLists.txt
index 0e1f2aa01..cfca8b81b 100644
--- a/gr-fcd/lib/CMakeLists.txt
+++ b/gr-fcd/lib/CMakeLists.txt
@@ -39,7 +39,7 @@ link_directories(${Boost_LIBRARY_DIRS})
# Setup library
########################################################################
list(APPEND gr_fcd_sources
- fcd_source_c.cc
+ fcd_source_c_impl.cc
)
list(APPEND fcd_libs
diff --git a/gr-fcd/lib/Makefile.am b/gr-fcd/lib/Makefile.am
index 30e9f0283..a288740b4 100644
--- a/gr-fcd/lib/Makefile.am
+++ b/gr-fcd/lib/Makefile.am
@@ -32,7 +32,9 @@ AM_CPPFLAGS = \
lib_LTLIBRARIES = libgnuradio-fcd.la
-libgnuradio_fcd_la_SOURCES = fcd_source_c.cc
+libgnuradio_fcd_la_SOURCES = fcd_source_c_impl.cc
+
+noinst_HEADERS = fcd_source_c_impl.h
libgnuradio_fcd_la_LIBADD = \
$(GNURADIO_CORE_LA) \
diff --git a/gr-fcd/lib/fcd_source_c.cc b/gr-fcd/lib/fcd_source_c.cc
deleted file mode 100644
index 75bdd3162..000000000
--- a/gr-fcd/lib/fcd_source_c.cc
+++ /dev/null
@@ -1,236 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2011 Free Software Foundation, Inc.
- *
- * 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.
- */
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-
-#include <fcd_source_c.h>
-#include <fcd.h>
-#include <fcdhidcmd.h> // needed for extended API
-#include <gr_io_signature.h>
-#include <gr_audio_source.h>
-#include <gr_float_to_complex.h>
-#include <gruel/attributes.h>
-
-//#include <iostream>
-//using namespace std;
-
-/*
- * Create a new instance of fcd_source_c and return
- * a boost shared_ptr. This is effectively the public constructor.
- */
-fcd_source_c_sptr fcd_make_source_c(const std::string device_name)
-{
- return gnuradio::get_initial_sptr(new fcd_source_c(device_name));
-}
-
-
-static const int MIN_IN = 0; /*!< Mininum number of input streams. */
-static const int MAX_IN = 0; /*!< Maximum number of input streams. */
-static const int MIN_OUT = 1; /*!< Minimum number of output streams. */
-static const int MAX_OUT = 1; /*!< Maximum number of output streams. */
-
-
-fcd_source_c::fcd_source_c(const std::string device_name)
- : gr_hier_block2 ("fcd_source_c",
- gr_make_io_signature (MIN_IN, MAX_IN, sizeof (gr_complex)),
- gr_make_io_signature (MIN_OUT, MAX_OUT, sizeof (gr_complex))),
- d_freq_corr(-120),
- d_freq_req(0)
-{
- gr_float_to_complex_sptr f2c;
-
- /* Audio source; sample rate fixed at 96kHz */
- fcd = audio_make_source(96000, device_name, true);
-
- /* block to convert stereo audio to a complex stream */
- f2c = gr_make_float_to_complex(1);
-
- connect(fcd, 0, f2c, 0);
- connect(fcd, 1, f2c, 1);
- connect(f2c, 0, self(), 0);
-
-}
-
-
-fcd_source_c::~fcd_source_c ()
-{
-
-}
-
-// Set frequency with Hz resolution
-void fcd_source_c::set_freq(int freq)
-{
- FCD_MODE_ENUM __GR_ATTR_UNUSED fme;
- double f = (double)freq;
-
- /* valid range 50 MHz - 2.0 GHz */
- if ((freq < 50000000) || (freq > 2000000000)) {
- return;
- }
-
- d_freq_req = freq;
- f *= 1.0 + d_freq_corr/1000000.0;
-
- fme = fcdAppSetFreq((int)f);
- /* TODO: check fme */
-}
-
-// Set frequency with Hz resolution (type float)
-void fcd_source_c::set_freq(float freq)
-{
- FCD_MODE_ENUM __GR_ATTR_UNUSED fme;
- double f = (double)freq;
-
- /* valid range 50 MHz - 2.0 GHz */
- if ((freq < 50.0e6) || (freq > 2.0e9)) {
- return;
- }
-
- d_freq_req = (int)freq;
- f *= 1.0 + d_freq_corr/1000000.0;
-
- fme = fcdAppSetFreq((int)f);
- /* TODO: check fme */
-}
-
-
-// Set frequency with kHz resolution.
-void fcd_source_c::set_freq_khz(int freq)
-{
- FCD_MODE_ENUM __GR_ATTR_UNUSED fme;
- double f = freq*1000.0;
-
- /* valid range 50 MHz - 2.0 GHz */
- if ((freq < 50000) || (freq > 2000000)) {
- return;
- }
-
- d_freq_req = freq*1000;
- f *= 1.0 + d_freq_corr/1000000.0;
-
- fme = fcdAppSetFreqkHz((int)(f/1000.0));
- /* TODO: check fme */
-}
-
-
-// Set LNA gain
-void fcd_source_c::set_lna_gain(float gain)
-{
- FCD_MODE_ENUM __GR_ATTR_UNUSED fme;
- unsigned char g;
-
- /* convert to nearest discrete value */
- if (gain > 27.5) {
- g = 14; // 30.0 dB
- }
- else if (gain > 22.5) {
- g = 13; // 25.0 dB
- }
- else if (gain > 18.75) {
- g = 12; // 20.0 dB
- }
- else if (gain > 16.25) {
- g = 11; // 17.5 dB
- }
- else if (gain > 13.75) {
- g = 10; // 15.0 dB
- }
- else if (gain > 11.25) {
- g = 9; // 12.5 dB
- }
- else if (gain > 8.75) {
- g = 8; // 10.0 dB
- }
- else if (gain > 6.25) {
- g = 7; // 7.5 dB
- }
- else if (gain > 3.75) {
- g = 6; // 5.0 dB
- }
- else if (gain > 1.25) {
- g = 5; // 2.5 dB
- }
- else if (gain > -1.25) {
- g = 4; // 0.0 dB
- }
- else if (gain > -3.75) {
- g = 1; // -2.5 dB
- }
- else {
- g = 0; // -5.0 dB
- }
-
- fme = fcdAppSetParam(FCD_CMD_APP_SET_LNA_GAIN, &g, 1);
- /* TODO: check fme */
-}
-
-// Set new frequency correction
-void fcd_source_c::set_freq_corr(int ppm)
-{
- d_freq_corr = ppm;
- // re-tune with new correction value
- set_freq(d_freq_req);
-}
-
-
-// Set DC offset correction.
-void fcd_source_c::set_dc_corr(double _dci, double _dcq)
-{
- union {
- unsigned char auc[4];
- struct {
- signed short dci; // equivalent of qint16 which should be 16 bit everywhere
- signed short dcq;
- };
- } dcinfo;
-
- if ((_dci < -1.0) || (_dci > 1.0) || (_dcq < -1.0) || (_dcq > 1.0))
- return;
-
- dcinfo.dci = static_cast<signed short>(_dci*32768.0);
- dcinfo.dcq = static_cast<signed short>(_dcq*32768.0);
-
- fcdAppSetParam(FCD_CMD_APP_SET_DC_CORR, dcinfo.auc, 4);
-
-}
-
-
-// Set IQ phase and gain balance.
-void fcd_source_c::set_iq_corr(double _gain, double _phase)
-{
- union {
- unsigned char auc[4];
- struct {
- signed short phase;
- signed short gain;
- };
- } iqinfo;
-
- if ((_gain < -1.0) || (_gain > 1.0) || (_phase < -1.0) || (_phase > 1.0))
- return;
-
- iqinfo.phase = static_cast<signed short>(_phase*32768.0);
- iqinfo.gain = static_cast<signed short>(_gain*32768.0);
-
- fcdAppSetParam(FCD_CMD_APP_SET_IQ_CORR, iqinfo.auc, 4);
-
-}
diff --git a/gr-fcd/lib/fcd_source_c_impl.cc b/gr-fcd/lib/fcd_source_c_impl.cc
new file mode 100644
index 000000000..a67d5bdbb
--- /dev/null
+++ b/gr-fcd/lib/fcd_source_c_impl.cc
@@ -0,0 +1,222 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2011-2012 Free Software Foundation, Inc.
+ *
+ * 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.
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+
+#include <fcd_source_c_impl.h>
+#include <fcd.h>
+#include <fcdhidcmd.h> // needed for extended API
+#include <gr_io_signature.h>
+#include <gr_float_to_complex.h>
+#include <gruel/attributes.h>
+
+//#include <iostream>
+//using namespace std;
+
+/*
+ * Create a new instance of fcd_source_c_impl and return
+ * an upcasted boost shared_ptr. This is effectively the public constructor.
+ */
+fcd_source_c_sptr fcd_make_source_c(const std::string device_name)
+{
+ return gnuradio::get_initial_sptr(new fcd_source_c_impl(device_name));
+}
+
+static const int MIN_IN = 0; /*!< Mininum number of input streams. */
+static const int MAX_IN = 0; /*!< Maximum number of input streams. */
+static const int MIN_OUT = 1; /*!< Minimum number of output streams. */
+static const int MAX_OUT = 1; /*!< Maximum number of output streams. */
+
+fcd_source_c_impl::fcd_source_c_impl(const std::string device_name)
+ : gr_hier_block2 ("fcd_source_c_impl",
+ gr_make_io_signature (MIN_IN, MAX_IN, sizeof (gr_complex)),
+ gr_make_io_signature (MIN_OUT, MAX_OUT, sizeof (gr_complex))),
+ d_freq_corr(-120),
+ d_freq_req(0)
+{
+ gr_float_to_complex_sptr f2c;
+
+ /* Audio source; sample rate fixed at 96kHz */
+ fcd = audio_make_source(96000, device_name, true);
+
+ /* block to convert stereo audio to a complex stream */
+ f2c = gr_make_float_to_complex(1);
+
+ connect(fcd, 0, f2c, 0);
+ connect(fcd, 1, f2c, 1);
+ connect(f2c, 0, self(), 0);
+}
+
+// Set frequency with Hz resolution
+void fcd_source_c_impl::set_freq(int freq)
+{
+ FCD_MODE_ENUM __GR_ATTR_UNUSED fme;
+ double f = (double)freq;
+
+ /* valid range 50 MHz - 2.0 GHz */
+ if ((freq < 50000000) || (freq > 2000000000)) {
+ return;
+ }
+
+ d_freq_req = freq;
+ f *= 1.0 + d_freq_corr/1000000.0;
+
+ fme = fcdAppSetFreq((int)f);
+ /* TODO: check fme */
+}
+
+// Set frequency with Hz resolution (type float)
+void fcd_source_c_impl::set_freq(float freq)
+{
+ FCD_MODE_ENUM __GR_ATTR_UNUSED fme;
+ double f = (double)freq;
+
+ /* valid range 50 MHz - 2.0 GHz */
+ if ((freq < 50.0e6) || (freq > 2.0e9)) {
+ return;
+ }
+
+ d_freq_req = (int)freq;
+ f *= 1.0 + d_freq_corr/1000000.0;
+
+ fme = fcdAppSetFreq((int)f);
+ /* TODO: check fme */
+}
+
+
+// Set frequency with kHz resolution.
+void fcd_source_c_impl::set_freq_khz(int freq)
+{
+ FCD_MODE_ENUM __GR_ATTR_UNUSED fme;
+ double f = freq*1000.0;
+
+ /* valid range 50 MHz - 2.0 GHz */
+ if ((freq < 50000) || (freq > 2000000)) {
+ return;
+ }
+
+ d_freq_req = freq*1000;
+ f *= 1.0 + d_freq_corr/1000000.0;
+
+ fme = fcdAppSetFreqkHz((int)(f/1000.0));
+ /* TODO: check fme */
+}
+
+
+// Set LNA gain
+void fcd_source_c_impl::set_lna_gain(float gain)
+{
+ FCD_MODE_ENUM __GR_ATTR_UNUSED fme;
+ unsigned char g;
+
+ /* convert to nearest discrete value */
+ if (gain > 27.5) {
+ g = 14; // 30.0 dB
+ }
+ else if (gain > 22.5) {
+ g = 13; // 25.0 dB
+ }
+ else if (gain > 18.75) {
+ g = 12; // 20.0 dB
+ }
+ else if (gain > 16.25) {
+ g = 11; // 17.5 dB
+ }
+ else if (gain > 13.75) {
+ g = 10; // 15.0 dB
+ }
+ else if (gain > 11.25) {
+ g = 9; // 12.5 dB
+ }
+ else if (gain > 8.75) {
+ g = 8; // 10.0 dB
+ }
+ else if (gain > 6.25) {
+ g = 7; // 7.5 dB
+ }
+ else if (gain > 3.75) {
+ g = 6; // 5.0 dB
+ }
+ else if (gain > 1.25) {
+ g = 5; // 2.5 dB
+ }
+ else if (gain > -1.25) {
+ g = 4; // 0.0 dB
+ }
+ else if (gain > -3.75) {
+ g = 1; // -2.5 dB
+ }
+ else {
+ g = 0; // -5.0 dB
+ }
+
+ fme = fcdAppSetParam(FCD_CMD_APP_SET_LNA_GAIN, &g, 1);
+ /* TODO: check fme */
+}
+
+// Set new frequency correction
+void fcd_source_c_impl::set_freq_corr(int ppm)
+{
+ d_freq_corr = ppm;
+ // re-tune with new correction value
+ set_freq(d_freq_req);
+}
+
+// Set DC offset correction.
+void fcd_source_c_impl::set_dc_corr(double _dci, double _dcq)
+{
+ union {
+ unsigned char auc[4];
+ struct {
+ signed short dci; // equivalent of qint16 which should be 16 bit everywhere
+ signed short dcq;
+ };
+ } dcinfo;
+
+ if ((_dci < -1.0) || (_dci > 1.0) || (_dcq < -1.0) || (_dcq > 1.0))
+ return;
+
+ dcinfo.dci = static_cast<signed short>(_dci*32768.0);
+ dcinfo.dcq = static_cast<signed short>(_dcq*32768.0);
+
+ fcdAppSetParam(FCD_CMD_APP_SET_DC_CORR, dcinfo.auc, 4);
+}
+
+// Set IQ phase and gain balance.
+void fcd_source_c_impl::set_iq_corr(double _gain, double _phase)
+{
+ union {
+ unsigned char auc[4];
+ struct {
+ signed short phase;
+ signed short gain;
+ };
+ } iqinfo;
+
+ if ((_gain < -1.0) || (_gain > 1.0) || (_phase < -1.0) || (_phase > 1.0))
+ return;
+
+ iqinfo.phase = static_cast<signed short>(_phase*32768.0);
+ iqinfo.gain = static_cast<signed short>(_gain*32768.0);
+
+ fcdAppSetParam(FCD_CMD_APP_SET_IQ_CORR, iqinfo.auc, 4);
+}
diff --git a/gr-fcd/lib/fcd_source_c_impl.h b/gr-fcd/lib/fcd_source_c_impl.h
new file mode 100644
index 000000000..e4a7467c5
--- /dev/null
+++ b/gr-fcd/lib/fcd_source_c_impl.h
@@ -0,0 +1,49 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2011-2012 Free Software Foundation, Inc.
+ *
+ * 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.
+ */
+
+#ifndef INCLUDED_FCD_SOURCE_C_IMPL_H
+#define INCLUDED_FCD_SOURCE_C_IMPL_H
+
+#include <fcd_source_c.h>
+#include <gr_audio_source.h>
+
+class FCD_API fcd_source_c_impl : public fcd_source_c
+{
+public:
+ /* Public API functions documented in include/fcd_source_c.h */
+ void set_freq(int freq);
+ void set_freq(float freq);
+ void set_freq_khz(int freq);
+ void set_lna_gain(float gain);
+ void set_freq_corr(int ppm);
+ void set_dc_corr(double _dci, double _dcq);
+ void set_iq_corr(double _gain, double _phase);
+
+private:
+ fcd_source_c_impl(const std::string device_name = "");
+ friend FCD_API fcd_source_c_sptr
+ fcd_make_source_c(const std::string device_name);
+
+ audio_source::sptr fcd; /*!< The audio input source */
+ int d_freq_corr; /*!< The frequency correction in ppm */
+ int d_freq_req; /*!< The latest requested frequency in Hz */
+};
+
+#endif /* INCLUDED_FCD_SOURCE_C_IMPL_H */