aboutsummaryrefslogtreecommitdiffstats
path: root/gr-vocoder
diff options
context:
space:
mode:
authorClayton Smith <argilo@gmail.com>2020-10-12 09:09:43 -0400
committermormj <34754695+mormj@users.noreply.github.com>2020-10-20 08:40:31 -0400
commit629d8854863ab9ea782d0c0d648f525ed5d4c71b (patch)
tree7fba59da700a1080c2f259abbb33a9c184a0b9a7 /gr-vocoder
parentmodtool: check blockname before other checks (diff)
downloadgnuradio-629d8854863ab9ea782d0c0d648f525ed5d4c71b.tar.xz
gnuradio-629d8854863ab9ea782d0c0d648f525ed5d4c71b.zip
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')
-rw-r--r--gr-vocoder/examples/grfreedv.grc71
-rw-r--r--gr-vocoder/grc/vocoder_freedv_rx_ss.block.yml3
-rw-r--r--gr-vocoder/lib/freedv_rx_ss_impl.cc30
-rw-r--r--gr-vocoder/lib/freedv_rx_ss_impl.h14
4 files changed, 80 insertions, 38 deletions
diff --git a/gr-vocoder/examples/grfreedv.grc b/gr-vocoder/examples/grfreedv.grc
index 25865df36..5bb41d2b8 100644
--- a/gr-vocoder/examples/grfreedv.grc
+++ b/gr-vocoder/examples/grfreedv.grc
@@ -1,6 +1,7 @@
options:
parameters:
author: A. Maitland Bottoms
+ catch_exceptions: 'True'
category: Custom
cmake_opt: ''
comment: ''
@@ -22,9 +23,11 @@ options:
sizing_mode: fixed
thread_safe_setters: ''
title: GNU Radio FreeDV
- window_size: ''
states:
- coordinate: [8, 8]
+ bus_sink: false
+ bus_source: false
+ bus_structure: null
+ coordinate: [8, 4.0]
rotation: 0
state: enabled
@@ -35,7 +38,10 @@ blocks:
comment: ''
value: '8000'
states:
- coordinate: [8, 160]
+ bus_sink: false
+ bus_source: false
+ bus_structure: null
+ coordinate: [8, 164.0]
rotation: 0
state: enabled
- name: squelch
@@ -45,7 +51,7 @@ blocks:
gui_hint: ''
label: squelch slider
min_len: '256'
- orient: Qt.Horizontal
+ orient: QtCore.Qt.Horizontal
rangeType: float
start: '-127'
step: '1'
@@ -53,7 +59,10 @@ blocks:
value: '-120'
widget: counter_slider
states:
- coordinate: [232, 16]
+ bus_sink: false
+ bus_source: false
+ bus_structure: null
+ coordinate: [184, 4.0]
rotation: 0
state: enabled
- name: audio_sink_0
@@ -67,7 +76,10 @@ blocks:
ok_to_block: 'True'
samp_rate: samp_rate
states:
- coordinate: [1152, 220.0]
+ bus_sink: false
+ bus_source: false
+ bus_structure: null
+ coordinate: [1192, 204.0]
rotation: 0
state: enabled
- name: audio_source_0
@@ -83,6 +95,9 @@ blocks:
ok_to_block: 'True'
samp_rate: '48000'
states:
+ bus_sink: false
+ bus_source: false
+ bus_structure: null
coordinate: [8, 300.0]
rotation: 0
state: enabled
@@ -97,9 +112,25 @@ blocks:
scale: '32768'
vlen: '1'
states:
- coordinate: [456, 220.0]
+ bus_sink: false
+ bus_source: false
+ bus_structure: null
+ coordinate: [416, 220.0]
rotation: 0
state: enabled
+- name: blocks_message_debug_0
+ id: blocks_message_debug
+ parameters:
+ affinity: ''
+ alias: ''
+ comment: ''
+ states:
+ bus_sink: false
+ bus_source: false
+ bus_structure: null
+ coordinate: [1104, 288.0]
+ rotation: 0
+ state: true
- name: blocks_short_to_float_0
id: blocks_short_to_float
parameters:
@@ -111,7 +142,10 @@ blocks:
scale: '32768'
vlen: '1'
states:
- coordinate: [1008, 220.0]
+ bus_sink: false
+ bus_source: false
+ bus_structure: null
+ coordinate: [1024, 204.0]
rotation: 0
state: enabled
- name: blocks_wavfile_source_0
@@ -126,7 +160,10 @@ blocks:
nchan: '1'
repeat: 'True'
states:
- coordinate: [120, 164.0]
+ bus_sink: false
+ bus_source: false
+ bus_structure: null
+ coordinate: [176, 164.0]
rotation: 0
state: disabled
- name: rational_resampler_xxx_0
@@ -143,7 +180,10 @@ blocks:
taps: ''
type: fff
states:
- coordinate: [232, 276.0]
+ bus_sink: false
+ bus_source: false
+ bus_structure: null
+ coordinate: [200, 276.0]
rotation: 0
state: enabled
- name: vocoder_freedv_rx_ss_0
@@ -159,7 +199,10 @@ blocks:
squelch_enable: 'True'
squelch_thresh: squelch
states:
- coordinate: [816, 196.0]
+ bus_sink: false
+ bus_source: false
+ bus_structure: null
+ coordinate: [808, 196.0]
rotation: 0
state: enabled
- name: vocoder_freedv_tx_ss_0
@@ -176,7 +219,10 @@ blocks:
tx_bpf_val: 'True'
txt_msg: '''GNU Radio'''
states:
- coordinate: [608, 188.0]
+ bus_sink: false
+ bus_source: false
+ bus_structure: null
+ coordinate: [584, 188.0]
rotation: 0
state: enabled
@@ -187,6 +233,7 @@ connections:
- [blocks_wavfile_source_0, '0', blocks_float_to_short_0, '0']
- [rational_resampler_xxx_0, '0', blocks_float_to_short_0, '0']
- [vocoder_freedv_rx_ss_0, '0', blocks_short_to_float_0, '0']
+- [vocoder_freedv_rx_ss_0, text, blocks_message_debug_0, print]
- [vocoder_freedv_tx_ss_0, '0', vocoder_freedv_rx_ss_0, '0']
metadata:
diff --git a/gr-vocoder/grc/vocoder_freedv_rx_ss.block.yml b/gr-vocoder/grc/vocoder_freedv_rx_ss.block.yml
index b1ec5339e..31f88b322 100644
--- a/gr-vocoder/grc/vocoder_freedv_rx_ss.block.yml
+++ b/gr-vocoder/grc/vocoder_freedv_rx_ss.block.yml
@@ -29,6 +29,9 @@ inputs:
outputs:
- domain: stream
dtype: short
+- domain: message
+ id: text
+ optional: true
templates:
imports: |-
diff --git a/gr-vocoder/lib/freedv_rx_ss_impl.cc b/gr-vocoder/lib/freedv_rx_ss_impl.cc
index 03bfdda08..266e2954f 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 23c4e485f..9a5d991f1 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;