From 1b927e745cdb7d2306413c78f8e340481a521306 Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Mon, 9 May 2022 00:42:47 -0400 Subject: [PATCH 01/45] Update receiver.cc --- CC/Sounder/receiver.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/CC/Sounder/receiver.cc b/CC/Sounder/receiver.cc index 44df6a6c..2a0faf4a 100644 --- a/CC/Sounder/receiver.cc +++ b/CC/Sounder/receiver.cc @@ -1066,3 +1066,4 @@ void Receiver::clientSyncTxRx(int tid, int core_id, SampleBuffer* rx_buffer) { slot_id = 0; } // end while } + From f8232456fbcf0081526221044c6b78c408b957cf Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Mon, 9 May 2022 00:47:11 -0400 Subject: [PATCH 02/45] Update receiver.cc address multi USRP case --- CC/Sounder/receiver.cc | 63 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/CC/Sounder/receiver.cc b/CC/Sounder/receiver.cc index 2a0faf4a..6b9d64a6 100644 --- a/CC/Sounder/receiver.cc +++ b/CC/Sounder/receiver.cc @@ -85,6 +85,7 @@ Receiver::Receiver( this->initBuffers(); MLPD_TRACE("Construction complete\n"); + std::cout << "receiver done\n"; } Receiver::~Receiver() { @@ -156,6 +157,7 @@ std::vector Receiver::startClientThreads(SampleBuffer* rx_buffer, client_threads[i] = cl_thread_; } } + std::cout << "finish start client threads" << std::endl; return client_threads; } @@ -165,6 +167,9 @@ std::vector Receiver::startRecvThreads(SampleBuffer* rx_buffer, unsigned in_core_id) { assert(rx_buffer[0].buffer.size() != 0); thread_num_ = n_rx_threads; + // added + // thread_num_ = 1; + std::cout << "rx thread num are: " << thread_num_ << std::endl; bs_tx_buffer_ = tx_buffer; std::vector created_threads; created_threads.resize(this->thread_num_); @@ -204,10 +209,18 @@ void Receiver::go() { void Receiver::baseTxBeacon(int radio_id, int cell, int frame_id, long long base_time) { // prepare BS beacon in host buffer +#if defined(USE_UHD) + int cha = config_->bs_channel() == "AB" ? 2 : 1; + const size_t num_channels = config_->num_bs_sdrs_all() * cha; + std::vector beaconbuff(num_channels); +#else + size_t num_channels = config_->bs_sdr_ch(); std::vector beaconbuff(2); +#endif + if (config_->beam_sweep() == true) { size_t beacon_frame_slot = frame_id % config_->num_bs_antennas_all(); - for (size_t ch = 0; ch < config_->bs_sdr_ch(); ++ch) { + for (size_t ch = 0; ch < num_channels; ++ch) { size_t cell_radio_id = radio_id + config_->n_bs_sdrs_agg().at(cell); size_t cell_ant_id = cell_radio_id * config_->bs_sdr_ch(); int hdmd = CommsLib::hadamard2(beacon_frame_slot, cell_ant_id); @@ -220,7 +233,7 @@ void Receiver::baseTxBeacon(int radio_id, int cell, int frame_id, beaconbuff.at(bcn_ch) = config_->beacon_ci16().data(); if (config_->bs_sdr_ch() > 1) beaconbuff.at(1 - bcn_ch) = zeros_.at(0); } else { // set both channels to zeros - for (size_t ch = 0; ch < config_->bs_sdr_ch(); ++ch) + for (size_t ch = 0; ch < num_channels; ++ch) beaconbuff.at(ch) = zeros_.at(ch); } } @@ -241,7 +254,16 @@ int Receiver::baseTxData(int radio_id, int cell, int frame_id, size_t packetLength = sizeof(Packet) + config_->getPacketDataLength(); size_t tx_buffer_size = bs_tx_buffer_[radio_id].buffer.size() / packetLength; int flagsTxData; +#if defined(USE_UHD) + int cha = config_->bs_channel() == "AB" ? 2 : 1; + size_t num_channels = config_->num_bs_sdrs_all() * cha; + // size_t num_channels = 2; + std::vector dl_txbuff(num_channels); +#else + size_t num_channels = config_->bs_sdr_ch(); std::vector dl_txbuff(2); +#endif + Event_data event; if (tx_queue_.at(radio_id)->try_dequeue_from_producer(*tx_ptoks_.at(radio_id), event) == true) { @@ -250,10 +272,12 @@ int Receiver::baseTxData(int radio_id, int cell, int frame_id, size_t cur_offset = event.offset; long long txFrameTime = base_time + (event.frame_id - frame_id) * config_->samps_per_frame(); + std::cout << "beacon radio id is:" << radio_id << std::endl; if (config_->bs_hw_framer() == false) this->baseTxBeacon(radio_id, cell, event.frame_id, txFrameTime); for (size_t s = 0; s < config_->dl_slot_per_frame(); s++) { - for (size_t ch = 0; ch < config_->bs_sdr_ch(); ++ch) { + // for (size_t ch = 0; ch < config_->bs_sdr_ch(); ++ch) { + for (size_t ch = 0; ch < num_channels; ++ch) { char* cur_ptr_buffer = bs_tx_buffer_[radio_id].buffer.data() + (cur_offset * packetLength); Packet* pkt = reinterpret_cast(cur_ptr_buffer); @@ -342,7 +366,16 @@ void Receiver::loopRecv(int tid, int core_id, SampleBuffer* rx_buffer) { // use token to speed up moodycamel::ProducerToken local_ptok(*message_queue_); +#if defined(USE_UHD) + int cha = config_->bs_channel() == "AB" ? 2 : 1; + std::cout << "cha is" << cha << std::endl; + const size_t num_channels = config_->num_bs_sdrs_all() * cha; +// const size_t num_channels = 2; +#else const size_t num_channels = config_->bs_channel().length(); +#endif + + std::cout << "num channels are: " << num_channels << std::endl; size_t packetLength = sizeof(Packet) + config_->getPacketDataLength(); int buffer_chunk_size = rx_buffer[0].buffer.size() / packetLength; int bs_tx_buff_size = kSampleBufferFrameNum * config_->slot_per_frame(); @@ -352,7 +385,12 @@ void Receiver::loopRecv(int tid, int core_id, SampleBuffer* rx_buffer) { std::atomic_int* pkt_buf_inuse = rx_buffer[tid].pkt_buf_inuse; char* buffer = rx_buffer[tid].buffer.data(); +#if defined(USE_UHD) + size_t num_radios = 1; +#else size_t num_radios = config_->num_bs_sdrs_all(); //config_->n_bs_sdrs()[0] +#endif + std::vector radio_ids_in_thread; if (config_->internal_measurement() && config_->ref_node_enable()) { if (tid == 0) @@ -392,6 +430,14 @@ void Receiver::loopRecv(int tid, int core_id, SampleBuffer* rx_buffer) { // read rx_offset to align the FPGA time of the BS // by performing dummy readStream() +#if defined(USE_UHD) + std::vector samp_buffer(num_channels); + std::vector> samp_buffer0(config_->samps_per_frame(), + 0); + for (size_t i = 0; i < num_channels; i++) { + samp_buffer[i] = samp_buffer0.data(); + } +#else std::vector> samp_buffer0(config_->samps_per_frame(), 0); std::vector> samp_buffer1(config_->samps_per_frame(), @@ -399,6 +445,7 @@ void Receiver::loopRecv(int tid, int core_id, SampleBuffer* rx_buffer) { std::vector samp_buffer(2); samp_buffer[0] = samp_buffer0.data(); if (num_channels == 2) samp_buffer[1] = samp_buffer1.data(); +#endif int cell = 0; // for UHD device, the first pilot should not have an END_BURST flag @@ -415,7 +462,11 @@ void Receiver::loopRecv(int tid, int core_id, SampleBuffer* rx_buffer) { break; } } +#if defined(USE_UHD) + size_t radio_id = 0; +#else size_t radio_id = it - config_->n_bs_sdrs_agg().at(cell); +#endif bs_sync_ret = -1; while (bs_sync_ret < 0) { bs_sync_ret = @@ -442,6 +493,7 @@ void Receiver::loopRecv(int tid, int core_id, SampleBuffer* rx_buffer) { } // Receive data + // num_channels = 4; for (auto& it : radio_ids_in_thread) { Packet* pkt[num_channels]; void* samp[num_channels]; @@ -454,7 +506,11 @@ void Receiver::loopRecv(int tid, int core_id, SampleBuffer* rx_buffer) { } } +#if defined(USE_UHD) + size_t radio_id = 0; +#else size_t radio_id = it - config_->n_bs_sdrs_agg().at(cell); +#endif size_t num_packets = config_->internal_measurement() && @@ -1066,4 +1122,3 @@ void Receiver::clientSyncTxRx(int tid, int core_id, SampleBuffer* rx_buffer) { slot_id = 0; } // end while } - From 74546282b7fdaa44928ed6c220bd810429095f32 Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Mon, 9 May 2022 01:06:46 -0400 Subject: [PATCH 03/45] Update config.cc address multi USRP case --- CC/Sounder/config.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CC/Sounder/config.cc b/CC/Sounder/config.cc index dcccc8bf..261500df 100644 --- a/CC/Sounder/config.cc +++ b/CC/Sounder/config.cc @@ -626,10 +626,14 @@ Config::Config(const std::string& jsonfile, const std::string& directory, unsigned num_cores = this->getCoreCount(); MLPD_INFO("Cores found %u ... \n", num_cores); if (bs_present_ == true && pilot_slot_per_frame_ + ul_slot_per_frame_ > 0) { +#if defined(USE_UHD) + bs_rx_thread_num_ = 1; +#else bs_rx_thread_num_ = (num_cores >= (2 * RX_THREAD_NUM)) ? std::min(RX_THREAD_NUM, static_cast(num_bs_sdrs_all_)) : 1; +#endif if (internal_measurement_ == true && ref_node_enable_ == true) { bs_rx_thread_num_ = 2; } From faa88c6740bf25a68b740501173e752f85badd0c Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Mon, 9 May 2022 01:09:12 -0400 Subject: [PATCH 04/45] Update BaseRadioSetUHD.h address Multi USRP issue --- CC/Sounder/include/BaseRadioSetUHD.h | 1 + 1 file changed, 1 insertion(+) diff --git a/CC/Sounder/include/BaseRadioSetUHD.h b/CC/Sounder/include/BaseRadioSetUHD.h index 1bfb7424..5c04c27f 100644 --- a/CC/Sounder/include/BaseRadioSetUHD.h +++ b/CC/Sounder/include/BaseRadioSetUHD.h @@ -8,6 +8,7 @@ #include #include +#include #include #include "RadioUHD.h" From 311c42764b1bd10bec96387ee68871b603ddeae1 Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Mon, 9 May 2022 01:09:41 -0400 Subject: [PATCH 05/45] Update RadioUHD.cc address multi USRP issue --- CC/Sounder/RadioUHD.cc | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/CC/Sounder/RadioUHD.cc b/CC/Sounder/RadioUHD.cc index 07575260..c4d9af6d 100644 --- a/CC/Sounder/RadioUHD.cc +++ b/CC/Sounder/RadioUHD.cc @@ -77,10 +77,18 @@ RadioUHD::RadioUHD(const std::map& args, Config* _cfg) { dev_ = uhd::usrp::multi_usrp::make(args); if (dev_ == NULL) throw std::invalid_argument("error making UHD:Device\n"); - for (auto ch : channels) { - dev_->set_rx_rate(_cfg->rate(), ch); - dev_->set_tx_rate(_cfg->rate(), ch); - } + // for (auto ch : channels){ + // std::cout << "channesl are: " << ch << std::endl; + // } + // std::string subdev = "A:0"; + // dev_->set_rx_subdev_spec(subdev); + // dev_->set_tx_subdev_spec(subdev); + dev_->set_rx_rate(_cfg->rate()); + dev_->set_tx_rate(_cfg->rate()); + // for (auto ch : channels) { + // dev_->set_rx_rate(_cfg->rate(), ch); + // dev_->set_tx_rate(_cfg->rate(), ch); + // } const std::string& format = uhdFmt; std::string hostFormat; for (const char ch : format) { @@ -97,19 +105,24 @@ RadioUHD::RadioUHD(const std::map& args, } uhd::stream_args_t stream_args(hostFormat); + std::cout << "channel size is: " << channels.size() << std::endl; stream_args.channels = channels; + // std::vector channel_nums = {0,2,4}; + // stream_args.channels = channel_nums; stream_args.args = args; if (args.count("WIRE") != 0) stream_args.otw_format = args.at("WIRE"); uhd::stream_args_t stream_args1(hostFormat); stream_args1.channels = channels; + // std::vector channel_nums1 = {1,3,5}; + // stream_args1.channels = channel_nums1; stream_args1.args = args; if (args.count("WIRE") != 0) stream_args1.otw_format = args.at("WIRE"); std::cout << "format is " << hostFormat << std::endl; - rxs_ = dev_->get_rx_stream(stream_args); txs_ = dev_->get_tx_stream(stream_args1); + rxs_ = dev_->get_rx_stream(stream_args); } int RadioUHD::activateRecv(const long long rxTime, const size_t numSamps, From 844cf286c434de153260078f7fa3bdeda50567f0 Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Mon, 9 May 2022 01:10:23 -0400 Subject: [PATCH 06/45] Update BaseRadioSetUHD.cc address multi USRP issue --- CC/Sounder/BaseRadioSetUHD.cc | 199 ++++++++++++++++++++-------------- 1 file changed, 119 insertions(+), 80 deletions(-) diff --git a/CC/Sounder/BaseRadioSetUHD.cc b/CC/Sounder/BaseRadioSetUHD.cc index ff591145..44528631 100644 --- a/CC/Sounder/BaseRadioSetUHD.cc +++ b/CC/Sounder/BaseRadioSetUHD.cc @@ -27,33 +27,36 @@ BaseRadioSetUHD::BaseRadioSetUHD(Config* cfg) : _cfg(cfg) { std::vector radio_serial_not_found; // need to be further modified + std::cout << "num of cells are: " << _cfg->num_cells() << std::endl; for (size_t c = 0; c < _cfg->num_cells(); c++) { size_t num_radios = _cfg->n_bs_sdrs()[c]; num_bs_antenntas[c] = num_radios * _cfg->bs_channel().length(); + std::cout << "num bs antennas is " << num_bs_antenntas[c] << std::endl; MLPD_TRACE("Setting up radio: %zu, cells: %zu\n", num_radios, _cfg->num_cells()); - std::atomic_ulong thread_count = ATOMIC_VAR_INIT(num_radios); + std::atomic_ulong thread_count = ATOMIC_VAR_INIT(1); MLPD_TRACE("Init base radios: %zu\n", num_radios); - for (size_t i = 0; i < num_radios; i++) { - BaseRadioContext* context = new BaseRadioContext; - context->brs = this; - context->thread_count = &thread_count; - context->tid = i; - context->cell = c; + std::cout << "num of radios are: " << num_radios << std::endl; + size_t i = 0; + BaseRadioContext* context = new BaseRadioContext; + context->brs = this; + context->thread_count = &thread_count; + context->tid = i; + context->cell = c; #ifdef THREADED_INIT - pthread_t init_thread_; - - if (pthread_create(&init_thread_, NULL, BaseRadioSetUHD::init_launch, - context) != 0) { - delete context; - throw std::runtime_error("BaseRadioSet - init thread create failed"); - } + pthread_t init_thread_; + std::cout << "init_launch" << std::endl; + if (pthread_create(&init_thread_, NULL, BaseRadioSetUHD::init_launch, + context) != 0) { + delete context; + throw std::runtime_error("BaseRadioSet - init thread create failed"); + } #else - init(context); + std::cout << "init" << std::endl; + init(context); #endif - } // Wait for init while (thread_count.load() > 0) { @@ -71,66 +74,64 @@ BaseRadioSetUHD::BaseRadioSetUHD(Config* cfg) : _cfg(cfg) { dciqCalibrationProcUHD(1); } - thread_count.store(num_radios); - for (size_t i = 0; i < num_radios; i++) { - BaseRadioContext* context = new BaseRadioContext; - context->brs = this; - context->thread_count = &thread_count; - context->tid = i; - context->cell = c; + std::cout << "check point here" << std::endl; + thread_count.store(1); + size_t ii = 0; + BaseRadioContext* context1 = new BaseRadioContext; + context1->brs = this; + context1->thread_count = &thread_count; + context1->tid = ii; + context1->cell = c; #ifdef THREADED_INIT - pthread_t configure_thread_; - if (pthread_create(&configure_thread_, NULL, - BaseRadioSetUHD::configure_launch, context) != 0) { - delete context; - throw std::runtime_error( - "BaseRadioSet - configure thread create failed"); - } + std::cout << "config_launch" << std::endl; + pthread_t configure_thread_; + if (pthread_create(&configure_thread_, NULL, + BaseRadioSetUHD::configure_launch, context1) != 0) { + delete context1; + throw std::runtime_error("BaseRadioSet - configure thread create failed"); + } #else - configure(context); + configure(context1); #endif - } while (thread_count.load() > 0) { } - auto channels = Utils::strToChannels(_cfg->bs_channel()); - - for (size_t i = 0; i < bsRadios->RawDev()->get_num_mboards(); i++) { - auto dev = bsRadios->RawDev(); - std::cout << _cfg->bs_sdr_ids().at(c).at(i) << ": Front end " + std::cout << "numer of mboards are: " + << bsRadios->RawDev()->get_num_mboards() << std::endl; + auto dev = bsRadios->RawDev(); + for (size_t index = 0; index < bsRadios->RawDev()->get_num_mboards(); + index++) { + std::cout << _cfg->bs_sdr_ids().at(c).at(index) << ": Front end " << dev->get_usrp_rx_info()["frontend"] << std::endl; - for (auto ch : channels) { - if (ch < dev->get_rx_num_channels()) { - printf("RX Channel %zu\n", ch); - printf("Actual RX sample rate: %fMSps...\n", - (dev->get_rx_rate(ch) / 1e6)); - printf("Actual RX frequency: %fGHz...\n", - (dev->get_rx_freq(ch) / 1e9)); - printf("Actual RX gain: %f...\n", (dev->get_rx_gain(ch))); - printf("Actual RX bandwidth: %fM...\n", - (dev->get_rx_bandwidth(ch) / 1e6)); - printf("Actual RX antenna: %s...\n", - (dev->get_rx_antenna(ch).c_str())); - } + } + size_t total_rx_channel = _cfg->num_bs_sdrs_all() * 2; + for (size_t ch = 0; ch < total_rx_channel; ch++) { + if (ch < dev->get_rx_num_channels()) { + printf("RX Channel %lu\n", ch); + printf("Actual RX sample rate: %fMSps...\n", + (dev->get_rx_rate(ch) / 1e6)); + printf("Actual RX frequency: %fGHz...\n", (dev->get_rx_freq(ch) / 1e9)); + printf("Actual RX gain: %f...\n", (dev->get_rx_gain(ch))); + printf("Actual RX bandwidth: %fM...\n", + (dev->get_rx_bandwidth(ch) / 1e6)); + printf("Actual RX antenna: %s...\n", (dev->get_rx_antenna(ch).c_str())); } + } - for (auto ch : channels) { - if (ch < dev->get_tx_num_channels()) { - printf("TX Channel %zu\n", ch); - printf("Actual TX sample rate: %fMSps...\n", - (dev->get_tx_rate(ch) / 1e6)); - printf("Actual TX frequency: %fGHz...\n", - (dev->get_tx_freq(ch) / 1e9)); - printf("Actual TX gain: %f...\n", (dev->get_tx_gain(ch))); - printf("Actual TX bandwidth: %fM...\n", - (dev->get_tx_bandwidth(ch) / 1e6)); - printf("Actual TX antenna: %s...\n", - (dev->get_tx_antenna(ch).c_str())); - } + for (size_t ch = 0; ch < total_rx_channel; ch++) { + if (ch < dev->get_tx_num_channels()) { + printf("TX Channel %lu\n", ch); + printf("Actual TX sample rate: %fMSps...\n", + (dev->get_tx_rate(ch) / 1e6)); + printf("Actual TX frequency: %fGHz...\n", (dev->get_tx_freq(ch) / 1e9)); + printf("Actual TX gain: %f...\n", (dev->get_tx_gain(ch))); + printf("Actual TX bandwidth: %fM...\n", + (dev->get_tx_bandwidth(ch) / 1e6)); + printf("Actual TX antenna: %s...\n", (dev->get_tx_antenna(ch).c_str())); } - std::cout << std::endl; } + std::cout << std::endl; } if (radioNotFound == true) { @@ -166,8 +167,8 @@ BaseRadioSetUHD::BaseRadioSetUHD(Config* cfg) : _cfg(cfg) { // write TDD schedule and beacons to FPFA buffers only for Iris for (size_t c = 0; c < _cfg->num_cells(); c++) { - bsRadios->RawDev()->set_time_source("external", 0); - bsRadios->RawDev()->set_clock_source("external", 0); + bsRadios->RawDev()->set_time_source("external"); + bsRadios->RawDev()->set_clock_source("external"); uhd::time_spec_t time = uhd::time_spec_t::from_ticks(0, 1e9); bsRadios->RawDev()->set_time_next_pps(time); @@ -190,28 +191,60 @@ void* BaseRadioSetUHD::init_launch(void* in_context) { } void BaseRadioSetUHD::init(BaseRadioContext* context) { - int i = context->tid; + // int i = context->tid; int c = context->cell; std::atomic_ulong* thread_count = context->thread_count; delete context; MLPD_TRACE("Deleting context for tid: %d\n", i); - auto channels = Utils::strToChannels(_cfg->bs_channel()); std::map args; args["driver"] = "uhd"; - args["addr"] = _cfg->bs_sdr_ids().at(c).at(i); - std::cout << "Init bsRadios: " << args["addr"] << std::endl; - // } + size_t num_radios = _cfg->n_bs_sdrs()[c]; + std::vector address_list; + for (size_t i = 0; i < num_radios; i++) { + std::ostringstream oss; + oss << "addr" << i; + address_list.push_back(oss.str()); + args[address_list.at(i)] = _cfg->bs_sdr_ids().at(c).at(i); + } + args["timeout"] = "1000000"; try { bsRadios = nullptr; - bsRadios = new RadioUHD(args, SOAPY_SDR_CS16, channels, _cfg); + size_t total_rx_channel; + + if (_cfg->bs_channel() == "AB") { + total_rx_channel = _cfg->num_bs_sdrs_all() * 2; + } else { + total_rx_channel = _cfg->num_bs_sdrs_all(); + } + std::vector new_channels(total_rx_channel); + if (_cfg->bs_channel() == "AB") { + for (size_t ii = 0; ii < total_rx_channel; ii++) { + new_channels[ii] = ii; + std::cout << new_channels[ii] << std::endl; + } + } else if (_cfg->bs_channel() == "A") { + for (size_t ii = 0; ii < total_rx_channel; ii++) { + new_channels[ii] = ii * 2; + std::cout << new_channels[ii] << std::endl; + } + } else { + for (size_t ii = 0; ii < total_rx_channel; ii++) { + new_channels[ii] = ii * 2 + 1; + std::cout << new_channels[ii] << std::endl; + } + } + + for (size_t j = 0; j < new_channels.size(); j++) { + std::cout << new_channels[j] << std::endl; + } + bsRadios = new RadioUHD(args, SOAPY_SDR_CS16, new_channels, _cfg); } catch (std::runtime_error& err) { - std::cerr << "Ignoring uhd device " << _cfg->bs_sdr_ids().at(c).at(i) - << std::endl; - // } + std::cerr << "Ignoring uhd device "; + // } if (bsRadios != nullptr) { MLPD_TRACE("Deleting radio ptr due to exception\n"); delete bsRadios; @@ -234,13 +267,19 @@ void BaseRadioSetUHD::configure(BaseRadioContext* context) { delete context; //load channels - auto channels = Utils::strToChannels(_cfg->bs_channel()); + std::cout << "num channels in BSradio are: " << _cfg->bs_channel() + << std::endl; RadioUHD* bsRadio = bsRadios; uhd::usrp::multi_usrp::sptr dev = bsRadio->RawDev(); - for (auto ch : channels) { - double rxgain = _cfg->rx_gain().at(ch); - double txgain = _cfg->tx_gain().at(ch); - bsRadios->dev_init(_cfg, ch, rxgain, txgain); + + auto total_rx_channel = _cfg->num_bs_sdrs_all() * 2; + + for (unsigned int ch = 0; ch < total_rx_channel; ch++) { + std::cout << "ch to init is: " << ch << std::endl; + double rxgain = _cfg->rx_gain().at(0); + double txgain = _cfg->tx_gain().at(0); + + bsRadios->dev_init(_cfg, (ch), rxgain, txgain); } assert(thread_count->load() != 0); thread_count->store(thread_count->load() - 1); From 99bd345b0a8650dc85e4b09fc7300ccf15181c68 Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Mon, 9 May 2022 15:35:42 -0400 Subject: [PATCH 07/45] Update CMakeLists.txt address issue if not Ubuntu 20.04 systems --- CC/Sounder/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CC/Sounder/CMakeLists.txt b/CC/Sounder/CMakeLists.txt index 3766ab82..f8c7bfe5 100644 --- a/CC/Sounder/CMakeLists.txt +++ b/CC/Sounder/CMakeLists.txt @@ -189,7 +189,8 @@ endif() target_link_libraries(sounder -lpthread -lhdf5_cpp --enable-threadsafe gflags ${UHD_LIBRARIES} ${SoapySDR_LIBRARIES} ${HDF5_LIBRARIES} - ${MUFFT_LIBRARIES}) + ${MUFFT_LIBRARIES} + -lboost_system) add_library(sounder_module MODULE ${SOUNDER_SOURCES}) From c399b7f22eee727d66fbfcf0f5a3b64ee309a54f Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Mon, 16 May 2022 22:03:22 -0400 Subject: [PATCH 08/45] Update RadioUHD.cc clean up --- CC/Sounder/RadioUHD.cc | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/CC/Sounder/RadioUHD.cc b/CC/Sounder/RadioUHD.cc index c4d9af6d..54dfc8b6 100644 --- a/CC/Sounder/RadioUHD.cc +++ b/CC/Sounder/RadioUHD.cc @@ -77,18 +77,10 @@ RadioUHD::RadioUHD(const std::map& args, Config* _cfg) { dev_ = uhd::usrp::multi_usrp::make(args); if (dev_ == NULL) throw std::invalid_argument("error making UHD:Device\n"); - // for (auto ch : channels){ - // std::cout << "channesl are: " << ch << std::endl; - // } - // std::string subdev = "A:0"; - // dev_->set_rx_subdev_spec(subdev); - // dev_->set_tx_subdev_spec(subdev); + dev_->set_rx_rate(_cfg->rate()); dev_->set_tx_rate(_cfg->rate()); - // for (auto ch : channels) { - // dev_->set_rx_rate(_cfg->rate(), ch); - // dev_->set_tx_rate(_cfg->rate(), ch); - // } + const std::string& format = uhdFmt; std::string hostFormat; for (const char ch : format) { @@ -107,15 +99,11 @@ RadioUHD::RadioUHD(const std::map& args, uhd::stream_args_t stream_args(hostFormat); std::cout << "channel size is: " << channels.size() << std::endl; stream_args.channels = channels; - // std::vector channel_nums = {0,2,4}; - // stream_args.channels = channel_nums; stream_args.args = args; if (args.count("WIRE") != 0) stream_args.otw_format = args.at("WIRE"); uhd::stream_args_t stream_args1(hostFormat); stream_args1.channels = channels; - // std::vector channel_nums1 = {1,3,5}; - // stream_args1.channels = channel_nums1; stream_args1.args = args; if (args.count("WIRE") != 0) stream_args1.otw_format = args.at("WIRE"); From a240ddd15012d383d9d007f0924f7d3954ad49d8 Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Mon, 16 May 2022 22:05:46 -0400 Subject: [PATCH 09/45] Update receiver.cc clean up --- CC/Sounder/receiver.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CC/Sounder/receiver.cc b/CC/Sounder/receiver.cc index 6b9d64a6..bd9973bc 100644 --- a/CC/Sounder/receiver.cc +++ b/CC/Sounder/receiver.cc @@ -167,8 +167,6 @@ std::vector Receiver::startRecvThreads(SampleBuffer* rx_buffer, unsigned in_core_id) { assert(rx_buffer[0].buffer.size() != 0); thread_num_ = n_rx_threads; - // added - // thread_num_ = 1; std::cout << "rx thread num are: " << thread_num_ << std::endl; bs_tx_buffer_ = tx_buffer; std::vector created_threads; @@ -257,7 +255,6 @@ int Receiver::baseTxData(int radio_id, int cell, int frame_id, #if defined(USE_UHD) int cha = config_->bs_channel() == "AB" ? 2 : 1; size_t num_channels = config_->num_bs_sdrs_all() * cha; - // size_t num_channels = 2; std::vector dl_txbuff(num_channels); #else size_t num_channels = config_->bs_sdr_ch(); @@ -276,7 +273,6 @@ int Receiver::baseTxData(int radio_id, int cell, int frame_id, if (config_->bs_hw_framer() == false) this->baseTxBeacon(radio_id, cell, event.frame_id, txFrameTime); for (size_t s = 0; s < config_->dl_slot_per_frame(); s++) { - // for (size_t ch = 0; ch < config_->bs_sdr_ch(); ++ch) { for (size_t ch = 0; ch < num_channels; ++ch) { char* cur_ptr_buffer = bs_tx_buffer_[radio_id].buffer.data() + (cur_offset * packetLength); @@ -370,7 +366,6 @@ void Receiver::loopRecv(int tid, int core_id, SampleBuffer* rx_buffer) { int cha = config_->bs_channel() == "AB" ? 2 : 1; std::cout << "cha is" << cha << std::endl; const size_t num_channels = config_->num_bs_sdrs_all() * cha; -// const size_t num_channels = 2; #else const size_t num_channels = config_->bs_channel().length(); #endif @@ -493,7 +488,6 @@ void Receiver::loopRecv(int tid, int core_id, SampleBuffer* rx_buffer) { } // Receive data - // num_channels = 4; for (auto& it : radio_ids_in_thread) { Packet* pkt[num_channels]; void* samp[num_channels]; From 62b76fe5966221058535b4f0dfc93b3cbd82aa27 Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Mon, 16 May 2022 22:07:53 -0400 Subject: [PATCH 10/45] Update BaseRadioSetUHD.cc clean up --- CC/Sounder/BaseRadioSetUHD.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/CC/Sounder/BaseRadioSetUHD.cc b/CC/Sounder/BaseRadioSetUHD.cc index 44528631..5827f250 100644 --- a/CC/Sounder/BaseRadioSetUHD.cc +++ b/CC/Sounder/BaseRadioSetUHD.cc @@ -191,7 +191,6 @@ void* BaseRadioSetUHD::init_launch(void* in_context) { } void BaseRadioSetUHD::init(BaseRadioContext* context) { - // int i = context->tid; int c = context->cell; std::atomic_ulong* thread_count = context->thread_count; delete context; From 1e410321d6ebd116eb1ff1cd0954b1f32038283a Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Mon, 16 May 2022 22:14:17 -0400 Subject: [PATCH 11/45] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6b520206..6d478b45 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ $ cd build $ cmake .. -DCMAKE_BUILD_TYPE=Release -DLOG_LEVEL=info && make -j $ cd ../ ``` -If you wish to switch to use the UHD impelentation (install necessary UHD packages [here](https://kb.ettus.com/Building_and_Installing_the_USRP_Open-Source_Toolchain_(UHD_and_GNU_Radio)_on_Linux)): +If you wish to switch to use the UHD impelentation (install necessary UHD packages [here](https://kb.ettus.com/Building_and_Installing_the_USRP_Open-Source_Toolchain_(UHD_and_GNU_Radio)_on_Linux), recommended setting is to use Ubuntu 20.4, Boost version 1.71 and UHD version of 4.1.0.4): ```sh $ cd build $ cmake .. -DRADIO_TYPE=PURE_UHD From edfaa181a014e4eb97a05fd0d3ef27783e8a4be5 Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Tue, 31 May 2022 14:20:18 -0400 Subject: [PATCH 12/45] Update receiver.cc Comment and debug print clean up --- CC/Sounder/receiver.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CC/Sounder/receiver.cc b/CC/Sounder/receiver.cc index 69876a6e..13c26780 100644 --- a/CC/Sounder/receiver.cc +++ b/CC/Sounder/receiver.cc @@ -169,7 +169,6 @@ std::vector Receiver::startRecvThreads(SampleBuffer* rx_buffer, unsigned in_core_id) { assert(rx_buffer[0].buffer.size() != 0); thread_num_ = n_rx_threads; - std::cout << "rx thread num are: " << thread_num_ << std::endl; bs_tx_buffer_ = tx_buffer; std::vector created_threads; created_threads.resize(this->thread_num_); @@ -271,7 +270,6 @@ int Receiver::baseTxData(int radio_id, int cell, int frame_id, size_t cur_offset = event.offset; long long txFrameTime = base_time + (event.frame_id - frame_id) * config_->samps_per_frame(); - std::cout << "beacon radio id is:" << radio_id << std::endl; if (config_->bs_hw_framer() == false) this->baseTxBeacon(radio_id, cell, event.frame_id, txFrameTime); for (size_t s = 0; s < config_->dl_slot_per_frame(); s++) { @@ -366,7 +364,6 @@ void Receiver::loopRecv(int tid, int core_id, SampleBuffer* rx_buffer) { #if defined(USE_UHD) int cha = config_->bs_channel() == "AB" ? 2 : 1; - std::cout << "cha is" << cha << std::endl; const size_t num_channels = config_->num_bs_sdrs_all() * cha; #else const size_t num_channels = config_->bs_channel().length(); @@ -1084,7 +1081,6 @@ void Receiver::clientSyncTxRx(int tid, int core_id, SampleBuffer* rx_buffer) { resync_retry_cnt++; } } - // std::cout<<"here"< resync_retry_max)) { MLPD_WARN( "Exceeded resync retry limit (%zu) for client " From 51081e0f70df01b42686a4c2b91b2c141c5f18cd Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Tue, 31 May 2022 14:20:53 -0400 Subject: [PATCH 13/45] Update RadioUHD.cc Comment and Debug print clean up --- CC/Sounder/RadioUHD.cc | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/CC/Sounder/RadioUHD.cc b/CC/Sounder/RadioUHD.cc index 54dfc8b6..0806354b 100644 --- a/CC/Sounder/RadioUHD.cc +++ b/CC/Sounder/RadioUHD.cc @@ -23,7 +23,6 @@ void RadioUHD::dev_init(Config* _cfg, int ch, double rxgain, double txgain) { // these params are sufficient to set before DC offset and IQ imbalance calibration - std::cout << "radioUHD.cc being called" << std::endl; MLPD_INFO("Init USRP channel: %d\n", ch); // update for UHD multi USRP dev_->set_tx_antenna("TX/RX", ch); @@ -107,8 +106,6 @@ RadioUHD::RadioUHD(const std::map& args, stream_args1.args = args; if (args.count("WIRE") != 0) stream_args1.otw_format = args.at("WIRE"); - std::cout << "format is " << hostFormat << std::endl; - txs_ = dev_->get_tx_stream(stream_args1); rxs_ = dev_->get_rx_stream(stream_args); } @@ -142,8 +139,6 @@ int RadioUHD::activateRecv(const long long rxTime, const size_t numSamps, void RadioUHD::activateXmit(void) { std::cout << "activate xmit" << std::endl; // for USRP device start tx stream UHD_INIT_TIME_SEC sec in the future - std::cout << "no input yet, from example, seems no issue command is needed" - << std::endl; } void RadioUHD::deactivateRecv(void) { @@ -156,10 +151,7 @@ void RadioUHD::deactivateRecv(void) { rxs_->issue_stream_cmd(stream_cmd_1); } -void RadioUHD::deactivateXmit(void) { - std::cout << "no input yet, from example, seems no issue command is needed" - << std::endl; -} +void RadioUHD::deactivateXmit(void) {} RadioUHD::~RadioUHD(void) { deactivateRecv(); From 418a3c943d3b442a324b527e0ff230c9b38c8d4c Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Tue, 31 May 2022 14:21:25 -0400 Subject: [PATCH 14/45] Update ClientRadioSetUHD.cc Comment and Debug print clean up --- CC/Sounder/ClientRadioSetUHD.cc | 8 -------- 1 file changed, 8 deletions(-) diff --git a/CC/Sounder/ClientRadioSetUHD.cc b/CC/Sounder/ClientRadioSetUHD.cc index adba9b74..ddaa8d1b 100644 --- a/CC/Sounder/ClientRadioSetUHD.cc +++ b/CC/Sounder/ClientRadioSetUHD.cc @@ -20,7 +20,6 @@ ClientRadioSetUHD::ClientRadioSetUHD(Config* cfg) : _cfg(cfg) { size_t num_radios = _cfg->num_cl_sdrs(); //load channels - std::cout << "channel is: " << _cfg->cl_channel() << std::endl; auto channels = Utils::strToChannels(_cfg->cl_channel()); // Update for UHD multi USRP radioNotFound = false; @@ -87,8 +86,6 @@ ClientRadioSetUHD::ClientRadioSetUHD(Config* cfg) : _cfg(cfg) { (radio_->RawDev()->get_tx_antenna(ch).c_str())); } } - std::cout << "ClientRadioSetUHD Init Check" << std::endl; - std::cout << std::endl; // Update for UHD multi USRP if (radioNotFound == true) { @@ -96,15 +93,12 @@ ClientRadioSetUHD::ClientRadioSetUHD(Config* cfg) : _cfg(cfg) { "discovered in the network!" << std::endl; } else { - std::cout << "checking tx advance " << _cfg->tx_advance(0) << std::endl; radio_->RawDev()->set_time_source("internal"); radio_->RawDev()->set_clock_source("internal"); radio_->RawDev()->set_time_unknown_pps(uhd::time_spec_t(0.0)); radio_->activateRecv(); radio_->activateXmit(); - std::cout << "sync check" << std::endl; - std::cout << std::endl; MLPD_INFO("%s done!\n", __func__); } } @@ -133,7 +127,6 @@ void ClientRadioSetUHD::init(ClientRadioContext* context) { args["timeout"] = "1000000"; args["driver"] = "uhd"; args["addr"] = _cfg->cl_sdr_ids().at(i); - std::cout << "address i is " << i << std::endl; try { radio_ = nullptr; @@ -155,7 +148,6 @@ void ClientRadioSetUHD::init(ClientRadioContext* context) { } if (has_runtime_error == false) { for (auto ch : channels) { - std::cout << "check ch: " << ch << std::endl; auto new_ch = _cfg->cl_channel(); double rxgain = _cfg->cl_rxgain_vec().at(ch).at( i); // w/CBRS 3.6GHz [0:105], 2.5GHZ [0:108] From d8d893e5ece3af2dd41b31139d3ad31235650b5b Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Tue, 31 May 2022 14:22:00 -0400 Subject: [PATCH 15/45] Update BaseRadioSetUHD.cc Comment and Debug print clean up --- CC/Sounder/BaseRadioSetUHD.cc | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/CC/Sounder/BaseRadioSetUHD.cc b/CC/Sounder/BaseRadioSetUHD.cc index 5827f250..8b8f5c2d 100644 --- a/CC/Sounder/BaseRadioSetUHD.cc +++ b/CC/Sounder/BaseRadioSetUHD.cc @@ -47,14 +47,12 @@ BaseRadioSetUHD::BaseRadioSetUHD(Config* cfg) : _cfg(cfg) { context->cell = c; #ifdef THREADED_INIT pthread_t init_thread_; - std::cout << "init_launch" << std::endl; if (pthread_create(&init_thread_, NULL, BaseRadioSetUHD::init_launch, context) != 0) { delete context; throw std::runtime_error("BaseRadioSet - init thread create failed"); } #else - std::cout << "init" << std::endl; init(context); #endif @@ -74,7 +72,6 @@ BaseRadioSetUHD::BaseRadioSetUHD(Config* cfg) : _cfg(cfg) { dciqCalibrationProcUHD(1); } - std::cout << "check point here" << std::endl; thread_count.store(1); size_t ii = 0; BaseRadioContext* context1 = new BaseRadioContext; @@ -83,7 +80,6 @@ BaseRadioSetUHD::BaseRadioSetUHD(Config* cfg) : _cfg(cfg) { context1->tid = ii; context1->cell = c; #ifdef THREADED_INIT - std::cout << "config_launch" << std::endl; pthread_t configure_thread_; if (pthread_create(&configure_thread_, NULL, BaseRadioSetUHD::configure_launch, context1) != 0) { @@ -223,23 +219,17 @@ void BaseRadioSetUHD::init(BaseRadioContext* context) { if (_cfg->bs_channel() == "AB") { for (size_t ii = 0; ii < total_rx_channel; ii++) { new_channels[ii] = ii; - std::cout << new_channels[ii] << std::endl; } } else if (_cfg->bs_channel() == "A") { for (size_t ii = 0; ii < total_rx_channel; ii++) { new_channels[ii] = ii * 2; - std::cout << new_channels[ii] << std::endl; } } else { for (size_t ii = 0; ii < total_rx_channel; ii++) { new_channels[ii] = ii * 2 + 1; - std::cout << new_channels[ii] << std::endl; } } - for (size_t j = 0; j < new_channels.size(); j++) { - std::cout << new_channels[j] << std::endl; - } bsRadios = new RadioUHD(args, SOAPY_SDR_CS16, new_channels, _cfg); } catch (std::runtime_error& err) { std::cerr << "Ignoring uhd device "; @@ -274,7 +264,6 @@ void BaseRadioSetUHD::configure(BaseRadioContext* context) { auto total_rx_channel = _cfg->num_bs_sdrs_all() * 2; for (unsigned int ch = 0; ch < total_rx_channel; ch++) { - std::cout << "ch to init is: " << ch << std::endl; double rxgain = _cfg->rx_gain().at(0); double txgain = _cfg->tx_gain().at(0); @@ -315,7 +304,6 @@ void BaseRadioSetUHD::radioStop(void) { void BaseRadioSetUHD::radioTx(const void* const* buffs) { long long frameTime(0); - std::cout << "running tx 1" << std::endl; bsRadios->xmit(buffs, _cfg->samps_per_slot(), 0, frameTime); } @@ -385,7 +373,6 @@ int BaseRadioSetUHD::radioRx(size_t radio_id, size_t cell_id, int BaseRadioSetUHD::syncTimeOffsetUHD(bool measure_ref_radio, bool adjust_trigger) { - std::cout << "sync time being called" << std::endl; int num_radios = _cfg->n_bs_sdrs().at(0) - 1; if (num_radios < 1) { std::cout << "No need to sample calibrate with one Iris! skipping ..." From 67d819d7df67ba7658a25e9a9f210e53407aa4d0 Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Thu, 2 Jun 2022 02:11:28 -0400 Subject: [PATCH 16/45] Update BaseRadioSetUHD.cc addressed comments --- CC/Sounder/BaseRadioSetUHD.cc | 62 +++++++++++++++++------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/CC/Sounder/BaseRadioSetUHD.cc b/CC/Sounder/BaseRadioSetUHD.cc index 8b8f5c2d..5dc8b52d 100644 --- a/CC/Sounder/BaseRadioSetUHD.cc +++ b/CC/Sounder/BaseRadioSetUHD.cc @@ -27,18 +27,17 @@ BaseRadioSetUHD::BaseRadioSetUHD(Config* cfg) : _cfg(cfg) { std::vector radio_serial_not_found; // need to be further modified - std::cout << "num of cells are: " << _cfg->num_cells() << std::endl; + MLPD_TRACE("num of cells are: %zu\n", _cfg->num_cells()); for (size_t c = 0; c < _cfg->num_cells(); c++) { size_t num_radios = _cfg->n_bs_sdrs()[c]; num_bs_antenntas[c] = num_radios * _cfg->bs_channel().length(); - std::cout << "num bs antennas is " << num_bs_antenntas[c] << std::endl; + MLPD_TRACE("num of bs antennas are: %zu\n", num_bs_antenntas[c]); MLPD_TRACE("Setting up radio: %zu, cells: %zu\n", num_radios, _cfg->num_cells()); std::atomic_ulong thread_count = ATOMIC_VAR_INIT(1); MLPD_TRACE("Init base radios: %zu\n", num_radios); - std::cout << "num of radios are: " << num_radios << std::endl; size_t i = 0; BaseRadioContext* context = new BaseRadioContext; context->brs = this; @@ -74,27 +73,26 @@ BaseRadioSetUHD::BaseRadioSetUHD(Config* cfg) : _cfg(cfg) { thread_count.store(1); size_t ii = 0; - BaseRadioContext* context1 = new BaseRadioContext; - context1->brs = this; - context1->thread_count = &thread_count; - context1->tid = ii; - context1->cell = c; + BaseRadioContext* context_config = new BaseRadioContext; + context_config->brs = this; + context_config->thread_count = &thread_count; + context_config->tid = ii; + context_config->cell = c; #ifdef THREADED_INIT pthread_t configure_thread_; if (pthread_create(&configure_thread_, NULL, - BaseRadioSetUHD::configure_launch, context1) != 0) { - delete context1; + BaseRadioSetUHD::configure_launch, + context_config) != 0) { + delete context_config; throw std::runtime_error("BaseRadioSet - configure thread create failed"); } #else - configure(context1); + configure(context_config); #endif while (thread_count.load() > 0) { } - std::cout << "numer of mboards are: " - << bsRadios->RawDev()->get_num_mboards() << std::endl; auto dev = bsRadios->RawDev(); for (size_t index = 0; index < bsRadios->RawDev()->get_num_mboards(); index++) { @@ -104,30 +102,33 @@ BaseRadioSetUHD::BaseRadioSetUHD(Config* cfg) : _cfg(cfg) { size_t total_rx_channel = _cfg->num_bs_sdrs_all() * 2; for (size_t ch = 0; ch < total_rx_channel; ch++) { if (ch < dev->get_rx_num_channels()) { - printf("RX Channel %lu\n", ch); - printf("Actual RX sample rate: %fMSps...\n", - (dev->get_rx_rate(ch) / 1e6)); - printf("Actual RX frequency: %fGHz...\n", (dev->get_rx_freq(ch) / 1e9)); - printf("Actual RX gain: %f...\n", (dev->get_rx_gain(ch))); - printf("Actual RX bandwidth: %fM...\n", - (dev->get_rx_bandwidth(ch) / 1e6)); - printf("Actual RX antenna: %s...\n", (dev->get_rx_antenna(ch).c_str())); + std::cout << "RX Channel " << ch << std::endl; + std::cout << "Actual RX sample rate: " << (dev->get_rx_rate(ch) / 1e6) + << "MSps" << std::endl; + std::cout << "Actual RX frequency: " << (dev->get_rx_freq(ch) / 1e9) + << "GHz" << std::endl; + std::cout << "Actual RX gain: " << (dev->get_rx_gain(ch)) << std::endl; + std::cout << "Actual RX bandwidth: " + << (dev->get_rx_bandwidth(ch) / 1e6) << "M" << std::endl; + std::cout << "Actual RX antenna: " << dev->get_rx_antenna(ch).c_str() + << std::endl; } } for (size_t ch = 0; ch < total_rx_channel; ch++) { if (ch < dev->get_tx_num_channels()) { - printf("TX Channel %lu\n", ch); - printf("Actual TX sample rate: %fMSps...\n", - (dev->get_tx_rate(ch) / 1e6)); - printf("Actual TX frequency: %fGHz...\n", (dev->get_tx_freq(ch) / 1e9)); - printf("Actual TX gain: %f...\n", (dev->get_tx_gain(ch))); - printf("Actual TX bandwidth: %fM...\n", - (dev->get_tx_bandwidth(ch) / 1e6)); - printf("Actual TX antenna: %s...\n", (dev->get_tx_antenna(ch).c_str())); + std::cout << "TX Channel " << ch << std::endl; + std::cout << "Actual TX sample rate: " << (dev->get_tx_rate(ch) / 1e6) + << "MSps" << std::endl; + std::cout << "Actual TX frequency: " << (dev->get_tx_freq(ch) / 1e9) + << "GHz" << std::endl; + std::cout << "Actual TX gain: " << (dev->get_tx_gain(ch)) << std::endl; + std::cout << "Actual TX bandwidth: " + << (dev->get_tx_bandwidth(ch) / 1e6) << "M" << std::endl; + std::cout << "Actual TX antenna: " << (dev->get_tx_antenna(ch).c_str()) + << std::endl; } } - std::cout << std::endl; } if (radioNotFound == true) { @@ -207,7 +208,6 @@ void BaseRadioSetUHD::init(BaseRadioContext* context) { args["timeout"] = "1000000"; try { - bsRadios = nullptr; size_t total_rx_channel; if (_cfg->bs_channel() == "AB") { From 5fcddcb400f94b5275dc77f64c4dd56775a0a693 Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Thu, 2 Jun 2022 02:13:58 -0400 Subject: [PATCH 17/45] Update CMakeLists.txt Comments addressed --- CC/Sounder/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CC/Sounder/CMakeLists.txt b/CC/Sounder/CMakeLists.txt index f8c7bfe5..3766ab82 100644 --- a/CC/Sounder/CMakeLists.txt +++ b/CC/Sounder/CMakeLists.txt @@ -189,8 +189,7 @@ endif() target_link_libraries(sounder -lpthread -lhdf5_cpp --enable-threadsafe gflags ${UHD_LIBRARIES} ${SoapySDR_LIBRARIES} ${HDF5_LIBRARIES} - ${MUFFT_LIBRARIES} - -lboost_system) + ${MUFFT_LIBRARIES}) add_library(sounder_module MODULE ${SOUNDER_SOURCES}) From d68d93a16400b030f69a804d0d37a54987a60f1b Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Thu, 2 Jun 2022 02:19:04 -0400 Subject: [PATCH 18/45] Update RadioUHD.cc comments addressed --- CC/Sounder/RadioUHD.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CC/Sounder/RadioUHD.cc b/CC/Sounder/RadioUHD.cc index 0806354b..de6e00be 100644 --- a/CC/Sounder/RadioUHD.cc +++ b/CC/Sounder/RadioUHD.cc @@ -96,7 +96,7 @@ RadioUHD::RadioUHD(const std::map& args, } uhd::stream_args_t stream_args(hostFormat); - std::cout << "channel size is: " << channels.size() << std::endl; + MLPD_TRACE("channel size is: %zu\n", channels.size()); stream_args.channels = channels; stream_args.args = args; if (args.count("WIRE") != 0) stream_args.otw_format = args.at("WIRE"); From b8c24eb85d2590a3558c7736ba8a65c10b64b0ed Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Thu, 2 Jun 2022 02:20:59 -0400 Subject: [PATCH 19/45] Update BaseRadioSetUHD.h comments addressed --- CC/Sounder/include/BaseRadioSetUHD.h | 1 - 1 file changed, 1 deletion(-) diff --git a/CC/Sounder/include/BaseRadioSetUHD.h b/CC/Sounder/include/BaseRadioSetUHD.h index 5c04c27f..1bfb7424 100644 --- a/CC/Sounder/include/BaseRadioSetUHD.h +++ b/CC/Sounder/include/BaseRadioSetUHD.h @@ -8,7 +8,6 @@ #include #include -#include #include #include "RadioUHD.h" From 08d02cad30337c3f61e1ab1d2d7d9d333e0dc424 Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Tue, 5 Jul 2022 12:01:27 -0400 Subject: [PATCH 20/45] Update receiver.h Sync update --- CC/Sounder/include/receiver.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CC/Sounder/include/receiver.h b/CC/Sounder/include/receiver.h index ac98843b..77fbff64 100644 --- a/CC/Sounder/include/receiver.h +++ b/CC/Sounder/include/receiver.h @@ -71,13 +71,16 @@ class Receiver { static void* clientTxRx_launch(void* in_context); void clientTxRx(int tid); void clientSyncTxRx(int tid, int core_id, SampleBuffer* rx_buffer); - int syncSearch(const std::vector>& sync_buff, - size_t sync_num_samps); + ssize_t syncSearch(const std::complex* check_data, + size_t search_window); + float estimateCFO(const std::vector>& sync_buff, int sync_index); void initBuffers(); void clientTxPilots(size_t user_id, long long base_time); int clientTxData(int tid, int frame_id, long long base_time); + ssize_t clientSyncBeacon(size_t radio_id, size_t sample_window); + void clientAdjustRx(size_t radio_id, size_t discard_samples); private: Config* config_; From 55df9a1e0a9d5f0e02fdfd283fae89830fa67f5d Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Tue, 5 Jul 2022 12:02:12 -0400 Subject: [PATCH 21/45] Update comms-lib.h sync update --- CC/Sounder/include/comms-lib.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/CC/Sounder/include/comms-lib.h b/CC/Sounder/include/comms-lib.h index 4741c275..2d579a60 100644 --- a/CC/Sounder/include/comms-lib.h +++ b/CC/Sounder/include/comms-lib.h @@ -120,9 +120,20 @@ class CommsLib { const size_t delta = 10); // Functions using AVX - static int find_beacon(const std::vector>& iq); - static int find_beacon_avx(const std::vector>& iq, - const std::vector>& seq); + static int find_beacon(const std::vector>& raw_samples); + static int find_beacon_avx( + const std::vector>& raw_samples, + const std::vector>& match_samples); + + ///Find Beacon with raw samples from the radio + static int find_beacon(const std::complex* raw_samples, + size_t check_window); + + static ssize_t find_beacon_avx( + const std::complex* raw_samples, + const std::vector>& match_samples, + size_t check_window); + static std::vector correlate_avx_s(std::vector const& f, std::vector const& g); static std::vector correlate_avx_si(std::vector const& f, From b356de0e5b599a37a99ea7172765a6015bdc1f23 Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Tue, 5 Jul 2022 12:03:00 -0400 Subject: [PATCH 22/45] Update comms-lib-avx.cc sync update --- CC/Sounder/comms-lib-avx.cc | 52 ++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/CC/Sounder/comms-lib-avx.cc b/CC/Sounder/comms-lib-avx.cc index 45afcd5e..060a45b2 100644 --- a/CC/Sounder/comms-lib-avx.cc +++ b/CC/Sounder/comms-lib-avx.cc @@ -12,6 +12,7 @@ find_beacon_avx: Correlation and Peak detection of a beacon with Gold code (2 re #include #include +#include #include #include @@ -21,24 +22,52 @@ find_beacon_avx: Correlation and Peak detection of a beacon with Gold code (2 re #define USE_AVX -static const size_t kBytesIn256Bits = (256 / 8); - -#define AVX_PACKED_SP 8 //single-precision -#define AVX_PACKED_SI 16 // short int -#define AVX_PACKED_CS 8 // complex short int +static constexpr size_t kBytesIn256Bits = (256 / 8); + +//single-precision +#define AVX_PACKED_SP (8) +// short int +#define AVX_PACKED_SI (16) +// complex short int +#define AVX_PACKED_CS (8) + +static constexpr float kShortMaxFloat = SHRT_MAX; + +ssize_t CommsLib::find_beacon_avx( + const std::complex* raw_samples, + const std::vector>& match_samples, + size_t check_window) { + //Sample window must be multiple of 64Bytes (for avx 512) + static constexpr size_t kWindowAlignment = 64; + const size_t padded_window = + (((check_window / kWindowAlignment) + 1) * kWindowAlignment); + + //Allocate memory, only used for beacon detection + std::vector> sync_compare( + padded_window, std::complex(0.0f, 0.0f)); + + // convert entire frame data to complex float for sync detection + for (size_t i = 0; i < check_window; i++) { + sync_compare.at(i) = (std::complex( + static_cast(raw_samples[i].real()) / kShortMaxFloat, + static_cast(raw_samples[i].imag()) / kShortMaxFloat)); + } + return CommsLib::find_beacon_avx(sync_compare, match_samples); +} -int CommsLib::find_beacon_avx(const std::vector>& iq, - const std::vector>& seq) { +int CommsLib::find_beacon_avx( + const std::vector>& raw_samples, + const std::vector>& match_samples) { std::queue valid_peaks; // Original LTS sequence - int seqLen = seq.size(); + int seqLen = match_samples.size(); struct timespec tv, tv2; clock_gettime(CLOCK_MONOTONIC, &tv); // correlate signal with beacon std::vector> gold_corr_avx = - CommsLib::correlate_avx(iq, seq); + CommsLib::correlate_avx(raw_samples, match_samples); clock_gettime(CLOCK_MONOTONIC, &tv2); #ifdef TEST_BENCH double diff1 = @@ -100,15 +129,14 @@ int CommsLib::find_beacon_avx(const std::vector>& iq, fclose(fp); filename = "indata.bin"; FILE* fi = fopen(filename.c_str(), "wb"); - float* idata_ptr = (float*)iq.data(); - fwrite(idata_ptr, iq.size() * 2, sizeof(float), fi); + float* idata_ptr = (float*)raw_samples.data(); + fwrite(idata_ptr, raw_samples.size() * 2, sizeof(float), fi); fclose(fi); #endif if (valid_peaks.empty()) { valid_peaks.push(-1); } - return valid_peaks.front(); } From 0d590618279cef9aab31ccc7c17a4aeaefad0b1f Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Tue, 5 Jul 2022 12:03:41 -0400 Subject: [PATCH 23/45] Update comms-lib.cc Sync update --- CC/Sounder/comms-lib.cc | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/CC/Sounder/comms-lib.cc b/CC/Sounder/comms-lib.cc index 11e01191..59f9e9f3 100644 --- a/CC/Sounder/comms-lib.cc +++ b/CC/Sounder/comms-lib.cc @@ -19,11 +19,15 @@ #include "include/comms-lib.h" +#include + #include #include "include/constants.h" #include "include/utils.h" +static constexpr float kShortMaxFloat = SHRT_MAX; + int CommsLib::findLTS(const std::vector>& iq, int seqLen) { /* * Find 802.11-based LTS (Long Training Sequence) @@ -110,8 +114,22 @@ size_t CommsLib::find_pilot_seq(const std::vector>& iq, return best_peak; } +int CommsLib::find_beacon(const std::complex* raw_samples, + size_t check_window) { + //Allocate memory, only used for beacon detection (consider making this static) + std::vector> beacon_compare( + check_window, std::complex(0.0f, 0.0f)); + + // convert entire frame data to complex float for sync detection + for (size_t i = 0; i < check_window; i++) { + beacon_compare.at(i) = (std::complex( + static_cast(raw_samples[i].real()) / kShortMaxFloat, + static_cast(raw_samples[i].imag()) / kShortMaxFloat)); + } + return CommsLib::find_beacon(beacon_compare); +} + int CommsLib::find_beacon(const std::vector>& iq) { - //std::vector> gold_seq; int best_peak; std::queue valid_peaks; From d9f7676cc61acb12941f1f35fb617076ba973ee1 Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Tue, 5 Jul 2022 12:06:59 -0400 Subject: [PATCH 24/45] Update receiver.cc Sync Update --- CC/Sounder/receiver.cc | 458 ++++++++++++++++++++++++----------------- 1 file changed, 265 insertions(+), 193 deletions(-) diff --git a/CC/Sounder/receiver.cc b/CC/Sounder/receiver.cc index 13c26780..4b3a2580 100644 --- a/CC/Sounder/receiver.cc +++ b/CC/Sounder/receiver.cc @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -26,9 +27,12 @@ #include "include/macros.h" #include "include/utils.h" +//Default to detect the beacon on first channel +static constexpr size_t kSyncDetectChannel = 0; +static constexpr float kBeaconDetectWindowScaler = 2.33f; + pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; -static constexpr float SHRT_MAX_FLOAT = SHRT_MAX; Receiver::Receiver( Config* config, moodycamel::ConcurrentQueue* in_queue, @@ -53,11 +57,18 @@ Receiver::Receiver( config_->client_present() ? new ClientRadioSetUHD(config_) : nullptr; this->base_radio_set_ = config_->bs_present() ? new BaseRadioSetUHD(config_) : nullptr; + int cha = config_->bs_channel() == "AB" ? 2 : 1; + num_channels_buff_ = config_->num_bs_sdrs_all() * cha; + num_channels_ = config_->num_bs_sdrs_all() * cha; + num_radios_ = 1; #else this->client_radio_set_ = config_->client_present() ? new ClientRadioSet(config_) : nullptr; this->base_radio_set_ = config_->bs_present() ? new BaseRadioSet(config_) : nullptr; + num_channels_buff_ = 2; + num_channels_ = config_->bs_channel().length(); + num_radios_ = config_->num_bs_sdrs_all(); //config_->n_bs_sdrs()[0] #endif } catch (std::exception& e) { throw ReceiverException(e.what()); @@ -208,14 +219,8 @@ void Receiver::go() { void Receiver::baseTxBeacon(int radio_id, int cell, int frame_id, long long base_time) { // prepare BS beacon in host buffer -#if defined(USE_UHD) - int cha = config_->bs_channel() == "AB" ? 2 : 1; - const size_t num_channels = config_->num_bs_sdrs_all() * cha; - std::vector beaconbuff(num_channels); -#else - size_t num_channels = config_->bs_sdr_ch(); - std::vector beaconbuff(2); -#endif + std::vector beaconbuff(num_channels_buff_); + size_t num_channels = num_channels_; if (config_->beam_sweep() == true) { size_t beacon_frame_slot = frame_id % config_->num_bs_antennas_all(); @@ -253,14 +258,8 @@ int Receiver::baseTxData(int radio_id, int cell, int frame_id, size_t packetLength = sizeof(Packet) + config_->getPacketDataLength(); size_t tx_buffer_size = bs_tx_buffer_[radio_id].buffer.size() / packetLength; int flagsTxData; -#if defined(USE_UHD) - int cha = config_->bs_channel() == "AB" ? 2 : 1; - size_t num_channels = config_->num_bs_sdrs_all() * cha; - std::vector dl_txbuff(num_channels); -#else - size_t num_channels = config_->bs_sdr_ch(); - std::vector dl_txbuff(2); -#endif + size_t num_channels = num_channels_; + std::vector dl_txbuff(num_channels_buff_); Event_data event; if (tx_queue_.at(radio_id)->try_dequeue_from_producer(*tx_ptoks_.at(radio_id), @@ -361,14 +360,7 @@ void Receiver::loopRecv(int tid, int core_id, SampleBuffer* rx_buffer) { // use token to speed up moodycamel::ProducerToken local_ptok(*message_queue_); - -#if defined(USE_UHD) - int cha = config_->bs_channel() == "AB" ? 2 : 1; - const size_t num_channels = config_->num_bs_sdrs_all() * cha; -#else - const size_t num_channels = config_->bs_channel().length(); -#endif - + size_t num_channels = num_channels_; std::cout << "num channels are: " << num_channels << std::endl; size_t packetLength = sizeof(Packet) + config_->getPacketDataLength(); int buffer_chunk_size = rx_buffer[0].buffer.size() / packetLength; @@ -379,11 +371,7 @@ void Receiver::loopRecv(int tid, int core_id, SampleBuffer* rx_buffer) { std::atomic_int* pkt_buf_inuse = rx_buffer[tid].pkt_buf_inuse; char* buffer = rx_buffer[tid].buffer.data(); -#if defined(USE_UHD) - size_t num_radios = 1; -#else - size_t num_radios = config_->num_bs_sdrs_all(); //config_->n_bs_sdrs()[0] -#endif + size_t num_radios = num_radios_; std::vector radio_ids_in_thread; if (config_->internal_measurement() && config_->ref_node_enable()) { @@ -424,22 +412,15 @@ void Receiver::loopRecv(int tid, int core_id, SampleBuffer* rx_buffer) { // read rx_offset to align the FPGA time of the BS // by performing dummy readStream() -#if defined(USE_UHD) - std::vector samp_buffer(num_channels); + std::vector samp_buffer(num_channels_buff_); std::vector> samp_buffer0(config_->samps_per_frame(), 0); - for (size_t i = 0; i < num_channels; i++) { - samp_buffer[i] = samp_buffer0.data(); - } -#else - std::vector> samp_buffer0(config_->samps_per_frame(), - 0); - std::vector> samp_buffer1(config_->samps_per_frame(), - 0); - std::vector samp_buffer(2); samp_buffer[0] = samp_buffer0.data(); - if (num_channels == 2) samp_buffer[1] = samp_buffer1.data(); -#endif + if (num_channels > 1) { + for (size_t i = 1; i < num_channels; i++) { + samp_buffer[i] = samp_buffer0.data(); + } + } int cell = 0; // for UHD device, the first pilot should not have an END_BURST flag @@ -850,21 +831,15 @@ int Receiver::clientTxData(int tid, int frame_id, long long base_time) { return -1; } -int Receiver::syncSearch(const std::vector>& sync_buff, - size_t sync_num_samps) { - int sync_index(-1); - // convert data to complex float for sync detection - std::vector> sync_buff_float(sync_num_samps, 0); - for (size_t i = 0; i < sync_num_samps; i++) { - sync_buff_float[i] = - (std::complex(sync_buff[i].real() / SHRT_MAX_FLOAT, - sync_buff[i].imag() / SHRT_MAX_FLOAT)); - } - //TODO syncbuff0 is sloppy here since we recevied into syncrxbuff.data(), r bytes. +ssize_t Receiver::syncSearch(const std::complex* check_data, + size_t search_window) { + ssize_t sync_index(-1); + assert(search_window <= config_->samps_per_frame()); #if defined(__x86_64__) - sync_index = CommsLib::find_beacon_avx(sync_buff_float, config_->gold_cf32()); + sync_index = CommsLib::find_beacon_avx(check_data, config_->gold_cf32(), + search_window); #else - sync_index = CommsLib::find_beacon(sync_buff_float); + sync_index = CommsLib::find_beacon(check_data, search_window); #endif return sync_index; } @@ -872,22 +847,23 @@ int Receiver::syncSearch(const std::vector>& sync_buff, float Receiver::estimateCFO(const std::vector>& sync_buff, int sync_index) { float cfo_phase_est = 0; - int beacon_start = sync_index - config_->beacon_size(); - int beacon_half_size = config_->beacon_size() / 2; - std::vector> beacon0(beacon_half_size); - std::vector> beacon1(beacon_half_size); + const int beacon_start = sync_index - config_->beacon_size(); + const int beacon_half_size = config_->beacon_size() / 2; + std::vector> beacon0(beacon_half_size, 0.0f); + std::vector> beacon1(beacon_half_size, 0.0f); for (int i = 0; i < beacon_half_size; i++) { - size_t beacon0_id = i + beacon_start; - size_t beacon1_id = i + beacon_start + beacon_half_size; - beacon0[i] = - std::complex(sync_buff[beacon0_id].real() / SHRT_MAX_FLOAT, - sync_buff[beacon0_id].imag() / SHRT_MAX_FLOAT); - beacon1[i] = - std::complex(sync_buff[beacon1_id].real() / SHRT_MAX_FLOAT, - sync_buff[beacon1_id].imag() / SHRT_MAX_FLOAT); + const size_t beacon0_id = i + beacon_start; + const size_t beacon1_id = i + beacon_start + beacon_half_size; + beacon0.at(i) = + std::complex(sync_buff[beacon0_id].real() / SHRT_MAX, + sync_buff[beacon0_id].imag() / SHRT_MAX); + beacon1.at(i) = + std::complex(sync_buff[beacon1_id].real() / SHRT_MAX, + sync_buff[beacon1_id].imag() / SHRT_MAX); } - auto cfo_mult = CommsLib::complex_mult_avx(beacon1, beacon0, true); - float phase = 0, prev_phase = 0; + const auto cfo_mult = CommsLib::complex_mult_avx(beacon1, beacon0, true); + float phase = 0.0f; + float prev_phase = 0.0f; for (size_t i = 0; i < cfo_mult.size(); i++) { phase = std::arg(cfo_mult.at(i)); float unwrapped_phase = 0; @@ -910,7 +886,7 @@ float Receiver::estimateCFO(const std::vector>& sync_buff, void Receiver::clientSyncTxRx(int tid, int core_id, SampleBuffer* rx_buffer) { if (config_->core_alloc() == true) { - int core = tid + core_id; + const int core = tid + core_id; MLPD_INFO("Pinning client synctxrx thread %d to core %d\n", tid, core); if (pin_to_core(core) != 0) { @@ -924,25 +900,18 @@ void Receiver::clientSyncTxRx(int tid, int core_id, SampleBuffer* rx_buffer) { this->txFrameDelta_, this->txFrameDelta_ * (1e3 * config_->getFrameDurationSec())); - int SYNC_NUM_SAMPS = config_->samps_per_frame(); - std::vector> syncbuff0(SYNC_NUM_SAMPS, 0); - std::vector> syncbuff1(SYNC_NUM_SAMPS, 0); - std::vector syncrxbuff(2); - syncrxbuff.at(0) = syncbuff0.data(); - if (config_->cl_sdr_ch() == 2) { - syncrxbuff.at(1) = syncbuff1.data(); - } + const size_t samples_per_slot = config_->samps_per_slot(); + const size_t num_rx_buffs = config_->cl_sdr_ch(); + std::vector>> samplemem( + num_rx_buffs, std::vector>( + samples_per_slot, std::complex(0, 0))); - int NUM_SAMPS = config_->samps_per_slot(); - std::vector> buff0(SYNC_NUM_SAMPS, 0); - std::vector> buff1(SYNC_NUM_SAMPS, 0); - std::vector rxbuff(2); - rxbuff.at(0) = buff0.data(); - if (config_->cl_sdr_ch() == 2) { - rxbuff.at(1) = buff1.data(); + std::vector rxbuff; + for (size_t ch = 0; ch < num_rx_buffs; ch++) { + rxbuff.push_back(samplemem.at(ch).data()); } - size_t ant_id = tid * config_->cl_sdr_ch(); + const size_t ant_id = tid * config_->cl_sdr_ch(); // use token to speed up moodycamel::ProducerToken local_ptok(*message_queue_); @@ -951,7 +920,6 @@ void Receiver::clientSyncTxRx(int tid, int core_id, SampleBuffer* rx_buffer) { int buffer_chunk_size = 0; int buffer_id = tid + config_->bs_rx_thread_num(); size_t packetLength = sizeof(Packet) + config_->getPacketDataLength(); - //if (config_->dl_slot_per_frame() > 0) { if (config_->cl_dl_slots().at(0).empty() == false) { buffer_chunk_size = rx_buffer[buffer_id].buffer.size() / packetLength; // handle two channels at each radio @@ -966,66 +934,61 @@ void Receiver::clientSyncTxRx(int tid, int core_id, SampleBuffer* rx_buffer) { tx_buffer_size = cl_tx_buffer_[tid].buffer.size() / packetLength; } - long long rxTime(0); - int sync_index(-1); - int rx_offset = 0; - float cfo_phase_est = 0; - // For USRP clients skip UHD_INIT_TIME_SEC to avoid late packets if (kUsePureUHD == true || kUseSoapyUHD == true) { - int cl_sync_ret = -1; - sleep(UHD_INIT_TIME_SEC); - while (cl_sync_ret < 0) { - cl_sync_ret = client_radio_set_->radioRx(tid, syncrxbuff.data(), - SYNC_NUM_SAMPS, rxTime); - } - } - - // Keep reading one frame worth of data until a beacon is found - // Perform initial beacon detection once every BEACON_INTERVAL frames - while ((config_->running() == true) && (sync_index < 0)) { - for (int find_beacon_retry = 0; find_beacon_retry < BEACON_INTERVAL; - find_beacon_retry++) { - int r; - r = client_radio_set_->radioRx(tid, syncrxbuff.data(), SYNC_NUM_SAMPS, - rxTime); - if (r != SYNC_NUM_SAMPS) { - MLPD_WARN("BAD SYNC Receive( %d / %d ) at Time %lld\n", r, - SYNC_NUM_SAMPS, rxTime); - } + auto start_time = std::chrono::steady_clock::now(); + std::chrono::duration elapsed_seconds{0.0}; + + while (elapsed_seconds.count() < UHD_INIT_TIME_SEC) { + long long ignore_time; + client_radio_set_->radioRx(tid, rxbuff.data(), samples_per_slot, + ignore_time); + elapsed_seconds = std::chrono::duration_cast( + std::chrono::steady_clock::now() - start_time); } - sync_index = this->syncSearch(syncbuff0, SYNC_NUM_SAMPS); - } - if (sync_index >= 0) { - MLPD_INFO("Beacon detected at Time %lld, sync_index: %d\n", rxTime, - sync_index); - rx_offset = sync_index - config_->beacon_size() - config_->prefix(); - cfo_phase_est = estimateCFO(syncbuff0, sync_index); - std::cout << "Client " << tid - << " Estimated CFO (Hz): " << cfo_phase_est * config_->rate() - << std::endl; + std::printf("Wait duration %3.2f seconds \n", elapsed_seconds.count()); } - // Read rx_offset to align with the begining of a frame - assert((rx_offset >= 0) && (rx_offset <= SYNC_NUM_SAMPS)); - if (config_->running() == true) { - MLPD_INFO("Start main client txrx loop... tid=%d\n", tid); - if (rx_offset > 0) { - int rx_data; - rx_data = - client_radio_set_->radioRx(tid, syncrxbuff.data(), rx_offset, rxTime); - if (rx_data != rx_offset) { - MLPD_WARN("Rx data: %d : %d failed to align sync read\n", rx_data, - rx_offset); + //-------------------- New sync + const size_t beacon_detect_window = + static_cast(static_cast(config_->samps_per_slot()) * + kBeaconDetectWindowScaler); + size_t sync_count = 0; + constexpr size_t kTargetSyncCount = 2; + assert(config_->samps_per_frame() >= beacon_detect_window); + while ((sync_count < kTargetSyncCount) && config_->running()) { + const ssize_t sync_index = clientSyncBeacon(tid, beacon_detect_window); + if (sync_index >= 0) { + const ssize_t adjust = + sync_index - (config_->beacon_size() + config_->prefix()); + const size_t alignment_samples = + config_->samps_per_frame() - beacon_detect_window; + MLPD_INFO( + "clientSyncTxRx [%zu]: Beacon detected sync_index: %ld, rx sample " + "offset: %ld, window %zu, samples in frame %zu, alignment removal " + "%zu\n", + tid, sync_index, adjust, beacon_detect_window, + config_->samps_per_frame(), alignment_samples); + + //By definition alignment_samples + adjust must be > 0; + if (static_cast(alignment_samples) + adjust < 0) { + throw std::runtime_error("Unexpected alignment"); } + clientAdjustRx(tid, alignment_samples + adjust); + sync_count++; + } else if (config_->running()) { + MLPD_WARN( + "clientSyncTxRx [%d]: Beacon could not be detected sync_index: %ld\n", + tid, sync_index); + throw std::runtime_error("rx sample offset is less than 0"); } } // Main client read/write loop. size_t frame_id = 0; - size_t slot_id = 0; size_t buffer_offset = 0; - bool resync = false; + //sync on the first beacon after initial detection + bool resync = true; bool resync_enable = (config_->frame_mode() == "continuous_resync"); size_t resync_retry_cnt(0); size_t resync_retry_max(100); @@ -1035,81 +998,110 @@ void Receiver::clientSyncTxRx(int tid, int core_id, SampleBuffer* rx_buffer) { size_t resync_period = static_cast( std::floor(1e9 / (max_cfo * config_->samps_per_frame()))); size_t last_resync = frame_id; - std::printf("Using resync period of %zu\n", resync_period); - int r = 0; - rx_offset = 0; + MLPD_INFO("Start main client txrx loop... tid=%d with resync period of %zu\n", + tid, resync_period); + long long rx_beacon_time(0); + //Always decreases the requested rx samples + size_t beacon_adjust = 0; while (config_->running() == true) { if (config_->max_frame() > 0 && frame_id >= config_->max_frame()) { config_->running(false); break; } - r = client_radio_set_->radioRx(tid, syncrxbuff.data(), - NUM_SAMPS + rx_offset, rxTime); - - if (r < 0) { + //Slot 0 / Beacon... + const int request_samples = samples_per_slot - beacon_adjust; + const int rx_status = client_radio_set_->radioRx( + tid, rxbuff.data(), request_samples, rx_beacon_time); + if (rx_status < 0) { + MLPD_ERROR("Rx status reporting error %d, exiting\n", rx_status); config_->running(false); break; } if (config_->ul_data_slot_present() == true) { + // Notify new frame this->notifyPacket(kClient, frame_id + this->txFrameDelta_, 0, tid, - tx_buffer_size); // Notify new frame + tx_buffer_size); } - if (frame_id - last_resync >= resync_period) { + if ((frame_id - last_resync) >= resync_period) { resync = resync_enable; last_resync = frame_id; MLPD_TRACE("Enable resyncing at frame %zu\n", frame_id); } - rx_offset = 0; if (resync == true) { //Need to bound the beacon detection to the last 'r not the size of the memory (vector) //TODO: Use SIMD for faster conversion // convert data to complex float for sync detection - sync_index = this->syncSearch(syncbuff0, NUM_SAMPS); + ssize_t sync_index = + this->syncSearch(reinterpret_cast*>( + rxbuff.at(kSyncDetectChannel)), + request_samples); if (sync_index >= 0) { - rx_offset = sync_index - config_->beacon_size() - config_->prefix(); - rxTime += rx_offset; + const int new_rx_offset = + sync_index - (config_->beacon_size() + config_->prefix()); + //Adjust tx time + rx_beacon_time += new_rx_offset; resync = false; resync_retry_cnt = 0; resync_success++; MLPD_INFO( - "Re-syncing with offset: %d, after %zu " - "tries, index: %d, tid %d\n", - rx_offset, resync_retry_cnt + 1, sync_index, tid); + "Re-syncing success with offset: %d, after %zu tries, index: %d, " + "tid %d\n", + new_rx_offset, resync_retry_cnt + 1, sync_index, tid); + + if (sync_index >= 0) { + const auto cfo_phase_est = + estimateCFO(samplemem.at(kSyncDetectChannel), sync_index); + std::cout << "Client " << tid << " Estimated CFO (Hz): " + << cfo_phase_est * config_->rate() << std::endl; + } + + //Offset Alignment logic + //If new_rx_offset is positive -- we need to right shift (read less) + if (new_rx_offset >= 0) { + beacon_adjust = new_rx_offset; + } else { + const size_t discard_samples = (-1 * new_rx_offset); + //throw away samples to get back in alignment, could combine with the next beacon but would need bigger buffers + clientAdjustRx(tid, discard_samples); + } } else { resync_retry_cnt++; + + if (resync_retry_cnt > resync_retry_max) { + MLPD_WARN( + "Exceeded resync retry limit (%zu) for client %d reached after " + "%zu resync successes at frame: %zu. Stopping!\n", + resync_retry_max, tid, resync_success, frame_id); + resync = false; + resync_retry_cnt = 0; + config_->running(false); + break; + } } } - if ((resync == true) && (resync_retry_cnt > resync_retry_max)) { - MLPD_WARN( - "Exceeded resync retry limit (%zu) for client " - "%d reached after %zu resync successes at " - "frame: %zu. Stopping!\n", - resync_retry_max, tid, resync_success, frame_id); - resync = false; - resync_retry_cnt = 0; - config_->running(false); - break; - } // schedule all TX slot // config_->tx_advance() needs calibration based on SDR model and sampling rate if (config_->ul_data_slot_present() == true) { - while (-1 != this->clientTxData(tid, frame_id, rxTime)) - ; + int tx_return = 0; + while (tx_return >= 0) { + tx_return = this->clientTxData(tid, frame_id, rx_beacon_time); + } } else { - this->clientTxPilots(tid, rxTime + txTimeDelta_); + this->clientTxPilots(tid, rx_beacon_time + txTimeDelta_); } // end if config_->ul_data_slot_present() - slot_id++; - - for (; slot_id < config_->slot_per_frame(); slot_id++) { + //Beacon + Tx Complete, process the rest of the slots + for (size_t slot_id = 1; slot_id < config_->slot_per_frame(); slot_id++) { + int rx_data_status; + long long rx_data_time; if (config_->isDlData(tid, slot_id)) { // Set buffer status(es) to full; fail if full already for (size_t ch = 0; ch < config_->cl_sdr_ch(); ++ch) { - int bit = 1 << (buffer_offset + ch) % sizeof(std::atomic_int); - int offs = (buffer_offset + ch) / sizeof(std::atomic_int); - int old = + const int bit = 1 << (buffer_offset + ch) % sizeof(std::atomic_int); + const int offs = (buffer_offset + ch) / sizeof(std::atomic_int); + const int old = std::atomic_fetch_or(&pkt_buf_inuse[offs], bit); // now full // if buffer was full, exit if ((old & bit) != 0) { @@ -1120,21 +1112,18 @@ void Receiver::clientSyncTxRx(int tid, int core_id, SampleBuffer* rx_buffer) { } // Receive data into buffers - Packet* pkt[config_->cl_sdr_ch()]; - void* samp[config_->cl_sdr_ch()]; + std::vector pkts(config_->cl_sdr_ch()); + std::vector dl_slot_samp(config_->cl_sdr_ch()); for (size_t ch = 0; ch < config_->cl_sdr_ch(); ++ch) { - pkt[ch] = (Packet*)(buffer + (buffer_offset + ch) * packetLength); - samp[ch] = pkt[ch]->data; - } - - if ((r = this->client_radio_set_->radioRx(tid, samp, NUM_SAMPS, - rxTime)) < 0) { - config_->running(false); - break; + pkts.at(ch) = reinterpret_cast( + buffer + (buffer_offset + ch) * packetLength); + dl_slot_samp.at(ch) = pkts.at(ch)->data; } + rx_data_status = this->client_radio_set_->radioRx( + tid, dl_slot_samp.data(), samples_per_slot, rx_data_time); for (size_t ch = 0; ch < config_->cl_sdr_ch(); ++ch) { - new (pkt[ch]) Packet(frame_id, slot_id, 0, ant_id + ch); + new (pkts.at(ch)) Packet(frame_id, slot_id, 0, ant_id + ch); // push kEventRxSymbol event into the queue this->notifyPacket(kClient, frame_id, slot_id, ant_id + ch, buffer_chunk_size, @@ -1143,19 +1132,102 @@ void Receiver::clientSyncTxRx(int tid, int core_id, SampleBuffer* rx_buffer) { buffer_offset %= buffer_chunk_size; } } else { - r = this->client_radio_set_->radioRx(tid, rxbuff.data(), NUM_SAMPS, - rxTime); - if (r < 0) { - config_->running(false); - break; - } + //Not dl data so we throw it away + rx_data_status = this->client_radio_set_->radioRx( + tid, rxbuff.data(), samples_per_slot, rx_data_time); } - if (r != NUM_SAMPS) { - MLPD_WARN("BAD Receive(%d/%d) at Time %lld, frame count %zu\n", r, - NUM_SAMPS, rxTime, frame_id); + if (rx_data_status < 0) { + MLPD_ERROR( + "Rx status reporting error %d during frame %zu , slot %zu, " + "exiting\n", + rx_data_status, frame_id, slot_id); + config_->running(false); + break; + } else if (rx_data_status != static_cast(samples_per_slot)) { + MLPD_WARN("BAD Receive(%d/%zu) at Time %lld, frame count %zu\n", + rx_data_status, samples_per_slot, rx_data_time, frame_id); } } // end for frame_id++; - slot_id = 0; } // end while } + +//Blocking function for beacon detected or exit() +ssize_t Receiver::clientSyncBeacon(size_t radio_id, size_t sample_window) { + ssize_t sync_index = -1; + long long rx_time = 0; + assert(sample_window <= config_->samps_per_frame()); + const size_t num_rx_buffs = config_->cl_sdr_ch(); + std::vector>> syncbuffmem( + num_rx_buffs, std::vector>( + sample_window, std::complex(0, 0))); + + std::vector syncrxbuffs; + for (size_t ch = 0; ch < num_rx_buffs; ch++) { + syncrxbuffs.push_back(syncbuffmem.at(ch).data()); + } + + while (config_->running() && (sync_index < 0)) { + const int rx_status = client_radio_set_->radioRx( + radio_id, syncrxbuffs.data(), sample_window, rx_time); + + if (rx_status < 0) { + MLPD_ERROR("clientSyncBeacon [%zu]: BAD SYNC Received (%d/%zu) %lld\n", + radio_id, rx_status, sample_window, rx_time); + } else { + const size_t new_samples = static_cast(rx_status); + if (new_samples == sample_window) { + MLPD_TRACE( + "clientSyncBeacon - Samples %zu - Window %zu - Check Beacon %ld\n", + new_samples, sample_window); + + sync_index = syncSearch(syncbuffmem.at(kSyncDetectChannel).data(), + sample_window); + } else { + MLPD_ERROR( + "clientSyncBeacon [%zu]: BAD SYNC - Rx samples not requested size " + "(%zu/%zu) %lld\n", + radio_id, new_samples, sample_window, rx_time); + } + } + } // end while sync_index < 0 + return sync_index; +} + +/// This function blocks untill all the discard_samples are received for a given radio +void Receiver::clientAdjustRx(size_t radio_id, size_t discard_samples) { + const size_t num_rx_buffs = config_->cl_sdr_ch(); + long long rx_time = 0; + + //This can be fixed and combined with other scratch memory + std::vector>> temp_mem( + num_rx_buffs, std::vector>(discard_samples)); + + std::vector trash_memory; + for (size_t ch = 0; ch < num_rx_buffs; ch++) { + trash_memory.push_back(temp_mem.at(ch).data()); + } + + while (config_->running() && (discard_samples > 0)) { + const int rx_status = client_radio_set_->radioRx( + radio_id, trash_memory.data(), discard_samples, rx_time); + + if (rx_status < 0) { + MLPD_ERROR( + "clientAdjustRx [%zu]: BAD Rx Adjust Status Received (%d/%zu) %lld\n", + radio_id, rx_status, discard_samples, rx_time); + } else { + size_t new_samples = static_cast(rx_status); + if (new_samples <= discard_samples) { + discard_samples -= new_samples; + MLPD_INFO("clientAdjustRx [%zu]: Discarded Samples (%zu/%zu)\n", + radio_id, new_samples, discard_samples); + } else { + MLPD_ERROR( + "clientAdjustRx [%zu]: BAD radioRx more samples then requested " + "(%zu/%zu) %lld\n", + radio_id, new_samples, discard_samples, rx_time); + } + } + } // request_samples > 0 +} From 486209338f459a3eabe186ad692e0a9c5849995a Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Tue, 5 Jul 2022 12:07:24 -0400 Subject: [PATCH 25/45] Update receiver.h Sync Update --- CC/Sounder/include/receiver.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CC/Sounder/include/receiver.h b/CC/Sounder/include/receiver.h index 77fbff64..2284795d 100644 --- a/CC/Sounder/include/receiver.h +++ b/CC/Sounder/include/receiver.h @@ -84,6 +84,10 @@ class Receiver { private: Config* config_; + size_t num_channels_buff_; + size_t num_channels_; + size_t num_radios_; + size_t radio_id_; #if defined(USE_UHD) ClientRadioSetUHD* client_radio_set_; From 2fde7cca775d6952e271785dcc5f33c0f54a30ab Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Thu, 7 Jul 2022 14:06:11 -0400 Subject: [PATCH 26/45] Update comms-lib.h Changed back to the original implementation --- CC/Sounder/include/comms-lib.h | 541 ++++++++++++++++++++++++--------- 1 file changed, 393 insertions(+), 148 deletions(-) diff --git a/CC/Sounder/include/comms-lib.h b/CC/Sounder/include/comms-lib.h index 2d579a60..90e6f05d 100644 --- a/CC/Sounder/include/comms-lib.h +++ b/CC/Sounder/include/comms-lib.h @@ -1,166 +1,411 @@ /* - - Communications Library: - a) Generate pilot/preamble sequences - b) OFDM modulation - ---------------------------------------------------------------------- - Copyright (c) 2018-2019, Rice University + Copyright (c) 2018-2021, Rice University RENEW OPEN SOURCE LICENSE: http://renew-wireless.org/license Author(s): Rahman Doost-Mohamamdy: doost@rice.edu - Oscar Bejarano: obejarano@rice.edu + +--------------------------------------------------------------------- + Reads Configuration Parameters from file --------------------------------------------------------------------- */ +#ifndef CONFIG_HEADER +#define CONFIG_HEADER + #include -#include -#include /* for fprintf */ -#include -#include /* for memcpy */ -#include #include -#include -#include // std::ifstream -#include -#include +#include #include -#include "fft.h" +class Config { + public: + Config(const std::string&, const std::string&, const bool, const bool); + ~Config(); -static constexpr size_t kPilotSubcarrierSpacing = 12; -static constexpr size_t kDefaultPilotScOffset = 6; + //Accessors + inline bool bs_present(void) const { return this->bs_present_; } + inline bool client_present(void) const { return this->client_present_; } + inline size_t num_bs_sdrs_all(void) const { return this->num_bs_sdrs_all_; } + inline size_t num_bs_antennas_all(void) const { + return this->num_bs_antennas_all_; + } + inline size_t num_cl_sdrs(void) const { return this->num_cl_sdrs_; } + inline size_t core_alloc(void) const { return this->core_alloc_; } + inline int slot_samp_size(void) const { return this->slot_samp_size_; } + inline size_t samps_per_slot(void) const { return this->samps_per_slot_; } + inline size_t slot_per_frame(void) const { return this->slot_per_frame_; } + inline size_t symbol_per_slot(void) const { return this->symbol_per_slot_; } + inline size_t samps_per_frame(void) const { + return this->samps_per_slot_ * this->slot_per_frame_; + } + inline bool ul_data_slot_present(void) const { + return this->ul_data_slot_present_; + } + inline bool dl_data_slot_present(void) const { + return this->dl_data_slot_present_; + } + inline size_t num_cells(void) const { return this->num_cells_; } + inline size_t guard_mult(void) const { return this->guard_mult_; } + inline bool bs_hw_framer(void) const { return this->bs_hw_framer_; } + inline bool hw_framer(void) const { return this->hw_framer_; } + inline int prefix(void) const { return this->prefix_; } + inline int postfix(void) const { return this->postfix_; } + inline int beacon_size(void) const { return this->beacon_size_; } + inline double bw_filter(void) const { return this->bw_filter_; } + inline double freq(void) const { return this->freq_; } + inline double nco(void) const { return this->nco_; } + inline double radio_rf_freq(void) const { return this->radio_rf_freq_; } + inline bool single_gain(void) const { return this->single_gain_; } + inline bool cl_agc_en(void) const { return this->cl_agc_en_; } + inline int cl_agc_gain_init(void) const { return this->cl_agc_gain_init_; } + inline bool imbalance_cal_en(void) const { return this->imbalance_cal_en_; } + inline bool sample_cal_en(void) const { return this->sample_cal_en_; } + inline size_t max_frame(void) const { return this->max_frame_; } + inline size_t ul_data_frame_num(void) const { + return this->ul_data_frame_num_; + } + inline size_t dl_data_frame_num(void) const { + return this->dl_data_frame_num_; + } + inline bool beam_sweep(void) const { return this->beam_sweep_; } + inline size_t beacon_channel(void) const { return this->beacon_ch_; } + inline size_t beacon_ant(void) const { return this->beacon_ant_; } + inline size_t beacon_radio(void) const { return this->beacon_radio_; } + inline size_t num_cl_antennas(void) const { return this->num_cl_antennas_; } + inline size_t fft_size(void) const { return this->fft_size_; } + inline size_t cp_size(void) const { return this->cp_size_; } + inline size_t symbol_data_subcarrier_num(void) const { + return this->symbol_data_subcarrier_num_; + } + inline size_t pilot_slot_per_frame(void) const { + return this->pilot_slot_per_frame_; + } + inline size_t noise_slot_per_frame(void) const { + return this->noise_slot_per_frame_; + } + inline size_t ul_slot_per_frame(void) const { + return this->ul_slot_per_frame_; + } + inline size_t dl_slot_per_frame(void) const { + return this->dl_slot_per_frame_; + } + inline const std::vector>& dl_slots(void) const { + return this->dl_slots_; + } + inline double rate(void) const { return this->rate_; } + inline int tx_advance(size_t id) const { return this->tx_advance_.at(id); } + inline size_t cl_sdr_ch(void) const { return this->cl_sdr_ch_; } + inline size_t bs_sdr_ch(void) const { return this->bs_sdr_ch_; } -static inline double computeAbs(std::complex x) { return std::abs(x); } + inline bool running(void) const { return this->running_.load(); } + inline void running(bool value) { this->running_ = value; } -//template -//static inline T computeAbs(std::complex x) { return std::abs(x); } -static inline double computePower(std::complex x) { - return std::pow(std::abs(x), 2); -} -static inline double computeSquare(double x) { return x * x; } + inline const std::string& frame_mode(void) const { return this->frame_mode_; } + inline const std::string& bs_channel(void) const { return this->bs_channel_; } + inline const std::string& trace_file(void) const { return this->trace_file_; } + inline const std::string& cl_channel(void) const { return this->cl_channel_; } + inline const std::string& beacon_seq(void) const { return this->beacon_seq_; } + inline const std::string& pilot_seq(void) const { return this->pilot_seq_; } + inline const std::string& data_mod(void) const { return this->data_mod_; } + inline const std::string& cl_data_mod(void) const { + return this->cl_data_mod_; + } -class CommsLib { - public: - enum SequenceType { - STS_SEQ, - LTS_SEQ, - LTS_SEQ_F, - LTE_ZADOFF_CHU, - LTE_ZADOFF_CHU_F, - GOLD_IFFT, - HADAMARD + inline const std::vector& n_bs_sdrs_agg(void) const { + return this->n_bs_sdrs_agg_; + } + inline bool internal_measurement(void) const { + return this->internal_measurement_; + } + inline bool ref_node_enable(void) const { return this->ref_node_enable_; } + inline size_t cal_ref_sdr_id(void) const { return this->cal_ref_sdr_id_; } + inline const std::vector>& calib_frames(void) const { + return this->calib_frames_; + } + + //TODO split the following (4) in accessor and setter + inline std::vector>& beacon_ci16(void) { + return this->beacon_ci16_; + } + inline std::vector>& neg_beacon_ci16(void) { + return this->neg_beacon_ci16_; + } + inline std::vector>>& tx_data(void) { + return this->tx_data_; + }; + inline std::vector>& pilot_ci16(void) { + return this->pilot_ci16_; + } + inline std::vector& n_bs_sdrs(void) { return this->n_bs_sdrs_; } + + inline const std::vector& cl_frames(void) const { + return this->cl_frames_; + } + inline const std::vector>& cl_pilot_slots(void) const { + return this->cl_pilot_slots_; + } + inline const std::vector>& cl_ul_slots(void) const { + return this->cl_ul_slots_; + } + inline const std::vector>& cl_dl_slots(void) const { + return this->cl_dl_slots_; + } + inline const std::vector& cl_sdr_ids(void) const { + return this->cl_sdr_ids_; + } + inline const std::vector& ul_tx_fd_data_files(void) const { + return this->ul_tx_fd_data_files_; + } + inline const std::vector& ul_tx_td_data_files(void) const { + return this->ul_tx_td_data_files_; + } + inline const std::vector& dl_tx_fd_data_files(void) const { + return this->dl_tx_fd_data_files_; + } + inline const std::vector& dl_tx_td_data_files(void) const { + return this->dl_tx_td_data_files_; + } + + inline const std::vector& data_ind(void) const { + return this->data_ind_; + } + inline const std::vector& coeffs(void) const { + return this->coeffs_; + } + inline const std::vector& pilot(void) const { return this->pilot_; } + inline const std::vector>& cl_txgain_vec(void) const { + return this->cl_txgain_vec_; + } + inline const std::vector>& cl_rxgain_vec(void) const { + return this->cl_rxgain_vec_; + } + inline const std::vector& beacon(void) const { + return this->beacon_; + } + + inline std::vector>& pilot_sym_t(void) { + return this->pilot_sym_t_; + }; + inline std::vector>& pilot_sym_f(void) { + return this->pilot_sym_f_; + }; + inline std::vector>& pilot_sc(void) { + return this->pilot_sc_; }; + inline std::vector& pilot_sc_ind(void) { + return this->pilot_sc_ind_; + }; + + inline const std::vector& frames(void) const { + return this->frames_; + } - enum ModulationOrder { QPSK = 2, QAM16 = 4, QAM64 = 6 }; - - CommsLib(std::string); - ~CommsLib(); - - static std::vector> getSequence(size_t type, - size_t seq_len = 0); - static std::vector> modulate(std::vector, int); - static std::vector getDataSc( - size_t fftSize, size_t DataScNum, - size_t PilotScOffset = kDefaultPilotScOffset); - static std::vector getNullSc(size_t fftSize, size_t DataScNum); - static std::vector> getPilotScValue( - size_t fftSize, size_t DataScNum, - size_t PilotScOffset = kDefaultPilotScOffset); - static std::vector getPilotScIndex( - size_t fftSize, size_t DataScNum, - size_t PilotScOffset = kDefaultPilotScOffset); - static std::vector> FFT( - const std::vector>&, int); - static std::vector> IFFT( - const std::vector>&, int, float scale = 0.5, - bool normalize = true); - - static int findLTS(const std::vector>& iq, int seqLen); - static size_t find_pilot_seq(const std::vector>& iq, - const std::vector>& pilot, - size_t seqLen); - template - //static std::vector convolve(std::vector const& f, std::vector const& g); - static std::vector convolve(std::vector const& f, - std::vector const& g) { - /* Convolution of two vectors - * Source: - * https://stackoverflow.com/questions/24518989/how-to-perform-1-dimensional-valid-convolution - */ - int const nf = f.size(); - int const ng = g.size(); - int const n = nf + ng - 1; - std::vector out(n, 0); - for (auto i(0); i < n; ++i) { - int const jmn = (i >= ng - 1) ? i - (ng - 1) : 0; - int const jmx = (i < nf - 1) ? i : nf - 1; - for (auto j(jmn); j <= jmx; ++j) { - out[i] += f[j] * g[i - j]; - } - } - return out; - } - static float find_max_abs(const std::vector>& in); - static std::vector> csign( - const std::vector>& iq); - static inline int hadamard2(int i, int j) { - return (__builtin_parity(i & j) != 0 ? -1 : 1); - } - static std::vector magnitudeFFT( - std::vector> const&, std::vector const&, - size_t); - static std::vector hannWindowFunction(size_t); - static double windowFunctionPower(std::vector const&); - template - static T findTone(std::vector const&, double, double, size_t, - const size_t delta = 10); - static float measureTone(std::vector> const&, - std::vector const&, double, double, size_t, - const size_t delta = 10); - - // Functions using AVX - static int find_beacon(const std::vector>& raw_samples); - static int find_beacon_avx( - const std::vector>& raw_samples, - const std::vector>& match_samples); - - ///Find Beacon with raw samples from the radio - static int find_beacon(const std::complex* raw_samples, - size_t check_window); - - static ssize_t find_beacon_avx( - const std::complex* raw_samples, - const std::vector>& match_samples, - size_t check_window); - - static std::vector correlate_avx_s(std::vector const& f, - std::vector const& g); - static std::vector correlate_avx_si(std::vector const& f, - std::vector const& g); - static std::vector abs2_avx(std::vector> const& f); - static std::vector abs2_avx( - std::vector> const& f); - static std::vector> auto_corr_mult_avx( - std::vector> const& f, const int dly, - const bool conj = true); - static std::vector> auto_corr_mult_avx( - std::vector> const& f, const int dly, - const bool conj = true); - static std::vector> correlate_avx( - std::vector> const& f, - std::vector> const& g); - static std::vector> correlate_avx( - std::vector> const& f, - std::vector> const& g); - static std::vector> complex_mult_avx( - std::vector> const& f, - std::vector> const& g, const bool conj); - static std::vector> complex_mult_avx( - std::vector> const& f, - std::vector> const& g, const bool conj); - //private: - // static inline float** init_qpsk(); - // static inline float** init_qam16(); - // static inline float** init_qam64(); + inline const std::vector>& bs_sdr_ids(void) const { + return this->bs_sdr_ids_; + } + inline const std::vector>& gold_cf32(void) const { + return this->gold_cf32_; + } + + inline size_t cl_rx_thread_num(void) const { return this->cl_rx_thread_num_; } + inline size_t bs_rx_thread_num(void) const { return this->bs_rx_thread_num_; } + inline size_t recorder_thread_num(void) const { + return this->recorder_thread_num_; + } + inline size_t reader_thread_num(void) const { + return this->reader_thread_num_; + } + + inline const std::vector& hub_ids(void) const { + return this->hub_ids_; + } + + inline const std::vector& calib_ids(void) const { + return this->calib_ids_; + } + + inline const std::vector& tx_gain(void) const { + return this->tx_gain_; + } + inline const std::vector& rx_gain(void) const { + return this->rx_gain_; + } + inline const std::vector& cal_tx_gain(void) const { + return this->cal_tx_gain_; + } + + inline const std::vector>>& txdata_freq_dom( + void) const { + return this->txdata_freq_dom_; + } + + inline const std::vector>>& + dl_txdata_freq_dom(void) const { + return this->dl_txdata_freq_dom_; + } + + inline double tx_scale(void) const { return this->tx_scale_; } + inline double pilot_scale(void) const { return this->pilot_scale_; } + inline size_t getPacketDataLength() const { + return (2 * this->samps_per_slot_ * sizeof(short)); + } + + /// Return the slot duration in seconds + inline double getSlotDurationSec() const { + return ((this->symbol_per_slot_ * this->samps_per_slot_) / this->rate_); + } + /// Return the frame duration in seconds + inline double getFrameDurationSec() const { + return ((this->samps_per_frame()) / this->rate_); + } + inline size_t getTxFrameDelta() const { return tx_frame_delta_; } + + size_t getNumAntennas(); + size_t getMaxNumAntennas(); + size_t getNumBsSdrs(); + size_t getTotNumAntennas(); + size_t getNumRecordedSdrs(); + int getClientId(int, int); + int getNoiseSlotIndex(int, int); + int getUlSlotIndex(int, int); + int getDlSlotIndex(int, int); + bool isPilot(int, int); + bool isNoise(int, int); + bool isUlData(int, int); + bool isDlData(int, int); + unsigned getCoreCount(); + + void loadULData(); + void loadDLData(); + + private: + bool bs_present_; + bool client_present_; + std::string directory_; + + // common features + double freq_; + double nco_; // baseband frequency controlled by NCO + double rate_; + double + radio_rf_freq_; // RF frequency set frame_modeon the radio after NCO adjustments + double bw_filter_; + size_t fft_size_; + size_t cp_size_; + size_t ofdm_symbol_size_; + size_t symbol_data_subcarrier_num_; + size_t symbol_per_slot_; + size_t slot_samp_size_; + size_t samps_per_slot_; + size_t prefix_; + size_t postfix_; + size_t slot_per_frame_; + size_t pilot_slot_per_frame_; + size_t noise_slot_per_frame_; + size_t ul_slot_per_frame_; + size_t dl_slot_per_frame_; + float tx_scale_; + float pilot_scale_; + std::string pilot_seq_; + std::string beacon_seq_; + bool ul_data_slot_present_; + bool dl_data_slot_present_; + std::string data_mod_; + std::string cl_data_mod_; + + // BS features + size_t num_cells_; + size_t guard_mult_; + std::vector bs_sdr_file_; // No accessor + std::string hub_file_; // No accessor + std::string ref_sdr; + size_t bs_sdr_ch_; + std::vector> bs_sdr_ids_; + std::vector hub_ids_; + std::vector calib_ids_; + std::vector> gold_cf32_; + std::vector beacon_; + std::vector> beacon_ci16_; + std::vector> neg_beacon_ci16_; + int beacon_size_; + size_t beacon_ant_; + size_t beacon_radio_; + size_t beacon_ch_; + bool beam_sweep_; + std::vector n_bs_sdrs_; + std::vector n_bs_antennas_; //No accessor + std::vector n_bs_sdrs_agg_; + size_t num_bs_sdrs_all_; + size_t num_bs_antennas_all_; + std::string bs_channel_; + std::vector frames_; + std::string frame_mode_; + bool bs_hw_framer_; + bool hw_framer_; + size_t max_frame_; + size_t ul_data_frame_num_; + size_t dl_data_frame_num_; + std::vector> + pilot_slots_; // Accessed through getClientId + std::vector> noise_slots_; + std::vector> + ul_slots_; // Accessed through getUlSFIndex() + std::vector> dl_slots_; + bool single_gain_; + std::vector tx_gain_; + std::vector rx_gain_; + std::vector cal_tx_gain_; + bool sample_cal_en_; + bool imbalance_cal_en_; + std::string trace_file_; + std::vector> calib_frames_; + bool internal_measurement_; + bool ref_node_enable_; + size_t cal_ref_sdr_id_; + size_t tx_frame_delta_; + + // Clients features + std::vector cl_sdr_ids_; + size_t max_tx_gain_ue_; + size_t num_cl_sdrs_; + size_t cl_sdr_ch_; + size_t num_cl_antennas_; + std::string cl_channel_; + bool cl_agc_en_; + int cl_agc_gain_init_; + std::vector tx_advance_; + std::vector data_ind_; + std::vector coeffs_; + std::vector> pilot_ci16_; + std::vector pilot_; + std::vector> pilot_sc_; + std::vector pilot_sc_ind_; + std::vector> pilot_sym_t_; + std::vector> pilot_sym_f_; + std::vector>> tx_data_; + std::vector>> txdata_freq_dom_; + std::vector>> txdata_time_dom_; + std::vector>> dl_txdata_freq_dom_; + std::vector>> dl_txdata_time_dom_; + + std::vector cl_frames_; + std::vector> cl_pilot_slots_; + std::vector> cl_ul_slots_; + std::vector> cl_dl_slots_; + + std::vector> cl_txgain_vec_; + std::vector> cl_rxgain_vec_; + std::vector ul_tx_td_data_files_; + std::vector ul_tx_fd_data_files_; + std::vector dl_tx_td_data_files_; + std::vector dl_tx_fd_data_files_; + + std::atomic running_; + bool core_alloc_; + size_t bs_rx_thread_num_; + size_t cl_rx_thread_num_; + size_t recorder_thread_num_; + size_t reader_thread_num_; }; + +#endif /* CONFIG_HEADER */ From de76e35fba4a1c1b36fc007d5d0dcf16e897c3a4 Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Thu, 7 Jul 2022 14:08:17 -0400 Subject: [PATCH 27/45] Update receiver.h Changed back to the original implementation. --- CC/Sounder/include/receiver.h | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/CC/Sounder/include/receiver.h b/CC/Sounder/include/receiver.h index 2284795d..ac98843b 100644 --- a/CC/Sounder/include/receiver.h +++ b/CC/Sounder/include/receiver.h @@ -71,23 +71,16 @@ class Receiver { static void* clientTxRx_launch(void* in_context); void clientTxRx(int tid); void clientSyncTxRx(int tid, int core_id, SampleBuffer* rx_buffer); - ssize_t syncSearch(const std::complex* check_data, - size_t search_window); - + int syncSearch(const std::vector>& sync_buff, + size_t sync_num_samps); float estimateCFO(const std::vector>& sync_buff, int sync_index); void initBuffers(); void clientTxPilots(size_t user_id, long long base_time); int clientTxData(int tid, int frame_id, long long base_time); - ssize_t clientSyncBeacon(size_t radio_id, size_t sample_window); - void clientAdjustRx(size_t radio_id, size_t discard_samples); private: Config* config_; - size_t num_channels_buff_; - size_t num_channels_; - size_t num_radios_; - size_t radio_id_; #if defined(USE_UHD) ClientRadioSetUHD* client_radio_set_; From 8edc0660dca8ce74b973fb381cd9fd5e1f213c2e Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Thu, 7 Jul 2022 14:09:54 -0400 Subject: [PATCH 28/45] Update comms-lib-avx.cc Changed the original implementation. --- CC/Sounder/comms-lib-avx.cc | 52 +++++++++---------------------------- 1 file changed, 12 insertions(+), 40 deletions(-) diff --git a/CC/Sounder/comms-lib-avx.cc b/CC/Sounder/comms-lib-avx.cc index 060a45b2..45afcd5e 100644 --- a/CC/Sounder/comms-lib-avx.cc +++ b/CC/Sounder/comms-lib-avx.cc @@ -12,7 +12,6 @@ find_beacon_avx: Correlation and Peak detection of a beacon with Gold code (2 re #include #include -#include #include #include @@ -22,52 +21,24 @@ find_beacon_avx: Correlation and Peak detection of a beacon with Gold code (2 re #define USE_AVX -static constexpr size_t kBytesIn256Bits = (256 / 8); - -//single-precision -#define AVX_PACKED_SP (8) -// short int -#define AVX_PACKED_SI (16) -// complex short int -#define AVX_PACKED_CS (8) - -static constexpr float kShortMaxFloat = SHRT_MAX; - -ssize_t CommsLib::find_beacon_avx( - const std::complex* raw_samples, - const std::vector>& match_samples, - size_t check_window) { - //Sample window must be multiple of 64Bytes (for avx 512) - static constexpr size_t kWindowAlignment = 64; - const size_t padded_window = - (((check_window / kWindowAlignment) + 1) * kWindowAlignment); - - //Allocate memory, only used for beacon detection - std::vector> sync_compare( - padded_window, std::complex(0.0f, 0.0f)); - - // convert entire frame data to complex float for sync detection - for (size_t i = 0; i < check_window; i++) { - sync_compare.at(i) = (std::complex( - static_cast(raw_samples[i].real()) / kShortMaxFloat, - static_cast(raw_samples[i].imag()) / kShortMaxFloat)); - } - return CommsLib::find_beacon_avx(sync_compare, match_samples); -} +static const size_t kBytesIn256Bits = (256 / 8); -int CommsLib::find_beacon_avx( - const std::vector>& raw_samples, - const std::vector>& match_samples) { +#define AVX_PACKED_SP 8 //single-precision +#define AVX_PACKED_SI 16 // short int +#define AVX_PACKED_CS 8 // complex short int + +int CommsLib::find_beacon_avx(const std::vector>& iq, + const std::vector>& seq) { std::queue valid_peaks; // Original LTS sequence - int seqLen = match_samples.size(); + int seqLen = seq.size(); struct timespec tv, tv2; clock_gettime(CLOCK_MONOTONIC, &tv); // correlate signal with beacon std::vector> gold_corr_avx = - CommsLib::correlate_avx(raw_samples, match_samples); + CommsLib::correlate_avx(iq, seq); clock_gettime(CLOCK_MONOTONIC, &tv2); #ifdef TEST_BENCH double diff1 = @@ -129,14 +100,15 @@ int CommsLib::find_beacon_avx( fclose(fp); filename = "indata.bin"; FILE* fi = fopen(filename.c_str(), "wb"); - float* idata_ptr = (float*)raw_samples.data(); - fwrite(idata_ptr, raw_samples.size() * 2, sizeof(float), fi); + float* idata_ptr = (float*)iq.data(); + fwrite(idata_ptr, iq.size() * 2, sizeof(float), fi); fclose(fi); #endif if (valid_peaks.empty()) { valid_peaks.push(-1); } + return valid_peaks.front(); } From 0489daf3936ba5a627148960e1067fab2c9bb382 Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Thu, 7 Jul 2022 14:10:44 -0400 Subject: [PATCH 29/45] Update comms-lib.cc Changed to the original implementation --- CC/Sounder/comms-lib.cc | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/CC/Sounder/comms-lib.cc b/CC/Sounder/comms-lib.cc index 59f9e9f3..11e01191 100644 --- a/CC/Sounder/comms-lib.cc +++ b/CC/Sounder/comms-lib.cc @@ -19,15 +19,11 @@ #include "include/comms-lib.h" -#include - #include #include "include/constants.h" #include "include/utils.h" -static constexpr float kShortMaxFloat = SHRT_MAX; - int CommsLib::findLTS(const std::vector>& iq, int seqLen) { /* * Find 802.11-based LTS (Long Training Sequence) @@ -114,22 +110,8 @@ size_t CommsLib::find_pilot_seq(const std::vector>& iq, return best_peak; } -int CommsLib::find_beacon(const std::complex* raw_samples, - size_t check_window) { - //Allocate memory, only used for beacon detection (consider making this static) - std::vector> beacon_compare( - check_window, std::complex(0.0f, 0.0f)); - - // convert entire frame data to complex float for sync detection - for (size_t i = 0; i < check_window; i++) { - beacon_compare.at(i) = (std::complex( - static_cast(raw_samples[i].real()) / kShortMaxFloat, - static_cast(raw_samples[i].imag()) / kShortMaxFloat)); - } - return CommsLib::find_beacon(beacon_compare); -} - int CommsLib::find_beacon(const std::vector>& iq) { + //std::vector> gold_seq; int best_peak; std::queue valid_peaks; From f041bcf4edb2b3d9b99b5c3dc7668cfb7db0e416 Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Thu, 7 Jul 2022 14:17:20 -0400 Subject: [PATCH 30/45] Update receiver.h Changed to the original implementation --- CC/Sounder/include/receiver.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CC/Sounder/include/receiver.h b/CC/Sounder/include/receiver.h index ac98843b..a6b63906 100644 --- a/CC/Sounder/include/receiver.h +++ b/CC/Sounder/include/receiver.h @@ -81,6 +81,10 @@ class Receiver { private: Config* config_; + size_t num_channels_buff_; + size_t num_channels_; + size_t num_radios_; + size_t radio_id_; #if defined(USE_UHD) ClientRadioSetUHD* client_radio_set_; From 79e499c21aebef21895999e6de0b859113969a51 Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Thu, 7 Jul 2022 15:11:35 -0400 Subject: [PATCH 31/45] Update receiver.cc changed and cleaned up to the original implementation --- CC/Sounder/receiver.cc | 397 ++++++++++++++++------------------------- 1 file changed, 151 insertions(+), 246 deletions(-) diff --git a/CC/Sounder/receiver.cc b/CC/Sounder/receiver.cc index 4b3a2580..821d5a9a 100644 --- a/CC/Sounder/receiver.cc +++ b/CC/Sounder/receiver.cc @@ -12,7 +12,6 @@ #include #include -#include #include #include @@ -27,12 +26,9 @@ #include "include/macros.h" #include "include/utils.h" -//Default to detect the beacon on first channel -static constexpr size_t kSyncDetectChannel = 0; -static constexpr float kBeaconDetectWindowScaler = 2.33f; - pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; +static constexpr float SHRT_MAX_FLOAT = SHRT_MAX; Receiver::Receiver( Config* config, moodycamel::ConcurrentQueue* in_queue, @@ -831,15 +827,21 @@ int Receiver::clientTxData(int tid, int frame_id, long long base_time) { return -1; } -ssize_t Receiver::syncSearch(const std::complex* check_data, - size_t search_window) { - ssize_t sync_index(-1); - assert(search_window <= config_->samps_per_frame()); +int Receiver::syncSearch(const std::vector>& sync_buff, + size_t sync_num_samps) { + int sync_index(-1); + // convert data to complex float for sync detection + std::vector> sync_buff_float(sync_num_samps, 0); + for (size_t i = 0; i < sync_num_samps; i++) { + sync_buff_float[i] = + (std::complex(sync_buff[i].real() / SHRT_MAX_FLOAT, + sync_buff[i].imag() / SHRT_MAX_FLOAT)); + } + //TODO syncbuff0 is sloppy here since we recevied into syncrxbuff.data(), r bytes. #if defined(__x86_64__) - sync_index = CommsLib::find_beacon_avx(check_data, config_->gold_cf32(), - search_window); + sync_index = CommsLib::find_beacon_avx(sync_buff_float, config_->gold_cf32()); #else - sync_index = CommsLib::find_beacon(check_data, search_window); + sync_index = CommsLib::find_beacon(sync_buff_float); #endif return sync_index; } @@ -847,23 +849,22 @@ ssize_t Receiver::syncSearch(const std::complex* check_data, float Receiver::estimateCFO(const std::vector>& sync_buff, int sync_index) { float cfo_phase_est = 0; - const int beacon_start = sync_index - config_->beacon_size(); - const int beacon_half_size = config_->beacon_size() / 2; - std::vector> beacon0(beacon_half_size, 0.0f); - std::vector> beacon1(beacon_half_size, 0.0f); + int beacon_start = sync_index - config_->beacon_size(); + int beacon_half_size = config_->beacon_size() / 2; + std::vector> beacon0(beacon_half_size); + std::vector> beacon1(beacon_half_size); for (int i = 0; i < beacon_half_size; i++) { - const size_t beacon0_id = i + beacon_start; - const size_t beacon1_id = i + beacon_start + beacon_half_size; - beacon0.at(i) = - std::complex(sync_buff[beacon0_id].real() / SHRT_MAX, - sync_buff[beacon0_id].imag() / SHRT_MAX); - beacon1.at(i) = - std::complex(sync_buff[beacon1_id].real() / SHRT_MAX, - sync_buff[beacon1_id].imag() / SHRT_MAX); + size_t beacon0_id = i + beacon_start; + size_t beacon1_id = i + beacon_start + beacon_half_size; + beacon0[i] = + std::complex(sync_buff[beacon0_id].real() / SHRT_MAX_FLOAT, + sync_buff[beacon0_id].imag() / SHRT_MAX_FLOAT); + beacon1[i] = + std::complex(sync_buff[beacon1_id].real() / SHRT_MAX_FLOAT, + sync_buff[beacon1_id].imag() / SHRT_MAX_FLOAT); } - const auto cfo_mult = CommsLib::complex_mult_avx(beacon1, beacon0, true); - float phase = 0.0f; - float prev_phase = 0.0f; + auto cfo_mult = CommsLib::complex_mult_avx(beacon1, beacon0, true); + float phase = 0, prev_phase = 0; for (size_t i = 0; i < cfo_mult.size(); i++) { phase = std::arg(cfo_mult.at(i)); float unwrapped_phase = 0; @@ -886,7 +887,7 @@ float Receiver::estimateCFO(const std::vector>& sync_buff, void Receiver::clientSyncTxRx(int tid, int core_id, SampleBuffer* rx_buffer) { if (config_->core_alloc() == true) { - const int core = tid + core_id; + int core = tid + core_id; MLPD_INFO("Pinning client synctxrx thread %d to core %d\n", tid, core); if (pin_to_core(core) != 0) { @@ -900,18 +901,25 @@ void Receiver::clientSyncTxRx(int tid, int core_id, SampleBuffer* rx_buffer) { this->txFrameDelta_, this->txFrameDelta_ * (1e3 * config_->getFrameDurationSec())); - const size_t samples_per_slot = config_->samps_per_slot(); - const size_t num_rx_buffs = config_->cl_sdr_ch(); - std::vector>> samplemem( - num_rx_buffs, std::vector>( - samples_per_slot, std::complex(0, 0))); + int SYNC_NUM_SAMPS = config_->samps_per_frame(); + std::vector> syncbuff0(SYNC_NUM_SAMPS, 0); + std::vector> syncbuff1(SYNC_NUM_SAMPS, 0); + std::vector syncrxbuff(2); + syncrxbuff.at(0) = syncbuff0.data(); + if (config_->cl_sdr_ch() == 2) { + syncrxbuff.at(1) = syncbuff1.data(); + } - std::vector rxbuff; - for (size_t ch = 0; ch < num_rx_buffs; ch++) { - rxbuff.push_back(samplemem.at(ch).data()); + int NUM_SAMPS = config_->samps_per_slot(); + std::vector> buff0(SYNC_NUM_SAMPS, 0); + std::vector> buff1(SYNC_NUM_SAMPS, 0); + std::vector rxbuff(2); + rxbuff.at(0) = buff0.data(); + if (config_->cl_sdr_ch() == 2) { + rxbuff.at(1) = buff1.data(); } - const size_t ant_id = tid * config_->cl_sdr_ch(); + size_t ant_id = tid * config_->cl_sdr_ch(); // use token to speed up moodycamel::ProducerToken local_ptok(*message_queue_); @@ -920,6 +928,7 @@ void Receiver::clientSyncTxRx(int tid, int core_id, SampleBuffer* rx_buffer) { int buffer_chunk_size = 0; int buffer_id = tid + config_->bs_rx_thread_num(); size_t packetLength = sizeof(Packet) + config_->getPacketDataLength(); + //if (config_->dl_slot_per_frame() > 0) { if (config_->cl_dl_slots().at(0).empty() == false) { buffer_chunk_size = rx_buffer[buffer_id].buffer.size() / packetLength; // handle two channels at each radio @@ -934,61 +943,66 @@ void Receiver::clientSyncTxRx(int tid, int core_id, SampleBuffer* rx_buffer) { tx_buffer_size = cl_tx_buffer_[tid].buffer.size() / packetLength; } + long long rxTime(0); + int sync_index(-1); + int rx_offset = 0; + float cfo_phase_est = 0; + // For USRP clients skip UHD_INIT_TIME_SEC to avoid late packets if (kUsePureUHD == true || kUseSoapyUHD == true) { - auto start_time = std::chrono::steady_clock::now(); - std::chrono::duration elapsed_seconds{0.0}; - - while (elapsed_seconds.count() < UHD_INIT_TIME_SEC) { - long long ignore_time; - client_radio_set_->radioRx(tid, rxbuff.data(), samples_per_slot, - ignore_time); - elapsed_seconds = std::chrono::duration_cast( - std::chrono::steady_clock::now() - start_time); + int cl_sync_ret = -1; + sleep(UHD_INIT_TIME_SEC); + while (cl_sync_ret < 0) { + cl_sync_ret = client_radio_set_->radioRx(tid, syncrxbuff.data(), + SYNC_NUM_SAMPS, rxTime); } - std::printf("Wait duration %3.2f seconds \n", elapsed_seconds.count()); } - //-------------------- New sync - const size_t beacon_detect_window = - static_cast(static_cast(config_->samps_per_slot()) * - kBeaconDetectWindowScaler); - size_t sync_count = 0; - constexpr size_t kTargetSyncCount = 2; - assert(config_->samps_per_frame() >= beacon_detect_window); - while ((sync_count < kTargetSyncCount) && config_->running()) { - const ssize_t sync_index = clientSyncBeacon(tid, beacon_detect_window); - if (sync_index >= 0) { - const ssize_t adjust = - sync_index - (config_->beacon_size() + config_->prefix()); - const size_t alignment_samples = - config_->samps_per_frame() - beacon_detect_window; - MLPD_INFO( - "clientSyncTxRx [%zu]: Beacon detected sync_index: %ld, rx sample " - "offset: %ld, window %zu, samples in frame %zu, alignment removal " - "%zu\n", - tid, sync_index, adjust, beacon_detect_window, - config_->samps_per_frame(), alignment_samples); - - //By definition alignment_samples + adjust must be > 0; - if (static_cast(alignment_samples) + adjust < 0) { - throw std::runtime_error("Unexpected alignment"); + // Keep reading one frame worth of data until a beacon is found + // Perform initial beacon detection once every BEACON_INTERVAL frames + while ((config_->running() == true) && (sync_index < 0)) { + for (int find_beacon_retry = 0; find_beacon_retry < BEACON_INTERVAL; + find_beacon_retry++) { + int r; + r = client_radio_set_->radioRx(tid, syncrxbuff.data(), SYNC_NUM_SAMPS, + rxTime); + if (r != SYNC_NUM_SAMPS) { + MLPD_WARN("BAD SYNC Receive( %d / %d ) at Time %lld\n", r, + SYNC_NUM_SAMPS, rxTime); + } + } + sync_index = this->syncSearch(syncbuff0, SYNC_NUM_SAMPS); + } + if (sync_index >= 0) { + MLPD_INFO("Beacon detected at Time %lld, sync_index: %d\n", rxTime, + sync_index); + rx_offset = sync_index - config_->beacon_size() - config_->prefix(); + cfo_phase_est = estimateCFO(syncbuff0, sync_index); + std::cout << "Client " << tid + << " Estimated CFO (Hz): " << cfo_phase_est * config_->rate() + << std::endl; + } + + // Read rx_offset to align with the begining of a frame + assert((rx_offset >= 0) && (rx_offset <= SYNC_NUM_SAMPS)); + if (config_->running() == true) { + MLPD_INFO("Start main client txrx loop... tid=%d\n", tid); + if (rx_offset > 0) { + int rx_data; + rx_data = + client_radio_set_->radioRx(tid, syncrxbuff.data(), rx_offset, rxTime); + if (rx_data != rx_offset) { + MLPD_WARN("Rx data: %d : %d failed to align sync read\n", rx_data, + rx_offset); } - clientAdjustRx(tid, alignment_samples + adjust); - sync_count++; - } else if (config_->running()) { - MLPD_WARN( - "clientSyncTxRx [%d]: Beacon could not be detected sync_index: %ld\n", - tid, sync_index); - throw std::runtime_error("rx sample offset is less than 0"); } } // Main client read/write loop. size_t frame_id = 0; + size_t slot_id = 0; size_t buffer_offset = 0; - //sync on the first beacon after initial detection - bool resync = true; + bool resync = false; bool resync_enable = (config_->frame_mode() == "continuous_resync"); size_t resync_retry_cnt(0); size_t resync_retry_max(100); @@ -998,110 +1012,81 @@ void Receiver::clientSyncTxRx(int tid, int core_id, SampleBuffer* rx_buffer) { size_t resync_period = static_cast( std::floor(1e9 / (max_cfo * config_->samps_per_frame()))); size_t last_resync = frame_id; - MLPD_INFO("Start main client txrx loop... tid=%d with resync period of %zu\n", - tid, resync_period); - long long rx_beacon_time(0); - //Always decreases the requested rx samples - size_t beacon_adjust = 0; + std::printf("Using resync period of %zu\n", resync_period); + int r = 0; + rx_offset = 0; while (config_->running() == true) { if (config_->max_frame() > 0 && frame_id >= config_->max_frame()) { config_->running(false); break; } - //Slot 0 / Beacon... - const int request_samples = samples_per_slot - beacon_adjust; - const int rx_status = client_radio_set_->radioRx( - tid, rxbuff.data(), request_samples, rx_beacon_time); - if (rx_status < 0) { - MLPD_ERROR("Rx status reporting error %d, exiting\n", rx_status); + r = client_radio_set_->radioRx(tid, syncrxbuff.data(), + NUM_SAMPS + rx_offset, rxTime); + + if (r < 0) { config_->running(false); break; } if (config_->ul_data_slot_present() == true) { - // Notify new frame this->notifyPacket(kClient, frame_id + this->txFrameDelta_, 0, tid, - tx_buffer_size); + tx_buffer_size); // Notify new frame } - if ((frame_id - last_resync) >= resync_period) { + if (frame_id - last_resync >= resync_period) { resync = resync_enable; last_resync = frame_id; MLPD_TRACE("Enable resyncing at frame %zu\n", frame_id); } + rx_offset = 0; if (resync == true) { //Need to bound the beacon detection to the last 'r not the size of the memory (vector) //TODO: Use SIMD for faster conversion // convert data to complex float for sync detection - ssize_t sync_index = - this->syncSearch(reinterpret_cast*>( - rxbuff.at(kSyncDetectChannel)), - request_samples); + sync_index = this->syncSearch(syncbuff0, NUM_SAMPS); if (sync_index >= 0) { - const int new_rx_offset = - sync_index - (config_->beacon_size() + config_->prefix()); - //Adjust tx time - rx_beacon_time += new_rx_offset; + rx_offset = sync_index - config_->beacon_size() - config_->prefix(); + rxTime += rx_offset; resync = false; resync_retry_cnt = 0; resync_success++; MLPD_INFO( - "Re-syncing success with offset: %d, after %zu tries, index: %d, " - "tid %d\n", - new_rx_offset, resync_retry_cnt + 1, sync_index, tid); - - if (sync_index >= 0) { - const auto cfo_phase_est = - estimateCFO(samplemem.at(kSyncDetectChannel), sync_index); - std::cout << "Client " << tid << " Estimated CFO (Hz): " - << cfo_phase_est * config_->rate() << std::endl; - } - - //Offset Alignment logic - //If new_rx_offset is positive -- we need to right shift (read less) - if (new_rx_offset >= 0) { - beacon_adjust = new_rx_offset; - } else { - const size_t discard_samples = (-1 * new_rx_offset); - //throw away samples to get back in alignment, could combine with the next beacon but would need bigger buffers - clientAdjustRx(tid, discard_samples); - } + "Re-syncing with offset: %d, after %zu " + "tries, index: %d, tid %d\n", + rx_offset, resync_retry_cnt + 1, sync_index, tid); } else { resync_retry_cnt++; - - if (resync_retry_cnt > resync_retry_max) { - MLPD_WARN( - "Exceeded resync retry limit (%zu) for client %d reached after " - "%zu resync successes at frame: %zu. Stopping!\n", - resync_retry_max, tid, resync_success, frame_id); - resync = false; - resync_retry_cnt = 0; - config_->running(false); - break; - } } } + if ((resync == true) && (resync_retry_cnt > resync_retry_max)) { + MLPD_WARN( + "Exceeded resync retry limit (%zu) for client " + "%d reached after %zu resync successes at " + "frame: %zu. Stopping!\n", + resync_retry_max, tid, resync_success, frame_id); + resync = false; + resync_retry_cnt = 0; + config_->running(false); + break; + } // schedule all TX slot // config_->tx_advance() needs calibration based on SDR model and sampling rate if (config_->ul_data_slot_present() == true) { - int tx_return = 0; - while (tx_return >= 0) { - tx_return = this->clientTxData(tid, frame_id, rx_beacon_time); - } + while (-1 != this->clientTxData(tid, frame_id, rxTime)) + ; } else { - this->clientTxPilots(tid, rx_beacon_time + txTimeDelta_); + this->clientTxPilots(tid, rxTime + txTimeDelta_); } // end if config_->ul_data_slot_present() - //Beacon + Tx Complete, process the rest of the slots - for (size_t slot_id = 1; slot_id < config_->slot_per_frame(); slot_id++) { - int rx_data_status; - long long rx_data_time; + slot_id++; + + for (; slot_id < config_->slot_per_frame(); slot_id++) { if (config_->isDlData(tid, slot_id)) { // Set buffer status(es) to full; fail if full already for (size_t ch = 0; ch < config_->cl_sdr_ch(); ++ch) { - const int bit = 1 << (buffer_offset + ch) % sizeof(std::atomic_int); - const int offs = (buffer_offset + ch) / sizeof(std::atomic_int); - const int old = + int bit = 1 << (buffer_offset + ch) % sizeof(std::atomic_int); + int offs = (buffer_offset + ch) / sizeof(std::atomic_int); + int old = std::atomic_fetch_or(&pkt_buf_inuse[offs], bit); // now full // if buffer was full, exit if ((old & bit) != 0) { @@ -1112,18 +1097,21 @@ void Receiver::clientSyncTxRx(int tid, int core_id, SampleBuffer* rx_buffer) { } // Receive data into buffers - std::vector pkts(config_->cl_sdr_ch()); - std::vector dl_slot_samp(config_->cl_sdr_ch()); + Packet* pkt[config_->cl_sdr_ch()]; + void* samp[config_->cl_sdr_ch()]; for (size_t ch = 0; ch < config_->cl_sdr_ch(); ++ch) { - pkts.at(ch) = reinterpret_cast( - buffer + (buffer_offset + ch) * packetLength); - dl_slot_samp.at(ch) = pkts.at(ch)->data; + pkt[ch] = (Packet*)(buffer + (buffer_offset + ch) * packetLength); + samp[ch] = pkt[ch]->data; + } + + if ((r = this->client_radio_set_->radioRx(tid, samp, NUM_SAMPS, + rxTime)) < 0) { + config_->running(false); + break; } - rx_data_status = this->client_radio_set_->radioRx( - tid, dl_slot_samp.data(), samples_per_slot, rx_data_time); for (size_t ch = 0; ch < config_->cl_sdr_ch(); ++ch) { - new (pkts.at(ch)) Packet(frame_id, slot_id, 0, ant_id + ch); + new (pkt[ch]) Packet(frame_id, slot_id, 0, ant_id + ch); // push kEventRxSymbol event into the queue this->notifyPacket(kClient, frame_id, slot_id, ant_id + ch, buffer_chunk_size, @@ -1132,102 +1120,19 @@ void Receiver::clientSyncTxRx(int tid, int core_id, SampleBuffer* rx_buffer) { buffer_offset %= buffer_chunk_size; } } else { - //Not dl data so we throw it away - rx_data_status = this->client_radio_set_->radioRx( - tid, rxbuff.data(), samples_per_slot, rx_data_time); + r = this->client_radio_set_->radioRx(tid, rxbuff.data(), NUM_SAMPS, + rxTime); + if (r < 0) { + config_->running(false); + break; + } } - if (rx_data_status < 0) { - MLPD_ERROR( - "Rx status reporting error %d during frame %zu , slot %zu, " - "exiting\n", - rx_data_status, frame_id, slot_id); - config_->running(false); - break; - } else if (rx_data_status != static_cast(samples_per_slot)) { - MLPD_WARN("BAD Receive(%d/%zu) at Time %lld, frame count %zu\n", - rx_data_status, samples_per_slot, rx_data_time, frame_id); + if (r != NUM_SAMPS) { + MLPD_WARN("BAD Receive(%d/%d) at Time %lld, frame count %zu\n", r, + NUM_SAMPS, rxTime, frame_id); } } // end for frame_id++; + slot_id = 0; } // end while } - -//Blocking function for beacon detected or exit() -ssize_t Receiver::clientSyncBeacon(size_t radio_id, size_t sample_window) { - ssize_t sync_index = -1; - long long rx_time = 0; - assert(sample_window <= config_->samps_per_frame()); - const size_t num_rx_buffs = config_->cl_sdr_ch(); - std::vector>> syncbuffmem( - num_rx_buffs, std::vector>( - sample_window, std::complex(0, 0))); - - std::vector syncrxbuffs; - for (size_t ch = 0; ch < num_rx_buffs; ch++) { - syncrxbuffs.push_back(syncbuffmem.at(ch).data()); - } - - while (config_->running() && (sync_index < 0)) { - const int rx_status = client_radio_set_->radioRx( - radio_id, syncrxbuffs.data(), sample_window, rx_time); - - if (rx_status < 0) { - MLPD_ERROR("clientSyncBeacon [%zu]: BAD SYNC Received (%d/%zu) %lld\n", - radio_id, rx_status, sample_window, rx_time); - } else { - const size_t new_samples = static_cast(rx_status); - if (new_samples == sample_window) { - MLPD_TRACE( - "clientSyncBeacon - Samples %zu - Window %zu - Check Beacon %ld\n", - new_samples, sample_window); - - sync_index = syncSearch(syncbuffmem.at(kSyncDetectChannel).data(), - sample_window); - } else { - MLPD_ERROR( - "clientSyncBeacon [%zu]: BAD SYNC - Rx samples not requested size " - "(%zu/%zu) %lld\n", - radio_id, new_samples, sample_window, rx_time); - } - } - } // end while sync_index < 0 - return sync_index; -} - -/// This function blocks untill all the discard_samples are received for a given radio -void Receiver::clientAdjustRx(size_t radio_id, size_t discard_samples) { - const size_t num_rx_buffs = config_->cl_sdr_ch(); - long long rx_time = 0; - - //This can be fixed and combined with other scratch memory - std::vector>> temp_mem( - num_rx_buffs, std::vector>(discard_samples)); - - std::vector trash_memory; - for (size_t ch = 0; ch < num_rx_buffs; ch++) { - trash_memory.push_back(temp_mem.at(ch).data()); - } - - while (config_->running() && (discard_samples > 0)) { - const int rx_status = client_radio_set_->radioRx( - radio_id, trash_memory.data(), discard_samples, rx_time); - - if (rx_status < 0) { - MLPD_ERROR( - "clientAdjustRx [%zu]: BAD Rx Adjust Status Received (%d/%zu) %lld\n", - radio_id, rx_status, discard_samples, rx_time); - } else { - size_t new_samples = static_cast(rx_status); - if (new_samples <= discard_samples) { - discard_samples -= new_samples; - MLPD_INFO("clientAdjustRx [%zu]: Discarded Samples (%zu/%zu)\n", - radio_id, new_samples, discard_samples); - } else { - MLPD_ERROR( - "clientAdjustRx [%zu]: BAD radioRx more samples then requested " - "(%zu/%zu) %lld\n", - radio_id, new_samples, discard_samples, rx_time); - } - } - } // request_samples > 0 -} From 08dc9b87480824b67680bb3acbce25c3beb49d87 Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Thu, 7 Jul 2022 15:21:27 -0400 Subject: [PATCH 32/45] Update comms-lib-avx.cc changed to Original From 51d589971f24b13f6af0d322b362287d25d30545 Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Thu, 7 Jul 2022 15:22:21 -0400 Subject: [PATCH 33/45] Update comms-lib.cc changed to original From ebefdd6d183ac6246b0b06074e9240d9e0f43c7d Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Thu, 7 Jul 2022 15:23:55 -0400 Subject: [PATCH 34/45] Update comms-lib.h changed to orginal --- CC/Sounder/include/comms-lib.h | 530 +++++++++------------------------ 1 file changed, 137 insertions(+), 393 deletions(-) diff --git a/CC/Sounder/include/comms-lib.h b/CC/Sounder/include/comms-lib.h index 90e6f05d..4741c275 100644 --- a/CC/Sounder/include/comms-lib.h +++ b/CC/Sounder/include/comms-lib.h @@ -1,411 +1,155 @@ /* - Copyright (c) 2018-2021, Rice University + + Communications Library: + a) Generate pilot/preamble sequences + b) OFDM modulation + +--------------------------------------------------------------------- + Copyright (c) 2018-2019, Rice University RENEW OPEN SOURCE LICENSE: http://renew-wireless.org/license Author(s): Rahman Doost-Mohamamdy: doost@rice.edu - ---------------------------------------------------------------------- - Reads Configuration Parameters from file + Oscar Bejarano: obejarano@rice.edu --------------------------------------------------------------------- */ -#ifndef CONFIG_HEADER -#define CONFIG_HEADER - #include +#include +#include /* for fprintf */ +#include +#include /* for memcpy */ +#include #include -#include +#include +#include // std::ifstream +#include +#include #include -class Config { - public: - Config(const std::string&, const std::string&, const bool, const bool); - ~Config(); +#include "fft.h" - //Accessors - inline bool bs_present(void) const { return this->bs_present_; } - inline bool client_present(void) const { return this->client_present_; } - inline size_t num_bs_sdrs_all(void) const { return this->num_bs_sdrs_all_; } - inline size_t num_bs_antennas_all(void) const { - return this->num_bs_antennas_all_; - } - inline size_t num_cl_sdrs(void) const { return this->num_cl_sdrs_; } - inline size_t core_alloc(void) const { return this->core_alloc_; } - inline int slot_samp_size(void) const { return this->slot_samp_size_; } - inline size_t samps_per_slot(void) const { return this->samps_per_slot_; } - inline size_t slot_per_frame(void) const { return this->slot_per_frame_; } - inline size_t symbol_per_slot(void) const { return this->symbol_per_slot_; } - inline size_t samps_per_frame(void) const { - return this->samps_per_slot_ * this->slot_per_frame_; - } - inline bool ul_data_slot_present(void) const { - return this->ul_data_slot_present_; - } - inline bool dl_data_slot_present(void) const { - return this->dl_data_slot_present_; - } - inline size_t num_cells(void) const { return this->num_cells_; } - inline size_t guard_mult(void) const { return this->guard_mult_; } - inline bool bs_hw_framer(void) const { return this->bs_hw_framer_; } - inline bool hw_framer(void) const { return this->hw_framer_; } - inline int prefix(void) const { return this->prefix_; } - inline int postfix(void) const { return this->postfix_; } - inline int beacon_size(void) const { return this->beacon_size_; } - inline double bw_filter(void) const { return this->bw_filter_; } - inline double freq(void) const { return this->freq_; } - inline double nco(void) const { return this->nco_; } - inline double radio_rf_freq(void) const { return this->radio_rf_freq_; } - inline bool single_gain(void) const { return this->single_gain_; } - inline bool cl_agc_en(void) const { return this->cl_agc_en_; } - inline int cl_agc_gain_init(void) const { return this->cl_agc_gain_init_; } - inline bool imbalance_cal_en(void) const { return this->imbalance_cal_en_; } - inline bool sample_cal_en(void) const { return this->sample_cal_en_; } - inline size_t max_frame(void) const { return this->max_frame_; } - inline size_t ul_data_frame_num(void) const { - return this->ul_data_frame_num_; - } - inline size_t dl_data_frame_num(void) const { - return this->dl_data_frame_num_; - } - inline bool beam_sweep(void) const { return this->beam_sweep_; } - inline size_t beacon_channel(void) const { return this->beacon_ch_; } - inline size_t beacon_ant(void) const { return this->beacon_ant_; } - inline size_t beacon_radio(void) const { return this->beacon_radio_; } - inline size_t num_cl_antennas(void) const { return this->num_cl_antennas_; } - inline size_t fft_size(void) const { return this->fft_size_; } - inline size_t cp_size(void) const { return this->cp_size_; } - inline size_t symbol_data_subcarrier_num(void) const { - return this->symbol_data_subcarrier_num_; - } - inline size_t pilot_slot_per_frame(void) const { - return this->pilot_slot_per_frame_; - } - inline size_t noise_slot_per_frame(void) const { - return this->noise_slot_per_frame_; - } - inline size_t ul_slot_per_frame(void) const { - return this->ul_slot_per_frame_; - } - inline size_t dl_slot_per_frame(void) const { - return this->dl_slot_per_frame_; - } - inline const std::vector>& dl_slots(void) const { - return this->dl_slots_; - } - inline double rate(void) const { return this->rate_; } - inline int tx_advance(size_t id) const { return this->tx_advance_.at(id); } - inline size_t cl_sdr_ch(void) const { return this->cl_sdr_ch_; } - inline size_t bs_sdr_ch(void) const { return this->bs_sdr_ch_; } +static constexpr size_t kPilotSubcarrierSpacing = 12; +static constexpr size_t kDefaultPilotScOffset = 6; - inline bool running(void) const { return this->running_.load(); } - inline void running(bool value) { this->running_ = value; } +static inline double computeAbs(std::complex x) { return std::abs(x); } - inline const std::string& frame_mode(void) const { return this->frame_mode_; } - inline const std::string& bs_channel(void) const { return this->bs_channel_; } - inline const std::string& trace_file(void) const { return this->trace_file_; } - inline const std::string& cl_channel(void) const { return this->cl_channel_; } - inline const std::string& beacon_seq(void) const { return this->beacon_seq_; } - inline const std::string& pilot_seq(void) const { return this->pilot_seq_; } - inline const std::string& data_mod(void) const { return this->data_mod_; } - inline const std::string& cl_data_mod(void) const { - return this->cl_data_mod_; - } - - inline const std::vector& n_bs_sdrs_agg(void) const { - return this->n_bs_sdrs_agg_; - } - inline bool internal_measurement(void) const { - return this->internal_measurement_; - } - inline bool ref_node_enable(void) const { return this->ref_node_enable_; } - inline size_t cal_ref_sdr_id(void) const { return this->cal_ref_sdr_id_; } - inline const std::vector>& calib_frames(void) const { - return this->calib_frames_; - } - - //TODO split the following (4) in accessor and setter - inline std::vector>& beacon_ci16(void) { - return this->beacon_ci16_; - } - inline std::vector>& neg_beacon_ci16(void) { - return this->neg_beacon_ci16_; - } - inline std::vector>>& tx_data(void) { - return this->tx_data_; - }; - inline std::vector>& pilot_ci16(void) { - return this->pilot_ci16_; - } - inline std::vector& n_bs_sdrs(void) { return this->n_bs_sdrs_; } - - inline const std::vector& cl_frames(void) const { - return this->cl_frames_; - } - inline const std::vector>& cl_pilot_slots(void) const { - return this->cl_pilot_slots_; - } - inline const std::vector>& cl_ul_slots(void) const { - return this->cl_ul_slots_; - } - inline const std::vector>& cl_dl_slots(void) const { - return this->cl_dl_slots_; - } - inline const std::vector& cl_sdr_ids(void) const { - return this->cl_sdr_ids_; - } - inline const std::vector& ul_tx_fd_data_files(void) const { - return this->ul_tx_fd_data_files_; - } - inline const std::vector& ul_tx_td_data_files(void) const { - return this->ul_tx_td_data_files_; - } - inline const std::vector& dl_tx_fd_data_files(void) const { - return this->dl_tx_fd_data_files_; - } - inline const std::vector& dl_tx_td_data_files(void) const { - return this->dl_tx_td_data_files_; - } - - inline const std::vector& data_ind(void) const { - return this->data_ind_; - } - inline const std::vector& coeffs(void) const { - return this->coeffs_; - } - inline const std::vector& pilot(void) const { return this->pilot_; } - inline const std::vector>& cl_txgain_vec(void) const { - return this->cl_txgain_vec_; - } - inline const std::vector>& cl_rxgain_vec(void) const { - return this->cl_rxgain_vec_; - } - inline const std::vector& beacon(void) const { - return this->beacon_; - } +//template +//static inline T computeAbs(std::complex x) { return std::abs(x); } +static inline double computePower(std::complex x) { + return std::pow(std::abs(x), 2); +} +static inline double computeSquare(double x) { return x * x; } - inline std::vector>& pilot_sym_t(void) { - return this->pilot_sym_t_; - }; - inline std::vector>& pilot_sym_f(void) { - return this->pilot_sym_f_; - }; - inline std::vector>& pilot_sc(void) { - return this->pilot_sc_; - }; - inline std::vector& pilot_sc_ind(void) { - return this->pilot_sc_ind_; +class CommsLib { + public: + enum SequenceType { + STS_SEQ, + LTS_SEQ, + LTS_SEQ_F, + LTE_ZADOFF_CHU, + LTE_ZADOFF_CHU_F, + GOLD_IFFT, + HADAMARD }; - inline const std::vector& frames(void) const { - return this->frames_; - } - - inline const std::vector>& bs_sdr_ids(void) const { - return this->bs_sdr_ids_; - } - inline const std::vector>& gold_cf32(void) const { - return this->gold_cf32_; - } - - inline size_t cl_rx_thread_num(void) const { return this->cl_rx_thread_num_; } - inline size_t bs_rx_thread_num(void) const { return this->bs_rx_thread_num_; } - inline size_t recorder_thread_num(void) const { - return this->recorder_thread_num_; - } - inline size_t reader_thread_num(void) const { - return this->reader_thread_num_; - } - - inline const std::vector& hub_ids(void) const { - return this->hub_ids_; - } - - inline const std::vector& calib_ids(void) const { - return this->calib_ids_; - } - - inline const std::vector& tx_gain(void) const { - return this->tx_gain_; - } - inline const std::vector& rx_gain(void) const { - return this->rx_gain_; - } - inline const std::vector& cal_tx_gain(void) const { - return this->cal_tx_gain_; - } - - inline const std::vector>>& txdata_freq_dom( - void) const { - return this->txdata_freq_dom_; - } - - inline const std::vector>>& - dl_txdata_freq_dom(void) const { - return this->dl_txdata_freq_dom_; - } - - inline double tx_scale(void) const { return this->tx_scale_; } - inline double pilot_scale(void) const { return this->pilot_scale_; } - inline size_t getPacketDataLength() const { - return (2 * this->samps_per_slot_ * sizeof(short)); - } - - /// Return the slot duration in seconds - inline double getSlotDurationSec() const { - return ((this->symbol_per_slot_ * this->samps_per_slot_) / this->rate_); - } - /// Return the frame duration in seconds - inline double getFrameDurationSec() const { - return ((this->samps_per_frame()) / this->rate_); - } - inline size_t getTxFrameDelta() const { return tx_frame_delta_; } - - size_t getNumAntennas(); - size_t getMaxNumAntennas(); - size_t getNumBsSdrs(); - size_t getTotNumAntennas(); - size_t getNumRecordedSdrs(); - int getClientId(int, int); - int getNoiseSlotIndex(int, int); - int getUlSlotIndex(int, int); - int getDlSlotIndex(int, int); - bool isPilot(int, int); - bool isNoise(int, int); - bool isUlData(int, int); - bool isDlData(int, int); - unsigned getCoreCount(); - - void loadULData(); - void loadDLData(); - - private: - bool bs_present_; - bool client_present_; - std::string directory_; - - // common features - double freq_; - double nco_; // baseband frequency controlled by NCO - double rate_; - double - radio_rf_freq_; // RF frequency set frame_modeon the radio after NCO adjustments - double bw_filter_; - size_t fft_size_; - size_t cp_size_; - size_t ofdm_symbol_size_; - size_t symbol_data_subcarrier_num_; - size_t symbol_per_slot_; - size_t slot_samp_size_; - size_t samps_per_slot_; - size_t prefix_; - size_t postfix_; - size_t slot_per_frame_; - size_t pilot_slot_per_frame_; - size_t noise_slot_per_frame_; - size_t ul_slot_per_frame_; - size_t dl_slot_per_frame_; - float tx_scale_; - float pilot_scale_; - std::string pilot_seq_; - std::string beacon_seq_; - bool ul_data_slot_present_; - bool dl_data_slot_present_; - std::string data_mod_; - std::string cl_data_mod_; - - // BS features - size_t num_cells_; - size_t guard_mult_; - std::vector bs_sdr_file_; // No accessor - std::string hub_file_; // No accessor - std::string ref_sdr; - size_t bs_sdr_ch_; - std::vector> bs_sdr_ids_; - std::vector hub_ids_; - std::vector calib_ids_; - std::vector> gold_cf32_; - std::vector beacon_; - std::vector> beacon_ci16_; - std::vector> neg_beacon_ci16_; - int beacon_size_; - size_t beacon_ant_; - size_t beacon_radio_; - size_t beacon_ch_; - bool beam_sweep_; - std::vector n_bs_sdrs_; - std::vector n_bs_antennas_; //No accessor - std::vector n_bs_sdrs_agg_; - size_t num_bs_sdrs_all_; - size_t num_bs_antennas_all_; - std::string bs_channel_; - std::vector frames_; - std::string frame_mode_; - bool bs_hw_framer_; - bool hw_framer_; - size_t max_frame_; - size_t ul_data_frame_num_; - size_t dl_data_frame_num_; - std::vector> - pilot_slots_; // Accessed through getClientId - std::vector> noise_slots_; - std::vector> - ul_slots_; // Accessed through getUlSFIndex() - std::vector> dl_slots_; - bool single_gain_; - std::vector tx_gain_; - std::vector rx_gain_; - std::vector cal_tx_gain_; - bool sample_cal_en_; - bool imbalance_cal_en_; - std::string trace_file_; - std::vector> calib_frames_; - bool internal_measurement_; - bool ref_node_enable_; - size_t cal_ref_sdr_id_; - size_t tx_frame_delta_; - - // Clients features - std::vector cl_sdr_ids_; - size_t max_tx_gain_ue_; - size_t num_cl_sdrs_; - size_t cl_sdr_ch_; - size_t num_cl_antennas_; - std::string cl_channel_; - bool cl_agc_en_; - int cl_agc_gain_init_; - std::vector tx_advance_; - std::vector data_ind_; - std::vector coeffs_; - std::vector> pilot_ci16_; - std::vector pilot_; - std::vector> pilot_sc_; - std::vector pilot_sc_ind_; - std::vector> pilot_sym_t_; - std::vector> pilot_sym_f_; - std::vector>> tx_data_; - std::vector>> txdata_freq_dom_; - std::vector>> txdata_time_dom_; - std::vector>> dl_txdata_freq_dom_; - std::vector>> dl_txdata_time_dom_; - - std::vector cl_frames_; - std::vector> cl_pilot_slots_; - std::vector> cl_ul_slots_; - std::vector> cl_dl_slots_; - - std::vector> cl_txgain_vec_; - std::vector> cl_rxgain_vec_; - std::vector ul_tx_td_data_files_; - std::vector ul_tx_fd_data_files_; - std::vector dl_tx_td_data_files_; - std::vector dl_tx_fd_data_files_; - - std::atomic running_; - bool core_alloc_; - size_t bs_rx_thread_num_; - size_t cl_rx_thread_num_; - size_t recorder_thread_num_; - size_t reader_thread_num_; + enum ModulationOrder { QPSK = 2, QAM16 = 4, QAM64 = 6 }; + + CommsLib(std::string); + ~CommsLib(); + + static std::vector> getSequence(size_t type, + size_t seq_len = 0); + static std::vector> modulate(std::vector, int); + static std::vector getDataSc( + size_t fftSize, size_t DataScNum, + size_t PilotScOffset = kDefaultPilotScOffset); + static std::vector getNullSc(size_t fftSize, size_t DataScNum); + static std::vector> getPilotScValue( + size_t fftSize, size_t DataScNum, + size_t PilotScOffset = kDefaultPilotScOffset); + static std::vector getPilotScIndex( + size_t fftSize, size_t DataScNum, + size_t PilotScOffset = kDefaultPilotScOffset); + static std::vector> FFT( + const std::vector>&, int); + static std::vector> IFFT( + const std::vector>&, int, float scale = 0.5, + bool normalize = true); + + static int findLTS(const std::vector>& iq, int seqLen); + static size_t find_pilot_seq(const std::vector>& iq, + const std::vector>& pilot, + size_t seqLen); + template + //static std::vector convolve(std::vector const& f, std::vector const& g); + static std::vector convolve(std::vector const& f, + std::vector const& g) { + /* Convolution of two vectors + * Source: + * https://stackoverflow.com/questions/24518989/how-to-perform-1-dimensional-valid-convolution + */ + int const nf = f.size(); + int const ng = g.size(); + int const n = nf + ng - 1; + std::vector out(n, 0); + for (auto i(0); i < n; ++i) { + int const jmn = (i >= ng - 1) ? i - (ng - 1) : 0; + int const jmx = (i < nf - 1) ? i : nf - 1; + for (auto j(jmn); j <= jmx; ++j) { + out[i] += f[j] * g[i - j]; + } + } + return out; + } + static float find_max_abs(const std::vector>& in); + static std::vector> csign( + const std::vector>& iq); + static inline int hadamard2(int i, int j) { + return (__builtin_parity(i & j) != 0 ? -1 : 1); + } + static std::vector magnitudeFFT( + std::vector> const&, std::vector const&, + size_t); + static std::vector hannWindowFunction(size_t); + static double windowFunctionPower(std::vector const&); + template + static T findTone(std::vector const&, double, double, size_t, + const size_t delta = 10); + static float measureTone(std::vector> const&, + std::vector const&, double, double, size_t, + const size_t delta = 10); + + // Functions using AVX + static int find_beacon(const std::vector>& iq); + static int find_beacon_avx(const std::vector>& iq, + const std::vector>& seq); + static std::vector correlate_avx_s(std::vector const& f, + std::vector const& g); + static std::vector correlate_avx_si(std::vector const& f, + std::vector const& g); + static std::vector abs2_avx(std::vector> const& f); + static std::vector abs2_avx( + std::vector> const& f); + static std::vector> auto_corr_mult_avx( + std::vector> const& f, const int dly, + const bool conj = true); + static std::vector> auto_corr_mult_avx( + std::vector> const& f, const int dly, + const bool conj = true); + static std::vector> correlate_avx( + std::vector> const& f, + std::vector> const& g); + static std::vector> correlate_avx( + std::vector> const& f, + std::vector> const& g); + static std::vector> complex_mult_avx( + std::vector> const& f, + std::vector> const& g, const bool conj); + static std::vector> complex_mult_avx( + std::vector> const& f, + std::vector> const& g, const bool conj); + //private: + // static inline float** init_qpsk(); + // static inline float** init_qam16(); + // static inline float** init_qam64(); }; - -#endif /* CONFIG_HEADER */ From 389beabbb86be3dcd2ecdcf785cf0bad88726bac Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Fri, 8 Jul 2022 11:12:17 -0400 Subject: [PATCH 35/45] Update usrp-16QAM.json Updated to ORBIT grid configuration --- CC/Sounder/files/special_conf/usrp-16QAM.json | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/CC/Sounder/files/special_conf/usrp-16QAM.json b/CC/Sounder/files/special_conf/usrp-16QAM.json index d69e7ed6..bab41cf2 100644 --- a/CC/Sounder/files/special_conf/usrp-16QAM.json +++ b/CC/Sounder/files/special_conf/usrp-16QAM.json @@ -1,33 +1,33 @@ { "serial_file" : "files/special_conf/usrp_16qam.json", - "frequency" : 2.5e9, - "channel" : "AB", - "rx_gain_a" : 15, - "tx_gain_a" : 15, - "rx_gain_b" : 15, - "tx_gain_b" : 15, + "frequency" : 1e9, + "channel" : "A", + "rx_gain_a" : 25, + "tx_gain_a" : 25, + "rx_gain_b" : 25, + "tx_gain_b" : 25, "sample_rate" : 5e6, - "modulation" : "64QAM", + "modulation" : "16QAM", "frame_schedule" : [ - "BGGPPGGGGUGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" + "BGGGGGPGGGGUGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" ], "max_frame" : 4000, "ofdm_symbol_per_slot" : 10, "fft_size" : 64, "cp_size" : 16, - "ofdm_tx_zero_prefix" : 160, - "ofdm_tx_zero_postfix" : 160, + "ofdm_tx_zero_prefix" : 1840, + "ofdm_tx_zero_postfix" : 120, "beamsweep" : true, - "ue_channel" : "AB", - "ue_rx_gain_a" : [15], - "ue_tx_gain_a" : [15], - "ue_rx_gain_b" : [15], - "ue_tx_gain_b" : [15], + "ue_channel" : "A", + "ue_rx_gain_a" : [75], + "ue_tx_gain_a" : [75], + "ue_rx_gain_b" : [75], + "ue_tx_gain_b" : [75], "ue_frame_schedule" : [ - "BGGPPGGGGUGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" + "BGGGGGPGGGGUGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" ], - "tx_advance" : [100], + "tx_advance" : [300], "hw_framer" : false, - "ue_modulation" : "64QAM", + "ue_modulation" : "16QAM", "frame_mode" : "free_running" } From 66e870182c52b5ef2daf6144f1eed0794913d26d Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Fri, 8 Jul 2022 11:13:52 -0400 Subject: [PATCH 36/45] Update usrp_16qam.json Updated to ORBIT grid --- CC/Sounder/files/special_conf/usrp_16qam.json | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/CC/Sounder/files/special_conf/usrp_16qam.json b/CC/Sounder/files/special_conf/usrp_16qam.json index 0389855d..caa0cf22 100644 --- a/CC/Sounder/files/special_conf/usrp_16qam.json +++ b/CC/Sounder/files/special_conf/usrp_16qam.json @@ -2,14 +2,20 @@ "BaseStations": { "BS0": { "sdr": [ - "192.168.30.2" - ] + "10.10.23.1", + "10.10.23.2", + "10.10.23.3", + "10.10.23.4", + "10.10.23.5", + "10.10.23.6", + "10.10.23.7", + "10.10.23.8" + ] } }, "Clients": { "sdr": [ - "192.168.70.2" + "10.10.23.5" ] } } - From 7051b80355c3627c16aa1bd774c92660de15746b Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Fri, 29 Jul 2022 13:20:20 -0400 Subject: [PATCH 37/45] Update receiver.cc Added Beacon interval to support high BW for USRPs --- CC/Sounder/receiver.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/CC/Sounder/receiver.cc b/CC/Sounder/receiver.cc index 4b3a2580..928077fc 100644 --- a/CC/Sounder/receiver.cc +++ b/CC/Sounder/receiver.cc @@ -1167,9 +1167,14 @@ ssize_t Receiver::clientSyncBeacon(size_t radio_id, size_t sample_window) { syncrxbuffs.push_back(syncbuffmem.at(ch).data()); } + int Beacon_interval = 10; while (config_->running() && (sync_index < 0)) { - const int rx_status = client_radio_set_->radioRx( - radio_id, syncrxbuffs.data(), sample_window, rx_time); + int rx_status = -1; + for (int find_beacon_retry = 0; find_beacon_retry < Beacon_interval; + find_beacon_retry++) { + rx_status = client_radio_set_->radioRx(radio_id, syncrxbuffs.data(), + sample_window, rx_time); + } if (rx_status < 0) { MLPD_ERROR("clientSyncBeacon [%zu]: BAD SYNC Received (%d/%zu) %lld\n", From ee5fab88c9f5bb32f5d56b0ebc7f2090090a190c Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Fri, 29 Jul 2022 14:33:10 -0400 Subject: [PATCH 38/45] Update receiver.cc --- CC/Sounder/receiver.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/CC/Sounder/receiver.cc b/CC/Sounder/receiver.cc index 928077fc..c111f6c2 100644 --- a/CC/Sounder/receiver.cc +++ b/CC/Sounder/receiver.cc @@ -950,11 +950,12 @@ void Receiver::clientSyncTxRx(int tid, int core_id, SampleBuffer* rx_buffer) { } //-------------------- New sync - const size_t beacon_detect_window = - static_cast(static_cast(config_->samps_per_slot()) * - kBeaconDetectWindowScaler); + // const size_t beacon_detect_window = + // static_cast(static_cast(config_->samps_per_slot()) * + // kBeaconDetectWindowScaler); + const size_t beacon_detect_window = config_->samps_per_frame()/100; size_t sync_count = 0; - constexpr size_t kTargetSyncCount = 2; + constexpr size_t kTargetSyncCount = 1; assert(config_->samps_per_frame() >= beacon_detect_window); while ((sync_count < kTargetSyncCount) && config_->running()) { const ssize_t sync_index = clientSyncBeacon(tid, beacon_detect_window); @@ -1167,7 +1168,7 @@ ssize_t Receiver::clientSyncBeacon(size_t radio_id, size_t sample_window) { syncrxbuffs.push_back(syncbuffmem.at(ch).data()); } - int Beacon_interval = 10; + int Beacon_interval = 20; while (config_->running() && (sync_index < 0)) { int rx_status = -1; for (int find_beacon_retry = 0; find_beacon_retry < Beacon_interval; From 808abda54bc22c3bf8d2190faf65149146ed5836 Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Fri, 19 Aug 2022 15:17:18 -0400 Subject: [PATCH 39/45] Update RadioUHD.cc Update according to sync --- CC/Sounder/RadioUHD.cc | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/CC/Sounder/RadioUHD.cc b/CC/Sounder/RadioUHD.cc index de6e00be..423a723f 100644 --- a/CC/Sounder/RadioUHD.cc +++ b/CC/Sounder/RadioUHD.cc @@ -21,20 +21,28 @@ #include "uhd/utils/log_add.hpp" #endif +void RadioUHD::dev_init_set_freq(Config* _cfg, unsigned int total_channels) { + MLPD_INFO("setting frequency \n"); + dev_->clear_command_time(); + dev_->set_command_time(dev_->get_time_now() + uhd::time_spec_t(0.1)); + uhd::tune_request_t tune_request(_cfg->radio_rf_freq()); + // update for UHD multi USRP + for (unsigned int ch = 0; ch < total_channels; ch++) { + dev_->set_rx_freq(tune_request, ch); + dev_->set_tx_freq(tune_request, ch); + } + + std::this_thread::sleep_for(std::chrono::milliseconds(550)); //sleep 110ms (~10ms after retune occurs) to allow LO to lock + + dev_->clear_command_time(); +} + void RadioUHD::dev_init(Config* _cfg, int ch, double rxgain, double txgain) { // these params are sufficient to set before DC offset and IQ imbalance calibration MLPD_INFO("Init USRP channel: %d\n", ch); // update for UHD multi USRP dev_->set_tx_antenna("TX/RX", ch); dev_->set_rx_antenna("TX/RX", ch); - uhd::tune_request_t tune_request(0); - dev_->set_rx_freq(tune_request, ch); - dev_->set_tx_freq(tune_request, ch); - - // update for UHD multi USRP - tune_request = _cfg->radio_rf_freq(); - dev_->set_rx_freq(tune_request, ch); - dev_->set_tx_freq(tune_request, ch); // update for UHD multi USRP dev_->set_rx_gain(std::min(31.5, rxgain), "PGA0", ch); From b581aaf92557a1976eca411886747b6bd043d314 Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Fri, 19 Aug 2022 15:17:41 -0400 Subject: [PATCH 40/45] Update RadioUHD.h update --- CC/Sounder/include/RadioUHD.h | 1 + 1 file changed, 1 insertion(+) diff --git a/CC/Sounder/include/RadioUHD.h b/CC/Sounder/include/RadioUHD.h index e2f74c66..976106d1 100644 --- a/CC/Sounder/include/RadioUHD.h +++ b/CC/Sounder/include/RadioUHD.h @@ -40,6 +40,7 @@ class RadioUHD { void dev_init(Config* _cfg, int ch, double rxgain, double txgain); void reset_DATA_clk_domain(void); + void dev_init_set_freq(Config* _cfg, unsigned int total_channels); }; #endif /* RADIOUHD_H_ */ From a4f80734419b3e1fdcc7accd09f855124ec28bc2 Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Fri, 19 Aug 2022 15:18:11 -0400 Subject: [PATCH 41/45] Update RadioUHD.cc update --- CC/Sounder/RadioUHD.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CC/Sounder/RadioUHD.cc b/CC/Sounder/RadioUHD.cc index 423a723f..6f3ad7b7 100644 --- a/CC/Sounder/RadioUHD.cc +++ b/CC/Sounder/RadioUHD.cc @@ -32,7 +32,8 @@ void RadioUHD::dev_init_set_freq(Config* _cfg, unsigned int total_channels) { dev_->set_tx_freq(tune_request, ch); } - std::this_thread::sleep_for(std::chrono::milliseconds(550)); //sleep 110ms (~10ms after retune occurs) to allow LO to lock + std::this_thread::sleep_for(std::chrono::milliseconds( + 550)); //sleep 110ms (~10ms after retune occurs) to allow LO to lock dev_->clear_command_time(); } From e78723e9083237b987456909179a4ab9283cddc9 Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Fri, 19 Aug 2022 15:19:43 -0400 Subject: [PATCH 42/45] Update BaseRadioSetUHD.cc Update --- CC/Sounder/BaseRadioSetUHD.cc | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/CC/Sounder/BaseRadioSetUHD.cc b/CC/Sounder/BaseRadioSetUHD.cc index 5dc8b52d..ad1c3d50 100644 --- a/CC/Sounder/BaseRadioSetUHD.cc +++ b/CC/Sounder/BaseRadioSetUHD.cc @@ -9,6 +9,12 @@ */ #include "include/BaseRadioSetUHD.h" +#include +#include +#include +#include +#include + #include "SoapySDR/Formats.h" #include "SoapySDR/Time.hpp" #include "include/RadioUHD.h" @@ -26,6 +32,8 @@ BaseRadioSetUHD::BaseRadioSetUHD(Config* cfg) : _cfg(cfg) { radioNotFound = false; std::vector radio_serial_not_found; + std::cout << "error found !!!" << std::endl; + // need to be further modified MLPD_TRACE("num of cells are: %zu\n", _cfg->num_cells()); for (size_t c = 0; c < _cfg->num_cells(); c++) { @@ -71,6 +79,14 @@ BaseRadioSetUHD::BaseRadioSetUHD(Config* cfg) : _cfg(cfg) { dciqCalibrationProcUHD(1); } + // write TDD schedule and beacons to FPFA buffers only for Iris + bsRadios->RawDev()->set_time_source("external"); + bsRadios->RawDev()->set_clock_source("external"); + bsRadios->RawDev()->set_time_unknown_pps(uhd::time_spec_t(0.0)); + + // Wait for pps sync pulse + std::this_thread::sleep_for(std::chrono::seconds(1)); + thread_count.store(1); size_t ii = 0; BaseRadioContext* context_config = new BaseRadioContext; @@ -164,13 +180,6 @@ BaseRadioSetUHD::BaseRadioSetUHD(Config* cfg) : _cfg(cfg) { // write TDD schedule and beacons to FPFA buffers only for Iris for (size_t c = 0; c < _cfg->num_cells(); c++) { - bsRadios->RawDev()->set_time_source("external"); - bsRadios->RawDev()->set_clock_source("external"); - uhd::time_spec_t time = uhd::time_spec_t::from_ticks(0, 1e9); - bsRadios->RawDev()->set_time_next_pps(time); - - // Wait for pps sync pulse - std::this_thread::sleep_for(std::chrono::seconds(2)); // Activate Rx and Tx streamers bsRadios->activateRecv(); bsRadios->activateXmit(); @@ -269,6 +278,9 @@ void BaseRadioSetUHD::configure(BaseRadioContext* context) { bsRadios->dev_init(_cfg, (ch), rxgain, txgain); } + + bsRadios->dev_init_set_freq(_cfg, total_rx_channel); + assert(thread_count->load() != 0); thread_count->store(thread_count->load() - 1); } From 4ce1b3a6a1bf9c497c9ea69c1446c690ad840a4e Mon Sep 17 00:00:00 2001 From: Tom <82247342+Shadowcaster77@users.noreply.github.com> Date: Fri, 19 Aug 2022 15:20:30 -0400 Subject: [PATCH 43/45] Update ClientRadioSetUHD.cc Update --- CC/Sounder/ClientRadioSetUHD.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CC/Sounder/ClientRadioSetUHD.cc b/CC/Sounder/ClientRadioSetUHD.cc index ddaa8d1b..4d2daa94 100644 --- a/CC/Sounder/ClientRadioSetUHD.cc +++ b/CC/Sounder/ClientRadioSetUHD.cc @@ -153,6 +153,9 @@ void ClientRadioSetUHD::init(ClientRadioContext* context) { i); // w/CBRS 3.6GHz [0:105], 2.5GHZ [0:108] double txgain = _cfg->cl_txgain_vec().at(ch).at( i); // w/CBRS 3.6GHz [0:105], 2.5GHZ [0:105] + + auto total_rx_channel = 2; + radio_->dev_init_set_freq(_cfg, total_rx_channel); radio_->dev_init(_cfg, ch, rxgain, txgain); } } From c00684491fd7af2371ed8dc3d55853273948e1bb Mon Sep 17 00:00:00 2001 From: Andrew Sedlmayr Date: Mon, 1 May 2023 16:40:52 -0500 Subject: [PATCH 44/45] build fix --- .gitignore | 6 ++++-- CC/Sounder/BaseRadioSetUHD.cc | 8 ++++---- CC/Sounder/CMakeLists.txt | 21 ++++++++++++++------- CC/Sounder/main.cc | 6 ++++++ 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 4aa4e966..1f73bdca 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,10 @@ build/* CMakeFiles/* Beamformer/build/* Beamformer/build/CMakeFiles/* -Sounder/CMakeFiles/* -Sounder/CMakeCache* +CC/Sounder/CMakeFiles/* +CC/Sounder/CMakeCache* +CC/Sounder/mufft +CC/Sounder/build sounder *.com diff --git a/CC/Sounder/BaseRadioSetUHD.cc b/CC/Sounder/BaseRadioSetUHD.cc index 3d699263..05761a0d 100644 --- a/CC/Sounder/BaseRadioSetUHD.cc +++ b/CC/Sounder/BaseRadioSetUHD.cc @@ -329,10 +329,10 @@ int BaseRadioSetUHD::radioTx(size_t radio_id, size_t cell_id, w = bsRadios->xmit(buffs, _cfg->samps_per_slot(), flags, frameTimeNs); // } if (kDebugRadio) { - size_t chanMask; - long timeoutUs(0); - auto* dev = bsRadios->dev; - auto* txs = bsRadios->txs; + //size_t chanMask; + //long timeoutUs(0); + //auto* dev = bsRadios->dev; + //auto* txs = bsRadios->txs; // int s = dev->readStreamStatus(txs, chanMask, flags, frameTime, timeoutUs); // std::cout << "cell " << cell_id << " radio " << radio_id << " tx returned " // << w << " and status " << s << std::endl; diff --git a/CC/Sounder/CMakeLists.txt b/CC/Sounder/CMakeLists.txt index d8185293..8cc3157a 100644 --- a/CC/Sounder/CMakeLists.txt +++ b/CC/Sounder/CMakeLists.txt @@ -24,6 +24,10 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) STRING "Choose the type of build." FORCE) endif() +message(STATUS "Debug Flags: ${CMAKE_CXX_FLAGS_DEBUG}") +message(STATUS "Release Flags: ${CMAKE_CXX_FLAGS_RELEASE}") +message(STATUS "Compiling with CXX Flags: ${CMAKE_CXX_FLAGS}") + if(CMAKE_BUILD_TYPE MATCHES Debug) message(STATUS "Verbose Makefile") set( CMAKE_VERBOSE_MAKEFILE on ) @@ -51,10 +55,15 @@ else() set(CMAKE_CXX_STANDARD_REQUIRED ON) endif() -message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") -message(STATUS "Compiling with CXX Flags: ${CMAKE_CXX_FLAGS}") -message(STATUS "Debug Flags: ${CMAKE_CXX_FLAGS_DEBUG}") -message(STATUS "Release Flags: ${CMAKE_CXX_FLAGS_RELEASE}") +#Settable values +message(STATUS "\n-- ----- Configuration values -----") +message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}") +set(RADIO_TYPE SIMULATION CACHE STRING "RADIO_TYPE defaulting to 'SIMULATION', valid types are SIMULATION / SOAPY_IRIS / SOAPY_UHD / PURE_UHD") +message(STATUS "RADIO_TYPE: ${RADIO_TYPE}") +set(LOG_LEVEL "info" CACHE STRING "Console logging level (none/error/warn/info/frame/subframe/trace)") +message(STATUS "LOG_LEVEL: ${LOG_LEVEL}") +message(STATUS "--------------------------------\n--") + # Console logging level if(LOG_LEVEL STREQUAL "none") @@ -92,8 +101,6 @@ set(THREADS_PREFER_PTHREAD_FLAG TRUE) #find_package(Threads REQUIRED) message(STATUS "Using Pthread Library: ${CMAKE_THREAD_LIBS_INIT}: ${CMAKE_USE_PTHREADS_INIT}") -set(RADIO_TYPE SOAPY_IRIS CACHE STRING "RADIO_TYPE defaulting to 'SOAPY_IRIS', valid types are SOAPY_IRIS / SOAPY_UHD / PURE_UHD") -message(STATUS "RADIO_TYPE: ${RADIO_TYPE}") if(RADIO_TYPE STREQUAL PURE_UHD) message(STATUS "Enabled PURE_UHD radio") add_definitions(-DUSE_UHD) @@ -148,7 +155,6 @@ if (NOT HDF5_FOUND) endif() message(VERBOSE " HDF5 Includes: ${HDF5_INCLUDE_DIRS} Libraries: ${HDF5_LIBRARIES}") - set(directory "logs") file(MAKE_DIRECTORY ${directory}) @@ -208,3 +214,4 @@ target_link_libraries(sounder_module -lpthread --enable-threadsafe ${GFLAGS_LIBR -Wl,--no-whole-archive ${HDF5_LIBRARIES} ${SoapySDR_LIBRARIES}) + diff --git a/CC/Sounder/main.cc b/CC/Sounder/main.cc index a1ebe288..fcc1fabe 100644 --- a/CC/Sounder/main.cc +++ b/CC/Sounder/main.cc @@ -42,7 +42,13 @@ int main(int argc, char* argv[]) { auto dg = std::make_unique(config.get()); dg->GenerateData(FLAGS_storepath); } else if (FLAGS_calibrate) { +#if defined(USE_UHD) + std::cout << "Radio calibrate function is not compatible with the radio " + "calibratate flag!" + << std::endl; +#else auto base_radio_set_ = std::make_unique(config.get(), true); +#endif } else { int cnt = 0; int maxTry = 2; From 9aaed8a73599c7c14330a3170ad45453a6485a01 Mon Sep 17 00:00:00 2001 From: Andrew Sedlmayr Date: Tue, 2 May 2023 15:20:26 -0500 Subject: [PATCH 45/45] Added clock type configuration --- CC/Sounder/BaseRadioSetUHD.cc | 16 ++++++++++++++-- CC/Sounder/ClientRadioSetUHD.cc | 19 +++++++++++++++---- CC/Sounder/RadioUHD.cc | 3 ++- CC/Sounder/config.cc | 31 ++++++++++++++++++++++++------- CC/Sounder/include/RadioUHD.h | 3 ++- CC/Sounder/include/config.h | 15 ++++++++++++--- CC/Sounder/receiver.cc | 2 +- 7 files changed, 70 insertions(+), 19 deletions(-) diff --git a/CC/Sounder/BaseRadioSetUHD.cc b/CC/Sounder/BaseRadioSetUHD.cc index 05761a0d..43916b9f 100644 --- a/CC/Sounder/BaseRadioSetUHD.cc +++ b/CC/Sounder/BaseRadioSetUHD.cc @@ -80,9 +80,21 @@ BaseRadioSetUHD::BaseRadioSetUHD(Config* cfg) : _cfg(cfg) { } // write TDD schedule and beacons to FPFA buffers only for Iris - bsRadios->RawDev()->set_time_source("external"); - bsRadios->RawDev()->set_clock_source("external"); + const auto clock_source = _cfg->getBsClockType(); + bsRadios->RawDev()->set_time_source(clock_source); + bsRadios->RawDev()->set_clock_source(clock_source); bsRadios->RawDev()->set_time_unknown_pps(uhd::time_spec_t(0.0)); + MLPD_INFO( + "USRP BS Clock source requested %s, actual %s, Time Source requested " + "%s, actual %s\n", + clock_source.c_str(), + bsRadios->RawDev() + ->get_clock_source(uhd::usrp::multi_usrp::ALL_MBOARDS) + .c_str(), + clock_source.c_str(), + bsRadios->RawDev() + ->get_time_source(uhd::usrp::multi_usrp::ALL_MBOARDS) + .c_str()); // Wait for pps sync pulse std::this_thread::sleep_for(std::chrono::seconds(1)); diff --git a/CC/Sounder/ClientRadioSetUHD.cc b/CC/Sounder/ClientRadioSetUHD.cc index 40a1fb41..f365f2e1 100644 --- a/CC/Sounder/ClientRadioSetUHD.cc +++ b/CC/Sounder/ClientRadioSetUHD.cc @@ -29,7 +29,7 @@ ClientRadioSetUHD::ClientRadioSetUHD(Config* cfg) : _cfg(cfg) { context->crs = this; context->thread_count = &thread_count; context->tid = i; -#ifdef THREADED_INIT +#if defined(THREADED_INIT) pthread_t init_thread_; if (pthread_create(&init_thread_, NULL, ClientRadioSetUHD::init_launch, @@ -93,12 +93,23 @@ ClientRadioSetUHD::ClientRadioSetUHD(Config* cfg) : _cfg(cfg) { "discovered in the network!" << std::endl; } else { - radio_->RawDev()->set_time_source("internal"); - radio_->RawDev()->set_clock_source("internal"); + const auto cl_clock_source = _cfg->getClClockType(0); + radio_->RawDev()->set_time_source(cl_clock_source); + radio_->RawDev()->set_clock_source(cl_clock_source); radio_->RawDev()->set_time_unknown_pps(uhd::time_spec_t(0.0)); + MLPD_INFO( + "USRP UE Clock source requested %s, actual %s, Time Source requested " + "%s, actual %s\n", + cl_clock_source.c_str(), + radio_->RawDev() + ->get_clock_source(uhd::usrp::multi_usrp::ALL_MBOARDS) + .c_str(), + cl_clock_source.c_str(), + radio_->RawDev() + ->get_time_source(uhd::usrp::multi_usrp::ALL_MBOARDS) + .c_str()); radio_->activateRecv(); radio_->activateXmit(); - MLPD_INFO("%s done!\n", __func__); } } diff --git a/CC/Sounder/RadioUHD.cc b/CC/Sounder/RadioUHD.cc index 6f3ad7b7..f882428f 100644 --- a/CC/Sounder/RadioUHD.cc +++ b/CC/Sounder/RadioUHD.cc @@ -38,7 +38,8 @@ void RadioUHD::dev_init_set_freq(Config* _cfg, unsigned int total_channels) { dev_->clear_command_time(); } -void RadioUHD::dev_init(Config* _cfg, int ch, double rxgain, double txgain) { +void RadioUHD::dev_init([[maybe_unused]] Config* _cfg, int ch, double rxgain, + double txgain) { // these params are sufficient to set before DC offset and IQ imbalance calibration MLPD_INFO("Init USRP channel: %d\n", ch); // update for UHD multi USRP diff --git a/CC/Sounder/config.cc b/CC/Sounder/config.cc index f60ae78f..5d04798b 100644 --- a/CC/Sounder/config.cc +++ b/CC/Sounder/config.cc @@ -17,10 +17,13 @@ #include "nlohmann/json.hpp" using json = nlohmann::json; -static size_t kFpgaTxRamSize = 4096; -static size_t kMaxSupportedFFTSize = 2048; -static size_t kMinSupportedFFTSize = 64; -static size_t kMaxSupportedCPSize = 128; +static constexpr size_t kFpgaTxRamSize = 4096; +static constexpr size_t kMaxSupportedFFTSize = 2048; +static constexpr size_t kMinSupportedFFTSize = 64; +static constexpr size_t kMaxSupportedCPSize = 128; + +static const std::string kDefaultBsClockType = "external"; +static const std::string kDefaultUeClockType = "internal"; Config::Config(const std::string& jsonfile, const std::string& directory, const bool bs_only, const bool client_only, const bool calibrate) @@ -124,6 +127,7 @@ Config::Config(const std::string& jsonfile, const std::string& directory, beacon_ch_ = beacon_ant_ % bs_sdr_ch_; max_frame_ = tddConf.value("max_frame", 0); bs_hw_framer_ = tddConf.value("bs_hw_framer", true); + bs_clock_type_ = tddConf.value("bs_clock_type", kDefaultBsClockType); // Load/Build BS and Client SDRs' Schedules bs_array_frames_.resize(num_cells_); @@ -191,20 +195,33 @@ Config::Config(const std::string& jsonfile, const std::string& directory, } else { if (client_present_ && tx_advance.size() != num_cl_sdrs_) { MLPD_ERROR("tx_advance size must be same as the number of clients!\n"); - exit(1); + std::exit(1); } tx_advance_.assign(tx_advance.begin(), tx_advance.end()); } + auto corr_scale = tddConf.value("corr_scale", json::array()); if (corr_scale.empty() == true) { corr_scale_.resize(num_cl_sdrs_, 1); } else { if (client_present_ && corr_scale.size() != num_cl_sdrs_) { - MLPD_ERROR("tx_advance size must be same as the number of clients!\n"); - exit(1); + MLPD_ERROR("corr_scale size must be same as the number of clients!\n"); + std::exit(1); } corr_scale_.assign(corr_scale.begin(), corr_scale.end()); } + + auto cl_clock_type = tddConf.value("cl_clock_type", json::array()); + if (tx_advance.empty() == true) { + cl_clock_type_.resize(num_cl_sdrs_, kDefaultUeClockType); + } else { + if (client_present_ && tx_advance.size() != num_cl_sdrs_) { + MLPD_ERROR("cl_clock_type size must be same as the number of clients!\n"); + std::exit(1); + } + cl_clock_type_.assign(cl_clock_type.begin(), cl_clock_type.end()); + } + ul_data_frame_num_ = tddConf.value("ul_data_frame_num", 1); dl_data_frame_num_ = tddConf.value("dl_data_frame_num", 1); diff --git a/CC/Sounder/include/RadioUHD.h b/CC/Sounder/include/RadioUHD.h index 976106d1..b7d7aa5c 100644 --- a/CC/Sounder/include/RadioUHD.h +++ b/CC/Sounder/include/RadioUHD.h @@ -38,7 +38,8 @@ class RadioUHD { void deactivateXmit(void); int getTriggers(void) const; - void dev_init(Config* _cfg, int ch, double rxgain, double txgain); + void dev_init([[maybe_unused]] Config* _cfg, int ch, double rxgain, + double txgain); void reset_DATA_clk_domain(void); void dev_init_set_freq(Config* _cfg, unsigned int total_channels); }; diff --git a/CC/Sounder/include/config.h b/CC/Sounder/include/config.h index 5e42b037..d2619b0b 100644 --- a/CC/Sounder/include/config.h +++ b/CC/Sounder/include/config.h @@ -263,6 +263,11 @@ class Config { } inline size_t getTxFrameDelta() const { return tx_frame_delta_; } + inline const std::string getBsClockType() const { return bs_clock_type_; } + inline const std::string getClClockType(size_t ue_idx) const { + return cl_clock_type_.at(ue_idx); + } + size_t getNumAntennas(); size_t getMaxNumAntennas(); size_t getNumBsSdrs(); @@ -300,10 +305,11 @@ class Config { // common features double freq_; - double nco_; // baseband frequency controlled by NCO + // baseband frequency controlled by NCO + double nco_; double rate_; - double - radio_rf_freq_; // RF frequency set frame_modeon the radio after NCO adjustments + // RF frequency set frame_modeon the radio after NCO adjustments + double radio_rf_freq_; double bw_filter_; size_t fft_size_; size_t cp_size_; @@ -378,6 +384,7 @@ class Config { bool ref_node_enable_; size_t cal_ref_sdr_id_; size_t tx_frame_delta_; + std::string bs_clock_type_; // Clients features std::vector cl_sdr_ids_; @@ -391,6 +398,8 @@ class Config { bool cl_power_ramp_; int cl_power_ramp_lo_; int cl_power_ramp_hi_; + std::vector cl_clock_type_; + std::vector tx_advance_; std::vector corr_scale_; std::vector data_ind_; diff --git a/CC/Sounder/receiver.cc b/CC/Sounder/receiver.cc index 56c47b2f..fc00664e 100644 --- a/CC/Sounder/receiver.cc +++ b/CC/Sounder/receiver.cc @@ -952,7 +952,7 @@ void Receiver::clientSyncTxRx(int tid, int core_id, SampleBuffer* rx_buffer) { // const size_t beacon_detect_window = // static_cast(static_cast(config_->samps_per_slot()) * // kBeaconDetectWindowScaler); - const size_t beacon_detect_window = config_->samps_per_frame()/100; + const size_t beacon_detect_window = config_->samps_per_frame() / 100; size_t sync_count = 0; constexpr size_t kTargetSyncCount = 1; assert(config_->samps_per_frame() >= beacon_detect_window);