diff --git a/grc/CMakeLists.txt b/grc/CMakeLists.txt index 3c8a675..07917f9 100644 --- a/grc/CMakeLists.txt +++ b/grc/CMakeLists.txt @@ -47,9 +47,10 @@ if(${INCLUDE_DEBUG_BLOCKS}) list(APPEND enabled_blocks ${debug_blocks}) endif() install(FILES - ${enabled_blocks} + ${enabled_blocks} satnogs_ogg_source.xml satnogs_noaa_apt_sink.xml satnogs_frame_file_sink.xml - satnogs_iq_sink.xml DESTINATION share/gnuradio/grc/blocks + satnogs_iq_sink.xml + satnogs_cw_encoder.xml DESTINATION share/gnuradio/grc/blocks ) diff --git a/grc/satnogs_cw_encoder.xml b/grc/satnogs_cw_encoder.xml new file mode 100644 index 0000000..c3d5288 --- /dev/null +++ b/grc/satnogs_cw_encoder.xml @@ -0,0 +1,38 @@ + + + cw_encoder + satnogs_cw_encoder + [satnogs] + import satnogs + satnogs.cw_encoder($samp_rate, $cw_freq, $wpm) + + + ... + ... + ... + + + + + in + + + + + + out + + + diff --git a/include/satnogs/CMakeLists.txt b/include/satnogs/CMakeLists.txt index cb685fc..63b6843 100644 --- a/include/satnogs/CMakeLists.txt +++ b/include/satnogs/CMakeLists.txt @@ -65,5 +65,6 @@ install(FILES ogg_source.h noaa_apt_sink.h frame_file_sink.h - iq_sink.h DESTINATION include/satnogs + iq_sink.h DESTINATION + cw_encoder.h DESTINATION include/satnogs ) \ No newline at end of file diff --git a/include/satnogs/cw_encoder.h b/include/satnogs/cw_encoder.h new file mode 100644 index 0000000..d21ed7b --- /dev/null +++ b/include/satnogs/cw_encoder.h @@ -0,0 +1,59 @@ +/* -*- c++ -*- */ +/* + * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module + * + * Copyright (C) 2017 + * 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_CW_ENCODER_H +#define INCLUDED_SATNOGS_CW_ENCODER_H + +#include +#include + +namespace gr +{ + namespace satnogs + { + + /*! + * \brief CW encoder block, mainly for debugging and testing purposes. + * It accepts a CW word via a message source port and transmits the + * corresponding CW symbols. + * \ingroup satnogs + * + */ + class SATNOGS_API cw_encoder : virtual public gr::sync_block + { + public: + typedef boost::shared_ptr sptr; + + /*! + * \brief Return a shared_ptr to a new instance of satnogs::cw_encoder. + * @param samp_rate the sampling rate + * @param cw_freq the CW tone frequency + * @param wpm words per minute (WPM) + */ + static sptr + make (double samp_rate, double cw_freq = 700, size_t wpm = 20); + }; + + } // namespace satnogs +} // namespace gr + +#endif /* INCLUDED_SATNOGS_CW_ENCODER_H */ + diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index a36a166..95c2e00 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -63,7 +63,8 @@ list(APPEND satnogs_sources ogg_source_impl.cc noaa_apt_sink_impl.cc frame_file_sink_impl.cc - iq_sink_impl.cc) + iq_sink_impl.cc + cw_encoder_impl.cc) if(${INCLUDE_DEBUG_BLOCKS}) list(APPEND satnogs_sources ${satnogs_debug_sources}) diff --git a/lib/cw_encoder_impl.cc b/lib/cw_encoder_impl.cc new file mode 100644 index 0000000..5476627 --- /dev/null +++ b/lib/cw_encoder_impl.cc @@ -0,0 +1,114 @@ +/* -*- c++ -*- */ +/* + * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module + * + * Copyright (C) 2017 + * 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 "cw_encoder_impl.h" + +namespace gr { + namespace satnogs { + + const std::vector cw_encoder_impl::cw_chars ( + { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', + 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', + '3', '4', '5', '6', '7', '8', '9', '0' }); + const std::vector cw_encoder_impl::cw_symbols ( + { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", + ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", + "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", ".----", + "..---", "...--", "....-", ".....", "-....", "--...", "---..", + "----.", "-----" }); + + cw_encoder::sptr + cw_encoder::make(double samp_rate, double cw_freq, size_t wpm) + { + return gnuradio::get_initial_sptr + (new cw_encoder_impl(samp_rate, cw_freq, wpm)); + } + + /* + * The private constructor + */ + cw_encoder_impl::cw_encoder_impl(double samp_rate, double cw_freq, + size_t wpm) + : gr::sync_block("cw_encoder", + gr::io_signature::make(0, 0, 0), + gr::io_signature::make(1, 1, sizeof(gr_complex))), + d_samp_rate (samp_rate), + d_cw_freq (cw_freq), + d_wpm (wpm), + d_nco (), + d_word (new uint8_t[2048]), + d_remaining (0) + { + message_port_register_in(pmt::mp("word")); + d_nco.set_freq ((2 * M_PI * cw_freq) / samp_rate); + } + + /* + * Our virtual destructor. + */ + cw_encoder_impl::~cw_encoder_impl() + { + delete [] d_word; + } + + static inline size_t + find_char_idx(const char* characters, size_t len, char c) + { + size_t i; + for(i = 0; i < len; i++) { + if(characters[i] == c){ + return i; + } + } + return len; + } + + std::string + cw_encoder_impl::get_cw_symbol (char c) + { + size_t i; + for(i = 0; i < cw_chars.size(); i++) { + if(cw_chars[i] == c) { + return cw_symbols[i]; + } + } + return ""; + } + + int + cw_encoder_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + gr_complex *out = (gr_complex *) output_items[0]; + + // Tell runtime system how many output items we produced. + return noutput_items; + } + + } /* namespace satnogs */ +} /* namespace gr */ + diff --git a/lib/cw_encoder_impl.h b/lib/cw_encoder_impl.h new file mode 100644 index 0000000..8124c50 --- /dev/null +++ b/lib/cw_encoder_impl.h @@ -0,0 +1,64 @@ +/* -*- c++ -*- */ +/* + * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module + * + * Copyright (C) 2017 + * 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_CW_ENCODER_IMPL_H +#define INCLUDED_SATNOGS_CW_ENCODER_IMPL_H + +#include +#include +#include +#include + +namespace gr +{ + namespace satnogs + { + + class cw_encoder_impl : public cw_encoder + { + private: + const double d_samp_rate; + const double d_cw_freq; + const size_t d_wpm; + gr::fxpt_nco d_nco; + uint8_t *d_word; + size_t d_remaining; + + std::string + get_cw_symbol(char c); + + public: + static const std::vector cw_chars; + static const std::vector cw_symbols; + cw_encoder_impl (double samp_rate, double cw_freq, size_t wpm); + ~cw_encoder_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_CW_ENCODER_IMPL_H */ + diff --git a/swig/satnogs_swig.i b/swig/satnogs_swig.i index fa27c39..3f55333 100644 --- a/swig/satnogs_swig.i +++ b/swig/satnogs_swig.i @@ -35,6 +35,7 @@ #include "satnogs/noaa_apt_sink.h" #include "satnogs/frame_file_sink.h" #include "satnogs/iq_sink.h" +#include "satnogs/cw_encoder.h" %} @@ -108,3 +109,5 @@ GR_SWIG_BLOCK_MAGIC2(satnogs, noaa_apt_sink); GR_SWIG_BLOCK_MAGIC2(satnogs, frame_file_sink); %include "satnogs/iq_sink.h" GR_SWIG_BLOCK_MAGIC2(satnogs, iq_sink); +%include "satnogs/cw_encoder.h" +GR_SWIG_BLOCK_MAGIC2(satnogs, cw_encoder);