какая-то куча изменений
This commit is contained in:
206
src/api-driver/structs.cpp
Normal file
206
src/api-driver/structs.cpp
Normal file
@@ -0,0 +1,206 @@
|
||||
#include "api-driver/structs.h"
|
||||
|
||||
#include <iomanip>
|
||||
|
||||
#include "api-driver/proxy.h"
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, CP_Result result) {
|
||||
switch (result) {
|
||||
case OK: out << "OK"; break;
|
||||
case TIMEOUT: out << "TIMEOUT"; break;
|
||||
case ERROR: out << "ERROR"; break;
|
||||
case ABORT: out << "ABORT"; break;
|
||||
case BUSY: out << "BUSY"; break;
|
||||
default:
|
||||
out << static_cast<int>(result);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string makeTimepointFromMillis(int64_t unix_time_ms) {
|
||||
// Преобразуем миллисекунды в микросекунды для std::chrono
|
||||
auto time_point = std::chrono::time_point<std::chrono::system_clock,
|
||||
std::chrono::microseconds>(std::chrono::microseconds(unix_time_ms * 1000));
|
||||
|
||||
auto tp = std::chrono::system_clock::to_time_t(time_point);
|
||||
tm* t = std::localtime(&tp);
|
||||
|
||||
std::stringstream ss;
|
||||
ss << std::put_time(t, "%Y-%m-%d %H:%M:%S");
|
||||
auto ms = (unix_time_ms % 1000);
|
||||
ss << '.' << std::setw(3) << std::setfill('0') << ms;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
bool api_driver::obj::CpUpdatebleObject::checkNeedUpdate(int64_t now) const {
|
||||
if (updatePeriodMs < 0) return false;
|
||||
// тут нет смысла спать меньше чем на 20мс, поэтому можно разрешить чтение на некоторое время раньше
|
||||
return now - lastUpdate >= (updatePeriodMs - 20);
|
||||
}
|
||||
int64_t api_driver::obj::CpUpdatebleObject::getNextUpdate(int64_t now) const {
|
||||
if (checkNeedUpdate(now)) {
|
||||
return 0;
|
||||
}
|
||||
auto next = now - lastUpdate;
|
||||
return next < 0 ? 0 : next;
|
||||
}
|
||||
api_driver::obj::CpUpdatebleObject::~CpUpdatebleObject() = default;
|
||||
|
||||
|
||||
void api_driver::obj::TerminalState::updateCallback(TSID sid, CP_Result &lastCpError) {
|
||||
constexpr const char* thisFunc = "api_driver::obj::TerminalState::load()";
|
||||
|
||||
modulator_state modulator{};
|
||||
demodulator_state demodulator{};
|
||||
#ifdef MODEM_IS_SCPC
|
||||
CinC_state cinc{};
|
||||
#endif
|
||||
|
||||
proxy::getModState(sid, modulator, thisFunc);
|
||||
proxy::getDemodState(sid, demodulator, thisFunc);
|
||||
#ifdef MODEM_IS_TDMA
|
||||
const auto tmpDevState = proxy::getDmaDebug(sid, "status_init", thisFunc);
|
||||
#endif
|
||||
|
||||
#ifdef MODEM_IS_SCPC
|
||||
bool isCinC = getIsCinC();
|
||||
if (isCinC) {
|
||||
logCpApiError("api_driver::TerminalApiDaemon::updateState()->CP_GetCinCState()", CP_GetCinCState(sid, cinc));
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
std::lock_guard lock2(this->mutex);
|
||||
#ifdef MODEM_IS_TDMA
|
||||
this->fInitState = tmpDevState;
|
||||
#endif
|
||||
this->fTxState = modulator.is_tx_on;
|
||||
this->fTxModcod = modulator.modcod;
|
||||
this->fTxSnr = modulator.snr_remote;
|
||||
this->fTxframeSizeNormal = modulator.snr_remote;
|
||||
this->fTx = modulator.snr_remote;
|
||||
this->fTx = modulator.snr_remote;
|
||||
this->fTx = modulator.snr_remote;
|
||||
#ifdef MODEM_IS_SCPC
|
||||
result << ",\"tx.snr\":"; writeDouble(result, modulator.snr_remote);
|
||||
|
||||
if (modulator.is_short) { result << R"(,"tx.frameSizeNormal":false)"; }
|
||||
else { result << R"(,"tx.frameSizeNormal":true)"; }
|
||||
|
||||
if (modulator.is_pilots) { result << R"(,"tx.isPilots":true)"; }
|
||||
else { result << R"(,"tx.isPilots":false)"; }
|
||||
#else
|
||||
{
|
||||
modulator_settings modSet{};
|
||||
daemon->getSettings(&modSet, nullptr, nullptr, nullptr);
|
||||
result << ",\"tx.centerFreq\":"; writeDouble(result, modSet.central_freq_in_kGz);
|
||||
result << ",\"tx.symSpeed\":"; writeDouble(result, (static_cast<double>(modSet.baudrate) / 1000.0));
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
||||
|
||||
result << ",\"tx.speedOnTxKbit\":"; writeDouble(result, static_cast<double>(modulator.speed_in_bytes_tx) / 128.0);
|
||||
result << ",\"tx.speedOnIifKbit\":"; writeDouble(result, (static_cast<double>(modulator.speed_in_bytes_tx_iface) / 128.0));
|
||||
|
||||
// формируем структуру для RX
|
||||
result << ",\n\"rx.state\":" << boolAsStr(demodulator.locks.sym_sync_lock && demodulator.locks.freq_lock && demodulator.locks.afc_lock && demodulator.locks.pkt_sync);
|
||||
result << ",\"rx.sym_sync_lock\":" << boolAsStr(demodulator.locks.sym_sync_lock);
|
||||
result << ",\"rx.freq_search_lock\":" << boolAsStr(demodulator.locks.freq_lock);
|
||||
result << ",\"rx.afc_lock\":" << boolAsStr(demodulator.locks.afc_lock);
|
||||
result << ",\"rx.pkt_sync\":" << boolAsStr(demodulator.locks.pkt_sync);
|
||||
|
||||
result << ",\"rx.snr\":"; writeDouble(result, demodulator.snr);
|
||||
result << ",\"rx.rssi\":"; writeDouble(result, demodulator.rssi);
|
||||
result << ",\"rx.modcod\":" << demodulator.modcod;
|
||||
|
||||
if (demodulator.is_short) {
|
||||
result << R"(,"rx.frameSizeNormal":false)";
|
||||
} else {
|
||||
result << R"(,"rx.frameSizeNormal":true)";
|
||||
}
|
||||
|
||||
if (demodulator.is_pilots) {
|
||||
result << R"(,"rx.isPilots":true)";
|
||||
} else {
|
||||
result << R"(,"rx.isPilots":false)";
|
||||
}
|
||||
|
||||
result << ",\n\"rx.symError\":"; writeDouble(result, demodulator.sym_err);
|
||||
result << ",\"rx.freqErr\":"; writeDouble(result, demodulator.crs_freq_err);
|
||||
result << ",\"rx.freqErrAcc\":"; writeDouble(result, demodulator.fine_freq_err);
|
||||
result << ",\"rx.inputSignalLevel\":"; writeDouble(result, demodulator.if_overload);
|
||||
result << ",\"rx.pllError\":"; writeDouble(result, demodulator.afc_err);
|
||||
result << ",\"rx.speedOnRxKbit\":"; writeDouble(result, static_cast<double>(demodulator.speed_in_bytes_rx) / 128.0);
|
||||
result << ",\"rx.speedOnIifKbit\":"; writeDouble(result, static_cast<double>(demodulator.speed_in_bytes_rx_iface) / 128.0);
|
||||
result << ",\"rx.packetsOk\":" << demodulator.packet_ok_cnt;
|
||||
result << ",\"rx.packetsBad\":" << demodulator.packet_bad_cnt;
|
||||
result << ",\"rx.packetsDummy\":" << demodulator.dummy_cnt;
|
||||
|
||||
#ifdef MODEM_IS_SCPC
|
||||
// формируем структуру для CinC
|
||||
if (isCinC) {
|
||||
if (modulator.is_tx_on) {
|
||||
if (cinc.carrier_lock) {
|
||||
result << R"(,"cinc.correlator":true)";
|
||||
} else {
|
||||
result << R"(,"cinc.correlator":false)";
|
||||
}
|
||||
} else {
|
||||
result << R"(,"cinc.correlator":null)";
|
||||
}
|
||||
|
||||
result << ",\n\"cinc.occ\":"; writeDouble(result, cinc.ratio_signal_signal, 3);
|
||||
result << ",\"cinc.correlatorFails\":" << cinc.cnt_bad_lock;
|
||||
result << ",\"cinc.freqErr\":" << cinc.freq_error_offset;
|
||||
result << ",\"cinc.freqErrAcc\":" << cinc.freq_fine_estimate;
|
||||
result << ",\"cinc.channelDelay\":" << cinc.delay_dpdi;
|
||||
} else {
|
||||
result << R"(,"cinc.correlator":null)";
|
||||
}
|
||||
#endif
|
||||
|
||||
// структура температур девайса
|
||||
result << ",\n\"device.adrv\":"; writeDouble(result, device.adrv_temp, 1);
|
||||
result << ",\"device.fpga\":"; writeDouble(result, device.pl_temp, 1);
|
||||
result << ",\"device.zynq\":"; writeDouble(result, device.zynq_temp, 1);
|
||||
#ifdef MODEM_IS_TDMA
|
||||
if (device.cur_image.empty()) {
|
||||
result << R"(,
|
||||
"device.upgradeStatus":"Нет обновлений","device.upgradePercent":0,"device.upgradeImage":"")";
|
||||
} else {
|
||||
switch (device.status) {
|
||||
case NORM_RX_OBJECT_NEW_API: result << ",\n" R"("device.upgradeStatus": "Начало загрузки")"; break;
|
||||
case NORM_RX_OBJECT_INFO_API: result << ",\n" R"("device.upgradeStatus": "Получено имя образа")"; break;
|
||||
case NORM_RX_OBJECT_UPDATED_API: result << ",\n" R"("device.upgradeStatus": "Загружается")"; break;
|
||||
case NORM_RX_OBJECT_COMPLETED_API: result << ",\n" R"("device.upgradeStatus": "Загрузка завершена")"; break;
|
||||
case NORM_RX_OBJECT_ABORTED_API: result << ",\n" R"("device.upgradeStatus": "Загрузка прервана")"; break;
|
||||
default: result << ",\n" R"("device.upgradeStatus": "?")";
|
||||
|
||||
}
|
||||
result << ",\"device.upgradePercent\":" << device.dwl_percent;
|
||||
result << ",\"device.upgradeImage\":" << buildEscapedString(device.cur_image);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
result << "}";
|
||||
*/
|
||||
this->modState = modulator;
|
||||
this->demodState = demodulator;
|
||||
|
||||
#ifdef MODEM_IS_SCPC
|
||||
this->cincState = cinc;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
api_driver::obj::TerminalState::~TerminalState() = default;
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user