#ifndef __DATAHANDLING_H__
#define __DATAHANDLING_H__

#include "main.h"
#include "string.h"
#include "stdio.h"
#include "usart.h"
#include "stmflash.h"
#include "iap.h"

#define STM32_FLASH_SIZE 	512 	 		//所选STM32的FLASH容量大小(单位为K)
#define STM32_FLASH_WREN 	1              	//使能FLASH写入(0，不是能;1，使能)
#define FLASH_WAITETIME  	50000          	//FLASH等待超时时间

extern uint32_t flash_addr;
extern uint16_t iapversion[5];
extern uint16_t iapmd5[10];



// 定义一个长度为16的字符数组，用于存储MD5摘要
extern unsigned char digest[16];

//FLASH起始地址
#define STM32_FLASH_BASE 	0x08000000 		//STM32 FLASH的起始地址

void Flash_ReadBytes(uint16_t* sorBuf,uint32_t FlashAddr,uint16_t len);
int App2_MD5_Check(uint32_t addr,unsigned int all_len);
void  Flash_WriteBytes(uint16_t* sorBuf,uint32_t FlashAddr,uint16_t len);
void Set_App2_Flag(void);
void delay_sys_us(uint32_t Delay);//1个delay，大概1.5us

void search_seat(const uint8_t* hexData);
uint16_t crc16_xmodem(uint8_t *data, uint16_t length);
void Set_Update_Down(void);
void iap_write_appbin(uint32_t appxaddr, uint32_t appbuf, uint32_t appsize);
void Set_jump_Flag(void);
void convertHexToAscii(uint16_t version[4], uint32_t* System_version);

void readFlashToArr(uint8_t *arr, uint32_t addr);
void Set_normal_Flag(void);










#endif
