GNU Radio's SATELLITES Package
doppler_correction_impl.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2022-2023,2025 Daniel Estevez <daniel@destevez.net>.
4 *
5 * This file is part of gr-satellites
6 *
7 * SPDX-License-Identifier: GPL-3.0-or-later
8 */
9
10#ifndef INCLUDED_SATELLITES_DOPPLER_CORRECTION_IMPL_H
11#define INCLUDED_SATELLITES_DOPPLER_CORRECTION_IMPL_H
12
13#include <gnuradio/math.h>
15#include <cstdint>
16#include <vector>
17
18namespace gr {
19namespace satellites {
20
22{
23private:
24 double d_phase;
25 double d_samp_rate;
26 size_t d_current_index;
27 double d_t0;
28 uint64_t d_sample_t0;
29 std::vector<double> times;
30 std::vector<double> freqs_rad_per_sample;
31 std::vector<tag_t> d_tags;
32
33 // Used by UHD
34 const pmt::pmt_t d_rx_time_key;
35
36 // Used by gr-difi
37 const pmt::pmt_t d_pck_n_key;
38 const pmt::pmt_t d_full_key;
39 const pmt::pmt_t d_frac_key;
40
41 // timesync tag
42 const bool d_timesync_enabled;
43 const pmt::pmt_t d_timesync_key;
44
45 double d_current_time;
46 double d_current_freq;
47
48 // Implementation taken from gr::block::control_loop
49 void phase_wrap()
50 {
51 while (d_phase > (2 * GR_M_PI))
52 d_phase -= 2 * GR_M_PI;
53 while (d_phase < (-2 * GR_M_PI))
54 d_phase += 2 * GR_M_PI;
55 }
56
57 // Called after a time update. Makes the current index go backwards if
58 // needed because of a time update "to the past".
59 void adjust_current_index()
60 {
61 while ((d_current_index > 0) && (times[d_current_index] > d_t0)) {
62 --d_current_index;
63 }
64 }
65
66 void read_doppler_file(const std::string& filename);
67
68public:
69 doppler_correction_impl(const std::string& filename,
70 double samp_rate,
71 double t0,
72 const std::string& timesync_tag);
74
75 void set_time(double) override;
76
77 double time() override
78 {
79 gr::thread::scoped_lock guard(d_setlock);
80 return d_current_time;
81 }
82
83 double frequency() override
84 {
85 gr::thread::scoped_lock guard(d_setlock);
86 return d_current_freq * d_samp_rate / (2.0 * GR_M_PI);
87 }
88
89 int work(int noutput_items,
90 gr_vector_const_void_star& input_items,
91 gr_vector_void_star& output_items) override;
92};
93
94} // namespace satellites
95} // namespace gr
96
97#endif /* INCLUDED_SATELLITES_DOPPLER_CORRECTION_IMPL_H */
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) override
double frequency() override
Returns the current frequency in Hz.
Definition doppler_correction_impl.h:83
void set_time(double) override
Sets the current time.
double time() override
Returns the current time.
Definition doppler_correction_impl.h:77
doppler_correction_impl(const std::string &filename, double samp_rate, double t0, const std::string &timesync_tag)
Performs Doppler correction using a frequency vs. time file.
Definition doppler_correction.h:53
Definition ax100_decode.h:18
Definition ax100_decode.h:17