diff options
Diffstat (limited to 'gr-blocks/lib')
27 files changed, 472 insertions, 226 deletions
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index 3f456b6b04..6e2b583308 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -91,8 +91,8 @@ endmacro(expand_cc_h_impl) # Invoke macro to generate various sources ######################################################################## expand_cc_h_impl(add_XX ss ii cc) -expand_cc_h_impl(add_const_XX ss ii ff cc) -expand_cc_h_impl(add_const_vXX ss ii ff cc) +expand_cc_h_impl(add_const_XX bb ss ii ff cc) +expand_cc_h_impl(add_const_vXX bb ss ii ff cc) expand_cc_h_impl(and_XX bb ss ii) expand_cc_h_impl(and_const_XX bb ss ii) expand_cc_h_impl(argmax_XX fs is ss) @@ -134,6 +134,11 @@ include_directories( link_directories(${Boost_LIBRARY_DIRS}) +if(ENABLE_GR_CTRLPORT) + ADD_DEFINITIONS(-DGR_CTRLPORT) + include_directories(${ICE_INCLUDE_DIR}) +endif(ENABLE_GR_CTRLPORT) + ######################################################################## # Setup library ######################################################################## @@ -204,6 +209,7 @@ list(APPEND gr_blocks_sources tag_debug_impl.cc pdu_to_tagged_stream_impl.cc peak_detector2_fb_impl.cc + random_pdu_impl.cc probe_rate_impl.cc regenerate_bb_impl.cc repack_bits_bb_impl.cc diff --git a/gr-blocks/lib/burst_tagger_impl.cc b/gr-blocks/lib/burst_tagger_impl.cc index 5d0691bde6..31c535290d 100644 --- a/gr-blocks/lib/burst_tagger_impl.cc +++ b/gr-blocks/lib/burst_tagger_impl.cc @@ -47,13 +47,13 @@ namespace gr { std::stringstream str; str << name() << unique_id(); - d_true_key = pmt::pmt_string_to_symbol("burst"); + d_true_key = pmt::string_to_symbol("burst"); d_true_value = pmt::PMT_T; - d_false_key = pmt::pmt_string_to_symbol("burst"); + d_false_key = pmt::string_to_symbol("burst"); d_false_value = pmt::PMT_F; - d_id = pmt::pmt_string_to_symbol(str.str()); + d_id = pmt::string_to_symbol(str.str()); } burst_tagger_impl::~burst_tagger_impl() @@ -63,7 +63,7 @@ namespace gr { void burst_tagger_impl::set_true_tag(const std::string &key, bool value) { - d_true_key = pmt::pmt_string_to_symbol(key); + d_true_key = pmt::string_to_symbol(key); if(value == true) { d_true_value = pmt::PMT_T; } @@ -75,7 +75,7 @@ namespace gr { void burst_tagger_impl::set_false_tag (const std::string &key, bool value) { - d_false_key = pmt::pmt_string_to_symbol(key); + d_false_key = pmt::string_to_symbol(key); if(value == true) { d_false_value = pmt::PMT_T; } diff --git a/gr-blocks/lib/file_meta_sink_impl.cc b/gr-blocks/lib/file_meta_sink_impl.cc index b707bfac4e..d996e7a93e 100644 --- a/gr-blocks/lib/file_meta_sink_impl.cc +++ b/gr-blocks/lib/file_meta_sink_impl.cc @@ -100,34 +100,34 @@ namespace gr { if(!open(filename)) throw std::runtime_error("file_meta_sink: can't open file\n"); - pmt_t timestamp = pmt_make_tuple(pmt_from_uint64(0), - pmt_from_double(0)); + pmt::pmt_t timestamp = pmt::make_tuple(pmt::from_uint64(0), + pmt::from_double(0)); // handle extra dictionary - d_extra = pmt_make_dict(); + d_extra = pmt::make_dict(); if(extra_dict.size() > 0) { - pmt_t extras = pmt_deserialize_str(extra_dict); - pmt_t keys = pmt_dict_keys(extras); - pmt_t vals = pmt_dict_values(extras); - size_t nitems = pmt_length(keys); + pmt::pmt_t extras = pmt::deserialize_str(extra_dict); + pmt::pmt_t keys = pmt::dict_keys(extras); + pmt::pmt_t vals = pmt::dict_values(extras); + size_t nitems = pmt::length(keys); for(size_t i = 0; i < nitems; i++) { - d_extra = pmt_dict_add(d_extra, - pmt_nth(i, keys), - pmt_nth(i, vals)); + d_extra = pmt::dict_add(d_extra, + pmt::nth(i, keys), + pmt::nth(i, vals)); } } - d_extra_size = pmt_serialize_str(d_extra).size(); + d_extra_size = pmt::serialize_str(d_extra).size(); - d_header = pmt_make_dict(); - d_header = pmt_dict_add(d_header, mp("version"), mp(METADATA_VERSION)); - d_header = pmt_dict_add(d_header, mp("rx_rate"), mp(samp_rate)); - d_header = pmt_dict_add(d_header, mp("rx_time"), timestamp); - d_header = pmt_dict_add(d_header, mp("size"), pmt_from_long(d_itemsize)); - d_header = pmt_dict_add(d_header, mp("type"), pmt_from_long(type)); - d_header = pmt_dict_add(d_header, mp("cplx"), complex ? PMT_T : PMT_F); - d_header = pmt_dict_add(d_header, mp("strt"), pmt_from_uint64(METADATA_HEADER_SIZE+d_extra_size)); - d_header = pmt_dict_add(d_header, mp("bytes"), pmt_from_uint64(0)); + d_header = pmt::make_dict(); + d_header = pmt::dict_add(d_header, pmt::mp("version"), pmt::mp(METADATA_VERSION)); + d_header = pmt::dict_add(d_header, pmt::mp("rx_rate"), pmt::mp(samp_rate)); + d_header = pmt::dict_add(d_header, pmt::mp("rx_time"), timestamp); + d_header = pmt::dict_add(d_header, pmt::mp("size"), pmt::from_long(d_itemsize)); + d_header = pmt::dict_add(d_header, pmt::mp("type"), pmt::from_long(type)); + d_header = pmt::dict_add(d_header, pmt::mp("cplx"), complex ? pmt::PMT_T : pmt::PMT_F); + d_header = pmt::dict_add(d_header, pmt::mp("strt"), pmt::from_uint64(METADATA_HEADER_SIZE+d_extra_size)); + d_header = pmt::dict_add(d_header, mp("bytes"), pmt::from_uint64(0)); do_update(); @@ -240,10 +240,10 @@ namespace gr { } void - file_meta_sink_impl::write_header(FILE *fp, pmt_t header, pmt_t extra) + file_meta_sink_impl::write_header(FILE *fp, pmt::pmt_t header, pmt::pmt_t extra) { - std::string header_str = pmt_serialize_str(header); - std::string extra_str = pmt_serialize_str(extra); + std::string header_str = pmt::serialize_str(header); + std::string extra_str = pmt::serialize_str(extra); if((header_str.size() != METADATA_HEADER_SIZE) && (extra_str.size() != d_extra_size)) throw std::runtime_error("file_meta_sink: header or extras is wrong size.\n"); @@ -274,24 +274,24 @@ namespace gr { } void - file_meta_sink_impl::update_header(pmt_t key, pmt_t value) + file_meta_sink_impl::update_header(pmt::pmt_t key, pmt::pmt_t value) { // Special handling caveat to transform rate from radio source into // the rate at this sink. - if(pmt_eq(key, mp("rx_rate"))) { - d_samp_rate = pmt_to_double(value); - value = pmt_from_double(d_samp_rate*d_relative_rate); + if(pmt::eq(key, mp("rx_rate"))) { + d_samp_rate = pmt::to_double(value); + value = pmt::from_double(d_samp_rate*d_relative_rate); } // If the tag is not part of the standard header, we put it into the // extra data, which either updates the current dictionary or adds a // new item. - if(pmt_dict_has_key(d_header, key)) { - d_header = pmt_dict_add(d_header, key, value); + if(pmt::dict_has_key(d_header, key)) { + d_header = pmt::dict_add(d_header, key, value); } else { - d_extra = pmt_dict_add(d_extra, key, value); - d_extra_size = pmt_serialize_str(d_extra).size(); + d_extra = pmt::dict_add(d_extra, key, value); + d_extra_size = pmt::serialize_str(d_extra).size(); } } @@ -310,11 +310,11 @@ namespace gr { // Update the last header info with the number of samples this // block represents. - size_t hdrlen = pmt_to_uint64(pmt_dict_ref(d_header, mp("strt"), PMT_NIL)); + size_t hdrlen = pmt::to_uint64(pmt::dict_ref(d_header, mp("strt"), pmt::PMT_NIL)); size_t seg_size = d_itemsize*d_total_seg_size; - pmt_t s = pmt_from_uint64(seg_size); + pmt::pmt_t s = pmt::from_uint64(seg_size); update_header(mp("bytes"), s); - update_header(mp("strt"), pmt_from_uint64(METADATA_HEADER_SIZE+d_extra_size)); + update_header(mp("strt"), pmt::from_uint64(METADATA_HEADER_SIZE+d_extra_size)); fseek(d_fp, -seg_size-hdrlen, SEEK_CUR); write_header(d_fp, d_header, d_extra); fseek(d_fp, seg_size, SEEK_CUR); @@ -325,11 +325,11 @@ namespace gr { { // Update the last header info with the number of samples this // block represents. - size_t hdrlen = pmt_to_uint64(pmt_dict_ref(d_header, mp("strt"), PMT_NIL)); + size_t hdrlen = pmt::to_uint64(pmt::dict_ref(d_header, mp("strt"), pmt::PMT_NIL)); size_t seg_size = d_itemsize*d_total_seg_size; - pmt_t s = pmt_from_uint64(seg_size); + pmt::pmt_t s = pmt::from_uint64(seg_size); update_header(mp("bytes"), s); - update_header(mp("strt"), pmt_from_uint64(METADATA_HEADER_SIZE+d_extra_size)); + update_header(mp("strt"), pmt::from_uint64(METADATA_HEADER_SIZE+d_extra_size)); fseek(d_hdr_fp, -hdrlen, SEEK_CUR); write_header(d_hdr_fp, d_header, d_extra); } @@ -340,13 +340,13 @@ namespace gr { // New header, so set current size of chunk to 0 and start of chunk // based on current index + header size. //uint64_t loc = get_last_header_loc(); - pmt_t s = pmt_from_uint64(0); + pmt::pmt_t s = pmt::from_uint64(0); update_header(mp("bytes"), s); // If we have multiple tags on the same offset, this makes // sure we just overwrite the same header each time instead // of creating a new header per tag. - s = pmt_from_uint64(METADATA_HEADER_SIZE + d_extra_size); + s = pmt::from_uint64(METADATA_HEADER_SIZE + d_extra_size); update_header(mp("strt"), s); if(d_state == STATE_DETACHED) @@ -358,10 +358,10 @@ namespace gr { void file_meta_sink_impl::update_rx_time() { - pmt_t rx_time = pmt_string_to_symbol("rx_time"); - pmt_t r = pmt_dict_ref(d_header, rx_time, PMT_NIL); - uint64_t secs = pmt_to_uint64(pmt_tuple_ref(r, 0)); - double fracs = pmt_to_double(pmt_tuple_ref(r, 1)); + pmt::pmt_t rx_time = pmt::string_to_symbol("rx_time"); + pmt::pmt_t r = pmt::dict_ref(d_header, rx_time, pmt::PMT_NIL); + uint64_t secs = pmt::to_uint64(pmt::tuple_ref(r, 0)); + double fracs = pmt::to_double(pmt::tuple_ref(r, 1)); double diff = d_total_seg_size / (d_samp_rate*d_relative_rate); //std::cerr << "old secs: " << secs << std::endl; @@ -377,8 +377,8 @@ namespace gr { //std::cerr << "new secs: " << secs << std::endl; //std::cerr << "new fracs: " << fracs << std::endl << std::endl; - r = pmt_make_tuple(pmt_from_uint64(secs), pmt_from_double(fracs)); - d_header = pmt_dict_add(d_header, rx_time, r); + r = pmt::make_tuple(pmt::from_uint64(secs), pmt::from_double(fracs)); + d_header = pmt::dict_add(d_header, rx_time, r); } int diff --git a/gr-blocks/lib/file_meta_source_impl.cc b/gr-blocks/lib/file_meta_source_impl.cc index 42fdabb541..9d66193e53 100644 --- a/gr-blocks/lib/file_meta_source_impl.cc +++ b/gr-blocks/lib/file_meta_source_impl.cc @@ -95,7 +95,7 @@ namespace gr { do_update(); - pmt_t hdr = PMT_NIL, extras = PMT_NIL; + pmt::pmt_t hdr = pmt::PMT_NIL, extras = pmt::PMT_NIL; if(read_header(hdr, extras)) { parse_header(hdr, 0, d_tags); parse_extras(extras, 0, d_tags); @@ -125,7 +125,7 @@ namespace gr { } bool - file_meta_source_impl::read_header(pmt_t &hdr, pmt_t &extras) + file_meta_source_impl::read_header(pmt::pmt_t &hdr, pmt::pmt_t &extras) { // Select which file handle to read from. FILE *fp; @@ -156,14 +156,14 @@ namespace gr { // Convert to string or the char array gets confused by the \0 str.insert(0, hdr_buffer, METADATA_HEADER_SIZE); - hdr = pmt_deserialize_str(str); + hdr = pmt::deserialize_str(str); delete [] hdr_buffer; uint64_t seg_start, extra_len; - pmt_t r, dump; - if(pmt_dict_has_key(hdr, pmt_string_to_symbol("strt"))) { - r = pmt_dict_ref(hdr, pmt_string_to_symbol("strt"), dump); - seg_start = pmt_to_uint64(r); + pmt::pmt_t r, dump; + if(pmt::dict_has_key(hdr, pmt::string_to_symbol("strt"))) { + r = pmt::dict_ref(hdr, pmt::string_to_symbol("strt"), dump); + seg_start = pmt::to_uint64(r); extra_len = seg_start - METADATA_HEADER_SIZE; } @@ -188,7 +188,7 @@ namespace gr { str.clear(); str.insert(0, hdr_buffer, extra_len); - extras = pmt_deserialize_str(str); + extras = pmt::deserialize_str(str); delete [] hdr_buffer; } @@ -196,16 +196,16 @@ namespace gr { } void - file_meta_source_impl::parse_header(pmt_t hdr, uint64_t offset, + file_meta_source_impl::parse_header(pmt::pmt_t hdr, uint64_t offset, std::vector<gr_tag_t> &tags) { - pmt_t r, key; + pmt::pmt_t r, key; // GET SAMPLE RATE - key = pmt_string_to_symbol("rx_rate"); - if(pmt_dict_has_key(hdr, key)) { - r = pmt_dict_ref(hdr, key, PMT_NIL); - d_samp_rate = pmt_to_double(r); + key = pmt::string_to_symbol("rx_rate"); + if(pmt::dict_has_key(hdr, key)) { + r = pmt::dict_ref(hdr, key, pmt::PMT_NIL); + d_samp_rate = pmt::to_double(r); gr_tag_t t; t.offset = offset; @@ -219,9 +219,9 @@ namespace gr { } // GET TIME STAMP - key = pmt_string_to_symbol("rx_time"); - if(pmt_dict_has_key(hdr, key)) { - d_time_stamp = pmt_dict_ref(hdr, key, PMT_NIL); + key = pmt::string_to_symbol("rx_time"); + if(pmt::dict_has_key(hdr, key)) { + d_time_stamp = pmt::dict_ref(hdr, key, pmt::PMT_NIL); gr_tag_t t; t.offset = offset; @@ -235,16 +235,16 @@ namespace gr { } // GET ITEM SIZE OF DATA - if(pmt_dict_has_key(hdr, pmt_string_to_symbol("size"))) { - d_itemsize = pmt_to_long(pmt_dict_ref(hdr, pmt_string_to_symbol("size"), PMT_NIL)); + if(pmt::dict_has_key(hdr, pmt::string_to_symbol("size"))) { + d_itemsize = pmt::to_long(pmt::dict_ref(hdr, pmt::string_to_symbol("size"), pmt::PMT_NIL)); } else { throw std::runtime_error("file_meta_source: Could not extract item size.\n"); } // GET SEGMENT SIZE - if(pmt_dict_has_key(hdr, pmt_string_to_symbol("bytes"))) { - d_seg_size = pmt_to_uint64(pmt_dict_ref(hdr, pmt_string_to_symbol("bytes"), PMT_NIL)); + if(pmt::dict_has_key(hdr, pmt::string_to_symbol("bytes"))) { + d_seg_size = pmt::to_uint64(pmt::dict_ref(hdr, pmt::string_to_symbol("bytes"), pmt::PMT_NIL)); // Convert from bytes to items d_seg_size /= d_itemsize; @@ -255,16 +255,16 @@ namespace gr { } void - file_meta_source_impl::parse_extras(pmt_t extras, uint64_t offset, + file_meta_source_impl::parse_extras(pmt::pmt_t extras, uint64_t offset, std::vector<gr_tag_t> &tags) { - pmt_t item, key, val; + pmt::pmt_t item, key, val; - size_t nitems = pmt_length(extras); + size_t nitems = pmt::length(extras); for(size_t i = 0; i < nitems; i++) { - item = pmt_nth(i, extras); - key = pmt_car(item); - val = pmt_cdr(item); + item = pmt::nth(i, extras); + key = pmt::car(item); + val = pmt::cdr(item); gr_tag_t t; t.offset = offset; @@ -370,7 +370,7 @@ namespace gr { // We've reached the end of a segment; parse the next header and get // the new tags to send and set the next segment size. if(d_seg_size == 0) { - pmt_t hdr=PMT_NIL, extras=PMT_NIL; + pmt::pmt_t hdr=pmt::PMT_NIL, extras=pmt::PMT_NIL; if(read_header(hdr, extras)) { parse_header(hdr, nitems_written(0), d_tags); parse_extras(extras, nitems_written(0), d_tags); diff --git a/gr-blocks/lib/message_burst_source_impl.cc b/gr-blocks/lib/message_burst_source_impl.cc index f3c90eda31..5ac417f7a5 100644 --- a/gr-blocks/lib/message_burst_source_impl.cc +++ b/gr-blocks/lib/message_burst_source_impl.cc @@ -61,7 +61,7 @@ namespace gr { { std::stringstream id; id << name() << unique_id(); - d_me = pmt::pmt_string_to_symbol(id.str()); + d_me = pmt::string_to_symbol(id.str()); } message_burst_source_impl::message_burst_source_impl(size_t itemsize, gr_msg_queue_sptr msgq) @@ -73,7 +73,7 @@ namespace gr { { std::stringstream id; id << name() << unique_id(); - d_me = pmt::pmt_string_to_symbol(id.str()); + d_me = pmt::string_to_symbol(id.str()); } message_burst_source_impl::~message_burst_source_impl() @@ -112,8 +112,8 @@ namespace gr { //tag end of burst add_item_tag(0, //stream ID abs_sample_count+nn-1, //sample number - pmt::pmt_string_to_symbol("tx_eob"), - pmt::pmt_from_bool(1), + pmt::string_to_symbol("tx_eob"), + pmt::from_bool(1), d_me); //block src id } } @@ -133,8 +133,8 @@ namespace gr { //tag start of burst add_item_tag(0, //stream ID abs_sample_count+nn, //sample number - pmt::pmt_string_to_symbol("tx_sob"), - pmt::pmt_from_bool(1), + pmt::string_to_symbol("tx_sob"), + pmt::from_bool(1), d_me); //block src id if((d_msg->length() % d_itemsize) != 0) diff --git a/gr-blocks/lib/message_debug_impl.cc b/gr-blocks/lib/message_debug_impl.cc index d7b1e5db09..6455513d76 100644 --- a/gr-blocks/lib/message_debug_impl.cc +++ b/gr-blocks/lib/message_debug_impl.cc @@ -43,7 +43,7 @@ namespace gr { message_debug_impl::print(pmt::pmt_t msg) { std::cout << "******* MESSAGE DEBUG PRINT ********\n"; - pmt::pmt_print(msg); + pmt::print(msg); std::cout << "************************************\n"; } @@ -57,15 +57,15 @@ namespace gr { void message_debug_impl::print_pdu(pmt::pmt_t pdu) { - pmt::pmt_t meta = pmt::pmt_car(pdu); - pmt::pmt_t vector = pmt::pmt_cdr(pdu); + pmt::pmt_t meta = pmt::car(pdu); + pmt::pmt_t vector = pmt::cdr(pdu); std::cout << "* MESSAGE DEBUG PRINT PDU VERBOSE *\n"; - pmt::pmt_print(meta); - size_t len = pmt::pmt_length(vector); + pmt::print(meta); + size_t len = pmt::length(vector); std::cout << "pdu_length = " << len << std::endl; std::cout << "contents = " << std::endl; size_t offset(0); - const uint8_t* d = (const uint8_t*) pmt_uniform_vector_elements(vector, offset); + const uint8_t* d = (const uint8_t*) pmt::uniform_vector_elements(vector, offset); for(size_t i=0; i<len; i+=16){ printf("%04x: ", ((unsigned int)i)); for(size_t j=i; j<std::min(i+16,len); j++){ diff --git a/gr-blocks/lib/message_sink_impl.cc b/gr-blocks/lib/message_sink_impl.cc index a8dbfb4c71..fbc7b27d58 100644 --- a/gr-blocks/lib/message_sink_impl.cc +++ b/gr-blocks/lib/message_sink_impl.cc @@ -44,11 +44,30 @@ namespace gr { (new message_sink_impl(itemsize, msgq, dont_block)); } + message_sink::sptr + message_sink::make(size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block, + const std::string& lengthtagname) + { + return gnuradio::get_initial_sptr + (new message_sink_impl(itemsize, msgq, dont_block, lengthtagname)); + } + message_sink_impl::message_sink_impl(size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block) : gr_sync_block("message_sink", gr_make_io_signature(1, 1, itemsize), gr_make_io_signature(0, 0, 0)), - d_itemsize(itemsize), d_msgq(msgq), d_dont_block(dont_block) + d_itemsize(itemsize), d_msgq(msgq), d_dont_block(dont_block), + d_tags(false), d_items_read(0) + { + } + + message_sink_impl::message_sink_impl(size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block, + const std::string& lengthtagname) + : gr_sync_block("message_sink", + gr_make_io_signature(1, 1, itemsize), + gr_make_io_signature(0, 0, 0)), + d_itemsize(itemsize), d_msgq(msgq), d_dont_block(dont_block), + d_tags(true), d_lengthtagname(lengthtagname), d_items_read(0) { } @@ -61,23 +80,53 @@ namespace gr { gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { - const char *in = (const char*)input_items[0]; - - // if we'd block, drop the data on the floor and say everything is OK - if(d_dont_block && d_msgq->full_p()) - return noutput_items; - - // build a message to hold whatever we've got - gr_message_sptr msg = gr_make_message(0, // msg type - d_itemsize, // arg1 for other end - noutput_items, // arg2 for other end (redundant) - noutput_items * d_itemsize); // len of msg - memcpy(msg->msg(), in, noutput_items * d_itemsize); + const char *in = (const char *) input_items[0]; - d_msgq->handle(msg); // send it + if (d_tags) { + long packet_length = 0; + std::vector<gr_tag_t> tags; + this->get_tags_in_range(tags, 0, d_items_read, d_items_read+1); + //const size_t ninput_items = noutput_items; //assumption for sync block, this can change + for (unsigned int i = 0; i < tags.size(); i++) { + if (pmt::symbol_to_string(tags[i].key) == d_lengthtagname) { + packet_length = pmt::to_long(tags[i].value); + } + } + assert(packet_length != 0); + + // FIXME run this multiple times if input_items >= N * packet_length + if (noutput_items >= packet_length ) { + // If the message queue is full we drop the packet. + if (!d_msgq->full_p()) { + gr_message_sptr msg = gr_make_message(0, // msg type + d_itemsize, // arg1 for other end + packet_length, // arg2 for other end (redundant) + packet_length * d_itemsize); // len of msg + memcpy(msg->msg(), in, packet_length * d_itemsize); + d_msgq->handle(msg); // send it + } + d_items_read += packet_length; + return packet_length; + } else { + return 0; + } + } else { + // If the queue if full we drop all the data we got. + if (!d_msgq->full_p()) { + // build a message to hold whatever we've got + gr_message_sptr msg = gr_make_message(0, // msg type + d_itemsize, // arg1 for other end + noutput_items, // arg2 for other end (redundant) + noutput_items * d_itemsize); // len of msg + memcpy(msg->msg(), in, noutput_items * d_itemsize); + + d_msgq->handle(msg); // send it + } - return noutput_items; + return noutput_items; + } } } /* namespace blocks */ } /* namespace gr */ + diff --git a/gr-blocks/lib/message_sink_impl.h b/gr-blocks/lib/message_sink_impl.h index a3106bc058..280a46765e 100644 --- a/gr-blocks/lib/message_sink_impl.h +++ b/gr-blocks/lib/message_sink_impl.h @@ -34,9 +34,15 @@ namespace gr { size_t d_itemsize; gr_msg_queue_sptr d_msgq; bool d_dont_block; + bool d_tags; + std::string d_lengthtagname; + uint64_t d_items_read; public: message_sink_impl(size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block); + message_sink_impl(size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block, + const std::string& lengthtagname); + ~message_sink_impl(); int work(int noutput_items, diff --git a/gr-blocks/lib/message_source_impl.cc b/gr-blocks/lib/message_source_impl.cc index cda4fc16c0..818cd336f1 100644 --- a/gr-blocks/lib/message_source_impl.cc +++ b/gr-blocks/lib/message_source_impl.cc @@ -51,12 +51,20 @@ namespace gr { (new message_source_impl(itemsize, msgq)); } + message_source::sptr + message_source::make(size_t itemsize, gr_msg_queue_sptr msgq, + const std::string& lengthtagname) + { + return gnuradio::get_initial_sptr + (new message_source_impl(itemsize, msgq, lengthtagname)); + } + message_source_impl::message_source_impl(size_t itemsize, int msgq_limit) : gr_sync_block("message_source", gr_make_io_signature(0, 0, 0), gr_make_io_signature(1, 1, itemsize)), d_itemsize(itemsize), d_msgq(gr_make_msg_queue(msgq_limit)), - d_msg_offset(0), d_eof(false) + d_msg_offset(0), d_eof(false), d_tags(false) { } @@ -65,7 +73,17 @@ namespace gr { gr_make_io_signature(0, 0, 0), gr_make_io_signature(1, 1, itemsize)), d_itemsize(itemsize), d_msgq(msgq), - d_msg_offset(0), d_eof(false) + d_msg_offset(0), d_eof(false), d_tags(false) + { + } + + message_source_impl::message_source_impl(size_t itemsize, gr_msg_queue_sptr msgq, + const std::string& lengthtagname) + : gr_sync_block("message_source", + gr_make_io_signature(0, 0, 0), + gr_make_io_signature(1, 1, itemsize)), + d_itemsize(itemsize), d_msgq(msgq), d_msg_offset(0), d_eof(false), + d_tags(true), d_lengthtagname(lengthtagname) { } @@ -82,42 +100,48 @@ namespace gr { int nn = 0; while(nn < noutput_items) { - if(d_msg) { - // - // Consume whatever we can from the current message - // - int mm = std::min(noutput_items - nn, - (int)((d_msg->length() - d_msg_offset) / d_itemsize)); - memcpy(out, &(d_msg->msg()[d_msg_offset]), mm * d_itemsize); - - nn += mm; - out += mm * d_itemsize; - d_msg_offset += mm * d_itemsize; - assert(d_msg_offset <= d_msg->length()); - - if(d_msg_offset == d_msg->length()) { - if(d_msg->type() == 1) // type == 1 sets EOF - d_eof = true; - d_msg.reset(); - } - } - else { - // - // No current message - // - if(d_msgq->empty_p() && nn > 0) { // no more messages in the queue, return what we've got - break; - } - - if(d_eof) - return -1; - - d_msg = d_msgq->delete_head(); // block, waiting for a message - d_msg_offset = 0; - - if((d_msg->length() % d_itemsize) != 0) - throw std::runtime_error("msg length is not a multiple of d_itemsize"); - } + if (d_msg){ + // + // Consume whatever we can from the current message + // + int mm = std::min(noutput_items - nn, (int)((d_msg->length() - d_msg_offset) / d_itemsize)); + memcpy (out, &(d_msg->msg()[d_msg_offset]), mm * d_itemsize); + + if (d_tags && (d_msg_offset == 0)) { + const uint64_t offset = this->nitems_written(0) + nn; + pmt::pmt_t key = pmt::string_to_symbol(d_lengthtagname); + pmt::pmt_t value = pmt::from_long(d_msg->length()); + this->add_item_tag(0, offset, key, value); + } + nn += mm; + out += mm * d_itemsize; + d_msg_offset += mm * d_itemsize; + assert(d_msg_offset <= d_msg->length()); + + if (d_msg_offset == d_msg->length()){ + if (d_msg->type() == 1) // type == 1 sets EOF + d_eof = true; + d_msg.reset(); + } + } + else { + // + // No current message + // + if (d_msgq->empty_p() && nn > 0){ // no more messages in the queue, return what we've got + break; + } + + if (d_eof) + return -1; + + d_msg = d_msgq->delete_head(); // block, waiting for a message + d_msg_offset = 0; + + if ((d_msg->length() % d_itemsize) != 0) + throw std::runtime_error("msg length is not a multiple of d_itemsize"); + } + } return nn; diff --git a/gr-blocks/lib/message_source_impl.h b/gr-blocks/lib/message_source_impl.h index c420704478..8fbd209e0a 100644 --- a/gr-blocks/lib/message_source_impl.h +++ b/gr-blocks/lib/message_source_impl.h @@ -37,10 +37,16 @@ namespace gr { gr_message_sptr d_msg; unsigned d_msg_offset; bool d_eof; + bool d_tags; + // FIXME: Is this adequate tagname length. + std::string d_lengthtagname; public: message_source_impl(size_t itemsize, int msgq_limit); message_source_impl(size_t itemsize, gr_msg_queue_sptr msgq); + message_source_impl(size_t itemsize, gr_msg_queue_sptr msgq, + const std::string& lengthtagname); + ~message_source_impl(); gr_msg_queue_sptr msgq() const { return d_msgq; } diff --git a/gr-blocks/lib/pdu.cc b/gr-blocks/lib/pdu.cc index 41a2d88c3a..ae4b17aecc 100644 --- a/gr-blocks/lib/pdu.cc +++ b/gr-blocks/lib/pdu.cc @@ -50,11 +50,11 @@ namespace gr { { switch(type) { case byte_t: - return pmt::pmt_is_u8vector(v); + return pmt::is_u8vector(v); case float_t: - return pmt::pmt_is_f32vector(v); + return pmt::is_f32vector(v); case complex_t: - return pmt::pmt_is_c32vector(v); + return pmt::is_c32vector(v); default: throw std::runtime_error("bad PDU type"); } @@ -65,11 +65,11 @@ namespace gr { { switch(type) { case byte_t: - return pmt::pmt_init_u8vector(items, buf); + return pmt::init_u8vector(items, buf); case float_t: - return pmt::pmt_init_f32vector(items, (const float *)buf); + return pmt::init_f32vector(items, (const float *)buf); case complex_t: - return pmt::pmt_init_c32vector(items, (const gr_complex *)buf); + return pmt::init_c32vector(items, (const gr_complex *)buf); default: throw std::runtime_error("bad PDU type"); } @@ -78,11 +78,11 @@ namespace gr { vector_type type_from_pmt(pmt::pmt_t vector) { - if(pmt_is_u8vector(vector)) + if(pmt::is_u8vector(vector)) return byte_t; - if(pmt_is_f32vector(vector)) + if(pmt::is_f32vector(vector)) return float_t; - if(pmt_is_c32vector(vector)) + if(pmt::is_c32vector(vector)) return complex_t; throw std::runtime_error("bad PDU type"); } diff --git a/gr-blocks/lib/pdu_to_tagged_stream_impl.cc b/gr-blocks/lib/pdu_to_tagged_stream_impl.cc index 80785b4781..1fc4857f2e 100644 --- a/gr-blocks/lib/pdu_to_tagged_stream_impl.cc +++ b/gr-blocks/lib/pdu_to_tagged_stream_impl.cc @@ -73,43 +73,43 @@ namespace gr { return nout; // make sure type is valid - if (!pmt::pmt_is_pair(msg)) // TODO: implement pdu::is_valid() + if (!pmt::is_pair(msg)) // TODO: implement pdu::is_valid() throw std::runtime_error("received a malformed pdu message"); // grab the components of the pdu message - pmt::pmt_t meta(pmt::pmt_car(msg)); - pmt::pmt_t vect(pmt::pmt_cdr(msg)); + pmt::pmt_t meta(pmt::car(msg)); + pmt::pmt_t vect(pmt::cdr(msg)); // compute offset for output tag uint64_t offset = nitems_written(0) + nout; // add a tag for pdu length - add_item_tag(0, offset, PDU_LENGTH_TAG, pmt::pmt_from_long(pmt::pmt_length(vect)), pmt::mp(alias())); + add_item_tag(0, offset, PDU_LENGTH_TAG, pmt::from_long(pmt::length(vect)), pmt::mp(alias())); // if we recieved metadata add it as tags - if (!pmt_eq(meta, pmt::PMT_NIL) ) { - pmt::pmt_t pair(pmt::pmt_dict_keys(meta)); + if (!pmt::eq(meta, pmt::PMT_NIL) ) { + pmt::pmt_t pair(pmt::dict_keys(meta)); - while (!pmt_eq(pair, pmt::PMT_NIL) ) { - pmt::pmt_t k(pmt::pmt_cdr(pair)); - pmt::pmt_t v(pmt::pmt_dict_ref(meta, k, pmt::PMT_NIL)); + while (!pmt::eq(pair, pmt::PMT_NIL) ) { + pmt::pmt_t k(pmt::cdr(pair)); + pmt::pmt_t v(pmt::dict_ref(meta, k, pmt::PMT_NIL)); add_item_tag(0, offset, k, v, pmt::mp(alias())); } } // copy vector output - size_t ncopy = std::min((size_t)noutput_items, (size_t)pmt::pmt_length(vect)); - size_t nsave = pmt::pmt_length(vect) - ncopy; + size_t ncopy = std::min((size_t)noutput_items, (size_t)pmt::length(vect)); + size_t nsave = pmt::length(vect) - ncopy; // copy output size_t io(0); nout += ncopy; - memcpy(out, pmt_uniform_vector_elements(vect,io), ncopy*d_itemsize); + memcpy(out, uniform_vector_elements(vect,io), ncopy*d_itemsize); // save leftover items if needed for next work call if (nsave > 0) { d_remain.resize(nsave*d_itemsize, 0); - memcpy(&d_remain[0], pmt_uniform_vector_elements(vect,ncopy), nsave*d_itemsize); + memcpy(&d_remain[0], uniform_vector_elements(vect,ncopy), nsave*d_itemsize); } } diff --git a/gr-blocks/lib/random_pdu_impl.cc b/gr-blocks/lib/random_pdu_impl.cc new file mode 100644 index 0000000000..0b194a0537 --- /dev/null +++ b/gr-blocks/lib/random_pdu_impl.cc @@ -0,0 +1,80 @@ +/* -*- c++ -*- */ +/* + * Copyright 2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio 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. + * + * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "random_pdu_impl.h" +#include <gr_io_signature.h> +#include <blocks/pdu.h> + +namespace gr { + namespace blocks { + + random_pdu::sptr + random_pdu::make(int min_items, int max_items) + { + return gnuradio::get_initial_sptr(new random_pdu_impl(min_items, max_items)); + } + + random_pdu_impl::random_pdu_impl(int min_items, int max_items) + : gr_block("random_pdu", + gr_make_io_signature (0, 0, 0), + gr_make_io_signature (0, 0, 0)), + d_urange(min_items, max_items), + d_brange(0, 255), + d_rvar(d_rng, d_urange), + d_bvar(d_rng, d_brange) + { + message_port_register_out(PDU_PORT_ID); + message_port_register_in(pmt::mp("generate")); + set_msg_handler(pmt::mp("generate"), boost::bind(&random_pdu_impl::generate_pdu, this, _1)); + } + + bool + random_pdu_impl::start() + { + output_random(); + return true; + } + + void + random_pdu_impl::output_random() + { + // pick a random vector length + int len = d_rvar(); + + // fill it with random bytes + std::vector<unsigned char> vec; + for (int i=0; i<len; i++) + vec.push_back((unsigned char) d_bvar()); + + // send the vector + pmt::pmt_t vecpmt(pmt::make_blob(&vec[0], len)); + pmt::pmt_t pdu(pmt::cons(pmt::PMT_NIL, vecpmt)); + + message_port_pub(PDU_PORT_ID, pdu); + } + + } /* namespace blocks */ +}/* namespace gr */ diff --git a/gr-blocks/lib/random_pdu_impl.h b/gr-blocks/lib/random_pdu_impl.h new file mode 100644 index 0000000000..3197f740a0 --- /dev/null +++ b/gr-blocks/lib/random_pdu_impl.h @@ -0,0 +1,54 @@ +/* -*- c++ -*- */ +/* + * Copyright 2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio 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. + * + * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_BLOCKS_SOCKET_PDU_IMPL_H +#define INCLUDED_BLOCKS_RANDOM_PDU_IMPL_H + +#include <blocks/random_pdu.h> +#include <boost/random.hpp> +#include <boost/generator_iterator.hpp> + +namespace gr { + namespace blocks { + + class random_pdu_impl : public random_pdu + { + private: + boost::mt19937 d_rng; + boost::uniform_int<> d_urange; + boost::uniform_int<> d_brange; + boost::variate_generator< boost::mt19937, boost::uniform_int<> > d_rvar; // pdu length + boost::variate_generator< boost::mt19937, boost::uniform_int<> > d_bvar; // pdu contents + + public: + random_pdu_impl(int min_items, int max_items); + + bool start(); + void output_random(); + void generate_pdu(pmt::pmt_t msg) { output_random(); } + void generate_pdu() { output_random(); } + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_BLOCKS_RANDOM_PDU_IMPL_H */ diff --git a/gr-blocks/lib/rms_cf_impl.cc b/gr-blocks/lib/rms_cf_impl.cc index d956b45f1a..9b2c031e10 100644 --- a/gr-blocks/lib/rms_cf_impl.cc +++ b/gr-blocks/lib/rms_cf_impl.cc @@ -38,12 +38,12 @@ namespace gr { (new rms_cf_impl(alpha)); } - rms_cf_impl::rms_cf_impl (double alpha) + rms_cf_impl::rms_cf_impl(double alpha) : gr_sync_block("rms_cf", gr_make_io_signature(1, 1, sizeof(gr_complex)), - gr_make_io_signature(1, 1, sizeof(float))), - d_iir(alpha) + gr_make_io_signature(1, 1, sizeof(float))) { + set_alpha(alpha); } rms_cf_impl::~rms_cf_impl() @@ -53,7 +53,9 @@ namespace gr { void rms_cf_impl::set_alpha(double alpha) { - d_iir.set_taps(alpha); + d_alpha = alpha; + d_beta = 1 - d_alpha; + d_avg = 0; } int @@ -66,8 +68,8 @@ namespace gr { for(int i = 0; i < noutput_items; i++) { double mag_sqrd = in[i].real()*in[i].real() + in[i].imag()*in[i].imag(); - double f = d_iir.filter(mag_sqrd); - out[i] = sqrt(f); + d_avg = d_beta*d_avg + d_alpha*mag_sqrd; + out[i] = sqrt(d_avg); } return noutput_items; diff --git a/gr-blocks/lib/rms_cf_impl.h b/gr-blocks/lib/rms_cf_impl.h index 438b8549db..316ab2f304 100644 --- a/gr-blocks/lib/rms_cf_impl.h +++ b/gr-blocks/lib/rms_cf_impl.h @@ -24,7 +24,6 @@ #define INCLUDED_BLOCKS_RMS_CF_IMPL_H #include <blocks/rms_cf.h> -#include <gr_single_pole_iir.h> namespace gr { namespace blocks { @@ -36,7 +35,7 @@ namespace gr { class rms_cf_impl : public rms_cf { private: - gr_single_pole_iir<double,double,double> d_iir; + double d_alpha, d_beta, d_avg; public: rms_cf_impl(double alpha = 0.0001); diff --git a/gr-blocks/lib/rms_ff_impl.cc b/gr-blocks/lib/rms_ff_impl.cc index 2b8cdc34e7..8e004ad61e 100644 --- a/gr-blocks/lib/rms_ff_impl.cc +++ b/gr-blocks/lib/rms_ff_impl.cc @@ -41,9 +41,9 @@ namespace gr { rms_ff_impl::rms_ff_impl(double alpha) : gr_sync_block("rms_ff", gr_make_io_signature(1, 1, sizeof(float)), - gr_make_io_signature(1, 1, sizeof(float))), - d_iir(alpha) + gr_make_io_signature(1, 1, sizeof(float))) { + set_alpha(alpha); } rms_ff_impl::~rms_ff_impl() @@ -53,7 +53,9 @@ namespace gr { void rms_ff_impl::set_alpha(double alpha) { - d_iir.set_taps(alpha); + d_alpha = alpha; + d_beta = 1 - d_alpha; + d_avg = 0; } int @@ -66,8 +68,8 @@ namespace gr { for(int i = 0; i < noutput_items; i++) { double mag_sqrd = in[i]*in[i]; - double f = d_iir.filter(mag_sqrd); - out[i] = sqrt(f); + d_avg = d_beta*d_avg + d_alpha*mag_sqrd; + out[i] = sqrt(d_avg); } return noutput_items; diff --git a/gr-blocks/lib/rms_ff_impl.h b/gr-blocks/lib/rms_ff_impl.h index 82ecbda52d..34d7d986c0 100644 --- a/gr-blocks/lib/rms_ff_impl.h +++ b/gr-blocks/lib/rms_ff_impl.h @@ -24,7 +24,6 @@ #define INCLUDED_BLOCKS_RMS_FF_IMPL_H #include <blocks/rms_ff.h> -#include <gr_single_pole_iir.h> namespace gr { namespace blocks { @@ -36,7 +35,7 @@ namespace gr { class rms_ff_impl : public rms_ff { private: - gr_single_pole_iir<double,double,double> d_iir; + double d_alpha, d_beta, d_avg; public: rms_ff_impl(double alpha = 0.0001); diff --git a/gr-blocks/lib/socket_pdu_impl.cc b/gr-blocks/lib/socket_pdu_impl.cc index 0a48c2b9f4..4ff5ce6eb9 100644 --- a/gr-blocks/lib/socket_pdu_impl.cc +++ b/gr-blocks/lib/socket_pdu_impl.cc @@ -27,7 +27,7 @@ #include "socket_pdu_impl.h" #include "tcp_connection.h" #include <gr_io_signature.h> -#include <gr_pdu.h> +#include <blocks/pdu.h> namespace gr { namespace blocks { @@ -112,8 +112,8 @@ namespace gr { socket_pdu_impl::handle_tcp_read(const boost::system::error_code& error, size_t bytes_transferred) { if (!error) { - pmt::pmt_t vector = pmt::pmt_init_u8vector(bytes_transferred, (const uint8_t *)&d_rxbuf[0]); - pmt::pmt_t pdu = pmt::pmt_cons(pmt::PMT_NIL, vector); + pmt::pmt_t vector = pmt::init_u8vector(bytes_transferred, (const uint8_t *)&d_rxbuf[0]); + pmt::pmt_t pdu = pmt::cons(pmt::PMT_NIL, vector); message_port_pub(PDU_PORT_ID, pdu); d_tcp_socket->async_read_some(boost::asio::buffer(d_rxbuf), @@ -138,7 +138,7 @@ namespace gr { void socket_pdu_impl::tcp_server_send(pmt::pmt_t msg) { - pmt::pmt_t vector = pmt::pmt_cdr(msg); + pmt::pmt_t vector = pmt::cdr(msg); for(size_t i = 0; i < d_tcp_connections.size(); i++) d_tcp_connections[i]->send(vector); } @@ -158,22 +158,22 @@ namespace gr { void socket_pdu_impl::tcp_client_send(pmt::pmt_t msg) { - pmt::pmt_t vector = pmt::pmt_cdr(msg); - size_t len = pmt::pmt_length(vector); + pmt::pmt_t vector = pmt::cdr(msg); + size_t len = pmt::length(vector); size_t offset(0); boost::array<char, 10000> txbuf; - memcpy(&txbuf[0], pmt::pmt_uniform_vector_elements(vector, offset), len); + memcpy(&txbuf[0], pmt::uniform_vector_elements(vector, offset), len); d_tcp_socket->send(boost::asio::buffer(txbuf,len)); } void socket_pdu_impl::udp_send(pmt::pmt_t msg) { - pmt::pmt_t vector = pmt::pmt_cdr(msg); - size_t len = pmt::pmt_length(vector); + pmt::pmt_t vector = pmt::cdr(msg); + size_t len = pmt::length(vector); size_t offset(0); boost::array<char, 10000> txbuf; - memcpy(&txbuf[0], pmt::pmt_uniform_vector_elements(vector, offset), len); + memcpy(&txbuf[0], pmt::uniform_vector_elements(vector, offset), len); if (d_udp_endpoint_other.address().to_string() != "0.0.0.0") d_udp_socket->send_to(boost::asio::buffer(txbuf,len), d_udp_endpoint_other); } @@ -182,8 +182,8 @@ namespace gr { socket_pdu_impl::handle_udp_read(const boost::system::error_code& error, size_t bytes_transferred) { if (!error) { - pmt::pmt_t vector = pmt::pmt_init_u8vector(bytes_transferred, (const uint8_t*)&d_rxbuf[0]); - pmt::pmt_t pdu = pmt::pmt_cons( pmt::PMT_NIL, vector); + pmt::pmt_t vector = pmt::init_u8vector(bytes_transferred, (const uint8_t*)&d_rxbuf[0]); + pmt::pmt_t pdu = pmt::cons( pmt::PMT_NIL, vector); message_port_pub(PDU_PORT_ID, pdu); diff --git a/gr-blocks/lib/stream_pdu_base.cc b/gr-blocks/lib/stream_pdu_base.cc index 21fbb5eabe..0c4e7e0863 100644 --- a/gr-blocks/lib/stream_pdu_base.cc +++ b/gr-blocks/lib/stream_pdu_base.cc @@ -87,8 +87,8 @@ namespace gr { if (result <= 0) throw std::runtime_error("stream_pdu_base, bad socket read!"); - pmt::pmt_t vector = pmt::pmt_init_u8vector(result, &d_rxbuf[0]); - pmt::pmt_t pdu = pmt::pmt_cons(pmt::PMT_NIL, vector); + pmt::pmt_t vector = pmt::init_u8vector(result, &d_rxbuf[0]); + pmt::pmt_t pdu = pmt::cons(pmt::PMT_NIL, vector); d_blk->message_port_pub(d_port, pdu); } @@ -114,12 +114,12 @@ namespace gr { void stream_pdu_base::send(pmt::pmt_t msg) { - pmt::pmt_t vector = pmt::pmt_cdr(msg); + pmt::pmt_t vector = pmt::cdr(msg); size_t offset(0); size_t itemsize(pdu::itemsize(pdu::type_from_pmt(vector))); - int len(pmt::pmt_length(vector)*itemsize); + int len(pmt::length(vector)*itemsize); - const int rv = write(d_fd, pmt::pmt_uniform_vector_elements(vector, offset), len); + const int rv = write(d_fd, pmt::uniform_vector_elements(vector, offset), len); if (rv != len) { std::cerr << boost::format("WARNING: stream_pdu_base::send(pdu) write failed! (d_fd=%d, len=%d, rv=%d)") % d_fd % len % rv << std::endl; diff --git a/gr-blocks/lib/tag_debug_impl.cc b/gr-blocks/lib/tag_debug_impl.cc index a216879637..c595d41db5 100644 --- a/gr-blocks/lib/tag_debug_impl.cc +++ b/gr-blocks/lib/tag_debug_impl.cc @@ -95,8 +95,8 @@ namespace gr { for(d_tags_itr = d_tags.begin(); d_tags_itr != d_tags.end(); d_tags_itr++) { sout << std::setw(10) << "Offset: " << d_tags_itr->offset << std::setw(10) << "Source: " - << (pmt::pmt_is_symbol(d_tags_itr->srcid) ? pmt::pmt_symbol_to_string(d_tags_itr->srcid) : "n/a") - << std::setw(10) << "Key: " << pmt::pmt_symbol_to_string(d_tags_itr->key) + << (pmt::is_symbol(d_tags_itr->srcid) ? pmt::symbol_to_string(d_tags_itr->srcid) : "n/a") + << std::setw(10) << "Key: " << pmt::symbol_to_string(d_tags_itr->key) << std::setw(10) << "Value: "; sout << d_tags_itr->value << std::endl; } diff --git a/gr-blocks/lib/tagged_file_sink_impl.cc b/gr-blocks/lib/tagged_file_sink_impl.cc index a2e9ab3853..7d011e45f0 100644 --- a/gr-blocks/lib/tagged_file_sink_impl.cc +++ b/gr-blocks/lib/tagged_file_sink_impl.cc @@ -84,8 +84,8 @@ namespace gr { uint64_t start_N = nitems_read(0); uint64_t end_N = start_N + (uint64_t)(noutput_items); - pmt::pmt_t bkey = pmt::pmt_string_to_symbol("burst"); - pmt::pmt_t tkey = pmt::pmt_string_to_symbol("rx_time"); // use gr_tags::key_time + pmt::pmt_t bkey = pmt::string_to_symbol("burst"); + pmt::pmt_t tkey = pmt::string_to_symbol("rx_time"); // use gr_tags::key_time std::vector<gr_tag_t> all_tags; get_tags_in_range(all_tags, 0, start_N, end_N); @@ -101,8 +101,8 @@ namespace gr { const gr_tag_t tag = time_tags_outer[0]; uint64_t offset = tag.offset; pmt::pmt_t time = tag.value; - uint64_t tsecs = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(time, 0)); - double tfrac = pmt::pmt_to_double(pmt::pmt_tuple_ref(time, 1)); + uint64_t tsecs = pmt::to_uint64(pmt::tuple_ref(time, 0)); + double tfrac = pmt::to_double(pmt::tuple_ref(time, 1)); double delta = (double)offset / d_sample_rate; d_timeval = (double)tsecs + tfrac + delta; d_last_N = offset; @@ -112,8 +112,8 @@ namespace gr { while(idx < noutput_items) { if(d_state == NOT_IN_BURST) { while(vitr != all_tags.end()) { - if((pmt::pmt_eqv((*vitr).key, bkey)) && - pmt::pmt_is_true((*vitr).value)) { + if((pmt::eqv((*vitr).key, bkey)) && + pmt::is_true((*vitr).value)) { uint64_t N = (*vitr).offset; idx = (int)(N - start_N); @@ -133,8 +133,8 @@ namespace gr { // Get time based on last time tag from USRP pmt::pmt_t time = tag.value; - uint64_t tsecs = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(time, 0)); - double tfrac = pmt::pmt_to_double(pmt::pmt_tuple_ref(time, 1)); + uint64_t tsecs = pmt::to_uint64(pmt::tuple_ref(time, 0)); + double tfrac = pmt::to_double(pmt::tuple_ref(time, 1)); // Get new time from last time tag + difference in time to when // burst tag occured based on the sample rate @@ -190,8 +190,8 @@ namespace gr { } else { // In burst while(vitr != all_tags.end()) { - if((pmt::pmt_eqv((*vitr).key, bkey)) && - pmt::pmt_is_false((*vitr).value)) { + if((pmt::eqv((*vitr).key, bkey)) && + pmt::is_false((*vitr).value)) { uint64_t N = (*vitr).offset; idx_stop = (int)N - start_N; diff --git a/gr-blocks/lib/tagged_stream_to_pdu_impl.cc b/gr-blocks/lib/tagged_stream_to_pdu_impl.cc index acd07292f4..fc5c8f6424 100644 --- a/gr-blocks/lib/tagged_stream_to_pdu_impl.cc +++ b/gr-blocks/lib/tagged_stream_to_pdu_impl.cc @@ -65,15 +65,15 @@ namespace gr { get_tags_in_range(d_tags, 0, abs_N, abs_N+1); for (d_tags_itr = d_tags.begin(); (d_tags_itr != d_tags.end()) && (!found_length_tag); d_tags_itr++) { - if (pmt::pmt_equal((*d_tags_itr).key, PDU_LENGTH_TAG )) { + if (pmt::eq((*d_tags_itr).key, PDU_LENGTH_TAG )) { if ((*d_tags_itr).offset != abs_N ) throw std::runtime_error("expected next pdu length tag on a different item..."); found_length_tag = true; - d_pdu_length = pmt::pmt_to_long((*d_tags_itr).value); + d_pdu_length = pmt::to_long((*d_tags_itr).value); d_pdu_remain = d_pdu_length; - d_pdu_meta = pmt::pmt_make_dict(); + d_pdu_meta = pmt::make_dict(); break; } // if have length tag } // iter over tags @@ -87,8 +87,8 @@ namespace gr { // copy any tags in this range into our meta object get_tags_in_range(d_tags, 0, abs_N, abs_N+ncopy); for (d_tags_itr = d_tags.begin(); d_tags_itr != d_tags.end(); d_tags_itr++) - if(!pmt_equal((*d_tags_itr).key, PDU_LENGTH_TAG )) - d_pdu_meta = pmt_dict_add(d_pdu_meta, (*d_tags_itr).key, (*d_tags_itr).value); + if(!pmt::eq((*d_tags_itr).key, PDU_LENGTH_TAG )) + d_pdu_meta = dict_add(d_pdu_meta, (*d_tags_itr).key, (*d_tags_itr).value); // copy samples for this vector into either a pmt or our save buffer if (ncopy == d_pdu_remain) { // we will send this pdu @@ -119,10 +119,10 @@ namespace gr { void tagged_stream_to_pdu_impl::send_message() { - if (pmt::pmt_length(d_pdu_vector) != d_pdu_length) + if (pmt::length(d_pdu_vector) != d_pdu_length) throw std::runtime_error("msg length not correct"); - pmt::pmt_t msg = pmt::pmt_cons(d_pdu_meta, d_pdu_vector); + pmt::pmt_t msg = pmt::cons(d_pdu_meta, d_pdu_vector); message_port_pub(PDU_PORT_ID, msg); d_pdu_meta = pmt::PMT_NIL; diff --git a/gr-blocks/lib/tcp_connection.cc b/gr-blocks/lib/tcp_connection.cc index 4ead6442d8..33bb6f10f1 100644 --- a/gr-blocks/lib/tcp_connection.cc +++ b/gr-blocks/lib/tcp_connection.cc @@ -26,9 +26,7 @@ #include "tcp_connection.h" #include <gr_basic_block.h> -#include <gr_pdu.h> -//#include <boost/asio.hpp> -//#include <boost/bind.hpp> +#include <blocks/pdu.h> namespace gr { namespace blocks { @@ -46,10 +44,10 @@ namespace gr { void tcp_connection::send(pmt::pmt_t vector) { - size_t len = pmt::pmt_length(vector); + size_t len = pmt::length(vector); size_t offset(0); boost::array<char, 10000> txbuf; - memcpy(&txbuf[0], pmt::pmt_uniform_vector_elements(vector, offset), len); + memcpy(&txbuf[0], pmt::uniform_vector_elements(vector, offset), len); boost::asio::async_write(d_socket, boost::asio::buffer(txbuf, len), boost::bind(&tcp_connection::handle_write, this, boost::asio::placeholders::error, @@ -70,8 +68,8 @@ namespace gr { tcp_connection::handle_read(const boost::system::error_code& error, size_t bytes_transferred) { if (!error) { - pmt::pmt_t vector = pmt::pmt_init_u8vector(bytes_transferred, (const uint8_t*)&d_buf[0]); - pmt::pmt_t pdu = pmt::pmt_cons( pmt::PMT_NIL, vector); + pmt::pmt_t vector = pmt::init_u8vector(bytes_transferred, (const uint8_t*)&d_buf[0]); + pmt::pmt_t pdu = pmt::cons( pmt::PMT_NIL, vector); d_block->message_port_pub(PDU_PORT_ID, pdu); diff --git a/gr-blocks/lib/throttle_impl.cc b/gr-blocks/lib/throttle_impl.cc index 49743e3f26..b1cfe4b3c8 100644 --- a/gr-blocks/lib/throttle_impl.cc +++ b/gr-blocks/lib/throttle_impl.cc @@ -93,5 +93,25 @@ namespace gr { return noutput_items; } + void + throttle_impl::setup_rpc() + { +#ifdef GR_CTRLPORT + d_rpc_vars.push_back( + rpcbasic_sptr(new rpcbasic_register_get<throttle, double>( + alias(), "sample_rate", &throttle::sample_rate, + pmt::mp(0.0), pmt::mp(100.0e6), pmt::mp(0.0), + "Hz", "Sample Rate", RPC_PRIVLVL_MIN, + DISPTIME | DISPOPTSTRIP))); + + d_rpc_vars.push_back( + rpcbasic_sptr(new rpcbasic_register_set<throttle, double>( + alias(), "sample_rate", &throttle::set_sample_rate, + pmt::mp(0.0), pmt::mp(100.0e6), pmt::mp(0.0), + "Hz", "Sample Rate", RPC_PRIVLVL_MIN, + DISPTIME | DISPOPTSTRIP))); +#endif /* GR_CTRLPORT */ + } + } /* namespace blocks */ } /* namespace gr */ diff --git a/gr-blocks/lib/throttle_impl.h b/gr-blocks/lib/throttle_impl.h index 86dbef2ac9..2f2cdf108b 100644 --- a/gr-blocks/lib/throttle_impl.h +++ b/gr-blocks/lib/throttle_impl.h @@ -40,6 +40,8 @@ namespace gr { throttle_impl(size_t itemsize, double samples_per_sec); ~throttle_impl(); + void setup_rpc(); + void set_sample_rate(double rate); double sample_rate() const; diff --git a/gr-blocks/lib/wavfile_sink_impl.h b/gr-blocks/lib/wavfile_sink_impl.h index 8a364f2b90..4ad9958884 100644 --- a/gr-blocks/lib/wavfile_sink_impl.h +++ b/gr-blocks/lib/wavfile_sink_impl.h @@ -24,7 +24,6 @@ #define INCLUDED_GR_WAVFILE_SINK_IMPL_H #include <blocks/wavfile_sink.h> -#include <gr_file_sink_base.h> namespace gr { namespace blocks { |