2016-01-19 18:35:37 +01:00
|
|
|
/* -*- c++ -*- */
|
|
|
|
/*
|
|
|
|
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016, 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>
|
2016-01-21 20:33:08 +01:00
|
|
|
#include "morse_decoder_impl.h"
|
2016-01-22 21:10:06 +01:00
|
|
|
#include <satnogs/log.h>
|
2016-01-21 20:33:08 +01:00
|
|
|
namespace gr
|
|
|
|
{
|
|
|
|
namespace satnogs
|
|
|
|
{
|
2016-01-19 18:35:37 +01:00
|
|
|
|
2016-01-21 20:33:08 +01:00
|
|
|
morse_decoder::sptr
|
|
|
|
morse_decoder::make (char unrecognized_char)
|
2016-01-19 18:35:37 +01:00
|
|
|
{
|
2016-01-21 20:33:08 +01:00
|
|
|
return gnuradio::get_initial_sptr (
|
|
|
|
new morse_decoder_impl (unrecognized_char));
|
2016-01-19 18:35:37 +01:00
|
|
|
}
|
|
|
|
|
2016-01-21 20:33:08 +01:00
|
|
|
void
|
|
|
|
morse_decoder_impl::symbol_msg_handler (pmt::pmt_t msg)
|
2016-01-19 18:35:37 +01:00
|
|
|
{
|
2016-01-23 21:23:19 +01:00
|
|
|
bool res;
|
|
|
|
std::string str;
|
2016-01-21 20:33:08 +01:00
|
|
|
morse_symbol_t s;
|
|
|
|
s = (morse_symbol_t) pmt::to_long (msg);
|
|
|
|
|
2016-01-22 21:10:06 +01:00
|
|
|
switch(s) {
|
|
|
|
case MORSE_DOT:
|
|
|
|
case MORSE_DASH:
|
|
|
|
case MORSE_S_SPACE:
|
2016-01-23 21:23:19 +01:00
|
|
|
res = d_morse_tree.received_symbol(s);
|
2016-01-22 21:10:06 +01:00
|
|
|
break;
|
2016-01-23 21:23:19 +01:00
|
|
|
/*
|
|
|
|
* If a word separator occurs it is a good time to retrieve the decoded
|
|
|
|
* word
|
|
|
|
*/
|
2016-01-22 21:10:06 +01:00
|
|
|
case MORSE_L_SPACE:
|
2016-02-01 21:04:27 +01:00
|
|
|
/*
|
|
|
|
* Inject a character separator, for the morse decoder to commit
|
|
|
|
* the outstanding character
|
|
|
|
*/
|
|
|
|
res = d_morse_tree.received_symbol(MORSE_S_SPACE);
|
2016-01-30 20:37:36 +01:00
|
|
|
/* Just ignore the word separator if no word is yet decoded */
|
|
|
|
if (d_morse_tree.get_word_len() == 0) {
|
|
|
|
res = true;
|
|
|
|
break;
|
|
|
|
}
|
2016-01-23 21:23:19 +01:00
|
|
|
str = d_morse_tree.get_word();
|
|
|
|
d_morse_tree.reset();
|
2016-01-24 20:43:17 +01:00
|
|
|
message_port_pub(pmt::mp("out"), pmt::make_blob(str.c_str(),
|
|
|
|
str.length()));
|
2016-01-22 21:10:06 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LOG_ERROR("Unknown Morse symbol");
|
2016-01-23 21:23:19 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the decoding return false, it means that either an non decode-able
|
|
|
|
* character situation occurred or the maximum word limit reached
|
|
|
|
*/
|
|
|
|
if (!s) {
|
|
|
|
if(d_morse_tree.get_max_word_len() == d_morse_tree.get_word_len()){
|
|
|
|
str = d_morse_tree.get_word();
|
|
|
|
d_morse_tree.reset();
|
|
|
|
std::cout << "Received word: " << str << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
LOG_DEBUG("Something went wrong");
|
2016-01-22 21:10:06 +01:00
|
|
|
}
|
2016-01-21 20:33:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The private constructor
|
|
|
|
*/
|
|
|
|
morse_decoder_impl::morse_decoder_impl (char unrecognized_char) :
|
|
|
|
gr::block ("morse_decoder",
|
|
|
|
gr::io_signature::make (0, 0, 0),
|
|
|
|
gr::io_signature::make (0, 0, 0)),
|
|
|
|
d_morse_tree (unrecognized_char)
|
|
|
|
{
|
2016-01-24 20:43:17 +01:00
|
|
|
/* Register the input and output msg handler */
|
2016-01-21 20:33:08 +01:00
|
|
|
message_port_register_in (pmt::mp ("in"));
|
2016-01-24 20:43:17 +01:00
|
|
|
message_port_register_out(pmt::mp("out"));
|
2016-01-21 20:33:08 +01:00
|
|
|
set_msg_handler (
|
|
|
|
pmt::mp ("in"),
|
|
|
|
boost::bind (&morse_decoder_impl::symbol_msg_handler, this, _1));
|
2016-01-19 18:35:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace satnogs */
|
|
|
|
} /* namespace gr */
|
|
|
|
|