diff --git a/grc/ccs_burst_tagger.xml b/grc/ccs_burst_tagger.xml
index e3969a8..ecfa431 100644
--- a/grc/ccs_burst_tagger.xml
+++ b/grc/ccs_burst_tagger.xml
@@ -3,6 +3,7 @@
Burst Tagger
ccs_burst_tagger
CCS
+ import pmt
import ccs
ccs.burst_tagger($tag_name)
diff --git a/lib/burst_tagger_impl.cc b/lib/burst_tagger_impl.cc
index 1f99b17..fa92bb1 100644
--- a/lib/burst_tagger_impl.cc
+++ b/lib/burst_tagger_impl.cc
@@ -1,16 +1,16 @@
-/*
+/*
* Copyright 2013 Bastian Bloessl.
- *
+ *
* This 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.
- *
+ *
* This software 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 this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
@@ -20,6 +20,8 @@
#include "burst_tagger_impl.h"
#include
+#define dout std::cout
+
namespace gr {
namespace ccs {
@@ -27,12 +29,35 @@ burst_tagger_impl::burst_tagger_impl(pmt::pmt_t tag_name)
: gr::sync_block("burst_tagger",
gr::io_signature::make(1, 1, sizeof(gr_complex)),
gr::io_signature::make(1, 1, sizeof(gr_complex))),
- d_tag_name(tag_name) {
+ d_tag_name(tag_name),
+ d_copy(0) {
}
burst_tagger_impl::~burst_tagger_impl() {
}
+void
+burst_tagger_impl::add_sob(uint64_t item) {
+ dout << "burst tagger: insert sob at: " << item << std::endl;
+
+ const pmt::pmt_t sob_key = pmt::string_to_symbol("tx_sob");
+ const pmt::pmt_t value = pmt::PMT_T;
+ const pmt::pmt_t srcid = pmt::string_to_symbol(alias());
+ add_item_tag(0, item, sob_key, value, srcid);
+}
+
+
+void
+burst_tagger_impl::add_eob(uint64_t item) {
+ dout << "burst tagger: insert eob at: " << item << std::endl;
+
+ const pmt::pmt_t eob_key = pmt::string_to_symbol("tx_eob");
+ const pmt::pmt_t value = pmt::PMT_T;
+ const pmt::pmt_t srcid = pmt::string_to_symbol(alias());
+ add_item_tag(0, item, eob_key, value, srcid);
+}
+
+
int
burst_tagger_impl::work(int noutput_items,
gr_vector_const_void_star &input_items,
@@ -41,17 +66,47 @@ burst_tagger_impl::work(int noutput_items,
const gr_complex *in = (const gr_complex*)input_items[0];
gr_complex *out = (gr_complex*)output_items[0];
- std::vector tags;
- const uint64_t nread = nitems_read(0);
- get_tags_in_range(tags, 0, nread, nread + noutput_items - 1,
- d_tag_name);
- std::sort(tags.begin(), tags.end(), tag_t::offset_compare);
+ if(!d_copy) {
+ dout << "nothing to copy, searching for tags" << std::endl;
+ std::vector tags;
+ const uint64_t nread = nitems_read(0);
- if(tags.size()) {
+ get_tags_in_range(tags, 0, nread, nread + noutput_items - 1,
+ d_tag_name);
+ std::sort(tags.begin(), tags.end(), tag_t::offset_compare);
+
+ // copy until the first tag
+ if(tags.size()) {
+ dout << "tags found" << std::endl;
+ tag_t tag = tags.front();
+ if(tag.offset == nitems_read(0)) {
+ d_copy = pmt::to_uint64(tag.value) * 128;
+ dout << "tag is at current offset -- packet len " << d_copy << " items read " << nitems_read(0) << std::endl;
+ add_sob(nitems_written(0));
+ } else {
+ uint64_t cpy = std::min((uint64_t)noutput_items, tag.offset - nitems_written(0));
+ dout << "tag is not at current offset copying " << cpy << std::endl;
+ std::memcpy(out, in, cpy * sizeof(gr_complex));
+ return cpy;
+ }
+ }
}
- return noutput_items;
+ if(d_copy) {
+ int cpy = std::min(d_copy, noutput_items);
+ dout << "packet copy " << cpy << std::endl;
+ std::memcpy(out, in, cpy * sizeof(gr_complex));
+ d_copy -= cpy;
+ if(d_copy == 0) {
+ add_eob(nitems_written(0) + cpy - 1);
+ }
+ return cpy;
+ } else {
+ dout << "copy random stuff " << std::endl;
+ std::memcpy(out, in, noutput_items * sizeof(gr_complex));
+ return noutput_items;
+ }
}
burst_tagger::sptr burst_tagger::make(pmt::pmt_t tag_name) {
diff --git a/lib/burst_tagger_impl.h b/lib/burst_tagger_impl.h
index 3148a9a..bd2952b 100644
--- a/lib/burst_tagger_impl.h
+++ b/lib/burst_tagger_impl.h
@@ -28,7 +28,11 @@ namespace ccs {
class burst_tagger_impl : public burst_tagger {
private:
+ void add_eob(uint64_t item);
+ void add_sob(uint64_t item);
+
pmt::pmt_t d_tag_name;
+ int d_copy;
public:
burst_tagger_impl(pmt::pmt_t tag_name);