diff options
author | Sean Nowlan <sean.nowlan@gtri.gatech.edu> | 2015-04-17 19:01:10 -0400 |
---|---|---|
committer | Sean Nowlan <sean.nowlan@gtri.gatech.edu> | 2015-04-17 19:01:10 -0400 |
commit | 5f16e9dc71b3ee1b609279294a27cc0ed85dba22 (patch) | |
tree | 852eed518fd486eaf51cf86d78f04cdf79096d1b | |
parent | 2e2cc50976b4669a18e61e4c3f2ec3da36bae41f (diff) |
digital: wip: more progress
-rw-r--r-- | gr-digital/include/gnuradio/digital/burst_shaper_XX.h.t | 10 | ||||
-rw-r--r-- | gr-digital/lib/burst_shaper_XX_impl.cc.t | 76 | ||||
-rw-r--r-- | gr-digital/lib/burst_shaper_XX_impl.h.t | 32 |
3 files changed, 93 insertions, 25 deletions
diff --git a/gr-digital/include/gnuradio/digital/burst_shaper_XX.h.t b/gr-digital/include/gnuradio/digital/burst_shaper_XX.h.t index d527428911..682515505e 100644 --- a/gr-digital/include/gnuradio/digital/burst_shaper_XX.h.t +++ b/gr-digital/include/gnuradio/digital/burst_shaper_XX.h.t @@ -81,7 +81,7 @@ namespace gr { * \param length_tag_name: the name of the tagged stream length * tag key. */ - static sptr make(const std::vector<@I_TYPE@> &taps, + static sptr make(const std::vector<@O_TYPE@> &taps, int pre_padding=0, int post_padding=0, bool insert_phasing=false, const std::string &length_tag_name="packet_len"); @@ -89,24 +89,24 @@ namespace gr { /*! * Returns the amount of zero padding inserted before each burst. */ - virtual unsigned int pre_padding() const = 0; + virtual int pre_padding() const = 0; /*! * Returns the amount of zero padding inserted after each burst. */ - virtual unsigned int post_padding() const = 0; + virtual int post_padding() const = 0; /*! * Returns the total amount of zero padding and phasing symbols * inserted before each burst. */ - virtual unsigned int prefix_length() const = 0; + virtual int prefix_length() const = 0; /*! * Returns the total amount of zero padding and phasing symbols * inserted after each burst. */ - virtual unsigned int suffix_length() const = 0; + virtual int suffix_length() const = 0; }; } // namespace digital diff --git a/gr-digital/lib/burst_shaper_XX_impl.cc.t b/gr-digital/lib/burst_shaper_XX_impl.cc.t index eb7338a887..cdbc7ce918 100644 --- a/gr-digital/lib/burst_shaper_XX_impl.cc.t +++ b/gr-digital/lib/burst_shaper_XX_impl.cc.t @@ -50,17 +50,29 @@ namespace gr { : gr::block("@BASE_NAME@", gr::io_signature::make(1, 1, sizeof(@I_TYPE@)), gr::io_signature::make(1, 1, sizeof(@O_TYPE@))), - d_upflank(taps.begin(), taps.begin() + taps.size()/2 + taps.size()%2), - d_downflank(taps.begin() + taps.size()/2, taps.end()), + d_up_flank(taps.begin(), taps.begin() + taps.size()/2 + taps.size()%2), + d_down_flank(taps.begin() + taps.size()/2, taps.end()), d_nprepad(pre_padding), d_npostpad(post_padding), d_insert_phasing(insert_phasing), d_length_tag_key(pmt::string_to_symbol(length_tag_name)), d_state(STATE_WAITING) { - if(d_insert_phasing) - for(unsigned int i = 0; i < d_upflank.size(); i++) - d_phasing.push_back(i%2 ? @I_TYPE@(1.0f) : @I_TYPE@(-1.0f)); + assert(d_up_flank.size() == d_down_flank.size()); + + d_up_phasing.resize(d_up_flank.size()); + d_down_phasing.resize(d_up_flank.size()); + if(d_insert_phasing) { + @I_TYPE@ symbol; + for(unsigned int i = 0; i < d_up_flank.size(); i++) { + symbol = (i%2) ? @I_TYPE@(1.0f) : @I_TYPE@(-1.0f); + d_up_phasing.push_back(symbol * d_up_flank[i]); + d_down_phasing.push_back(symbol * d_down_flank[i]); + } + } + + set_relative_rate(1.0); + set_tag_propagation_policy(TPP_DONT); } @IMPL_NAME@::~@IMPL_NAME@() @@ -84,33 +96,79 @@ namespace gr { int nwritten = 0; int nread = 0; - int curr_tag_index = 0; - int nprocess = 0; + int nstart = 0; + int nstop = 0; + int nremaining = 0; + int nprocessed = 0; + uint64_t curr_tag_index = nitems_read(0); std::vector<tag_t> tags; get_tags_in_window(tags, 0, 0, ninput_items[0]); std::sort(tags.begin(), tags.end(), tag_t::offset_compare); - //TODO: figure out what to do with tag gaps - should probably just drop while((nwritten < noutput_items) && (nread < ninput_items[0])) { + nremaining = noutput_items - nwritten; switch(d_state) { case(STATE_WAITING): + curr_tag_index = tags[0].offset; + d_nremaining = pmt::to_long(tags[0].value) + + prefix_length() + suffix_length(); + nprocessed += (int)curr_tag_index; // drop orphaned samples + add_length_tag(nwritten); + enter_prepad(); + break; + case(STATE_PREPAD): std::memset(out, 0x00, nprocess * sizeof(@O_TYPE@)); + break; + case(STATE_RAMPUP): + nprocess = std::min( + if(d_insert_phasing) { + + } + break; + case(STATE_COPY): std::memcpy(out, in, nprocess * sizeof(@O_TYPE@)); + break; + case(STATE_RAMPDOWN): + break; + case(STATE_POSTPAD): std::memset(out, 0x00, nprocess * sizeof(@O_TYPE@)); + break; + + default: + throw std::runtime_error("burst_shaper: invalid state reached"); } } - consume_each (noutput_items); + consume_each (nconsumed); // Tell runtime system how many output items we produced. return noutput_items; } + void + @IMPL_NAME@::add_length_tag(int offset) + { + add_item_tag(0, nitems_written(0) + offset, d_length_tag_key, + pmt::from_long(d_nremaining), + pmt::string_to_symbol(name())); + } + + void + @IMPL_NAME@::propagate_tags(std::vector<tag_t> &tags, int offset) + { + // FIXME: need to handle offsets correctly + std::vector<tag_t>::iterator tag; + for(tag = tags.begin(); tag != tags.end(); tag++) { + tag_t new_tag = *tag; + new_tag.offset = nitems_written(0) + offset; + add_item_tag(0, new_tag); + } + } } /* namespace digital */ } /* namespace gr */ diff --git a/gr-digital/lib/burst_shaper_XX_impl.h.t b/gr-digital/lib/burst_shaper_XX_impl.h.t index c36a3ad31d..66b5e2428e 100644 --- a/gr-digital/lib/burst_shaper_XX_impl.h.t +++ b/gr-digital/lib/burst_shaper_XX_impl.h.t @@ -37,18 +37,28 @@ namespace gr { STATE_COPY, STATE_RAMPDOWN, STATE_POSTPAD}; private: - const std::vector<@I_TYPE@> d_upflank; - const std::vector<@I_TYPE@> d_downflank; + const std::vector<@O_TYPE@> d_up_flank; + const std::vector<@O_TYPE@> d_down_flank; const int d_nprepad; const int d_npostpad; const bool d_insert_phasing; const pmt::pmt_t d_length_tag_key; - std::vector<@I_TYPE@> d_phasing; - int d_remaining; + std::vector<@O_TYPE@> d_up_phasing; + std::vector<@O_TYPE@> d_down_phasing; + uint64_t d_nremaining; state_t d_state; + void enter_waiting() { d_state = STATE_WAITING; } + void enter_prepad() { d_state = STATE_PREPAD; } + void enter_rampup() { d_state = STATE_RAMPUP; } + void enter_copy() { d_state = STATE_COPY; } + void enter_rampdown() { d_state = STATE_RAMPDOWN; } + void enter_postpad() { d_state = STATE_POSTPAD; } + void add_length_tag(int offset); + void propagate_tag(tag_t &tag, int offset); + public: - @IMPL_NAME@(const std::vector<@I_TYPE@> &taps, int pre_padding, + @IMPL_NAME@(const std::vector<@O_TYPE@> &taps, int pre_padding, int post_padding, bool insert_phasing, const std::string &length_tag_name); ~@IMPL_NAME@(); @@ -60,12 +70,12 @@ namespace gr { gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); - unsigned int pre_padding() const { return d_nprepad; } - unsigned int post_padding() const { return d_npostpad; } - unsigned int prefix_length() const { return d_nprepad + - d_upflank.size(); } - unsigned int suffix_length() const { return d_npostpad + - d_downflank.size(); } + int pre_padding() const { return d_nprepad; } + int post_padding() const { return d_npostpad; } + int prefix_length() const { return d_nprepad + + d_up_flank.size(); } + int suffix_length() const { return d_npostpad + + d_down_flank.size(); } }; } // namespace digital |