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

111 lines
3.1 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 "os_utils_api.h"
#include "iot_io_api.h"
#include "iot_cli.h"
#include "iot_cli_msg.h"
#include "iot_cli_common.h"
#include "iot_cli_tx_rx.h"
#include "iot_cli_module_config.h"
#include "iot_cli_host_interface.h"
#include "iot_cli_ul_buf.h"
#include "iot_cli_plc_mgr_alive.h"
#ifdef HOST_APP_FEATURE_ENABLE
#ifdef CLI_FULL_FEATURE_ENABLE
#include "iot_cli_sg.h"
#endif
extern iot_cli_host_info_t *host_info;
extern iot_cli_t cli;
/* keep alive cli handler*/
void cli_plc_mgr_alive(
uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac)
{
(void)buffer;
(void)bufferlen;
(void)src_mac;
iot_plc_mgr_alive_ack_t ack_rpt = { 0 };
ack_rpt.is_ready = (!!host_info->is_ready);
host_info->host_app_live = 1;
iot_cli_send_to_host(CLI_MSGID_PLC_MGR_ALIVE_ACK, (uint8_t *)&ack_rpt,
sizeof(ack_rpt), src_mac);
}
/* set plc mgr state */
void cli_set_plc_mgr_state(uint8_t state)
{
if (state != host_info->host_app_state)
{
#ifdef CLI_FULL_FEATURE_ENABLE
// send live msg to sg
iot_cli_sg_plc_mgr_state_change_t state_change;
state_change.state = state;
iot_sg_cli_plc_mgr_state_change(
CLI_HOST_USE_API_BY_PLCM, &state_change);
#endif
host_info->host_app_state = state;
cli_set_ul_buf_active(state);
iot_printf("set plc mgr state %lu\n", state);
}
}
void iot_cli_plc_mgr_alive_handle_timer_msg()
{
if (host_info->host_app_live)
{
// change plc mgr state to 1
cli_set_plc_mgr_state(1);
host_info->host_app_live = 0;
} else {
// change plc mgr state to 0
cli_set_plc_mgr_state(0);
}
}
/* timer alive */
static void iot_cli_alive_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_ALIVE_TIMER, NULL);
if (msg) {
iot_task_queue_msg(cli.cli_task_h, msg, IOT_CLI_QUEUE_TIMER);
}
}
/* init plc mgr alive */
void iot_cli_plc_mgr_alive_init()
{
host_info->host_app_state = 0;
host_info->host_app_live = 0;
host_info->live_timer =
os_create_timer(IOT_CLI_MID, 1,
iot_cli_alive_timer, NULL);
os_start_timer(host_info->live_timer, CLI_PLC_MGR_STATE_TIMER);
}
#endif