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

The RESTful API handler. More...

#include <RestHandler.h>

Collaboration diagram for RestHandler:
Collaboration graph
[legend]

Classes

class  ChannelInfo
 RX Info pertaining to an SCH (MCCH/MCH or PDSCH) More...
 

Public Types

typedef 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.
 

Public Member Functions

 RestHandler (const libconfig::Config &cfg, const std::string &url, state_t &state, LimeSdrReader &lime, Phy &phy, set_params_t set_params)
 Default constructor. More...
 
virtual ~RestHandler ()
 Default destructor.
 
float cinr_db ()
 Current CINR value.
 
void add_cinr_value (float cinr)
 

Public Attributes

std::vector< uint8_t > _ce_values = {}
 Time domain subcarrier CE values.
 
ChannelInfo _pdsch
 RX info for PDSCH.
 
ChannelInfo _mcch
 RX info for MCCH.
 
std::map< uint32_t, ChannelInfo > _mch
 RX info for MCHs.
 

Detailed Description

The RESTful API handler.

Supports GET and PUT verbs for SDR parameters, and GET for reception info

Definition at line 47 of file RestHandler.h.

Constructor & Destructor Documentation

◆ 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.

Parameters
cfgConfig singleton reference
urlURL to open the server on
stateReference to the main loop sate
limeReference to the LimeSDR reader
set_paramsSet parameters callback

Definition at line 35 of file RestHandler.cpp.

38  : _cfg(cfg),
39  _state(state),
40  _lime(lime),
41  _phy(phy),
42  _set_params(std::move(set_params)) {
43 
44  http_listener_config server_config;
45  if (url.rfind("https", 0) == 0) {
46  server_config.set_ssl_context_callback(
47  [&](boost::asio::ssl::context& ctx) {
48  std::string cert_file = "/usr/share/obeca/cert.pem";
49  cfg.lookupValue("restful_api.cert", cert_file);
50 
51  std::string key_file = "/usr/share/obeca/key.pem";
52  cfg.lookupValue("restful_api.key", key_file);
53 
54  ctx.set_options(boost::asio::ssl::context::default_workarounds);
55  ctx.use_certificate_chain_file(cert_file);
56  ctx.use_private_key_file(key_file, boost::asio::ssl::context::pem);
57  });
58  }
59 
60  cfg.lookupValue("restful_api.api_key.enabled", _require_bearer_token);
61  if (_require_bearer_token) {
62  _api_key = "106cd60-76c8-4c37-944c-df21aa690c1e";
63  cfg.lookupValue("restful_api.api_key.key", _api_key);
64  }
65 
66  _listener = std::make_unique<http_listener>(
67  url, server_config);
68 
69  _listener->support(methods::GET, std::bind(&RestHandler::get, this, std::placeholders::_1)); // NOLINT
70  _listener->support(methods::PUT, std::bind(&RestHandler::put, this, std::placeholders::_1)); // NOLINT
71 
72  _listener->open().wait();
73 }

The documentation for this class was generated from the following files:
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