Skip to content

Commit

Permalink
orgainzed more stuff. Tests failing probably due to gnuradio's stubbo…
Browse files Browse the repository at this point in the history
…rn not-enough-samples issue. Added temporary patch for that but further investigation is required
  • Loading branch information
swarnavaghosh04 committed Aug 25, 2023
1 parent 82afda2 commit d6b05b0
Show file tree
Hide file tree
Showing 15 changed files with 189 additions and 119 deletions.
1 change: 1 addition & 0 deletions Testing/Temporary/CTestCostData.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
3 changes: 3 additions & 0 deletions Testing/Temporary/LastTest.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Start testing: Aug 24 20:30 EDT
----------------------------------------------------------
End testing: Aug 24 20:30 EDT
2 changes: 1 addition & 1 deletion grc/UTAT_HERON_esttc_deframer.block.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ parameters:
- id: samp_rate
label: Sample Rate
dtype: float
default: 48e3
default: samp_rate
#- id: ...
# label: ...
# dtype: ...
Expand Down
1 change: 1 addition & 0 deletions include/gnuradio/UTAT_HERON/header_format_esttc.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class UTAT_HERON_API header_format_esttc : public gr::digital::header_format_def
std::vector<pmt::pmt_t>& info,
int& nbits_processed) override;
size_t header_nbits() const override;
size_t header_nbits_without_access_code() const;
protected:
int d_trailer_nbits;
void enter_have_sync() override;
Expand Down
4 changes: 4 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ list(APPEND UTAT_HERON_sources
utils/heron_packet.h
utils/debug_logger.cc
utils/debug_logger.h
utils/pdu_lambda.h
utils/pdu_lambda.cc
utils/common.h
utils/common.cc
heron_rx_bb_impl.cc
heron_rx_bb_impl.h
header_format_esttc.cc
Expand Down
142 changes: 41 additions & 101 deletions lib/esttc_deframer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/

#include "esttc_deframer_impl.h"
#include "utils/pdu_lambda.h"
#include "utils/common.h"
#include <gnuradio/io_signature.h>

#include <gnuradio/UTAT_HERON/header_format_esttc.h>
Expand All @@ -25,96 +27,23 @@ esttc_deframer::sptr esttc_deframer::make(float samp_rate)
return gnuradio::make_block_sptr<esttc_deframer_impl>(samp_rate);
}

class prepend_length : public gr::sync_block{

private:
int skip_bytes;
void handle_msg(const pmt::pmt_t& pdu){
auto data = pmt::u8vector_elements(pmt::cdr(pdu));
auto start = data.begin();
data.insert(start, data.size()-skip_bytes);
auto new_cdr = pmt::init_u8vector(data.size(), data);
auto new_pdu = pmt::cons(pmt::car(pdu), new_cdr);
message_port_pub(pmt::intern("pdu_out"), new_pdu);
}
public:

prepend_length(int skip_bytes=0):
gr::sync_block(
"prepend_length",
gr::io_signature::make(0,0,0),
gr::io_signature::make(0,0,0)
),
skip_bytes(skip_bytes)
{
message_port_register_in(pmt::intern("pdu_in"));
message_port_register_out(pmt::intern("pdu_out"));

set_msg_handler(pmt::intern("pdu_in"), [this](const pmt::pmt_t& pdu){
this->handle_msg(pdu);
});
}

int work(
int noutput_items,
gr_vector_const_void_star& input_items,
gr_vector_void_star& output_items
) override
{
return 0;
}

typedef std::shared_ptr<prepend_length> sptr;

static sptr make(int skip_bytes=0){
return gnuradio::make_block_sptr<prepend_length>(skip_bytes);
}
};

class strip_prepended_length : public gr::sync_block{
private:
void handle_msg(const pmt::pmt_t& pdu){
auto data = pmt::u8vector_elements(pmt::cdr(pdu));
auto start = data.begin();
auto end = data.end();
data = std::vector<uint8_t>(start+1, end);
auto new_cdr = pmt::init_u8vector(data.size(), data);
auto new_pdu = pmt::cons(pmt::car(pdu), new_cdr);
message_port_pub(pmt::intern("pdu_out"), new_pdu);
}
public:

strip_prepended_length():
gr::sync_block(
"strip_prepended_length",
gr::io_signature::make(0,0,0),
gr::io_signature::make(0,0,0)
)
{
message_port_register_in(pmt::intern("pdu_in"));
message_port_register_out(pmt::intern("pdu_out"));

set_msg_handler(pmt::intern("pdu_in"), [this](const pmt::pmt_t& pdu){
this->handle_msg(pdu);
});
}

int work(
int noutput_items,
gr_vector_const_void_star& input_items,
gr_vector_void_star& output_items
) override
{
return 0;
}

typedef std::shared_ptr<strip_prepended_length> sptr;

static sptr make(){
return gnuradio::make_block_sptr<strip_prepended_length>();
}
void prepend_len_minus_crc_bytes(pmt::pmt_t pdu){
auto data = pmt::u8vector_elements(pmt::cdr(pdu));
auto start = data.begin();
uint8_t crc_nbytes = utils::crc::num_bits/8;
data.insert(start, data.size()-crc_nbytes);
auto new_cdr = pmt::init_u8vector(data.size(), data);
pmt::set_cdr(pdu, new_cdr);
}

};
void strip_prepended_len(pmt::pmt_t pdu){
auto data = pmt::u8vector_elements(pmt::cdr(pdu));
auto start = data.begin();
auto end = data.end();
data = std::vector<uint8_t>(start+1, end);
auto new_cdr = pmt::init_u8vector(data.size(), data.data());
pmt::set_cdr(pdu, new_cdr);
}


