#ifndef _UPDATE_PROTOCOL_H_
#define _UPDATE_PROTOCOL_H_

#include "stdint.h"

#define	CRC16_BASE	0xA001

//帧头结构体
typedef struct {
	uint8_t Header;
	uint8_t SlvAddr;
	uint8_t Cmd;		
	uint8_t PayloadLen;
}update_protocol_hd_t;

//主机下发升级请求载荷结构体
typedef struct {
	uint16_t PackageNum;
	uint32_t AppSize;
	uint32_t AppCrc32;
}__attribute__ ((packed))update_protocol_req_t;

//从机请求下发结构体
typedef struct {
	uint16_t PackageIndex;
	uint32_t PackageNum;
}__attribute__ ((packed))update_protocol_get_t;

//主机应答下发数据结构体
typedef struct {
	uint16_t PackageIndex;
	uint16_t PackageNum;
	uint8_t  DataLen;
}__attribute__ ((packed))update_protocol_rsp_t;


typedef int (*update_callback_t)(uint8_t cmd, void *pdata, int len,void *pload,int size);

typedef void (*update_send_t)(uint8_t *pBuf,int len);

void  update_init(update_send_t pCbs);

void update_event_cbs_reg(update_callback_t pCbs);

uint8_t update_unpack(uint8_t* rxData, int rLen,uint8_t *cmd, void *pUser, int *pLen);
 
void update_send_cmd(uint8_t Cmd, uint16_t Indx, int PageNum);

#endif




