Uplink: convert preliminary uplink work to next branch

This commit is contained in:
Nick Foster 2013-08-09 21:31:30 -07:00
parent adbb7ec64b
commit d0101017e3
5 changed files with 151 additions and 99 deletions

View File

@ -1,64 +0,0 @@
/*
# Copyright 2010 Nick Foster
#
# This file is part of gr-air-modes
#
# gr-air-modes 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-air-modes 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-air-modes; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
*/
#ifndef INCLUDED_AIR_MODES_UPLINK_H
#define INCLUDED_AIR_MODES_UPLINK_H
#include <gr_block.h>
#include <gr_msg_queue.h>
#include <air_modes_api.h>
class air_modes_uplink;
typedef boost::shared_ptr<air_modes_uplink> air_modes_uplink_sptr;
AIR_MODES_API air_modes_uplink_sptr air_make_modes_uplink(int channel_rate, float threshold_db, gr_msg_queue_sptr queue);
/*!
* \brief mode select uplink detection
* \ingroup block
*/
class AIR_MODES_API air_modes_uplink : public gr_block
{
private:
friend air_modes_uplink_sptr air_make_modes_uplink(int channel_rate, float threshold_db, gr_msg_queue_sptr queue);
air_modes_uplink(int channel_rate, float threshold_db, gr_msg_queue_sptr queue);
int d_check_width;
float d_symbol_rate;
float d_uplink_length_us;
int d_samples_per_symbol;
float d_threshold_db;
float d_threshold;
pmt::pmt_t d_me, d_key;
gr_tag_t d_timestamp;
double d_secs_per_sample;
gr_msg_queue_sptr d_queue;
std::ostringstream d_payload;
public:
int general_work (int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
};
#endif /* INCLUDED_AIR_MODES_UPLINK_H */

View File

@ -0,0 +1,52 @@
/*
# Copyright 2013 Nick Foster
#
# This file is part of gr-air-modes
#
# gr-air-modes 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-air-modes 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-air-modes; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
*/
#ifndef INCLUDED_AIR_MODES_UPLINK_H
#define INCLUDED_AIR_MODES_UPLINK_H
#include <gnuradio/block.h>
#include <gr_air_modes/api.h>
#include <gnuradio/msg_queue.h>
namespace gr {
namespace air_modes {
/*!
* \brief mode select preamble detection
* \ingroup block
*/
class AIR_MODES_API uplink : virtual public gr::block
{
public:
typedef boost::shared_ptr<uplink> sptr;
static sptr make(int channel_rate, float threshold_db, gr::msg_queue::sptr queue);
virtual void set_rate(int channel_rate) = 0;
virtual void set_threshold(float threshold_db) = 0;
virtual int get_rate(void) = 0;
virtual float get_threshold(void) = 0;
};
} // namespace air_modes
} // namespace gr
#endif /* INCLUDED_AIR_MODES_UPLINK_H */

View File

@ -1,5 +1,5 @@
/*
# Copyright 2010 Nick Foster
# Copyright 2013 Nick Foster
#
# This file is part of gr-air-modes
#
@ -24,51 +24,66 @@
#include "config.h"
#endif
#include <air_modes_uplink.h>
#include <gr_io_signature.h>
#include <gnuradio/io_signature.h>
#include <string.h>
#include <iostream>
#include <iomanip>
#include <gr_tags.h>
#include <gnuradio/tags.h>
#include "uplink_impl.h"
air_modes_uplink_sptr air_make_modes_uplink(int channel_rate, float threshold_db, gr_msg_queue_sptr queue)
{
return air_modes_uplink_sptr (new air_modes_uplink(channel_rate, threshold_db, queue));
namespace gr {
air_modes::uplink::sptr air_modes::uplink::make(int channel_rate, float threshold_db, gr::msg_queue::sptr queue) {
return gnuradio::get_initial_sptr(new air_modes::uplink_impl(channel_rate, threshold_db, queue));
}
air_modes_uplink::air_modes_uplink(int channel_rate, float threshold_db, gr_msg_queue_sptr queue) :
gr_block ("modes_uplink",
gr_make_io_signature2 (2, 2, sizeof(float), sizeof(float)), //stream 0 is received data, stream 1 is moving average for reference
gr_make_io_signature (1, 1, sizeof(float))) //the output packets
air_modes::uplink_impl::uplink_impl(int channel_rate, float threshold_db, gr::msg_queue::sptr queue) :
gr::block ("uplink",
gr::io_signature::make2 (2, 2, sizeof(float), sizeof(float)), //stream 0 is received data, stream 1 is moving average for reference
gr::io_signature::make (1, 1, sizeof(float))) //the output packets
{
d_symbol_rate = 4000000; //2Mchips per second
d_samples_per_symbol = channel_rate / d_symbol_rate; //must be integer number of samples per chip to work
d_check_width = 120 * d_samples_per_symbol; //only search to this far from the end of the stream buffer
d_threshold_db = threshold_db;
d_threshold = powf(10., threshold_db/20.); //the level that the sample must be above the moving average in order to qualify as a pulse
d_secs_per_sample = 1.0 / channel_rate;
set_output_multiple(1+d_check_width*2);
std::stringstream str;
str << name() << unique_id();
d_me = pmt::pmt_string_to_symbol(str.str());
d_key = pmt::pmt_string_to_symbol("uplink_found");
set_history(d_samples_per_symbol);
d_queue = queue;
d_chip_rate = 4000000;
set_rate(channel_rate);
set_threshold(threshold_db);
std::stringstream str;
str << name() << unique_id();
d_me = pmt::string_to_symbol(str.str());
d_key = pmt::string_to_symbol("uplink_found");
d_queue = queue;
}
//the uplink pattern in bits
//fixme goes in .h
void air_modes::uplink_impl::set_rate(int channel_rate) {
d_samples_per_chip = channel_rate / d_chip_rate;
d_samples_per_symbol = d_samples_per_chip * 2;
d_check_width = 120 * d_samples_per_symbol;
d_secs_per_sample = 1.0/channel_rate;
set_output_multiple(1+d_check_width*2);
set_history(d_samples_per_symbol);
}
void air_modes::uplink_impl::set_threshold(float threshold_db) {
d_threshold_db = threshold_db;
d_threshold = powf(10., threshold_db/20.);
}
float air_modes::uplink_impl::get_threshold(void) {
return d_threshold_db;
}
int air_modes::uplink_impl::get_rate(void) {
return d_samples_per_chip * d_chip_rate;
}
//todo: make it return a pair of some kind, otherwise you can lose precision
static double tag_to_timestamp(gr_tag_t tstamp, uint64_t abs_sample_cnt, double secs_per_sample) {
static double tag_to_timestamp(gr::tag_t tstamp, uint64_t abs_sample_cnt, double secs_per_sample) {
uint64_t ts_sample, last_whole_stamp;
double last_frac_stamp;
if(tstamp.key == NULL || pmt::pmt_symbol_to_string(tstamp.key) != "rx_time") return 0;
if(tstamp.key == NULL || pmt::symbol_to_string(tstamp.key) != "rx_time") return 0;
last_whole_stamp = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(tstamp.value, 0));
last_frac_stamp = pmt::pmt_to_double(pmt::pmt_tuple_ref(tstamp.value, 1));
last_whole_stamp = pmt::to_uint64(pmt::tuple_ref(tstamp.value, 0));
last_frac_stamp = pmt::to_double(pmt::tuple_ref(tstamp.value, 1));
ts_sample = tstamp.offset;
double tstime = double(abs_sample_cnt * secs_per_sample) + last_whole_stamp + last_frac_stamp;
@ -89,7 +104,7 @@ static double correlate_preamble(const float *in, int samples_per_chip) {
return corr/(20*samples_per_chip);
}
int air_modes_uplink::general_work(int noutput_items,
int air_modes::uplink_impl::general_work(int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
@ -108,8 +123,8 @@ int air_modes_uplink::general_work(int noutput_items,
if(0) std::cout << "Uplink called with " << ninputs << " samples" << std::endl;
uint64_t abs_sample_cnt = nitems_read(0);
std::vector<gr_tag_t> tstamp_tags;
get_tags_in_range(tstamp_tags, 0, abs_sample_cnt, abs_sample_cnt + ninputs, pmt::pmt_string_to_symbol("rx_time"));
std::vector<gr::tag_t> tstamp_tags;
get_tags_in_range(tstamp_tags, 0, abs_sample_cnt, abs_sample_cnt + ninputs, pmt::string_to_symbol("rx_time"));
//tags.back() is the most recent timestamp, then.
if(tstamp_tags.size() > 0) {
d_timestamp = tstamp_tags.back();
@ -175,7 +190,7 @@ int air_modes_uplink::general_work(int noutput_items,
d_payload << " " << std::setw(6) << 0 << " " << std::dec << ref_level
<< " " << std::setprecision(10) << std::setw(10) << tstamp;
gr_message_sptr msg = gr_make_message_from_string(std::string(d_payload.str()));
gr::message::sptr msg = gr::message::make_from_string(std::string(d_payload.str()));
d_queue->handle(msg);
//produce only one output per work call -- TODO this should probably change
@ -191,3 +206,5 @@ int air_modes_uplink::general_work(int noutput_items,
consume_each(ninputs);
return 0;
}
} //namespace gr

46
lib/uplink_impl.h Normal file
View File

@ -0,0 +1,46 @@
#ifndef _AIR_MODES_UPLINK_IMPL_H_
#define _AIR_MODES_UPLINK_IMPL_H_
#include <gnuradio/block.h>
#include <gr_air_modes/api.h>
#include <gr_air_modes/uplink.h>
#include <gnuradio/msg_queue.h>
namespace gr {
namespace air_modes {
class AIR_MODES_API uplink_impl : public uplink
{
private:
int d_check_width;
int d_chip_rate;
float d_preamble_length_us;
int d_samples_per_chip;
int d_samples_per_symbol;
float d_threshold_db;
float d_threshold;
pmt::pmt_t d_me, d_key;
gr::tag_t d_timestamp;
double d_secs_per_sample;
gr::msg_queue::sptr d_queue;
std::ostringstream d_payload;
public:
uplink_impl(int channel_rate, float threshold_db, gr::msg_queue::sptr queue);
int general_work (int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
void set_rate(int channel_rate);
void set_threshold(float threshold_db);
float get_threshold(void);
int get_rate(void);
};
} //namespace air_modes
} //namespace gr
#endif //_AIR_MODES_UPLINK_IMPL_H_

View File

@ -7,6 +7,7 @@
%{
#include "gr_air_modes/preamble.h"
#include "gr_air_modes/slicer.h"
#include "gr_air_modes/uplink.h"
%}
%include "gr_air_modes/preamble.h"