Skip to content

Commit

Permalink
print_payload_as_hex
Browse files Browse the repository at this point in the history
  • Loading branch information
tapparelj committed Dec 14, 2023
1 parent 2a1f4ec commit a002311
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 35 deletions.
4 changes: 2 additions & 2 deletions examples/lora_RX.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# GNU Radio Python Flow Graph
# Title: Lora Rx
# Author: Tapparel Joachim@EPFL,TCL
# GNU Radio version: 3.10.5.1
# GNU Radio version: v3.11.0.0git-604-gd7f88722

from gnuradio import gr
from gnuradio.filter import firdes
Expand Down Expand Up @@ -69,7 +69,7 @@ def __init__(self):
self.lora_sdr_fft_demod_0 = lora_sdr.fft_demod( soft_decoding, True)
self.lora_sdr_dewhitening_0 = lora_sdr.dewhitening()
self.lora_sdr_deinterleaver_0 = lora_sdr.deinterleaver( soft_decoding)
self.lora_sdr_crc_verif_0 = lora_sdr.crc_verif( True, False)
self.lora_sdr_crc_verif_0 = lora_sdr.crc_verif( 1, False)


##################################################
Expand Down
2 changes: 1 addition & 1 deletion examples/lora_TX.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# GNU Radio Python Flow Graph
# Title: Lora Tx
# Author: Tapparel Joachim@EPFL,TCL
# GNU Radio version: 3.10.5.1
# GNU Radio version: v3.11.0.0git-604-gd7f88722

from gnuradio import blocks
import pmt
Expand Down
9 changes: 5 additions & 4 deletions examples/tx_rx_functionality_check.grc
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ blocks:
maxoutbuf: '0'
minoutbuf: '0'
num_ports: '1'
showports: 'False'
type: complex
vlen: '1'
states:
Expand Down Expand Up @@ -241,7 +242,7 @@ blocks:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [1576, 252.0]
coordinate: [1584, 244.0]
rotation: 0
state: enabled
- name: channels_channel_model_0
Expand Down Expand Up @@ -290,12 +291,12 @@ blocks:
maxoutbuf: '0'
minoutbuf: '0'
output_crc_check: 'False'
print_rx_msg: 'True'
print_rx_msg: '1'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [256, 424.0]
coordinate: [248, 424.0]
rotation: 180
state: enabled
- name: lora_sdr_deinterleaver_0
Expand Down Expand Up @@ -575,4 +576,4 @@ connections:

metadata:
file_format: 1
grc_version: 3.10.5.1
grc_version: v3.11.0.0git-604-gd7f88722
4 changes: 2 additions & 2 deletions examples/tx_rx_functionality_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# GNU Radio Python Flow Graph
# Title: Tx Rx Functionality Check
# Author: Tapparel Joachim@EPFL,TCL
# GNU Radio version: 3.10.5.1
# GNU Radio version: v3.11.0.0git-604-gd7f88722

