230 lines
7.0 KiB
C
230 lines
7.0 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 APP_UPG_H
|
|
#define APP_UPG_H
|
|
|
|
#include "iot_utils_api.h"
|
|
#include "app_types.h"
|
|
//#include "iot_upgrade_api.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
/* max data lenth in one upgrade frame */
|
|
#define PROTO_UPGRADE_BLOCK_SIZE (400)
|
|
/* max STA count for upgrade */
|
|
#define PROTO_UPGRADE_MAX_STA (200)
|
|
/* max query sta upgrade progress count */
|
|
#define PROTO_UPGD_RESP_MAX_CNT (20)
|
|
/* for resp upgrade data response */
|
|
#define UPGRADE_DATA_HEAD_LEN (9)
|
|
|
|
/* 启动文件传输 */
|
|
#define UPGRADE_START_TRANS_FILE 1
|
|
/* 文件传输内容 */
|
|
#define UPGRADE_TRANS_FILE_DATA 2
|
|
/* 查询升级状态 */
|
|
#define UPGRADE_STATE_QUERY 3
|
|
/* 配置升级列表 */
|
|
#define UPGRADE_SET_MAC_LIST 4
|
|
/* 查询升级节点进度 */
|
|
#define UPGRADE_STA_PROGRESS_QUERY 5
|
|
|
|
#define PROTO_RET_CODE_SUCCESS 0x00
|
|
#define PROTO_RET_CODE_FAILED 0x01
|
|
|
|
/* Abnormal status code */
|
|
#define PROTO_REASON_NORMAL 0x00 /* The status is normal. */
|
|
#define PROTO_REASON_TIMEOUT 0x01 /* communication timeout */
|
|
#define PROTO_REASON_FORMAT 0x02 /* format error */
|
|
#define PROTO_REASON_BUSY 0x03 /* node busy */
|
|
#define PROTO_REASON_OTHER 0xFF /* Other errors */
|
|
|
|
/* file attribution */
|
|
typedef enum {
|
|
/* Clear the download. */
|
|
UPGRADE_FILE_ATTR_CLEAR = 0x00,
|
|
/* local upgrade file */
|
|
UPGRADE_FILE_ATTR_LOCAL = 0x01,
|
|
/* network-wide upgrade file */
|
|
UPGRADE_FILE_ATTR_REMOTE = 0x02,
|
|
/* upgrade the assigned STA */
|
|
UPGRADE_FILE_ATTR_LIST = 0x03,
|
|
/* invalid attribution */
|
|
UPGRADE_FILE_ATTR_INVALID
|
|
} proto_upgrd_file_attr_e;
|
|
|
|
/* progress of upgrade */
|
|
typedef enum {
|
|
/* all done */
|
|
UPGRADE_TRANS_FILE_DONE = 0x00,
|
|
/* on the go */
|
|
UPGRADE_TRANS_FILE_INPROGRESS = 0x01,
|
|
/* partly failed */
|
|
UPGRADE_TRANS_FILE_UNCOMPLETE = 0x02,
|
|
/* unknown state */
|
|
UPGRADE_TRANS_FILE_INVALID = 0x03,
|
|
} proto_upgrd_file_state_e;
|
|
|
|
/** sta remote network upgrade info */
|
|
typedef struct _sta_upgrd_info {
|
|
uint8_t mac[IOT_MAC_ADDR_LEN];
|
|
uint8_t status;
|
|
uint8_t progress;
|
|
} sta_upgrd_info_t;
|
|
|
|
/* upgrade context */
|
|
typedef struct {
|
|
/* File attribute */
|
|
uint8_t file_attr;
|
|
/* current upgrade stage */
|
|
uint8_t stage;
|
|
/* current upgrade state */
|
|
uint8_t upgrd_state;
|
|
/* report count at one time */
|
|
uint8_t rpt_num;
|
|
/* Total segments of the file */
|
|
uint16_t seg_total;
|
|
/* current segment index */
|
|
uint16_t cur_seg_indx;
|
|
/* typical segment size */
|
|
uint16_t seg_size;
|
|
/* File length. */
|
|
uint32_t file_len;
|
|
/* File CRC check */
|
|
uint32_t file_crc;
|
|
/* upgrade id */
|
|
uint32_t upgrade_id;
|
|
/* upgrade monitor timer */
|
|
timer_id_t mon_timer;
|
|
/* total sta count in upgrade */
|
|
uint16_t total_sta_cnt;
|
|
/* total failed sta count */
|
|
uint16_t fail_sta_cnt;
|
|
/* upgrade list current indx */
|
|
uint16_t upgrd_list_indx;
|
|
/* file data */
|
|
uint8_t *file_data;
|
|
/* Timeout interval for file transfer, in minutes. */
|
|
uint32_t trans_timeout;
|
|
/* cco upgrade status in remote mode */
|
|
uint8_t cco_upd_state;
|
|
/* temporary sta upgrade data */
|
|
uint8_t * temp_data;
|
|
/* calculate crc32 value of all data received */
|
|
uint32_t calc_crc32;
|
|
/* upgrade info for every STA */
|
|
sta_upgrd_info_t sta_info[PROTO_UPGRADE_MAX_STA];
|
|
} proto_upgrd_contxt_t;
|
|
|
|
typedef struct _data_trans_head_t {
|
|
uint16_t cmd;
|
|
uint16_t length;
|
|
uint8_t data[0];
|
|
} data_trans_head_t;
|
|
|
|
/* pack for the structures in the whole file */
|
|
#pragma pack(push) // save the pack status
|
|
#pragma pack(1)
|
|
typedef struct {
|
|
/* file attribution, see PROTO_FILE_ATTR_xxx */
|
|
uint8_t file_attr;
|
|
/* Total segments of the file */
|
|
uint16_t seg_total;
|
|
/* File length. */
|
|
uint32_t file_len;
|
|
/* File content CRC32 checksum */
|
|
uint32_t file_crc;
|
|
/* Timeout interval for file transfer, in minutes. */
|
|
uint32_t trans_timeout;
|
|
} proto_start_trans_file_req;
|
|
|
|
/* Data transfer request structure */
|
|
typedef struct {
|
|
/* resrve */
|
|
uint8_t rsv;
|
|
/* File transfer segment number. */
|
|
uint16_t seg_num;
|
|
/* File transfer segment size. */
|
|
uint16_t seg_size;
|
|
/* File transfer segment CRC16-XMODEM(0x1021) checksum. */
|
|
uint16_t seg_crc;
|
|
/* File transfer segment data. */
|
|
uint8_t seg_data[0];
|
|
} proto_trans_file_data_req;
|
|
|
|
/* setting upgrade list */
|
|
typedef struct _set_upgrd_list_t {
|
|
/* Number of nodes */
|
|
uint8_t count;
|
|
/* sta mac which will be upgraded */
|
|
uint8_t mac[0];
|
|
} set_upgrd_list_t;
|
|
|
|
/* Structure of the response for setting upgrade list */
|
|
typedef struct _upgrd_resp_t {
|
|
/* Error code. 0: success; 1: failure */
|
|
uint8_t state;
|
|
/* fail reason */
|
|
uint8_t reason;
|
|
/* reserved for the future */
|
|
uint8_t rsv;
|
|
} upgrd_resp_t;
|
|
|
|
typedef struct query_progress_req {
|
|
/* read start index */
|
|
uint16_t start_index;
|
|
/* read num */
|
|
uint8_t count;
|
|
} query_progress_req;
|
|
|
|
typedef struct query_progress_ind {
|
|
/* total count */
|
|
uint16_t upgrade_total_count;
|
|
/* start index */
|
|
uint16_t start_index;
|
|
/* real repet count */
|
|
uint8_t resp_count;
|
|
/* data struct*/
|
|
sta_upgrd_info_t info[0];
|
|
} query_progress_ind;
|
|
|
|
/* response for the processing progress */
|
|
typedef struct upgrade_state_resp_t {
|
|
/* progress of upgrade */
|
|
uint8_t state;
|
|
/* counte fo failed STA */
|
|
uint16_t fail_sta;
|
|
/* reserve */
|
|
uint8_t rsv;
|
|
} upgrade_state_resp_t;
|
|
|
|
#pragma pack(pop)
|
|
|
|
uint32_t app_proto_start_trans_file(const proto_start_trans_file_req *frame, uint8_t *out_buffer, uint16_t *length);
|
|
uint32_t app_proto_trans_file_data(proto_trans_file_data_req *frame, uint8_t *out_buffer, uint16_t *length);
|
|
uint32_t app_proto_trans_file_query(uint8_t *out_buffer, uint16_t *length);
|
|
uint32_t app_proto_set_upgrd_list(set_upgrd_list_t *frame, uint8_t *out_buffer,
|
|
uint16_t *length,uint8_t renew);
|
|
uint32_t app_proto_trans_file_query_progress(query_progress_req *frame, uint8_t *out_buffer, uint16_t *length);
|
|
uint16_t app_proto_upgrd_contxt_init(void);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* end APP_UPG_H */
|
|
|