Commit 52411357 authored by Manolis Surligas's avatar Manolis Surligas

Fix bug at Morse debug source block

The Morse decoder seems that works properly now. However, there is no
recovery strategy yet from undecodeable symbol sequences. 
parent ebd07215
......@@ -148,7 +148,7 @@
</param>
<param>
<key>debug_seq</key>
<value>"HELLO WORLD"</value>
<value>"HELLO EARTH WORLD"</value>
</param>
</block>
<block>
......
......@@ -80,6 +80,10 @@ namespace gr
received_symbol (morse_symbol_t s);
std::string
get_word ();
size_t
get_max_word_len () const;
size_t
get_word_len ();
private:
const char d_unrecognized_symbol;
......
......@@ -84,7 +84,7 @@ namespace gr {
size_t len = sentence.length();
pmt::pmt_t port = pmt::mp("out");
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
while(d_run) {
/* Not the best approach, but hey, this is only for debug */
for(i = 0; i < len; i++){
......@@ -103,12 +103,15 @@ namespace gr {
else{
message_port_pub(port, pmt::from_long(MORSE_DASH));
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
/* Send also a character delimiter after waiting a little */
std::this_thread::sleep_for(std::chrono::milliseconds(400));
std::this_thread::sleep_for(std::chrono::milliseconds(200));
message_port_pub(port, pmt::from_long(MORSE_S_SPACE));
}
}
}
message_port_pub(port, pmt::from_long(MORSE_L_SPACE));
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
}
......
......@@ -40,24 +40,45 @@ namespace gr
void
morse_decoder_impl::symbol_msg_handler (pmt::pmt_t msg)
{
bool res;
std::string str;
morse_symbol_t s;
s = (morse_symbol_t) pmt::to_long (msg);
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");
LOG_DEBUG("Received %d", s);
res = d_morse_tree.received_symbol(s);
break;
/*
* If a word separator occurs it is a good time to retrieve the decoded
* word
*/
case MORSE_L_SPACE:
LOG_DEBUG("Long space received");
str = d_morse_tree.get_word();
d_morse_tree.reset();
std::cout << "Received word: " << str << std::endl;
break;
default:
LOG_ERROR("Unknown Morse symbol");
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");
}
}
......
......@@ -41,7 +41,7 @@ namespace gr
d_current (d_root),
d_buff_len(4096),
d_word_len(0),
d_word_buffer(new char(d_buff_len))
d_word_buffer(new char[d_buff_len])
{
construct_tree ();
}
......@@ -57,7 +57,7 @@ namespace gr
d_current (d_root),
d_buff_len(4096),
d_word_len(0),
d_word_buffer(new char(d_buff_len))
d_word_buffer(new char[d_buff_len])
{
construct_tree ();
}
......@@ -197,6 +197,7 @@ namespace gr
morse_tree::received_symbol (morse_symbol_t s)
{
char c = 0;
bool ret = false;
/* Check for overflow */
if (d_word_len == d_buff_len) {
return false;
......@@ -206,33 +207,18 @@ namespace gr
case MORSE_DOT:
if (d_current->get_left_child ()) {
d_current = d_current->get_left_child ();
c = d_current->get_char ();
}
/*
* There is no left child. Something went wrong. Let the caller decide
*/
else {
return false;
ret = true;
}
break;
case MORSE_DASH:
if (d_current->get_right_child ()) {
d_current = d_current->get_right_child ();
c = d_current->get_char ();
}
/*
* There is no right child. Something went wrong.
* Let the caller decide
*/
else {
return false;
ret = true;
}
break;
default:
LOG_ERROR("Unsupported Morse symbol");
return false;
}
case MORSE_S_SPACE:
c = d_current->get_char ();
d_current = d_root;
/*
* Some nodes are null transitions and do not correspond to
* a specific character
......@@ -240,14 +226,32 @@ namespace gr
if (c != 0) {
d_word_buffer[d_word_len] = c;
d_word_len++;
ret = true;
}
break;
default:
LOG_ERROR("Unsupported Morse symbol");
return false;
}
return true;
return ret;
}
std::string
morse_tree::get_word ()
{
return std::string(d_word_buffer.get(), d_buff_len);
return std::string(d_word_buffer.get(), d_word_len);
}
size_t
morse_tree::get_max_word_len () const
{
return d_buff_len;
}
size_t
morse_tree::get_word_len ()
{
return d_word_len;
}
void
......
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