добавил запись настроек BucLnb
This commit is contained in:
parent
cb9d412c8e
commit
857a01528b
32
src/main.cpp
32
src/main.cpp
@ -217,8 +217,6 @@ public:
|
||||
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||
}));
|
||||
|
||||
|
||||
|
||||
s.resources.emplace_back(std::make_unique<http::resource::GenericResource>("/api/set/qos", [this](const auto& req, auto& rep) {
|
||||
if (req.method != "POST") {
|
||||
http::server::stockReply(http::server::bad_request, rep);
|
||||
@ -236,7 +234,7 @@ public:
|
||||
|
||||
api->setQosSettings(pt);
|
||||
|
||||
std::string result = R"({"settings":)";
|
||||
std::string result = R"({""status":"ok",settings":)";
|
||||
result += api->loadSettings();
|
||||
result += "}";
|
||||
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||
@ -247,6 +245,34 @@ public:
|
||||
}
|
||||
}));
|
||||
|
||||
s.resources.emplace_back(std::make_unique<http::resource::GenericResource>("/api/set/bucLnb", [this](const auto& req, auto& rep) {
|
||||
if (req.method != "POST") {
|
||||
http::server::stockReply(http::server::bad_request, rep);
|
||||
}
|
||||
|
||||
rep.status = http::server::ok;
|
||||
rep.headers.clear();
|
||||
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
|
||||
|
||||
try {
|
||||
std::stringstream ss;
|
||||
ss.str(std::string(req.payload.begin(), req.payload.end()));
|
||||
boost::property_tree::ptree pt;
|
||||
read_json(ss, pt);
|
||||
|
||||
api->setBucLnbSettings(pt);
|
||||
|
||||
std::string result = R"({"status":"ok","settings":)";
|
||||
result += api->loadSettings();
|
||||
result += "}";
|
||||
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||
} catch (std::exception& e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "WebHandle(/api/set/bucLnb): Can't set settings: " << e.what();
|
||||
const std::string result = R"({"status":"error"})";
|
||||
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||
}
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
~ServerResources() = default;
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
#include "../dependencies/control_system/common/protocol_commands.h"
|
||||
|
||||
typedef boost::property_tree::ptree::path_type json_path;
|
||||
|
||||
/**
|
||||
* Этот демон нужен для того, чтобы получать статистику из API, а так же корректно сохранять настройки
|
||||
@ -205,6 +206,22 @@ public:
|
||||
json = this->qosClassesJson;
|
||||
}
|
||||
|
||||
void setStrringsRxTx(bool readback = true) {}
|
||||
void setStrringsCinc(bool readback = true) {}
|
||||
|
||||
void setStrringsBucLnb(const buc_lnb_settings& bucLnb, bool readback = true) {
|
||||
std::lock_guard lock(this->cpApiMutex);
|
||||
buc_lnb_settings tmp = bucLnb;
|
||||
CP_SetBUC_LNB_settings(this->sid, tmp);
|
||||
if (readback) {
|
||||
CP_GetBUC_LNB_settings(this->sid, tmp);
|
||||
{
|
||||
std::lock_guard lock2{this->settingsMutex};
|
||||
this->bucLnbSettings = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setQosSettings(bool enabled, const std::string& str, bool readback = true) {
|
||||
std::lock_guard lock(this->cpApiMutex);
|
||||
CP_SetQoSSettings(this->sid, str, enabled);
|
||||
@ -473,7 +490,43 @@ std::string api_driver::ApiDriver::loadSettings() const {
|
||||
return result.str();
|
||||
}
|
||||
|
||||
api_driver::ApiDriver::~ApiDriver() = default;
|
||||
void api_driver::ApiDriver::setRxTxSettings(boost::property_tree::ptree &pt) {
|
||||
}
|
||||
|
||||
void api_driver::ApiDriver::setCincSettings(boost::property_tree::ptree &pt) {
|
||||
}
|
||||
|
||||
void api_driver::ApiDriver::setBucLnbSettings(boost::property_tree::ptree &pt) {
|
||||
buc_lnb_settings s{};
|
||||
|
||||
auto tmp = pt.get<int>(json_path("lnb.powering", '/'));
|
||||
switch (tmp) {
|
||||
case 13: s.lnb = voltage_lnb::_13V; break;
|
||||
case 18: s.lnb = voltage_lnb::_18V; break;
|
||||
case 24: s.lnb = voltage_lnb::_24V; break;
|
||||
case 0:
|
||||
default:
|
||||
s.lnb = voltage_lnb::DISABLE;
|
||||
}
|
||||
s.is_ref_10MHz_lnb = pt.get<bool>(json_path("lnb.refClk10M", '/'));
|
||||
|
||||
tmp = pt.get<int>(json_path("buc.powering", '/'));
|
||||
switch (tmp) {
|
||||
case 24: s.buc = voltage_buc::_24V; break;
|
||||
case 48: s.buc = voltage_buc::_48V; break;
|
||||
case 0:
|
||||
default:
|
||||
s.lnb = voltage_lnb::DISABLE;
|
||||
}
|
||||
// { "lnb": {"powering": 0} }
|
||||
|
||||
s.is_ref_10MHz_buc = pt.get<bool>(json_path("buc.refClk10M", '/'));
|
||||
|
||||
s.is_ref_10MHz_output = pt.get<bool>(json_path("serviceSettings.refClk10M", '/'));
|
||||
s.is_save_current_state = pt.get<bool>(json_path("serviceSettings.autoStart", '/'));
|
||||
|
||||
this->daemon->setStrringsBucLnb(s);
|
||||
}
|
||||
|
||||
void api_driver::ApiDriver::setQosSettings(boost::property_tree::ptree &pt) {
|
||||
bool enabled = pt.get<bool>("en");
|
||||
@ -490,3 +543,5 @@ bool api_driver::ApiDriver::getIsCinC() const {
|
||||
daemon->getSettings(&s, nullptr, nullptr, nullptr, nullptr);
|
||||
return s.is_cinc;
|
||||
}
|
||||
|
||||
api_driver::ApiDriver::~ApiDriver() = default;
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
|
||||
namespace api_driver {
|
||||
|
||||
constexpr int CACHE_STATISTICS_UPDATE_MS = 500;
|
||||
constexpr int CACHE_SETTINGS_UPDATE_MS = 5000;
|
||||
constexpr int CACHE_QOS_UPDATE_MS = 5000;
|
||||
@ -40,10 +39,28 @@ namespace api_driver {
|
||||
|
||||
std::string loadSettings() const;
|
||||
|
||||
~ApiDriver();
|
||||
/**
|
||||
* Установить настройки RX/TX, readback можно получить используя loadTerminalState
|
||||
*/
|
||||
void setRxTxSettings(boost::property_tree::ptree &pt);
|
||||
|
||||
/**
|
||||
* Установить настройки CinC, readback можно получить используя loadTerminalState.
|
||||
*/
|
||||
void setCincSettings(boost::property_tree::ptree &pt);
|
||||
|
||||
/**
|
||||
* Установить настройки BUC и LNB, readback можно получить используя loadTerminalState.
|
||||
*/
|
||||
void setBucLnbSettings(boost::property_tree::ptree &pt);
|
||||
|
||||
/**
|
||||
* Установить настройки QoS, readback можно получить используя loadTerminalState.
|
||||
*/
|
||||
void setQosSettings(boost::property_tree::ptree &pt);
|
||||
|
||||
~ApiDriver();
|
||||
|
||||
private:
|
||||
TSID sid{0};
|
||||
unsigned int access{0};
|
||||
|
@ -863,18 +863,21 @@
|
||||
// TODO сделать всплывающее окно с подтверждением того, что настройки действительно нужно применить
|
||||
let query = {
|
||||
"buc.refClk10M": this.param.buc.refClk10M,
|
||||
"buc.powering": this.param.buc.powering,
|
||||
"buc.powering": parseInt(this.param.buc.powering),
|
||||
"lnb.refClk10M": this.param.lnb.refClk10M,
|
||||
"lnb.powering": this.param.lnb.powering,
|
||||
"lnb.powering": parseInt(this.param.lnb.powering),
|
||||
"serviceSettings.refClk10M": this.param.serviceSettings.refClk10M,
|
||||
"serviceSettings.autoStart": this.param.serviceSettings.autoStart
|
||||
}
|
||||
fetch('/api/set/bucLnb', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(query)
|
||||
}).then(() => {
|
||||
}).then(async (resp) => {
|
||||
this.submitStatus.bucLnb = false
|
||||
this.performUpdateSettings()
|
||||
this.updateBucLnbSettings(await resp.json())
|
||||
})
|
||||
},
|
||||
|
||||
@ -926,10 +929,13 @@
|
||||
console.log(query)
|
||||
fetch('/api/set/qos', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(query)
|
||||
}).then(async (response) => {
|
||||
}).then(async (resp) => {
|
||||
this.submitStatus.qos = false
|
||||
this.updateQosSettings(await response.json())
|
||||
this.updateQosSettings(await resp.json())
|
||||
})
|
||||
},
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user