summaryrefslogtreecommitdiff
path: root/gr-blocks/lib/correctiq_auto_impl.h
blob: 4a9f7105e1846ece071f5282a76dd99b94d9aa9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* -*- c++ -*- */
/*
 * Copyright 2020 Free Software Foundation, Inc.
 *
 * This file is part of GNU Radio
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 */

#ifndef INCLUDED_CORRECTIQ_CORRECTIQ_AUTO_IMPL_H
#define INCLUDED_CORRECTIQ_CORRECTIQ_AUTO_IMPL_H

#include <gnuradio/blocks/correctiq_auto.h>
#include <volk/volk_alloc.hh>

namespace gr {
namespace blocks {

class correctiq_auto_impl : public correctiq_auto
{
private:
    float d_avg_real{ 0.0 };
    float d_avg_img{ 0.0 };
    float d_ratio{ 1e-05f };
    gr_complex d_k{ 0, 0 };

    const double d_samp_rate;
    double d_freq;
    float d_gain;
    const float d_sync_window;

    long d_sync_counter{ 0 };
    bool d_synchronized{ false };

    const long d_max_sync_samples;

    void send_sync_values();
    void send_syncing();

    void trigger_resync(std::string reason);

    volk::vector<gr_complex> d_volk_const_buffer;

    void set_const_buffer(int new_size);
    void fill_const_buffer();

public:
    correctiq_auto_impl(double samp_rate, double freq, float gain, float sync_window);
    ~correctiq_auto_impl();

    double get_freq() const override;
    float get_gain() const override;

    void set_freq(double new_value) override;
    void set_gain(float new_value) override;

    void handle_resync(pmt::pmt_t msg);

    int work(int noutput_items,
             gr_vector_const_void_star& input_items,
             gr_vector_void_star& output_items);
};

} // namespace blocks
} // namespace gr

#endif /* INCLUDED_CORRECTIQ_CORRECTIQ_AUTO_IMPL_H */