Search for a cell.
Returns true if a cell has been found and the MIB could be decoded, false otherwise.
92 std::array<srsran_ue_cellsearch_result_t, kMaxCellsToDiscover> found_cells = {0};
94 uint32_t max_peak_cell = 0;
95 int ret = srsran_ue_cellsearch_scan(&
_cell_search, found_cells.data(), &max_peak_cell);
97 spdlog::error(
"Phy: Error decoding MIB: Error searching PSS\n");
101 spdlog::error(
"Phy: Could not find any cell in this frequency\n");
105 srsran_cell_t new_cell = {};
106 new_cell.id = found_cells.at(max_peak_cell).cell_id;
107 new_cell.cp = found_cells.at(max_peak_cell).cp;
108 new_cell.frame_type = found_cells.at(max_peak_cell).frame_type;
109 float cfo = found_cells.at(max_peak_cell).cfo;
111 spdlog::info(
"Phy: PSS/SSS detected: Mode {}, PCI {}, CFO {} KHz, CP {}",
112 new_cell.frame_type != 0U ?
"TDD" :
"FDD", new_cell.id,
113 cfo / 1000, srsran_cp_string(new_cell.cp));
117 std::array<uint8_t, SRSRAN_BCH_PAYLOAD_LEN> bch_payload = {};
122 new_cell.mbms_dedicated =
true;
124 spdlog::error(
"Phy: Error setting UE MIB sync cell");
127 srsran_ue_sync_reset(&
_mib_sync.ue_sync);
128 ret = srsran_ue_mib_sync_decode_prb(&
_mib_sync, 40, bch_payload.data(), &new_cell.nof_ports, &sfn_offset,
_cs_nof_prb);
132 new_cell.mbms_dedicated =
false;
134 spdlog::error(
"Phy: Error setting UE MIB sync cell");
137 srsran_ue_sync_reset(&
_mib_sync.ue_sync);
138 ret = srsran_ue_mib_sync_decode_prb(&
_mib_sync, 40, bch_payload.data(), &new_cell.nof_ports, &sfn_offset,
_cs_nof_prb);
144 if (new_cell.mbms_dedicated) {
145 srsran_pbch_mib_mbms_unpack(bch_payload.data(), &new_cell, &sfn,
nullptr,
148 srsran_pbch_mib_unpack(bch_payload.data(), &new_cell, &sfn);
150 sfn = (sfn + sfn_offset) % 1024;
153 "Phy: MIB Decoded. {} cell, Mode {}, PCI {}, PRB {}, Ports {}, CFO {} KHz, SFN "
154 "{}, sfn_offset {}\n",
155 new_cell.mbms_dedicated ?
"MBMS dedicated" :
"MBMS/Unicast mixed",
156 new_cell.frame_type != 0u ?
"TDD" :
"FDD", new_cell.id,
157 new_cell.nof_prb, new_cell.nof_ports,
cfo / 1000, sfn, sfn_offset);
159 if (!srsran_cell_isvalid(&new_cell)) {
160 spdlog::error(
"SYNC: Detected invalid cell.\n");
168 spdlog::error(
"Phy: failed to set cell.\n");
171 if (srsran_ue_mib_set_cell(&
_mib,
cell()) != 0) {
172 spdlog::error(
"Phy: Error setting UE MIB cell");
179 spdlog::error(
"Phy: failed to receive MIB\n");
srsran_cell_t cell()
Get the current cell (with params adjusted for MBSFN)
srsran_ue_cellsearch_t _cell_search
bool init()
Initialize the underlying components.
float cfo()
Get the current CFO value.
srsran_ue_mib_sync_t _mib_sync