сделал получение параметров через api, немного подредачил фронт

This commit is contained in:
2024-10-30 18:00:48 +03:00
parent 9037c6b329
commit e8eeee3755
5 changed files with 268 additions and 55 deletions

View File

@@ -73,7 +73,8 @@ void init_logging() {
}
static void initResources(http::server::Server& s, std::shared_ptr<api_driver::ApiDriver>& api) {
s.resources.emplace_back(std::make_unique<http::resource::StaticFileResource>("/", "static/login.html", mime_types::text_html));
s.resources.emplace_back(std::make_unique<http::resource::StaticFileResource>("/", "static/main.html", mime_types::text_html));
s.resources.emplace_back(std::make_unique<http::resource::StaticFileResource>("/login", "static/login.html", mime_types::text_html));
s.resources.emplace_back(std::make_unique<http::resource::StaticFileResource>("/favicon.ico", "static/favicon.png", mime_types::image_png));
s.resources.emplace_back(std::make_unique<http::resource::StaticFileResource>("/style.css", "static/style.css", mime_types::text_css));
s.resources.emplace_back(std::make_unique<http::resource::StaticFileResource>("/js/vue.js", "static/js/vue.js", mime_types::javascript));

View File

@@ -1,26 +1,73 @@
#include "terminal_api_driver.h"
#include "terminal_api/ControlProtoCInterface.h"
#include <sstream>
api_driver::ApiDriver::ApiDriver() {
CP_Login("admin", "pass", &sid, &access);
}
static bool DriverCP_GetLevelDemod(TSID sid, const char* param) {
double variable_dbl = 0;
CP_GetLevelDemod(sid, param, &variable_dbl);
return variable_dbl == 0;
}
static bool DriverCP_GetGain(TSID sid, const char* param) {
double variable_dbl = 0;
CP_GetGain(sid, param, &variable_dbl);
return variable_dbl == 0;
}
static const char* boolAsStr(bool value) {
return value ? "true" : "false";
}
std::string api_driver::ApiDriver::loadTerminalState() {
std::stringstream result;
result << "{";
return R"({"rxState":0,"txState":0,"testState":0})";
}
result << "\"txState\":" << boolAsStr(DriverCP_GetGain(sid, "TXPWD"));
std::string api_driver::ApiDriver::loadTxStatistics() {
return R"("{"error":"no impl"}")";
}
const auto sym_sync_lock = DriverCP_GetLevelDemod(sid, "sym_sync_lock"); // захват символьной
const auto freq_search_lock = DriverCP_GetLevelDemod(sid, "freq_lock"); // Захват поиска по частоте
const auto afc_lock = DriverCP_GetLevelDemod(sid, "afc_lock"); // захват ФАПЧ
const auto pkt_sync = DriverCP_GetLevelDemod(sid, "pkt_sync"); // захват пакетной синхронизации
const auto receive_active = sym_sync_lock && freq_search_lock && afc_lock && pkt_sync;
std::string api_driver::ApiDriver::loadRxStatistics() {
return R"("{"error":"no impl"}")";
result << ",\"rxState\":" << boolAsStr(receive_active);
result << ",\"rx.sym_sync_lock\":" << boolAsStr(sym_sync_lock);
result << ",\"rx.freq_search_lock\":" << boolAsStr(freq_search_lock);
result << ",\"rx.afc_lock\":" << boolAsStr(afc_lock);
result << ",\"rx.pkt_sync\":" << boolAsStr(pkt_sync);
result << "}";
// return R"({"rxState":0,"txState":0,"testState":0})";
return result.str();
}
std::string api_driver::ApiDriver::loadDeviceStatistics() {
return R"("{"error":"no impl"}")";
std::stringstream result;
result << "{";
result << "\"txState\":" << boolAsStr(DriverCP_GetGain(sid, "TXPWD"));
const auto sym_sync_lock = DriverCP_GetLevelDemod(sid, "sym_sync_lock"); // захват символьной
const auto freq_search_lock = DriverCP_GetLevelDemod(sid, "freq_lock"); // Захват поиска по частоте
const auto afc_lock = DriverCP_GetLevelDemod(sid, "afc_lock"); // захват ФАПЧ
const auto pkt_sync = DriverCP_GetLevelDemod(sid, "pkt_sync"); // захват пакетной синхронизации
const auto receive_active = sym_sync_lock && freq_search_lock && afc_lock && pkt_sync;
result << ",\"rxState\":" << boolAsStr(receive_active);
result << ",\"rx.sym_sync_lock\":" << boolAsStr(sym_sync_lock);
result << ",\"rx.freq_search_lock\":" << boolAsStr(freq_search_lock);
result << ",\"rx.afc_lock\":" << boolAsStr(afc_lock);
result << ",\"rx.pkt_sync\":" << boolAsStr(pkt_sync);
result << "}";
// return R"({"rxState":0,"txState":0,"testState":0})";
return result.str();
}
api_driver::ApiDriver::~ApiDriver() = default;

View File

@@ -15,14 +15,14 @@ namespace api_driver {
/**
* Запросить общее состояние терминала
* @return {"rxState":0,"txState":0,"testState":0}
* @return {"txState":false,"rxState":false,"rx.sym_sync_lock":false,"rx.freq_search_lock":false,"rx.afc_lock":false,"rx.pkt_sync":false}
*/
std::string loadTerminalState();
std::string loadTxStatistics();
std::string loadRxStatistics();
/**
* Запросить статистику модулятора, демодулятора, CicC и температурные датчики
* @return
*/
std::string loadDeviceStatistics();
~ApiDriver();