diff options
author | Clayton Smith <argilo@gmail.com> | 2020-10-12 09:09:43 -0400 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2020-10-20 08:40:31 -0400 |
commit | 629d8854863ab9ea782d0c0d648f525ed5d4c71b (patch) | |
tree | 7fba59da700a1080c2f259abbb33a9c184a0b9a7 /gr-vocoder/lib | |
parent | a61c0c32b92dad34d4c1dda77064f36ce2780fcf (diff) |
vocoder: add text message output to FreeDV demodulator
The FreeDV protocol includes a low bit rate text stream which is used to
transmit information such as call sign and location. GNU Radio's FreeDV
demodulator block sets up a callback to receive this text data, but the
callback currently does nothing.
Here I've added an optional message output to the block. It collects
characters until a carriage return is encountered, then outputs a
string. I've updated the sample flow graph to print these messages using
the Message Debug block.
Diffstat (limited to 'gr-vocoder/lib')
-rw-r--r-- | gr-vocoder/lib/freedv_rx_ss_impl.cc | 30 | ||||
-rw-r--r-- | gr-vocoder/lib/freedv_rx_ss_impl.h | 14 |
2 files changed, 18 insertions, 26 deletions
diff --git a/gr-vocoder/lib/freedv_rx_ss_impl.cc b/gr-vocoder/lib/freedv_rx_ss_impl.cc index 03bfdda08f..266e2954fa 100644 --- a/gr-vocoder/lib/freedv_rx_ss_impl.cc +++ b/gr-vocoder/lib/freedv_rx_ss_impl.cc @@ -18,20 +18,6 @@ #include <assert.h> #include <stdexcept> -extern "C" { -void put_next_rx_char(void* callback_state, char c) -{ - struct freedv_rx_callback_state* pstate; - - pstate = (struct freedv_rx_callback_state*)callback_state; - if (pstate->ftxt != NULL) { - // fprintf(pstate->ftxt, "%c\n", c); - } - return; -} -} - - namespace gr { namespace vocoder { @@ -48,6 +34,7 @@ freedv_rx_ss_impl::freedv_rx_ss_impl(int mode, : gr::block("vocoder_freedv_rx_ss", io_signature::make(1, 1, sizeof(short)), io_signature::make(1, 1, sizeof(short))), + d_port(pmt::mp("text")), d_mode(mode), d_squelch_thresh(squelch_thresh), d_interleave_frames(interleave_frames) @@ -67,7 +54,8 @@ freedv_rx_ss_impl::freedv_rx_ss_impl(int mode, #endif freedv_set_snr_squelch_thresh(d_freedv, d_squelch_thresh); freedv_set_squelch_en(d_freedv, 0); - freedv_set_callback_txt(d_freedv, put_next_rx_char, NULL, (void*)&d_cb_state); + freedv_set_callback_txt(d_freedv, put_next_rx_char, NULL, this); + message_port_register_out(d_port); d_speech_samples = freedv_get_n_speech_samples(d_freedv); d_max_modem_samples = freedv_get_n_max_modem_samples(d_freedv); d_nin = freedv_nin(d_freedv); @@ -147,5 +135,17 @@ void freedv_rx_ss_impl::set_squelch_en(bool squelch_enabled) float freedv_rx_ss_impl::squelch_thresh() { return (d_squelch_thresh); } +void freedv_rx_ss_impl::put_next_rx_char(void* callback_state, char c) +{ + freedv_rx_ss_impl* instance = static_cast<freedv_rx_ss_impl*>(callback_state); + + if (c == '\r') { + instance->message_port_pub(instance->d_port, pmt::intern(instance->d_rx_str)); + instance->d_rx_str = ""; + } else { + instance->d_rx_str += c; + } +} + } /* namespace vocoder */ } /* namespace gr */ diff --git a/gr-vocoder/lib/freedv_rx_ss_impl.h b/gr-vocoder/lib/freedv_rx_ss_impl.h index 23c4e485fc..9a5d991f10 100644 --- a/gr-vocoder/lib/freedv_rx_ss_impl.h +++ b/gr-vocoder/lib/freedv_rx_ss_impl.h @@ -13,16 +13,6 @@ #include <gnuradio/vocoder/freedv_rx_ss.h> -extern "C" { -struct freedv_rx_callback_state { - FILE* ftxt; -}; -static void put_next_rx_char(void* callback_state, char c); -void put_next_rx_proto(void* callback_state, char* proto_bits); -void datarx(void* callback_state, unsigned char* packet, size_t size); -void datatx(void* callback_state, unsigned char* packet, size_t* size); -} - namespace gr { namespace vocoder { @@ -33,7 +23,9 @@ private: short* d_demod_in; struct freedv* d_freedv; int d_nin, d_nout, d_frame; - struct freedv_rx_callback_state d_cb_state; + std::string d_rx_str; + static void put_next_rx_char(void* callback_state, char c); + const pmt::pmt_t d_port; struct MODEM_STATS d_stats; int d_mode; int d_sync; |