переход на получение статистики устройства новым API библиотеки control_system_client
This commit is contained in:
176
dependencies/control_system/client/main.cpp
vendored
176
dependencies/control_system/client/main.cpp
vendored
@@ -1,11 +1,175 @@
|
||||
#include <shared_mutex>
|
||||
#include "terminal_api/ControlProtoCInterface.h"
|
||||
#include <terminal_api/ControlProtoCInterface.h>
|
||||
#include "system_client.h"
|
||||
|
||||
std::shared_mutex mtx;
|
||||
TSID sid_counter { 0 };
|
||||
std::map<TSID, std::unique_ptr<system_client>> clients;
|
||||
|
||||
EXTERNC CP_Result CP_SetModulatorSettings(TSID sid, modulator_settings& settings){
|
||||
std::shared_lock lock(mtx);
|
||||
try
|
||||
{
|
||||
if (clients.find(sid) == clients.end())
|
||||
return ERROR;
|
||||
auto settings_ = reinterpret_cast<modulator_settings_com&>(settings);
|
||||
auto resp = clients[sid]->send_set_modulator_settings(settings_);
|
||||
if (resp == response_type::error)
|
||||
return ERROR;
|
||||
return OK;
|
||||
}
|
||||
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
EXTERNC CP_Result CP_SetDemodulatorSettings(TSID sid, demodulator_settings& settings){
|
||||
std::shared_lock lock(mtx);
|
||||
try
|
||||
{
|
||||
if (clients.find(sid) == clients.end())
|
||||
return ERROR;
|
||||
auto settings_ = reinterpret_cast<demodulator_settings_com&>(settings);
|
||||
auto resp = clients[sid]->send_set_demodulator_settings(settings_);
|
||||
if (resp == response_type::error)
|
||||
return ERROR;
|
||||
return OK;
|
||||
}
|
||||
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
EXTERNC CP_Result CP_GetModulatorSettings(TSID sid, modulator_settings& settings){
|
||||
std::shared_lock lock(mtx);
|
||||
try
|
||||
{
|
||||
if (clients.find(sid) == clients.end())
|
||||
return ERROR;
|
||||
|
||||
modulator_settings_com settings_com;
|
||||
auto resp = clients[sid]->send_get_modulator_settings(settings_com);
|
||||
if (resp == response_type::error)
|
||||
return ERROR;
|
||||
settings = reinterpret_cast<modulator_settings&>(settings_com);
|
||||
return OK;
|
||||
}
|
||||
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
EXTERNC CP_Result CP_GetDemodulatorSettings(TSID sid, demodulator_settings& settings){
|
||||
std::shared_lock lock(mtx);
|
||||
try
|
||||
{
|
||||
if (clients.find(sid) == clients.end())
|
||||
return ERROR;
|
||||
demodulator_settings_com settings_com;
|
||||
auto resp = clients[sid]->send_get_demodulator_settings(settings_com);
|
||||
if (resp == response_type::error)
|
||||
return ERROR;
|
||||
std::cout << "settings_com.rollof: " << settings_com.rollof << std::endl;
|
||||
std::cout << "settings_com.gain: " << settings_com.gain << std::endl;
|
||||
settings = reinterpret_cast<demodulator_settings&>(settings_com);
|
||||
return OK;
|
||||
}
|
||||
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
EXTERNC CP_Result CP_GetDemodulatorState(TSID sid, demodulator_state &state){
|
||||
std::shared_lock lock(mtx);
|
||||
try
|
||||
{
|
||||
if (clients.find(sid) == clients.end())
|
||||
return ERROR;
|
||||
demodulator_state_com state_com;
|
||||
auto resp = clients[sid]->send_get_demodulator_state(state_com);
|
||||
|
||||
if (resp == response_type::error)
|
||||
{
|
||||
std::cout << "error" << std::endl;
|
||||
return ERROR;
|
||||
}
|
||||
state = reinterpret_cast<demodulator_state&>(state_com);
|
||||
state.locks = reinterpret_cast<demodulator_locks&>(state_com.locks);
|
||||
return OK;
|
||||
}
|
||||
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
EXTERNC CP_Result CP_GetModulatorState(TSID sid, modulator_state &state){
|
||||
std::shared_lock lock(mtx);
|
||||
try
|
||||
{
|
||||
if (clients.find(sid) == clients.end())
|
||||
return ERROR;
|
||||
modulator_state_com state_com;
|
||||
auto resp = clients[sid]->send_get_modulator_state(state_com);
|
||||
if (resp == response_type::error)
|
||||
return ERROR;
|
||||
state = reinterpret_cast<modulator_state&>(state_com);
|
||||
return OK;
|
||||
}
|
||||
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
EXTERNC CP_Result CP_GetCinCState(TSID sid, CinC_state &state){
|
||||
std::shared_lock lock(mtx);
|
||||
try
|
||||
{
|
||||
if (clients.find(sid) == clients.end())
|
||||
return ERROR;
|
||||
CinC_state_com state_com;
|
||||
auto resp = clients[sid]->send_get_cinc_state(state_com);
|
||||
if (resp == response_type::error)
|
||||
return ERROR;
|
||||
state = reinterpret_cast<CinC_state&>(state_com);
|
||||
return OK;
|
||||
}
|
||||
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
EXTERNC CP_Result CP_GetDeviceState(TSID sid, device_state &state){
|
||||
|
||||
std::shared_lock lock(mtx);
|
||||
try
|
||||
{
|
||||
if (clients.find(sid) == clients.end())
|
||||
return ERROR;
|
||||
device_state_com state_com;
|
||||
auto resp = clients[sid]->send_get_device_state(state_com);
|
||||
if (resp == response_type::error)
|
||||
return ERROR;
|
||||
state = reinterpret_cast<device_state&>(state_com);
|
||||
return OK;
|
||||
}
|
||||
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
EXTERNC CP_Result CP_SetRollofBaudrate(TSID sid, double rollof, double baudrate)
|
||||
{
|
||||
std::shared_lock lock(mtx);
|
||||
@@ -285,6 +449,16 @@ EXTERNC CP_Result CP_GetNetwork(TSID sid, const char *param_name, std::string *v
|
||||
net_val = network_value::mac_eth1;
|
||||
else if(cmd == "name_serv")
|
||||
net_val = network_value::name_serv;
|
||||
else if(cmd == "network_debug_send")
|
||||
net_val = network_value::network_debug_send;
|
||||
else if(cmd == "network_port_metric")
|
||||
net_val = network_value::network_port_metric;
|
||||
else if(cmd == "network_port_data")
|
||||
net_val = network_value::network_port_data;
|
||||
else if(cmd == "if_debug_mode")
|
||||
net_val = network_value::if_debug_mode;
|
||||
else if(cmd == "periodic_send_metrics")
|
||||
net_val = network_value::periodic_send_metrics;
|
||||
|
||||
auto resp = clients[sid]->send_get_network_settings(net_val, val_from_server);
|
||||
if (resp == response_type::error)
|
||||
|
Reference in New Issue
Block a user