5G-MAG Reference Tools - MBMS Modem
RestHandler.h
Go to the documentation of this file.
1 // 5G-MAG Reference Tools
2 // MBMS Modem 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 
27 #include "SdrReader.h"
28 #include "Phy.h"
29 
30 #include "cpprest/json.h"
31 #include "cpprest/http_listener.h"
32 #include "cpprest/uri.h"
33 #include "cpprest/asyncrt_utils.h"
34 #include "cpprest/filestream.h"
35 #include "cpprest/containerstream.h"
36 #include "cpprest/producerconsumerstream.h"
37 
38 const int CINR_RAVG_CNT = 100;
39 typedef enum { searching, syncing, processing } state_t;
40 
44 class RestHandler {
45  public:
49  typedef std::function<void(const std::string& antenna, unsigned fcen, double gain, unsigned sample_rate, unsigned bandwidth)> set_params_t;
50 
60  RestHandler(const libconfig::Config& cfg, const std::string& url, state_t& state,
61  SdrReader& sdr, Phy& phy, set_params_t set_params);
65  virtual ~RestHandler();
66 
70  class ChannelInfo {
71  public:
72  void SetData( std::vector<uint8_t> data) {
73  std::lock_guard<std::mutex> lock(_data_mutex);
74  _data = data;
75  };
76  std::vector<uint8_t> GetData() {
77  std::lock_guard<std::mutex> lock(_data_mutex);
78  return _data;
79  };
80  bool present = false;
81  int mcs = 0;
82  double ber;
83  unsigned total = 1;
84  unsigned errors = 0;
85  private:
86  std::vector<uint8_t> _data = {};
87  std::mutex _data_mutex;
88  };
89 
93  std::vector<uint8_t> _ce_values = {};
94 
99 
104 
108  std::map<uint32_t, ChannelInfo> _mch;
109 
113  float cinr_db() { return _cinr_db.size() ? (std::accumulate(_cinr_db.begin(), _cinr_db.end(), 0) / (_cinr_db.size() * 1.0)) : 0.0; };
114  void add_cinr_value( float cinr);
115 
116  private:
117  std::vector<float> _cinr_db;
118  void get(web::http::http_request message);
119  void put(web::http::http_request message);
120 
121  const libconfig::Config& _cfg;
122 
123  std::unique_ptr<web::http::experimental::listener::http_listener> _listener;
124 
128 
130 
131  bool _require_bearer_token = false;
132  std::string _api_key;
133 };
134 
state_t
Definition: RestHandler.h:39
@ syncing
Definition: RestHandler.h:39
@ searching
Definition: RestHandler.h:39
@ processing
Definition: RestHandler.h:39
const int CINR_RAVG_CNT
Definition: RestHandler.h:38
The PHY component.
Definition: Phy.h:42
RX Info pertaining to an SCH (MCCH/MCH or PDSCH)
Definition: RestHandler.h:70
std::vector< uint8_t > _data
Definition: RestHandler.h:86
std::vector< uint8_t > GetData()
Definition: RestHandler.h:76
void SetData(std::vector< uint8_t > data)
Definition: RestHandler.h:72
The RESTful API handler.
Definition: RestHandler.h:44
SdrReader & _sdr
Definition: RestHandler.h:126
std::unique_ptr< web::http::experimental::listener::http_listener > _listener
Definition: RestHandler.h:123
float cinr_db()
Current CINR value.
Definition: RestHandler.h:113
std::vector< uint8_t > _ce_values
Time domain subcarrier CE values.
Definition: RestHandler.h:93
void put(web::http::http_request message)
ChannelInfo _mcch
RX info for MCCH.
Definition: RestHandler.h:103
std::string _api_key
Definition: RestHandler.h:132
std::vector< float > _cinr_db
Definition: RestHandler.h:117
void add_cinr_value(float cinr)
std::map< uint32_t, ChannelInfo > _mch
RX info for MCHs.
Definition: RestHandler.h:108
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:49
const libconfig::Config & _cfg
Definition: RestHandler.h:121
RestHandler(const libconfig::Config &cfg, const std::string &url, state_t &state, SdrReader &sdr, Phy &phy, set_params_t set_params)
Default constructor.
Definition: RestHandler.cpp:35
void get(web::http::http_request message)
Definition: RestHandler.cpp:77
ChannelInfo _pdsch
RX info for PDSCH.
Definition: RestHandler.h:98
virtual ~RestHandler()
Default destructor.
state_t & _state
Definition: RestHandler.h:125
bool _require_bearer_token
Definition: RestHandler.h:131
set_params_t _set_params
Definition: RestHandler.h:129
Interface to the SDR stick.
Definition: SdrReader.h:37
static Config cfg
Global configuration object.
Definition: main.cpp:165
static std::string antenna
Antenna input to be used.
Definition: main.cpp:172
static unsigned sample_rate
Sample rate of the SDR.
Definition: main.cpp:167
static uint32_t bandwidth
Low pass filter bandwidth for the SDR.
Definition: main.cpp:170
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:198
static double gain
Overall system gain for the SDR.
Definition: main.cpp:171