Add various setters at the Morse decoding related blocks

New setters (frequency, thresholds) accessible from both GRC callbacks
and async messages.
This commit is contained in:
Manolis Surligas 2016-02-17 03:16:18 +02:00
parent 27c597a874
commit 67eb17908e
9 changed files with 198 additions and 47 deletions

View File

@ -81,6 +81,69 @@
<value></value>
</param>
</block>
<block>
<key>variable_qtgui_range</key>
<param>
<key>comment</key>
<value></value>
</param>
<param>
<key>value</key>
<value>20e3</value>
</param>
<param>
<key>_enabled</key>
<value>True</value>
</param>
<param>
<key>_coordinate</key>
<value>(416, 10)</value>
</param>
<param>
<key>gui_hint</key>
<value></value>
</param>
<param>
<key>_rotation</key>
<value>180</value>
</param>
<param>
<key>id</key>
<value>act_thrld</value>
</param>
<param>
<key>label</key>
<value>Activation</value>
</param>
<param>
<key>min_len</key>
<value>200</value>
</param>
<param>
<key>orient</key>
<value>Qt.Horizontal</value>
</param>
<param>
<key>start</key>
<value>10e3</value>
</param>
<param>
<key>step</key>
<value>100</value>
</param>
<param>
<key>stop</key>
<value>80e3</value>
</param>
<param>
<key>rangeType</key>
<value>float</value>
</param>
<param>
<key>widget</key>
<value>counter_slider</value>
</param>
</block>
<block>
<key>variable_qtgui_range</key>
<param>
@ -97,7 +160,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(184, 9)</value>
<value>(168, 10)</value>
</param>
<param>
<key>gui_hint</key>
@ -187,7 +250,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(328, 9)</value>
<value>(296, 10)</value>
</param>
<param>
<key>gui_hint</key>
@ -1591,7 +1654,7 @@ of a full period of the CW signal with frequency freq.</value>
<key>satnogs_cw_to_symbol</key>
<param>
<key>threshold</key>
<value>20e3</value>
<value>act_thrld</value>
</param>
<param>
<key>alias</key>

View File

@ -4,9 +4,9 @@
<key>satnogs_cw_matched_filter_ff</key>
<category>satnogs</category>
<import>import satnogs</import>
<make>satnogs.cw_matched_filter_ff($sampling_rate, $carrier_freq, $wpm, $energy)
</make>
<make>satnogs.cw_matched_filter_ff($sampling_rate, $carrier_freq, $wpm, $energy)</make>
<callback>set_new_freq_locked($carrier_freq)</callback>
<param>
<name>Sampling Rate</name>
<key>sampling_rate</key>
@ -39,6 +39,12 @@
<key>True</key>
</option>
</param>
<sink>
<name>freq</name>
<type>message</type>
<optional>1</optional>
</sink>
<sink>
<name>in</name>

View File

@ -5,7 +5,8 @@
<category>satnogs</category>
<import>import satnogs</import>
<make>satnogs.cw_to_symbol($sampling_rate, $threshold, $conf_level, $wpm)</make>
<callback>set_act_threshold($threshold)</callback>
<param>
<name>Sampling Rate</name>
<key>sampling_rate</key>
@ -33,6 +34,12 @@
<type>int</type>
</param>
<sink>
<name>act_threshold</name>
<type>message</type>
<optional>1</optional>
</sink>
<sink>
<name>in</name>
<type>float</type>

View File

@ -53,6 +53,9 @@ namespace gr {
static sptr make(double sampling_rate, double carrier_freq = 500,
size_t wpm = 20,
bool energy_out = false);
virtual void set_new_freq_locked(double freq) = 0;
virtual void set_new_freq(double freq) = 0;
};
} // namespace satnogs

View File

@ -60,6 +60,8 @@ namespace gr {
*/
static sptr make(double sampling_rate, float threshold,
float conf_level = 0.9, size_t wpm = 20);
virtual void set_act_threshold(float thrld) = 0;
};
} // namespace satnogs

View File

