Commit d307d6ac authored by Manolis Surligas's avatar Manolis Surligas

Morse tree traversal is working

Depending the received symbol the tree is traversed towards the leafs.
At each step the corresponding decode-able character is appended at a
string buffer. 

TODOs: 
* Add logic in the decoder to retrieve the decoded words from the tree
* Create a debug source block  
parent ca49f817
......@@ -20,10 +20,13 @@
########################################################################
# Project setup
########################################################################
cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(gr-satnogs CXX C)
enable_testing()
# Enable C++11 support
set (CMAKE_CXX_STANDARD 11)
#select the release build type by default to get optimization flags
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
......
<?xml version="1.0"?>
<block>
<name>morse_decoder</name>
<name>Morse Decoder</name>
<key>satnogs_morse_decoder</key>
<category>satnogs</category>
<import>import satnogs</import>
<make>satnogs.morse_decoder()</make>
<make>satnogs.morse_decoder($unrecognized_char)</make>
<param>
<name>Unrecognized character</name>
<key>unrecognized_char</key>
<value>ord('#')</value>
<type>int</type>
</param>
<sink>
<name>in</name>
<type>message</type>
......
......@@ -22,7 +22,10 @@
########################################################################
install(FILES
api.h
config.h
cw_matched_filter_ff.h
morse_decoder.h
morse_tree.h DESTINATION include/satnogs
log.h
morse_tree.h
morse.h
morse_decoder.h DESTINATION include/satnogs
)
......@@ -18,25 +18,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef INCLUDE_SATNOGS_CONFIG_H_
#define INCLUDE_SATNOGS_CONFIG_H_
#include <gnuradio/io_signature.h>
#include <satnogs/morse_decoder.h>
namespace gr {
namespace satnogs {
morse_decoder::morse_decoder() :
d_morse_tree()
{
}
/*!
* Enable debug messages for the CW decoding mechanism
*/
#define CW_DEBUG 1
morse_decoder::~morse_decoder()
{
}
} /* namespace satnogs */
} /* namespace gr */
#endif /* INCLUDE_SATNOGS_CONFIG_H_ */
/* -*- 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/>.
*/
#ifndef LOG_H_
#define LOG_H_
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <satnogs/config.h>
#include <sys/syscall.h>
#if CW_DEBUG
#define LOG_INFO(M, ...) \
fprintf(stderr, "[INFO]: " M " \n", ##__VA_ARGS__)
#else
#define LOG_INFO(M, ...)
#endif
#define LOG_ERROR(M, ...) \
fprintf(stderr, "[ERROR] %s:%d: " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#define LOG_WARN(M, ...) \
fprintf(stderr, "[WARNING] %s:%d: " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#if CW_DEBUG
#define LOG_DEBUG(M, ...) \
fprintf(stderr, "[DEBUG]: " M "\n", ##__VA_ARGS__)
#else
#define LOG_DEBUG(M, ...)
#endif
#endif /* UTILS_LOG_H_ */
/* -*- 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/>.
*/
#ifndef INCLUDE_SATNOGS_MORSE_H_
#define INCLUDE_SATNOGS_MORSE_H_
/**
* The different Morse symbols
*/
typedef enum {
MORSE_DOT = 0,//!< MORSE_DOT Morse dot (.) symbol
MORSE_DASH, //!< MORSE_DASH Morse dash (-) symbol
MORSE_S_SPACE,//!< MORSE_S_SPACE Morse short space between characters
MORSE_L_SPACE //!< MORSE_L_SPACE Morse long space between words
} morse_symbol_t;
#endif /* INCLUDE_SATNOGS_MORSE_H_ */
......@@ -22,24 +22,28 @@
#define INCLUDED_SATNOGS_MORSE_DECODER_H
#include <satnogs/api.h>
#include <satnogs/morse_tree.h>
#include <gnuradio/block.h>
namespace gr {
namespace satnogs {
/*!
* \brief Morse code decoder block.
*
* This block received messages from the previous blocks
* and try to decode the dot and dashes into clear text.
*/
class SATNOGS_API morse_decoder
class SATNOGS_API morse_decoder : virtual public gr::block
{
public:
morse_decoder();
~morse_decoder();
private:
morse_tree d_morse_tree;
public:
typedef boost::shared_ptr<morse_decoder> sptr;
/*!
* Creates a Morse decoder block
* @param unrecognized_char the character that will be placed
* in situations where the decoder can not decide which character
* was received.
*/
static sptr make(char unrecognized_char = '#');
};
} // namespace satnogs
......
......@@ -22,9 +22,14 @@
#define INCLUDED_SATNOGS_MORSE_TREE_H
#include <satnogs/api.h>
#include <memory>
#include <string>
#include <satnogs/morse.h>
namespace gr {
namespace satnogs {
namespace gr
{
namespace satnogs
{
/*!
* \brief Binary tree node containing the corresponding character
......@@ -46,16 +51,19 @@ namespace gr {
set_right_child (tree_node *child);
tree_node*
get_left_child();
get_left_child ();
tree_node*
get_right_child();
get_right_child ();
char
get_char ();
};
/*!
* \brief A Binary tree representation of the Morse coding scheme.
* Left transitions occur when a dot is received, whereas right transitions
* are perfromed during the reception of a dash.
* are performed during the reception of a dash.
*
* The tree follows the ITU International Morse code representation
* ITU-R M.1677-1
......@@ -63,16 +71,28 @@ namespace gr {
class SATNOGS_API morse_tree
{
public:
morse_tree();
~morse_tree();
morse_tree ();
morse_tree (char unrecognized);
~morse_tree ();
void
reset ();
bool
received_symbol (morse_symbol_t s);
std::string
get_word ();
void reset();
private:
const char d_unrecognized_symbol;
tree_node *d_root;
tree_node *d_current;
const size_t d_buff_len;
size_t d_word_len;
std::unique_ptr<char[]> d_word_buffer;
void construct_tree();
void delete_tree(tree_node *node);
void
construct_tree ();
void
delete_tree (tree_node *node);
};
} // namespace satnogs
......
......@@ -26,8 +26,8 @@ include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIRS})
list(APPEND satnogs_sources
cw_matched_filter_ff_impl.cc
morse_decoder.cc
morse_tree.cc )
morse_tree.cc
morse_decoder_impl.cc )
set(satnogs_sources "${satnogs_sources}" PARENT_SCOPE)
if(NOT satnogs_sources)
......
/* -*- 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>
#include "morse_decoder_impl.h"
namespace gr
{
namespace satnogs
{
morse_decoder::sptr
morse_decoder::make (char unrecognized_char)
{
return gnuradio::get_initial_sptr (
new morse_decoder_impl (unrecognized_char));
}
void
morse_decoder_impl::symbol_msg_handler (pmt::pmt_t msg)
{
morse_symbol_t s;
s = (morse_symbol_t) pmt::to_long (msg);
//TODO Continue the logic based on s
}
/*
* 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)
{
/* Register the input msg handler */
message_port_register_in (pmt::mp ("in"));
set_msg_handler (
pmt::mp ("in"),
boost::bind (&morse_decoder_impl::symbol_msg_handler, this, _1));
}
} /* namespace satnogs */
} /* namespace gr */
/* -*- 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/>.
*/
#ifndef INCLUDED_SATNOGS_MORSE_DECODER_IMPL_H
#define INCLUDED_SATNOGS_MORSE_DECODER_IMPL_H
#include <satnogs/morse_decoder.h>
#include <satnogs/morse_tree.h>
namespace gr {
namespace satnogs {
class morse_decoder_impl : public morse_decoder
{
private:
morse_tree d_morse_tree;
void
symbol_msg_handler(pmt::pmt_t msg);
public:
morse_decoder_impl(char unrecognized_char);
};
} // namespace satnogs
} // namespace gr
#endif /* INCLUDED_SATNOGS_MORSE_DECODER_IMPL_H */
This diff is collapsed.
......@@ -9,11 +9,12 @@
%{
#include "satnogs/cw_matched_filter_ff.h"
#include "satnogs/morse_decoder.h"
#include "satnogs/morse_tree.h"
#include "satnogs/morse_decoder.h"
%}
%include "satnogs/cw_matched_filter_ff.h"
GR_SWIG_BLOCK_MAGIC2(satnogs, cw_matched_filter_ff);
%include "satnogs/morse_decoder.h"
%include "satnogs/morse_tree.h"
%include "satnogs/morse_decoder.h"
GR_SWIG_BLOCK_MAGIC2(satnogs, morse_decoder);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment