компилируемая версия для всех версий модемов, пока без CP Proxy
This commit is contained in:
parent
50f82483fd
commit
f30e1adb49
@ -52,20 +52,25 @@ namespace api_driver {
|
||||
// * Получение настроек, копирует текущие значения в структуры, переданные по указателю. Если передан пустой указатель, копирования не произойдет.
|
||||
// */
|
||||
void getSettingsRxTx(obj::TerminalRxTxSettings &dest);
|
||||
|
||||
#ifdef API_OBJECT_NETWORK_SETTINGS_ENABLE
|
||||
void getNetworkSettings(obj::TerminalNetworkSettings &dest);
|
||||
void setNetworkSettings(obj::TerminalNetworkSettings &s, bool readback = true);
|
||||
#endif
|
||||
|
||||
#ifdef API_OBJECT_QOS_SETTINGS_ENABLE
|
||||
void getQosSettings(bool &isEnabled, std::string &json);
|
||||
void setQosSettings(bool enabled, const std::string &str, bool readback = true);
|
||||
#endif
|
||||
|
||||
void setSettingsRxTx(obj::TerminalRxTxSettings &s, bool readback = true);
|
||||
|
||||
#ifdef API_OBJECT_DPDI_SETTINGS_ENABLE
|
||||
void setSettingsDpdi(DPDI_parmeters &s, bool readback = true);
|
||||
#endif
|
||||
|
||||
#ifdef API_OBJECT_BUCLNB_SETTINGS_ENABLE
|
||||
void setSettingsBucLnb(buc_lnb_settings &bucLnb, bool readback = true);
|
||||
|
||||
void setQosSettings(bool enabled, const std::string &str, bool readback = true);
|
||||
|
||||
void setNetworkSettings(obj::TerminalNetworkSettings &s, bool readback = true);
|
||||
#endif
|
||||
|
||||
obj::TerminalFirmwareVersion getFirmware();
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, CP_Result result);
|
||||
|
||||
|
||||
namespace api_driver::proxy {
|
||||
class CpProxy {
|
||||
public:
|
||||
@ -41,19 +40,39 @@ namespace api_driver::proxy {
|
||||
void getDemodSettings(demodulator_settings& dest);
|
||||
void setDemodSettings(demodulator_settings& dest);
|
||||
|
||||
#ifdef API_STRUCT_ACM_ENABLE
|
||||
void getAcmSettings(ACM_parameters_serv_& dest);
|
||||
void setAcmSettings(ACM_parameters_serv_& dest);
|
||||
#endif
|
||||
|
||||
void getDeviceState(device_state& dest);
|
||||
|
||||
#ifdef MODEM_IS_SCPC
|
||||
#ifdef API_OBJECT_QOS_SETTINGS_ENABLE
|
||||
std::tuple<std::string, bool> getQosSettings();
|
||||
void setQosSettings(const std::string& rules, bool enable);
|
||||
#endif
|
||||
|
||||
#ifdef API_OBJECT_DPDI_SETTINGS_ENABLE
|
||||
void getDpdiSettings(DPDI_parmeters& dest);
|
||||
void setDpdiSettings(DPDI_parmeters& dest);
|
||||
#endif
|
||||
|
||||
#ifdef API_OBJECT_BUCLNB_SETTINGS_ENABLE
|
||||
void getBuclnbSettings(buc_lnb_settings& dest);
|
||||
void setBuclnbSettings(buc_lnb_settings& dest);
|
||||
#endif
|
||||
|
||||
#ifdef MODEM_IS_SCPC
|
||||
void getCincState(CinC_state& dest);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef API_OBJECT_DEBUG_METRICS_ENABLE
|
||||
#ifdef API_OBJECT_DEBUG_METRICS_ENABLE
|
||||
void getDebugMetrics(debug_metrics& dest);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef MODEM_IS_TDMA
|
||||
#ifdef MODEM_IS_TDMA
|
||||
void getUpdateStatus(progress_msg& dest);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
~CpProxy();
|
||||
};
|
||||
|
@ -6,6 +6,10 @@
|
||||
#define API_OBJECT_DEBUG_METRICS_ENABLE
|
||||
#endif
|
||||
|
||||
#if defined(MODEM_IS_SCPC)
|
||||
#define API_STRUCT_ACM_ENABLE
|
||||
#endif
|
||||
|
||||
#if defined(MODEM_IS_SCPC) || defined(MODEM_IS_TDMA)
|
||||
#define API_OBJECT_NETWORK_SETTINGS_ENABLE
|
||||
#endif
|
||||
|
@ -11,10 +11,6 @@
|
||||
|
||||
typedef boost::property_tree::ptree::path_type json_path;
|
||||
|
||||
double translateCoordinates(uint8_t deg, uint8_t min) {
|
||||
return static_cast<double>(deg) + static_cast<double>(min) / 60;
|
||||
}
|
||||
|
||||
// static int calculateSubnetMask(const std::string& subnet_mask) {
|
||||
// int mask = 0;
|
||||
// std::istringstream iss(subnet_mask);
|
||||
@ -108,10 +104,10 @@ std::string api_driver::obj::StatisticsLogger::getSettings() {
|
||||
return res.str();
|
||||
}
|
||||
|
||||
void api_driver::obj::StatisticsLogger::setSettings(boost::property_tree::ptree &pt) {
|
||||
const bool newEn = pt.get<bool>("en");
|
||||
const int newInterval = pt.get<int>("logPeriodMs");
|
||||
const int newMaxAgeMs = pt.get<int>("maxAgeMs");
|
||||
void api_driver::obj::StatisticsLogger::setSettings(const nlohmann::json& data) {
|
||||
const bool newEn = data.value("en", logEn);
|
||||
const int newInterval = data.value("logPeriodMs", logPeriodMs.load());
|
||||
const int newMaxAgeMs = data.value("maxAgeMs", maxAgeMs.load());
|
||||
|
||||
std::lock_guard _lock(this->mutex);
|
||||
this->logPeriodMs = newInterval;
|
||||
@ -217,7 +213,7 @@ void api_driver::obj::TerminalNetworkSettings::updateCallback(proxy::CpProxy &cp
|
||||
}
|
||||
}
|
||||
|
||||
void api_driver::obj::TerminalNetworkSettings::updateFromPt(boost::property_tree::ptree &pt) {
|
||||
void api_driver::obj::TerminalNetworkSettings::updateFromJson(nlohmann::json &data) {
|
||||
}
|
||||
|
||||
void api_driver::obj::TerminalNetworkSettings::store(proxy::CpProxy& cp) {
|
||||
@ -239,17 +235,22 @@ void api_driver::obj::TerminalNetworkSettings::store(proxy::CpProxy& cp) {
|
||||
}
|
||||
}
|
||||
|
||||
std::string api_driver::obj::TerminalNetworkSettings::asJson() {
|
||||
std::stringstream out;
|
||||
|
||||
return out.str();
|
||||
nlohmann::json api_driver::obj::TerminalNetworkSettings::asJson() {
|
||||
nlohmann::json res;
|
||||
res["isL2"] = isL2;
|
||||
res["managementIp"] = managementIp;
|
||||
res["managementGateway"] = managementGateway;
|
||||
res["dataIp"] = dataIp;
|
||||
res["dataMtu"] = dataMtu;
|
||||
res["serverName"] = serverName;
|
||||
return res;
|
||||
}
|
||||
|
||||
api_driver::obj::TerminalNetworkSettings::~TerminalNetworkSettings() = default;
|
||||
#endif
|
||||
|
||||
#ifdef API_OBJECT_QOS_SETTINGS_ENABLE
|
||||
api_driver::obj::TerminalQosSettings::TerminalQosSettings() = default;
|
||||
api_driver::obj::TerminalQosSettings::TerminalQosSettings(): qosSettingsJson(DEFAULT_QOS_CLASSES) {};
|
||||
api_driver::obj::TerminalQosSettings::TerminalQosSettings(const TerminalQosSettings &src) = default;
|
||||
api_driver::obj::TerminalQosSettings & api_driver::obj::TerminalQosSettings::operator=(const TerminalQosSettings &src) = default;
|
||||
|
||||
@ -259,20 +260,60 @@ void api_driver::obj::TerminalQosSettings::loadDefaults() {
|
||||
}
|
||||
|
||||
void api_driver::obj::TerminalQosSettings::updateCallback(proxy::CpProxy &cp) {
|
||||
auto [profile, en] = cp.getQosSettings();
|
||||
qosEnabled = en;
|
||||
try {
|
||||
qosSettingsJson = nlohmann::json::parse(profile);
|
||||
} catch (std::exception& e) {
|
||||
BOOST_LOG_TRIVIAL(warning) << "api_driver::obj::TerminalQosSettings::updateCallback(): Failed to parse QoS settings json: " << e.what();
|
||||
qosSettingsJson = DEFAULT_QOS_CLASSES;
|
||||
}
|
||||
}
|
||||
|
||||
void api_driver::obj::TerminalQosSettings::updateFromPt(boost::property_tree::ptree &pt) {
|
||||
void api_driver::obj::TerminalQosSettings::updateFromJson(nlohmann::json &data) {
|
||||
qosEnabled = data.value("en", qosEnabled);
|
||||
qosSettingsJson = data.value("profile", qosSettingsJson);
|
||||
}
|
||||
|
||||
void api_driver::obj::TerminalQosSettings::store(proxy::CpProxy &cp) {
|
||||
cp.setQosSettings(qosSettingsJson.dump(), qosEnabled);
|
||||
}
|
||||
|
||||
std::string api_driver::obj::TerminalQosSettings::asJson() {
|
||||
nlohmann::json api_driver::obj::TerminalQosSettings::asJson() {
|
||||
nlohmann::json res;
|
||||
res["en"] = qosEnabled;
|
||||
res["profile"] = qosSettingsJson;
|
||||
return res;
|
||||
}
|
||||
|
||||
api_driver::obj::TerminalQosSettings::~TerminalQosSettings() = default;
|
||||
#endif
|
||||
|
||||
api_driver::obj::TerminalFirmwareVersion::TerminalFirmwareVersion() = default;
|
||||
api_driver::obj::TerminalFirmwareVersion::TerminalFirmwareVersion(const TerminalFirmwareVersion &src) = default;
|
||||
api_driver::obj::TerminalFirmwareVersion & api_driver::obj::TerminalFirmwareVersion::operator=(const TerminalFirmwareVersion &src) = default;
|
||||
|
||||
void api_driver::obj::TerminalFirmwareVersion::load(proxy::CpProxy &cp) {
|
||||
version = cp.getNetwork("version");
|
||||
modemId = cp.getNetwork("chip_id");
|
||||
rtrim(modemId);
|
||||
modemSn = cp.getNetwork("serial");
|
||||
macMang = cp.getNetwork("mac_eth0");
|
||||
macData = cp.getNetwork("mac_eth1");
|
||||
}
|
||||
|
||||
nlohmann::json api_driver::obj::TerminalFirmwareVersion::asJson() {
|
||||
nlohmann::json res;
|
||||
res["version"] = version;
|
||||
res["modemId"] = modemId;
|
||||
res["modemSn"] = modemSn;
|
||||
res["macMang"] = macMang;
|
||||
res["macData"] = macData;
|
||||
return res;
|
||||
}
|
||||
|
||||
api_driver::obj::TerminalFirmwareVersion::~TerminalFirmwareVersion() = default;
|
||||
|
||||
|
||||
api_driver::obj::TerminalState::TerminalState() = default;
|
||||
|
||||
@ -487,6 +528,389 @@ nlohmann::json api_driver::obj::TerminalDeviceState::asJson() const {
|
||||
api_driver::obj::TerminalDeviceState::~TerminalDeviceState() = default;
|
||||
|
||||
|
||||
api_driver::obj::TerminalRxTxSettings::TerminalRxTxSettings() = default;
|
||||
api_driver::obj::TerminalRxTxSettings::TerminalRxTxSettings(const TerminalRxTxSettings &src) = default;
|
||||
api_driver::obj::TerminalRxTxSettings & api_driver::obj::TerminalRxTxSettings::operator=(const TerminalRxTxSettings &src) = default;
|
||||
|
||||
void api_driver::obj::TerminalRxTxSettings::updateCallback(proxy::CpProxy &cp) {
|
||||
cp.getModSettings(mod);
|
||||
cp.getDemodSettings(dem);
|
||||
#ifdef API_STRUCT_ACM_ENABLE
|
||||
cp.getAcmSettings(acm);
|
||||
#endif
|
||||
#ifdef API_OBJECT_DPDI_SETTINGS_ENABLE
|
||||
cp.getDpdiSettings(dpdi);
|
||||
#endif
|
||||
#ifdef API_OBJECT_BUCLNB_SETTINGS_ENABLE
|
||||
cp.getBuclnbSettings(buclnb);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
struct ModcodDef_t {const char* modulation; const char* speed;};
|
||||
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 ? ModcodDefs : ModcodDefs + 1;
|
||||
if (modcod < (sizeof(ModcodDefs) / sizeof(ModcodDef_t))) {
|
||||
d = ModcodDefs + modcod;
|
||||
}
|
||||
return d->modulation;
|
||||
}
|
||||
static const char* extractModcodSpeed(uint32_t modcod, bool defaultQpsk1_4 = true) {
|
||||
modcod >>= 2;
|
||||
const auto* d = defaultQpsk1_4 ? ModcodDefs : ModcodDefs + 1;
|
||||
if (modcod < (sizeof(ModcodDefs) / sizeof(ModcodDef_t))) {
|
||||
d = ModcodDefs + modcod;
|
||||
}
|
||||
return d->speed;
|
||||
}
|
||||
static bool extractModcodFrameSizeNormal(uint32_t modcod) { return (modcod & 2) == 0; }
|
||||
static bool extractModcodIsPilots(uint32_t modcod) { return (modcod & 1) != 0; }
|
||||
static uint32_t buildModcodFromJson(const nlohmann::json& data, uint32_t modcod, const std::string& name, bool isNormalFrame, bool isPilots = false) {
|
||||
const std::string mod = data.value(name + "Modulation", extractModcodModulation(modcod));
|
||||
const std::string speed = data.value(name + "Speed", extractModcodSpeed(modcod));
|
||||
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)| (isNormalFrame ? 0 : 2) | (isPilots ? 1 : 0);
|
||||
}
|
||||
|
||||
|
||||
void api_driver::obj::TerminalRxTxSettings::updateMainSettings(const nlohmann::json &data) {
|
||||
// для модулятора
|
||||
#ifdef MODEM_IS_SCPC
|
||||
mod.is_cinc = data.value("isCinC", mod.is_cinc);
|
||||
#endif
|
||||
mod.tx_is_on = data.value("txEn", mod.tx_is_on);
|
||||
#ifdef MODEM_IS_SCPC
|
||||
mod.is_save_current_state = data.value("txAutoStart", mod.is_save_current_state);
|
||||
mod.is_test_data = data.value("txIsTestInput", mod.is_test_data);
|
||||
#endif
|
||||
mod.is_carrier = !data.value("txModulatorIsTest", !mod.is_carrier);
|
||||
mod.central_freq_in_kGz = data.value("txCentralFreq", mod.central_freq_in_kGz);
|
||||
#ifdef MODEM_IS_SCPC
|
||||
mod.baudrate = data.value("txBaudrate", mod.baudrate);
|
||||
mod.rollof = data.value("txRolloff", mod.rollof);
|
||||
mod.gold_seq_is_active = data.value("txGoldan", mod.gold_seq_is_active);
|
||||
#endif
|
||||
mod.attenuation = data.value("txAttenuation", mod.attenuation);
|
||||
|
||||
#if defined(MODEM_IS_SCPC) || defined(MODEM_IS_SHPS)
|
||||
bool acmIsFrameSizeNormal = extractModcodFrameSizeNormal(mod.modcod_tx);
|
||||
bool acmIsPilots = extractModcodIsPilots(mod.modcod_tx);
|
||||
|
||||
acmIsFrameSizeNormal = data.value("txFrameSizeNormal", acmIsFrameSizeNormal);
|
||||
acmIsPilots = data.value("txIsPilots", acmIsPilots);
|
||||
mod.modcod_tx = buildModcodFromJson(data, mod.modcod_tx, "dvbCcm", acmIsFrameSizeNormal, acmIsPilots);
|
||||
#endif
|
||||
|
||||
// демодулятор
|
||||
dem.is_aru_on = data.value("rxAgcEn", dem.is_aru_on);
|
||||
dem.gain = data.value("rxManualGain", dem.gain);
|
||||
dem.is_rvt_iq = data.value("rxSpectrumInversion", dem.is_rvt_iq);
|
||||
dem.central_freq_in_kGz = data.value("rxCentralFreq", dem.central_freq_in_kGz);
|
||||
dem.baudrate = data.value("rxBaudrate", dem.baudrate);
|
||||
dem.rollof = data.value("rxRolloff", dem.rollof);
|
||||
#ifdef MODEM_IS_SCPC
|
||||
dem.gold_seq_is_active = data.value("rxGoldan", dem.gold_seq_is_active);
|
||||
#endif
|
||||
|
||||
#ifdef API_STRUCT_ACM_ENABLE
|
||||
// ACM
|
||||
#ifndef MODEM_IS_SHPS
|
||||
// в ШПС этих настроек нет
|
||||
acm.period_pack_acm = data.value("dvbServicePacketPeriod", acm.period_pack_acm);
|
||||
acm.enable_acm = data.value("dvbIsAcm", acm.enable_acm);
|
||||
acm.min_modcod_acm = buildModcodFromJson(data, acm.min_modcod_acm, "dvbAcmMin", acmIsFrameSizeNormal, acmIsPilots);
|
||||
acm.min_modcod_acm = buildModcodFromJson(data, acm.max_modcod_acm, "dvbAcmMax", acmIsFrameSizeNormal, acmIsPilots);
|
||||
acm.snr_threashold_acm = data.value("dvbSnrReserve", acm.snr_threashold_acm); // запас ОСШ
|
||||
#endif
|
||||
|
||||
acm.enable_aupc = data.value("aupcEn", acm.enable_aupc);
|
||||
acm.min_attenuation_aupc = data.value("aupcMinAttenuation", acm.min_attenuation_aupc);
|
||||
acm.max_attenuation_aupc = data.value("aupcMaxAttenuation", acm.max_attenuation_aupc);
|
||||
acm.snr_threashold_aupc = data.value("aupcRequiredSnr", acm.snr_threashold_aupc);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef API_OBJECT_DPDI_SETTINGS_ENABLE
|
||||
double translateCoordinates(uint8_t deg, uint8_t min) {
|
||||
return static_cast<double>(deg) + static_cast<double>(min) / 60;
|
||||
}
|
||||
|
||||
std::tuple<uint8_t, uint8_t> translateCoordinates(double abs) {
|
||||
auto deg = static_cast<uint8_t>(abs);
|
||||
double min_double = (abs - deg) * 60;
|
||||
auto min = static_cast<uint8_t>(min_double);
|
||||
return std::make_tuple(deg, min);
|
||||
}
|
||||
|
||||
void api_driver::obj::TerminalRxTxSettings::updateDpdiSettings(const nlohmann::json &data) {
|
||||
dpdi.is_delay_window = !data.value("dpdiIsPositional", !dpdi.is_delay_window);
|
||||
#ifdef MODEM_IS_SCPC
|
||||
dpdi.freq_offset = data.value("dpdiSearchBandwidth", dpdi.freq_offset);
|
||||
#endif
|
||||
|
||||
if (data["dpdiPositionStationLatitude"]) {
|
||||
const double pos = data["dpdiPositionStationLatitude"];
|
||||
const auto [g, m] = translateCoordinates(pos);
|
||||
dpdi.latitude_station_grad = g;
|
||||
dpdi.latitude_station_minute = m;
|
||||
}
|
||||
|
||||
if (data["dpdiPositionStationLongitude"]) {
|
||||
const double pos = data["dpdiPositionStationLongitude"];
|
||||
const auto [g, m] = translateCoordinates(pos);
|
||||
dpdi.longitude_station_grad = g;
|
||||
dpdi.longitude_station_minute = m;
|
||||
}
|
||||
|
||||
if (data["dpdiPositionSatelliteLongitude"]) {
|
||||
const double pos = data["dpdiPositionSatelliteLongitude"];
|
||||
const auto [g, m] = translateCoordinates(pos);
|
||||
dpdi.longitude_sattelite_grad = g;
|
||||
dpdi.longitude_sattelite_minute = m;
|
||||
}
|
||||
|
||||
#ifdef MODEM_IS_SCPC
|
||||
dpdi.min_delay = data.value("dpdiDelayMin", dpdi.min_delay);
|
||||
dpdi.max_delay = data.value("dpdiDelayMax", dpdi.max_delay);
|
||||
#else
|
||||
s.min_delay = 0;
|
||||
s.max_delay = data.value("dpdiDelay", dpdi.max_delay);
|
||||
#endif
|
||||
}
|
||||
void api_driver::obj::TerminalRxTxSettings::storeDpdiSettings(proxy::CpProxy &cp) {
|
||||
cp.setDpdiSettings(dpdi);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef API_OBJECT_BUCLNB_SETTINGS_ENABLE
|
||||
void api_driver::obj::TerminalRxTxSettings::updateBuclnbSettings(const nlohmann::json &data) {
|
||||
{
|
||||
// напряжение buc
|
||||
int oldVoltage = 0;
|
||||
if (buclnb.buc == voltage_buc::_24V) { oldVoltage = 24; }
|
||||
#ifdef MODEM_IS_SCPC
|
||||
if (buclnb.buc == voltage_buc::_24V) { oldVoltage = 24; }
|
||||
#endif
|
||||
|
||||
auto result = data.value("bucPowering", oldVoltage);
|
||||
switch (result) {
|
||||
case 24: buclnb.buc = voltage_buc::_24V; break;
|
||||
#ifdef MODEM_IS_SCPC
|
||||
case 48: buclnb.buc = voltage_buc::_48V; break;
|
||||
#endif
|
||||
case 0:
|
||||
default:
|
||||
buclnb.buc = voltage_buc::DISABLE;
|
||||
}
|
||||
}
|
||||
buclnb.is_ref_10MHz_buc = data.value("bucRefClk10M", buclnb.is_ref_10MHz_buc);
|
||||
|
||||
{
|
||||
// напряжение lnb
|
||||
int oldVoltage;
|
||||
switch (buclnb.lnb) {
|
||||
case voltage_lnb::_13V: oldVoltage = 13; break;
|
||||
case voltage_lnb::_18V: oldVoltage = 18; break;
|
||||
case voltage_lnb::_24V: oldVoltage = 24; break;
|
||||
default: oldVoltage = 0;
|
||||
}
|
||||
|
||||
auto result = data.value("lnbPowering", oldVoltage);
|
||||
switch (result) {
|
||||
case 13: buclnb.lnb = voltage_lnb::_13V; break;
|
||||
case 18: buclnb.lnb = voltage_lnb::_18V; break;
|
||||
case 24: buclnb.lnb = voltage_lnb::_24V; break;
|
||||
default: buclnb.lnb = voltage_lnb::DISABLE;
|
||||
}
|
||||
}
|
||||
|
||||
buclnb.is_ref_10MHz_lnb = data.value("lnbRefClk10M", buclnb.is_ref_10MHz_lnb);
|
||||
|
||||
buclnb.is_ref_10MHz_output = data.value("srvRefClk10M", buclnb.is_ref_10MHz_output);
|
||||
buclnb.is_save_current_state = data.value("bucLnbAutoStart", buclnb.is_save_current_state);
|
||||
}
|
||||
void api_driver::obj::TerminalRxTxSettings::storeBuclnbSettings(proxy::CpProxy &cp) {
|
||||
cp.setBuclnbSettings(buclnb);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void api_driver::obj::TerminalRxTxSettings::storeAll(proxy::CpProxy &cp) {
|
||||
storeMainSettings(cp);
|
||||
#ifdef API_OBJECT_DPDI_SETTINGS_ENABLE
|
||||
storeDpdiSettings(cp);
|
||||
#endif
|
||||
#ifdef API_OBJECT_BUCLNB_SETTINGS_ENABLE
|
||||
storeBuclnbSettings(cp);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
nlohmann::json api_driver::obj::TerminalRxTxSettings::asJson() const {
|
||||
nlohmann::json res;
|
||||
|
||||
// RX TX
|
||||
{
|
||||
auto& rxtx = res["rxtx"];
|
||||
// для модулятора
|
||||
#ifdef MODEM_IS_SCPC
|
||||
rxtx["isCinC"] = mod.is_cinc;
|
||||
#endif
|
||||
rxtx["txEn"] = mod.tx_is_on;
|
||||
#ifdef MODEM_IS_SCPC
|
||||
rxtx["txAutoStart"] = mod.is_save_current_state;
|
||||
rxtx["txIsTestInput"] = mod.is_test_data;
|
||||
#endif
|
||||
rxtx["txModulatorIsTest"] = !mod.is_carrier;
|
||||
rxtx["txCentralFreq"] = mod.central_freq_in_kGz;
|
||||
#ifdef MODEM_IS_SCPC
|
||||
rxtx["txBaudrate"] = mod.baudrate;
|
||||
rxtx["txRolloff"] = mod.rollof;
|
||||
rxtx["txGoldan"] = mod.gold_seq_is_active;
|
||||
#endif
|
||||
rxtx["txAttenuation"] = mod.attenuation;
|
||||
|
||||
#if defined(MODEM_IS_SCPC) || defined(MODEM_IS_SHPS)
|
||||
const bool acmIsFrameSizeNormal = extractModcodFrameSizeNormal(mod.modcod_tx);
|
||||
const bool acmIsPilots = extractModcodIsPilots(mod.modcod_tx);
|
||||
|
||||
rxtx["txFrameSizeNormal"] = acmIsFrameSizeNormal;
|
||||
rxtx["txIsPilots"] = acmIsPilots;
|
||||
|
||||
rxtx["dvbCcmModulation"] = extractModcodModulation(mod.modcod_tx);
|
||||
rxtx["dvbCcmSpeed"] = extractModcodSpeed(mod.modcod_tx);
|
||||
#endif
|
||||
|
||||
// демодулятор
|
||||
rxtx["rxAgcEn"] = dem.is_aru_on;
|
||||
rxtx["rxManualGain"] = dem.gain;
|
||||
rxtx["rxSpectrumInversion"] = dem.is_rvt_iq;
|
||||
rxtx["rxCentralFreq"] = dem.central_freq_in_kGz;
|
||||
rxtx["rxBaudrate"] = dem.baudrate;
|
||||
rxtx["rxRolloff"] = dem.rollof;
|
||||
#ifdef MODEM_IS_SCPC
|
||||
rxtx["rxGoldan"] = dem.gold_seq_is_active;
|
||||
#endif
|
||||
|
||||
#ifdef API_STRUCT_ACM_ENABLE
|
||||
// ACM
|
||||
#ifndef MODEM_IS_SHPS
|
||||
// в ШПС этих настроек нет
|
||||
rxtx["dvbServicePacketPeriod"] = acm.period_pack_acm;
|
||||
rxtx["dvbIsAcm"] = acm.enable_acm;
|
||||
|
||||
rxtx["dvbAcmMinModulation"] = extractModcodModulation(acm.min_modcod_acm);
|
||||
rxtx["dvbAcmMinSpeed"] = extractModcodSpeed(acm.min_modcod_acm);
|
||||
|
||||
rxtx["dvbAcmMaxModulation"] = extractModcodModulation(acm.max_modcod_acm);
|
||||
rxtx["dvbAcmMaxSpeed"] = extractModcodSpeed(acm.max_modcod_acm);
|
||||
|
||||
rxtx["dvbSnrReserve"] = acm.snr_threashold_acm; // запас ОСШ
|
||||
#endif
|
||||
|
||||
rxtx["aupcEn"] = acm.enable_aupc;
|
||||
rxtx["aupcMinAttenuation"] = acm.min_attenuation_aupc;
|
||||
rxtx["aupcMaxAttenuation"] = acm.max_attenuation_aupc;
|
||||
rxtx["aupcRequiredSnr"] = acm.snr_threashold_aupc;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef API_OBJECT_DPDI_SETTINGS_ENABLE
|
||||
{
|
||||
auto& dp = res["dpdi"];
|
||||
|
||||
dp["dpdiIsPositional"] = !dpdi.is_delay_window;
|
||||
#ifdef MODEM_IS_SCPC
|
||||
dp["dpdiSearchBandwidth"] = dpdi.freq_offset;
|
||||
#endif
|
||||
|
||||
dp["dpdiPositionStationLatitude"] = translateCoordinates(dpdi.latitude_station_grad, dpdi.latitude_station_minute);
|
||||
dp["dpdiPositionStationLongitude"] = translateCoordinates(dpdi.longitude_station_grad, dpdi.longitude_station_minute);
|
||||
dp["dpdiPositionSatelliteLongitude"] = translateCoordinates(dpdi.longitude_sattelite_grad, dpdi.longitude_sattelite_minute);
|
||||
|
||||
#ifdef MODEM_IS_SCPC
|
||||
dp["dpdiDelayMin"] = dpdi.min_delay;
|
||||
dp["dpdiDelayMax"] = dpdi.max_delay;
|
||||
#else
|
||||
dp["dpdiDelay"] = dpdi.max_delay;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// BucLnb
|
||||
#ifdef API_OBJECT_BUCLNB_SETTINGS_ENABLE
|
||||
{
|
||||
auto& bl = res["buclnb"];
|
||||
switch (buclnb.buc) {
|
||||
case voltage_buc::_24V: bl["bucPowering"] = 24; break;
|
||||
#ifdef MODEM_IS_SCPC
|
||||
case voltage_buc::_48V: bl["bucPowering"] = 48; break;
|
||||
#endif
|
||||
default: bl["bucPowering"] = 0;
|
||||
}
|
||||
|
||||
bl["bucRefClk10M"] = buclnb.is_ref_10MHz_buc;
|
||||
switch (buclnb.lnb) {
|
||||
case voltage_lnb::_13V: bl["lnbPowering"] = 13; break;
|
||||
case voltage_lnb::_18V: bl["lnbPowering"] = 18; break;
|
||||
case voltage_lnb::_24V: bl["lnbPowering"] = 24; break;
|
||||
default: bl["lnbPowering"] = 0;
|
||||
}
|
||||
bl["lnbRefClk10M"] = buclnb.is_ref_10MHz_lnb;
|
||||
|
||||
bl["srvRefClk10M"] = buclnb.is_ref_10MHz_output;
|
||||
bl["bucLnbAutoStart"] = buclnb.is_save_current_state;
|
||||
}
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
||||
api_driver::obj::TerminalRxTxSettings::~TerminalRxTxSettings() = default;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -7,8 +7,7 @@
|
||||
#include <fstream>
|
||||
#include <shared_mutex>
|
||||
#include <string>
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <boost/property_tree/ptree_fwd.hpp>
|
||||
//#include <boost/property_tree/ptree_fwd.hpp>
|
||||
|
||||
#include "common/nlohmann/json.hpp"
|
||||
|
||||
@ -32,7 +31,7 @@ namespace api_driver::obj {
|
||||
* @return {"en": bool, "logPeriodMs": int, "maxAgeMs": int}
|
||||
*/
|
||||
std::string getSettings();
|
||||
void setSettings(boost::property_tree::ptree &pt);
|
||||
void setSettings(const nlohmann::json& data);
|
||||
|
||||
void updateCallback(proxy::CpProxy& cp);
|
||||
/**
|
||||
@ -60,7 +59,7 @@ namespace api_driver::obj {
|
||||
static constexpr const char* DEFAULT_SERVER_NAME = "RSCM-101";
|
||||
#elif defined(MODEM_IS_TDMA)
|
||||
static constexpr const char* DEFAULT_SERVER_NAME = "TDMA Abonent";
|
||||
#elif defined(MODEM_IS_SHPC)
|
||||
#elif defined(MODEM_IS_SHPS)
|
||||
static constexpr const char* DEFAULT_SERVER_NAME = "SHPS Terminal";
|
||||
#else
|
||||
#error "Selected modem type not supported!"
|
||||
@ -80,9 +79,9 @@ namespace api_driver::obj {
|
||||
void loadDefaults();
|
||||
|
||||
void updateCallback(proxy::CpProxy& cp);
|
||||
void updateFromPt(boost::property_tree::ptree &pt);
|
||||
void updateFromJson(nlohmann::json& data);
|
||||
void store(proxy::CpProxy& cp);
|
||||
std::string asJson();
|
||||
nlohmann::json asJson();
|
||||
|
||||
~TerminalNetworkSettings();
|
||||
};
|
||||
@ -92,7 +91,7 @@ namespace api_driver::obj {
|
||||
class TerminalQosSettings {
|
||||
public:
|
||||
static constexpr const char* DEFAULT_QOS_CLASSES = R"({"rt1":[],"rt2":[],"rt3":[],"cd":[]})";
|
||||
std::string qosSettingsJson;
|
||||
nlohmann::json qosSettingsJson;
|
||||
bool qosEnabled = false;
|
||||
|
||||
TerminalQosSettings();
|
||||
@ -102,9 +101,9 @@ namespace api_driver::obj {
|
||||
void loadDefaults();
|
||||
|
||||
void updateCallback(proxy::CpProxy& cp);
|
||||
void updateFromPt(boost::property_tree::ptree &pt);
|
||||
void updateFromJson(nlohmann::json& data);
|
||||
void store(proxy::CpProxy& cp);
|
||||
std::string asJson();
|
||||
nlohmann::json asJson();
|
||||
|
||||
~TerminalQosSettings();
|
||||
};
|
||||
@ -116,18 +115,12 @@ namespace api_driver::obj {
|
||||
|
||||
TerminalFirmwareVersion();
|
||||
TerminalFirmwareVersion(const TerminalFirmwareVersion& src);
|
||||
~TerminalFirmwareVersion();
|
||||
|
||||
// logCpApiError("api_driver::TerminalApiDaemon::connectToApi()->CP_GetNetwork(version)", CP_GetNetwork(sid, "version", &f.version));
|
||||
// logCpApiError("api_driver::TerminalApiDaemon::connectToApi()->CP_GetNetwork(chip_id)", CP_GetNetwork(sid, "chip_id", &f.modemId));
|
||||
// rtrim(f.modemId);
|
||||
// logCpApiError("api_driver::TerminalApiDaemon::connectToApi()->CP_GetNetwork(serial)", CP_GetNetwork(sid, "serial", &f.modemSn));
|
||||
// logCpApiError("api_driver::TerminalApiDaemon::connectToApi()->CP_GetNetwork(mac_eth0)", CP_GetNetwork(sid, "mac_eth0", &f.macMang));
|
||||
// logCpApiError("api_driver::TerminalApiDaemon::connectToApi()->CP_GetNetwork(mac_eth1)", CP_GetNetwork(sid, "mac_eth1", &f.macData));
|
||||
void load(proxy::CpProxy& cp);
|
||||
std::string asJson();
|
||||
|
||||
TerminalFirmwareVersion& operator= (const TerminalFirmwareVersion& src);
|
||||
|
||||
void load(proxy::CpProxy& cp);
|
||||
nlohmann::json asJson();
|
||||
|
||||
~TerminalFirmwareVersion();
|
||||
};
|
||||
|
||||
/**
|
||||
@ -142,42 +135,42 @@ namespace api_driver::obj {
|
||||
bool fIsCinC = false;
|
||||
#endif
|
||||
|
||||
bool fRxState;
|
||||
bool fRxSymSyncLock;
|
||||
bool fRxFreqSearchLock;
|
||||
bool fRxAfcLock;
|
||||
bool fRxPktSync;
|
||||
bool fRxState{};
|
||||
bool fRxSymSyncLock{};
|
||||
bool fRxFreqSearchLock{};
|
||||
bool fRxAfcLock{};
|
||||
bool fRxPktSync{};
|
||||
|
||||
float fRxSnr;
|
||||
float fRxRssi;
|
||||
uint16_t fRxModcod;
|
||||
bool fRxFrameSizeNormal;
|
||||
bool fRxIsPilots;
|
||||
float fRxSnr{};
|
||||
float fRxRssi{};
|
||||
uint16_t fRxModcod{};
|
||||
bool fRxFrameSizeNormal{};
|
||||
bool fRxIsPilots{};
|
||||
|
||||
double fRxSymError;
|
||||
double fRxFreqErr;
|
||||
double fRxFreqErrAcc;
|
||||
double fRxInputSignalLevel;
|
||||
double fRxPllError;
|
||||
double fRxSpeedOnRxKbit;
|
||||
double fRxSpeedOnIifKbit;
|
||||
uint32_t fRxPacketsOk;
|
||||
uint32_t fRxPacketsBad;
|
||||
uint32_t fRxPacketsDummy;
|
||||
double fRxSymError{};
|
||||
double fRxFreqErr{};
|
||||
double fRxFreqErrAcc{};
|
||||
double fRxInputSignalLevel{};
|
||||
double fRxPllError{};
|
||||
double fRxSpeedOnRxKbit{};
|
||||
double fRxSpeedOnIifKbit{};
|
||||
uint32_t fRxPacketsOk{};
|
||||
uint32_t fRxPacketsBad{};
|
||||
uint32_t fRxPacketsDummy{};
|
||||
|
||||
uint16_t fTxModcod;
|
||||
double fTxSpeedOnTxKbit;
|
||||
double fTxSpeedOnIifKbit;
|
||||
uint16_t fTxModcod{};
|
||||
double fTxSpeedOnTxKbit{};
|
||||
double fTxSpeedOnIifKbit{};
|
||||
#ifdef MODEM_IS_SCPC
|
||||
float fTxSnr;
|
||||
bool fTxFrameSizeNormal;
|
||||
bool fTxIsPilots;
|
||||
double fCincOcc;
|
||||
bool fCincCorrelator;
|
||||
uint32_t fCincCorrelatorFails;
|
||||
int32_t fCincFreqErr;
|
||||
int32_t fCincFreqErrAcc;
|
||||
float fCincChannelDelay;
|
||||
float fTxSnr{};
|
||||
bool fTxFrameSizeNormal{};
|
||||
bool fTxIsPilots{};
|
||||
double fCincOcc{};
|
||||
bool fCincCorrelator{};
|
||||
uint32_t fCincCorrelatorFails{};
|
||||
int32_t fCincFreqErr{};
|
||||
int32_t fCincFreqErrAcc{};
|
||||
float fCincChannelDelay{};
|
||||
#endif
|
||||
#ifdef MODEM_IS_TDMA
|
||||
double fTxCenterFreq;
|
||||
@ -225,14 +218,40 @@ namespace api_driver::obj {
|
||||
};
|
||||
|
||||
class TerminalRxTxSettings {
|
||||
modulator_settings mod{};
|
||||
demodulator_settings dem{};
|
||||
#ifdef API_STRUCT_ACM_ENABLE
|
||||
ACM_parameters_serv_ acm{};
|
||||
#endif
|
||||
#ifdef API_OBJECT_DPDI_SETTINGS_ENABLE
|
||||
DPDI_parmeters dpdi{};
|
||||
#endif
|
||||
#ifdef API_OBJECT_BUCLNB_SETTINGS_ENABLE
|
||||
buc_lnb_settings buclnb{};
|
||||
#endif
|
||||
public:
|
||||
|
||||
// TODO описать все параметры для всех терминалов
|
||||
TerminalRxTxSettings();
|
||||
TerminalRxTxSettings(const TerminalRxTxSettings& src);
|
||||
TerminalRxTxSettings& operator= (const TerminalRxTxSettings& src);
|
||||
|
||||
void updateCallback(proxy::CpProxy& cp);
|
||||
void updateFromPt(boost::property_tree::ptree &pt);
|
||||
void store(proxy::CpProxy& cp);
|
||||
std::string asJson();
|
||||
|
||||
void updateMainSettings(const nlohmann::json& data);
|
||||
void storeMainSettings(proxy::CpProxy& cp);
|
||||
|
||||
#ifdef API_OBJECT_DPDI_SETTINGS_ENABLE
|
||||
void updateDpdiSettings(const nlohmann::json& data);
|
||||
void storeDpdiSettings(proxy::CpProxy& cp);
|
||||
#endif
|
||||
|
||||
#ifdef API_OBJECT_BUCLNB_SETTINGS_ENABLE
|
||||
void updateBuclnbSettings(const nlohmann::json& data);
|
||||
void storeBuclnbSettings(proxy::CpProxy& cp);
|
||||
#endif
|
||||
|
||||
void storeAll(proxy::CpProxy& cp);
|
||||
nlohmann::json asJson() const;
|
||||
|
||||
~TerminalRxTxSettings();
|
||||
};
|
||||
|
184
src/main.cpp
184
src/main.cpp
@ -11,7 +11,6 @@
|
||||
#include <boost/log/utility/setup/formatter_parser.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <boost/asio/ssl/context.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <fstream>
|
||||
@ -178,11 +177,9 @@ public:
|
||||
rep.headers.clear();
|
||||
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
|
||||
try {
|
||||
std::istringstream is(std::string(req.payload.data(), req.payload.size()));
|
||||
boost::property_tree::ptree pt;
|
||||
read_json(is, pt);
|
||||
auto reqJson = nlohmann::json::parse(std::string(req.payload.begin(), req.payload.end()));
|
||||
|
||||
auto u = auth.doAuth(pt.get<std::string>("username"), pt.get<std::string>("password"), req, rep);
|
||||
auto u = auth.doAuth(reqJson["username"], reqJson["username"], req, rep);
|
||||
if (u == nullptr) {
|
||||
throw std::runtime_error("invalid session");
|
||||
}
|
||||
@ -266,6 +263,7 @@ public:
|
||||
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||
}));
|
||||
|
||||
#ifdef API_OBJECT_QOS_SETTINGS_ENABLE
|
||||
s.resources.emplace_back(std::make_unique<http::auth::AuthRequiredResource>("/api/set/qos", this->auth, http::auth::User::SETUP_QOS, [this](const auto& req, auto& rep) {
|
||||
if (req.method != "POST") {
|
||||
http::server::stockReply(http::server::bad_request, rep);
|
||||
@ -274,26 +272,26 @@ public:
|
||||
|
||||
rep.status = http::server::ok;
|
||||
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
|
||||
nlohmann::json resultJson;
|
||||
|
||||
try {
|
||||
std::stringstream ss;
|
||||
ss.str(std::string(req.payload.begin(), req.payload.end()));
|
||||
boost::property_tree::ptree pt;
|
||||
read_json(ss, pt);
|
||||
|
||||
api->setQosSettings(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());
|
||||
auto reqJson = nlohmann::json::parse(std::string(req.payload.begin(), req.payload.end()));
|
||||
api->setQosSettings(reqJson);
|
||||
resultJson["status"] = "ok";
|
||||
resultJson["settings"] = api->loadSettings();
|
||||
} catch (std::exception& e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "WebHandle(/api/set/qos): Can't set QoS settings: " << e.what();
|
||||
const std::string result = R"({"status": "error", "error": )" + api_driver::buildEscapedString(e.what()) + "}";
|
||||
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||
resultJson.clear();
|
||||
resultJson["status"] = "error";
|
||||
resultJson["error"] = e.what();
|
||||
}
|
||||
}));
|
||||
|
||||
auto result = resultJson.dump();
|
||||
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||
}));
|
||||
#endif
|
||||
|
||||
#ifdef API_OBJECT_BUCLNB_SETTINGS_ENABLE
|
||||
s.resources.emplace_back(std::make_unique<http::auth::AuthRequiredResource>("/api/set/buclnb", 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);
|
||||
@ -303,25 +301,26 @@ public:
|
||||
rep.status = http::server::ok;
|
||||
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
|
||||
|
||||
nlohmann::json resultJson;
|
||||
|
||||
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());
|
||||
auto reqJson = nlohmann::json::parse(std::string(req.payload.begin(), req.payload.end()));
|
||||
api->setBucLnbSettings(reqJson);
|
||||
resultJson["status"] = "ok";
|
||||
resultJson["settings"] = api->loadSettings();
|
||||
} catch (std::exception& e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "WebHandle(/api/set/buclnb): Can't set BUC LNB settings: " << e.what();
|
||||
const std::string result = R"({"status": "error", "error": )" + api_driver::buildEscapedString(e.what()) + "}";
|
||||
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||
resultJson.clear();
|
||||
resultJson["status"] = "error";
|
||||
resultJson["error"] = e.what();
|
||||
}
|
||||
}));
|
||||
|
||||
auto result = resultJson.dump();
|
||||
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||
}));
|
||||
#endif
|
||||
|
||||
#ifdef API_OBJECT_DPDI_SETTINGS_ENABLE
|
||||
s.resources.emplace_back(std::make_unique<http::auth::AuthRequiredResource>("/api/set/dpdi", 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);
|
||||
@ -330,25 +329,24 @@ public:
|
||||
|
||||
rep.status = http::server::ok;
|
||||
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
|
||||
nlohmann::json resultJson;
|
||||
|
||||
try {
|
||||
std::stringstream ss;
|
||||
ss.str(std::string(req.payload.begin(), req.payload.end()));
|
||||
boost::property_tree::ptree pt;
|
||||
read_json(ss, pt);
|
||||
|
||||
api->setDpdiSettings(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());
|
||||
auto reqJson = nlohmann::json::parse(std::string(req.payload.begin(), req.payload.end()));
|
||||
api->setDpdiSettings(reqJson);
|
||||
resultJson["status"] = "ok";
|
||||
resultJson["settings"] = api->loadSettings();
|
||||
} catch (std::exception& e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "WebHandle(/api/set/dpdi): Can't set DPDI settings: " << e.what();
|
||||
const std::string result = R"({"status": "error", "error": )" + api_driver::buildEscapedString(e.what()) + "}";
|
||||
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||
resultJson.clear();
|
||||
resultJson["status"] = "error";
|
||||
resultJson["error"] = e.what();
|
||||
}
|
||||
|
||||
auto result = resultJson.dump();
|
||||
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||
}));
|
||||
#endif
|
||||
|
||||
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") {
|
||||
@ -358,26 +356,25 @@ public:
|
||||
|
||||
rep.status = http::server::ok;
|
||||
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
|
||||
nlohmann::json resultJson;
|
||||
|
||||
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());
|
||||
auto reqJson = nlohmann::json::parse(std::string(req.payload.begin(), req.payload.end()));
|
||||
api->setRxTxSettings(reqJson);
|
||||
resultJson["status"] = "ok";
|
||||
resultJson["settings"] = api->loadSettings();
|
||||
} 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", "error": )" + api_driver::buildEscapedString(e.what()) + "}";
|
||||
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||
resultJson.clear();
|
||||
resultJson["status"] = "error";
|
||||
resultJson["error"] = e.what();
|
||||
}
|
||||
|
||||
auto result = resultJson.dump();
|
||||
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||
}));
|
||||
|
||||
#ifdef API_OBJECT_NETWORK_SETTINGS_ENABLE
|
||||
s.resources.emplace_back(std::make_unique<http::auth::AuthRequiredResource>("/api/set/network", 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);
|
||||
@ -386,25 +383,24 @@ public:
|
||||
|
||||
rep.status = http::server::ok;
|
||||
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
|
||||
nlohmann::json resultJson;
|
||||
|
||||
try {
|
||||
std::stringstream ss;
|
||||
ss.str(std::string(req.payload.begin(), req.payload.end()));
|
||||
boost::property_tree::ptree pt;
|
||||
read_json(ss, pt);
|
||||
|
||||
api->setNetworkSettings(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());
|
||||
auto reqJson = nlohmann::json::parse(std::string(req.payload.begin(), req.payload.end()));
|
||||
api->setNetworkSettings(reqJson);
|
||||
resultJson["status"] = "ok";
|
||||
resultJson["settings"] = api->loadSettings();
|
||||
} catch (std::exception& e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "WebHandle(/api/set/network): Can't set network settings: " << e.what();
|
||||
const std::string result = R"({"status": "error", "error": )" + api_driver::buildEscapedString(e.what()) + "}";
|
||||
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||
resultJson.clear();
|
||||
resultJson["status"] = "error";
|
||||
resultJson["error"] = e.what();
|
||||
}
|
||||
|
||||
auto result = resultJson.dump();
|
||||
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||
}));
|
||||
#endif
|
||||
|
||||
s.resources.emplace_back(std::make_unique<http::auth::AuthRequiredResource>("/api/reboot", this->auth, 0, [this](const auto& req, auto& rep) {
|
||||
if (req.method != "POST") {
|
||||
@ -511,34 +507,38 @@ public:
|
||||
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
|
||||
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||
}));
|
||||
#ifdef MODEM_IS_SCPC
|
||||
#ifdef API_OBJECT_DEBUG_METRICS_ENABLE
|
||||
s.resources.emplace_back(std::make_unique<http::auth::AuthRequiredResource>("/dev/settings", this->auth, http::auth::User::DEVELOPER, [this](const auto& req, auto& rep) {
|
||||
std::string result;
|
||||
if (req.method == "GET") {
|
||||
result = R"({"status":"ok","logstat":)";
|
||||
result += this->api->getLoggingStatisticsSettings();
|
||||
result += "}";
|
||||
} else if (req.method == "POST") {
|
||||
std::stringstream ss;
|
||||
ss.str(std::string(req.payload.begin(), req.payload.end()));
|
||||
boost::property_tree::ptree pt;
|
||||
read_json(ss, pt);
|
||||
nlohmann::json resultJson;
|
||||
|
||||
api->setLoggingStatisticsSettings(pt);
|
||||
try {
|
||||
if (req.method == "GET") {
|
||||
resultJson["status"] = "ok";
|
||||
resultJson["logstat"] = api->getLoggingStatisticsSettings();
|
||||
} else if (req.method == "POST") {
|
||||
auto reqJson = nlohmann::json::parse(std::string(req.payload.begin(), req.payload.end()));
|
||||
api->setQosSettings(reqJson);
|
||||
|
||||
result = R"({"status":"ok","logstat":)";
|
||||
result += this->api->getLoggingStatisticsSettings();
|
||||
result += "}";
|
||||
} else {
|
||||
http::server::stockReply(http::server::bad_request, rep);
|
||||
return;
|
||||
resultJson["status"] = "ok";
|
||||
resultJson["logstat"] = api->getLoggingStatisticsSettings();
|
||||
} else {
|
||||
rep.status = http::server::bad_request;
|
||||
resultJson["status"] = "error";
|
||||
resultJson["error"] = "unsupported request type";
|
||||
}
|
||||
} catch (std::exception& e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "WebHandle(/api/set/qos): Can't set QoS settings: " << e.what();
|
||||
resultJson.clear();
|
||||
resultJson["status"] = "error";
|
||||
resultJson["error"] = e.what();
|
||||
}
|
||||
|
||||
rep.status = http::server::ok;
|
||||
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
|
||||
auto result = resultJson.dump();
|
||||
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||
}));
|
||||
#endif
|
||||
|
||||
#ifdef API_OBJECT_DEBUG_METRICS_ENABLE
|
||||
s.resources.emplace_back(std::make_unique<http::auth::AuthRequiredResource>("/dev/logs.csv", this->auth, http::auth::User::DEVELOPER, [this](const auto& req, auto& rep) {
|
||||
if (req.method != "GET") {
|
||||
http::server::stockReply(http::server::bad_request, rep);
|
||||
|
@ -64,59 +64,6 @@ void api_driver::ApiDriver::resetPacketStatistics() const {
|
||||
this->daemon->resetPacketStatistics();
|
||||
}
|
||||
|
||||
#ifdef MODEM_IS_SCPC
|
||||
struct ModcodDef_t {const char* modulation; const char* speed;};
|
||||
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 ? ModcodDefs : ModcodDefs + 1;
|
||||
if (modcod < (sizeof(ModcodDefs) / sizeof(ModcodDef_t))) {
|
||||
d = ModcodDefs + modcod;
|
||||
}
|
||||
return d->modulation;
|
||||
}
|
||||
|
||||
static const char* extractModcodSpeed(uint32_t modcod, bool defaultQpsk1_4 = true) {
|
||||
modcod >>= 2;
|
||||
const auto* d = defaultQpsk1_4 ? ModcodDefs : ModcodDefs + 1;
|
||||
if (modcod < (sizeof(ModcodDefs) / sizeof(ModcodDef_t))) {
|
||||
d = ModcodDefs + modcod;
|
||||
}
|
||||
return d->speed;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::string api_driver::ApiDriver::loadSettings() const {
|
||||
if (daemon == nullptr) {
|
||||
return R"({"error": "api daemon not started!"})";
|
||||
@ -142,43 +89,23 @@ 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, bool isPilots = false) {
|
||||
uint32_t modcod = 0;
|
||||
const auto mod = pt.get<std::string>(name + "Modulation");
|
||||
const auto speed = pt.get<std::string>(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) | (isPilots ? 1 : 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
void api_driver::ApiDriver::setRxTxSettings(boost::property_tree::ptree &pt) {
|
||||
void api_driver::ApiDriver::setRxTxSettings(const nlohmann::json& data) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void api_driver::ApiDriver::setDpdiSettings(boost::property_tree::ptree &pt) {
|
||||
void api_driver::ApiDriver::setDpdiSettings(const nlohmann::json& data) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void api_driver::ApiDriver::setBucLnbSettings(boost::property_tree::ptree &pt) {
|
||||
void api_driver::ApiDriver::setBucLnbSettings(const nlohmann::json& data) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void api_driver::ApiDriver::setQosSettings(boost::property_tree::ptree &pt) {
|
||||
void api_driver::ApiDriver::setQosSettings(const nlohmann::json& data) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void api_driver::ApiDriver::setNetworkSettings(boost::property_tree::ptree &pt) {
|
||||
void api_driver::ApiDriver::setNetworkSettings(const nlohmann::json& data) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@ -208,8 +135,8 @@ std::string api_driver::ApiDriver::getLoggingStatisticsSettings() {
|
||||
return this->daemon->statsLogs.getSettings();
|
||||
}
|
||||
|
||||
void api_driver::ApiDriver::setLoggingStatisticsSettings(boost::property_tree::ptree &pt) {
|
||||
this->daemon->statsLogs.setSettings(pt);
|
||||
void api_driver::ApiDriver::setLoggingStatisticsSettings(const nlohmann::json& data) {
|
||||
this->daemon->statsLogs.setSettings(data);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -5,8 +5,8 @@
|
||||
#include "api-driver/proxy.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
|
||||
#include "common/nlohmann/json.hpp"
|
||||
|
||||
namespace api_driver {
|
||||
constexpr int CACHE_STATISTICS_UPDATE_MS = 500; ///< время обновления кеша статистики модулятора/демодулятора
|
||||
@ -46,32 +46,32 @@ namespace api_driver {
|
||||
/**
|
||||
* Установить настройки RX/TX, readback можно получить используя loadTerminalState
|
||||
*/
|
||||
void setRxTxSettings(boost::property_tree::ptree &pt);
|
||||
void setRxTxSettings(const nlohmann::json& data);
|
||||
|
||||
#ifdef API_OBJECT_DPDI_SETTINGS_ENABLE
|
||||
/**
|
||||
* Установить настройки DPDI, readback можно получить используя loadTerminalState.
|
||||
* @note Для TDMA и SCPC модемов эти настройки доступны
|
||||
*/
|
||||
void setDpdiSettings(boost::property_tree::ptree &pt);
|
||||
void setDpdiSettings(const nlohmann::json& data);
|
||||
#endif
|
||||
|
||||
#ifdef API_OBJECT_BUCLNB_SETTINGS_ENABLE
|
||||
/**
|
||||
* Установить настройки BUC и LNB, readback можно получить используя loadTerminalState.
|
||||
*/
|
||||
void setBucLnbSettings(boost::property_tree::ptree &pt);
|
||||
void setBucLnbSettings(const nlohmann::json& data);
|
||||
#endif
|
||||
|
||||
#ifdef API_OBJECT_QOS_SETTINGS_ENABLE
|
||||
/**
|
||||
* Установить настройки QoS, readback можно получить используя loadTerminalState.
|
||||
*/
|
||||
void setQosSettings(boost::property_tree::ptree &pt);
|
||||
void setQosSettings(const nlohmann::json& data);
|
||||
#endif
|
||||
|
||||
#ifdef API_OBJECT_NETWORK_SETTINGS_ENABLE
|
||||
void setNetworkSettings(boost::property_tree::ptree &pt);
|
||||
void setNetworkSettings(const nlohmann::json& data);
|
||||
#endif
|
||||
|
||||
void resetDefaultSettings();
|
||||
@ -80,7 +80,7 @@ namespace api_driver {
|
||||
|
||||
#ifdef API_OBJECT_DEBUG_METRICS_ENABLE
|
||||
std::string getLoggingStatisticsSettings();
|
||||
void setLoggingStatisticsSettings(boost::property_tree::ptree &pt);
|
||||
void setLoggingStatisticsSettings(const nlohmann::json& data);
|
||||
|
||||
/**
|
||||
* Получить статистику в формате json. Выход будет дописан в вектор
|
||||
|
Loading…
x
Reference in New Issue
Block a user