OBECA Receive Process
RestHandler.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 #include <string>
22 #include <vector>
23 #include <map>
24 #include <memory>
25 #include <libconfig.h++>
26 #include "srslte/srslte.h"
27 #include "srslte/upper/rlc.h"
28 #include "srslte/asn1/rrc_asn1.h"
29 
30 #include "LimeSdrReader.h"
31 #include "Phy.h"
32 
33 #include "cpprest/json.h"
34 #include "cpprest/http_listener.h"
35 #include "cpprest/uri.h"
36 #include "cpprest/asyncrt_utils.h"
37 #include "cpprest/filestream.h"
38 #include "cpprest/containerstream.h"
39 #include "cpprest/producerconsumerstream.h"
40 
41 const int CINR_RAVG_CNT = 100;
42 typedef enum { searching, syncing, processing } state_t;
43 
47 class RestHandler {
48  public:
52  typedef std::function<void(const std::string& antenna, unsigned fcen, double gain, unsigned sample_rate, unsigned bandwidth)> set_params_t;
53 
63  RestHandler(const libconfig::Config& cfg, const std::string& url, state_t& state,
68  virtual ~RestHandler();
69 
73  class ChannelInfo {
74  public:
75  void SetData( std::vector<uint8_t> data) {
76  std::lock_guard<std::mutex> lock(_data_mutex);
77  _data = data;
78  };
79  std::vector<uint8_t> GetData() {
80  std::lock_guard<std::mutex> lock(_data_mutex);
81  return _data;
82  };
83  bool present = false;
84  int mcs = 0;
85  double ber;
86  unsigned total = 1;
87  unsigned errors = 0;
88  private:
89  std::vector<uint8_t> _data = {};
90  std::mutex _data_mutex;
91  };
92 
96  std::vector<uint8_t> _ce_values = {};
97 
102 
107 
111  std::map<uint32_t, ChannelInfo> _mch;
112 
116  float cinr_db() { return (std::accumulate(_cinr_db.begin(), _cinr_db.end(), 0) / (_cinr_db.size() * 1.0)); };
117  void add_cinr_value( float cinr);
118 
119  private:
120  std::vector<float> _cinr_db;
121  void get(web::http::http_request message);
122  void put(web::http::http_request message);
123 
124  const libconfig::Config& _cfg;
125 
126  std::unique_ptr<web::http::experimental::listener::http_listener> _listener;
127 
128  state_t& _state;
129  LimeSdrReader& _lime;
130  Phy& _phy;
131 
132  set_params_t _set_params;
133 
134  bool _require_bearer_token = false;
135  std::string _api_key;
136 };
137 
RestHandler::_pdsch
ChannelInfo _pdsch
RX info for PDSCH.
Definition: RestHandler.h:101
Phy
The PHY component.
Definition: Phy.h:43
RestHandler::ChannelInfo
RX Info pertaining to an SCH (MCCH/MCH or PDSCH)
Definition: RestHandler.h:73
RestHandler::~RestHandler
virtual ~RestHandler()
Default destructor.
set_params
void set_params(const std::string &ant, unsigned fc, double g, unsigned sr, unsigned bw)
Set new SDR parameters and initialize resynchronisation.
Definition: main.cpp:191
RestHandler::set_params_t
std::function< void(const std::string &antenna, unsigned fcen, double gain, unsigned sample_rate, unsigned bandwidth)> set_params_t
Definition of the callback for setting new reception parameters.
Definition: RestHandler.h:52
RestHandler::_mch
std::map< uint32_t, ChannelInfo > _mch
RX info for MCHs.
Definition: RestHandler.h:111
RestHandler::_ce_values
std::vector< uint8_t > _ce_values
Time domain subcarrier CE values.
Definition: RestHandler.h:96
RestHandler
The RESTful API handler.
Definition: RestHandler.h:47
RestHandler::_mcch
ChannelInfo _mcch
RX info for MCCH.
Definition: RestHandler.h:106
RestHandler::RestHandler
RestHandler(const libconfig::Config &cfg, const std::string &url, state_t &state, LimeSdrReader &lime, Phy &phy, set_params_t set_params)
Default constructor.
Definition: RestHandler.cpp:35
RestHandler::cinr_db
float cinr_db()
Current CINR value.
Definition: RestHandler.h:116
LimeSdrReader
Interface to LimeSDR via LimeSuite.
Definition: LimeSdrReader.h:36