diff --git a/include/lora/utilities.h b/include/lora/utilities.h index 2f46993..25f8dea 100644 --- a/include/lora/utilities.h +++ b/include/lora/utilities.h @@ -24,6 +24,7 @@ #include #include #include +#include #define MAC_CRC_SIZE 2u #define MAX_PWR_QUEUE_SIZE 4 @@ -348,11 +349,18 @@ namespace gr { } template - inline void print_vector_hex(std::ostream& out, const T* v, const uint32_t size, bool endline) { + inline void print_vector_hex(std::ostream& out, const T* v, const uint32_t size, bool endline, bool print_ascii) { + std::stringstream ss; + for (uint32_t i = 0u; i < size; i++) { out << " " << std::hex << std::setw(2) << std::setfill('0') << (int)v[i]; + if (v[i] >= ' ' && v[i] <= '~') + ss << v[i]; } + if (print_ascii) + out << " (" << ss.str() << ")"; + if(endline) out << std::endl; diff --git a/lib/decoder_impl.cc b/lib/decoder_impl.cc index 264e715..e0c9a91 100644 --- a/lib/decoder_impl.cc +++ b/lib/decoder_impl.cc @@ -840,7 +840,7 @@ namespace gr { if (demodulate(input, true)) { decode(true); - gr::lora::print_vector_hex(std::cout, &d_decoded[0], d_decoded.size(), false); + gr::lora::print_vector_hex(std::cout, &d_decoded[0], d_decoded.size(), false, false); memcpy(&d_phdr, &d_decoded[0], sizeof(loraphy_header_t)); if (d_phdr.cr > 4) d_phdr.cr = 4; @@ -880,7 +880,7 @@ namespace gr { if (d_payload_symbols <= 0) { decode(false); - gr::lora::print_vector_hex(std::cout, &d_decoded[0], d_payload_length, true); + gr::lora::print_vector_hex(std::cout, &d_decoded[0], d_payload_length, true, true); msg_lora_frame(); d_state = gr::lora::DecoderState::DETECT;