New blocks (msg to tag and controlled resampler) related stuff
This commit is contained in:
parent
24db07572f
commit
74c4f2c14c
|
@ -59,6 +59,7 @@
|
|||
<block>gsm_extract_immediate_assignment</block>
|
||||
<block>gsm_controlled_rotator_cc</block>
|
||||
<block>gsm_controlled_const_source_f</block>
|
||||
<block>gsm_controlled_fractional_resampler_cc</block>
|
||||
<block>gsm_message_printer</block>
|
||||
<block>gsm_clock_offset_corrector</block>
|
||||
<block>gsm_tmsi_dumper</block>
|
||||
|
|
|
@ -29,5 +29,7 @@ install(FILES
|
|||
gsm_burst_file_sink.xml
|
||||
gsm_burst_file_source.xml
|
||||
gsm_message_file_sink.xml
|
||||
gsm_message_file_source.xml DESTINATION share/gnuradio/grc/blocks
|
||||
gsm_message_file_source.xml
|
||||
gsm_msg_to_tag.xml
|
||||
gsm_controlled_fractional_resampler_cc.xml DESTINATION share/gnuradio/grc/blocks
|
||||
)
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
<sink>
|
||||
<name>phase_inc</name>
|
||||
<type>float</type>
|
||||
<optional>1</optional>
|
||||
</sink>
|
||||
|
||||
<source>
|
||||
|
|
|
@ -24,7 +24,8 @@ install(FILES
|
|||
plotting.hpp
|
||||
api.h
|
||||
gsmtap.h
|
||||
msg_to_tag.h DESTINATION include/grgsm
|
||||
msg_to_tag.h
|
||||
controlled_fractional_resampler_cc.h DESTINATION include/grgsm
|
||||
)
|
||||
|
||||
add_subdirectory(decoding)
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include <gnuradio/sync_block.h>
|
||||
|
||||
namespace gr {
|
||||
namespace grgsm {
|
||||
namespace gsm {
|
||||
|
||||
/*!
|
||||
* \brief <+description of block+>
|
||||
|
@ -39,7 +39,6 @@ namespace gr {
|
|||
{
|
||||
public:
|
||||
typedef boost::shared_ptr<msg_to_tag> sptr;
|
||||
|
||||
/*!
|
||||
* \brief Return a shared_ptr to a new instance of grgsm::msg_to_tag.
|
||||
*
|
||||
|
|
|
@ -31,9 +31,6 @@ list(APPEND grgsm_sources
|
|||
receiver/sch.c
|
||||
receiver/clock_offset_control_impl.cc
|
||||
receiver/cx_channel_hopper_impl.cc
|
||||
misc_utils/bursts_printer_impl.cc
|
||||
misc_utils/extract_system_info_impl.cc
|
||||
misc_utils/extract_immediate_assignment_impl.cc
|
||||
demapping/universal_ctrl_chans_demapper_impl.cc
|
||||
demapping/tch_f_chans_demapper_impl.cc
|
||||
decoding/control_channels_decoder_impl.cc
|
||||
|
@ -54,18 +51,22 @@ list(APPEND grgsm_sources
|
|||
flow_control/dummy_burst_filter_impl.cc
|
||||
misc_utils/controlled_rotator_cc_impl.cc
|
||||
misc_utils/controlled_const_source_f_impl.cc
|
||||
misc_utils/controlled_fractional_resampler_cc_impl.cc
|
||||
misc_utils/msg_to_tag_impl.cc
|
||||
misc_utils/message_printer_impl.cc
|
||||
misc_utils/tmsi_dumper_impl.cc
|
||||
misc_utils/burst_file_sink_impl.cc
|
||||
misc_utils/burst_file_source_impl.cc
|
||||
misc_utils/message_file_sink_impl.cc
|
||||
misc_utils/message_file_source_impl.cc
|
||||
misc_utils/message_file_source_impl.cc
|
||||
misc_utils/bursts_printer_impl.cc
|
||||
misc_utils/extract_system_info_impl.cc
|
||||
misc_utils/extract_immediate_assignment_impl.cc
|
||||
qa_utils/burst_sink_impl.cc
|
||||
qa_utils/burst_source_impl.cc
|
||||
qa_utils/message_source_impl.cc
|
||||
qa_utils/message_sink_impl.cc
|
||||
decryption/decryption_impl.cc
|
||||
msg_to_tag_impl.cc
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -87,32 +87,65 @@ namespace gr {
|
|||
std::vector<tag_t> set_resamp_ratio_tags;
|
||||
|
||||
pmt::pmt_t key = pmt::string_to_symbol("set_resamp_ratio");
|
||||
get_tags_in_window(set_resamp_ratio_tags, 0, 0, noutput_items, key);
|
||||
get_tags_in_window(set_resamp_ratio_tags, 0, 0, ninput_items[0]);
|
||||
|
||||
std::cout << "-----------------------------" << std::endl;
|
||||
// std::cout << "-----------------------------" << std::endl;
|
||||
// std::cout << "ninput_items[0] " << ninput_items[0] << std::endl;
|
||||
// std::cout << "noutput_items " << noutput_items << std::endl;
|
||||
|
||||
bool all_output_samples_produced = false;
|
||||
for(std::vector<tag_t>::iterator i_tag = set_resamp_ratio_tags.begin(); i_tag < set_resamp_ratio_tags.end(); i_tag++)
|
||||
{
|
||||
uint64_t tag_offset_rel = i_tag->offset-nitems_read(0);
|
||||
uint64_t samples_to_produce = (tag_offset_rel-processed_in_sum)/d_mu_inc; //tu może być problem
|
||||
std::cout << "samples_to_produce = (tag_offset_rel-processed_in_sum)/d_mu_inc: " << samples_to_produce << " = " << tag_offset_rel << " - " << processed_in_sum << std::endl;
|
||||
processed_in = resample(in, processed_in_sum, out, produced_out_sum, samples_to_produce);
|
||||
processed_in_sum = processed_in_sum + processed_in;
|
||||
produced_out_sum = produced_out_sum + samples_to_produce;
|
||||
std::cout << "processed_in: " << processed_in << " tag_offset_rel: " << tag_offset_rel << " produced_out_sum: " << produced_out_sum << std::endl;
|
||||
set_resamp_ratio(pmt::to_double(i_tag->value));
|
||||
uint64_t tag_offset_rel = i_tag->offset - nitems_read(0);
|
||||
|
||||
if(pmt::symbol_to_string(i_tag->key) == "set_resamp_ratio")
|
||||
{
|
||||
uint64_t samples_to_produce = static_cast<uint64_t>(round(static_cast<double>(tag_offset_rel-processed_in_sum)/d_mu_inc)); //tu może być problem - bo to jest głupota przy d_mu_inc różnym od 1.0
|
||||
|
||||
if( (samples_to_produce + produced_out_sum) > noutput_items)
|
||||
{
|
||||
samples_to_produce = noutput_items - produced_out_sum;
|
||||
all_output_samples_produced = true;
|
||||
}
|
||||
|
||||
// std::cout << "samples_to_produce = (tag_offset_rel-processed_in_sum)/d_mu_inc: " << samples_to_produce << " = " << tag_offset_rel << " - " << processed_in_sum << std::endl;
|
||||
processed_in = resample(in, processed_in_sum, out, produced_out_sum, samples_to_produce);
|
||||
processed_in_sum = processed_in_sum + processed_in;
|
||||
produced_out_sum = produced_out_sum + samples_to_produce;
|
||||
|
||||
// std::cout << "d_ii " << d_ii << std::endl;
|
||||
// std::cout << "produced_out_sum + nitems_written(0) " << produced_out_sum + nitems_written(0) << std::endl;
|
||||
if(all_output_samples_produced)
|
||||
{
|
||||
break;
|
||||
} else {
|
||||
add_item_tag(0, produced_out_sum + nitems_written(0), i_tag->key, i_tag->value);
|
||||
set_resamp_ratio(pmt::to_double(i_tag->value));
|
||||
}
|
||||
} else {
|
||||
uint64_t out_samples_to_tag = round(static_cast<double>(tag_offset_rel-processed_in_sum)/d_mu_inc);
|
||||
if( (out_samples_to_tag + produced_out_sum) <= noutput_items)
|
||||
{
|
||||
add_item_tag(0, produced_out_sum + out_samples_to_tag + nitems_written(0), i_tag->key, i_tag->value);
|
||||
}
|
||||
}
|
||||
// std::cout << "processed_in: " << processed_in << " tag_offset_rel: " << tag_offset_rel << " produced_out_sum: " << produced_out_sum << std::endl;
|
||||
// std::cout << "Setting resamp ratio: " << d_mu_inc << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "noutput_items: " << noutput_items << " produced_out_sum: " << produced_out_sum << std::endl;
|
||||
std::cout << "last_resample_outputs: " << (noutput_items-produced_out_sum) << std::endl;
|
||||
// std::cout << "noutput_items: " << noutput_items << " produced_out_sum: " << produced_out_sum << std::endl;
|
||||
// std::cout << "last_resample_outputs: " << (noutput_items-produced_out_sum) << std::endl;
|
||||
// processed_in = resample(in, processed_in_sum, out, produced_out_sum, samples_to_produce);
|
||||
// processed_in_sum = processed_in_sum + processed_in;
|
||||
// produced_out_sum = produced_out_sum + samples_to_produce;
|
||||
|
||||
processed_in = resample(in, processed_in_sum, out, produced_out_sum, (noutput_items-produced_out_sum));
|
||||
// processed_in = resample(in, 0, out, 0, noutput_items);
|
||||
processed_in_sum = processed_in_sum + processed_in;
|
||||
|
||||
if(!all_output_samples_produced)
|
||||
{
|
||||
processed_in = resample(in, processed_in_sum, out, produced_out_sum, (noutput_items-produced_out_sum));
|
||||
processed_in_sum = processed_in_sum + processed_in;
|
||||
}
|
||||
|
||||
consume_each(processed_in_sum);
|
||||
return noutput_items;
|
||||
}
|
|
@ -38,7 +38,7 @@ namespace gr {
|
|||
float d_mu;
|
||||
float d_mu_inc;
|
||||
mmse_fir_interpolator_cc *d_resamp;
|
||||
|
||||
|
||||
inline uint64_t resample(const gr_complex *in,
|
||||
uint64_t first_in_sample,
|
||||
gr_complex *out,
|
|
@ -74,10 +74,8 @@ namespace gr {
|
|||
controlled_rotator_cc_impl::work(int noutput_items,
|
||||
gr_vector_const_void_star &input_items,
|
||||
gr_vector_void_star &output_items)
|
||||
{
|
||||
const gr_complex *in = (const gr_complex *)input_items[0];
|
||||
gr_complex *out = (gr_complex *)output_items[0];
|
||||
|
||||
{
|
||||
//process phase_inc input
|
||||
if(input_items.size() == 2) {
|
||||
int ii=0;
|
||||
const float *pp = (const float *)input_items[1];
|
||||
|
@ -101,10 +99,38 @@ namespace gr {
|
|||
ii++;
|
||||
}
|
||||
}
|
||||
d_r.rotateN(out, const_cast<gr_complex *>(in), noutput_items); //const_cast<gr_complex *> is workaround old implementation of rotateN that is still present in ubuntu 14.04 packages
|
||||
return noutput_items;
|
||||
}
|
||||
|
||||
//get complex input and output
|
||||
const gr_complex *in = (const gr_complex *)input_items[0];
|
||||
gr_complex *out = (gr_complex *)output_items[0];
|
||||
//get tags
|
||||
|
||||
uint64_t processed_in = 0;
|
||||
uint64_t produced_out = 0;
|
||||
|
||||
std::vector<tag_t> set_phase_inc_tags;
|
||||
|
||||
pmt::pmt_t key = pmt::string_to_symbol("set_phase_inc");
|
||||
get_tags_in_window(set_phase_inc_tags, 0, 0, noutput_items, key);
|
||||
|
||||
for(std::vector<tag_t>::iterator i_tag = set_phase_inc_tags.begin(); i_tag < set_phase_inc_tags.end(); i_tag++){
|
||||
uint64_t tag_offset_rel = i_tag->offset-nitems_read(0);
|
||||
set_phase_inc(pmt::to_double(i_tag->value));
|
||||
uint64_t samples_to_process = tag_offset_rel-processed_in;
|
||||
d_r.rotateN((out+produced_out), const_cast<gr_complex *>(in+processed_in), samples_to_process);
|
||||
processed_in = processed_in + samples_to_process;
|
||||
produced_out = produced_out + samples_to_process;
|
||||
// std::cout << "Rotator, phase inc: " << pmt::to_double(i_tag->value) << std::endl;
|
||||
|
||||
float freq_offset_setting = (pmt::to_double(i_tag->value) / (2*M_PI)) * d_samp_rate; //send stream tag with a new value of the frequency offset
|
||||
pmt::pmt_t key = pmt::string_to_symbol("setting_freq_offset");
|
||||
pmt::pmt_t value = pmt::from_double(freq_offset_setting);
|
||||
add_item_tag(0,i_tag->offset, key, value);
|
||||
}
|
||||
|
||||
d_r.rotateN((out+produced_out), const_cast<gr_complex *>(in+processed_in), (noutput_items-produced_out)); //const_cast<gr_complex *> is workaround old implementation of rotateN that is still present in ubuntu 14.04 packages
|
||||
return noutput_items;
|
||||
}
|
||||
} /* namespace gsm */
|
||||
} /* namespace gr */
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ namespace gr {
|
|||
|
||||
virtual void set_phase_inc(double phase_inc);
|
||||
virtual void set_samp_rate(double samp_rate);
|
||||
|
||||
// Where all the action really happens
|
||||
int work(int noutput_items,
|
||||
gr_vector_const_void_star &input_items,
|
||||
|
|
|
@ -25,11 +25,10 @@
|
|||
#endif
|
||||
|
||||
#include <gnuradio/io_signature.h>
|
||||
//#include <gnuradio/msg_queue.h>
|
||||
#include "msg_to_tag_impl.h"
|
||||
|
||||
namespace gr {
|
||||
namespace grgsm {
|
||||
namespace gsm {
|
||||
|
||||
msg_to_tag::sptr
|
||||
msg_to_tag::make()
|
||||
|
@ -38,9 +37,16 @@ namespace gr {
|
|||
(new msg_to_tag_impl());
|
||||
}
|
||||
|
||||
// void msg_to_tag_impl::queue_msg(pmt::pmt_t msg){
|
||||
//
|
||||
// }
|
||||
void msg_to_tag_impl::queue_msg(pmt::pmt_t msg){
|
||||
if(pmt::is_dict(msg)){
|
||||
try {
|
||||
pmt::pmt_t keys = pmt::dict_keys(msg);
|
||||
} catch (const pmt::wrong_type &e) {
|
||||
msg = pmt::dict_add(pmt::make_dict(), pmt::car(msg), pmt::cdr(msg));
|
||||
}
|
||||
}
|
||||
d_msg_queue.push_back(msg);
|
||||
}
|
||||
|
||||
/*
|
||||
* The private constructor
|
||||
|
@ -48,10 +54,10 @@ namespace gr {
|
|||
msg_to_tag_impl::msg_to_tag_impl()
|
||||
: gr::sync_block("msg_to_tag",
|
||||
gr::io_signature::make(1, 1, sizeof(gr_complex)),
|
||||
gr::io_signature::make(1, 1, sizeof(gr_complex)))
|
||||
gr::io_signature::make(1, 1, sizeof(gr_complex)))
|
||||
{
|
||||
message_port_register_in(pmt::mp("msg"));
|
||||
// set_msg_handler(pmt::mp("msg"), boost::bind(&msg_to_tag::queue_msg, this, _1));
|
||||
message_port_register_in(pmt::mp("msg"));
|
||||
set_msg_handler(pmt::mp("msg"), boost::bind(&msg_to_tag_impl::queue_msg, this, _1));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -66,11 +72,24 @@ namespace gr {
|
|||
gr_vector_const_void_star &input_items,
|
||||
gr_vector_void_star &output_items)
|
||||
{
|
||||
const gr_complex *in = (const gr_complex *) input_items[0];
|
||||
gr_complex *out = (gr_complex *) output_items[0];
|
||||
while(!d_msg_queue.empty()){
|
||||
pmt::pmt_t msg(d_msg_queue.front());
|
||||
d_msg_queue.pop_front();
|
||||
if(pmt::is_dict(msg)){
|
||||
pmt::pmt_t klist(pmt::dict_keys(msg));
|
||||
for (size_t i = 0; i < pmt::length(klist); i++) {
|
||||
pmt::pmt_t k(pmt::nth(i, klist));
|
||||
pmt::pmt_t v(pmt::dict_ref(msg, k, pmt::PMT_NIL));
|
||||
add_item_tag(0, nitems_written(0), k, v, alias_pmt());
|
||||
}
|
||||
} else if(pmt::is_number(msg)) {
|
||||
add_item_tag(0, nitems_written(0), pmt::intern(""), msg, alias_pmt());
|
||||
} else if(pmt::is_symbol(msg)) {
|
||||
add_item_tag(0, nitems_written(0), msg, pmt::intern(""), alias_pmt());
|
||||
}
|
||||
}
|
||||
|
||||
// Do <+signal processing+>
|
||||
memcpy(out, in, sizeof(gr_complex)*noutput_items);
|
||||
memcpy(output_items[0], input_items[0], sizeof(gr_complex)*noutput_items);
|
||||
// Tell runtime system how many output items we produced.
|
||||
return noutput_items;
|
||||
}
|
|
@ -26,16 +26,17 @@
|
|||
#include <grgsm/msg_to_tag.h>
|
||||
|
||||
namespace gr {
|
||||
namespace grgsm {
|
||||
namespace gsm {
|
||||
|
||||
class msg_to_tag_impl : public msg_to_tag
|
||||
{
|
||||
private:
|
||||
// Nothing to declare in this block.
|
||||
std::deque<pmt::pmt_t> d_msg_queue;
|
||||
|
||||
public:
|
||||
msg_to_tag_impl();
|
||||
~msg_to_tag_impl();
|
||||
void queue_msg(pmt::pmt_t msg);
|
||||
|
||||
// Where all the action really happens
|
||||
int work(int noutput_items,
|
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @file
|
||||
# @author Piotr Krysik <ptrkrysik@gmail.com>
|
||||
# @section LICENSE
|
||||
#
|
||||
# Gr-gsm is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# Gr-gsm is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with gr-gsm; see the file COPYING. If not, write to
|
||||
# the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
#
|
||||
|
||||
from gnuradio import gr, gr_unittest
|
||||
from gnuradio import blocks
|
||||
import grgsm_swig as grgsm
|
||||
|
||||
class qa_controlled_fractional_resampler_cc (gr_unittest.TestCase):
|
||||
|
||||
def setUp (self):
|
||||
self.tb = gr.top_block ()
|
||||
|
||||
def tearDown (self):
|
||||
self.tb = None
|
||||
|
||||
def test_001_t (self):
|
||||
# set up fg
|
||||
self.tb.run ()
|
||||
# check data
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
gr_unittest.run(qa_controlled_fractional_resampler_cc, "qa_controlled_fractional_resampler_cc.xml")
|
|
@ -38,6 +38,7 @@
|
|||
#include "grgsm/misc_utils/message_file_sink.h"
|
||||
#include "grgsm/misc_utils/message_file_source.h"
|
||||
#include "grgsm/msg_to_tag.h"
|
||||
#include "grgsm/controlled_fractional_resampler_cc.h"
|
||||
%}
|
||||
|
||||
%include "grgsm/receiver/receiver.h"
|
||||
|
@ -105,5 +106,6 @@ GR_SWIG_BLOCK_MAGIC2(gsm, message_source);
|
|||
%include "grgsm/qa_utils/message_sink.h"
|
||||
GR_SWIG_BLOCK_MAGIC2(gsm, message_sink);
|
||||
%include "grgsm/msg_to_tag.h"
|
||||
GR_SWIG_BLOCK_MAGIC2(grgsm, msg_to_tag);
|
||||
GR_SWIG_BLOCK_MAGIC2(gsm, msg_to_tag);
|
||||
%include "grgsm/controlled_fractional_resampler_cc.h"
|
||||
GR_SWIG_BLOCK_MAGIC2(gsm, controlled_fractional_resampler_cc);
|
||||
|
|
Loading…
Reference in New Issue