Skip to content

Commit

Permalink
why shouldn't we collect Power from pwr_squelch_cc()? 🤔
Browse files Browse the repository at this point in the history
  • Loading branch information
robotastic committed Feb 20, 2024
1 parent 761ff94 commit 62f6322
Show file tree
Hide file tree
Showing 20 changed files with 445 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ list(APPEND trunk_recorder_sources
trunk-recorder/gr_blocks/decoder_wrapper_impl.cc
trunk-recorder/gr_blocks/plugin_wrapper_impl.cc
trunk-recorder/gr_blocks/selector_impl.cc
trunk-recorder/gr_blocks/pwr_squelch_cc_impl.cc
trunk-recorder/gr_blocks/squelch_base_cc_impl.cc
trunk-recorder/gr_blocks/wavfile_gr3.8.cc
trunk-recorder/gr_blocks/rms_agc.cc
trunk-recorder/gr_blocks/channelizer.cc
Expand Down
2 changes: 1 addition & 1 deletion trunk-recorder/call_conventional.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void Call_conventional::restart_call() {
emergency = false;
this->update_talkgroup_display();
recorder->start(this);
recroder->set_rssi(0);
recorder->set_rssi(0);
}

time_t Call_conventional::get_start_time() {
Expand Down
8 changes: 8 additions & 0 deletions trunk-recorder/gr_blocks/channelizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ void channelizer::set_squelch_db(double squelch_db) {
squelch->set_threshold(squelch_db);
}

double channelizer::get_pwr() {
if (d_conventional) {
return squelch->get_pwr();
} else {
return 0;
}
}

void channelizer::set_analog_squelch(bool analog_squelch) {
if (analog_squelch) {
squelch->set_alpha(0.01);
Expand Down
5 changes: 3 additions & 2 deletions trunk-recorder/gr_blocks/channelizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <boost/log/trivial.hpp>
#include <iomanip>

#include "../gr_blocks/rms_agc.h"
#include <gnuradio/analog/pwr_squelch_cc.h>
#include "./rms_agc.h"
#include "./pwr_squelch_cc.h"
#include <gnuradio/blocks/copy.h>
#include <gnuradio/digital/fll_band_edge_cc.h>
#include <gnuradio/filter/fft_filter_ccc.h>
Expand Down Expand Up @@ -90,6 +90,7 @@ class channelizer : public gr::hier_block2 {
int get_freq_error();
bool is_enabled();
bool is_squelched();
double get_pwr();
void tune_offset(double f);
void set_samples_per_symbol(int samples_per_symbol);
void set_enabled(bool enabled);
Expand Down
68 changes: 68 additions & 0 deletions trunk-recorder/gr_blocks/pwr_squelch_cc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* -*- c++ -*- */
/*
* Copyright 2006,2012 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/

#ifndef INCLUDED_ANALOG_PWR_SQUELCH_CC_H
#define INCLUDED_ANALOG_PWR_SQUELCH_CC_H

#include <gnuradio/analog/api.h>
#include <gnuradio/analog/squelch_base_cc.h>
#include <cmath>

namespace gr {
namespace analog {

/*!
* \brief gate or zero output when input power below threshold
* \ingroup level_controllers_blk
*/
class ANALOG_API pwr_squelch_cc : public squelch_base_cc, virtual public block
{
protected:
void update_state(const gr_complex& in) override = 0;
bool mute() const override = 0;

public:
// gr::analog::pwr_squelch_cc::sptr
typedef std::shared_ptr<pwr_squelch_cc> sptr;

/*!
* \brief Make power-based squelch block.
*
* \param db threshold (in dB) for power squelch
* \param alpha Gain of averaging filter. Defaults to 0.0001.
* \param ramp attack / release time in samples; a sinusodial ramp
* is used. set to 0 to disable.
* \param gate if true, no output if no squelch tone.
* if false, output 0's if no squelch tone (default).
*
* The block will emit a tag with the key pmt::intern("squelch_sob")
* with the value of pmt::PMT_NIL on the first item it passes, and with
* the key pmt::intern("squelch_eob") on the last item it passes.
*/
static sptr make(double db, double alpha = 0.0001, int ramp = 0, bool gate = false);

std::vector<float> squelch_range() const override = 0;

virtual double threshold() const = 0;
virtual double get_pwr() const = 0;
virtual void set_threshold(double db) = 0;
virtual void set_alpha(double alpha) = 0;

int ramp() const override = 0;
void set_ramp(int ramp) override = 0;
bool gate() const override = 0;
void set_gate(bool gate) override = 0;
bool unmuted() const override = 0;
};

} /* namespace analog */
} /* namespace gr */

#endif /* INCLUDED_ANALOG_PWR_SQUELCH_CC_H */
75 changes: 75 additions & 0 deletions trunk-recorder/gr_blocks/pwr_squelch_cc_impl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* -*- c++ -*- */
/*
* Copyright 2004,2006,2010,2012 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "pwr_squelch_cc_impl.h"

namespace gr {
namespace analog {

pwr_squelch_cc::sptr
pwr_squelch_cc::make(double threshold, double alpha, int ramp, bool gate)
{
return gnuradio::make_block_sptr<pwr_squelch_cc_impl>(threshold, alpha, ramp, gate);
}

pwr_squelch_cc_impl::pwr_squelch_cc_impl(double threshold,
double alpha,
int ramp,
bool gate)
: block("pwr_squelch_cc",
io_signature::make(1, 1, sizeof(gr_complex)),
io_signature::make(1, 1, sizeof(gr_complex))),
squelch_base_cc_impl("pwr_squelch_cc", ramp, gate),
d_pwr(0),
d_iir(alpha)
{
set_threshold(threshold);
}

pwr_squelch_cc_impl::~pwr_squelch_cc_impl() {}

std::vector<float> pwr_squelch_cc_impl::squelch_range() const
{
std::vector<float> r(3);
r[0] = -50.0; // min FIXME
r[1] = +50.0; // max FIXME
r[2] = (r[1] - r[0]) / 100; // step size

return r;
}

void pwr_squelch_cc_impl::update_state(const gr_complex& in)
{
d_pwr = d_iir.filter(in.real() * in.real() + in.imag() * in.imag());
}

double pwr_squelch_cc_impl::get_pwr()
{
double db = 10 * std::log10(d_pwr);
return db;
}
void pwr_squelch_cc_impl::set_threshold(double db)
{
gr::thread::scoped_lock l(d_setlock);
d_threshold = std::pow(10.0, db / 10);
}

void pwr_squelch_cc_impl::set_alpha(double alpha)
{
gr::thread::scoped_lock l(d_setlock);
d_iir.set_taps(alpha);
}

} /* namespace analog */
} /* namespace gr */
66 changes: 66 additions & 0 deletions trunk-recorder/gr_blocks/pwr_squelch_cc_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* -*- c++ -*- */
/*
* Copyright 2006,2012 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/

#ifndef INCLUDED_ANALOG_PWR_SQUELCH_CC_IMPL_H
#define INCLUDED_ANALOG_PWR_SQUELCH_CC_IMPL_H

#include "squelch_base_cc_impl.h"
#include <gnuradio/analog/pwr_squelch_cc.h>
#include <gnuradio/filter/single_pole_iir.h>
#include <cmath>

namespace gr {
namespace analog {

class ANALOG_API pwr_squelch_cc_impl : public pwr_squelch_cc, squelch_base_cc_impl
{
private:
double d_threshold;
double d_pwr;
filter::single_pole_iir<double, double, double> d_iir;

protected:
void update_state(const gr_complex& in) override;
bool mute() const override { return d_pwr < d_threshold; }

public:
pwr_squelch_cc_impl(double db,
double alpha = 0.0001,
int ramp = 0,
bool gate = false);
~pwr_squelch_cc_impl() override;

std::vector<float> squelch_range() const override;

double threshold() const override { return 10 * log10(d_threshold); }
void set_threshold(double db) override;
double get_pwr() ;
void set_alpha(double alpha) override;

int ramp() const override { return squelch_base_cc_impl::ramp(); }
void set_ramp(int ramp) override { squelch_base_cc_impl::set_ramp(ramp); }
bool gate() const override { return squelch_base_cc_impl::gate(); }
void set_gate(bool gate) override { squelch_base_cc_impl::set_gate(gate); }
bool unmuted() const override { return squelch_base_cc_impl::unmuted(); }

int general_work(int noutput_items,
gr_vector_int& ninput_items,
gr_vector_const_void_star& input_items,
gr_vector_void_star& output_items) override
{
return squelch_base_cc_impl::general_work(
noutput_items, ninput_items, input_items, output_items);
}
};

} /* namespace analog */
} /* namespace gr */

#endif /* INCLUDED_ANALOG_PWR_SQUELCH_CC_IMPL_H */
Loading

0 comments on commit 62f6322

Please sign in to comment.