diff --git a/grc/CMakeLists.txt b/grc/CMakeLists.txt index 86b312b..0834299 100644 --- a/grc/CMakeLists.txt +++ b/grc/CMakeLists.txt @@ -28,5 +28,6 @@ install(FILES satnogs_ax25_decoder_b.xml satnogs_udp_msg_source.xml satnogs_debug_msg_source.xml - satnogs_tcp_rigctl_msg_source.xml DESTINATION share/gnuradio/grc/blocks + satnogs_tcp_rigctl_msg_source.xml + satnogs_doppler_correction_cc.xml DESTINATION share/gnuradio/grc/blocks ) diff --git a/grc/satnogs_doppler_correction_cc.xml b/grc/satnogs_doppler_correction_cc.xml new file mode 100644 index 0000000..084bb41 --- /dev/null +++ b/grc/satnogs_doppler_correction_cc.xml @@ -0,0 +1,38 @@ + + + doppler_correction_cc + satnogs_doppler_correction_cc + satnogs + import satnogs + satnogs.doppler_correction_cc($target_freq) + + + ... + ... + ... + + + + + in + + + + + + out + + + diff --git a/include/satnogs/CMakeLists.txt b/include/satnogs/CMakeLists.txt index 24b753e..4c36c64 100644 --- a/include/satnogs/CMakeLists.txt +++ b/include/satnogs/CMakeLists.txt @@ -40,5 +40,6 @@ install(FILES udp_msg_source.h debug_msg_source.h tc_tm.h - tcp_rigctl_msg_source.h DESTINATION include/satnogs + tcp_rigctl_msg_source.h + doppler_correction_cc.h DESTINATION include/satnogs ) diff --git a/include/satnogs/doppler_correction_cc.h b/include/satnogs/doppler_correction_cc.h new file mode 100644 index 0000000..3f130f5 --- /dev/null +++ b/include/satnogs/doppler_correction_cc.h @@ -0,0 +1,66 @@ +/* -*- c++ -*- */ +/* + * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module + * + * Copyright (C) 2016, Libre Space Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef INCLUDED_SATNOGS_DOPPLER_CORRECTION_CC_H +#define INCLUDED_SATNOGS_DOPPLER_CORRECTION_CC_H + +#include +#include + +namespace gr +{ + namespace satnogs + { + + /*! + * \brief This block corrects the doppler effect between the ground + * station and the satellite. It takes the imput stream in baseband + * and applies proper corrections to keep the carrier at the desired + * frequency. To achieve that it uses messages containing the absolute + * predicted frequency of the satellite from software like Gpredict. + * + * \ingroup satnogs + * + */ + class SATNOGS_API doppler_correction_cc : virtual public gr::sync_block + { + public: + typedef boost::shared_ptr sptr; + + /*! + * The doppler correction block. The input is the complex signal at + * baseband as it comes from the SDR device. The message input \p freq + * received periodically messages containing the predicted absolute + * frequency of the satellite at the moment of the + * @param target_freq the absolute frequency of the satellite + * @param sampling_rate the sampling rate of the signal + * @param corrections_per_sec the number of the corrections every second + * that the block should perform + */ + static sptr + make (double target_freq, double sampling_rate, + size_t corrections_per_sec = 1000); + }; + + } // namespace satnogs +} // namespace gr + +#endif /* INCLUDED_SATNOGS_DOPPLER_CORRECTION_CC_H */ + diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index daafdec..11aed97 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -37,7 +37,8 @@ list(APPEND satnogs_sources ax25_decoder_b_impl.cc udp_msg_source_impl.cc debug_msg_source_impl.cc - tcp_rigctl_msg_source_impl.cc ) + tcp_rigctl_msg_source_impl.cc + doppler_correction_cc_impl.cc ) set(satnogs_sources "${satnogs_sources}" PARENT_SCOPE) if(NOT satnogs_sources) diff --git a/lib/doppler_correction_cc_impl.cc b/lib/doppler_correction_cc_impl.cc new file mode 100644 index 0000000..3c12dac --- /dev/null +++ b/lib/doppler_correction_cc_impl.cc @@ -0,0 +1,84 @@ +/* -*- c++ -*- */ +/* + * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module + * + * Copyright (C) 2016, Libre Space Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include "doppler_correction_cc_impl.h" + +namespace gr +{ + namespace satnogs + { + + doppler_correction_cc::sptr + doppler_correction_cc::make (double target_freq, double sampling_rate, + size_t corrections_per_sec) + { + return gnuradio::get_initial_sptr ( + new doppler_correction_cc_impl (target_freq, sampling_rate, + corrections_per_sec)); + } + + /* + * The private constructor + */ + doppler_correction_cc_impl::doppler_correction_cc_impl ( + double target_freq, double sampling_rate, size_t corrections_per_sec) : + gr::sync_block ("doppler_correction_cc", + gr::io_signature::make (1, 1, sizeof(gr_complex)), + gr::io_signature::make (1, 1, sizeof(gr_complex))), + d_target_freq (target_freq), + d_samp_rate (sampling_rate), + d_update_period (sampling_rate / (double) corrections_per_sec), + d_freq_diff (0.0) + { + message_port_register_in (pmt::mp ("freq")); + /* + * Set the maximum number of samples to be equivalent of half a second. + * With this way we are sure that at least one frequency message + * per second will be processed. + */ + set_max_noutput_items (d_samp_rate / 2.0); + } + + /* + * Our virtual destructor. + */ + doppler_correction_cc_impl::~doppler_correction_cc_impl () + { + } + + int + doppler_correction_cc_impl::work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const gr_complex *in = (const gr_complex *) input_items[0]; + gr_complex *out = (gr_complex *) output_items[0]; + + return noutput_items; + } + + } /* namespace satnogs */ +} /* namespace gr */ + diff --git a/lib/doppler_correction_cc_impl.h b/lib/doppler_correction_cc_impl.h new file mode 100644 index 0000000..7c67fc6 --- /dev/null +++ b/lib/doppler_correction_cc_impl.h @@ -0,0 +1,55 @@ +/* -*- c++ -*- */ +/* + * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module + * + * Copyright (C) 2016, Libre Space Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef INCLUDED_SATNOGS_DOPPLER_CORRECTION_CC_IMPL_H +#define INCLUDED_SATNOGS_DOPPLER_CORRECTION_CC_IMPL_H + +#include + +namespace gr +{ + namespace satnogs + { + + class doppler_correction_cc_impl : public doppler_correction_cc + { + private: + const double d_target_freq; + const double d_samp_rate; + const double d_update_period; + + double d_freq_diff; + + public: + doppler_correction_cc_impl (double target_freq, double sampling_rate, + size_t corrections_per_sec); + ~doppler_correction_cc_impl (); + + // Where all the action really happens + int + work (int noutput_items, gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } // namespace satnogs +} // namespace gr + +#endif /* INCLUDED_SATNOGS_DOPPLER_CORRECTION_CC_IMPL_H */ + diff --git a/swig/satnogs_swig.i b/swig/satnogs_swig.i index 66f5011..fc09185 100644 --- a/swig/satnogs_swig.i +++ b/swig/satnogs_swig.i @@ -22,6 +22,7 @@ #include "satnogs/udp_msg_source.h" #include "satnogs/debug_msg_source.h" #include "satnogs/tcp_rigctl_msg_source.h" +#include "satnogs/doppler_correction_cc.h" %} @@ -50,3 +51,5 @@ GR_SWIG_BLOCK_MAGIC2(satnogs, udp_msg_source); GR_SWIG_BLOCK_MAGIC2(satnogs, debug_msg_source); %include "satnogs/tcp_rigctl_msg_source.h" GR_SWIG_BLOCK_MAGIC2(satnogs, tcp_rigctl_msg_source); +%include "satnogs/doppler_correction_cc.h" +GR_SWIG_BLOCK_MAGIC2(satnogs, doppler_correction_cc);