OBECA Receive Process
Phy.h
1 // OBECA - Open Broadcast Edge Cache Appliance
2 // Receive Process
3 //
4 // Copyright (C) 2021 Klaus Kühnhammer (Österreichische Rundfunksender GmbH & Co KG)
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Affero General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Affero General Public License for more details.
15 //
16 // You should have received a copy of the GNU Affero General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 //
19 
20 #pragma once
21 
22 #include <lime/LimeSuite.h>
23 #include <functional>
24 #include <cstdint>
25 #include <string>
26 #include <map>
27 #include <vector>
28 #include <thread>
29 #include <libconfig.h++>
30 
31 #include "srslte/srslte.h"
32 #include "srslte/interfaces/rrc_interface_types.h"
33 #include "srslte/common/gen_mch_tables.h"
34 #include "srslte/phy/common/phy_common.h"
35 
36 constexpr unsigned int MAX_PRB = 100;
37 
43 class Phy {
44  public:
48  typedef std::function<int(cf_t* data, uint32_t nsamples, srslte_timestamp_t* rx_time)> get_samples_t;
49 
58  Phy(const libconfig::Config& cfg, get_samples_t cb, uint8_t cs_nof_prb, int8_t override_nof_prb);
59 
63  virtual ~Phy();
64 
68  bool init();
69 
75  bool cell_search();
76 
82  bool synchronize_subframe();
83 
87  bool get_next_frame(cf_t** buffer, uint32_t size);
88 
92  srslte_cell_t cell() {
93  return _cell;
94  }
95 
99  unsigned nr_prb() { return _cell.nof_prb; }
100 
104  uint32_t tti() { return _tti; }
105 
109  float cfo() { return srslte_ue_sync_get_cfo(&_ue_sync);}
110 
114  void set_cfo_from_channel_estimation(float cfo) { srslte_ue_sync_set_cfo_ref(&_ue_sync, cfo); }
115 
119  void set_mch_scheduling_info(const srslte::sib13_t& sib13);
120 
124  void set_mbsfn_config(const srslte::mcch_msg_t& mcch);
125 
129  void reset() { _mcch_configured = _mch_configured = false; }
130 
134  bool mcch_configured() { return _mcch_configured; }
135 
139  uint8_t mbsfn_area_id() { return _sib13.mbsfn_area_info_list[0].mbsfn_area_id; }
140 
144  srslte_mbsfn_cfg_t mbsfn_config_for_tti(uint32_t tti, unsigned& area);
145 
149  void set_decode_mcch(bool d) { _decode_mcch = d; }
150 
154  uint8_t nof_mbsfn_prb() { return _cell.mbsfn_prb; }
155 
156  void set_cell();
157 
158  typedef struct {
159  std::string tmgi;
160  std::string dest;
161  int lcid;
162  } mtch_info_t;
163  typedef struct {
164  int mcs;
165  std::vector< mtch_info_t > mtchs;
166  } mch_info_t;
167 
168  const std::vector< mch_info_t>& mch_info() { return _mch_info; }
169 
170  void set_dest_for_lcid(int lcid, std::string dest) { _dests[_mcs][lcid] = dest; }
171 
172  enum class SubcarrierSpacing {
173  df_15kHz,
174  df_7kHz5,
175  df_1kHz25
176  };
177 
178  SubcarrierSpacing mbsfn_subcarrier_spacing() {
179  switch (_sib13.mbsfn_area_info_list[0].subcarrier_spacing) {
180  case srslte::mbsfn_area_info_t::subcarrier_spacing_t::khz_1dot25: return SubcarrierSpacing::df_1kHz25;
181  case srslte::mbsfn_area_info_t::subcarrier_spacing_t::khz_7dot5: return SubcarrierSpacing::df_7kHz5;
182  default: return SubcarrierSpacing::df_15kHz;
183  }
184  }
185 
186  float mbsfn_subcarrier_spacing_khz() {
187  switch (_sib13.mbsfn_area_info_list[0].subcarrier_spacing) {
188  case srslte::mbsfn_area_info_t::subcarrier_spacing_t::khz_1dot25: return 1.25;
189  case srslte::mbsfn_area_info_t::subcarrier_spacing_t::khz_7dot5: return 7.5;
190  default: return 15;
191  }
192  }
193 
194  srslte::mcch_msg_t& mcch() { return _mcch; }
195 
196  int _mcs = 0;
197  get_samples_t _sample_cb;
198 
199  private:
200  const libconfig::Config& _cfg;
201  srslte_ue_sync_t _ue_sync = {};
202  srslte_ue_cellsearch_t _cell_search = {};
203  srslte_ue_mib_sync_t _mib_sync = {};
204  srslte_ue_mib_t _mib = {};
205  srslte_cell_t _cell = {};
206 
207  bool _decode_mcch = false;
208 
209  cf_t* _mib_buffer[SRSLTE_MAX_CHANNELS] = {};
210  uint32_t _buffer_max_samples = 0;
211  uint32_t _tti = 0;
212 
213  uint8_t _mcch_table[10] = {};
214  bool _mcch_configured = false;
215  srslte::sib13_t _sib13 = {};
216  srslte::mcch_msg_t _mcch = {};
217 
218  bool _mch_configured = false;
219 
220  uint8_t _cs_nof_prb;
221 
222  std::vector< mch_info_t > _mch_info;
223 
224  std::map< int, std::map< int, std::string >> _dests;
225 
226  int8_t _override_nof_prb;
227 };
Phy::set_mch_scheduling_info
void set_mch_scheduling_info(const srslte::sib13_t &sib13)
Set the values received in SIB13.
Definition: Phy.cpp:194
Phy::~Phy
virtual ~Phy()
Default destructor.
Definition: Phy.cpp:50
Phy::nr_prb
unsigned nr_prb()
Get the current number of PRB.
Definition: Phy.h:99
Phy::mbsfn_config_for_tti
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.
Definition: Phy.cpp:256
Phy
The PHY component.
Definition: Phy.h:43
Phy::reset
void reset()
Clear configuration values.
Definition: Phy.h:129
Phy::nof_mbsfn_prb
uint8_t nof_mbsfn_prb()
Get number of PRB in MBSFN/PMCH.
Definition: Phy.h:154
Phy::mbsfn_area_id
uint8_t mbsfn_area_id()
Returns the current MBSFN area ID.
Definition: Phy.h:139
Phy::mtch_info_t
Definition: Phy.h:158
Phy::mcch_configured
bool mcch_configured()
Return true if MCCH has been configured.
Definition: Phy.h:134
Phy::cfo
float cfo()
Get the current CFO value.
Definition: Phy.h:109
Phy::get_samples_t
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.
Definition: Phy.h:48
Phy::get_next_frame
bool get_next_frame(cf_t **buffer, uint32_t size)
Get the sample data for the next subframe.
Definition: Phy.cpp:190
Phy::init
bool init()
Initialize the underlying components.
Definition: Phy.cpp:162
Phy::set_cfo_from_channel_estimation
void set_cfo_from_channel_estimation(float cfo)
Set the CFO value from channel estimation.
Definition: Phy.h:114
Phy::set_mbsfn_config
void set_mbsfn_config(const srslte::mcch_msg_t &mcch)
Set MBSFN configuration values.
Definition: Phy.cpp:230
Phy::synchronize_subframe
bool synchronize_subframe()
Synchronizes PSS/SSS and tries to deocode the MIB.
Definition: Phy.cpp:55
Phy::cell
srslte_cell_t cell()
Get the current cell (with params adjusted for MBSFN)
Definition: Phy.h:92
Phy::set_decode_mcch
void set_decode_mcch(bool d)
Enable MCCH decoding.
Definition: Phy.h:149
Phy::cell_search
bool cell_search()
Search for a cell.
Definition: Phy.cpp:82
Phy::tti
uint32_t tti()
Get the current subframe TTI.
Definition: Phy.h:104
Phy::mch_info_t
Definition: Phy.h:163
Phy::Phy
Phy(const libconfig::Config &cfg, get_samples_t cb, uint8_t cs_nof_prb, int8_t override_nof_prb)
Default constructor.
Definition: Phy.cpp:40