Skip to content

Commit

Permalink
Changed protocol parsing to accomodate the use of correlate_access_co…
Browse files Browse the repository at this point in the history
…de_tag block
  • Loading branch information
swarnavaghosh04 committed Aug 11, 2023
1 parent dddc7cc commit f1ade3a
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 23 deletions.
28 changes: 25 additions & 3 deletions grc/UTAT_HERON_header_format_esttc.block.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,38 @@ label: ESTTC Header Format
category: '[UTAT]'
flags: [ show_id, python, cpp ]

value: ${ UTAT_HERON.header_format_esttc() }
parameters:
- id: access_code
label: Access Code
dtype: string
default: '"101010111"'
- id: threshold
label: Threshold
dtype: int
default: 0
- id: bps
label: Payload Bits per Symbol
dtype: int
default: 1
- id: trailer_nbits
label: Trailer Bits
dtype: int
default: 0

value: ${ UTAT_HERON.header_format_esttc(access_code, threshold, bps, trailer_nbits) }

templates:
imports: from gnuradio import UTAT_HERON
var_make: self.${id} = ${id} = UTAT_HERON.header_format_esttc()
var_make: |-
self.${id} = ${id} = UTAT_HERON.header_format_esttc(${access_code},\
${threshold}, ${bps}, ${trailer_nbits})
cpp_templates:
includes: ['#include <gnuradio/UTAT_HERON/header_format_esttc.h>']
declarations: 'UTAT_HERON::header_format_esttc::sptr ${id};'
var_make: this->${id} = ${id} = UTAT_HERON::header_format_esttc();
var_make: |-
this->${id} = ${id} = UTAT_HERON::header_format_esttc(${access_code},\
${threshold}, ${bps}, ${trailer_nbits});
link: ['gnuradio::gnuradio-digital']

# Make one 'parameters' list entry for every parameter you want settable from the GUI.
Expand Down
10 changes: 8 additions & 2 deletions include/gnuradio/UTAT_HERON/header_format_esttc.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define INCLUDED_UTAT_HERON_HEADER_FORMAT_ESTTC_H

#include <gnuradio/UTAT_HERON/api.h>
#include <gnuradio/logger.h>
#include <gnuradio/digital/header_format_default.h>

