From cf99c8674cfacef5ffb45cda9ff102e5111eded5 Mon Sep 17 00:00:00 2001 From: Jean-Michel Friedt Date: Tue, 21 Feb 2023 19:03:23 +0100 Subject: [PATCH] add debug flag to decoder and coder function of GNU Radio 3.10 --- grc/m17_m17_coder.block.yml | 8 +++++++- grc/m17_m17_decoder.block.yml | 11 ++++++++++- include/gnuradio/m17/m17_coder.h | 3 ++- include/gnuradio/m17/m17_decoder.h | 3 ++- lib/m17_coder_impl.cc | 15 ++++++++++----- lib/m17_coder_impl.h | 4 +++- lib/m17_decoder_impl.cc | 28 +++++++++++++++++++--------- lib/m17_decoder_impl.h | 5 +++-- 8 files changed, 56 insertions(+), 21 deletions(-) diff --git a/grc/m17_m17_coder.block.yml b/grc/m17_m17_coder.block.yml index 058bd65..5b9576b 100644 --- a/grc/m17_m17_coder.block.yml +++ b/grc/m17_m17_coder.block.yml @@ -23,18 +23,24 @@ parameters: label: Meta dtype: string default: 'helloworld' +- id: debug + label: Debug + dtype: bool + default: 'False' + options: ['True', 'False'] asserts: - ${type<256} templates: imports: from gnuradio import m17 - make: m17.m17_coder(${src_id},${dst_id},${type},${meta},${samp_rate}) + make: m17.m17_coder(${src_id},${dst_id},${type},${meta},${samp_rate},${debug}) callbacks: - set_meta(${meta}) - set_samp_rate(${samp_rate}) - set_src_id(${src_id}) - set_dst_id(${dst_id}) - set_type(${type}) + - set_debug(${debug}) # Make one 'inputs' list entry per input and one 'outputs' list entry per output. # Keys include: diff --git a/grc/m17_m17_decoder.block.yml b/grc/m17_m17_decoder.block.yml index ed6cf59..22fc073 100644 --- a/grc/m17_m17_decoder.block.yml +++ b/grc/m17_m17_decoder.block.yml @@ -2,9 +2,18 @@ id: m17_m17_decoder label: m17_decoder category: '[m17]' +parameters: +- id: debug + label: Debug + dtype: bool + default: 'False' + options: ['True', 'False'] + templates: imports: from gnuradio import m17 - make: m17.m17_decoder() + make: m17.m17_decoder(${debug}) + callbacks: + - set_debug(${debug}) # Make one 'inputs' list entry per input and one 'outputs' list entry per output. # Keys include: diff --git a/include/gnuradio/m17/m17_coder.h b/include/gnuradio/m17/m17_coder.h index ef2736c..803949c 100644 --- a/include/gnuradio/m17/m17_coder.h +++ b/include/gnuradio/m17/m17_coder.h @@ -32,11 +32,12 @@ public: * class. m17::m17_coder::make is the public interface for * creating new instances. */ - static sptr make(std::string src_id,std::string dst_id,short type,std::string meta,float samp_rate); + static sptr make(std::string src_id,std::string dst_id,short type,std::string meta,float samp_rate,bool debug); virtual void set_meta(std::string meta)=0; virtual void set_src_id(std::string src_id)=0; virtual void set_dst_id(std::string dst_id)=0; virtual void set_samp_rate(float samp_rate)=0; + virtual void set_debug(bool debug)=0; }; } // namespace m17 diff --git a/include/gnuradio/m17/m17_decoder.h b/include/gnuradio/m17/m17_decoder.h index 7027999..631077e 100644 --- a/include/gnuradio/m17/m17_decoder.h +++ b/include/gnuradio/m17/m17_decoder.h @@ -32,7 +32,8 @@ public: * class. m17::m17_decoder::make is the public interface for * creating new instances. */ - static sptr make(); + static sptr make(bool debug); + virtual void set_debug(bool debug)=0; }; } // namespace m17 diff --git a/lib/m17_coder_impl.cc b/lib/m17_coder_impl.cc index 8f905ad..1d2a7cf 100644 --- a/lib/m17_coder_impl.cc +++ b/lib/m17_coder_impl.cc @@ -261,31 +261,31 @@ uint16_t LSF_CRC(struct LSF *in) } m17_coder::sptr - m17_coder::make(std::string src_id,std::string dst_id,short type,std::string meta, float samp_rate) + m17_coder::make(std::string src_id,std::string dst_id,short type,std::string meta, float samp_rate,bool debug) { return gnuradio::get_initial_sptr - (new m17_coder_impl(src_id,dst_id,type,meta,samp_rate)); + (new m17_coder_impl(src_id,dst_id,type,meta,samp_rate,debug)); } /* * The private constructor */ - m17_coder_impl::m17_coder_impl(std::string src_id,std::string dst_id,short type,std::string meta, float samp_rate) + m17_coder_impl::m17_coder_impl(std::string src_id,std::string dst_id,short type,std::string meta, float samp_rate, bool debug) : gr::block("m17_coder", gr::io_signature::make(1, 1, sizeof(char)), gr::io_signature::make(1, 1, sizeof(float))) - ,_meta(meta), _samp_rate(samp_rate) + ,_meta(meta), _samp_rate(samp_rate), _debug(debug) { set_meta(meta); set_src_id(src_id); set_dst_id(dst_id); set_samp_rate(samp_rate); set_type(type); + set_debug(debug); uint16_t ccrc=LSF_CRC(&lsf); lsf.crc[0]=ccrc>>8; lsf.crc[1]=ccrc&0xFF; _got_lsf=0; //have we filled the LSF struct yet? _fn=0; //16-bit Frame Number (for the stream mode) - } void m17_coder_impl::set_samp_rate(float samp_rate) @@ -293,6 +293,11 @@ void m17_coder_impl::set_samp_rate(float samp_rate) printf("New sampling rate: %f\n",_samp_rate); } +void m17_coder_impl::set_debug(bool debug) +{_debug=debug; + if (_debug==true) printf("true\n"); else printf("Debug false\n"); +} + void m17_coder_impl::set_src_id(std::string src_id) {for (int i=0;i<6;i++) {_src_id[i]=0;} sscanf(src_id.c_str(), "%hhu.%hhu.%hhu.%hhu.%hhu.%hhu", &_src_id[0], &_src_id[1], &_src_id[2], &_src_id[3],&_src_id[4],&_src_id[5]); diff --git a/lib/m17_coder_impl.h b/lib/m17_coder_impl.h index ecc5c59..da8bb74 100644 --- a/lib/m17_coder_impl.h +++ b/lib/m17_coder_impl.h @@ -22,6 +22,7 @@ private: short _type; int _got_lsf=0; uint16_t _fn=0; //16-bit Frame Number (for the stream mode) + bool _debug=0; public: @@ -30,7 +31,8 @@ public: void set_samp_rate(float samp_rate); void set_meta(std::string meta); void set_type(short type); - m17_coder_impl(std::string src_id,std::string dst_id,short type,std::string meta,float samp_rate); + void set_debug(bool debug); + m17_coder_impl(std::string src_id,std::string dst_id,short type,std::string meta,float samp_rate,bool debug); ~m17_coder_impl(); // Where all the action really happens diff --git a/lib/m17_decoder_impl.cc b/lib/m17_decoder_impl.cc index 096529e..491892f 100644 --- a/lib/m17_decoder_impl.cc +++ b/lib/m17_decoder_impl.cc @@ -101,21 +101,22 @@ void decode_callsign(uint8_t *outp, const uint8_t *inp) } m17_decoder::sptr - m17_decoder::make() + m17_decoder::make(bool debug) { return gnuradio::get_initial_sptr - (new m17_decoder_impl()); + (new m17_decoder_impl(debug)); } /* * The private constructor */ - m17_decoder_impl::m17_decoder_impl() + m17_decoder_impl::m17_decoder_impl(bool debug) : gr::block("m17_decoder", gr::io_signature::make(1, 1, sizeof(float)), - gr::io_signature::make(1, 1, sizeof(char))) - {} + gr::io_signature::make(1, 1, sizeof(char))), + _debug(debug) + {set_debug(debug);} /* * Our virtual destructor. @@ -124,6 +125,11 @@ void decode_callsign(uint8_t *outp, const uint8_t *inp) { } +void m17_decoder_impl::set_debug(bool debug) +{_debug=debug; + if (_debug==true) printf("true\n"); else printf("Debug false\n"); +} + void m17_decoder_impl::forecast (int noutput_items, gr_vector_int &ninput_items_required) { @@ -281,6 +287,7 @@ uint8_t pushed; //counter for pushed symbols decode_callsign(d_dst, &lsf[0]); decode_callsign(d_src, &lsf[6]); +if (_debug==true) { //DST printf("DST: %-9s ", d_dst); @@ -321,7 +328,7 @@ uint8_t pushed; //counter for pushed symbols else printf(" LSF_CRC_OK "); printf("\n"); - +} lich_chunks_rcvd=0; //reset all flags } @@ -334,6 +341,7 @@ uint8_t pushed; //counter for pushed symbols //decode uint32_t e=decodePunctured(frame_data, enc_data, P_2, 272, 12); +if (_debug==true) { //dump data - first byte is empty printf("FN: %02X%02X PLD: ", frame_data[1], frame_data[2]); for(uint8_t i=3; i<19; i++) @@ -345,14 +353,15 @@ uint8_t pushed; //counter for pushed symbols #else printf("\n"); #endif - +} //send codec2 stream to stdout //write(STDOUT_FILENO, &frame_data[3], 16); } else //lsf { +if (_debug==true) { printf("LSF\n"); - +} //decode uint32_t e=decodePunctured(lsf, d_soft_bit, P_1, 2*SYM_PER_PLD, 61); @@ -367,6 +376,7 @@ uint8_t pushed; //counter for pushed symbols decode_callsign(d_dst, &lsf[0]); decode_callsign(d_src, &lsf[6]); +if (_debug==true) { //DST printf("DST: %-9s ", d_dst); @@ -406,13 +416,13 @@ uint8_t pushed; //counter for pushed symbols printf("LSF_CRC_ERR"); else printf("LSF_CRC_OK "); - //Viterbi decoder errors #ifdef SHOW_VITERBI_ERRS printf(" e=%1.1f\n", (float)e/0xFFFF); #else printf("\n"); #endif +} } //job done diff --git a/lib/m17_decoder_impl.h b/lib/m17_decoder_impl.h index 12a198c..d395798 100644 --- a/lib/m17_decoder_impl.h +++ b/lib/m17_decoder_impl.h @@ -16,11 +16,12 @@ namespace m17 { class m17_decoder_impl : public m17_decoder { private: - // Nothing to declare in this block. + bool _debug=false; public: - m17_decoder_impl(); + m17_decoder_impl(bool debug); ~m17_decoder_impl(); + void set_debug(bool debug); // Where all the action really happens void forecast(int noutput_items, gr_vector_int& ninput_items_required);