diff --git a/src/main.cpp b/src/main.cpp index ff80f16..5cbd7f7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -286,7 +286,7 @@ public: } })); - s.resources.emplace_back(std::make_unique("/api/set/bucLnb", this->auth, http::auth::User::SUPERUSER, [this](const auto& req, auto& rep) { + s.resources.emplace_back(std::make_unique("/api/set/buclnb", this->auth, http::auth::User::SUPERUSER, [this](const auto& req, auto& rep) { if (req.method != "POST") { http::server::stockReply(http::server::bad_request, rep); } @@ -308,7 +308,7 @@ public: 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(); + BOOST_LOG_TRIVIAL(error) << "WebHandle(/api/set/buclnb): Can't set BUC LNB settings: " << e.what(); const std::string result = R"({"status":"error"})"; rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size()); } @@ -392,35 +392,7 @@ public: 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()); - } - })); - - s.resources.emplace_back(std::make_unique("/api/set/debugSend", 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->setDebugSendSettings(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(); + BOOST_LOG_TRIVIAL(error) << "WebHandle(/api/set/network): Can't set network settings: " << e.what(); const std::string result = R"({"status":"error"})"; rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size()); } @@ -485,16 +457,16 @@ public: s.resources.emplace_back(std::make_unique("/dev", this->auth, http::auth::User::SUPERUSER, [this](const auto& req, auto& rep) { boost::ignore_unused(req); - sf->serve(INTERNET_JPG, rep); + sf->serve(DEV_HTML, rep); })); - s.resources.emplace_back(std::make_unique("/dev/fetchParams", this->auth, http::auth::User::SUPERUSER, [this](const auto& req, auto& rep) { - rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)}); - std::string result = R"({"status":"ok","fwsize":)"; - result += std::to_string(req.payload.size()); - result += R"(,"sha256":")"; - result += "\"}"; - })); + // s.resources.emplace_back(std::make_unique("/dev/fetchParams", this->auth, http::auth::User::SUPERUSER, [this](const auto& req, auto& rep) { + // rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)}); + // std::string result = R"({"status":"ok","fwsize":)"; + // result += std::to_string(req.payload.size()); + // result += R"(,"sha256":")"; + // result += "\"}"; + // })); } ~ServerResources() = default; diff --git a/src/terminal_api_driver.cpp b/src/terminal_api_driver.cpp index f983c65..758a97b 100644 --- a/src/terminal_api_driver.cpp +++ b/src/terminal_api_driver.cpp @@ -801,52 +801,52 @@ void api_driver::ApiDriver::resetPacketStatistics() const { #ifdef MODEM_IS_SCPC struct ModcodDef_t {const char* modulation; const char* speed;}; -const static ModcodDef_t defs[] = { - {.modulation = "DUMMY", .speed = "0"}, - {.modulation = "QPSK", .speed = "1/4"}, - {.modulation = "QPSK", .speed = "1/3"}, - {.modulation = "QPSK", .speed = "2/5"}, - {.modulation = "QPSK", .speed = "1/2"}, - {.modulation = "QPSK", .speed = "3/5"}, - {.modulation = "QPSK", .speed = "2/3"}, - {.modulation = "QPSK", .speed = "3/4"}, - {.modulation = "QPSK", .speed = "4/5"}, - {.modulation = "QPSK", .speed = "5/6"}, - {.modulation = "QPSK", .speed = "8/9"}, - {.modulation = "QPSK", .speed = "9/10"}, - {.modulation = "8PSK", .speed = "3/5"}, - {.modulation = "8PSK", .speed = "2/3"}, - {.modulation = "8PSK", .speed = "3/4"}, - {.modulation = "8PSK", .speed = "5/6"}, - {.modulation = "8PSK", .speed = "8/9"}, - {.modulation = "8PSK", .speed = "9/10"}, - {.modulation = "16APSK", .speed = "2/3"}, - {.modulation = "16APSK", .speed = "3/4"}, - {.modulation = "16APSK", .speed = "4/5"}, - {.modulation = "16APSK", .speed = "5/6"}, - {.modulation = "16APSK", .speed = "8/9"}, - {.modulation = "16APSK", .speed = "9/10"}, - {.modulation = "32APSK", .speed = "3/4"}, - {.modulation = "32APSK", .speed = "4/5"}, - {.modulation = "32APSK", .speed = "5/6"}, - {.modulation = "32APSK", .speed = "8/9"}, - {.modulation = "32APSK", .speed = "9/10"}, +const static ModcodDef_t ModcodDefs[] = { + {.modulation = "dummy", .speed = "0"}, + {.modulation = "qpsk", .speed = "1/4"}, + {.modulation = "qpsk", .speed = "1/3"}, + {.modulation = "qpsk", .speed = "2/5"}, + {.modulation = "qpsk", .speed = "1/2"}, + {.modulation = "qpsk", .speed = "3/5"}, + {.modulation = "qpsk", .speed = "2/3"}, + {.modulation = "qpsk", .speed = "3/4"}, + {.modulation = "qpsk", .speed = "4/5"}, + {.modulation = "qpsk", .speed = "5/6"}, + {.modulation = "qpsk", .speed = "8/9"}, + {.modulation = "qpsk", .speed = "9/10"}, + {.modulation = "8psk", .speed = "3/5"}, + {.modulation = "8psk", .speed = "2/3"}, + {.modulation = "8psk", .speed = "3/4"}, + {.modulation = "8psk", .speed = "5/6"}, + {.modulation = "8psk", .speed = "8/9"}, + {.modulation = "8psk", .speed = "9/10"}, + {.modulation = "16apsk", .speed = "2/3"}, + {.modulation = "16apsk", .speed = "3/4"}, + {.modulation = "16apsk", .speed = "4/5"}, + {.modulation = "16apsk", .speed = "5/6"}, + {.modulation = "16apsk", .speed = "8/9"}, + {.modulation = "16apsk", .speed = "9/10"}, + {.modulation = "32apsk", .speed = "3/4"}, + {.modulation = "32apsk", .speed = "4/5"}, + {.modulation = "32apsk", .speed = "5/6"}, + {.modulation = "32apsk", .speed = "8/9"}, + {.modulation = "32apsk", .speed = "9/10"}, }; static const char* extractModcodModulation(uint32_t modcod, bool defaultQpsk1_4 = true) { modcod >>= 2; - const auto* d = defaultQpsk1_4 ? defs : defs + 1; + const auto* d = defaultQpsk1_4 ? ModcodDefs : ModcodDefs + 1; if (modcod < 28) { - d = defs + modcod; + d = ModcodDefs + modcod; } return d->modulation; } static const char* extractModcodSpeed(uint32_t modcod, bool defaultQpsk1_4 = true) { modcod >>= 2; - const auto* d = defaultQpsk1_4 ? defs : defs + 1; + const auto* d = defaultQpsk1_4 ? ModcodDefs : ModcodDefs + 1; if (modcod < 28) { - d = defs + modcod; + d = ModcodDefs + modcod; } return d->speed; } @@ -978,6 +978,26 @@ std::string api_driver::ApiDriver::loadFirmwareVersion() const { return result.str(); } +#ifdef MODEM_IS_SCPC +static uint32_t buildModcodFromPt(const boost::property_tree::ptree& pt, const std::string& name, bool isShortFrame) { + uint32_t modcod = 0; + const auto mod = pt.get(name + "Modulation"); + const auto speed = pt.get(name + "Speed"); + uint32_t _index = 0; + for (const auto& m: ModcodDefs) { + if (mod == m.modulation) { + if (modcod == 0) modcod = _index; + if (speed == m.speed) { + modcod = _index; + break; + } + } + _index++; + } + return (modcod << 2) | (isShortFrame ? 2 : 0); +} +#endif + void api_driver::ApiDriver::setRxTxSettings(boost::property_tree::ptree &pt) { modulator_settings mod{}; demodulator_settings demod{}; @@ -991,54 +1011,45 @@ void api_driver::ApiDriver::setRxTxSettings(boost::property_tree::ptree &pt) { // для модулятора #ifdef MODEM_IS_SCPC mod.is_cinc = pt.get("isCinC"); - mod.tx_is_on = pt.get(json_path("general.txEn", '/')); - auto tmp = pt.get(json_path("general.modulatorMode", '/')); - if (tmp == "normal") { mod.is_carrier = true; } - else if (tmp == "test") { mod.is_carrier = false; } - else { throw std::runtime_error("api_driver::ApiDriver::setRxTxSettings(): Wrong carrier mode: " + tmp); } - mod.is_save_current_state = pt.get(json_path("general.autoStartTx", '/')); - mod.is_test_data = pt.get(json_path("general.isTestInputData", '/')); - mod.attenuation = pt.get(json_path("tx.attenuation", '/')); - mod.rollof = pt.get(json_path("tx.rolloff", '/')) / 100.0; - mod.baudrate = pt.get(json_path("tx.cymRate", '/')); - mod.central_freq_in_kGz = pt.get(json_path("tx.centerFreq", '/')); +#endif + mod.tx_is_on = pt.get("txEn"); +#ifdef MODEM_IS_SCPC + mod.is_save_current_state = pt.get("txAutoStart"); + mod.is_carrier = !pt.get("txModulatorIsTest"); +#endif + mod.is_test_data = pt.get("txIsTestInput"); + mod.central_freq_in_kGz = pt.get("txCentralFreq"); + mod.baudrate = pt.get("txBaudrate"); + mod.rollof = pt.get("txRolloff") / 100.0; +#ifdef MODEM_IS_SCPC + //mod.qold_seq_is_active = pt.get("isCinC"); +#endif + mod.attenuation = pt.get("txAttenuation"); - const bool acmIsShortFrame = !pt.get(json_path("dvbs2.frameSizeNormal", '/')); - mod.modcod_tx = (pt.get(json_path("dvbs2.ccm_modcod", '/')) << 2) | (acmIsShortFrame ? 2 : 0); -#else - mod.tx_is_on = pt.get(json_path("tx.txEn", '/')); - mod.is_test_data = pt.get(json_path("tx.isTestInputData", '/')); - mod.central_freq_in_kGz = pt.get(json_path("tx.centerFreq", '/')); - mod.baudrate = pt.get(json_path("tx.cymRate", '/')); - mod.attenuation = pt.get(json_path("tx.attenuation", '/')); +#ifdef MODEM_IS_SCPC + const bool acmIsShortFrame = !pt.get("txFrameSizeNormal"); + mod.modcod_tx = buildModcodFromPt(pt, "dvbCcm", acmIsShortFrame); #endif // демодулятор -#ifdef MODEM_IS_SCPC - tmp = pt.get(json_path("rx.gainMode", '/')); -#else - auto tmp = pt.get(json_path("rx.gainMode", '/')); -#endif - if (tmp == "auto") { demod.is_aru_on = true; } - else if (tmp == "manual") { demod.is_aru_on = false; } - else { throw std::runtime_error("api_driver::ApiDriver::setRxTxSettings(): Wrong gain mode: " + tmp); } - demod.gain = pt.get(json_path("rx.manualGain", '/')); - demod.baudrate = pt.get(json_path("rx.cymRate", '/')); - demod.is_rvt_iq = pt.get(json_path("rx.spectrumInversion", '/')); - demod.rollof = pt.get(json_path("rx.rolloff", '/')) / 100.0; - demod.central_freq_in_kGz = pt.get(json_path("rx.centerFreq", '/')); + demod.is_aru_on = pt.get("rxAgcEn"); + demod.gain = pt.get("rxManualGain"); + demod.is_rvt_iq = pt.get("aupcEn"); + demod.central_freq_in_kGz = pt.get("rxCentralFreq"); + demod.baudrate = pt.get("rxBaudrate"); + demod.rollof = pt.get("rxRolloff") / 100.0; #ifdef MODEM_IS_SCPC // ACM - acm.enable = pt.get(json_path("dvbs2.isAcm", '/')); - acm.max_modcod = (pt.get(json_path("dvbs2.acm_maxModcod", '/')) << 2) | (acmIsShortFrame ? 2 : 0); - acm.min_modcod = (pt.get(json_path("dvbs2.acm_minModcod", '/')) << 2) | (acmIsShortFrame ? 2 : 0); - acm.snr_treashold_acm = pt.get(json_path("dvbs2.snrReserve", '/')); // запас ОСШ - acm.period_pack = pt.get(json_path("dvbs2.servicePacketPeriod", '/')); - acm.enable_auto_atten = pt.get(json_path("acm.en", '/')); - acm.max_attenuation = pt.get(json_path("acm.maxAttenuation", '/')); - acm.min_attenuation = pt.get(json_path("acm.minAttenuation", '/')); - acm.snr_treashold = pt.get(json_path("acm.requiredSnr", '/')); // требуемый ОСШ + acm.period_pack = pt.get("dvbServicePacketPeriod"); + acm.enable = pt.get("rxAgcEn"); + acm.min_modcod = buildModcodFromPt(pt, "dvbAcmMin", acmIsShortFrame); + acm.max_modcod = buildModcodFromPt(pt, "dvbAcmMax", acmIsShortFrame); + acm.snr_treashold_acm = pt.get("dvbSnrReserve"); // запас ОСШ + acm.enable_auto_atten = pt.get(json_path("aupcEn", '/')); + acm.min_attenuation = pt.get("aupcMinAttenuation"); + acm.max_attenuation = pt.get("aupcMaxAttenuation"); + acm.snr_treashold = pt.get("aupcRequiredSnr"); daemon->setSettingsRxTx(mod, demod, acm); #else @@ -1050,30 +1061,23 @@ 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(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); - } + s.is_delay_window = !pt.get("cincIsPositional"); + s.freq_offset = pt.get("cincSearchBandwidth"); - auto ctmp = translateCoordinates(pt.get(json_path("cinc.position.station.latitude", '/'))); + auto ctmp = translateCoordinates(pt.get("cincPositionStationLatitude")); s.latitude_station_grad = std::get<0>(ctmp); s.latitude_station_minute = std::get<1>(ctmp); - ctmp = translateCoordinates(pt.get(json_path("cinc.position.station.longitude", '/'))); + ctmp = translateCoordinates(pt.get("cincPositionStationLongitude")); s.longitude_station_grad = std::get<0>(ctmp); s.longitude_station_minute = std::get<1>(ctmp); - ctmp = translateCoordinates(pt.get(json_path("cinc.position.satelliteLongitude", '/'))); + ctmp = translateCoordinates(pt.get("cincPositionSatelliteLongitude")); s.longitude_sattelite_grad = std::get<0>(ctmp); s.longitude_sattelite_minute = std::get<1>(ctmp); - s.max_delay = pt.get(json_path("cinc.delayMax", '/')); - s.min_delay = pt.get(json_path("cinc.delayMin", '/')); - - s.freq_offset = pt.get(json_path("cinc.searchBandwidth", '/')); + s.min_delay = pt.get("cincDelayMin"); + s.max_delay = pt.get("cincDelayMax"); this->daemon->setSettingsCinc(s); } @@ -1081,19 +1085,13 @@ void api_driver::ApiDriver::setCincSettings(boost::property_tree::ptree &pt) { void api_driver::ApiDriver::setBucLnbSettings(boost::property_tree::ptree &pt) { buc_lnb_settings s{}; +#ifdef MODEM_IS_SCPC + daemon->getSettings(nullptr, nullptr, nullptr, nullptr, &s); +#else + daemon->getSettings(nullptr, nullptr, &s); +#endif - auto tmp = pt.get(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(json_path("lnb.refClk10M", '/')); - - tmp = pt.get(json_path("buc.powering", '/')); + auto tmp = pt.get("bucPowering"); switch (tmp) { case 24: s.buc = voltage_buc::_24V; break; #ifdef MODEM_IS_SCPC @@ -1103,11 +1101,21 @@ void api_driver::ApiDriver::setBucLnbSettings(boost::property_tree::ptree &pt) { default: s.lnb = voltage_lnb::DISABLE; } + s.is_ref_10MHz_buc = pt.get("bucRefClk10M"); - s.is_ref_10MHz_buc = pt.get(json_path("buc.refClk10M", '/')); + tmp = pt.get("lnbPowering"); + 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("lnbRefClk10M"); - s.is_ref_10MHz_output = pt.get(json_path("serviceSettings.refClk10M", '/')); - s.is_save_current_state = pt.get(json_path("serviceSettings.autoStart", '/')); + s.is_ref_10MHz_output = pt.get("srvRefClk10M"); + s.is_save_current_state = pt.get("bucLnbAutoStart"); this->daemon->setSettingsBucLnb(s); } @@ -1124,19 +1132,17 @@ void api_driver::ApiDriver::setQosSettings(boost::property_tree::ptree &pt) { void api_driver::ApiDriver::setNetworkSettings(boost::property_tree::ptree &pt) { TerminalNetworkSettings s; - s.managementIp = pt.get(json_path("network.managementIp", '/')); - s.managementGateway = pt.get(json_path("network.managementGateway", '/')); - s.isL2 = pt.get(json_path("network.mode", '/')); - s.dataIp = pt.get(json_path("network.dataIp", '/')); - s.dataMtu = pt.get(json_path("network.dataMtu", '/')); + daemon->getNetworkSettings(s); + + s.managementIp = pt.get("netManagementIp"); + // s.managementGateway = pt.get(json_path("network.managementGateway", '/')); + s.isL2 = pt.get("netIsL2"); + s.dataIp = pt.get("netDataIp"); + s.dataMtu = pt.get("netDataMtu"); daemon->setNetworkSettings(s); } -void api_driver::ApiDriver::setDebugSendSettings(boost::property_tree::ptree &pt) { - boost::ignore_unused(pt); -} - void api_driver::ApiDriver::resetDefaultSettings() { daemon->resetDefaultSettings(); } @@ -1178,8 +1184,8 @@ std::string api_driver::ApiDriver::loadSysInfo() { result << ",\"load15min\":"; writeDouble(result, f_load * static_cast(info.loads[2]), 2); result << ",\"totalram\":" << ((info.totalram * info.mem_unit) >> 20); // Mb result << ",\"freeram\":" << ((info.freeram * info.mem_unit) >> 20); // Mb - result << ",\"sharedram\":" << ((info.sharedram * info.mem_unit) >> 20); // Mb - result << ",\"bufferram\":" << ((info.bufferram * info.mem_unit) >> 20); // Mb + // result << ",\"sharedram\":" << ((info.sharedram * info.mem_unit) >> 20); // Mb + // result << ",\"bufferram\":" << ((info.bufferram * info.mem_unit) >> 20); // Mb // result << ",\"totalswap\":" << info.totalswap * info.mem_unit; // result << ",\"freeswap\":" << info.freeswap * info.mem_unit; result << ",\"procs\":" << static_cast(info.procs);