переход на получение статистики устройства новым API библиотеки control_system_client

This commit is contained in:
2024-11-05 16:06:16 +03:00
parent 5bfc5cebaf
commit 541b08a40e
12 changed files with 855 additions and 181 deletions

View File

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

View File

@@ -29,8 +29,8 @@ void client::start()
seq_packet::seqpacket_protocol::socket::message_flags in_flags { MSG_WAITALL };
socket_.async_receive(boost::asio::buffer(data_), in_flags,
std::bind(&client::handle_read, this,
std::placeholders::_1,
std::placeholders::_2));
std::placeholders::_1,
std::placeholders::_2));
}
void client::handle_connect(const boost::system::error_code & error)

View File

@@ -315,6 +315,72 @@ void system_client::data_received(const std::vector<uint8_t> & data)
break;
}
case cmd_type::get_demodulator_state:
{
if(cmd.rsp == response_type::ok)
{
cmd_get_demodulator_state value;
iarchive(value);
data_from_serv = value;
}
break;
}
case cmd_type::get_modulator_state:
{
if(cmd.rsp == response_type::ok)
{
cmd_get_modulator_state value;
iarchive(value);
data_from_serv = value;
}
break;
}
case cmd_type::get_demodulator_settings:
{
if(cmd.rsp == response_type::ok)
{
cmd_demodulator_settings value;
iarchive(value);
data_from_serv = value;
}
break;
}
case cmd_type::get_modulator_settings:
{
if(cmd.rsp == response_type::ok)
{
cmd_modulator_settings value;
iarchive(value);
data_from_serv = value;
}
break;
}
case cmd_type::get_device_state:
{
if(cmd.rsp == response_type::ok)
{
cmd_get_device_state value;
iarchive(value);
data_from_serv = value;
}
break;
}
case cmd_type::get_cinc_state:
{
if(cmd.rsp == response_type::ok)
{
cmd_get_cinc_state value;
iarchive(value);
data_from_serv = value;
}
break;
}
case cmd_type::get_dma_debugg:
{
if (cmd.rsp == response_type::ok)
@@ -677,6 +743,136 @@ response_type system_client::send_set_lbq_params(const uint32_t & tick_ms, const
return result;
}
response_type system_client::send_set_modulator_settings(modulator_settings_com &settings)
{
std::scoped_lock lock(cmd_in_progress_mtx);
uint32_t curr_id { ++cmd_id };
cmd_header cmd_acm_header{curr_id, cmd_type::set_modulator_settings};
cmd_modulator_settings settings_;
settings_.modulator_settings = settings;
send_to_socket(cmd_acm_header, settings_);
std::any data_to_serv;
auto result = wait_for_response(curr_id, cmd_type::set_modulator_settings, data_to_serv);
return result;
}
response_type system_client::send_set_demodulator_settings(demodulator_settings_com &settings)
{
std::scoped_lock lock(cmd_in_progress_mtx);
uint32_t curr_id { ++cmd_id };
cmd_header cmd_acm_header{curr_id, cmd_type::set_demodulator_settings};
cmd_demodulator_settings settings_;
settings_.demodulator_settings = settings;
send_to_socket(cmd_acm_header, settings_);
std::any data_to_serv;
auto result = wait_for_response(curr_id, cmd_type::set_demodulator_settings, data_to_serv);
return result;
}
response_type system_client::send_get_modulator_settings(modulator_settings_com &settings)
{
std::scoped_lock lock(cmd_in_progress_mtx);
uint32_t curr_id { ++cmd_id };
cmd_header cmd_dpdi_header{curr_id, cmd_type::get_modulator_settings};
cmd_modulator_settings modulator;
send_to_socket(cmd_dpdi_header, modulator);
std::any data_from_serv;
auto result = wait_for_response(curr_id, cmd_type::get_modulator_settings, data_from_serv);
if (data_from_serv.has_value())
settings = std::any_cast<cmd_modulator_settings>(data_from_serv).modulator_settings;
return result;
}
response_type system_client::send_get_demodulator_settings(demodulator_settings_com &settings)
{
std::scoped_lock lock(cmd_in_progress_mtx);
uint32_t curr_id { ++cmd_id };
cmd_header cmd_dpdi_header{curr_id, cmd_type::get_demodulator_settings};
cmd_demodulator_settings demodulator;
send_to_socket(cmd_dpdi_header, demodulator);
std::cout << "END GET_DEMODULATOR SETTINGS SEND TO SOCKET" << std::endl;
std::any data_from_serv;
auto result = wait_for_response(curr_id, cmd_type::get_demodulator_settings, data_from_serv);
if (data_from_serv.has_value())
settings = std::any_cast<cmd_demodulator_settings>(data_from_serv).demodulator_settings;
return result;
}
response_type system_client::send_get_demodulator_state(demodulator_state_com &demodulator_state){
std::scoped_lock lock(cmd_in_progress_mtx);
uint32_t curr_id { ++cmd_id };
cmd_header cmd_dpdi_header{curr_id, cmd_type::get_demodulator_state};
cmd_get_demodulator_state demodulator;
send_to_socket(cmd_dpdi_header, demodulator);
std::any data_from_serv;
auto result = wait_for_response(curr_id, cmd_type::get_demodulator_state, data_from_serv);
if (data_from_serv.has_value())
demodulator_state = std::any_cast<cmd_get_demodulator_state>(data_from_serv).demodulator_state;
return result;
}
response_type system_client::send_get_modulator_state(modulator_state_com &modulator_state){
std::scoped_lock lock(cmd_in_progress_mtx);
uint32_t curr_id { ++cmd_id };
cmd_header cmd_dpdi_header{curr_id, cmd_type::get_modulator_state};
cmd_get_modulator_state modulator;
send_to_socket(cmd_dpdi_header, modulator);
std::any data_from_serv;
auto result = wait_for_response(curr_id, cmd_type::get_modulator_state, data_from_serv);
if (data_from_serv.has_value())
modulator_state = std::any_cast<cmd_get_modulator_state>(data_from_serv).modulator_state;
return result;
}
response_type system_client::send_get_device_state(device_state_com &device_state ){
std::scoped_lock lock(cmd_in_progress_mtx);
uint32_t curr_id { ++cmd_id };
cmd_header cmd_dpdi_header{curr_id, cmd_type::get_device_state};
cmd_get_device_state device;
send_to_socket(cmd_dpdi_header, device);
std::any data_from_serv;
auto result = wait_for_response(curr_id, cmd_type::get_device_state, data_from_serv);
if (data_from_serv.has_value())
device_state = std::any_cast<cmd_get_device_state>(data_from_serv).device_state;
return result;
}
response_type system_client::send_get_cinc_state(CinC_state_com &cinc_state){
std::scoped_lock lock(cmd_in_progress_mtx);
uint32_t curr_id { ++cmd_id };
cmd_header cmd_dpdi_header{curr_id, cmd_type::get_cinc_state};
cmd_get_cinc_state cinc;
send_to_socket(cmd_dpdi_header, cinc);
std::any data_from_serv;
auto result = wait_for_response(curr_id, cmd_type::get_cinc_state, data_from_serv);
if (data_from_serv.has_value())
cinc_state = std::any_cast<cmd_get_cinc_state>(data_from_serv).cinc_state;
return result;
}
response_type system_client::send_set_acm_params(const ACM_parameters_serv &acm_params)
{
std::scoped_lock lock(cmd_in_progress_mtx);
@@ -752,4 +948,4 @@ response_type system_client::send_get_network_settings(const network_value & cmd
if (data_from_serv.has_value())
value = std::any_cast<std::string>(data_from_serv);
return result;
}
}

View File

@@ -48,6 +48,18 @@ public:
response_type send_set_acm_params(const ACM_parameters_serv &acm_params);
response_type send_get_acm_params(cmd_get_acm_param &acm_params);
response_type send_get_demodulator_state(demodulator_state_com &demodulator_state);
response_type send_get_modulator_state(modulator_state_com &modulator_state);
response_type send_get_device_state(device_state_com &device_state);
response_type send_get_cinc_state(CinC_state_com &cinc_state);
response_type send_set_modulator_settings(modulator_settings_com &settings);
response_type send_set_demodulator_settings(demodulator_settings_com &settings);
response_type send_get_modulator_settings(modulator_settings_com &settings);
response_type send_get_demodulator_settings(demodulator_settings_com &settings);
response_type send_set_dpdi_params(dpdi_parameters &dpdi_params);
response_type send_get_dpdi_params(dpdi_parameters &dpdi_params);