diff --git a/CMakeLists.txt b/CMakeLists.txt index dd4a043..c5eeb03 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,7 @@ enable_testing() # Enable C++11 support set (CMAKE_CXX_STANDARD 11) +add_definitions(-std=c++11) #select the release build type by default to get optimization flags if(NOT CMAKE_BUILD_TYPE) @@ -103,6 +104,11 @@ if(APPLE) endif(NOT CMAKE_BUILD_WITH_INSTALL_RPATH) endif(APPLE) +######################################################################## +# Find gnuradio build dependencies +######################################################################## +find_package (Threads REQUIRED) + ######################################################################## # Find gnuradio build dependencies ######################################################################## diff --git a/examples/test_morse_decoder.grc b/examples/test_morse_decoder.grc new file mode 100644 index 0000000..4fd0e55 --- /dev/null +++ b/examples/test_morse_decoder.grc @@ -0,0 +1,195 @@ + + + + Fri Jan 22 20:01:21 2016 + + options + + author + + + + window_size + + + + category + Custom + + + comment + + + + description + + + + _enabled + True + + + _coordinate + (8, 8) + + + _rotation + 0 + + + generate_options + qt_gui + + + hier_block_src_path + .: + + + id + test_morse_decoder + + + max_nouts + 0 + + + qt_qss_theme + + + + realtime_scheduling + + + + run_command + {python} -u {filename} + + + run_options + prompt + + + run + True + + + thread_safe_setters + + + + title + + + + + variable + + comment + + + + _enabled + True + + + _coordinate + (8, 160) + + + _rotation + 0 + + + id + samp_rate + + + value + 32000 + + + + satnogs_morse_debug_source + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + _coordinate + (240, 196) + + + _rotation + 0 + + + id + satnogs_morse_debug_source_0 + + + maxoutbuf + 0 + + + minoutbuf + 0 + + + debug_seq + "HELLO WORLD" + + + + satnogs_morse_decoder + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + _coordinate + (752, 276) + + + _rotation + 0 + + + id + satnogs_morse_decoder_0 + + + unrecognized_char + ord('#') + + + + satnogs_morse_debug_source_0 + satnogs_morse_decoder_0 + out + in + + diff --git a/grc/CMakeLists.txt b/grc/CMakeLists.txt index 567eece..e7f9f22 100644 --- a/grc/CMakeLists.txt +++ b/grc/CMakeLists.txt @@ -18,5 +18,6 @@ # Boston, MA 02110-1301, USA. install(FILES satnogs_cw_matched_filter_ff.xml - satnogs_morse_decoder.xml DESTINATION share/gnuradio/grc/blocks + satnogs_morse_decoder.xml + satnogs_morse_debug_source.xml DESTINATION share/gnuradio/grc/blocks ) diff --git a/grc/satnogs_morse_debug_source.xml b/grc/satnogs_morse_debug_source.xml new file mode 100644 index 0000000..1993acd --- /dev/null +++ b/grc/satnogs_morse_debug_source.xml @@ -0,0 +1,24 @@ + + + Morse code Debug Source + satnogs_morse_debug_source + satnogs + import satnogs + satnogs.morse_debug_source($debug_seq) + + + Sentence + debug_seq + "HELLO WORLD" + string + + + + out + message + + diff --git a/include/satnogs/CMakeLists.txt b/include/satnogs/CMakeLists.txt index 7203505..ee0b40b 100644 --- a/include/satnogs/CMakeLists.txt +++ b/include/satnogs/CMakeLists.txt @@ -27,5 +27,6 @@ install(FILES log.h morse_tree.h morse.h - morse_decoder.h DESTINATION include/satnogs + morse_decoder.h + morse_debug_source.h DESTINATION include/satnogs ) diff --git a/include/satnogs/morse_debug_source.h b/include/satnogs/morse_debug_source.h new file mode 100644 index 0000000..c2939c1 --- /dev/null +++ b/include/satnogs/morse_debug_source.h @@ -0,0 +1,53 @@ +/* -*- 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_MORSE_DEBUG_SOURCE_H +#define INCLUDED_SATNOGS_MORSE_DEBUG_SOURCE_H + +#include +#include + +namespace gr { + namespace satnogs { + + /*! + * \brief A Morse debug source block + * \ingroup satnogs + * + */ + class SATNOGS_API morse_debug_source : virtual public gr::block + { + public: + typedef boost::shared_ptr sptr; + + /*! + * \brief A Morse debug source block that produces messages corresponding + * to Morse symbols, based on the given debug_seq string. + * + * @param debug_seq A string containing the debug sentence + */ + static sptr make(const std::string& debug_seq); + }; + + } // namespace satnogs +} // namespace gr + +#endif /* INCLUDED_SATNOGS_MORSE_DEBUG_SOURCE_H */ + diff --git a/include/satnogs/morse_tree.h b/include/satnogs/morse_tree.h index 337af33..47a5a10 100644 --- a/include/satnogs/morse_tree.h +++ b/include/satnogs/morse_tree.h @@ -34,7 +34,7 @@ namespace gr /*! * \brief Binary tree node containing the corresponding character */ - class tree_node + class SATNOGS_API tree_node { private: const char d_char; diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index d2f9c13..61851b1 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -27,7 +27,8 @@ link_directories(${Boost_LIBRARY_DIRS}) list(APPEND satnogs_sources cw_matched_filter_ff_impl.cc morse_tree.cc - morse_decoder_impl.cc ) + morse_decoder_impl.cc + morse_debug_source_impl.cc ) set(satnogs_sources "${satnogs_sources}" PARENT_SCOPE) if(NOT satnogs_sources) @@ -36,7 +37,11 @@ if(NOT satnogs_sources) endif(NOT satnogs_sources) add_library(gnuradio-satnogs SHARED ${satnogs_sources}) -target_link_libraries(gnuradio-satnogs ${Boost_LIBRARIES} ${GNURADIO_ALL_LIBRARIES}) +target_link_libraries(gnuradio-satnogs + ${Boost_LIBRARIES} + ${GNURADIO_ALL_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT}) + set_target_properties(gnuradio-satnogs PROPERTIES DEFINE_SYMBOL "gnuradio_satnogs_EXPORTS") if(APPLE) diff --git a/lib/morse_debug_source_impl.cc b/lib/morse_debug_source_impl.cc new file mode 100644 index 0000000..ceb59e6 --- /dev/null +++ b/lib/morse_debug_source_impl.cc @@ -0,0 +1,127 @@ +/* -*- 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 "morse_debug_source_impl.h" +#include + +namespace gr { + namespace satnogs { + + morse_debug_source::sptr + morse_debug_source::make(const std::string& debug_seq) + { + return gnuradio::get_initial_sptr + (new morse_debug_source_impl(debug_seq)); + } + + /* + * The private constructor + */ + morse_debug_source_impl::morse_debug_source_impl(std::string debug_seq) + : gr::block("morse_debug_source", + gr::io_signature::make(0, 0, 0), + gr::io_signature::make(0, 0, 0)), + d_run(true), + d_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' }, + d_symbols { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", + "....", "..", ".---", "-.-", ".-..", "--", "-.", + "---", ".--.", "--.-", ".-.", "...", "-", "..-", + "...-", ".--", "-..-", "-.--", "--..", ".----", + "..---", "...--", "....-", ".....", "-....", "--...", + "---..", "----.", "-----"} + { + message_port_register_out(pmt::mp("out")); + d_thread = std::thread(&morse_debug_source_impl::send_debug_msg, + this, + debug_seq); + } + + 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; + } + + void + morse_debug_source_impl::send_debug_msg (std::string sentence) + { + size_t i; + size_t j; + size_t idx; + std::string s; + char c; + size_t len = sentence.length(); + pmt::pmt_t port = pmt::mp("out"); + + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + while(d_run) { + /* Not the best approach, but hey, this is only for debug */ + for(i = 0; i < len; i++){ + c = std::toupper(sentence[i]); + if(c == ' '){ + message_port_pub(port, pmt::from_long(MORSE_L_SPACE)); + } + + idx = find_char_idx(d_chars, sizeof(d_chars), c); + if(idx != sizeof(d_chars)){ + s = d_symbols[idx]; + for(j = 0; j < s.length(); j++) { + if(s[j] == '.'){ + message_port_pub(port, pmt::from_long(MORSE_DOT)); + } + else{ + message_port_pub(port, pmt::from_long(MORSE_DASH)); + } + /* Send also a character delimiter after waiting a little */ + std::this_thread::sleep_for(std::chrono::milliseconds(400)); + message_port_pub(port, pmt::from_long(MORSE_S_SPACE)); + } + } + } + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + } + } + + /* + * Our virtual destructor. + */ + morse_debug_source_impl::~morse_debug_source_impl() + { + d_run = false; + d_thread.join(); + } + + } /* namespace satnogs */ +} /* namespace gr */ + diff --git a/lib/morse_debug_source_impl.h b/lib/morse_debug_source_impl.h new file mode 100644 index 0000000..5c1f7e2 --- /dev/null +++ b/lib/morse_debug_source_impl.h @@ -0,0 +1,52 @@ +/* -*- 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_MORSE_DEBUG_SOURCE_IMPL_H +#define INCLUDED_SATNOGS_MORSE_DEBUG_SOURCE_IMPL_H + +#include +#include +#include +#include + +namespace gr { + namespace satnogs { + + class morse_debug_source_impl : public morse_debug_source + { + private: + bool d_run; + const char d_chars[36]; + const std::vector d_symbols; + std::thread d_thread; + + void + send_debug_msg(std::string sentence); + + public: + morse_debug_source_impl(std::string debug_seq); + ~morse_debug_source_impl(); + }; + + } // namespace satnogs +} // namespace gr + +#endif /* INCLUDED_SATNOGS_MORSE_DEBUG_SOURCE_IMPL_H */ + diff --git a/lib/morse_decoder_impl.cc b/lib/morse_decoder_impl.cc index 5eca585..8b21600 100644 --- a/lib/morse_decoder_impl.cc +++ b/lib/morse_decoder_impl.cc @@ -24,7 +24,7 @@ #include #include "morse_decoder_impl.h" - +#include namespace gr { namespace satnogs @@ -43,7 +43,22 @@ namespace gr morse_symbol_t s; s = (morse_symbol_t) pmt::to_long (msg); - //TODO Continue the logic based on s + switch(s) { + case MORSE_DOT: + LOG_DEBUG("Dot received"); + break; + case MORSE_DASH: + LOG_DEBUG("Dash received"); + break; + case MORSE_S_SPACE: + LOG_DEBUG("Short space received"); + break; + case MORSE_L_SPACE: + LOG_DEBUG("Long space received"); + break; + default: + LOG_ERROR("Unknown Morse symbol"); + } } /* diff --git a/swig/satnogs_swig.i b/swig/satnogs_swig.i index 12796ff..ad58389 100644 --- a/swig/satnogs_swig.i +++ b/swig/satnogs_swig.i @@ -11,6 +11,7 @@ #include "satnogs/cw_matched_filter_ff.h" #include "satnogs/morse_tree.h" #include "satnogs/morse_decoder.h" +#include "satnogs/morse_debug_source.h" %} %include "satnogs/cw_matched_filter_ff.h" @@ -18,3 +19,5 @@ GR_SWIG_BLOCK_MAGIC2(satnogs, cw_matched_filter_ff); %include "satnogs/morse_tree.h" %include "satnogs/morse_decoder.h" GR_SWIG_BLOCK_MAGIC2(satnogs, morse_decoder); +%include "satnogs/morse_debug_source.h" +GR_SWIG_BLOCK_MAGIC2(satnogs, morse_debug_source);