/*
Expand All @@ -126,21 +55,28 @@ esttc_deframer_impl::esttc_deframer_impl(float samp_rate)
gr::io_signature::make(0, 0, 0))
{

message_port_register_hier_out(pmt::intern("crc_ok"));
message_port_register_hier_out(pmt::intern("crc_fail"));
message_port_register_hier_out(pmt::mp("crc_ok"));
message_port_register_hier_out(pmt::mp("crc_fail"));

auto access_code = "101010101010101010101010101010101010101001111110";

auto hdr_format = UTAT_HERON::header_format_esttc::make(access_code, 3, 1, 16);
auto find_access_code = gr::digital::correlate_access_code_tag_bb::make(&access_code[8], 0, "time_est");
auto hdr_payload_demux = gr::digital::header_payload_demux::make(8, 1, 0, "payload symbols", "time_est", false, sizeof(uint8_t), "rx_time", samp_rate);
auto hdr_format = UTAT_HERON::header_format_esttc::make(utils::access_code, 3, 1, utils::crc::num_bits);
auto find_access_code = gr::digital::correlate_access_code_tag_bb::make(utils::trimmed_access_code, 0, "time_est");
auto hdr_payload_demux = gr::digital::header_payload_demux::make(
hdr_format->header_nbits_without_access_code(),
1, 0, "payload symbols", "time_est", false, sizeof(uint8_t), "", samp_rate);
auto parser = gr::digital::protocol_parser_b::make(hdr_format);
auto pack_bits = gr::blocks::repack_bits_bb::make(1, 8, "", false, gr::GR_MSB_FIRST);
auto scale_length = gr::blocks::tagged_stream_multiply_length::make(sizeof(uint8_t), "payload symbols", 1./8);
auto stream_to_pdu = gr::pdu::tagged_stream_to_pdu::make(gr::types::byte_t, "payload symbols");
auto prepend_length = prepend_length::make(2);
auto crc = gr::digital::crc_check::make(16, 0x1021, 0xFFFF, 0x0000, false, false, false, true, 0);
auto strip_prepended_len = strip_prepended_length::make();
auto prepend_length = utils::pdu_lambda::make(prepend_len_minus_crc_bytes);
auto crc = gr::digital::crc_check::make(
utils::crc::num_bits,
utils::crc::poly,
utils::crc::inital_value,
utils::crc::final_xor,
utils::crc::input_reflected,
utils::crc::result_reflected,
false, true, 0);
auto strip_prepended_length = utils::pdu_lambda::make(strip_prepended_len);

connect(self(), 0, find_access_code, 0);
connect(find_access_code, 0, hdr_payload_demux, 0);
Expand All @@ -151,10 +87,14 @@ esttc_deframer_impl::esttc_deframer_impl(float samp_rate)
connect(scale_length, 0, stream_to_pdu, 0);
msg_connect(stream_to_pdu, "pdus", prepend_length, "pdu_in");
msg_connect(prepend_length, "pdu_out", crc, "in");
msg_connect(crc, "ok", strip_prepended_len, "pdu_in");
msg_connect(crc, "ok", strip_prepended_length, "pdu_in");
msg_connect(crc, "fail", self(), "crc_fail");
msg_connect(strip_prepended_len, "pdu_out", self(), "crc_ok");
msg_connect(strip_prepended_length, "pdu_out", self(), "crc_ok");

// msg_connect(stream_to_pdu, "pdus", crc, "in");
// msg_connect(crc, "ok", self(), "crc_ok");
// msg_connect(crc, "fail", self(), "crc_fail");

}

/*
Expand Down
18 changes: 12 additions & 6 deletions lib/esttc_framer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include "esttc_framer_impl.h"
#include "utils/common.h"
#include <gnuradio/io_signature.h>

#include <gnuradio/UTAT_HERON/header_format_esttc.h>
Expand Down Expand Up @@ -33,18 +34,23 @@ esttc_framer_impl::esttc_framer_impl()
gr::io_signature::make(0,0,0),
gr::io_signature::make(0,0,0))
{
message_port_register_hier_in(pmt::intern("pdu_in"));
message_port_register_hier_out(pmt::intern("pdu_out"));
message_port_register_hier_in(pmt::mp("pdu_in"));
message_port_register_hier_out(pmt::mp("pdu_out"));

auto access_code = "101010101010101010101010101010101010101001111110";

auto hdr_format = UTAT_HERON::header_format_esttc::make(access_code, 3, 1, 16);
auto hdr_format = UTAT_HERON::header_format_esttc::make(utils::access_code, 3, 1, utils::crc::num_bits);
auto formatter = gr::digital::protocol_formatter_async::make(hdr_format);
auto header_stream = gr::pdu::pdu_to_tagged_stream::make(gr::types::byte_t, "packet_len");
auto payload_stream = gr::pdu::pdu_to_tagged_stream::make(gr::types::byte_t, "packet_len");
auto combine = gr::blocks::tagged_stream_mux::make(1, "packet_len");
auto stream_to_pdu = gr::pdu::tagged_stream_to_pdu::make(gr::types::byte_t, "packet_len");
auto crc = gr::digital::crc_append::make(16, 0x1021, 0xFFFF, 0x0000, false, false, false, 6);
auto crc = gr::digital::crc_append::make(
utils::crc::num_bits,
utils::crc::poly,
utils::crc::inital_value,
utils::crc::final_xor,
utils::crc::input_reflected,
utils::crc::result_reflected,
false, 6);

msg_connect(self(), "pdu_in", formatter, "in");
msg_connect(formatter, "header", header_stream, "pdus");
Expand Down
6 changes: 5 additions & 1 deletion lib/header_format_esttc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ bool header_format_esttc::parse(


size_t header_format_esttc::header_nbits() const{
return d_access_code_len + 8 * 1 * sizeof(uint8_t);
return d_access_code_len + header_nbits_without_access_code();
}

size_t header_format_esttc::header_nbits_without_access_code() const{
return 8 * 1 * sizeof(uint8_t);
}

inline void header_format_esttc::enter_have_sync(){
Expand Down
12 changes: 12 additions & 0 deletions lib/utils/common.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "common.h"

namespace gr{
namespace UTAT_HERON{
namespace utils{

const char* access_code = "101010101010101010101010101010101010101001111110";
const char* trimmed_access_code = access_code + access_code_front_trim;

}
}
}
24 changes: 24 additions & 0 deletions lib/utils/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <cstdint>
#include <gnuradio/UTAT_HERON/header_format_esttc.h>

namespace gr{
namespace UTAT_HERON{
namespace utils{
namespace crc{

constexpr int num_bits = 16;
constexpr uint64_t poly = 0x1021;
constexpr uint64_t inital_value = 0xFFFF;
constexpr uint64_t final_xor = 0x0000;
constexpr bool input_reflected = false;
constexpr bool result_reflected = false;

}

extern const char* access_code;
constexpr int access_code_front_trim = 8;
extern const char* trimmed_access_code;

}
}
}
36 changes: 36 additions & 0 deletions lib/utils/pdu_lambda.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "pdu_lambda.h"

namespace gr{
namespace UTAT_HERON{
namespace utils{

pdu_lambda::sptr pdu_lambda::make(pdu_lambda::func callback){
return gnuradio::make_block_sptr<pdu_lambda>(callback);
}

pdu_lambda::pdu_lambda(pdu_lambda::func callback):
gr::sync_block(
"pdu_lambda",
gr::io_signature::make(0,0,0),
gr::io_signature::make(0,0,0)
),
callback(callback)
{
message_port_register_in(pmt::mp("pdu_in"));
message_port_register_out(pmt::mp("pdu_out"));

set_msg_handler(pmt::mp("pdu_in"), [this](pmt::pmt_t pdu){
this->callback(pdu);
message_port_pub(pmt::mp("pdu_out"), pdu);
});
}

int pdu_lambda::work(
int noutput_items,
gr_vector_const_void_star& input_items,
gr_vector_void_star& output_items
){ return 0; }

}
}
}
29 changes: 29 additions & 0 deletions lib/utils/pdu_lambda.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

#include <gnuradio/sync_block.h>
#include <functional>

namespace gr{
namespace UTAT_HERON{
namespace utils{

class pdu_lambda : public gr::sync_block{
private:
typedef std::function<void(pmt::pmt_t)> func;
func callback;
public:

pdu_lambda(func callback);

int work(
int noutput_items,
gr_vector_const_void_star& input_items,
gr_vector_void_star& output_items
) override;

typedef std::shared_ptr<pdu_lambda> sptr;
static sptr make(func callback);
};

}
}
}
2 changes: 1 addition & 1 deletion python/UTAT_HERON/bindings/header_format_esttc_python.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/* BINDTOOL_GEN_AUTOMATIC(0) */
/* BINDTOOL_USE_PYGCCXML(0) */
/* BINDTOOL_HEADER_FILE(header_format_esttc.h) */
/* BINDTOOL_HEADER_FILE_HASH(4debf424b7f86e2767073c5f2884768e) */
/* BINDTOOL_HEADER_FILE_HASH(2c8333b07b17c7f3cbc49db2d0ba17a4) */
/***********************************************************************************/

#include <pybind11/complex.h>
Expand Down
Loading

0 comments on commit d6b05b0

Please sign in to comment.