OBECA Receive Process
Classes | Public Types | Public Member Functions | Public Attributes | List of all members
Phy Class Reference

The PHY component. More...

#include <Phy.h>

Classes

struct  mch_info_t
 
struct  mtch_info_t
 

Public Types

enum  SubcarrierSpacing { df_15kHz, df_7kHz5, df_1kHz25 }
 
typedef std::function< int(cf_t *data, uint32_t nsamples, srslte_timestamp_t *rx_time)> get_samples_t
 Definition of the callback function used to fetch samples from the SDR.
 

Public Member Functions

 Phy (const libconfig::Config &cfg, get_samples_t cb, uint8_t cs_nof_prb, int8_t override_nof_prb)
 Default constructor. More...
 
virtual ~Phy ()
 Default destructor.
 
bool init ()
 Initialize the underlying components.
 
bool cell_search ()
 Search for a cell. More...
 
bool synchronize_subframe ()
 Synchronizes PSS/SSS and tries to deocode the MIB. More...
 
bool get_next_frame (cf_t **buffer, uint32_t size)
 Get the sample data for the next subframe.
 
srslte_cell_t cell ()
 Get the current cell (with params adjusted for MBSFN)
 
unsigned nr_prb ()
 Get the current number of PRB.
 
uint32_t tti ()
 Get the current subframe TTI.
 
float cfo ()
 Get the current CFO value.
 
void set_cfo_from_channel_estimation (float cfo)
 Set the CFO value from channel estimation.
 
void set_mch_scheduling_info (const srslte::sib13_t &sib13)
 Set the values received in SIB13.
 
void set_mbsfn_config (const srslte::mcch_msg_t &mcch)
 Set MBSFN configuration values.
 
void reset ()
 Clear configuration values.
 
bool mcch_configured ()
 Return true if MCCH has been configured.
 
uint8_t mbsfn_area_id ()
 Returns the current MBSFN area ID.
 
srslte_mbsfn_cfg_t mbsfn_config_for_tti (uint32_t tti, unsigned &area)
 Returns the MBSFN configuration (MCS, etc) for the subframe with the passed TTI.
 
void set_decode_mcch (bool d)
 Enable MCCH decoding.
 
uint8_t nof_mbsfn_prb ()
 Get number of PRB in MBSFN/PMCH.
 
void set_cell ()
 
const std::vector< mch_info_t > & mch_info ()
 
void set_dest_for_lcid (int lcid, std::string dest)
 
SubcarrierSpacing mbsfn_subcarrier_spacing ()
 
float mbsfn_subcarrier_spacing_khz ()
 
srslte::mcch_msg_t & mcch ()
 

Public Attributes

int _mcs = 0
 
get_samples_t _sample_cb
 

Detailed Description

The PHY component.

Handles synchronisation and is the central hub for lower level processing

Definition at line 43 of file Phy.h.

Constructor & Destructor Documentation

◆ Phy()

Phy::Phy ( const libconfig::Config &  cfg,
get_samples_t  cb,
uint8_t  cs_nof_prb,
int8_t  override_nof_prb 
)

Default constructor.

Parameters
cfgConfig singleton reference
cbSample recv callback
cs_nof_prbNr of PRBs to use during cell search
override_nof_prbIf set, overrides the nof PRB received in the MIB

Definition at line 40 of file Phy.cpp.

42  : _cfg(cfg),
43  _sample_cb(std::move(std::move(cb))),
44  _cs_nof_prb(cs_nof_prb),
45  _override_nof_prb(override_nof_prb) {
46  _buffer_max_samples = kMaxBufferSamples;
47  _mib_buffer[0] = static_cast<cf_t*>(malloc(_buffer_max_samples * sizeof(cf_t))); // NOLINT
48 }

Member Function Documentation

◆ cell_search()

auto Phy::cell_search ( )

Search for a cell.

Returns true if a cell has been found and the MIB could be decoded, false otherwise.

Definition at line 82 of file Phy.cpp.

