From d6851052b4bd09fafc140d77e275766dec21c53a Mon Sep 17 00:00:00 2001 From: Vladislav Ostapov Date: Tue, 29 Oct 2024 18:38:54 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B8=20=D0=BE=D1=82=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BB=20API=20=D0=BE=D1=82=20=D0=94?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../control_system-dvbs-2/CMakeLists.txt | 34 + .../client/ControlProtoCInterface.h | 223 +++ .../control_system-dvbs-2/client/main.cpp | 1244 +++++++++++++++++ .../client/sock_client.cpp | 51 + .../client/sock_client.h | 24 + .../client/system_client.cpp | 755 ++++++++++ .../client/system_client.h | 105 ++ .../common/protocol_commands.h | 671 +++++++++ .../control_system-dvbs-2/common/seq_packet.h | 23 + 9 files changed, 3130 insertions(+) create mode 100644 dependencies/control_system-dvbs-2/CMakeLists.txt create mode 100644 dependencies/control_system-dvbs-2/client/ControlProtoCInterface.h create mode 100644 dependencies/control_system-dvbs-2/client/main.cpp create mode 100644 dependencies/control_system-dvbs-2/client/sock_client.cpp create mode 100644 dependencies/control_system-dvbs-2/client/sock_client.h create mode 100644 dependencies/control_system-dvbs-2/client/system_client.cpp create mode 100644 dependencies/control_system-dvbs-2/client/system_client.h create mode 100644 dependencies/control_system-dvbs-2/common/protocol_commands.h create mode 100644 dependencies/control_system-dvbs-2/common/seq_packet.h diff --git a/dependencies/control_system-dvbs-2/CMakeLists.txt b/dependencies/control_system-dvbs-2/CMakeLists.txt new file mode 100644 index 0000000..7f14054 --- /dev/null +++ b/dependencies/control_system-dvbs-2/CMakeLists.txt @@ -0,0 +1,34 @@ +cmake_minimum_required(VERSION 3.20) + +project(terminal-client-api) + +set(CMAKE_CXX_STANDARD 17) + +if (CMAKE_VERSION VERSION_LESS 3.2) + set(UPDATE_DISCONNECTED_IF_AVAILABLE "") +else() + set(UPDATE_DISCONNECTED_IF_AVAILABLE "UPDATE_DISCONNECTED 1") +endif() + +include(CheckCXXCompilerFlag) +set(CMAKE_CXX_FLAGS -fPIC) + +set(default_build_type "Release") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror") +set(CMAKE_CXX_FLAGS_DEBUG "-ggdb -O0 -fprofile-arcs -ftest-coverage") +set(CMAKE_CXX_FLAGS_RELEASE "-O2 -s -DNDEBUG ") +message(${CMAKE_CXX_FLAGS}) +message("CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE}) + +message(${CMAKE_CXX_FLAGS}) + +add_library(terminal-client-api SHARED + client/main.cpp + client/sock_client.cpp + client/system_client.cpp +) + +find_package(Boost 1.53.0 COMPONENTS system log log_setup REQUIRED) +find_package(cereal REQUIRED) +target_link_libraries(terminal-client-api ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} cereal::cereal) +target_include_directories(terminal-client-api PRIVATE ${Boost_INCLUDE_DIR}) diff --git a/dependencies/control_system-dvbs-2/client/ControlProtoCInterface.h b/dependencies/control_system-dvbs-2/client/ControlProtoCInterface.h new file mode 100644 index 0000000..de62811 --- /dev/null +++ b/dependencies/control_system-dvbs-2/client/ControlProtoCInterface.h @@ -0,0 +1,223 @@ +#ifndef __CONTROL_PROTO_COMMANDS__ +#define __CONTROL_PROTO_COMMANDS__ + +#include +#include +#include + +#ifdef __cplusplus +#define EXTERNC extern "C" +#else +#define EXTERNC extern +#endif + +typedef unsigned int TSID; + +typedef enum CP_Res { + OK = 0, + TIMEOUT, + ERROR, + ABORT, + BUSY +} CP_Result; + +typedef void (*CP_cmd_stdout_cb)(const char * str, uint32_t len); + +/* + cb - callback for receive stdout of command +*/ +EXTERNC void CP_SetCmdStdoutCallback(TSID sid, CP_cmd_stdout_cb cb); +/* + sid -- current session ID +*/ +EXTERNC void CP_CmdAbort(TSID sid); +/* + host -- host name + user -- user name + pwd -- password hash + sid -- output session ID (used for all requests) + access -- output type of privilegies {admin|operator|...etc} +*/ +EXTERNC CP_Result CP_Login(const char * user, const char * pwd, TSID * sid, unsigned int * access); +/* + sid -- current session ID +*/ +EXTERNC CP_Result CP_Logout(TSID sid); +/* + sid -- current session ID + ip_address -- IP address of the host + packet_count -- count of packets to send +*/ +EXTERNC CP_Result CP_GetDmaDebug(TSID sid, const char *command, std::string *val); + +EXTERNC CP_Result CP_SetDemFreq(TSID sid, uint32_t freq); + +EXTERNC CP_Result CP_GetDemFreq(TSID sid, uint32_t * freq); + +EXTERNC CP_Result CP_SetDmaDebug(TSID sid, const char *command, std::string val); + +EXTERNC CP_Result CP_Set10gConfig(TSID sid, const char *parameter, std::string val); + +EXTERNC CP_Result CP_SetRollofBaudrate(TSID sid, double rollof,double baudrate); + +//interfaces +EXTERNC CP_Result CP_GetGain(TSID sid, const char *gain_interface, double *gain); +//interfaces +EXTERNC CP_Result CP_SetGain(TSID sid, const char *gain_interface, double gain); +//interfaces +EXTERNC CP_Result CP_RadioEnable(TSID sid, const char *radio_interface, bool on_of); +//interfaces +/* +BOD -- baud_rate +SPREAD -- koef spread +LO -- lo frequency +*/ +EXTERNC CP_Result CP_ModulatorParams(TSID sid, const char *modulator_param, uint32_t value); + +EXTERNC CP_Result CP_GetModulatorParams(TSID sid, const char *modulator_param, uint32_t *value); + +EXTERNC CP_Result CP_GetDemodulatorParams(TSID sid, const char *demodulator_param, uint32_t *value); + +EXTERNC CP_Result CP_GetLevelDemod(TSID sid, const char * param ,double *value); + +EXTERNC CP_Result CP_DemodulatorParams(TSID sid, const char *demodulator_param, uint32_t value); + +EXTERNC CP_Result CP_SetLBQParams(TSID sid, const uint32_t &tick_ms, const uint32_t &bucket_size); + +EXTERNC CP_Result CP_SetQoSParams(TSID sid, const std::string &type_node, const std::string & node); + +EXTERNC CP_Result CP_GetQoSParams(TSID sid, const std::string &type_node, std::string * node); + +struct ACM_parameters_serv_ +{ + double snr_treashold = 0; + double snr_treashold_acm = 0.5; + uint32_t period_pack = 15; + uint8_t max_modcod = 4; + uint8_t min_modcod = 4; + int max_attenuation = 0; + int min_attenuation = 0; + bool enable = false; + bool enable_auto_atten = false; +}; + +struct DPDI_parmeters +{ + uint8_t latitude_station_grad = 0; + uint8_t latitude_station_minute = 0; + uint8_t longitude_station_grad = 0; + uint8_t longitude_station_minute = 0; + uint8_t longitude_sattelite_grad = 0; + uint8_t longitude_sattelite_minute = 0; + bool is_delay_window = 0; + uint32_t max_delay = 1; + uint32_t min_delay = 0; + uint32_t freq_offset = 0; +}; + +EXTERNC CP_Result CP_SetAcmParams(TSID sid, ACM_parameters_serv_ acm_params); +EXTERNC CP_Result CP_GetAcmParams(TSID sid, ACM_parameters_serv_ *acm_params); + +EXTERNC CP_Result CP_SetDpdiParams(TSID sid, DPDI_parmeters dpdi_params); +EXTERNC CP_Result CP_GetDpdiParams(TSID sid, DPDI_parmeters *dpdi_pars_get); + +/* +PSV +PLV +PST +PLT +ADRVT +*/ +EXTERNC CP_Result CP_ZynqParams(TSID sid, const char *zynq_param, double *value); + +EXTERNC CP_Result CP_SetNetwork(TSID sid, const char *param_name, const char *val); +EXTERNC CP_Result CP_GetNetwork(TSID sid, const char *param_name, std::string *val); +/* + ip_address -- new IP address fot the host +*/ + +EXTERNC CP_Result CP_Ping(TSID sid, const char * ip_address, int packet_count); +/* + sid -- current session ID + ip_address -- IP address of the host +*/ +EXTERNC CP_Result CP_Traceroute(TSID sid, const char * ip_address); +/* + sid -- current session ID + src -- {"running-config"|"startup-config"|host_address} + dst -- {"running-config"|"startup-config"|host_address} + NOTE: + src and dst both must be different +*/ +EXTERNC CP_Result CP_Copy(TSID sid, const char * src, const char * dst); +/* + sid -- current session ID + interface -- {"all"|"sat0"|"gigabit"|"modulator"|"demodulator"} + output data goes to callback +*/ +EXTERNC CP_Result CP_ShowInterface(TSID sid, const char * interface); +/* + sid -- current session ID + out_startup_config -- received information about startup config +*/ +EXTERNC CP_Result CP_ShowStartupConfig(TSID sid, char ** out_startup_config); +/* + sid -- current session ID + interface -- {"all"|"sat0"|"gigabit"|"modulator"|"demodulator"} + out_startup_config -- received information about startup config +*/ +EXTERNC CP_Result CP_ShowStartupConfigInterface(TSID sid, const char * interface, char ** out_startup_config); + +// Demodulator +/* + sid -- current session ID + interface -- {"SAT"|"Ethernet"|"Loopback"} + rate -- symbol rate +*/ +EXTERNC CP_Result CP_SetDemodSymrate(TSID sid, const char * interface, uint32_t rate); +/* + sid -- current session ID + interface -- {"SAT"|"Ethernet"|"Loopback"} + rate -- frequency value in Hertz +*/ +EXTERNC CP_Result CP_SetDemodFrequency(TSID sid, const char * interface, uint32_t freq); +/* + sid -- current session ID + interface -- {"SAT"|"Ethernet"|"Loopback"} + mode -- {"on"|"off"|"auto"} +*/ +EXTERNC CP_Result CP_SetDemodSpectrum(TSID sid, const char * interface, const char * mode); +/* + sid -- current session ID + interface -- {"SAT"|"Ethernet"|"Loopback"} + mode -- {"on"|"off"} +*/ +EXTERNC CP_Result CP_SetDemodReference(TSID sid, const char * interface, const char * mode); +/* + sid -- current session ID + interface -- {"SAT"|"Ethernet"|"Loopback"} + rate -- frequency value in Hertz +*/ +EXTERNC CP_Result CP_SetDemodSearch(TSID sid, const char * interface, uint32_t freq); + +// Modulator + +/* + sid -- current session ID + interface -- {"SAT"|"Ethernet"|"Loopback"} + rate -- symbol rate +*/ +EXTERNC CP_Result CP_SetModSymrate(TSID sid, const char * interface, uint32_t rate); +/* + sid -- current session ID + interface -- {"SAT"|"Ethernet"|"Loopback"} + rate -- frequency value in Hertz +*/ +EXTERNC CP_Result CP_SetModSymFrequency(TSID sid, const char * interface, uint32_t freq); +/* + sid -- current session ID + interface -- {"SAT"|"Ethernet"|"Loopback"} + mode -- {"on"|"off"} +*/ +EXTERNC CP_Result CP_SetModReference(TSID sid, const char * interface, const char * mode); +#endif diff --git a/dependencies/control_system-dvbs-2/client/main.cpp b/dependencies/control_system-dvbs-2/client/main.cpp new file mode 100644 index 0000000..97acf30 --- /dev/null +++ b/dependencies/control_system-dvbs-2/client/main.cpp @@ -0,0 +1,1244 @@ +#include +#include "ControlProtoCInterface.h" +#include "system_client.h" + +std::shared_mutex mtx; +TSID sid_counter { 0 }; +std::map> clients; + +EXTERNC CP_Result CP_SetRollofBaudrate(TSID sid, double rollof, double baudrate) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + auto resp = clients[sid]->send_rollof_and_baudrate(rollof, baudrate); + if (resp == response_type::error) + return ERROR; + return OK; + } + + catch(const std::exception& e) + { + return ERROR; + } +} + +EXTERNC CP_Result CP_SetQoSParams(TSID sid, const std::string &type_node, const std::string & node) +{ + std::shared_lock lock(mtx); + name_classes_qos name_class; + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + if(type_node == "realtime1") + { + name_class = name_classes_qos::realtime1; + } + else if(type_node == "realtime2") + { + name_class = name_classes_qos::realtime2; + } + else if(type_node == "realtime3") + { + name_class = name_classes_qos::realtime3; + } + else if(type_node == "critical1") + { + name_class = name_classes_qos::critical1; + } + else if(type_node == "critical2") + { + name_class = name_classes_qos::critical2; + } + else if(type_node == "critical3") + { + name_class = name_classes_qos::critical3; + } + else if(type_node == "cir") + { + name_class = name_classes_qos::cir; + } + else if(type_node == "pir") + { + name_class = name_classes_qos::pir; + } + else if(type_node == "wcr1") + { + name_class = name_classes_qos::wcr1; + } + else if(type_node == "wcr2") + { + name_class = name_classes_qos::wcr2; + } + else if(type_node == "wcr3") + { + name_class = name_classes_qos::wcr3; + } + else if(type_node == "enable") + { + name_class = name_classes_qos::enable; + } + else if(type_node == "ful_node") + { + name_class = name_classes_qos::ful_node; + } + + auto resp = clients[sid]->send_set_qos_params(node, name_class); + if (resp == response_type::error) + return ERROR; + return OK; + } + + catch(const std::exception& e) + { + return ERROR; + } +} + +EXTERNC CP_Result CP_GetQoSParams(TSID sid, const std::string &type_node, std::string * node) +{ + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + + std::string node_ = std::string(); + name_classes_qos name_class; + if(type_node == "realtime1") + { + name_class = name_classes_qos::realtime1; + } + else if(type_node == "realtime2") + { + name_class = name_classes_qos::realtime2; + } + else if(type_node == "realtime3") + { + name_class = name_classes_qos::realtime3; + } + else if(type_node == "critical1") + { + name_class = name_classes_qos::critical1; + } + else if(type_node == "critical2") + { + name_class = name_classes_qos::critical2; + } + else if(type_node == "critical3") + { + name_class = name_classes_qos::critical3; + } + else if(type_node == "cir") + { + name_class = name_classes_qos::cir; + } + else if(type_node == "pir") + { + name_class = name_classes_qos::pir; + } + else if(type_node == "wcr1") + { + name_class = name_classes_qos::wcr1; + } + else if(type_node == "wcr2") + { + name_class = name_classes_qos::wcr2; + } + else if(type_node == "wcr3") + { + name_class = name_classes_qos::wcr3; + } + else if(type_node == "enable") + { + name_class = name_classes_qos::enable; + } + else if(type_node == "ful_node") + { + name_class = name_classes_qos::ful_node; + } + + auto resp = clients[sid]->send_get_qos_params(node_, name_class); + if (resp == response_type::error) + return ERROR; + *node = node_; + return OK; + } + catch(const std::exception& e) + { + return ERROR; + } +} + +EXTERNC CP_Result CP_SetDpdiParams(TSID sid, DPDI_parmeters dpdi_params) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + + dpdi_parameters dpdi_pars; + dpdi_pars.is_delay_window = dpdi_params.is_delay_window; + dpdi_pars.max_delay = dpdi_params.max_delay; + dpdi_pars.min_delay = dpdi_params.min_delay; + dpdi_pars.freq_offset = dpdi_params.freq_offset; + dpdi_pars.latitude_station_grad = dpdi_params.latitude_station_grad; + dpdi_pars.latitude_station_minute = dpdi_params.latitude_station_minute; + dpdi_pars.longitude_sattelite_grad = dpdi_params.longitude_sattelite_grad; + dpdi_pars.longitude_sattelite_minute = dpdi_params.longitude_sattelite_minute; + dpdi_pars.longitude_station_grad = dpdi_params.longitude_station_grad; + dpdi_pars.longitude_station_minute = dpdi_params.longitude_station_minute; + auto resp = clients[sid]->send_set_dpdi_params(dpdi_pars); + if (resp == response_type::error) + return ERROR; + return OK; + } + catch(const std::exception& e) + { + return ERROR; + } +} + +EXTERNC CP_Result CP_SetNetwork(TSID sid, const char *param_name, const char *val) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + network_value net_val; + std::string cmd(param_name); + if(cmd == "mode") + net_val = network_value::mode_interface; + else if(cmd == "addr") + net_val = network_value::network; + else if(cmd == "mask") + net_val = network_value::mask; + else if(cmd == "gateway") + net_val = network_value::gateway; + else if(cmd == "dhcp_on") + net_val = network_value::dhcp_on; + else if(cmd == "dhcp_range") + net_val = network_value::dhcp_range; + else if(cmd == "addr_data") + net_val = network_value::network_data; + 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_network_settings(net_val, val); + if (resp == response_type::error) + return ERROR; + return OK; + } + catch(const std::exception& e) + { + return ERROR; + } +} + +EXTERNC CP_Result CP_GetNetwork(TSID sid, const char *param_name, std::string *val) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + network_value net_val; + std::string cmd(param_name); + std::string val_from_server; + if(cmd == "mode") + net_val = network_value::mode_interface; + else if(cmd == "addr") + net_val = network_value::network; + else if(cmd == "version") + net_val = network_value::version; + else if(cmd == "chip_id") + net_val = network_value::chip_id; + else if(cmd == "mask") + net_val = network_value::mask; + else if(cmd == "gateway") + net_val = network_value::gateway; + else if(cmd == "dhcp_on") + net_val = network_value::dhcp_on; + else if(cmd == "dhcp_range") + net_val = network_value::dhcp_range; + else if(cmd == "addr_data") + net_val = network_value::network_data; + else if(cmd == "serial") + net_val = network_value::serial; + else if(cmd == "mac_eth0") + net_val = network_value::mac_eth0; + else if(cmd == "mac_eth1") + net_val = network_value::mac_eth1; + else if(cmd == "name_serv") + net_val = network_value::name_serv; + + auto resp = clients[sid]->send_get_network_settings(net_val, val_from_server); + if (resp == response_type::error) + return ERROR; + *val = val_from_server; + return OK; + } + catch(const std::exception& e) + { + return ERROR; + } +} + +EXTERNC CP_Result CP_SetLBQParams(TSID sid, const uint32_t &tick_ms, const uint32_t &bucket_size) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + auto resp = clients[sid]->send_set_lbq_params(tick_ms, bucket_size); + + if (resp == response_type::error) + return ERROR; + + return OK; + } + catch(const std::exception& e) + { + return ERROR; + } +} + +EXTERNC CP_Result CP_SetDmaDebug(TSID sid, const char *command, std::string val) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + cmd_dma_debugg dma_debugg; + std::string param_name(command); + + if (param_name == "start") + dma_debugg = cmd_dma_debugg::start; + else if (param_name == "stop") + dma_debugg = cmd_dma_debugg::stop; + else if (param_name == "reset") + dma_debugg = cmd_dma_debugg::reset; + else if (param_name == "reinit") + dma_debugg = cmd_dma_debugg::reinit; + else if (param_name == "modcod") + dma_debugg = cmd_dma_debugg::modcod; + else if (param_name == "log_bool") + dma_debugg = cmd_dma_debugg::log_bool; + else if (param_name == "data_mode") + dma_debugg = cmd_dma_debugg::data_mode; + else if (param_name == "buc_voltage") + dma_debugg = cmd_dma_debugg::buc_voltage; + else if (param_name == "lnb_voltage") + dma_debugg = cmd_dma_debugg::lnb_voltage; + else if (param_name == "10MHz_tx") + dma_debugg = cmd_dma_debugg::_10mhz_tx; + else if (param_name == "10MHz_rx") + dma_debugg = cmd_dma_debugg::_10mhz_rx; + else if (param_name == "10MHz_out") + dma_debugg = cmd_dma_debugg::_10MHz_out; + else if (param_name == "powerdown_plata") + dma_debugg = cmd_dma_debugg::powerdown_plata; + else if (param_name == "default_params") + dma_debugg = cmd_dma_debugg::default_params; + else if (param_name == "current_state_tx") + dma_debugg = cmd_dma_debugg::current_state_tx; + else if (param_name == "current_state_oib") + dma_debugg = cmd_dma_debugg::current_state_oib; + else if (param_name == "save_config") + dma_debugg = cmd_dma_debugg::save_config; + else if (param_name == "begin_save_config") + dma_debugg = cmd_dma_debugg::begin_save_config; + else return ERROR; + + auto resp = clients[sid]->send_set_dma_debug(dma_debugg, val); + if (resp == response_type::error) + return ERROR; + + return OK; + + } + catch(const std::exception& e) + { + return ERROR; + } +} + +EXTERNC CP_Result CP_SetAcmParams(TSID sid, ACM_parameters_serv_ acm_params) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + + ACM_parameters_serv acm_pars; + acm_pars.enable = acm_params.enable; + acm_pars.max_attenuation = acm_params.max_attenuation; + acm_pars.max_modcod = acm_params.max_modcod; + acm_pars.min_attenuation = acm_params.min_attenuation; + acm_pars.min_modcod = acm_params.min_modcod; + acm_pars.snr_treashold = acm_params.snr_treashold; + acm_pars.enable_auto_atten = acm_params.enable_auto_atten; + acm_pars.snr_treashold_acm = acm_params.snr_treashold_acm; + acm_pars.period_pack = acm_params.period_pack; + auto resp = clients[sid]->send_set_acm_params(acm_pars); + if (resp == response_type::error) + return ERROR; + return OK; + } + catch(const std::exception& e) + { + return ERROR; + } +} + +EXTERNC CP_Result CP_Set10gConfig(TSID sid, const char *parameter, std::string val) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + cmd_10g_config _10g_config; + std::string param_name(parameter); + if(param_name == "udp_payload_length") + _10g_config = cmd_10g_config::udp_payload_lenght; + else if (param_name == "local_ip") + _10g_config = cmd_10g_config::local_ip; + else if (param_name == "dest_ip") + _10g_config = cmd_10g_config::dest_ip; + else if (param_name == "gateway_ip") + _10g_config = cmd_10g_config::gateway_ip; + else if (param_name == "subnet_mask") + _10g_config = cmd_10g_config::subnet_mask; + else if (param_name == "udp_source_port") + _10g_config = cmd_10g_config::udp_source_port; + else if (param_name == "udp_dest_port") + _10g_config = cmd_10g_config::udp_dest_port; + else if (param_name == "local_mac_1") + _10g_config = cmd_10g_config::local_mac_31_0; + else if (param_name == "local_mac_2") + _10g_config = cmd_10g_config::local_mac_32_47; + else if (param_name == "chan0") + _10g_config = cmd_10g_config::mtx_chan0; + else if (param_name == "chan1") + _10g_config = cmd_10g_config::mtx_chan1; + else return ERROR; + + auto resp = clients[sid]->send_set_10g_config(_10g_config, val); + if (resp == response_type::error) + return ERROR; + + return OK; + + } + catch(const std::exception& e) + { + return ERROR; + } +} + +EXTERNC CP_Result CP_GetDpdiParams(TSID sid, DPDI_parmeters *dpdi_pars_get) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + + dpdi_parameters dpdi_from_server; + auto resp = clients[sid]->send_get_dpdi_params(dpdi_from_server); + if (resp == response_type::error) + return ERROR; + DPDI_parmeters dpdi_pars; + dpdi_pars.is_delay_window = dpdi_from_server.is_delay_window; + dpdi_pars.max_delay = dpdi_from_server.max_delay; + dpdi_pars.min_delay = dpdi_from_server.min_delay; + dpdi_pars.freq_offset = dpdi_from_server.freq_offset; + dpdi_pars.latitude_station_grad = dpdi_from_server.latitude_station_grad; + dpdi_pars.latitude_station_minute = dpdi_from_server.latitude_station_minute; + dpdi_pars.longitude_sattelite_grad = dpdi_from_server.longitude_sattelite_grad; + dpdi_pars.longitude_sattelite_minute = dpdi_from_server.longitude_sattelite_minute; + dpdi_pars.longitude_station_grad = dpdi_from_server.longitude_station_grad; + dpdi_pars.longitude_station_minute = dpdi_from_server.longitude_station_minute; + *dpdi_pars_get = dpdi_pars; + return OK; + } + catch(const std::exception& e) + { + return ERROR; + } +} + +EXTERNC CP_Result CP_GetAcmParams(TSID sid, ACM_parameters_serv_ *acm_params) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + + cmd_get_acm_param acm_from_server; + auto resp = clients[sid]->send_get_acm_params(acm_from_server); + if (resp == response_type::error) + return ERROR; + ACM_parameters_serv_ acm_from_serv_; + acm_from_serv_.enable = acm_from_server.enable; + acm_from_serv_.enable_auto_atten = acm_from_server.enable_auto_atten; + acm_from_serv_.min_attenuation = acm_from_server.min_attenuation; + acm_from_serv_.max_attenuation = acm_from_server.max_attenuation; + acm_from_serv_.min_modcod = acm_from_server.min_modcod; + acm_from_serv_.snr_treashold = acm_from_server.snr_treashold; + acm_from_serv_.max_modcod = acm_from_server.max_modcod; + acm_from_serv_.snr_treashold_acm = acm_from_server.snr_treashold_acm; + acm_from_serv_.period_pack = acm_from_server.period_pack; + *acm_params = acm_from_serv_; + return OK; + } + catch(const std::exception& e) + { + return ERROR; + } +} + +EXTERNC CP_Result CP_GetDmaDebug(TSID sid, const char *command, std::string *val) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + std::string value_from_server; + cmd_get_dma_debugg_enum cmd; + std::string param_name(command); + + if(param_name == "speed_tx") + cmd = cmd_get_dma_debugg_enum::speed_tx; + else if (param_name == "speed_rx") + cmd = cmd_get_dma_debugg_enum::speed_rx; + if(param_name == "speed_tx_iface") + cmd = cmd_get_dma_debugg_enum::speed_tx_iface; + else if (param_name == "speed_rx_iface") + cmd = cmd_get_dma_debugg_enum::speed_rx_iface; + else if (param_name == "modcod") + cmd = cmd_get_dma_debugg_enum::modcod; + else if (param_name == "drop_bad_rx") + cmd = cmd_get_dma_debugg_enum::drop_bad_rx; + else if (param_name == "drop_full_rx") + cmd = cmd_get_dma_debugg_enum::drop_full_rx; + else if (param_name == "packet_ok_rx") + cmd = cmd_get_dma_debugg_enum::packet_ok_rx; + else if (param_name == "packet_little_tx") + cmd = cmd_get_dma_debugg_enum::packet_little_tx; + else if (param_name == "packet_big_tx") + cmd = cmd_get_dma_debugg_enum::packet_big_tx; + else if (param_name == "bad_modcod_tx") + cmd = cmd_get_dma_debugg_enum::bad_modcod_tx; + else if (param_name == "bad_length_tx") + cmd = cmd_get_dma_debugg_enum::bad_length_tx; + else if (param_name == "reset_cnt_rx") + cmd = cmd_get_dma_debugg_enum::reset_cnt_rx; + else if (param_name == "buc_voltage") + cmd = cmd_get_dma_debugg_enum::buc_voltage; + else if (param_name == "lnb_voltage") + cmd = cmd_get_dma_debugg_enum::lnb_voltage; + else if (param_name == "10MHz_tx") + cmd = cmd_get_dma_debugg_enum::_10mhz_tx; + else if (param_name == "10MHz_rx") + cmd = cmd_get_dma_debugg_enum::_10mhz_rx; + else if (param_name == "10MHz_out") + cmd = cmd_get_dma_debugg_enum::_10MHz_out; + else if (param_name == "current_state_tx") + cmd = cmd_get_dma_debugg_enum::current_state_tx; + else if (param_name == "data_mode") + cmd = cmd_get_dma_debugg_enum::data_mode; + else if (param_name == "delay_dpdi") + cmd = cmd_get_dma_debugg_enum::real_dpdi_shift; + else if (param_name == "freq_error_offset") + cmd = cmd_get_dma_debugg_enum::freq_error_offset; + else if (param_name == "freq_fine_estimate") + cmd = cmd_get_dma_debugg_enum::freq_fine_estimate; + else if (param_name == "powerdown_plata") + cmd = cmd_get_dma_debugg_enum::powerdown_plata; + else if (param_name == "current_state_oib") + cmd = cmd_get_dma_debugg_enum::current_state_oib; + else if (param_name == "ratio_signal_signal") + cmd = cmd_get_dma_debugg_enum::ratio_signal_signal; + else if (param_name == "status_init") + cmd = cmd_get_dma_debugg_enum::status_init; + + auto resp = clients[sid]->send_get_dma_debug(cmd, value_from_server); + if (resp == response_type::error) + return ERROR; + *val = value_from_server; + return OK; + } + catch(const std::exception& e) + { + return ERROR; + } +} + +EXTERNC CP_Result CP_GetLevelDemod(TSID sid, const char * param ,double *value) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + double level_from_server; + cmd_level_dem level_value; + std::string param_name(param); + if(param_name == "snr") + level_value = cmd_level_dem::snr; + else if(param_name == "rssi") + level_value = cmd_level_dem::rssi; + else if(param_name == "pkt_sync") + level_value = cmd_level_dem::pkt_sync; + else if(param_name == "afc_lock") + level_value = cmd_level_dem::afc_lock; + else if(param_name == "freq_lock") + level_value = cmd_level_dem::freq_search_lock; + else if(param_name == "sym_sync_lock") + level_value = cmd_level_dem::sym_sync_lock; + else if(param_name == "phase_inv") + level_value = cmd_level_dem::phase_inv; + else if (param_name == "afc_err") + level_value = cmd_level_dem::afc_error; + else if (param_name == "crs_freq_err") + level_value = cmd_level_dem::crs_freq_error; + else if (param_name == "sym_err") + level_value = cmd_level_dem::sym_error; + else if (param_name == "fine_freq_err") + level_value = cmd_level_dem::fine_freq_error; + else if (param_name == "gain_aru") + level_value = cmd_level_dem::gc_gain_aru; + else if (param_name == "rollof") + level_value = cmd_level_dem::rollof; + else if (param_name == "carrier_lock") + level_value = cmd_level_dem::carrier_lock; + else if (param_name == "filt_adapt_lock") + level_value = cmd_level_dem::filt_adapt_lock; + else if (param_name == "snr_acm") + level_value = cmd_level_dem::snr_acm; + else if (param_name == "modcod_tx") + level_value = cmd_level_dem::modcod_tx; + auto resp = clients[sid]->send_get_level_dem(level_value, level_from_server); + if (resp == response_type::error) + return ERROR; + *value = level_from_server; + return OK; + } + catch(const std::exception& e) + { + return ERROR; + } +} + +EXTERNC CP_Result CP_ZynqParams(TSID sid, const char *zynq_param, double *value) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + zynq_value zyn_value; + double par_from_server; + std::string param_name(zynq_param); + if(param_name == "ps_voltage") + zyn_value = zynq_value::ps_volt; + else if(param_name == "ps_temper_celsius") + zyn_value = zynq_value::ps_temp; + else if(param_name == "pl_voltage") + zyn_value = zynq_value::pl_volt; + else if(param_name == "pl_temper_celsius") + zyn_value = zynq_value::pl_temp; + else if(param_name == "adrv-c_temper_celsius") + zyn_value = zynq_value::adrv_temp; + else if(param_name == "adrv-d_temper_celsius") + zyn_value = zynq_value::adrv_temp2; + else return ERROR; + + auto resp = clients[sid]->send_zynq_cmd(zyn_value, par_from_server); + if (resp == response_type::error) + return ERROR; + + *value = par_from_server; + return OK; + + } + catch(const std::exception& e) + { + return ERROR; + } +} + +EXTERNC CP_Result CP_GetModulatorParams(TSID sid, const char *modulator_param, uint32_t *value) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + modulator_value mod_val; + uint32_t par_from_server; + std::string param_name(modulator_param); + if(param_name == "baudrate") + mod_val = modulator_value::baud_rate; + else if (param_name == "center_freq") + mod_val = modulator_value::lo_freaquency; + else if (param_name == "rollof") + mod_val = modulator_value::rollof; + else if (param_name == "mode_trans") + mod_val = modulator_value::mode_transmitt; + else if (param_name == "if_overload") + mod_val = modulator_value::if_overload; + else if (param_name == "gold_seq") + mod_val = modulator_value::gold_seq; + + else return ERROR; + + auto resp = clients[sid]->send_get_modulator_param(mod_val, par_from_server); + if (resp == response_type::error) + return ERROR; + *value = par_from_server; + return OK; + } + catch(const std::exception& e) + { + return ERROR; + } +} + +EXTERNC CP_Result CP_GetDemodulatorParams(TSID sid, const char *demodulator_param, uint32_t *value) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + getdemodulator_value demod_val; + uint32_t par_from_server; + std::string param_name(demodulator_param); + if(param_name == "baudrate") + demod_val = getdemodulator_value::baud_rate; + else if (param_name == "center_freq") + demod_val = getdemodulator_value::lo_freaquency; + else if (param_name == "dummy_cnt") + demod_val = getdemodulator_value::dummy_counter; + else if (param_name == "modcod") + demod_val = getdemodulator_value::modcod; + else if (param_name == "mode_gain_control") + demod_val = getdemodulator_value::mode_gain_control; + else if (param_name == "sig_min") + demod_val = getdemodulator_value::sig_min; + else if (param_name == "sig_max") + demod_val = getdemodulator_value::sig_max; + else if (param_name == "rvt") + demod_val = getdemodulator_value::rvt; + else if (param_name == "fec_size") + demod_val = getdemodulator_value::fec_size; + else if (param_name == "mode_demod") + demod_val = getdemodulator_value::mode_demod; + else if (param_name == "cnt_bad_lock_cinc") + demod_val = getdemodulator_value::cnt_bad_lock_cinc; + else if (param_name == "gold_seq") + demod_val = getdemodulator_value::gold_seq; + else if (param_name == "attitude_signals") + demod_val = getdemodulator_value::attitude_signals; + else if (param_name == "cnt_dem_time_sinc") + demod_val = getdemodulator_value::cnt_dem_time_sinc; + else if (param_name == "cnt_dem_lock_afc") + demod_val = getdemodulator_value::cnt_dem_lock_afc; + else if (param_name == "cnt_dem_sync_pack") + demod_val = getdemodulator_value::cnt_dem_sync_pack; + else if (param_name == "cnt_dem_sinc_frec_corse") + demod_val = getdemodulator_value::cnt_dem_sinc_frec_corse; + else if (param_name == "freq_lock_estimate") + demod_val = getdemodulator_value::freq_lock_estimate; + else if (param_name == "reset_cinc") + demod_val = getdemodulator_value::is_reset_CinC; + else if (param_name == "type_pack") + demod_val = getdemodulator_value::type_pack; + else if (param_name == "is_pilots") + demod_val = getdemodulator_value::is_pilots; + else return ERROR; + + auto resp = clients[sid]->send_get_demodulator_param(demod_val, par_from_server); + if (resp == response_type::error) + return ERROR; + + *value = par_from_server; + return OK; + } + catch(const std::exception& e) + { + return ERROR; + } +} + +EXTERNC CP_Result CP_DemodulatorParams(TSID sid, const char *demodulator_param, uint32_t value) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + demodulator_value demod_val; + std::string param_name(demodulator_param); + if(param_name == "baudrate") + demod_val = demodulator_value::baud_rate; + else if (param_name == "center_freq") + demod_val = demodulator_value::lo_freaquency; + else if (param_name == "demod_reset") + demod_val = demodulator_value::demod_reset; + else if (param_name == "fec_size") + demod_val = demodulator_value::fec_frame_size; + else if (param_name == "rvt") + demod_val = demodulator_value::rvt; + else if (param_name == "mode_gain_control") + demod_val = demodulator_value::mode_gain_control; + else if (param_name == "sig_min") + demod_val = demodulator_value::sig_min; + else if (param_name == "sig_max") + demod_val = demodulator_value::sig_max; + else if (param_name == "afc_rst") + demod_val = demodulator_value::afc_rst; + else if (param_name == "mode_demod") + demod_val = demodulator_value::mode_demod; + else if (param_name == "gold_seq") + demod_val = demodulator_value::gold_seq; + else if (param_name == "attitude_signals") + demod_val = demodulator_value::attitude_signals; + else if (param_name == "reset_cinc") + demod_val = demodulator_value::is_reset_CinC; + else return ERROR; + auto resp = clients[sid]->send_set_demodulator_param(demod_val,value); + if (resp == response_type::error) + return ERROR; + + return OK; + } + catch(const std::exception& e) + { + return ERROR; + } +} +EXTERNC CP_Result CP_ModulatorParams(TSID sid, const char *modulator_param, uint32_t value) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + modulator_value mod_val; + std::string param_name(modulator_param); + if(param_name == "baudrate") + mod_val = modulator_value::baud_rate; + else if (param_name == "center_freq") + mod_val = modulator_value::lo_freaquency; + else if (param_name == "temp_treshold") + mod_val = modulator_value::temp_treshold; + else if (param_name == "modcod") + mod_val = modulator_value::modcod; + else if (param_name == "reset") + mod_val = modulator_value::mod_reset; + else if (param_name == "rollof") + mod_val = modulator_value::rollof; + else if (param_name == "mode_trans") + mod_val = modulator_value::mode_transmitt; + else if (param_name == "gold_seq") + mod_val = modulator_value::gold_seq; + + else return ERROR; + auto resp = clients[sid]->send_modulator_param(mod_val,value); + if (resp == response_type::error) + return ERROR; + + return OK; + } + catch(const std::exception& e) + { + return ERROR; + } +} + +EXTERNC CP_Result CP_RadioEnable(TSID sid, const char *radio_interface, bool on_of) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + cmd_radio radio; + std::string radio_name(radio_interface); + if(radio_name == "TX1") + radio = cmd_radio::tx1; + else if (radio_name == "TX2") + radio = cmd_radio::tx2; + else if (radio_name == "RX1") + radio = cmd_radio::rx1; + else if (radio_name == "RX2") + radio = cmd_radio::rx2; + else if(radio_name == "GLOBAL") + radio = cmd_radio::global; + else if(radio_name == "GLOBAL2") + radio = cmd_radio::global2; + else return ERROR; + + auto resp = clients[sid]->send_radio_enable(radio,on_of); + if (resp == response_type::error) + return ERROR; + + return OK; + } + catch(const std::exception& e) + { + return ERROR; + } + +} +EXTERNC CP_Result CP_SetGain(TSID sid,const char *gain_interface,double gain){ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + gain_value value; + std::string gain_name(gain_interface); + if(gain_name == "TX1") + value = gain_value::tx1; + else if (gain_name == "TX2") + value = gain_value::tx2; + else if (gain_name == "RX1") + value = gain_value::rx1; + else if (gain_name == "RX2") + value = gain_value::rx2; + else return ERROR; + + auto resp = clients[sid]->send_set_gain_param(value,gain); + if (resp == response_type::error) + return ERROR; + + return OK; + } + catch(const std::exception& e) + { + return ERROR; + } +} + +EXTERNC CP_Result CP_GetGain(TSID sid, const char *gain_interface, double *gain){ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + double gain_from_server; + gain_value value; + std::string gain_name(gain_interface); + if(gain_name == "TX1") + value = gain_value::tx1; + else if (gain_name == "TX2") + value = gain_value::tx2; + else if (gain_name == "RX1") + value = gain_value::rx1; + else if (gain_name == "RX2") + value = gain_value::rx2; + else if (gain_name == "TXPWD") + value = gain_value::txpwd; + else if (gain_name == "RXPWD") + value = gain_value::rxpwd; + else return ERROR; + + auto resp = clients[sid]->send_get_gain_param(value,gain_from_server); + if (resp == response_type::error) + return ERROR; + *gain = gain_from_server; + return OK; + } + catch(const std::exception& e) + { + return ERROR; + } + +} + +EXTERNC CP_Result CP_SetDemFreq(TSID sid, uint32_t freq) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + + auto resp = clients[sid]->send_set_dem_freq_cmd(freq); + if (resp == response_type::error) + return ERROR; + + return OK; + } + catch(const std::exception & e) + { + return ERROR; + } +} + +EXTERNC CP_Result CP_GetDemFreq(TSID sid, uint32_t * freq) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + + uint32_t freq_from_serv; + auto resp = clients[sid]->send_get_dem_freq_cmd(freq_from_serv); + if (resp == response_type::error) + return ERROR; + + *freq = freq_from_serv; + return OK; + } + catch(const std::exception & e) + { + return ERROR; + } +} + + +EXTERNC CP_Result CP_Login(const char * user, const char * pwd, TSID * sid, unsigned int * access) +{ + std::unique_lock lock(mtx); + try + { + clients[sid_counter] = std::make_unique("/tmp/control.sock"); + access_rights access_lvl; + auto resp = clients[sid_counter]->send_login_cmd(user, pwd, access_lvl); + *access = static_cast(access_lvl); + *sid = sid_counter; + + if (resp == response_type::error) + return ERROR; + + while (clients.find(sid_counter) != clients.end()) + sid_counter++; + + return OK; + } + catch(const std::exception & e) + { + return ERROR; + } +} + +EXTERNC CP_Result CP_Logout(TSID sid) +{ + std::unique_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + + auto resp = clients[sid]->send_logout_cmd(); + if (resp == response_type::error) + return ERROR; + + clients.erase(sid); + return OK; + } + catch(const std::exception & e) + { + return ERROR; + } +} + +EXTERNC void CP_SetCmdStdoutCallback(TSID sid, CP_cmd_stdout_cb cb) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return; + + clients[sid]->set_stdout_callback(cb); + } + catch(const std::exception & e) + { + return; + } +} + +EXTERNC CP_Result CP_Ping(TSID sid, const char * ip_address, int packet_count) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end() || packet_count < 1) + return ERROR; + + auto resp = clients[sid]->send_ping_cmd(ip_address, static_cast(packet_count)); + if (resp == response_type::error) + return ERROR; + else if (resp == response_type::abort) + return ABORT; + + return OK; + } + catch(const std::exception & e) + { + return ERROR; + } +} + +EXTERNC CP_Result CP_Traceroute(TSID sid, const char * ip_address) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + + auto resp = clients[sid]->send_traceroute_cmd(ip_address); + if (resp == response_type::error) + return ERROR; + else if (resp == response_type::abort) + return ABORT; + + return OK; + } + catch(const std::exception & e) + { + return ERROR; + } +} + +EXTERNC void CP_CmdAbort(TSID sid) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return; + + clients[sid]->abort(); + } + catch(const std::exception & e) + { + return; + } +} + +EXTERNC CP_Result CP_ShowInterface(TSID sid, const char * interface) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + + std::string interface_name(interface); + interface_value value; + if (interface_name == "all") + value = interface_value::all; + else if (interface_name == "sat0") + value = interface_value::sat0; + else if (interface_name == "gigabit") + value = interface_value::gigabit; + else if (interface_name == "modulator") + value = interface_value::modulator; + else if (interface_name == "demodulator") + value = interface_value::demodulator; + else + return ERROR; + + auto resp = clients[sid]->send_show_interface_cmd(value); + if (resp == response_type::error) + return ERROR; + else if (resp == response_type::abort) + return ABORT; + + return OK; + } + catch(const std::exception & e) + { + return ERROR; + } +} + +EXTERNC CP_Result CP_Copy(TSID sid, const char * src, const char * dst) +{ + std::shared_lock lock(mtx); + try + { + if (clients.find(sid) == clients.end()) + return ERROR; + + std::string src_str(src); + std::string dst_str(dst); + + fm::side_description src_desc; + fm::side_description dst_desc; + + if (src_str.find("flash:") == 0) + { + src_desc.s_type = fm::side_type::local; + size_t pos = src_str.find(":"); + src_desc.filepath = src_str.substr(pos + 1, src_str.size() - pos - 1); + } + else if (src_str.find("tftp://") == 0) + { + src_desc.s_type = fm::side_type::tftp; + size_t pos = src_str.find("://"); + src_desc.filepath = src_str.substr(pos + 3, src_str.size() - pos - 3); + } + else + return ERROR; + + if (dst_str.find("flash:") == 0) + { + dst_desc.s_type = fm::side_type::local; + size_t pos = dst_str.find(":"); + dst_desc.filepath = dst_str.substr(pos + 1, dst_str.size() - pos - 1); + } + else if (dst_str.find("tftp://") == 0) + { + dst_desc.s_type = fm::side_type::tftp; + size_t pos = dst_str.find("://"); + dst_desc.filepath = dst_str.substr(pos + 3, dst_str.size() - pos - 3); + } + else + return ERROR; + + if (src_desc.s_type == fm::side_type::tftp && dst_desc.s_type == fm::side_type::tftp) + return ERROR; + + auto resp = clients[sid]->send_copy_cmd(src_desc, dst_desc); + if (resp == response_type::error) + return ERROR; + else if (resp == response_type::abort) + return ABORT; + + return OK; + } + catch(const std::exception & e) + { + return ERROR; + } +} diff --git a/dependencies/control_system-dvbs-2/client/sock_client.cpp b/dependencies/control_system-dvbs-2/client/sock_client.cpp new file mode 100644 index 0000000..724e8cc --- /dev/null +++ b/dependencies/control_system-dvbs-2/client/sock_client.cpp @@ -0,0 +1,51 @@ +#include "sock_client.h" + +client::client(boost::asio::io_context & io_context, const std::string & unix_file, std::function&)> func_cb) + : socket_(io_context) + , callback_func(func_cb) +{ + socket_.async_connect(seq_packet::seqpacket_protocol::endpoint(unix_file), + std::bind(&client::handle_connect, this, + std::placeholders::_1)); +} + +client::~client() +{ + do_close(); +} + +void client::write(const std::vector & data) +{ + boost::asio::write(socket_, boost::asio::buffer(data)); +} + +void client::do_close() +{ + socket_.close(); +} + +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)); +} + +void client::handle_connect(const boost::system::error_code & error) +{ + if (!error) + start(); +} + +void client::handle_read(const boost::system::error_code & error, size_t bytes_transferred) +{ + if (!error && callback_func && bytes_transferred) + { + callback_func(std::vector(std::begin(data_), std::begin(data_) + bytes_transferred)); + start(); + } + //else + // do_close(); +} diff --git a/dependencies/control_system-dvbs-2/client/sock_client.h b/dependencies/control_system-dvbs-2/client/sock_client.h new file mode 100644 index 0000000..1d95931 --- /dev/null +++ b/dependencies/control_system-dvbs-2/client/sock_client.h @@ -0,0 +1,24 @@ +#pragma once +#include "../common/seq_packet.h" + +class client +{ +public: + client(boost::asio::io_context & io_context, const std::string & unix_file, std::function&)> func_cb = nullptr); + ~client(); + + void write(const std::vector & data); + void do_close(); + +private: + client(const client&) = delete; + const client& operator=(const client&) = delete; + + seq_packet::seqpacket_protocol::socket socket_; + std::array data_; + std::function&)> callback_func; + + void handle_connect(const boost::system::error_code & error); + void handle_read(const boost::system::error_code & error, size_t bytes_transferred); + void start(); +}; diff --git a/dependencies/control_system-dvbs-2/client/system_client.cpp b/dependencies/control_system-dvbs-2/client/system_client.cpp new file mode 100644 index 0000000..fed86ad --- /dev/null +++ b/dependencies/control_system-dvbs-2/client/system_client.cpp @@ -0,0 +1,755 @@ +#include "system_client.h" + +system_client::system_client(const std::string & unix_file, std::function log_func) + : clt(io_context, unix_file, std::bind(&system_client::data_received, this, std::placeholders::_1)) + , log(log_func) + , ctx_thread([&] { io_context.run(); } ) + , cmd_id(0) + , current_state(state::connected) +{ +} + +system_client::~system_client() +{ + io_context.stop(); + ctx_thread.join(); +} + +state system_client::get_current_state() const +{ + return current_state; +} + +response_type system_client::send_login_cmd(const std::string & username, const std::string & pass, access_rights & access) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + + uint32_t curr_id { ++cmd_id }; + + cmd_header login_cmd_hdr { curr_id, cmd_type::login }; + login_cmd log_req { username, pass }; + send_to_socket(login_cmd_hdr, log_req); + + std::any data_from_serv; + auto result = wait_for_response(curr_id, cmd_type::login, data_from_serv); + + access = access_rights::not_allowed; + if (data_from_serv.has_value()) + access = std::any_cast(data_from_serv); + + return result; +} + +response_type system_client::send_copy_cmd(const fm::side_description & src, const fm::side_description & dst) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + + uint32_t curr_id { ++cmd_id }; + + cmd_header copy_cmd_hdr { curr_id, cmd_type::copy }; + copy_cmd copy_req { src, dst }; + send_to_socket(copy_cmd_hdr, copy_req); + + return wait_for_progressing_response(curr_id, cmd_type::copy); +} + +response_type system_client::send_ping_cmd(const std::string & ip, size_t count) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + + uint32_t curr_id { ++cmd_id }; + + cmd_header ping_cmd_hdr { curr_id, cmd_type::ping }; + ping_cmd ping_req { ip, count }; + send_to_socket(ping_cmd_hdr, ping_req); + + return wait_for_progressing_response(curr_id, cmd_type::ping); +} + +response_type system_client::send_traceroute_cmd(const std::string & ip) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + + uint32_t curr_id { ++cmd_id }; + + cmd_header tracert_cmd_hdr { curr_id, cmd_type::tracert }; + tracert_cmd tracert_req { ip }; + send_to_socket(tracert_cmd_hdr, tracert_req); + + return wait_for_progressing_response(curr_id, cmd_type::tracert); +} + +response_type system_client::send_show_interface_cmd(const interface_value & interface) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + + uint32_t curr_id { ++cmd_id }; + + cmd_header interface_cmd_hdr { curr_id, cmd_type::interface }; + interface_cmd interface_req { interface }; + send_to_socket(interface_cmd_hdr, interface_req); + + return wait_for_progressing_response(curr_id, cmd_type::interface); +} + +response_type system_client::wait_for_progressing_response(uint32_t c_id, const cmd_type & cmd_t) +{ + auto result = response_type::in_progress; + while (result != response_type::ok && result != response_type::error && result != response_type::abort) + { + std::any data_from_serv; + result = wait_for_response(c_id, cmd_t, data_from_serv); + if (data_from_serv.has_value() && stdout_cb) + { + auto & text_bytes = std::any_cast&>(data_from_serv); + std::scoped_lock lock(cb_mtx); + stdout_cb(reinterpret_cast(text_bytes.data()), text_bytes.size()); + } + } + + if (result == response_type::abort) + { + std::scoped_lock lock_1(responses_mtx); + responses.erase(c_id); + responses_data.erase(c_id); + } + + return result; +} + +void system_client::abort() +{ + send_abort(cmd_id); + process_response(cmd_id, response_type::abort, {}); +} + +void system_client::send_abort(uint32_t id) +{ + std::stringstream s; + cmd_header abort_cmd { id, cmd_type::abort }; + { + cereal::BinaryOutputArchive oarchive(s); + oarchive(abort_cmd); + } + std::vector data((std::istream_iterator(s)), std::istream_iterator()); + clt.write(data); +} + +response_type system_client::send_logout_cmd() +{ + if (current_state != state::logged_in) + return response_type::error; + + std::scoped_lock lock(cmd_in_progress_mtx); + + uint32_t curr_id { cmd_id++ }; + + cmd_header logout_cmd_hdr { curr_id, cmd_type::exit }; + std::stringstream s; + { + cereal::BinaryOutputArchive oarchive(s); + oarchive(logout_cmd_hdr); + } + std::vector data((std::istream_iterator(s)), std::istream_iterator()); + clt.write(data); + std::any data_from_serv; + return wait_for_response(curr_id, cmd_type::exit, data_from_serv); +} + +response_type system_client::wait_for_response(uint32_t id, const cmd_type & type, std::any & data) +{ + std::unique_lock lock(responses_mtx); + cv_resp.wait(lock, [&] { return responses.find(id) != responses.end(); } ); + + auto result = std::move(responses[id].front()); + data = std::move(responses_data[id].front()); + + responses[id].pop(); + responses_data[id].pop(); + + if (result != response_type::abort && responses[id].empty()) + { + responses.erase(id); + responses_data.erase(id); + } + + if (result == response_type::ok) + { + switch (type) + { + case cmd_type::login: + { + current_state = state::logged_in; + break; + } + case cmd_type::exit: + { + current_state = state::disconnected; + clt.do_close(); + break; + } + default: break; + } + } + + return result; +} + +void system_client::process_response(uint32_t id, response_type resp, std::any && data) +{ + { + std::scoped_lock lock(responses_mtx); + if (responses.find(id) != responses.end() && responses[id].empty() && responses[id].front() == response_type::abort) + return; + + responses[id].push(resp); + responses_data[id].push(std::move(data)); + } + cv_resp.notify_all(); +} + +void system_client::data_received(const std::vector & data) +{ + std::stringstream ss; + std::copy(data.begin(), data.end(), std::ostream_iterator(ss)); + + cereal::BinaryInputArchive iarchive(ss); + response_header cmd; + iarchive(cmd); + std::any data_from_serv; + + switch (cmd.cmd) + { + case cmd_type::login: + { + if (cmd.rsp == response_type::ok) + { + access_rights access; + iarchive(access); + data_from_serv = access; + } + break; + } + case cmd_type::ping: + case cmd_type::tracert: + case cmd_type::interface: + { + if (cmd.rsp == response_type::in_progress) + { + std::vector data_rsp; + iarchive(data_rsp); + data_from_serv = std::move(data_rsp); + } + break; + } + case cmd_type::get_demodulator_frequency: + { + if (cmd.rsp == response_type::ok) + { + uint32_t freq; + iarchive(freq); + data_from_serv = freq; + } + break; + } + case cmd_type::get_gain_param: + { + if (cmd.rsp == response_type::ok) + { + double gain; + iarchive(gain); + data_from_serv = gain; + } + break; + } + case cmd_type::zynq_param: + { + if (cmd.rsp == response_type::ok) + { + double value; + iarchive(value); + data_from_serv = value; + } + break; + } + + case cmd_type::get_demodulator_param: + { + if (cmd.rsp == response_type::ok) + { + uint32_t value; + iarchive(value); + data_from_serv = value; + } + break; + } + case cmd_type::get_modulator_param: + { + if (cmd.rsp == response_type::ok) + { + uint32_t value; + iarchive(value); + data_from_serv = value; + } + break; + } + case cmd_type::get_level_dmd: + { + if (cmd.rsp == response_type::ok) + { + double value; + iarchive(value); + data_from_serv = value; + } + break; + } + + case cmd_type::get_acm_params: + { + if(cmd.rsp == response_type::ok) + { + cmd_get_acm_param value; + iarchive(value); + data_from_serv = value; + } + break; + } + + case cmd_type::get_dma_debugg: + { + if (cmd.rsp == response_type::ok) + { + std::string value; + iarchive(value); + data_from_serv = value; + } + break; + } + + case cmd_type::get_params_dpdi: + { + if (cmd.rsp == response_type::ok) + { + dpdi_parameters value; + iarchive(value); + data_from_serv = value; + } + break; + } + case cmd_type::get_network: + { + if (cmd.rsp == response_type::ok) + { + std::string value; + iarchive(value); + data_from_serv = value; + } + break; + } + case cmd_type::get_qos_settings: + { + if (cmd.rsp == response_type::ok) + { + std::string value; + iarchive(value); + data_from_serv = value; + } + break; + } + default: break; + } + + process_response(cmd.id, cmd.rsp, std::move(data_from_serv)); +} + +void system_client::set_stdout_callback(std::function cb) +{ + std::scoped_lock lock(cb_mtx); + stdout_cb = cb; +} + +response_type system_client::send_set_dem_freq_cmd(uint32_t freq) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + + uint32_t curr_id { ++cmd_id }; + cmd_header set_dem_freq_cmd_hdr { curr_id, cmd_type::set_demodulator_frequency }; + set_dem_freq_cmd freq_set { freq }; + send_to_socket(set_dem_freq_cmd_hdr, freq_set); + + std::any data_from_serv; + auto result = wait_for_response(curr_id, cmd_type::set_demodulator_frequency , data_from_serv); + + return result; +} + +response_type system_client::send_get_dem_freq_cmd(uint32_t & freq) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + + uint32_t curr_id { ++cmd_id }; + + cmd_header get_dem_freq_cmd_hdr { curr_id, cmd_type::get_demodulator_frequency }; + send_to_socket(get_dem_freq_cmd_hdr); + + std::any data_from_serv; + auto result = wait_for_response(curr_id, cmd_type::get_demodulator_frequency , data_from_serv); + if (data_from_serv.has_value()) + freq = std::any_cast(data_from_serv); + + return result; +} + +response_type system_client::send_get_gain_param(const gain_value & interface_gain, double & gain) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + uint32_t curr_id { ++cmd_id }; + + cmd_header get_gain_cmd_hdr{curr_id,cmd_type::get_gain_param}; + + get_gain_par get_gain_cmd{interface_gain}; + + send_to_socket(get_gain_cmd_hdr,get_gain_cmd); + std::any data_from_serv; + auto result = wait_for_response(curr_id, cmd_type::get_gain_param , data_from_serv); + if (data_from_serv.has_value()) + gain = std::any_cast(data_from_serv); + + return result; +} + +response_type system_client::send_get_demodulator_param(const getdemodulator_value & demod_val, uint32_t & value) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + uint32_t curr_id { ++cmd_id }; + + cmd_header get_demod_param{curr_id,cmd_type::get_demodulator_param}; + + cmd_get_demodulator_param get_dmd_param{demod_val, 0}; + + send_to_socket(get_demod_param,get_dmd_param); + std::any data_from_serv; + auto result = wait_for_response(curr_id, cmd_type::get_demodulator_param , data_from_serv); + if (data_from_serv.has_value()) + value = std::any_cast(data_from_serv); + + return result; +} +response_type system_client::send_get_modulator_param(const modulator_value & mod_val, uint32_t & value) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + uint32_t curr_id { ++cmd_id }; + + cmd_header get_mod_param{curr_id,cmd_type::get_modulator_param}; + + cmd_get_modulator_param cmd_get_mod_param{mod_val, 0}; + + send_to_socket(get_mod_param,cmd_get_mod_param); + std::any data_from_serv; + auto result = wait_for_response(curr_id, cmd_type::get_modulator_param , data_from_serv); + if (data_from_serv.has_value()) + value = std::any_cast(data_from_serv); + + return result; +} + +response_type system_client::send_set_gain_param(const gain_value & interface_gain, double gain) +{ + std::scoped_lock lock (cmd_in_progress_mtx); + uint32_t curr_id { ++cmd_id }; + cmd_header set_gain_cmd_hdr{curr_id, cmd_type::set_gain_param}; + + set_gain_par set_gain_cmd{interface_gain, gain}; + send_to_socket(set_gain_cmd_hdr,set_gain_cmd); + + std::any data_from_serv; + auto result = wait_for_response(curr_id, cmd_type::set_gain_param , data_from_serv); + return result; +} + +response_type system_client::send_radio_enable(const cmd_radio & enable_choice, bool enbl_) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + uint32_t curr_id { ++cmd_id }; + cmd_header radio_enable_cmd_hdr{curr_id, cmd_type::radio_on_of}; + + radio_enable radio_enable_cmd{enable_choice, enbl_}; + send_to_socket(radio_enable_cmd_hdr, radio_enable_cmd); + + std::any data_to_serv; + + auto result = wait_for_response(curr_id, cmd_type::radio_on_of, data_to_serv); + return result; +} +response_type system_client::send_set_demodulator_param(const demodulator_value & demod_val, uint32_t value) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + uint32_t curr_id { ++cmd_id }; + cmd_header demodulator_cmd_hdr{curr_id, cmd_type::set_demodulator_param}; + + cmd_set_demodulator_param demodulator_cmd{demod_val, value}; + send_to_socket(demodulator_cmd_hdr, demodulator_cmd); + + std::any data_to_serv; + + auto result = wait_for_response(curr_id, cmd_type::set_demodulator_param, data_to_serv); + + return result; +} + +response_type system_client::send_modulator_param(const modulator_value & mod_val, uint32_t value) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + uint32_t curr_id { ++cmd_id }; + cmd_header modulator_cmd_hdr{curr_id, cmd_type::modulator_param}; + + cmd_set_modulator_param modulator_cmd{mod_val, value}; + send_to_socket(modulator_cmd_hdr, modulator_cmd); + + std::any data_to_serv; + + auto result = wait_for_response(curr_id, cmd_type::modulator_param, data_to_serv); + + return result; +} + +response_type system_client::send_zynq_cmd(const zynq_value & zynq_val, double & value) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + uint32_t curr_id { ++cmd_id }; + cmd_header zynq_cmd_hdr{curr_id, cmd_type::zynq_param}; + + cmd_zynq_param zynq_cmd{zynq_val}; + send_to_socket(zynq_cmd_hdr, zynq_cmd); + + std::any data_from_serv; + + auto result = wait_for_response(curr_id, cmd_type::zynq_param, data_from_serv); + if (data_from_serv.has_value()) + value = std::any_cast(data_from_serv); + return result; +} + +response_type system_client::send_rollof_and_baudrate(double & rollof, double &baudrate) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + uint32_t curr_id { ++cmd_id }; + cmd_header roll_baud_cmd_hdr{curr_id, cmd_type::set_baudrate_rollof_dmd}; + cmd_set_rollof_and_demod cmd_roll_baud{baudrate, rollof}; + send_to_socket(roll_baud_cmd_hdr, cmd_roll_baud); + + std::any data_to_serv; + auto result = wait_for_response(curr_id, cmd_type::set_baudrate_rollof_dmd, data_to_serv); + return result; + +} + +response_type system_client::send_get_dma_debug(const cmd_get_dma_debugg_enum & dma_debug, std::string &value) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + uint32_t curr_id { ++cmd_id }; + cmd_header get_dma_debug_header{curr_id, cmd_type::get_dma_debugg}; + + cmd_get_dma_debug val_cmd{value, dma_debug}; + send_to_socket(get_dma_debug_header, val_cmd); + + std::any data_from_serv; + + auto result = wait_for_response(curr_id, cmd_type::get_dma_debugg, data_from_serv); + if (data_from_serv.has_value()) + value = std::any_cast(data_from_serv); + return result; +} + +response_type system_client::send_get_level_dem(const cmd_level_dem & lvl_dem_val, double &value) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + uint32_t curr_id { ++cmd_id }; + cmd_header snr_cmd_hdr{curr_id, cmd_type::get_level_dmd}; + + cmd_get_level_dem val_cmd{value, lvl_dem_val}; + send_to_socket(snr_cmd_hdr, val_cmd); + + std::any data_from_serv; + + auto result = wait_for_response(curr_id, cmd_type::get_level_dmd, data_from_serv); + if (data_from_serv.has_value()) + value = std::any_cast(data_from_serv); + return result; +} + +response_type system_client::send_get_acm_params(cmd_get_acm_param &acm_params) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + uint32_t curr_id { ++cmd_id }; + cmd_header cmd_acm_header{curr_id, cmd_type::get_acm_params}; + + send_to_socket(cmd_acm_header, acm_params); + + std::any data_from_serv; + + auto result = wait_for_response(curr_id, cmd_type::get_acm_params, data_from_serv); + if (data_from_serv.has_value()) + acm_params = std::any_cast(data_from_serv); + + return result; +} + +response_type system_client::send_set_qos_params(const std::string &node, const name_classes_qos & class_qos) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + uint32_t curr_id { ++cmd_id }; + cmd_header cmd_qos_header{curr_id, cmd_type::set_qos_settings}; + cmd_set_qos_settings qos_settings{node, class_qos}; + + send_to_socket(cmd_qos_header, qos_settings); + + std::any data_to_serv; + + auto result = wait_for_response(curr_id, cmd_type::set_qos_settings, data_to_serv); + + return result; +} + +response_type system_client::send_get_qos_params(std::string &node, const name_classes_qos & class_qos) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + uint32_t curr_id { ++cmd_id }; + cmd_header cmd_qos_header{curr_id, cmd_type::get_qos_settings}; + cmd_get_qos_settings qos_settings{node, class_qos}; + + send_to_socket(cmd_qos_header, qos_settings); + + std::any data_from_serv; + + auto result = wait_for_response(curr_id, cmd_type::get_qos_settings, data_from_serv); + if (data_from_serv.has_value()) + node = std::any_cast(data_from_serv); + return result; +} + +response_type system_client::send_set_10g_config(const cmd_10g_config & _10g_config, std::string &value) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + uint32_t curr_id { ++cmd_id }; + cmd_header _10g_config_header{curr_id, cmd_type::set_10g_config}; + + cmd_set_10g_config _10g_config_cmd{value, _10g_config}; + send_to_socket(_10g_config_header, _10g_config_cmd); + + std::any data_to_serv; + + auto result = wait_for_response(curr_id, cmd_type::set_10g_config, data_to_serv); + + return result; +} + +response_type system_client::send_set_dma_debug(const cmd_dma_debugg & dma_debugg, std::string &value) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + uint32_t curr_id { ++cmd_id }; + cmd_header dma_debug_header{curr_id, cmd_type::set_dma_debugg}; + + cmd_set_dma_debug cmd_dma_debug{value, dma_debugg}; + send_to_socket(dma_debug_header, cmd_dma_debug); + + std::any data_to_serv; + + auto result = wait_for_response(curr_id, cmd_type::set_dma_debugg, data_to_serv); + + return result; +} + +response_type system_client::send_set_lbq_params(const uint32_t & tick_ms, const uint32_t & bucket_size) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + uint32_t curr_id { ++cmd_id }; + cmd_header lbq_debug_header{curr_id, cmd_type::set_lbq_params}; + + cmd_lbq_params params{tick_ms, bucket_size}; + + send_to_socket(lbq_debug_header, params); + + std::any data_to_serv; + + auto result = wait_for_response(curr_id, cmd_type::set_lbq_params, data_to_serv); + + return result; +} + +response_type system_client::send_set_acm_params(const ACM_parameters_serv &acm_params) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + uint32_t curr_id { ++cmd_id }; + cmd_header cmd_acm_header{curr_id, cmd_type::set_acm_params}; + + cmd_set_acm_param cmd_set_acm{acm_params}; + send_to_socket(cmd_acm_header, cmd_set_acm); + + std::any data_to_serv; + + auto result = wait_for_response(curr_id, cmd_type::set_acm_params, data_to_serv); + + return result; +} + +response_type system_client::send_set_dpdi_params(dpdi_parameters &dpdi_params) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + uint32_t curr_id { ++cmd_id }; + cmd_header cmd_dpdi_header{curr_id, cmd_type::set_params_dpdi}; + + dpdi_parameters cmd_set_dpdi{dpdi_params}; + send_to_socket(cmd_dpdi_header, cmd_set_dpdi); + + std::any data_to_serv; + + auto result = wait_for_response(curr_id, cmd_type::set_params_dpdi, data_to_serv); + + return result; +} + +response_type system_client::send_get_dpdi_params(dpdi_parameters &dpdi_params) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + uint32_t curr_id { ++cmd_id }; + cmd_header cmd_dpdi_header{curr_id, cmd_type::get_params_dpdi}; + + send_to_socket(cmd_dpdi_header, dpdi_params); + + std::any data_from_serv; + + auto result = wait_for_response(curr_id, cmd_type::get_params_dpdi, data_from_serv); + if (data_from_serv.has_value()) + dpdi_params = std::any_cast(data_from_serv); + + return result; +} + +response_type system_client::send_network_settings(const network_value & cmd_netw, const std::string & value) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + uint32_t curr_id { ++cmd_id }; + cmd_header network_cmd_hdr{curr_id, cmd_type::set_network}; + cmd_set_network cmd_network{value, cmd_netw}; + send_to_socket(network_cmd_hdr, cmd_network); + + std::any data_to_serv; + auto result = wait_for_response(curr_id, cmd_type::set_network, data_to_serv); + return result; +} + +response_type system_client::send_get_network_settings(const network_value & cmd_netw, std::string & value) +{ + std::scoped_lock lock(cmd_in_progress_mtx); + uint32_t curr_id { ++cmd_id }; + cmd_header cmd_network_hdr{curr_id, cmd_type::get_network}; + cmd_get_network cmd_network{value, cmd_netw}; + send_to_socket(cmd_network_hdr, cmd_network); + + std::any data_from_serv; + auto result = wait_for_response(curr_id, cmd_type::get_network, data_from_serv); + if (data_from_serv.has_value()) + value = std::any_cast(data_from_serv); + return result; +} \ No newline at end of file diff --git a/dependencies/control_system-dvbs-2/client/system_client.h b/dependencies/control_system-dvbs-2/client/system_client.h new file mode 100644 index 0000000..bdd4bc8 --- /dev/null +++ b/dependencies/control_system-dvbs-2/client/system_client.h @@ -0,0 +1,105 @@ +#pragma once +#include +#include +#include +#include "sock_client.h" +#include "../common/protocol_commands.h" + +enum class state +{ + disconnected, + connected, + logged_in +}; + +class system_client +{ +public: + system_client(const std::string & unix_file, std::function log_func = nullptr); + ~system_client(); + + state get_current_state() const; + + response_type send_login_cmd (const std::string & username, const std::string & pass, access_rights & access); + response_type send_logout_cmd (); + response_type send_ping_cmd (const std::string & ip, size_t count); + response_type send_traceroute_cmd (const std::string & ip); + response_type send_show_interface_cmd(const interface_value & interface); + response_type send_copy_cmd (const fm::side_description & src, const fm::side_description & dst); + + response_type send_set_dem_freq_cmd(uint32_t freq); + response_type send_get_dem_freq_cmd(uint32_t & freq); + + response_type send_set_gain_param (const gain_value & interface_gain, double gain); + response_type send_get_gain_param (const gain_value & interface_gain, double & gain); + response_type send_radio_enable (const cmd_radio & enable_choice, bool enbl_); + response_type send_modulator_param(const modulator_value & mod_val, uint32_t value); + response_type send_get_modulator_param(const modulator_value & mod_val, uint32_t &value); + response_type send_set_demodulator_param(const demodulator_value & demod_val, uint32_t value); + response_type send_get_demodulator_param(const getdemodulator_value & demod_val, uint32_t &value); + response_type send_zynq_cmd(const zynq_value & zynq_val, double & value); + response_type send_network_settings(const network_value & cmd_netw, const std::string & value); + response_type send_get_network_settings(const network_value & cmd_netw, std::string & value); + response_type send_rollof_and_baudrate(double & rollof, double &baudrate); + response_type send_get_level_dem(const cmd_level_dem & lvl_dem_val, double &value); + response_type send_get_dma_debug(const cmd_get_dma_debugg_enum & dma_debug, std::string &value); + response_type send_set_10g_config(const cmd_10g_config & _10g_config, std::string &value); + response_type send_set_dma_debug(const cmd_dma_debugg & dma_debugg, std::string &value); + 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_set_dpdi_params(dpdi_parameters &dpdi_params); + response_type send_get_dpdi_params(dpdi_parameters &dpdi_params); + + response_type send_set_lbq_params(const uint32_t & tick_ms, const uint32_t & bucket_size); + + response_type send_set_qos_params(const std::string &node, const name_classes_qos & class_qos); + response_type send_get_qos_params(std::string &node, const name_classes_qos & class_qos); + + + void set_stdout_callback(std::function cb); + void abort(); + +private: + system_client(const system_client&) = delete; + const system_client& operator=(const system_client&) = delete; + + boost::asio::io_context io_context; + client clt; + std::function log; + std::thread ctx_thread; + std::atomic cmd_id; + + std::mutex cb_mtx; + std::function stdout_cb; + + std::mutex responses_mtx; + std::map> responses; + std::map> responses_data; + std::condition_variable cv_resp; + + state current_state; + + std::mutex cmd_in_progress_mtx; + + response_type wait_for_response (uint32_t id, const cmd_type & type, std::any & data); + response_type wait_for_progressing_response(uint32_t c_id, const cmd_type & cmd_t); + void process_response (uint32_t id, response_type resp, std::any && data); + void data_received (const std::vector & data); + void send_abort (uint32_t id); + + template + void send_to_socket(Args&&... args) + { + //TO-DO: need case for empty parameter pack? + std::stringstream s; + s << std::noskipws; + { + cereal::BinaryOutputArchive oarchive(s); + oarchive(std::forward(args)...); + } + std::vector data((std::istream_iterator(s)), std::istream_iterator()); + clt.write(data); + + } +}; diff --git a/dependencies/control_system-dvbs-2/common/protocol_commands.h b/dependencies/control_system-dvbs-2/common/protocol_commands.h new file mode 100644 index 0000000..cd3fd34 --- /dev/null +++ b/dependencies/control_system-dvbs-2/common/protocol_commands.h @@ -0,0 +1,671 @@ +#pragma once +#include +#include +#include + +namespace fm +{ + enum class side_type + { + local = 0, + tftp = 1, + config = 2 + }; + + struct side_description + { + side_type s_type; + std::string filepath; + + template + void serialize(Archive & archive) + { + archive(s_type, filepath); + } + }; +} + +enum class cmd_dma_debugg +{ + start = 0, + stop = 1, + reset = 2, + reinit = 3, + modcod = 4, + log_bool = 5, + data_mode = 6, + default_params = 7, + buc_voltage = 8, + lnb_voltage = 9, + _10mhz_tx = 10, + _10mhz_rx = 11, + powerdown_plata = 12, + _10MHz_out = 13, + current_state_tx = 14, + current_state_oib = 15, + save_config = 16, + begin_save_config = 17 +}; + +enum class name_classes_qos +{ + realtime1 = 0, + realtime2, + realtime3, + critical1, + critical2, + critical3, + cir, + pir, + wcr1, + wcr2, + wcr3, + enable, + ful_node +}; + +enum class cmd_get_dma_debugg_enum +{ + speed_tx = 0, + speed_rx = 1, + modcod = 2, + drop_bad_rx = 3, + drop_full_rx = 4, + packet_ok_rx = 5, + packet_little_tx = 6, + packet_big_tx = 7, + bad_modcod_tx = 8, + bad_length_tx = 9, + reset_cnt_rx = 10, + data_mode = 11, + buc_voltage = 12, + lnb_voltage = 13, + _10mhz_tx = 14, + _10mhz_rx = 15, + powerdown_plata = 16, + _10MHz_out = 17, + current_state_tx = 18, + real_dpdi_shift = 19, + freq_error_offset = 20, + freq_fine_estimate = 21, + speed_tx_iface = 22, + speed_rx_iface = 23, + current_state_oib = 24, + ratio_signal_signal = 25, + status_init = 26 +}; + +enum class cmd_10g_config +{ + udp_payload_lenght = 0, + local_ip = 1, + dest_ip = 2, + gateway_ip = 3, + subnet_mask = 4, + udp_source_port = 5, + udp_dest_port = 6, + local_mac_31_0 = 7, + local_mac_32_47 = 8, + mtx_chan0 = 9, + mtx_chan1 = 10 +}; + +enum class cmd_level_dem +{ + //! ОСШ на входе + snr = 0, + //! RSSI на входе + rssi = 1, + sym_sync_lock = 2, + freq_search_lock = 3, + afc_lock = 4, + pkt_sync = 5, + phase_inv = 6, + afc_error = 7, + sym_error = 8, + fine_freq_error = 9, + crs_freq_error = 10, + gc_gain_aru = 11, + rollof = 12, + carrier_lock = 13, + filt_adapt_lock = 14, + snr_acm = 15, + modcod_tx = 16 +}; + +enum class interface_value +{ + all = 0, + sat0 = 1, + gigabit = 2, + modulator = 3, + demodulator = 4 +}; + +enum class zynq_value +{ + ps_volt = 0, + pl_volt = 1, + adrv_temp = 2, + pl_temp = 3, + ps_temp = 4, + adrv_temp2 = 5 +}; + +enum class modulator_value +{ + lo_freaquency = 0, + baud_rate = 1, + temp_treshold = 2, + mod_reset = 3, + modcod = 4, + rollof = 5, + mode_transmitt = 6, + if_overload = 7, + gold_seq = 8 +}; + +enum class demodulator_value +{ + lo_freaquency = 0, + baud_rate = 1, + freq_search = 2, + demod_reset = 3, + fec_frame_size = 4, + rvt = 5, + mode_gain_control = 6, + sig_min = 7, + sig_max = 8, + afc_rst = 9, + mode_demod = 10, + gold_seq = 11, + attitude_signals = 12, + is_reset_CinC = 13 +}; +enum class getdemodulator_value +{ + lo_freaquency = 0, + baud_rate = 1, + dummy_counter = 2, + modcod = 3, + mode_gain_control = 4, + sig_min = 5, + sig_max = 6, + rvt = 7, + fec_size = 8, + mode_demod = 9, + cnt_bad_lock_cinc = 10, + gold_seq = 11, + attitude_signals = 12, + cnt_dem_time_sinc = 13, + cnt_dem_lock_afc = 14, + cnt_dem_sync_pack = 15, + cnt_dem_sinc_frec_corse = 16, + freq_lock_estimate = 17, + freq_fine_estimate = 18, + is_reset_CinC = 19, + type_pack = 20, + is_pilots = 21 +}; + +enum class gain_value +{ + tx1 = 0, + tx2 = 1, + rx1 = 2, + rx2 = 3, + txpwd = 4, + rxpwd = 5 +}; + +enum class acm_value +{ + enable = 0, + modcod_min = 1, + modcod_max = 2, + attenuation_min = 3, + attenuatin_max = 4, + required_snr = 5 +}; + +enum class cmd_radio +{ + tx1 = 0, + tx2 = 1, + rx1 = 2, + rx2 = 3, + global = 4, + global2 = 5 +}; + +enum class network_value +{ + network = 0, + mode_interface = 1, + version = 2, + mask = 3, + gateway = 4, + dhcp_on = 5, + dhcp_range = 6, + network_data = 7, + chip_id = 8, + serial = 9, + mac_eth0 = 10, + mac_eth1 = 11, + name_serv = 12, + network_debug_send = 13, + network_port_metric = 14, + network_port_data = 15, + periodic_send_metrics = 16, + if_debug_mode = 17 +}; + +enum class cmd_type +{ + login = 0, + exit = 1, + ping = 2, + tracert = 3, + interface = 4, + copy = 5, + abort = 6, + set_demodulator_frequency = 7, + get_demodulator_frequency = 8, + set_gain_param = 9, + get_gain_param = 10, + radio_on_of = 11, + modulator_param = 12, + zynq_param = 13, + set_demodulator_param = 14, + get_demodulator_param = 15, + get_modulator_param = 16, + set_network = 17, + get_level_dmd = 18, + set_10g_config = 19, + set_dma_debugg = 20, + get_dma_debugg = 21, + set_baudrate_rollof_dmd = 22, + set_acm_params = 23, + get_acm_params = 24, + set_params_dpdi = 25, + get_params_dpdi = 26, + get_network = 27, + set_qos_settings = 28, + get_qos_settings = 29, + set_lbq_params = 30 +}; + +struct cmd_lbq_params +{ + uint32_t tick_ms; + uint32_t bucket_size; + template + void serialize(Archive & archive) + { + archive(tick_ms, bucket_size); + } +}; + + +struct cmd_get_network +{ + std::string network; + network_value net_val; + template + void serialize(Archive & archive) + { + archive(net_val, network); + } +}; + +struct cmd_set_network +{ + std::string network; + network_value net_val; + template + void serialize(Archive & archive) + { + archive(net_val, network); + } +}; + +struct dpdi_parameters +{ + uint8_t latitude_station_grad = 0; + uint8_t latitude_station_minute = 0; + uint8_t longitude_station_grad = 0; + uint8_t longitude_station_minute = 0; + uint8_t longitude_sattelite_grad = 0; + uint8_t longitude_sattelite_minute = 0; + bool is_delay_window = 0; + uint32_t max_delay = 1; + uint32_t min_delay = 0; + uint32_t freq_offset = 0; + template + void serialize(Archive & archive) + { + archive(latitude_station_grad, latitude_station_minute, + longitude_station_grad, longitude_station_minute, + longitude_sattelite_grad, longitude_sattelite_minute, + is_delay_window, max_delay, min_delay, freq_offset); + } +}; + + +struct ACM_parameters_serv +{ + double snr_treashold = 0; + double snr_treashold_acm = 0.5; + uint32_t period_pack = 15; + uint8_t max_modcod = 4; + uint8_t min_modcod = 4; + int max_attenuation = 0; + int min_attenuation = 0; + bool enable = false; + bool enable_auto_atten = false; +}; + +struct cmd_get_acm_param +{ + double snr_treashold = 0; + double snr_treashold_acm = 0.5; + uint32_t period_pack = 15; + uint8_t max_modcod = 4; + uint8_t min_modcod = 4; + int max_attenuation = 0; + int min_attenuation = 0; + bool enable = false; + bool enable_auto_atten = false; + template + void serialize(Archive & archive) + { + archive(enable, max_attenuation, max_modcod, min_attenuation, min_modcod, snr_treashold, enable_auto_atten, snr_treashold_acm, period_pack); + } +}; + +struct cmd_set_qos_settings +{ + std::string node; + name_classes_qos class_qos; + template + void serialize(Archive & archive) + { + archive(node, class_qos); + } +}; + +struct cmd_get_qos_settings +{ + std::string node; + name_classes_qos class_qos; + template + void serialize(Archive & archive) + { + archive(node, class_qos); + } +}; + +struct cmd_set_acm_param +{ + ACM_parameters_serv acm_params; + template + void serialize(Archive & archive) + { + archive(acm_params.enable, acm_params.max_attenuation, acm_params.max_modcod, acm_params.min_attenuation, acm_params.min_modcod, acm_params.snr_treashold, acm_params.enable_auto_atten, acm_params.snr_treashold_acm, acm_params.period_pack); + } +}; + + +struct cmd_get_dma_debug +{ + std::string value; + cmd_get_dma_debugg_enum dma_debugg; + template + void serialize(Archive & archive) + { + archive(dma_debugg, value); + } +}; + +struct cmd_set_dma_debug +{ + std::string value; + cmd_dma_debugg dma_debugg; + template + void serialize(Archive & archive) + { + archive(dma_debugg, value); + } +}; + +struct cmd_set_10g_config +{ + std::string value; + cmd_10g_config _10g_config; + template + void serialize(Archive & archive) + { + archive(_10g_config, value); + } +}; + +struct cmd_get_level_dem +{ + double value; + cmd_level_dem lvl_dem; + template + void serialize(Archive & archive) + { + archive(lvl_dem, value); + } +}; + +struct cmd_zynq_param +{ + zynq_value cmd_zynq; + template + void serialize(Archive & archive) + { + archive(cmd_zynq); + } +}; + +struct radio_enable +{ + cmd_radio cmd_radio_; + bool enbl; + template + void serialize(Archive & archive) + { + archive(cmd_radio_, enbl); + } +}; + +struct cmd_set_modulator_param +{ + modulator_value mod_val; + long long value; + + template + void serialize(Archive & archive) + { + archive(mod_val,value); + } +}; +struct cmd_get_modulator_param +{ + modulator_value mod_val; + uint32_t value; + + template + void serialize(Archive & archive) + { + archive(mod_val,value); + } +}; + +struct cmd_set_rollof_and_demod +{ + double baudrate; + double rollof; + template + void serialize(Archive & archive) + { + archive(baudrate,rollof); + } +}; + + +struct cmd_set_demodulator_param +{ + demodulator_value demod_val; + uint32_t value; + template + void serialize(Archive & archive) + { + archive(demod_val,value); + } +}; + +struct cmd_get_demodulator_param +{ + getdemodulator_value demod_val; + uint32_t value; + + template + void serialize(Archive & archive) + { + archive(demod_val,value); + } +}; + +struct set_gain_par +{ + gain_value g_val; + double _gain; + + template + void serialize(Archive & archive) + { + archive(g_val,_gain); + } +}; + +struct get_gain_par +{ + gain_value g_val; + template + void serialize(Archive & archive) + { + archive(g_val); + } +}; + +struct set_dem_freq_cmd +{ + uint32_t frequency; + template + void serialize(Archive & archive) + { + archive(frequency); + } +}; + +enum class response_type +{ + ok = 0, + error = 1, + in_progress = 3, + abort = 4, + busy = 5 +}; + +enum class access_rights +{ + not_allowed = 0, + user = 1, + admin = 2 +}; + +struct cmd_header +{ + uint32_t id; + cmd_type cmd; + + template + void serialize(Archive & archive) + { + archive(id, cmd); + } +}; + +struct login_cmd +{ + std::string username; + std::string pass; + + template + void serialize(Archive & archive) + { + archive(username, pass); + } +}; + +struct ping_cmd +{ + std::string ip_address; + size_t count; + + template + void serialize(Archive & archive) + { + archive(ip_address, count); + } +}; + +struct tracert_cmd +{ + std::string ip_address; + + template + void serialize(Archive & archive) + { + archive(ip_address); + } +}; + +struct interface_cmd +{ + interface_value val; + + template + void serialize(Archive & archive) + { + archive(val); + } +}; + +struct copy_cmd +{ + fm::side_description src; + fm::side_description dst; + + template + void serialize(Archive & archive) + { + archive(src, dst); + } +}; + +struct response_header +{ + uint32_t id; + cmd_type cmd; + response_type rsp; + + template + void serialize(Archive & archive) + { + archive(id, cmd, rsp); + } +}; diff --git a/dependencies/control_system-dvbs-2/common/seq_packet.h b/dependencies/control_system-dvbs-2/common/seq_packet.h new file mode 100644 index 0000000..60e1c82 --- /dev/null +++ b/dependencies/control_system-dvbs-2/common/seq_packet.h @@ -0,0 +1,23 @@ +#pragma once +#include + +namespace seq_packet +{ + using namespace boost::asio::local; + + struct seqpacket_protocol + { + int type() const { return SOCK_SEQPACKET; } + int protocol() const { return 0; } + int family() const { return AF_UNIX; } + + using endpoint = basic_endpoint; + using socket = boost::asio::basic_stream_socket; + using acceptor = boost::asio::basic_socket_acceptor; + +#if !defined(BOOST_ASIO_NO_IOSTREAM) + /// The UNIX domain iostream type. + typedef boost::asio::basic_socket_iostream iostream; +#endif // !defined(BOOST_ASIO_NO_IOSTREAM) + }; +}