@ -50,6 +50,7 @@ namespace gr {
gr::sync_block ("cw_matched_filter_ff",
gr::io_signature::make (1, 1, sizeof(float)),
gr::io_signature::make (1, 1, sizeof(float))),
d_samp_rate(sampling_rate),
d_dot_duration(1.2/wpm),
d_produce_enrg(energy_out),
d_dot_samples(d_dot_duration / (1.0 / sampling_rate))
@ -63,6 +64,12 @@ namespace gr {
throw std::runtime_error("Could not allocate sine wave buffer");
}
/* Register the input port for frequency change messages */
message_port_register_in(pmt::mp("freq"));
set_msg_handler(pmt::mp("freq"),
boost::bind(&cw_matched_filter_ff_impl::new_freq_msg_handler,
this, _1));
/* Now fill the buffer with the appropriate sine wave */
gr::fxpt_nco nco;
nco.set_freq(2 * M_PI * carrier_freq / sampling_rate);
@ -77,23 +84,46 @@ namespace gr {
volk_free(d_sin_wave);
}
int
cw_matched_filter_ff_impl::work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
void
cw_matched_filter_ff_impl::new_freq_msg_handler (pmt::pmt_t msg)
{
const float *in = (const float *) input_items[0];
float *out = (float *) output_items[0];
if(pmt::is_pair(msg)){
set_new_freq(pmt::to_double(pmt::cdr(msg)));
}
}
for(int i = 0; i < noutput_items; i++ ){
volk_32f_x2_dot_prod_32f(out + i, in + i, d_sin_wave,
d_dot_samples);
}
if(d_produce_enrg){
volk_32f_s32f_power_32f(out, out, 2, noutput_items);
}
int
cw_matched_filter_ff_impl::work (int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
boost::mutex::scoped_lock lock (d_mutex);
const float *in = (const float *) input_items[0];
float *out = (float *) output_items[0];
return noutput_items;
for (int i = 0; i < noutput_items; i++) {
volk_32f_x2_dot_prod_32f (out + i, in + i, d_sin_wave, d_dot_samples);
}
if (d_produce_enrg) {
volk_32f_s32f_power_32f (out, out, 2, noutput_items);
}
return noutput_items;
}
void
cw_matched_filter_ff_impl::set_new_freq (double freq)
{
gr::fxpt_nco nco;
nco.set_freq(2 * M_PI * freq / d_samp_rate);
nco.sin(d_sin_wave, d_dot_samples, 1.0);
}
void
cw_matched_filter_ff_impl::set_new_freq_locked(double freq)
{
boost::mutex::scoped_lock lock(d_mutex);
set_new_freq(freq);
}
} /* namespace satnogs */

View File

@ -22,39 +22,57 @@
#define INCLUDED_SATNOGS_CW_MATCHED_FILTER_FF_IMPL_H
#include <satnogs/cw_matched_filter_ff.h>
#include <boost/thread/mutex.hpp>
namespace gr {
namespace satnogs {
namespace gr
{
namespace satnogs
{
class cw_matched_filter_ff_impl : public cw_matched_filter_ff
{
private:
/**
* The duration of the dot in seconds
*/
const double d_dot_duration;
/**
* If set to true, this block produces the energy of the filtered
* samples, rather the samples themselves
*/
const bool d_produce_enrg;
/**
* The duration of the dot in number of samples
*/
const size_t d_dot_samples;
private:
/**
* The sampling rate of the signal
*/
const double d_samp_rate;
float *d_sin_wave;
/**
* The duration of the dot in seconds
*/
const double d_dot_duration;
/**
* If set to true, this block produces the energy of the filtered
* samples, rather the samples themselves
*/
const bool d_produce_enrg;
/**
* The duration of the dot in number of samples
*/
const size_t d_dot_samples;
public:
cw_matched_filter_ff_impl(double sampling_rate, double carrier_freq,
size_t wpm, bool energy_out);
~cw_matched_filter_ff_impl();
float *d_sin_wave;
boost::mutex d_mutex;
void
new_freq_msg_handler(pmt::pmt_t msg);
public:
cw_matched_filter_ff_impl (double sampling_rate, double carrier_freq,
size_t wpm, bool energy_out);
~cw_matched_filter_ff_impl ();
// Where all the action really happens
int work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
int
work (int noutput_items, gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
void
set_new_freq(double freq);
void
set_new_freq_locked(double freq);
};
} // namespace satnogs

View File

@ -59,7 +59,11 @@ namespace gr
d_pause_cnt(0),
d_seq_started(false)
{
message_port_register_in(pmt::mp("act_threshold"));
message_port_register_out(pmt::mp("out"));
set_msg_handler(pmt::mp("act_threshold"),
boost::bind(&cw_to_symbol_impl::set_act_threshold_msg_handler,
this, _1));
}
inline void
@ -111,6 +115,14 @@ namespace gr
d_state = LONG_OFF_PERIOD;
}
void
cw_to_symbol_impl::set_act_threshold_msg_handler (pmt::pmt_t msg)
{
if(pmt::is_pair(msg)){
set_act_threshold(pmt::to_float(pmt::cdr(msg)));
}
}
int
cw_to_symbol_impl::work (int noutput_items,
gr_vector_const_void_star &input_items,
@ -236,6 +248,12 @@ namespace gr
return noutput_items;
}
void
cw_to_symbol_impl::set_act_threshold (float thrhld)
{
d_act_thrshld = thrhld;
}
} /* namespace satnogs */
} /* namespace gr */

View File

@ -40,7 +40,7 @@ namespace gr
} cw_state_t;
private:
const double d_sampling_rate;
const float d_act_thrshld;
float d_act_thrshld;
const float d_confidence_level;
const size_t d_dot_samples;
const size_t d_dash_samples;
@ -69,6 +69,8 @@ namespace gr
inline void
send_symbol_msg (morse_symbol_t s);
void set_act_threshold_msg_handler(pmt::pmt_t msg);
public:
cw_to_symbol_impl (double sampling_rate, float threshold,
float conf_level, size_t wpm);
@ -78,6 +80,8 @@ namespace gr
int
work (int noutput_items, gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
void set_act_threshold(float thrhld);
};
} // namespace satnogs