Simpify CW decoder

This commit is contained in:
Manolis Surligas 2017-08-08 22:53:26 +03:00
parent 94eef1463c
commit 9b9f8c92ad
8 changed files with 285 additions and 4 deletions

View File

@ -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
)

View File

@ -0,0 +1,38 @@
<?xml version="1.0"?>
<block>
<name>cw_encoder</name>
<key>satnogs_cw_encoder</key>
<category>[satnogs]</category>
<import>import satnogs</import>
<make>satnogs.cw_encoder($samp_rate, $cw_freq, $wpm)</make>
<!-- Make one 'param' node for every Parameter you want settable from the GUI.
Sub-nodes:
* name
* key (makes the value accessible as $keyname, e.g. in the make node)
* type -->
<param>
<name>...</name>
<key>...</key>
<type>...</type>
</param>
<!-- Make one 'sink' node per input. Sub-nodes:
* name (an identifier for the GUI)
* type
* vlen
* optional (set to 1 for optional inputs) -->
<sink>
<name>in</name>
<type><!-- e.g. int, float, complex, byte, short, xxx_vector, ...--></type>
</sink>
<!-- Make one 'source' node per output. Sub-nodes:
* name (an identifier for the GUI)
* type
* vlen
* optional (set to 1 for optional inputs) -->
<source>
<name>out</name>
<type><!-- e.g. int, float, complex, byte, short, xxx_vector, ...--></type>
</source>
</block>

View File

@ -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
)

View File

@ -0,0 +1,59 @@
/* -*- c++ -*- */
/*
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
*
* Copyright (C) 2017
* Libre Space Foundation <http://librespacefoundation.org/>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef INCLUDED_SATNOGS_CW_ENCODER_H
#define INCLUDED_SATNOGS_CW_ENCODER_H
#include <satnogs/api.h>
#include <gnuradio/sync_block.h>
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<cw_encoder> 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 */

View File

@ -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})

114
lib/cw_encoder_impl.cc Normal file
View File

@ -0,0 +1,114 @@
/* -*- c++ -*- */
/*
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
*
* Copyright (C) 2017
* Libre Space Foundation <http://librespacefoundation.org/>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gnuradio/io_signature.h>
#include "cw_encoder_impl.h"
namespace gr {
namespace satnogs {
const std::vector<char> 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<std::string> 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 */

64
lib/cw_encoder_impl.h Normal file
View File

@ -0,0 +1,64 @@
/* -*- c++ -*- */
/*
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
*
* Copyright (C) 2017
* Libre Space Foundation <http://librespacefoundation.org/>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef INCLUDED_SATNOGS_CW_ENCODER_IMPL_H
#define INCLUDED_SATNOGS_CW_ENCODER_IMPL_H
#include <vector>
#include <string>
#include <satnogs/cw_encoder.h>
#include <gnuradio/fxpt_nco.h>
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<char> cw_chars;
static const std::vector<std::string> 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 */

View File

@ -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);