Files
kunlun/app/smart_grid/inc/internal/iot_sg_cco_upgrade.h
2024-09-28 14:24:04 +08:00

218 lines
6.8 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.
****************************************************************************/
#ifndef IOT_SG_CCO_UPGRADE_H
#define IOT_SG_CCO_UPGRADE_H
#include "proto_gw_app.h"
#ifdef __cplusplus
extern "C" {
#endif
/* type of STA information */
#define IOT_PLC_STA_INFO_CRC 1
#define IOT_PLC_STA_INFO_VENDOR_ID 2
#define IOT_PLC_STA_INFO_VERSION 3
#define IOT_PLC_STA_INFO_BOOTLOADER_VER 4
#define IOT_PLC_STA_INFO_FILE_LEN 5
#define IOT_PLC_STA_INFO_DEV_TYPE 6
/**
* @brief - upgrade timer to drive upgrading state switching and data sending
* @param timer_id: timer id
* @param arg: argument for the timer
*/
void iot_sg_cco_upgrade_timer_func(timer_id_t timer_id, void *arg);
/**
* @brief - upgrade cancel timer to send stop commands
* @param timer_id: timer id
* @param arg: argument for the timer
*/
void iot_sg_cco_cancel_timer_func(timer_id_t timer_id, void *arg);
/*
* @brief: init sg cco upgrading module.
*/
void iot_sg_cco_upgrade_init();
/**
* @brief - upgrade window timer triggered when upgrading window timeout
* @param timer_id: timer id
* @param arg: argument for the timer
*/
void iot_sg_cco_upgrade_win_timer_func(timer_id_t timer_id, void *arg);
/**
* @brief - bcast stop upgrading commands for IOT_SG_CCO_STOP_BCAST_CNT times.
*/
void iot_sg_cco_bcast_stop_cmd();
/**
* @brief - process cli command
*/
void iot_sg_cco_handle_upgrade_cli_cmd(uint8_t cmd, iot_pkt_t *pkt);
/**
* @brief - upgrade bcast tx done
*/
void iot_sg_cco_upgrade_bcast_tx_done();
/**
* @brief - handle IOT_SG_CCO_UPGRADE_ST_SEND message.
* send upgrading data to a STA or switch to other state.
*/
void iot_sg_cco_handle_upgrade_resend_data();
/**
* @brief - handle STAs joined the network while upgrading is half done.
*/
void iot_sg_cco_handle_upgrade_late_sta();
/**
* @brief - handle sending block 1 to STA.
*/
void iot_sg_cco_handle_upgrade_send_block1();
/**
* @brief - handle broadcast all block to STA.
*/
void iot_sg_cco_handle_upgrade_bcast_all_block();
/**
* @brief - query sta info on VERDOR_ID/VERSION/CRC
*/
void iot_sg_cco_handle_query_sta_info();
/**
* @brief - handle IOT_SG_MSG_ID_UPGRADE_START message.
* send start upgrading message to a STA or switch to other state.
*/
void iot_sg_cco_handle_start_upgrade();
/**
* @brief - handle IOT_SG_MSG_ID_UPGRADE_STOP message.
* send stop upgrading message to a STA or switch to other state.
* @param clr_file_flag: 1 - clear upgrade file information, 0 don't clear
*/
void iot_sg_cco_handle_stop_upgrade(uint8_t clr_file_flag);
/**
* @brief - handle IOT_SG_MSG_ID_UPGRADE_EXECUTE message.
* send execute upgrading message to a STA or switch to other state.
*/
void iot_sg_cco_handle_upgrade_execute();
/**
* @brief - handle IOT_SG_MSG_ID_UPGRADE_WIN_TIMEOUT message.
* clear upgrading status and switch to IDLE state.
*/
void iot_sg_cco_handle_upgrade_win_timeout();
/**
* @brief - handle IOT_SG_MSG_ID_UPGRADE_QUERY_STA_2 message.
* clear upgrading status and switch to IDLE state.
*/
void iot_sg_cco_handle_query2_timeout();
/**
* @brief: handle sta joining event for upgrading
* @param sta_mac: sta mac address that just join the network
* @param new_sw_ver: sta renew sw version
* @param total_sta_cnt: total sta count in the network
* @param new_sta_joined: first join the network
*/
void iot_sg_cco_upgrade_on_sta_join(uint8_t *sta_mac, uint16_t new_sw_ver,
uint16_t total_sta_cnt, uint8_t new_sta_joined);
/**
* @brief: check if sg upgrading is in progress.
* @retval: 1 if sg upgrading is in progress.
* 0 if sg upgrading is NOT in progress.
*/
uint32_t iot_sg_cco_is_upgrading();
/*
* @brief: handle reply of start upgrading command from STA.
* @param sta_mac: mac address of the STA send the ack
* @param upgrade_id: id of the current upgrading session
* @param result: result of the upgrade command
*/
void iot_sg_cco_handle_start_ack_reply(uint8_t *sta_mac, uint32_t upgrade_id,
uint32_t result);
/*
* @brief: iot_sg_cco_handle_exe_ack_reply - handle reply of finish
* upgrading command from STA.
* @param sta_mac: mac address of the STA send the ack
* @param upgrade_id: id of the current upgrading session
* @param result: result of the upgrade command
*/
void iot_sg_cco_handle_exe_ack_reply(uint8_t *sta_mac, uint32_t upgrade_id,
uint32_t result);
/*
* @brief: handle reply for query status.
* @param sta_mac: mac address of the STA send the reply
* @param upgrade_id: id of the upgrading session
* @param bitmap: each bit in the bitmap indicate if a block was received
* @param bm_size: size of bitmap
* @param block_cnt: count of the block
* @param status: STA's upgrade status. see IOT_PLC_UPGRADE_ST_XXX
* @param start_req: sequence of first block in bitmap
*/
void iot_sg_cco_handle_query_status_reply(uint8_t *sta_mac,
uint32_t upgrade_id, uint8_t *bitmap, uint16_t bm_size, uint16_t block_cnt,
uint16_t status, uint32_t start_seq);
/*
* @brief: set local STA entry's information
* @param sta_mac: mac address of the STA
* @param info_type: type of information, see IOT_PLC_STA_INFO_XXX
* @param value: value of information
*/
void iot_sg_cco_set_sta_entry_info(uint8_t *sta_mac, uint32_t info_type,
uint32_t value);
/*
* @brief: get a flag indicate if CCo shall query STA's version info
* @return: 1 if CCo shall query STA's version info. 0 if not.
*/
uint32_t iot_sg_cco_get_qr_vendor_info_flag();
/*
* @brief: clear flag indicating if CCo shall vendor info
*/
void iot_sg_cco_clear_qr_vendor_info_flag();
/*
* @brief: set flag indicating if STA's version was updated.
* @param sta_mac: address of the SAT whose version updated flag will be set.
* it's big-endian.
*/
void iot_sg_cco_set_sta_ver_updated(uint8_t *sta_mac);
/*
* @brief: get cco upgrade file receive state.
* @return: 1 - receiving, 0 - other.
*/
uint8_t iot_sg_cco_get_upgrade_file_receiving();
#ifdef __cplusplus
}
#endif
#endif /* IOT_SG_CCO_UPGRADE_H */