82  {
83  std::array<srslte_ue_cellsearch_result_t, kMaxCellsToDiscover> found_cells = {0};
84 
85  uint32_t max_peak_cell = 0;
86  int ret = srslte_ue_cellsearch_scan(&_cell_search, found_cells.data(), &max_peak_cell);
87  if (ret < 0) {
88  spdlog::error("Phy: Error decoding MIB: Error searching PSS\n");
89  return false;
90  }
91  if (ret == 0) {
92  spdlog::error("Phy: Could not find any cell in this frequency\n");
93  return false;
94  }
95 
96  srslte_cell_t new_cell = {};
97  new_cell.id = found_cells.at(max_peak_cell).cell_id;
98  new_cell.cp = found_cells.at(max_peak_cell).cp;
99  new_cell.frame_type = found_cells.at(max_peak_cell).frame_type;
100  new_cell.mbms_dedicated = true;
101  float cfo = found_cells.at(max_peak_cell).cfo;
102 
103  spdlog::info("Phy: PSS/SSS detected: Mode {}, PCI {}, CFO {} KHz, CP {}",
104  new_cell.frame_type != 0U ? "TDD" : "FDD", new_cell.id,
105  cfo / 1000, srslte_cp_string(new_cell.cp));
106 
107  if (srslte_ue_mib_sync_set_cell_prb(&_mib_sync, new_cell, _cs_nof_prb) != 0) {
108  spdlog::error("Phy: Error setting UE MIB sync cell");
109  return false;
110  }
111 
112  srslte_ue_sync_reset(&_mib_sync.ue_sync);
113 
114  std::array<uint8_t, SRSLTE_BCH_PAYLOAD_LEN> bch_payload = {};
115  /* Find and decode MIB */
116  int sfn_offset = 0;
117  ret = srslte_ue_mib_sync_decode_prb(&_mib_sync, 40, bch_payload.data(), &new_cell.nof_ports, &sfn_offset, _cs_nof_prb);
118  if (ret == 1) {
119  uint32_t sfn = 0;
120  srslte_pbch_mib_mbms_unpack(bch_payload.data(), &new_cell, &sfn, nullptr,
121  _override_nof_prb);
122 
123  spdlog::info(
124  "Phy: MIB Decoded. Mode {}, PCI {}, PRB {}, Ports {}, CFO {} KHz, SFN "
125  "{}\n",
126  new_cell.frame_type != 0u ? "TDD" : "FDD", new_cell.id,
127  new_cell.nof_prb, new_cell.nof_ports, cfo / 1000, sfn);
128 
129  if (!srslte_cell_isvalid(&new_cell)) {
130  spdlog::error("SYNC: Detected invalid cell.\n");
131  return false;
132  }
133 
134  _cell = new_cell;
135  _cell.mbsfn_prb = _cell.nof_prb;
136 
137  if (srslte_ue_sync_set_cell(&_ue_sync, cell()) != 0) {
138  spdlog::error("Phy: failed to set cell.\n");
139  return false;
140  }
141  if (srslte_ue_mib_set_cell(&_mib, cell()) != 0) {
142  spdlog::error("Phy: Error setting UE MIB cell");
143  return false;
144  }
145 
146  return true;
147  }
148 
149  spdlog::error("Phy: failed to receive MIB\n");
150  return false;
151 }

◆ synchronize_subframe()

auto Phy::synchronize_subframe ( )

Synchronizes PSS/SSS and tries to deocode the MIB.

Returns true on success, false otherwise.

Definition at line 55 of file Phy.cpp.

55  {
56 
57  int ret = srslte_ue_sync_zerocopy(&_ue_sync, _mib_buffer, _buffer_max_samples); // NOLINT
58  if (ret < 0) {
59  spdlog::error("SYNC: Error calling ue_sync_get_buffer.\n");
60  return false;
61  }
62 
63  if (ret == 1) {
64  std::array<uint8_t, SRSLTE_BCH_PAYLOAD_LEN> bch_payload = {};
65  if (srslte_ue_sync_get_sfidx(&_ue_sync) == 0) {
66  int sfn_offset = 0;
67  int n =
68  srslte_ue_mib_decode(&_mib, bch_payload.data(), nullptr, &sfn_offset);
69  if (n == 1) {
70  uint32_t sfn = 0;
71  srslte_pbch_mib_mbms_unpack(bch_payload.data(), &_cell, &sfn, nullptr,
72  _override_nof_prb);
73  sfn = (sfn + sfn_offset * kSfnOffset) % kMaxSfn;
74  _tti = sfn * kSubframesPerFrame;
75  return true;
76  }
77  }
78  }
79  return false;
80 }

The documentation for this class was generated from the following files:
Phy::cfo
float cfo()
Get the current CFO value.
Definition: Phy.h:109
Phy::cell
srslte_cell_t cell()
Get the current cell (with params adjusted for MBSFN)
Definition: Phy.h:92