Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
marenz2569 committed Sep 21, 2023
1 parent b22d1fd commit 65b8cac
Show file tree
Hide file tree
Showing 5 changed files with 277 additions and 280 deletions.
81 changes: 41 additions & 40 deletions src/correlate_access_code_bb_ts_fl_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ correlate_access_code_bb_ts_fl_impl::correlate_access_code_bb_ts_fl_impl(
io_signature::make(1, 1, sizeof(char))),
d_data_reg(0), d_mask(0), d_threshold(threshold), d_len(0) {
set_tag_propagation_policy(TPP_DONT);
//set_ninput_items_required(len * 8);
set_min_noutput_items(len * 8);
set_output_multiple(len * 8);
// set_ninput_items_required(len * 8);
set_min_noutput_items(len * 8);
set_output_multiple(len * 8);

if (!set_access_code(access_code)) {
GR_LOG_ERROR(d_logger, "access_code is > 64 bits");
Expand All @@ -61,7 +61,7 @@ correlate_access_code_bb_ts_fl_impl::correlate_access_code_bb_ts_fl_impl(
d_me = pmt::string_to_symbol(str.str());
d_key = pmt::string_to_symbol(tag_name);

d_pkt_len = 8 * len;
d_pkt_len = 8 * len;
}

correlate_access_code_bb_ts_fl_impl::~correlate_access_code_bb_ts_fl_impl() {}
Expand Down Expand Up @@ -94,47 +94,48 @@ int correlate_access_code_bb_ts_fl_impl::general_work(
int noutput_items, gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) {

// Streaming correlate access code.
// Streaming correlate access code.
const unsigned char *in = (const unsigned char *)input_items[0];
unsigned char *out = (unsigned char *)output_items[0];

uint64_t abs_out_sample_cnt = nitems_written(0);

int nprod = 0;

// shift in new data
d_data_reg = (d_data_reg << 1) | (in[0] & 0x1);

// compute hamming distance between desired access code and current data
uint64_t wrong_bits = 0;
uint64_t nwrong = d_threshold + 1;

wrong_bits = (d_data_reg ^ d_access_code) & d_mask;
volk_64u_popcnt(&nwrong, wrong_bits);

if (nwrong <= d_threshold) {
if (d_pkt_len > noutput_items) {
GR_LOG_FATAL(d_logger,
boost::format("cannot write tagged stream not enough output_items available"));
return 0;
}

GR_LOG_DEBUG(d_logger,
boost::format("writing tag at sample %llu") %
(abs_out_sample_cnt));
// MAKE A TAG OUT OF THIS AND UPDATE OFFSET
add_item_tag(0, // stream ID
abs_out_sample_cnt, // sample
d_key, // length key
pmt::from_long(d_pkt_len), // length data
d_me); // block src id

for (int j = 0; j < d_pkt_len; j++) {
out[nprod++] = in[j];
}
}

consume_each(1);
int nprod = 0;

// shift in new data
d_data_reg = (d_data_reg << 1) | (in[0] & 0x1);

// compute hamming distance between desired access code and current data
uint64_t wrong_bits = 0;
uint64_t nwrong = d_threshold + 1;

wrong_bits = (d_data_reg ^ d_access_code) & d_mask;
volk_64u_popcnt(&nwrong, wrong_bits);

if (nwrong <= d_threshold) {
if (d_pkt_len > noutput_items) {
GR_LOG_FATAL(
d_logger,
boost::format(
"cannot write tagged stream not enough output_items available"));
return 0;
}

GR_LOG_DEBUG(d_logger, boost::format("writing tag at sample %llu") %
(abs_out_sample_cnt));
// MAKE A TAG OUT OF THIS AND UPDATE OFFSET
add_item_tag(0, // stream ID
abs_out_sample_cnt, // sample
d_key, // length key
pmt::from_long(d_pkt_len), // length data
d_me); // block src id

for (int j = 0; j < d_pkt_len; j++) {
out[nprod++] = in[j];
}
}

consume_each(1);
return nprod;
}

Expand Down
40 changes: 23 additions & 17 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <fstream>
#include <cstdlib>

#include "correlate_access_code_bb_ts_fl.h"
#include "rational_resampler.h"
Expand All @@ -30,7 +30,7 @@
#include <libenvpp/env.hpp>

int main(int argc, char **argv) {
auto pre = env::prefix("DECODER");
auto pre = env::prefix("DECODER");

gr::top_block_sptr tb;

Expand All @@ -53,24 +53,27 @@ int main(int argc, char **argv) {
float samp_rate = 2000000;
float bandwidth_sdr = 1000000;
float bandwidth_xlat = 5000;
float transition_bw = 1000;
float transition_bw = 1000;
int decimation = static_cast<int>(bandwidth_sdr / bandwidth_xlat);
float baud = 2400;
unsigned rs_interpolation = 24;
unsigned rs_decimation = 25;
float sps = samp_rate / decimation / baud * (float) rs_interpolation / (float) rs_decimation;
float sps = samp_rate / decimation / baud * (float)rs_interpolation /
(float)rs_decimation;
int RF, IF, BB;
std::string device_string;

const auto freq_id = pre.register_required_variable<float>("FREQUENCY");
const auto xlat_center_freq_id = pre.register_required_variable<float>("OFFSET");
const auto xlat_center_freq_id =
pre.register_required_variable<float>("OFFSET");
const auto RF_id = pre.register_variable<int>("RF");
const auto IF_id = pre.register_variable<int>("IF");
const auto BB_id = pre.register_variable<int>("BB");
const auto device_string_id = pre.register_variable<std::string>("DEVICE_STRING");

const auto device_string_id =
pre.register_variable<std::string>("DEVICE_STRING");

const auto parsed_and_validated_pre = pre.parse_and_validate();

if (parsed_and_validated_pre.ok()) {
freq = parsed_and_validated_pre.get(freq_id);
xlat_center_freq = parsed_and_validated_pre.get(xlat_center_freq_id);
Expand All @@ -81,7 +84,7 @@ int main(int argc, char **argv) {
} else {
std::cout << parsed_and_validated_pre.warning_message();
std::cout << parsed_and_validated_pre.error_message();

return EXIT_FAILURE;
}

Expand All @@ -90,7 +93,10 @@ int main(int argc, char **argv) {
transition_bw);
gr_vector_float fir1_taps =
gr::filter::firdes::high_pass(1.0, samp_rate / decimation, 100, 50);
gr_vector_float fir2_taps = std::vector<float>({0.002334677756186128, 0.01938096025639799, 0.14012609258404307, 0.25997995536747043, 0.24015818184610402, 0.25997995536747043, 0.14012609258404307, 0.01938096025639799, 0.002334677756186128});
gr_vector_float fir2_taps = std::vector<float>(
{0.002334677756186128, 0.01938096025639799, 0.14012609258404307,
0.25997995536747043, 0.24015818184610402, 0.25997995536747043,
0.14012609258404307, 0.01938096025639799, 0.002334677756186128});

tb = gr::make_top_block("fg");

Expand All @@ -109,19 +115,19 @@ int main(int argc, char **argv) {
xlat = gr::filter::freq_xlating_fir_filter_ccc::make(
decimation, xlat_taps, xlat_center_freq, samp_rate);
resampler = gr::filter::rational_resampler_ccc::make(
rs_interpolation, rs_decimation, std::vector<gr_complex>(), 0.4);
rs_interpolation, rs_decimation, std::vector<gr_complex>(), 0.4);
demod1 = gr::analog::quadrature_demod_cf::make(1.0);
fir1 = gr::filter::fir_filter_fff::make(1, fir1_taps);
hilbert = gr::filter::hilbert_fc::make(65);
demod2 = gr::analog::quadrature_demod_cf::make(4.0);
addConst = gr::blocks::add_const_ff::make(-1.5*M_PI);
addConst = gr::blocks::add_const_ff::make(-1.5 * M_PI);
fir2 = gr::filter::fir_filter_fff::make(1, fir2_taps);
clockRecovery = gr::digital::clock_recovery_mm_ff::make(
sps, 0.25f * 0.175f * 0.175f, 0.5, 0.175, 0.01);
multiplyConst = gr::blocks::multiply_const_ff::make(-1.0f);
slicer = gr::digital::binary_slicer_fb::make();
// set this to 24 to receive all possible telegrams.
// set it to 13 to receive not more data then needed for R09.16
// set this to 24 to receive all possible telegrams.
// set it to 13 to receive not more data then needed for R09.16
correlate = gr::reveng::correlate_access_code_bb_ts_fl::make(
"1111110000000001", 1, "packet_len", 13);
taggedStreamToPdu = gr::blocks::tagged_stream_to_pdu::make(
Expand Down Expand Up @@ -160,7 +166,7 @@ int main(int argc, char **argv) {

tb->start();

tb->wait();
tb->wait();

return EXIT_SUCCESS;
}
49 changes: 25 additions & 24 deletions src/rational_resampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <gnuradio/block.h>
#include <gnuradio/filter/api.h>


namespace gr {
namespace filter {

Expand Down Expand Up @@ -55,36 +54,38 @@ namespace filter {
* prefilter.
*/
template <class IN_T, class OUT_T, class TAP_T>
class FILTER_API rational_resampler : virtual public block
{
class FILTER_API rational_resampler : virtual public block {
public:
typedef boost::shared_ptr<rational_resampler<IN_T, OUT_T, TAP_T>> sptr;
typedef boost::shared_ptr<rational_resampler<IN_T, OUT_T, TAP_T>> sptr;

/*!
* Make a rational resampling FIR filter.
*
* \param interpolation The integer interpolation rate of the filter
* \param decimation The integer decimation rate of the filter
* \param taps The filter taps to control images and aliases
* \param fractional_bw The fractional bandwidth of the filter (0 to 0.5)
*/
static sptr make(unsigned interpolation,
unsigned decimation,
const std::vector<TAP_T>& taps = std::vector<TAP_T>(),
float fractional_bw = 0.0);
/*!
* Make a rational resampling FIR filter.
*
* \param interpolation The integer interpolation rate of the filter
* \param decimation The integer decimation rate of the filter
* \param taps The filter taps to control images and aliases
* \param fractional_bw The fractional bandwidth of the filter (0 to 0.5)
*/
static sptr make(unsigned interpolation, unsigned decimation,
const std::vector<TAP_T> &taps = std::vector<TAP_T>(),
float fractional_bw = 0.0);

virtual unsigned interpolation() const = 0;
virtual unsigned decimation() const = 0;
virtual unsigned interpolation() const = 0;
virtual unsigned decimation() const = 0;

virtual void set_taps(const std::vector<TAP_T>& taps) = 0;
virtual std::vector<TAP_T> taps() const = 0;
virtual void set_taps(const std::vector<TAP_T> &taps) = 0;
virtual std::vector<TAP_T> taps() const = 0;
};
typedef rational_resampler<gr_complex, gr_complex, gr_complex> rational_resampler_ccc;
typedef rational_resampler<gr_complex, gr_complex, float> rational_resampler_ccf;
typedef rational_resampler<float, gr_complex, gr_complex> rational_resampler_fcc;
typedef rational_resampler<gr_complex, gr_complex, gr_complex>
rational_resampler_ccc;
typedef rational_resampler<gr_complex, gr_complex, float>
rational_resampler_ccf;
typedef rational_resampler<float, gr_complex, gr_complex>
rational_resampler_fcc;
typedef rational_resampler<float, float, float> rational_resampler_fff;
typedef rational_resampler<float, std::int16_t, float> rational_resampler_fsf;
typedef rational_resampler<std::int16_t, gr_complex, gr_complex> rational_resampler_scc;
typedef rational_resampler<std::int16_t, gr_complex, gr_complex>
rational_resampler_scc;

} /* namespace filter */
} /* namespace gr */
Expand Down
Loading

0 comments on commit 65b8cac

Please sign in to comment.