diff --git a/CMakeLists.txt b/CMakeLists.txt index 467b7ca..8c9e9f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,8 @@ add_executable(terminal-web-server src/server/resource.h src/terminal_api_driver.h src/terminal_api_driver.cpp + src/auth/resources.cpp + src/auth/resources.h ) find_package(Boost 1.53.0 COMPONENTS system thread filesystem log log_setup REQUIRED) diff --git a/src/auth/resources.cpp b/src/auth/resources.cpp new file mode 100644 index 0000000..a925565 --- /dev/null +++ b/src/auth/resources.cpp @@ -0,0 +1,5 @@ +// +// Created by vlad on 31.10.2024. +// + +#include "resources.h" diff --git a/src/auth/resources.h b/src/auth/resources.h new file mode 100644 index 0000000..f36bd5b --- /dev/null +++ b/src/auth/resources.h @@ -0,0 +1,28 @@ +#ifndef RESOURCES_H +#define RESOURCES_H +#include "../server/resource.h" + +namespace http::auth { + /** + * Класс пользовательских разрешений, + */ + class UserPremision{}; + + /** + * Класс пользователя, содержит логин/хеш_пароля/настройки пользователя/права + */ + class User{}; + + /** + * Класс аутентификации. Управляет всеми сессиями, создает новые при логине, удаляет при логауте. + * @note Класс устанавливает заголовок 'Set-Cookie' в ответе, и этот заголовок должен дойти до пользователя! + */ + class AuthProvider { + + }; + + class NeedAuentificationResource: public resource::BasicResource {}; + +} + +#endif //RESOURCES_H diff --git a/src/main.cpp b/src/main.cpp index d28565a..b30a8d2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -75,7 +75,10 @@ void init_logging() { static void initResources(http::server::Server& s, std::shared_ptr& api) { s.resources.emplace_back(std::make_unique("/", "static/main.html", mime_types::text_html)); s.resources.emplace_back(std::make_unique("/login", "static/login.html", mime_types::text_html)); + s.resources.emplace_back(std::make_unique("/favicon.ico", "static/favicon.png", mime_types::image_png)); + s.resources.emplace_back(std::make_unique("/images/krokodil_vzryvaetsya_hd.gif", "static/krokodil.gif", mime_types::image_gif)); + s.resources.emplace_back(std::make_unique("/style.css", "static/style.css", mime_types::text_css)); s.resources.emplace_back(std::make_unique("/js/vue.js", "static/js/vue.js", mime_types::javascript)); diff --git a/src/terminal_api_driver.cpp b/src/terminal_api_driver.cpp index a981f8d..c5d2dd0 100644 --- a/src/terminal_api_driver.cpp +++ b/src/terminal_api_driver.cpp @@ -2,6 +2,36 @@ #include "terminal_api/ControlProtoCInterface.h" #include +/* +timer_->timeout().connect([=]{ + double txpwd = 0; + CP_GetGain(sid, "TXPWD", &txpwd); + transmitt_active->set_end(!txpwd); + CP_GetLevelDemod(sid, "modcod_tx", &txpwd); + modcod_tx->setText(std::to_string(static_cast(txpwd) >> 2)); + uint8_t type_pack = static_cast(txpwd); + type_pack = type_pack & 0b00000010; + if(type_pack) + type_pack_lbl->setText("short"); + else + type_pack_lbl->setText("normal"); + + uint8_t is_pilots = static_cast(txpwd); + is_pilots = is_pilots & 0b00000001; + if(is_pilots) + pilot_lbl->setText("pilots"); + else + pilot_lbl->setText("no pilots"); + + CP_GetLevelDemod(sid, "snr_acm", &txpwd); + std::stringstream buf_double; + buf_double << std::fixed << + std::setprecision(2) << txpwd; + snr_acm->setText(buf_double.str()); +}); + + */ + api_driver::ApiDriver::ApiDriver() { CP_Login("admin", "pass", &sid, &access); } @@ -26,48 +56,166 @@ std::string api_driver::ApiDriver::loadTerminalState() { std::stringstream result; result << "{"; - result << "\"txState\":" << boolAsStr(DriverCP_GetGain(sid, "TXPWD")); + { + // формируем структуру TX - 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 << "\"tx.state\":" << boolAsStr(DriverCP_GetGain(sid, "TXPWD")); + + double tmp = 0; + char tmpStr[64]; + + CP_GetLevelDemod(sid, "snr_acm", &tmp); + sprintf(tmpStr, "%.2f", tmp); + result << ",\"tx.snr\":" << tmpStr; + + CP_GetLevelDemod(sid, "modcod_tx", &tmp); + result << ",\"tx.modcod\":" << (static_cast(tmp) >> 2); + + if (static_cast(tmp) & 0b00000010) { + result << R"(,"tx.frameSize":"short")"; + } else { + result << R"(,"tx.frameSize":"normal")"; + } + + if (static_cast(tmp) & 0b00000001) { + result << R"(,"tx.pilots":"pilots")"; + } else { + result << R"(,"tx.pilots":"no pilots")"; + } + + std::string speed; + CP_GetDmaDebug(sid, "speed_tx", &speed); + sprintf(tmpStr, "%.3f", std::atof(speed.c_str()) / 128.0); + result << ",\"tx.speedOnTxKbit\":" << tmpStr; + + CP_GetDmaDebug(sid, "speed_tx_iface", &speed); + sprintf(tmpStr, "%.3f", std::atof(speed.c_str()) / 128.0); + result << ",\"tx.speedOnIifKbit\":" << tmpStr; + } + + { + // формируем структуру RX + + 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 << ",\"rx.state\":" << 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); + + double tmpd = 0; uint32_t tmpu32 = 0; + char tmpStr[64]; + + /* + rx: { + // индикаторы + state: '?', // общее состояние + sym_sync_lock: '?', // захват символьной + freq_search_lock: '?', // Захват поиска по частоте + afc_lock: '?', // захват ФАПЧ + pkt_sync: '?', // захват пакетной синхронизации + + // куча других параметров, идет в том же порядке, что и в таблице + snr: 0, rssi: -105, + modcod: 0, frameSize: 0, + pilots: '?', + symError: 0.0, + freqErr: 0, freqErrAcc: 0, + inputSignalLevel: 0, + pllError: 0, + speedOnRxKbit: 0, + speedOnIifKbit: 0, + + // статистика пакетов + packetsOk: 0, + packetsBad: 0, + packetsDummy: 0, + }, + + testState: '?' + */ + + CP_GetLevelDemod(sid, "snr", &tmpd); + sprintf(tmpStr, "%.2f", tmpd); + result << ",\"rx.snr\":" << tmpStr; + + CP_GetLevelDemod(sid, "rssi", &tmpd); + sprintf(tmpStr, "%.2f", tmpd); + result << ",\"rx.rssi\":" << tmpStr; + + CP_GetDemodulatorParams(sid, "modcod", &tmpu32); + result << ",\"rx.modcod\":" << tmpu32; + + CP_GetDemodulatorParams(sid, "type_pack", &tmpu32); + if (tmpu32) { + result << R"(,"rx.frameSize":"short")"; + } else { + result << R"(,"rx.frameSize":"normal")"; + } + + CP_GetDemodulatorParams(sid, "is_pilots", &tmpu32); + if (tmpu32) { + result << R"(,"rx.pilots":"pilots")"; + } else { + result << R"(,"rx.pilots":"no pilots")"; + } + + CP_GetLevelDemod(sid, "sym_err", &tmpd); + sprintf(tmpStr, "%.2f", tmpd); + result << ",\"rx.symError\":" << tmpStr; + + CP_GetLevelDemod(sid, "crs_freq_err", &tmpd); // freqErr + sprintf(tmpStr, "%.2f", tmpd); + result << ",\"rx.freqErr\":" << tmpStr; + + CP_GetLevelDemod(sid, "fine_freq_err", &tmpd); // freqErrAcc + sprintf(tmpStr, "%.2f", tmpd); + result << ",\"rx.freqErrAcc\":" << tmpStr; + + CP_GetModulatorParams(sid, "if_overload", &tmpu32); // inputSignalLevel + result << ",\"rx.inputSignalLevel\":" << tmpStr; + + CP_GetLevelDemod(sid, "afc_err", &tmpd); // PLL + sprintf(tmpStr, "%.2f", tmpd); + result << ",\"rx.pllError\":" << tmpStr; + + std::string speed; + CP_GetDmaDebug(sid, "speed_rx", &speed); + sprintf(tmpStr, "%.3f", std::atof(speed.c_str()) / 128.0); + result << ",\"rx.speedOnRxKbit\":" << tmpStr; + + speed.clear(); CP_GetDmaDebug(sid, "speed_rx_iface", &speed); + sprintf(tmpStr, "%.3f", std::atof(speed.c_str()) / 128.0); + result << ",\"rx.speedOnIifKbit\":" << tmpStr; + + speed.clear(); CP_GetDmaDebug(sid, "packet_ok_rx", &speed); + result << ",\"rx.packetsOk\":" << std::atoi(speed.c_str()); + + speed.clear(); CP_GetDmaDebug(sid, "drop_bad_rx", &speed); + result << ",\"rx.packetsBad\":" << std::atoi(speed.c_str()); + + CP_GetDemodulatorParams(sid, "dummy_cnt", &tmpu32); + result << ",\"rx.packetsDummy\":" << tmpu32; + + // auto reset_btn = m_lay->addWidget(std::make_unique("Обновить"), 3, 0); + // reset_btn->setMaximumSize(95, 50); + // reset_btn->clicked().connect([=] + // { + // std::string var = ""; + // CP_GetDmaDebug(sid, "reset_cnt_rx", &var); + // }); + } - 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() { - 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; diff --git a/static/krokodil.gif b/static/krokodil.gif new file mode 100644 index 0000000..faa7900 Binary files /dev/null and b/static/krokodil.gif differ diff --git a/static/login-failed.html b/static/login-failed.html new file mode 100644 index 0000000..793ed81 --- /dev/null +++ b/static/login-failed.html @@ -0,0 +1,99 @@ + + + + + + RSCM-101 | Вход + + + + + +
+

Вход

+
+ {% csrf_token %} +
+ Неверный логин или пароль +
+ +
+ + +
+ +
+ + +
+ +
+ +
+
+
+ + + + \ No newline at end of file diff --git a/static/login.html b/static/login.html index 07a3c67..1a2a57d 100644 --- a/static/login.html +++ b/static/login.html @@ -3,7 +3,7 @@ - Вход + RSCM-101 | Вход