Files
kunlun/cli/host_interface/iot_cli_basic_operation.c
2024-09-28 14:24:04 +08:00

159 lines
4.6 KiB
C

/****************************************************************************
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
be copied by any method or incorporated into another program without
the express written consent of Aerospace C.Power. This Information or any portion
thereof remains the property of Aerospace C.Power. The Information contained herein
is believed to be accurate and Aerospace C.Power assumes no responsibility or
liability for its use in any way and conveys no license or title under
any patent or copyright and makes no representation or warranty that this
Information is free from patent or copyright infringement.
****************************************************************************/
#include "iot_io.h"
#include "iot_utils_api.h"
#include "iot_system.h"
#include "iot_uart_h.h"
#include "iot_cli.h"
#include "iot_cli_host_interface.h"
#include "iot_cli_plc_module.h"
#include "iot_oem_api.h"
#include "iot_cli_tx_rx.h"
#include "iot_cli_basic_operation.h"
#include "iot_board_api.h"
#include "iot_version_api.h"
#if HW_PLATFORM == HW_PLATFORM_SIMU
#include "simulator_txrx.h"
extern uint32_t g_ip_addr;
#else
#include "iot_log_api.h"
#endif
extern iot_cli_t cli;
extern uint32_t g_fw_mode;
extern iot_plc_host_config_t *host_config;
void cli_set_snr(uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
{
#if HW_PLATFORM == HW_PLATFORM_SIMU
(void)bufferlen;
(void)src_mac;
snr_hdr_t *hdr = (snr_hdr_t*)buffer;
uint8_t is_plc = 1;
if (sizeof(snr_hdr_t) > 8 && hdr->mode == 0) {
is_plc = 0;
}
uint32_t infonum = hdr->num;
uint8_t addr[52] = { 0 };
os_ntoa(hdr->dest_addr, addr);
if (hdr->dest_addr != g_ip_addr) {
return;
}
for (uint32_t i = 0; i < infonum; i++) {
memset(addr, 0, sizeof(addr));
snr_info_t *info =
(snr_info_t *)&buffer[sizeof(snr_hdr_t) + i*(sizeof(snr_info_t))];
if (info->ip_addr == 0) {
continue;
}
os_ntoa(info->ip_addr, addr);
iot_printf("set snr, ip:%s, sr:%d, phase:%d, src_phase:%d\n", addr,
info->snr, info->phase, info->src_phase);
if (is_plc) {
update_sr(
(char*)&addr[0], (uint8_t)info->snr,
info->phase, info->src_phase);
}
else {
update_rf_sr(
(char*)&addr[0], (uint8_t)info->snr);
}
}
#else
(void)buffer;
(void)bufferlen;
(void)src_mac;
#endif
}
void cli_force_crash(uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
{
(void)src_mac;
#if HW_PLATFORM == HW_PLATFORM_SIMU
IOT_ASSERT(bufferlen == sizeof(uint32_t));
uint32_t* dest_addr = (uint32_t*)buffer;
uint8_t addr[52] = { 0 };
os_ntoa(*dest_addr, addr);
if (*dest_addr != g_ip_addr) {
return;
}
IOT_ASSERT(0);
#else
(void)buffer;
(void)bufferlen;
iot_printf("cli force crash\n");
IOT_ASSERT(0);
#endif
}
void cli_uart_test(uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
{
(void)src_mac;
iot_printf("cli uart loop back test, bufferlen:%d\n", bufferlen);
cli_send_module_msg(CLI_MODULEID_COMMUNICATION, CLI_MSGID_UART_TEST_RESP,
buffer, bufferlen);
}
void cli_set_baudrate(uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
{
(void)src_mac;
uint32_t baudrate = 0;
uint8_t set = 0;
if ((!buffer) || (bufferlen < sizeof(uint32_t))) {
return;
}
baudrate = *((uint32_t *)buffer);
if (g_fw_mode == FTM_MODE)
{
bool_t ret = false;
ret = iot_uart_set_config(cli.commu.uart_handle, baudrate,
CLI_FTM_PARITY, CLI_FTM_DATA_BITS, CLI_FTM_STOP_BITS);
if (ret)
{
set = 1;
}
iot_printf("cli_set_baudrate baud %d ret %d\n", baudrate, ret);
}
else {
iot_printf("cli_set_baudrate ignore, not in ftm mode\n");
}
iot_cli_send_to_host(
CLI_MSGID_SET_BAUD_RATE_ACK, &set, sizeof(set), src_mac);
}
void cli_get_local_info(uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
{
(void)buffer;
(void)bufferlen;
local_info_t info;
info.role = host_config->dev_role;
info.ver_type = iot_version_type();
info.user_type = iot_oem_get_user_type();
iot_mac_addr_cpy(info.mac_addr, host_config->mac_addr);
info.hw_ver = iot_board_hw_version_hex();
info.sw_ver = iot_version_hex();
iot_cli_send_to_host(CLI_MSGID_GET_LOCAL_INFO_RESP, (uint8_t *)&info,
sizeof(info), src_mac);
}