PV1_MakeProject/include/ota.h

157 lines
5.7 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef OTA_H
#define OTA_H
#ifdef __cplusplus
extern "C" {
#endif
#define SIZE_1K (1024) ///< 1K 字节大小
#define MD5_CHKSUM_LEN (16) ///< MD5校验和长度
#define MD5_CHKSUM_STR_LEN (MD5_CHKSUM_LEN * 2 + 1) ///< MD5校验和字符串格式长度
#define NO_OTA_STATUS_VAL_TAG (0) ///< 状态默认值
/**
* 系统启动模式定义
*/
typedef enum
{
NORMAL_SETUP = 0x1234, ///< 普通启动模式
RECOVERY_SETUP, ///< 恢复模式
SYSTEM_OTA, ///< OTA升级模式
SYSTEM_OTA_OK,
} SETUP_MODE;
/**
* OTA状态命令定义
*/
typedef enum
{
OTA_CURRENT_VERSION = 0, ///< 当前系统版本号
OTA_CURRENT_SETUP_MODE, ///< 当前系统启动模式
OTA_CURRENT_REBOOT_TIME, ///< 当前系统未正常启动次数
OTA_DOWNLOAD_FILE, ///< OTA升级包下载状态
OTA_DOWNLOAD_PROGRESS, ///< OTA升级包下载进度
OTA_VERIFY_FILE, ///< 文件校验结果
OTA_VERIFY_PARTITION, ///< OTA分区校验结果
OTA_DECOMPRESS_FILE, ///< OTA当前进度解压文件
OTA_UPGRADE_READY, ///< OTA更新准备完成
OTA_UPGRADE_START, ///< OTA更新开始
OTA_UPGRADE_PARTITION, ///< OTA写入分区数据
OTA_RECOVERY_START, ///< OTA恢复模式启动
OTA_REREQ_OTA_NOW, ///< OTA请求立即执行OTA更新系统
OTA_REBOOT_SYSTEM, ///< OTA准备重启系统
OTA_SUCCESED, ///< OTA执行成功
OTA_UNKNOWN_CMD, ///< 位置OTA状态命令
OTA_ERR_CODE, ///< OTA过程异常
OTA_DISK_FULL, ///< 存储空间不足
} OTA_STATUS_TYPE;
/**
* OTA模式
*/
typedef enum
{
OTA_MODE_NORMAL = 9029, ///< 普通OTA更新模式
OTA_MODE_FORCE_NOW, ///< 强制OTA更新模式
OTA_MODE_RECOVERY, ///< OTA恢复模式
} OTA_MODE;
/**
* OTA操作命令
*/
typedef enum
{
OTA_CMD_DOWNLOAD = 1234, ///< 下载OTA升级包
OTA_CMD_USED_LOCAL_IMAGE, ///< 从上次备份的OTA升级包升级
OTA_CMD_EXEC, ///< 开始OTA更新系统
} OTA_CMD;
/**
* OTA级包信息
*
*/
typedef struct
{
char url[SIZE_1K]; ///< URL, Base64编码
char md5[MD5_CHKSUM_STR_LEN]; ///< OTA升级包MD5校验和
unsigned int size; ///< OTA升级包文件大小
} OTA_FILE_INFO, *POTA_FILE_INFO;
/**
* 控制中心控制命令协议
*
* @see OTA_CMD
* @see OTA_MODE
* @see OTA_FILE_INFO
*/
typedef struct
{
int version; ///< OTA版本号
OTA_CMD otaCmd; ///< OTA命令
OTA_MODE otaMode; ///< OTA模式
OTA_FILE_INFO otaFileInfo; ///< OTA升级包信息
} OTA_DATA_INFO, *POTA_DATA_INFO;
/**
* OTA状态信息协议
*
* @see OTA_STATUS_TYPE
*/
typedef struct
{
OTA_STATUS_TYPE status; ///< 状态命令
int val; ///< 状态值
} OTA_RSP_STATUS, *POTA_RSP_STATUS;
static inline const char* otaStatusName(OTA_STATUS_TYPE type)
{
switch(type)
{
case OTA_CURRENT_VERSION:
return ("OTA_CURRENT_VERSION");
case OTA_CURRENT_SETUP_MODE:
return ("OTA_CURRENT_SETUP_MODE");
case OTA_CURRENT_REBOOT_TIME:
return ("OTA_CURRENT_REBOOT_TIME");
case OTA_DOWNLOAD_FILE:
return ("OTA_DOWNLOAD_FILE");
case OTA_DOWNLOAD_PROGRESS:
return ("OTA_DOWNLOAD_PROGRESS");
case OTA_VERIFY_FILE:
return ("OTA_VERIFY_FILE");
case OTA_VERIFY_PARTITION:
return ("OTA_VERIFY_PARTITION");
case OTA_DECOMPRESS_FILE:
return ("OTA_DECOMPRESS_FILE");
case OTA_UPGRADE_READY:
return ("OTA_UPGRADE_READY");
case OTA_UPGRADE_START:
return ("OTA_UPGRADE_START");
case OTA_UPGRADE_PARTITION:
return ("OTA_UPGRADE_PARTITION");
case OTA_RECOVERY_START:
return ("OTA_RECOVERY_START");
case OTA_REREQ_OTA_NOW:
return ("OTA_REREQ_OTA_NOW");
case OTA_REBOOT_SYSTEM:
return ("OTA_REBOOT_SYSTEM");
case OTA_SUCCESED:
return ("OTA_SUCCESED");
case OTA_UNKNOWN_CMD:
return ("OTA_UNKNOWN_CMD");
case OTA_ERR_CODE:
return ("OTA_ERR_CODE");
default:
return ("Unknown Type");
}
}
#ifdef __cplusplus
}
#endif
#endif