сделал частично работающую статистику

This commit is contained in:
2024-10-31 15:29:57 +03:00
parent e8eeee3755
commit a7f323a07c
9 changed files with 565 additions and 86 deletions

5
src/auth/resources.cpp Normal file
View File

@@ -0,0 +1,5 @@
//
// Created by vlad on 31.10.2024.
//
#include "resources.h"

28
src/auth/resources.h Normal file
View File

@@ -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

View File

@@ -75,7 +75,10 @@ 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/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>("/images/krokodil_vzryvaetsya_hd.gif", "static/krokodil.gif", mime_types::image_gif));
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

@@ -2,6 +2,36 @@
#include "terminal_api/ControlProtoCInterface.h"
#include <sstream>
/*
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<uint32_t>(txpwd) >> 2));
uint8_t type_pack = static_cast<uint8_t>(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<uint8_t>(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<uint32_t>(tmp) >> 2);
if (static_cast<uint8_t>(tmp) & 0b00000010) {
result << R"(,"tx.frameSize":"short")";
} else {
result << R"(,"tx.frameSize":"normal")";
}
if (static_cast<uint8_t>(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<Wt::WPushButton>("Обновить"), 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;