From 62c0f6ada7853e281c5c4705d2edd29518bfc54a Mon Sep 17 00:00:00 2001 From: Pieter Robyns Date: Wed, 20 Dec 2017 10:44:45 +0100 Subject: [PATCH] Colored interleave matrix print in debug mode --- include/lora/utilities.h | 41 +++++++++++++++++++++++++++++++++++----- lib/decoder_impl.cc | 5 ++--- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/include/lora/utilities.h b/include/lora/utilities.h index 20ad203..2f46993 100644 --- a/include/lora/utilities.h +++ b/include/lora/utilities.h @@ -25,7 +25,6 @@ #include #include -#define REV_BITS #define MAC_CRC_SIZE 2u #define MAX_PWR_QUEUE_SIZE 4 #define SM(value, shift, mask) (((value) << (shift)) & (mask)) @@ -33,6 +32,34 @@ namespace gr { namespace lora { + static std::vector term_colors = { + "\e[0m", + "\e[1m\e[91m", + "\e[1m\e[92m", + "\e[1m\e[93m", + "\e[1m\e[94m", + "\e[1m\e[95m", + "\e[1m\e[96m", + "\e[1m\e[97m", + "\e[1m\e[31m", + "\e[1m\e[32m", + "\e[1m\e[33m", + "\e[1m\e[34m", + "\e[1m\e[35m", + "\e[1m\e[36m" + }; + + /** + * \brief Wrap indices Python-like, i.e. array[wrap_index(-1, array_length)] gets the last element. + * + * \param i + * Index of array + * \param n + * Length of array + */ + inline int32_t wrap_index(int32_t i, int32_t n) { + return ((i % n) + n) % n; + } /** * \brief Clamp given value in the given range. @@ -86,7 +113,7 @@ namespace gr { */ template inline std::string to_bin(const T v, const uint32_t bitwidth) { - #ifdef REV_BITS + #ifdef LSB_FIRST const uint64_t maxpow = bitwidth ? (1ull << (bitwidth - 1)) : 0; uint64_t mask; @@ -340,13 +367,17 @@ namespace gr { out << "-"; out << std::endl; - for(uint32_t i = 0; i < sf; i++) { - for(uint32_t j = 0; j < cr; j++) { - out << to_bin(v[j], sf)[i]; + out << "LSB" << std::endl; + + for(int32_t i = sf-1; i >= 0; i--) { + for(int32_t j = 0; j < (int32_t)cr; j++) { + out << term_colors[wrap_index(j-i, (int32_t)sf)+1] << to_bin(v[j], sf)[i] << term_colors[0]; } out << std::endl; } + out << "MSB" << std::endl; + for(uint32_t i = 0; i < cr; i++) out << "-"; out << std::endl; diff --git a/lib/decoder_impl.cc b/lib/decoder_impl.cc index c6e8e7e..8a6fbc8 100644 --- a/lib/decoder_impl.cc +++ b/lib/decoder_impl.cc @@ -493,7 +493,7 @@ namespace gr { const uint32_t word = bin_idx ^ (bin_idx >> 1u); #ifdef DEBUG - d_debug << gr::lora::to_bin(word, is_header ? d_sf - 2u : d_sf) << " " << bin_idx << std::endl; + d_debug << gr::lora::to_bin(word, is_header ? d_sf - 2u : d_sf) << " " << word << " (bin " << bin_idx << ")" << std::endl; #endif d_words.push_back(word); @@ -533,8 +533,8 @@ namespace gr { } #ifdef DEBUG + print_interleave_matrix(d_debug, d_words, ppm); print_vector_bin(d_debug, words_deinterleaved, "D", sizeof(uint8_t) * 8u); - //print_interleave_matrix(d_debug, d_words, ppm); #endif // Add to demodulated data @@ -605,7 +605,6 @@ namespace gr { #ifdef DEBUG print_vector_bin(d_debug, d_words_deshuffled, "S", sizeof(uint8_t)*8); - d_debug << std::endl; #endif // We're done with these words