добавил изменение параметров dpdi (CinC)

This commit is contained in:
Vladislav Ostapov 2024-11-12 15:37:58 +03:00
parent 087da149f1
commit dc2d464f41
3 changed files with 214 additions and 4 deletions

View File

@ -267,6 +267,61 @@ public:
}
}));
s.resources.emplace_back(std::make_unique<http::auth::AuthRequiredResource>("/api/set/cinc", this->auth, http::auth::User::EDIT_SETTINGS, [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->setCincSettings(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/cinc): Can't set CinC settings: " << e.what();
const std::string result = R"({"status":"error"})";
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
}
}));
s.resources.emplace_back(std::make_unique<http::auth::AuthRequiredResource>("/api/set/rxtx", this->auth, http::auth::User::EDIT_SETTINGS, [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->setRxTxSettings(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/rxtx): Can't set RX/TX 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;

View File

@ -208,10 +208,24 @@ public:
json = this->qosClassesJson;
}
void setStrringsRxTx(bool readback = true) {}
void setStrringsCinc(bool readback = true) {}
void setSettingsRxTx(bool readback = true) {}
void setStrringsBucLnb(const buc_lnb_settings& bucLnb, bool readback = true) {
void setSettingsCinc(const DPDI_parmeters& s, bool readback = true) {
DPDI_parmeters tmp = s;
std::lock_guard lock(this->cpApiMutex);
CP_SetDmaDebug(sid, "begin_save_config", "");
CP_SetDpdiParams(sid, tmp);
if (readback) {
CP_GetDpdiParams(this->sid, &tmp);
{
std::lock_guard lock2{this->settingsMutex};
this->dpdiSettings = tmp;
}
}
CP_SetDmaDebug(sid, "save_config", "");
}
void setSettingsBucLnb(const buc_lnb_settings& bucLnb, bool readback = true) {
buc_lnb_settings tmp = bucLnb;
std::lock_guard lock(this->cpApiMutex);
CP_SetDmaDebug(sid, "begin_save_config", "");
@ -505,6 +519,32 @@ void api_driver::ApiDriver::setRxTxSettings(boost::property_tree::ptree &pt) {
}
void api_driver::ApiDriver::setCincSettings(boost::property_tree::ptree &pt) {
DPDI_parmeters s{};
//result << ",\n\"cinc.mode\":" << (dpdiSettings.is_delay_window ? "\"delay\"" : "\"positional\"");
auto tmp = pt.get<std::string>(json_path("cinc.mode", '/'));
if (tmp == "delay") { s.is_delay_window = true; }
else if (tmp == "positional") { s.is_delay_window = false; }
else {
throw std::runtime_error("Wrong CinC mode: " + tmp);
}
auto ctmp = translateCoordinates(pt.get<double>(json_path("cinc.position.station.latitude", '/')));
s.latitude_station_grad = std::get<0>(ctmp);
s.latitude_station_minute = std::get<1>(ctmp);
ctmp = translateCoordinates(pt.get<double>(json_path("cinc.position.station.longitude", '/')));
s.longitude_station_grad = std::get<0>(ctmp);
s.longitude_station_minute = std::get<1>(ctmp);
ctmp = translateCoordinates(pt.get<double>(json_path("cinc.position.satelliteLongitude", '/')));
s.longitude_sattelite_grad = std::get<0>(ctmp);
s.longitude_sattelite_minute = std::get<1>(ctmp);
s.max_delay = pt.get<int>(json_path("cinc.delayMax", '/'));
s.min_delay = pt.get<int>(json_path("cinc.delayMin", '/'));
this->daemon->setSettingsCinc(s);
}
void api_driver::ApiDriver::setBucLnbSettings(boost::property_tree::ptree &pt) {
@ -536,7 +576,7 @@ void api_driver::ApiDriver::setBucLnbSettings(boost::property_tree::ptree &pt) {
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);
this->daemon->setSettingsBucLnb(s);
}
void api_driver::ApiDriver::setQosSettings(boost::property_tree::ptree &pt) {

View File

@ -598,6 +598,55 @@
return modcods[modcod]
}
function toModcod(modulation, speed) {
switch (modulation.toLowerCase()) {
case 'qpsk':
switch (speed) {
case '1/4': return 1
case '1/3': return 2
case '2/5': return 3
case '1/2': return 4
case '3/5': return 5 // отключено
case '2/3': return 6
case '3/4': return 7
case '4/5': return 8
case '5/6': return 9
case '8/9': return 10
case '9/1': return 11
default: return 1 // минимальная скорость
}
case '8psk':
switch (speed) {
case '3/5': return 12 // отключено
case '2/3': return 13
case '3/4': return 14
case '5/6': return 15
case '8/9': return 16
case '9/10': return 17
default: return 12 // минимальная скорость
}
case '16apsk':
switch (speed) {
case '2/3': return 18
case '3/4': return 19
case '4/5': return 20
case '5/6': return 21
case '8/9': return 22
case '9/10': return 23
default: return 18 // минимальная скорость
}
case '32apsk':
switch (speed) {
case '3/4': return 24
case '4/5': return 25
case '5/6': return 26
case '8/9': return 27
case '9/10': return 28
default: return 24
}
}
}
function extractModulationAndSpeedFromModcod(modcod) {
switch (modcod) {
case 1: return { modulation: 'qpsk', speed: '1/4' }
@ -851,12 +900,78 @@
settingsSubmitRxTx() {
if (this.submitStatus.rxTx) { return }
// потом добавить: "dvbs2.isPilots": this.param.dvbs2.isPilots
let query = {
"general.isCinC": this.param.general.isCinC,
"general.txEn": this.param.general.txEn,
"general.modulatorMode": this.param.general.modulatorMode,
"general.autoStartTx": this.param.general.autoStartTx,
"general.isTestInputData": this.param.general.isTestInputData,
"tx.attenuation": this.param.tx.attenuation,
"tx.rolloff": this.param.tx.rolloff,
"tx.cymRate": this.param.tx.cymRate,
"tx.centerFreq": this.param.tx.centerFreq,
"dvbs2.isAcm": this.param.dvbs2.mode === 'acm',
"dvbs2.frameSizeNormal": this.param.dvbs2.frameSizeNormal,
"dvbs2.ccm_modcod": toModcod(this.param.dvbs2.ccm_modulation, this.param.dvbs2.ccm_speed),
"dvbs2.acm_minModcod": toModcod(this.param.dvbs2.acm_minModulation, this.param.dvbs2.acm_minSpeed),
"dvbs2.acm_maxModcod": toModcod(this.param.dvbs2.acm_maxModulation, this.param.dvbs2.acm_maxSpeed),
"dvbs2.snrReserve": this.param.dvbs2.snrReserve,
"dvbs2.servicePacketPeriod": this.param.dvbs2.servicePacketPeriod,
"acm.en": this.param.acm.en,
"acm.maxAttenuation": this.param.acm.maxAttenuation,
"acm.minAttenuation": this.param.acm.minAttenuation,
"acm.requiredSnr": this.param.acm.requiredSnr,
"rx.gainMode": this.param.rx.gainMode,
"rx.manualGain": this.param.rx.manualGain,
"rx.spectrumInversion": this.param.rx.spectrumInversion,
"rx.rolloff": this.param.rx.rolloff,
"rx.cymRate": this.param.rx.cymRate,
"rx.centerFreq": this.param.rx.centerFreq
}
this.submitStatus.rxTx = true
fetch('/api/set/rxtx', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(query)
}).then(async (resp) => {
this.submitStatus.rxTx = false
this.updateCincSettings(await resp.json())
}).catch((reason) => {
this.submitStatus.rxTx = false
alert(`Ошибка при применении настроек: ${reason}`)
})
},
settingsSubmitCinC() {
if (this.submitStatus.cinc) { return }
let query = {
"cinc.mode": this.param.cinc.mode,
"cinc.searchBandwidth": parseInt(this.param.cinc.searchBandwidth),
"cinc.position.station.latitude": parseFloat(this.param.cinc.position.station.latitude),
"cinc.position.station.longitude": parseFloat(this.param.cinc.position.station.longitude),
"cinc.position.satelliteLongitude": parseFloat(this.param.cinc.position.satelliteLongitude),
"cinc.delayMin": parseInt(this.param.cinc.delayMin),
"cinc.delayMax": parseInt(this.param.cinc.delayMax)
}
this.submitStatus.cinc = true
fetch('/api/set/cinc', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(query)
}).then(async (resp) => {
this.submitStatus.cinc = false
this.updateCincSettings(await resp.json())
}).catch((reason) => {
this.submitStatus.cinc = false
alert(`Ошибка при применении настроек: ${reason}`)
})
},
settingsSubmitBucLnb() {