from gnuradio import blocks
import pmt
Expand Down Expand Up @@ -66,7 +66,7 @@ def __init__(self):
self.lora_sdr_fft_demod_0 = lora_sdr.fft_demod( soft_decoding, True)
self.lora_sdr_dewhitening_0 = lora_sdr.dewhitening()
self.lora_sdr_deinterleaver_0 = lora_sdr.deinterleaver( soft_decoding)
self.lora_sdr_crc_verif_0 = lora_sdr.crc_verif( True, False)
self.lora_sdr_crc_verif_0 = lora_sdr.crc_verif( 1, False)
self.lora_sdr_add_crc_0 = lora_sdr.add_crc(has_crc)
self.channels_channel_model_0 = channels.channel_model(
noise_voltage=(10**(-SNRdB/20)),
Expand Down
2 changes: 1 addition & 1 deletion examples/tx_rx_hier_functionality_check.grc
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,4 @@ connections:

metadata:
file_format: 1
grc_version: 3.10.5.1
grc_version: v3.11.0.0git-604-gd7f88722
2 changes: 1 addition & 1 deletion examples/tx_rx_hier_functionality_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# GNU Radio Python Flow Graph
# Title: Tx Rx Hier Functionality Check
# Author: Tapparel Joachim@EPFL,TCL
# GNU Radio version: 3.10.5.1
# GNU Radio version: v3.11.0.0git-604-gd7f88722

from gnuradio import blocks
import pmt
Expand Down
4 changes: 2 additions & 2 deletions examples/tx_rx_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# GNU Radio Python Flow Graph
# Title: Tx Rx Simulation
# Author: Tapparel Joachim@EPFL,TCL
# GNU Radio version: 3.10.5.1
# GNU Radio version: v3.11.0.0git-604-gd7f88722

from gnuradio import blocks
import pmt
Expand Down Expand Up @@ -64,7 +64,7 @@ def __init__(self):
self.lora_sdr_fft_demod_0 = lora_sdr.fft_demod( soft_decoding, False)
self.lora_sdr_dewhitening_0 = lora_sdr.dewhitening()
self.lora_sdr_deinterleaver_0 = lora_sdr.deinterleaver( soft_decoding)
self.lora_sdr_crc_verif_0 = lora_sdr.crc_verif( True, False)
self.lora_sdr_crc_verif_0 = lora_sdr.crc_verif( 1, False)
self.lora_sdr_add_crc_0 = lora_sdr.add_crc(has_crc)
self.channels_channel_model_0 = channels.channel_model(
noise_voltage=(10**(-SNRdB/20)),
Expand Down
4 changes: 2 additions & 2 deletions examples/tx_rx_usrp.grc
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ blocks:
maxoutbuf: '0'
minoutbuf: '0'
output_crc_check: 'False'
print_rx_msg: 'True'
print_rx_msg: '1'
states:
bus_sink: false
bus_source: false
Expand Down Expand Up @@ -1236,4 +1236,4 @@ connections:

metadata:
file_format: 1
grc_version: 3.10.5.1
grc_version: v3.11.0.0git-604-gd7f88722
4 changes: 2 additions & 2 deletions examples/tx_rx_usrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# GNU Radio Python Flow Graph
# Title: Tx Rx Usrp
# Author: Tapparel Joachim@EPFL,TCL
# GNU Radio version: 3.10.5.1
# GNU Radio version: v3.11.0.0git-604-gd7f88722

from gnuradio import blocks
import pmt
Expand Down Expand Up @@ -98,7 +98,7 @@ def __init__(self):
self.lora_sdr_fft_demod_0 = lora_sdr.fft_demod( soft_decoding, False)
self.lora_sdr_dewhitening_0 = lora_sdr.dewhitening()
self.lora_sdr_deinterleaver_0 = lora_sdr.deinterleaver( soft_decoding)
self.lora_sdr_crc_verif_0 = lora_sdr.crc_verif( True, False)
self.lora_sdr_crc_verif_0 = lora_sdr.crc_verif( 1, False)
self.lora_sdr_add_crc_0 = lora_sdr.add_crc(has_crc)
self.blocks_multiply_const_vxx_0 = blocks.multiply_const_cc(10**((Att_dB)/20))
self.blocks_multiply_const_vxx_0.set_min_output_buffer(10000000)
Expand Down
8 changes: 4 additions & 4 deletions grc/lora_sdr_crc_verif.block.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ parameters:
- id: print_rx_msg
label: print_rx_msg
dtype: enum
options: ['False', 'True']
option_labels: ['No', 'Yes']
options: [0, 1, 2]
option_labels: ['None', 'ASCII', 'Hex']
default: 1
- id: output_crc_check
label: output_crc_check
dtype: enum
options: ['False', 'True']
option_labels: ['No', 'Yes']
default: 'False'


inputs:
- domain: stream
dtype: byte
Expand All @@ -42,7 +42,7 @@ documentation: |-
Calculate the CRC of the received data and compare it with the received CRC.
Parameters:
rx_log: filename where to store the received messages and their timestamp, put "" for no log. "Walltime,payload\n"
print_rx_msg: Print or not the received message.
print_rx_msg: Print the received message in the terminal with the specified format. 0: None, 1: ASCII, 2: Hex
output_crc_check: Ouput a stream of bytes containing either 0 or 1 based on the CRC check. If enabled, both stream output must be connected.
Input:
in: stream of payload bytes
Expand Down
7 changes: 6 additions & 1 deletion include/gnuradio/lora_sdr/crc_verif.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ namespace gr {
class LORA_SDR_API crc_verif : virtual public gr::block
{
public:
enum Print_type{
NONE,
ASCII,
HEX
};
typedef std::shared_ptr<crc_verif> sptr;

/*!
Expand All @@ -46,7 +51,7 @@ namespace gr {
* class. lora_sdr::crc_verif::make is the public interface for
* creating new instances.
*/
static sptr make(bool print_rx_msg, bool output_crc_check);
static sptr make(int print_rx_msg, bool output_crc_check);
};

} // namespace lora_sdr
Expand Down
35 changes: 27 additions & 8 deletions lib/crc_verif_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,32 @@
#include "crc_verif_impl.h"

#include <gnuradio/lora_sdr/utilities.h> // for print color
#include "gnuradio/lora_sdr/crc_verif.h"

namespace gr
{
namespace lora_sdr
{

crc_verif::sptr
crc_verif::make(bool print_rx_msg, bool output_crc_check)
crc_verif::make(int print_rx_msg, bool output_crc_check)
{
return gnuradio::get_initial_sptr(new crc_verif_impl(print_rx_msg, output_crc_check));
}

/*
* The private constructor
*/
crc_verif_impl::crc_verif_impl(bool print_rx_msg, bool output_crc_check)
crc_verif_impl::crc_verif_impl(int print_rx_msg, bool output_crc_check)
: gr::block("crc_verif",
gr::io_signature::make(1, 1, sizeof(uint8_t)),
gr::io_signature::make2(0, 2, sizeof(uint8_t), sizeof(uint8_t))),
print_rx_msg(print_rx_msg),
print_rx_msg(print_rx_msg),
output_crc_check(output_crc_check)
{
message_port_register_out(pmt::mp("msg"));
set_tag_propagation_policy(TPP_DONT);

}

/*
Expand Down Expand Up @@ -151,11 +153,19 @@ namespace gr
curent_tag.offset = nitems_written(0);
add_item_tag(0, curent_tag);
}

if (print_rx_msg)
if (print_rx_msg != NONE)
{
std::cout << "rx msg: " << message_str << std::endl
<< std::endl;
if(print_rx_msg == ASCII)
std::cout << "rx msg: " << message_str << std::endl;
else if(print_rx_msg == HEX){
std::cout << "rx msg: ";
for (int i = 0; i < (int)m_payload_len; i++){
std::cout << std::hex <<"0x"<< (int)in_buff[i] << std::dec;
if(i != (int)m_payload_len-1)
std::cout << ", ";
}
std::cout << std::endl;
}

if (crc_valid)
std::cout << "CRC valid!" << std::endl
Expand Down Expand Up @@ -191,8 +201,17 @@ namespace gr
}
cnt++;
in_buff.erase(in_buff.begin(), in_buff.begin() + m_payload_len );
if (print_rx_msg)
if (print_rx_msg == ASCII)
std::cout << "rx msg: " << message_str << std::endl;
else if(print_rx_msg == HEX){
std::cout << "rx msg: ";
for (int i = 0; i < (int)m_payload_len; i++){
std::cout << std::hex <<"0x"<< (int)in_buff[i]<< std::dec;
if(i != (int)m_payload_len-1)
std::cout << ", ";
}
std::cout << std::endl;
}
message_port_pub(pmt::intern("msg"), pmt::mp(message_str));

return m_payload_len;
Expand Down
4 changes: 2 additions & 2 deletions lib/crc_verif_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace gr {
char m_char;///< A new char of the payload
bool new_frame; ///<indicate a new frame
std::vector<uint8_t> in_buff;///< input buffer containing the data bytes and CRC if any
bool print_rx_msg; ///< print received message in terminal or not
int print_rx_msg; ///< print received message in terminal. 0: no print, 1: ASCII, 2: HEX
bool output_crc_check; ///< output the result of the payload CRC check
tag_t curent_tag; ///< the most recent tag for the packet we are currently processing

Expand All @@ -44,7 +44,7 @@ namespace gr {
unsigned int crc16(uint8_t* data, uint32_t len);

public:
crc_verif_impl(bool print_rx_msg, bool output_crc_check);
crc_verif_impl(int print_rx_msg, bool output_crc_check);
~crc_verif_impl();

void forecast (int noutput_items, gr_vector_int &ninput_items_required);
Expand Down
4 changes: 2 additions & 2 deletions python/lora_sdr/bindings/crc_verif_python.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Free Software Foundation, Inc.
* Copyright 2023 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
Expand All @@ -16,7 +16,7 @@
/* BINDTOOL_GEN_AUTOMATIC(0) */
/* BINDTOOL_USE_PYGCCXML(0) */
/* BINDTOOL_HEADER_FILE(crc_verif.h) */
/* BINDTOOL_HEADER_FILE_HASH(f21d76dec9ed1d7a8019b05dbdcceee7) */
/* BINDTOOL_HEADER_FILE_HASH(0c1080da98c3ced88d2f4a26b7d592da) */
/***********************************************************************************/

#include <pybind11/complex.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 Free Software Foundation, Inc.
* Copyright 2023 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
Expand Down

0 comments on commit a002311

Please sign in to comment.