diff --git a/README.md b/README.md index 16919f59cd7402bb18908696df1b20d7d0c1a79c..28afa5b6e6d48dbd6a8acababa9f377ea93017c6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # gr-cdc -GNU Radio out-of-tree (OOT) module for ELEN90089\_2021\_SM1 +GNU Radio out-of-tree (OOT) module for ELEN90089\_2021\_SM1 This module contains code for running the Dynamic Spectrum Access scenario for the CDC design project. @@ -23,13 +23,12 @@ $ cmake .. $ make $ sudo make install ``` -You see a number of blocks installed in GRC under the \[cdc\] category. - +You should see a number of blocks installed in GRC under the **\[cdc\]** category. ## Primary User Reference Code -GRC applications for running the Primary User Tx and Rx can be found in the -`./examples/` directory: +GRC applications for running the OFDM-based primary user Tx and Rx can be found + in the `./examples/` directory: - `pu_tx_1_channel.grc` - `pu_tx_4_channel.grc` @@ -46,19 +45,20 @@ the `./examples/` directory. - `test_dsa_database.grc` -If you want to test out this code, ensure you have first started an instance -of the database running on the local machine. +If you want to test out this code, first ensure you start an instance of the +database on the local machine. ``` $ ./run_dsa_database.py ``` +You should then be able to run the GRC application and see KPI statistics +printed to the terminal. -The key block that will need to be integrated into your secondary link is the -*DSA DB Connect*. This block should be used at both SU Tx and Rx. Request to the -DSA database can then be made by passing commands to the *DSA DB Connect* block -in the form of +The key block that you will need to integrate into your secondary link is +**DSA DB Connect**. This block should be used at both secondary user Tx and Rx. +Requests to the DSA database can then be made by passing commands to + *DSA DB Connect* block as [GNU Radio Messages](https://wiki.gnuradio.org/index.php/Message_Passing). - Example message formation for various command is shown in the following. ``` @@ -66,6 +66,7 @@ Example message formation for various command is shown in the following. msg = pmt.cons(pmt.intern('get_pkt'), pmt.PMT_NIL) # put packet +payload = pmt.init_u8vector(64, [ii for ii in range(64)]) msg = pmt.cons(pmt.intern('put_pkt), payload) # get current KPI report @@ -74,4 +75,5 @@ msg = pmt.cons(pmt.intern('get_kpi'), pmt.PMT_NIL) # get current PU mode (development only) msg = pmt.cons(pmt.intern('get_mode'), pmt.PMT_NIL) ``` - +Responses from the server will be provided as messages on either the **info** or +**pkt** output message ports. diff --git a/examples/pu_rx_1_channel.grc b/examples/pu_rx_1_channel.grc index 38f3859acd10d3afbcb637682e8612c48d1a782e..7581e88809aca8fa69dfd6c2b2fd4c2fdde5c1b6 100644 --- a/examples/pu_rx_1_channel.grc +++ b/examples/pu_rx_1_channel.grc @@ -56,6 +56,18 @@ blocks: coordinate: [710, 12] rotation: 0 state: enabled +- name: pdu_size + id: variable + parameters: + comment: '' + value: '64' + states: + bus_sink: false + bus_source: false + bus_structure: null + coordinate: [781, 11] + rotation: 0 + state: enabled - name: rf_freq id: variable_qtgui_range parameters: @@ -127,6 +139,25 @@ blocks: coordinate: [583, 307] rotation: 0 state: true +- name: cdc_dsa_db_connect_0 + id: cdc_dsa_db_connect + parameters: + affinity: '' + alias: '' + comment: '' + host: 127.0.0.1 + maxoutbuf: '0' + minoutbuf: '0' + pktsize: pdu_size + port: '9000' + radiotype: dsa.RADIO_PU_RX + states: + bus_sink: false + bus_source: false + bus_structure: null + coordinate: [855, 283] + rotation: 0 + state: disabled - name: digital_ofdm_rx_0 id: digital_ofdm_rx parameters: @@ -628,6 +659,7 @@ blocks: state: true connections: +- [blocks_tagged_stream_to_pdu_0, pdus, cdc_dsa_db_connect_0, cmd] - [digital_ofdm_rx_0, '0', blocks_tagged_stream_to_pdu_0, '0'] - [uhd_usrp_source_0, '0', digital_ofdm_rx_0, '0'] - [uhd_usrp_source_0, '0', qtgui_freq_sink_x_0, '0'] diff --git a/examples/pu_rx_4_channel.grc b/examples/pu_rx_4_channel.grc index 0b5bfee568d1fb512a61fd4b29565e22958a96af..ad4f52407914d61c1f9bb73247e36da16e4b9bad 100644 --- a/examples/pu_rx_4_channel.grc +++ b/examples/pu_rx_4_channel.grc @@ -56,6 +56,18 @@ blocks: coordinate: [656, 10] rotation: 0 state: enabled +- name: pdu_size + id: variable + parameters: + comment: '' + value: '64' + states: + bus_sink: false + bus_source: false + bus_structure: null + coordinate: [725, 10] + rotation: 0 + state: enabled - name: rf_freq id: variable_qtgui_range parameters: @@ -190,6 +202,25 @@ blocks: coordinate: [867, 841] rotation: 0 state: true +- name: cdc_dsa_db_connect_0 + id: cdc_dsa_db_connect + parameters: + affinity: '' + alias: '' + comment: '' + host: 127.0.0.1 + maxoutbuf: '0' + minoutbuf: '0' + pktsize: pdu_size + port: '9000' + radiotype: dsa.RADIO_PU_RX + states: + bus_sink: false + bus_source: false + bus_structure: null + coordinate: [1194, 197] + rotation: 0 + state: disabled - name: digital_ofdm_rx_0 id: digital_ofdm_rx parameters: @@ -504,7 +535,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [60, 389] + coordinate: [53, 326] rotation: 180 state: true - name: uhd_usrp_source_0 @@ -875,11 +906,15 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [68, 238] + coordinate: [64, 172] rotation: 0 state: true connections: +- [blocks_tagged_stream_to_pdu_0, pdus, cdc_dsa_db_connect_0, cmd] +- [blocks_tagged_stream_to_pdu_0_0, pdus, cdc_dsa_db_connect_0, cmd] +- [blocks_tagged_stream_to_pdu_0_0_0, pdus, cdc_dsa_db_connect_0, cmd] +- [blocks_tagged_stream_to_pdu_0_0_0_0, pdus, cdc_dsa_db_connect_0, cmd] - [digital_ofdm_rx_0, '0', blocks_tagged_stream_to_pdu_0, '0'] - [digital_ofdm_rx_0_0, '0', blocks_tagged_stream_to_pdu_0_0, '0'] - [digital_ofdm_rx_0_0_0, '0', blocks_tagged_stream_to_pdu_0_0_0, '0'] diff --git a/examples/pu_tx_1_channel.grc b/examples/pu_tx_1_channel.grc index d7dfb96589612a0555e9f207e41ed47c62bbbeff..684a6fb3667af3a867f2df6e7d4bdcea3eb1d84c 100644 --- a/examples/pu_tx_1_channel.grc +++ b/examples/pu_tx_1_channel.grc @@ -145,25 +145,6 @@ blocks: coordinate: [458, 186] rotation: 0 state: enabled -- name: blocks_random_pdu_0 - id: blocks_random_pdu - parameters: - affinity: '' - alias: '' - comment: '' - length_modulo: '2' - mask: '0xFF' - maxoutbuf: '0' - maxsize: '2000' - minoutbuf: '0' - minsize: '50' - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [1150, 299] - rotation: 0 - state: true - name: blocks_tagged_stream_to_pdu_0 id: blocks_tagged_stream_to_pdu parameters: @@ -228,8 +209,8 @@ blocks: maxoutbuf: '0' minoutbuf: '0' num_outputs: '1' - num_packets: '100' - num_queued: '5' + num_packets: '20' + num_queued: '20' scenario: '-1' seed: '1' states: @@ -743,7 +724,7 @@ blocks: bus_structure: null coordinate: [666, 361] rotation: 0 - state: enabled + state: disabled - name: virtual_sink_0 id: virtual_sink parameters: diff --git a/examples/pu_tx_4_channel.grc b/examples/pu_tx_4_channel.grc index bf45d607e28a4976c8662b09f0720723a1c173b5..72423054db643ea5d61f9f55844f56832e556c34 100644 --- a/examples/pu_tx_4_channel.grc +++ b/examples/pu_tx_4_channel.grc @@ -153,7 +153,7 @@ blocks: alias: '' amp: '1' comment: '' - freq: 1.25e6 + freq: -3.75e6 maxoutbuf: '0' minoutbuf: '0' offset: '0' @@ -197,7 +197,7 @@ blocks: alias: '' amp: '1' comment: '' - freq: 3.75e6 + freq: 1.25e6 maxoutbuf: '0' minoutbuf: '0' offset: '0' @@ -219,7 +219,7 @@ blocks: alias: '' amp: '1' comment: '' - freq: -3.75e6 + freq: 3.75e6 maxoutbuf: '0' minoutbuf: '0' offset: '0' @@ -423,8 +423,8 @@ blocks: maxoutbuf: '0' minoutbuf: '0' num_outputs: '4' - num_packets: '50' - num_queued: '50' + num_packets: '20' + num_queued: '20' scenario: '-1' seed: '1' states: diff --git a/examples/run_dsa_database.py b/examples/run_dsa_database.py index 8563efee20ef08b3f030ec513d0a888f7865cab3..e298d63650d516dbeb79dd6bb751b7fc7d85b790 100755 --- a/examples/run_dsa_database.py +++ b/examples/run_dsa_database.py @@ -4,7 +4,7 @@ import cdc host = '127.0.0.1' port = 9000 -shared_mode = True +share_mode = True mtu = 1500 iface = cdc.dsa_database(host, port, share_mode, mtu) diff --git a/lib/dsa_database.cc b/lib/dsa_database.cc index 18c7530a05cfe14f196259ffa64035725b353760..783669848cd3d0659111fc368bf725108663ce54 100644 --- a/lib/dsa_database.cc +++ b/lib/dsa_database.cc @@ -234,9 +234,9 @@ dsa_database::request_handler(std::shared_ptr<tcp::socket> sock, } else if (req == dsa::REQUEST_GET_MODE) { - int mode = htonl(d_pu_mode); - memcpy(buf.data(), &mode, 4); - boost::asio::write(*sock, boost::asio::buffer(buf.data(), 4)); + int mode = htonl(get_pu_mode()); + memcpy(buf.data(), &mode, sizeof(int)); + boost::asio::write(*sock, boost::asio::buffer(buf.data(), sizeof(int))); } else if (req == dsa::REQUEST_PUT_MODE) { @@ -245,7 +245,7 @@ dsa_database::request_handler(std::shared_ptr<tcp::socket> sock, int mode; memcpy(&mode, buf.data(), sizeof(int)); - d_pu_mode = ntohl(mode); + set_pu_mode(ntohl(mode)); } else if (req == dsa::REQUEST_RESET_KPI) { diff --git a/lib/dsa_pu_scenario_impl.cc b/lib/dsa_pu_scenario_impl.cc index 75ae03b79e046d5cba8f788584fc2e59fec3fa99..927742264497fecf4f6f6bbc8605d45ba4819a98 100644 --- a/lib/dsa_pu_scenario_impl.cc +++ b/lib/dsa_pu_scenario_impl.cc @@ -97,7 +97,8 @@ dsa_pu_scenario_impl::update_scenario(int n_chan) if (d_random && d_pkt_cnt <= 0) { d_scenario = (*d_uniform)(d_engine); - //message_port_pub(pmt::mp("cmd"), pmt::cons(pmt::mp("put_mode"), pmt::mp(d_scenario))); + //message_port_pub(pmt::mp("cmd"), + // pmt::cons(pmt::mp("put_mode"), pmt::mp(d_scenario))); d_pkt_cnt = d_num_packets; } @@ -134,7 +135,7 @@ dsa_pu_scenario_impl::work(int noutput_items, } else // inactive channel { - memset(out, 0x00, d_pkt_len * sizeof(gr_complex)); + memset(out, 0, d_pkt_len * sizeof(gr_complex)); } } n_out = d_pkt_len;