311 lines
8.6 KiB
C
311 lines
8.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_errno.h"
|
|
#include "iot_io.h"
|
|
#include "iot_app.h"
|
|
#include "iot_config.h"
|
|
#include "iot_system.h"
|
|
|
|
#include "iot_oem_api.h"
|
|
#include "iot_board_api.h"
|
|
|
|
#include "iot_cli_host_interface.h"
|
|
#include "iot_cli_plc_module.h"
|
|
#include "iot_cli_plc_tx_rx.h"
|
|
#include "iot_cli_plc_nw.h"
|
|
#include "iot_cli_host_upgrade.h"
|
|
#include "iot_cli_ckb.h"
|
|
#include "iot_cli_dbg_log.h"
|
|
#include "iot_cli_ada_dump.h"
|
|
#include "iot_cli_ul_buf.h"
|
|
#include "iot_cli_discovery.h"
|
|
#include "iot_cli_rate_test.h"
|
|
#include "iot_cli_set_info.h"
|
|
#include "iot_cli_plc_mgr_alive.h"
|
|
#include "iot_cli_hw_ver.h"
|
|
|
|
#if PLC_SUPPORT_CCO_ROLE
|
|
extern CLI_MSG_ENTRY
|
|
all_cli_cco_msg_entry[];
|
|
#endif
|
|
extern CLI_MSG_ENTRY
|
|
all_cli_sta_msg_entry[];
|
|
extern iot_cli_host_info_t *host_info;
|
|
extern iot_cli_t cli;
|
|
extern uint8_t cli_ftm_mode;
|
|
extern uint32_t cli_module_type;
|
|
|
|
iot_plc_host_config_t *host_config = NULL;
|
|
|
|
#if PLC_COMM_ENABLE
|
|
static uint8_t iot_cli_register()
|
|
{
|
|
iot_plc_app_t host_app;
|
|
host_app.app_id = IOT_PLC_APP_HOST_INTERFACE;
|
|
host_app.param = NULL;
|
|
host_app.prio = 3;
|
|
host_app.recv = iot_cli_plc_recv;
|
|
|
|
host_config->app_handle = iot_plc_register_app(&host_app);
|
|
if (host_config->app_handle == NULL) {
|
|
iot_printf("App handle NULL (%s)\n", __FUNCTION__);
|
|
return ERR_INVAL;
|
|
}
|
|
return ERR_OK;
|
|
}
|
|
#else
|
|
static uint8_t iot_cli_register()
|
|
{
|
|
host_config->app_handle = NULL;
|
|
return ERR_OK;
|
|
}
|
|
#endif /* PLC_COMM_ENABLE */
|
|
|
|
uint8_t iot_cli_module_handle_msg(
|
|
cli_moduleid_t moduleid, uint32_t msgid, iot_cli_msg_t *msg)
|
|
{
|
|
#if PLC_SUPPORT_CCO_ROLE
|
|
if (iot_plc_is_client_mode())
|
|
{
|
|
if (cli_execute_msg_entry(moduleid, msgid, all_cli_sta_msg_entry, msg)) {
|
|
return 1;
|
|
}
|
|
} else {
|
|
if (cli_execute_msg_entry(moduleid, msgid, all_cli_cco_msg_entry, msg)) {
|
|
return 1;
|
|
}
|
|
}
|
|
#else
|
|
if (cli_execute_msg_entry(moduleid, msgid, all_cli_sta_msg_entry, msg)) {
|
|
return 1;
|
|
}
|
|
#endif
|
|
|
|
return 0;
|
|
}
|
|
|
|
uint8_t iot_cli_module_handle_task_msg(iot_cli_msg_t *cli_msg, uint16_t id)
|
|
{
|
|
uint8_t handled = 1;
|
|
switch (id) {
|
|
case IOT_CLI_HOST_MSG:
|
|
cli_handle_plc_msg(cli_msg->data);
|
|
break;
|
|
case IOT_CLI_UPGRADE_TIMER:
|
|
iot_cli_upgrade_handle_timer_msg();
|
|
break;
|
|
case IOT_CLI_RATE_TEST_TIMER:
|
|
iot_cli_rate_test_handle_timer_msg();
|
|
break;
|
|
case IOT_CLI_SG_MSG:
|
|
iot_cli_sg_handle_msg(cli_msg->data);
|
|
break;
|
|
case IOT_CLI_SET_TIMER:
|
|
iot_cli_set_info_handle_timer_msg();
|
|
break;
|
|
case IOT_CLI_QUERY_HW_TIMER:
|
|
iot_cli_query_hw_ver_handle_timer_msg();
|
|
break;
|
|
#if PLC_SUPPORT_CCO_ROLE
|
|
case IOT_CLI_RPT_TOPO_TIMER:
|
|
iot_plc_query_nw_topo(host_config->app_handle,
|
|
host_config->cli_request_id, host_config->topo_ver,
|
|
IOT_PLC_QUERY_TOPO_START_AS_TEI,
|
|
host_config->topo_query_start_index,
|
|
host_config->topo_count_in_packet);
|
|
break;
|
|
case IOT_CLI_BCAST_TX_DONE:
|
|
cli_remote_upgrade_bcast_tx_done();
|
|
break;
|
|
#endif
|
|
#if (IOT_STA_CONTROL_MODE == IOT_STA_CONTROL_TYPE_STA)
|
|
case IOT_CLI_ADA_MSG:
|
|
iot_cli_handle_ada_msg(cli_msg->data);
|
|
break;
|
|
case IOT_CLI_DUMP_TIMER:
|
|
iot_cli_ada_dump_handle_timer_msg();
|
|
break;
|
|
#endif
|
|
#if IOT_TPUT_APP_ENABLE
|
|
case IOT_CLI_TPUT_MSG:
|
|
iot_cli_tput_handle_msg(cli_msg->data);
|
|
break;
|
|
#endif
|
|
default:
|
|
handled = 0;
|
|
break;
|
|
}
|
|
|
|
return handled;
|
|
}
|
|
|
|
uint8_t iot_cli_module_cancel_task_msg(
|
|
iot_cli_msg_t *cli_msg, uint16_t id)
|
|
{
|
|
switch (id) {
|
|
case IOT_CLI_HOST_MSG:
|
|
case IOT_CLI_UPGRADE_TIMER:
|
|
case IOT_CLI_RATE_TEST_TIMER:
|
|
case IOT_CLI_SG_MSG:
|
|
case IOT_CLI_SET_TIMER:
|
|
case IOT_CLI_QUERY_HW_TIMER:
|
|
case IOT_CLI_RPT_TOPO_TIMER:
|
|
case IOT_CLI_BCAST_TX_DONE:
|
|
#if IOT_TPUT_APP_ENABLE
|
|
case IOT_CLI_TPUT_MSG:
|
|
#endif
|
|
#if (IOT_STA_CONTROL_MODE == IOT_STA_CONTROL_TYPE_STA)
|
|
case IOT_CLI_ADA_MSG:
|
|
case IOT_CLI_DUMP_TIMER:
|
|
#endif
|
|
if (cli_msg->data) {
|
|
iot_pkt_free(cli_msg->data);
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
void iot_cli_module_init_uart(commnucator_t * com, uint8_t interface_type)
|
|
{
|
|
if (com && (com->is_initiated == 0)) {
|
|
#if (HW_PLATFORM != HW_PLATFORM_SIMU) && (!IOT_STA_CONTROL_MODE)
|
|
if ((MODULE_TYPE_CCO == cli_module_type) || cli_ftm_mode) {
|
|
#endif
|
|
com->type = interface_type;
|
|
if (com->type == COMMUNICATOR_UART)
|
|
{
|
|
os_mem_set(&(com->uart_frame), 0, sizeof(iot_frame_fmt));
|
|
com->uart_frame.preamble_codelen = 2;
|
|
os_mem_cpy(com->uart_frame.preamble_code, "##", 2);
|
|
com->uart_frame.backcode_len = 2;
|
|
os_mem_cpy(com->uart_frame.backcode, "@@", 2);
|
|
com->uart_frame.datalen_offset = 20;
|
|
com->uart_frame.datalen_size = 4;
|
|
com->uart_frame.backcode_offset = 0;
|
|
com->uart_frame.frame_timeout = 200;
|
|
}
|
|
#if IOT_STA_CONTROL_MODE > IOT_STA_CONTROL_TYPE_PPM_DETECT
|
|
// TODO: reserved for config depending on GPIO
|
|
IOT_ASSERT(0);
|
|
#else
|
|
#if HW_PLATFORM == HW_PLATFORM_SIMU
|
|
com->com_num = UART_CLI_PORT;
|
|
#else
|
|
com->com_num = iot_board_get_uart(UART_CLI_PORT);
|
|
#endif
|
|
#endif
|
|
commnunicator_init(com, &cli, CALLER_PLC_CLI, 1);
|
|
|
|
#if (HW_PLATFORM != HW_PLATFORM_SIMU) && (!IOT_STA_CONTROL_MODE)
|
|
}
|
|
#endif
|
|
cli.commu.is_initiated = 1;
|
|
}
|
|
}
|
|
|
|
/* timer for rpt topo data */
|
|
void iot_cli_rpt_topo_data_timer(timer_id_t timer_id, void *arg)
|
|
{
|
|
(void)timer_id;
|
|
(void)arg;
|
|
|
|
iot_task_msg_t *msg;
|
|
msg = iot_cli_create_cli_msg(IOT_CLI_RPT_TOPO_TIMER, NULL);
|
|
|
|
if (msg) {
|
|
iot_task_queue_msg(cli.cli_task_h, msg, IOT_CLI_QUEUE_TIMER);
|
|
}
|
|
}
|
|
|
|
uint8_t iot_cli_proto_module_init()
|
|
{
|
|
uint8_t ret = ERR_OK;
|
|
|
|
host_config = (iot_plc_host_config_t*)
|
|
os_mem_malloc(IOT_CLI_MID, sizeof(iot_plc_host_config_t));
|
|
if (host_config == NULL) {
|
|
ret = ERR_NOMEM;
|
|
goto label_failed1;
|
|
}
|
|
os_mem_set(host_config, 0, sizeof(host_config));
|
|
|
|
// resiter cli app to plc lib
|
|
ret = iot_cli_register();
|
|
if (ret != ERR_OK) {
|
|
goto label_failed1;
|
|
}
|
|
|
|
host_config->dev_role = IOT_PLC_DEV_ROLE_INVALID;
|
|
host_config->dev_type = IOT_PLC_DEV_TYPE_INVAL;
|
|
|
|
#if PLC_SUPPORT_CCO_ROLE
|
|
host_config->topo_data_timer = os_create_timer(IOT_CLI_MID, 0,
|
|
iot_cli_rpt_topo_data_timer, NULL);
|
|
iot_cli_ckb_init();
|
|
#endif
|
|
|
|
#if IOT_CLI_CKB_ADDR_MAPPING
|
|
iot_cli_addr_mapping_init();
|
|
#endif /* IOT_CLI_CKB_ADDR_MAPPING */
|
|
|
|
#if (PLC_SUPPORT_CCO_ROLE || (IOT_STA_CONTROL_MODE == IOT_STA_CONTROL_TYPE_STA))
|
|
iot_cli_plc_mgr_alive_init();
|
|
#endif
|
|
iot_cli_rate_test_init();
|
|
iot_cli_set_info_init();
|
|
iot_cli_dbg_log_init();
|
|
iot_cli_query_hw_ver_init();
|
|
#if (IOT_STA_CONTROL_MODE == IOT_STA_CONTROL_TYPE_STA)
|
|
iot_cli_ada_dump_init();
|
|
#endif
|
|
#if PLC_SUPPORT_CCO_ROLE
|
|
iot_cli_ul_buf_init();
|
|
#endif
|
|
|
|
#if (IOT_STA_CONTROL_MODE == IOT_STA_CONTROL_TYPE_STA)
|
|
iot_cli_host_set_ckb_dev_type();
|
|
iot_plc_wdg_set(host_config->app_handle, 0, 0);
|
|
iot_plc_set_whitelist(host_config->app_handle,
|
|
IOT_PLC_API_REQ_ID_DEFAULT, IOT_PLC_WL_ENABLE, 0, NULL);
|
|
cli_discovery_init();
|
|
#endif
|
|
return ERR_OK;
|
|
label_failed1:
|
|
iot_cli_proto_module_deinit();
|
|
return ret;
|
|
}
|
|
|
|
void iot_cli_proto_module_deinit()
|
|
{
|
|
#if PLC_SUPPORT_CCO_ROLE
|
|
iot_cli_ckb_deinit();
|
|
#endif /* PLC_SUPPORT_CCO_ROLE */
|
|
#if IOT_CLI_CKB_ADDR_MAPPING
|
|
iot_cli_addr_mapping_deinit();
|
|
#endif /* IOT_CLI_CKB_ADDR_MAPPING */
|
|
iot_cli_rate_test_deinit();
|
|
#if (IOT_STA_CONTROL_MODE == IOT_STA_CONTROL_TYPE_STA)
|
|
cli_discovery_deinit();
|
|
#endif
|
|
if (host_config) {
|
|
os_mem_free(host_config);
|
|
host_config = NULL;
|
|
}
|
|
} |