Skip to content

Commit

Permalink
Merged fixes from dual-rx branch. Dealt with warnings, added -Wall -W…
Browse files Browse the repository at this point in the history
…extra -Wpedantic -Werror flags
  • Loading branch information
kuehnhammer committed Oct 3, 2023
2 parents f9d98aa + 8ba15af commit cbffa71
Show file tree
Hide file tree
Showing 20 changed files with 128 additions and 149 deletions.
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
cmake_minimum_required(VERSION 3.16)

project (modem VERSION 1.2.2)
project (modem VERSION 1.3.0)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

find_package(cpprestsdk REQUIRED)
include(CTest)
include(FindPkgConfig)

Expand All @@ -29,7 +30,6 @@ set(ENABLE_SRSENB OFF CACHE BOOL "Build srsENB application")
set(ENABLE_SRSEPC OFF CACHE BOOL "Build srsEPC application")
add_subdirectory(lib/srsran)

find_package(cpprestsdk REQUIRED)
include_directories(
SYSTEM
${SPDLOG_INCLUDEDIR}
Expand All @@ -42,7 +42,7 @@ link_directories(
${PROJECT_BINARY_DIR}/lib/srsran/lib/src/phy/
)


add_compile_options(-Wall -Wextra -Wpedantic -Werror)
set(CMAKE_CXX_CLANG_TIDY clang-tidy --format-style=google --checks=clang-diagnostic-*,clang-analyzer-*,-*,bugprone*,modernize*,performance*)

add_executable(modem src/main.cpp src/SdrReader.cpp src/Phy.cpp
Expand All @@ -51,6 +51,7 @@ add_executable(modem src/main.cpp src/SdrReader.cpp src/Phy.cpp

target_link_libraries( modem
LINK_PUBLIC
spdlog
srsran_phy
srsran_mac
srsran_rlc
Expand Down
1 change: 0 additions & 1 deletion include/spdlog/details/log_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ struct SPDLOG_API log_msg
log_msg(log_clock::time_point log_time, source_loc loc, string_view_t logger_name, level::level_enum lvl, string_view_t msg);
log_msg(source_loc loc, string_view_t logger_name, level::level_enum lvl, string_view_t msg);
log_msg(string_view_t logger_name, level::level_enum lvl, string_view_t msg);
log_msg(const log_msg &other) = default;

string_view_t logger_name;
level::level_enum level{level::off};
Expand Down
2 changes: 0 additions & 2 deletions include/thread_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ class thread_pool
}

thread_pool(thread_pool const &) = delete;
thread_pool(thread_pool &&) = default;

thread_pool &operator=(thread_pool const &) = delete;
thread_pool &operator=(thread_pool &&) = default;

// Push a new task into the queue
template <class Func, class... Args>
Expand Down
12 changes: 6 additions & 6 deletions src/CasFrameProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
auto CasFrameProcessor::init() -> bool {
_signal_buffer_max_samples = 3 * SRSRAN_SF_LEN_PRB(MAX_PRB);

for (auto ch = 0; ch < _rx_channels; ch++) {
for (auto ch = 0U; ch < _rx_channels; ch++) {
_signal_buffer_rx[ch] = srsran_vec_cf_malloc(_signal_buffer_max_samples);
if (!_signal_buffer_rx[ch]) {
spdlog::error("Could not allocate regular DL signal buffer\n");
Expand Down Expand Up @@ -114,7 +114,7 @@ auto CasFrameProcessor::process(uint32_t tti) -> bool {
for (int k = 0; k < nof_grants; k++) {
char str[512]; // NOLINT
srsran_dci_dl_info(&dci[k], str, 512);
_rest._pdsch.mcs = dci[k].tb[0].mcs_idx;
_rest._pdsch.mcs = static_cast<int>(dci[k].tb[0].mcs_idx);
spdlog::debug("Decoded PDCCH: {}, snr={} dB\n", str, _ue_dl.chest_res.snr_db);

if (srsran_ue_dl_dci_to_pdsch_grant(&_ue_dl, &_sf_cfg, &_ue_dl_cfg, &dci[k], &_ue_dl_cfg.cfg.pdsch.grant)) {
Expand All @@ -133,7 +133,7 @@ auto CasFrameProcessor::process(uint32_t tti) -> bool {
if (pdsch_cfg->grant.tb[i].rv < 0) {
uint32_t sfn = tti / 10;
uint32_t k = (sfn / 2) % 4;
pdsch_cfg->grant.tb[i].rv = ((int32_t)ceilf(static_cast<float>(1.5) * k)) % 4;
pdsch_cfg->grant.tb[i].rv = ((int32_t)ceilf(1.5F * static_cast<float>(k))) % 4;
}
pdsch_res[i].payload = _data[i];
pdsch_res[i].crc = false;
Expand All @@ -142,7 +142,7 @@ auto CasFrameProcessor::process(uint32_t tti) -> bool {
}

_rest._pdsch.SetData(pdsch_data());
_rest._ce_values = std::move(ce_values());
_rest._ce_values = ce_values();

// Decode PDSCH..
auto ret = srsran_ue_dl_decode_pdsch(&_ue_dl, &_sf_cfg, &_ue_dl_cfg.cfg.pdsch, pdsch_res);
Expand Down Expand Up @@ -170,10 +170,10 @@ auto CasFrameProcessor::ce_values() -> std::vector<uint8_t> {
uint32_t g = (sz - 12 * _cell.nof_prb) / 2;
srsran_vec_abs_dB_cf(_ue_dl.chest_res.ce[0][0], -80, &ce_abs[g], SRSRAN_NRE * _cell.nof_prb);
const uint8_t* data = reinterpret_cast<uint8_t*>(ce_abs.data());
return std::vector<uint8_t>( data, data + sz * sizeof(float));
return { data, data + sz * sizeof(float)};
}

auto CasFrameProcessor::pdsch_data() -> std::vector<uint8_t> {
const uint8_t* data = reinterpret_cast<uint8_t*>(_ue_dl.pdsch.d[0]);
return std::vector<uint8_t>( data, data + _ue_dl_cfg.cfg.pdsch.grant.nof_re * sizeof(cf_t));
return { data, data + _ue_dl_cfg.cfg.pdsch.grant.nof_re * sizeof(cf_t)};
}
6 changes: 2 additions & 4 deletions src/CasFrameProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ class CasFrameProcessor {
* @param rlc RLC reference
* @param rest RESTful API handler reference
*/
CasFrameProcessor(const libconfig::Config& cfg, Phy& phy, srsran::rlc& rlc, RestHandler& rest, unsigned rx_channels)
: _cfg(cfg)
CasFrameProcessor(const libconfig::Config& /*cfg*/, Phy& phy, srsran::rlc& rlc, RestHandler& rest, unsigned rx_channels)
: _rlc(rlc)
, _phy(phy)
, _rest(rest)
, _rlc(rlc)
, _rx_channels(rx_channels)
{}

Expand Down Expand Up @@ -112,7 +111,6 @@ class CasFrameProcessor {
float cinr_db() { return _ue_dl.chest_res.snr_db; }

private:
const libconfig::Config& _cfg;
srsran::rlc& _rlc;
Phy& _phy;
RestHandler& _rest;
Expand Down
12 changes: 6 additions & 6 deletions src/Gw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ void Gw::write_pdu_mch(uint32_t mch_idx, uint32_t lcid, srsran::unique_byte_buff
} else {
auto ip_hdr = reinterpret_cast<iphdr*>(pdu->msg);
if (ip_hdr->protocol == 17 /*UDP*/) {
auto udp_hdr = reinterpret_cast<udphdr*>(pdu->msg + 4U * ip_hdr->ihl);
auto udp_hdr = reinterpret_cast<udphdr*>(pdu->msg + 4UL * ip_hdr->ihl);
char dest[INET6_ADDRSTRLEN] = ""; // NOLINT
inet_ntop(AF_INET, (const void*)&ip_hdr->daddr, dest, sizeof(dest));

_phy.set_dest_for_lcid(mch_idx, lcid, std::string(dest) + ":" + std::to_string(ntohs(udp_hdr->dest)));
_phy.set_dest_for_lcid(mch_idx, static_cast<int>(lcid), std::string(dest) + ":" + std::to_string(ntohs(udp_hdr->dest)));

auto ptr = reinterpret_cast<uint16_t*>(ip_hdr);
int32_t sum = 0;
Expand All @@ -73,16 +73,16 @@ void Gw::write_pdu_mch(uint32_t mch_idx, uint32_t lcid, srsran::unique_byte_buff
}

_wr_mutex.lock();
int n = write(_tun_fd, pdu->msg, pdu->N_bytes);
auto n = write(_tun_fd, pdu->msg, pdu->N_bytes);
_wr_mutex.unlock();

if (n > 0 && (pdu->N_bytes != static_cast<uint32_t>(n))) {
if (n > 0L && (pdu->N_bytes != static_cast<uint32_t>(n))) {
spdlog::warn("DL TUN/TAP short write");
}
if (n == 0) {
if (n == 0L) {
spdlog::warn("DL TUN/TAP 0 write");
}
if (n < 0) {
if (n < 0L) {
err_str = strerror(errno);
spdlog::warn("DL TUN/TAP write error {}", err_str);
}
Expand Down
19 changes: 8 additions & 11 deletions src/Gw.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ class Gw : public srsue::gw_interface_stack {
* @param cfg Config singleton reference
* @param phy PHY reference
*/
Gw(const libconfig::Config& cfg, Phy& phy)
: _cfg(cfg)
, _phy(phy)
Gw(const libconfig::Config& /*cfg*/, Phy& phy)
: _phy(phy)
{}

/**
Expand All @@ -63,17 +62,15 @@ class Gw : public srsue::gw_interface_stack {
void write_pdu_mch(uint32_t mch_idx, uint32_t lcid, srsran::unique_byte_buffer_t pdu) override;

// Unused interface methods
void add_mch_port(uint32_t lcid, uint32_t port) override {};
void write_pdu(uint32_t lcid, srsran::unique_byte_buffer_t pdu) override {};
int setup_if_addr(uint32_t lcid, uint8_t pdn_type, uint32_t ip_addr, uint8_t* ipv6_if_id, char* err_str) override { return -1; };
int apply_traffic_flow_template(const uint8_t& eps_bearer_id, const LIBLTE_MME_TRAFFIC_FLOW_TEMPLATE_STRUCT* tft) override { return -1; };
void set_test_loop_mode(const test_loop_mode_state_t mode, const uint32_t ip_pdu_delay_ms = 0) override {};
void add_mch_port(uint32_t /*lcid*/, uint32_t /*port*/) override {};
void write_pdu(uint32_t /*lcid*/, srsran::unique_byte_buffer_t /*pdu*/) override {};
int setup_if_addr(uint32_t /*lcid*/, uint8_t /*pdn_type*/, uint32_t /*ip_addr*/, uint8_t* /*ipv6_if_id*/, char* /*err_str*/) override { return -1; };
int apply_traffic_flow_template(const uint8_t& /*eps_bearer_id*/, const LIBLTE_MME_TRAFFIC_FLOW_TEMPLATE_STRUCT* /*tft*/) override { return -1; };
void set_test_loop_mode(const test_loop_mode_state_t /*mode*/, const uint32_t /*ip_pdu_delay_ms = 0*/) override {};

int deactivate_eps_bearer(const uint32_t eps_bearer_id) override {return 0;};
int deactivate_eps_bearer(const uint32_t /*eps_bearer_id*/) override {return 0;};
bool is_running() override { return true; };
private:
const libconfig::Config& _cfg;

std::mutex _wr_mutex;
int32_t _tun_fd = -1;
Phy& _phy;
Expand Down
8 changes: 4 additions & 4 deletions src/MbsfnFrameProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ std::mutex MbsfnFrameProcessor::_rlc_mutex;
auto MbsfnFrameProcessor::init() -> bool {
_signal_buffer_max_samples = 3 * SRSRAN_SF_LEN_PRB(MAX_PRB);

for (auto ch = 0; ch < _rx_channels; ch++) {
for (auto ch = 0U; ch < _rx_channels; ch++) {
_signal_buffer_rx[ch] = srsran_vec_cf_malloc(_signal_buffer_max_samples);
if (!_signal_buffer_rx[ch]) {
spdlog::error("Could not allocate regular DL signal buffer\n");
Expand Down Expand Up @@ -164,10 +164,10 @@ auto MbsfnFrameProcessor::process(uint32_t tti) -> int {

if (mbsfn_cfg.is_mcch) {
_rest._mcch.SetData(mch_data());
_rest._mcch.mcs = _pmch_cfg.pdsch_cfg.grant.tb[0].mcs_idx;
_rest._mcch.mcs = static_cast<int>(_pmch_cfg.pdsch_cfg.grant.tb[0].mcs_idx);
} else {
_rest._mch[mch_idx].SetData(mch_data());
_rest._mch[mch_idx].mcs = _pmch_cfg.pdsch_cfg.grant.tb[0].mcs_idx;
_rest._mch[mch_idx].mcs = static_cast<int>(_pmch_cfg.pdsch_cfg.grant.tb[0].mcs_idx);
_rest._mch[mch_idx].present = true;
}

Expand Down Expand Up @@ -264,5 +264,5 @@ void MbsfnFrameProcessor::configure_mbsfn(uint8_t area_id, srsran_scs_t subcarri

auto MbsfnFrameProcessor::mch_data() const -> std::vector<uint8_t> const {
const uint8_t* data = reinterpret_cast<uint8_t*>(_ue_dl.pmch.d);
return std::move(std::vector<uint8_t>( data, data + _pmch_cfg.pdsch_cfg.grant.nof_re * sizeof(cf_t)));
return std::vector<uint8_t>( data, data + _pmch_cfg.pdsch_cfg.grant.nof_re * sizeof(cf_t));
}
7 changes: 2 additions & 5 deletions src/MbsfnFrameProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ class MbsfnFrameProcessor {
* @param rest RESTful API handler reference
*/
MbsfnFrameProcessor(const libconfig::Config& cfg, srsran::rlc& rlc, Phy& phy, srslog::basic_logger& log_h, RestHandler& rest, unsigned rx_channels )
: _cfg(cfg)
, _rlc(rlc)
: _rlc(rlc)
, _phy(phy)
, _rest(rest)
, mch_mac_msg(20, log_h)
, _rest(rest)
, _rx_channels(rx_channels)
{
_allow_rrc_sn_across_periods = false;
Expand Down Expand Up @@ -128,7 +127,6 @@ class MbsfnFrameProcessor {
float cinr_db() { return _ue_dl.chest_res.snr_db; }

private:
const libconfig::Config& _cfg;
srsran::rlc& _rlc;
Phy& _phy;

Expand Down Expand Up @@ -157,7 +155,6 @@ class MbsfnFrameProcessor {
unsigned _rx_channels;

bool _allow_rrc_sn_across_periods = false;

static std::mutex _sched_stop_mutex;
static std::map<uint8_t, uint16_t> _sched_stops;

Expand Down
12 changes: 5 additions & 7 deletions src/MultichannelRingbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
#include <memory>
#include "spdlog/spdlog.h"

MultichannelRingbuffer::MultichannelRingbuffer(size_t size, size_t channels)
MultichannelRingbuffer::MultichannelRingbuffer(size_t size, size_t channels) //NOLINT
: _size( size )
, _channels( channels )
, _used( 0 )
, _head( 0 )
{
for (auto ch = 0; ch < _channels; ch++) {
for (auto ch = 0UL; ch < _channels; ch++) {
auto buf = (char*)malloc(_size);
if (buf == nullptr) {
throw "Could not allocate memory";
Expand Down Expand Up @@ -59,7 +59,7 @@ auto MultichannelRingbuffer::write_head(size_t* writeable) -> std::vector<void*>
} else {
*writeable = _size - tail;
}
for (auto ch = 0; ch < _channels; ch++) {
for (auto ch = 0UL; ch < _channels; ch++) {
buffers[ch] = (void*)(_buffers[ch] + tail);
}
}
Expand All @@ -69,7 +69,6 @@ auto MultichannelRingbuffer::write_head(size_t* writeable) -> std::vector<void*>

auto MultichannelRingbuffer::commit(size_t written) -> void
{
assert(written >= 0);
assert(written <= free_size());
std::lock_guard<std::mutex> lock(_mutex);
_used += written;
Expand All @@ -80,20 +79,19 @@ auto MultichannelRingbuffer::read(std::vector<char*> dest, size_t size) -> void
{
assert(dest.size() >= _channels);
assert(size <= used_size());
assert(size >= 0);

std::lock_guard<std::mutex> lock(_mutex);
auto end = (_head + size) % _size;

if (end <= _head) {
auto first_part = _size - _head;
auto second_part = size - first_part;
for (auto ch = 0; ch < _channels; ch++) {
for (auto ch = 0UL; ch < _channels; ch++) {
memcpy(dest[ch], _buffers[ch] + _head, first_part);
memcpy(dest[ch] + first_part, _buffers[ch], second_part);
}
} else {
for (auto ch = 0; ch < _channels; ch++) {
for (auto ch = 0UL; ch < _channels; ch++) {
memcpy(dest[ch], _buffers[ch] + _head, size);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/MultichannelRingbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MultichannelRingbuffer {
std::vector<char*> _buffers;
size_t _size;
size_t _channels;
size_t _head;
size_t _used;
size_t _head;
std::mutex _mutex;
};
22 changes: 13 additions & 9 deletions src/Phy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ const uint32_t kSubframesPerFrame = 10;

const uint32_t kMaxCellsToDiscover = 3;

Phy::Phy(const libconfig::Config& cfg, get_samples_t cb, uint8_t cs_nof_prb,
Phy::Phy(const libconfig::Config& /*cfg*/, get_samples_t cb, uint8_t cs_nof_prb, //NOLINT
int8_t override_nof_prb, uint8_t rx_channels)
: _cfg(cfg),
_sample_cb(std::move(std::move(cb))),
_cs_nof_prb(cs_nof_prb),
_override_nof_prb(override_nof_prb),
_rx_channels(rx_channels) {
: _sample_cb(std::move(cb))
, _cs_nof_prb(cs_nof_prb)
, _override_nof_prb(override_nof_prb)
, _rx_channels(rx_channels) {
_buffer_max_samples = kMaxBufferSamples;
_mib_buffer[0] = static_cast<cf_t*>(malloc(_buffer_max_samples * sizeof(cf_t))); // NOLINT
_mib_buffer[1] = static_cast<cf_t*>(malloc(_buffer_max_samples * sizeof(cf_t))); // NOLINT
Expand All @@ -54,6 +53,7 @@ Phy::Phy(const libconfig::Config& cfg, get_samples_t cb, uint8_t cs_nof_prb,
Phy::~Phy() {
srsran_ue_sync_free(&_ue_sync);
free(_mib_buffer[0]); // NOLINT
free(_mib_buffer[1]); // NOLINT
}

auto Phy::synchronize_subframe() -> bool {
Expand All @@ -66,8 +66,12 @@ auto Phy::synchronize_subframe() -> bool {

if (ret == 1) {
std::array<uint8_t, SRSRAN_BCH_PAYLOAD_LEN> bch_payload = {};
if (srsran_ue_sync_get_sfidx(&_ue_sync) == 0) {
auto sfn = srsran_ue_sync_get_sfn(&_ue_sync);
auto sf = srsran_ue_sync_get_sfidx(&_ue_sync);
if ((_cell.mbms_dedicated && sf == 0 && sfn % 4 == 0) ||
(!_cell.mbms_dedicated && sf == 0)) {
int sfn_offset = 0;
// srsran_ue_mib_reset(&_mib);
int n =
srsran_ue_mib_decode(&_mib, bch_payload.data(), nullptr, &sfn_offset);
if (n == 1) {
Expand All @@ -89,7 +93,7 @@ auto Phy::synchronize_subframe() -> bool {
}

auto Phy::cell_search() -> bool {
std::array<srsran_ue_cellsearch_result_t, kMaxCellsToDiscover> found_cells = {0};
std::array<srsran_ue_cellsearch_result_t, kMaxCellsToDiscover> found_cells = {};

uint32_t max_peak_cell = 0;
int ret = srsran_ue_cellsearch_scan(&_cell_search, found_cells.data(), &max_peak_cell);
Expand Down Expand Up @@ -365,7 +369,7 @@ auto Phy::mbsfn_config_for_tti(uint32_t tti, unsigned& area)
if (sf_idx <= _mcch.pmch_info_list[i].sf_alloc_end) {
area = i;
if ((i == 0 && fn_in_scheduling_period == 0 && sf == 1) ||
(i > 0 && _mcch.pmch_info_list[i-1].sf_alloc_end + 1 == sf_idx)) {
(i > 0 && static_cast<unsigned>(_mcch.pmch_info_list[i-1].sf_alloc_end) + 1 == sf_idx)) {
spdlog::debug("assigning sig_mcs {}, mch_idx is {}", area_info.mcch_cfg.sig_mcs, area);
cfg.mbsfn_mcs = enum_to_number(area_info.mcch_cfg.sig_mcs);
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/Phy.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,9 @@ class Phy {
srsran::mcch_msg_t& mcch() { return _mcch; }

int _mcs = 0;
get_samples_t _sample_cb;

get_samples_t _sample_cb;
private:
const libconfig::Config& _cfg;
srsran_ue_sync_t _ue_sync = {};
srsran_ue_cellsearch_t _cell_search = {};
srsran_ue_mib_sync_t _mib_sync = {};
Expand Down
Loading

0 comments on commit cbffa71

Please sign in to comment.