namespace gr {
Expand All @@ -22,16 +23,21 @@ class UTAT_HERON_API header_format_esttc : public gr::digital::header_format_def
{
public:
typedef std::shared_ptr<header_format_esttc> sptr;
static sptr make();
header_format_esttc();
static sptr make(const std::string& access_code, int threshold = 0, int bps = 1, int trailer_nbits = 0);
header_format_esttc(const std::string& access_code, int threshold, int bps, int trailer_nbits);
~header_format_esttc();
bool format(
int nbytes_in,
const unsigned char* input,
pmt::pmt_t& output,
pmt::pmt_t& info) override;
bool parse(int nbits_in,
const unsigned char* input,
std::vector<pmt::pmt_t>& info,
int& nbits_processed) override;
size_t header_nbits() const override;
protected:
int d_trailer_nbits;
void enter_have_sync() override;
void enter_have_header(int payload_len) override;
void enter_search() override;
Expand Down
34 changes: 24 additions & 10 deletions lib/header_format_esttc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
namespace gr {
namespace UTAT_HERON {

header_format_esttc::sptr header_format_esttc::make(){
return header_format_esttc::sptr(new header_format_esttc());
header_format_esttc::sptr header_format_esttc::make(const std::string& access_code, int threshold, int bps, int trailer_nbits){
return header_format_esttc::sptr(new header_format_esttc(access_code, threshold, bps, trailer_nbits));
}

header_format_esttc::header_format_esttc():
header_format_default("101010101010101010101010101010101010101001111110", 3, 1)
header_format_esttc::header_format_esttc(const std::string& access_code, int threshold, int bps, int trailer_nbits):
header_format_default(access_code, threshold, bps),
d_trailer_nbits(trailer_nbits)
{}

header_format_esttc::~header_format_esttc() {}
Expand All @@ -44,6 +45,18 @@ bool header_format_esttc::format(int nbytes_in,
return true;
}

bool header_format_esttc::parse(
int nbits_in,
const unsigned char* input,
std::vector<pmt::pmt_t>& info,
int& nbits_processed
){
if(d_state == STATE_SYNC_SEARCH)
enter_have_sync();

return header_format_default::parse(nbits_in, input, info, nbits_processed);
}


size_t header_format_esttc::header_nbits() const{
return d_access_code_len + 8 * 1 * sizeof(uint8_t);
Expand All @@ -54,26 +67,27 @@ inline void header_format_esttc::enter_have_sync(){
d_hdr_reg.clear();
}
inline void header_format_esttc::enter_have_header(int payload_len){
d_state = STATE_SYNC_SEARCH;
enter_search();
d_pkt_len = payload_len;
d_pkt_count = 0;
}
inline void header_format_esttc::enter_search(){
d_state = STATE_SYNC_SEARCH;
enter_have_sync();
}

bool header_format_esttc::header_ok(){
return d_hdr_reg.length() == 8 * 1 * sizeof(uint8_t);
bool ret = d_hdr_reg.length() == 8 * 1 * sizeof(uint8_t);
return ret;
}

int header_format_esttc::header_payload(){

uint8_t len = d_hdr_reg.extract_field16(0, 8);
uint8_t len = d_hdr_reg.extract_field8(0, 8);

d_info = pmt::make_dict();
d_info = pmt::dict_add(
d_info, pmt::intern("payload symbols"), pmt::from_long(8 * len / d_bps));
return static_cast<int>(len);
d_info, pmt::intern("payload symbols"), pmt::from_long((8 * len + d_trailer_nbits) / d_bps));
return static_cast<int>(len + std::ceil(d_trailer_nbits/8.0));
}

} /* namespace UTAT_HERON */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@



static const char *__doc_gr_UTAT_HERON_header_format_esttc = R"doc()doc";
static const char *__doc_gr_UTAT_HERON_header_format_esttc = R"doc()doc";


static const char *__doc_gr_UTAT_HERON_header_format_esttc_header_format_esttc = R"doc()doc";
static const char *__doc_gr_UTAT_HERON_header_format_esttc_header_format_esttc = R"doc()doc";


static const char *__doc_gr_UTAT_HERON_header_format_esttc_make = R"doc()doc";
static const char *__doc_gr_UTAT_HERON_header_format_esttc_make = R"doc()doc";


static const char *__doc_gr_UTAT_HERON_header_format_esttc_format = R"doc()doc";
static const char *__doc_gr_UTAT_HERON_header_format_esttc_format = R"doc()doc";


static const char *__doc_gr_UTAT_HERON_header_format_esttc_parse = R"doc()doc";


static const char *__doc_gr_UTAT_HERON_header_format_esttc_header_nbits = R"doc()doc";
static const char *__doc_gr_UTAT_HERON_header_format_esttc_header_nbits = R"doc()doc";


23 changes: 20 additions & 3 deletions 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(41bda5cf854f7a82ab2d53b92e58e7f5) */
/* BINDTOOL_HEADER_FILE_HASH(4debf424b7f86e2767073c5f2884768e) */
/***********************************************************************************/

#include <pybind11/complex.h>
Expand All @@ -36,12 +36,21 @@ void bind_header_format_esttc(py::module& m)
py::class_<header_format_esttc, gr::digital::header_format_default,
std::shared_ptr<header_format_esttc>>(m, "header_format_esttc", D(header_format_esttc))

.def(py::init(&header_format_esttc::make),
D(header_format_esttc,make)
.def(
py::init(&header_format_esttc::make),
py::arg("access_code"),
py::arg("threshold"),
py::arg("bps") = 1,
py::arg("trailer_nbits") = 0,
D(header_format_esttc,make)
)
.def_static(
"make",
&header_format_esttc::make,
py::arg("access_code"),
py::arg("threshold"),
py::arg("bps") = 1,
py::arg("trailer_nbits") = 0,
D(header_format_esttc,make)
)
.def(
Expand All @@ -52,6 +61,14 @@ void bind_header_format_esttc(py::module& m)
py::arg("output"),
py::arg("info"),
D(header_format_esttc, format))
.def(
"parse",
&header_format_esttc::parse,
py::arg("nbits_in"),
py::arg("input"),
py::arg("info"),
py::arg("nbits_processed"),
D(header_format_esttc, parse))
.def(
"header_nbits",
&header_format_esttc::header_nbits,
Expand Down

0 comments on commit f1ade3a

Please sign in to comment.