#ifndef __data_deal_H__
#define __data_deal_H__


#include "stdio.h"
#include "string.h"
#include "stdint.h"
#include <ctype.h>  

typedef struct _SDateTime{
	int year;
	char month;
	char day;
	char hour;
	char min;
	char sec;
	char week;
	int  msec;
}SDateTime;


void StrToHex(uint8_t *pbDest, uint8_t *pbSrc, int nLen);														//字符串转成16进制数
void HexToStr(uint8_t *pbDest, uint8_t *pbSrc, int nLen);														//16进制转换成字符串

void Switch_U32_To_BYTE4(unsigned long temp_U32_data, unsigned char*data);		//将32位无符号整数转成4字节数组存储
unsigned long Switch_BYTE4_To_U32(unsigned char*data);												//将U32的4字节数组转成32位无符号整数

void Switch_S32_to_ASCII(signed long data, unsigned char*str);								//将32位有符号整数转成ASCII字符串显示
void Switch_Float_To_ASCII(float temp_float_data, unsigned char*str);					//将浮点数转成ASCII字符串

void Switch_S16_To_Byte2(signed short temp_S16_data, unsigned char*data);			//将有符号整数转成2字节数组存储
signed short Switch_Byte2_To_S16(unsigned char*data);													//2字节数组转成有符号整数

float Switch_Byte4_To_Float(unsigned char*data);															//四字节数组转成浮点数
void Switch_Float_To_Byte4(float temp_float_data, unsigned char*data);				//将浮点数转成四字节数组存储

void Data32ToBuf(uint16_t *buf, uint32_t data32);															//4字节数存放到数组中	数组起始地址存放高字节
int32_t BufToData32(uint16_t *buf);																						//2字节数组组成一个32位数	数组起始地址存放高字节

void S32_to_u8(signed long data,unsigned char*str);

uint16_t LRC_Check(uint8_t *data);
uint16_t Calc_LRC(uint8_t* data, int data_len);
uint8_t MODBUS_ASCII_GetLrc(uint8_t *pCyAsciiBuf, uint16_t cyLen);
uint8_t MODBUS_Hex_GetLrc(uint8_t *pCyAsciiBuf, uint8_t cyLen);

uint8_t MODBUS_ASCII_AsciiToHex(uint8_t *pbDest);
 
void MODBUS_S32_to_ASCII(int32_t data32 ,uint8_t *pAsciiBuf );
void MODBUS_S16_to_ASCII(int16_t data16 ,uint8_t *pAsciiBuf );
void MODBUS_S8_to_ASCII(int8_t data8 ,uint8_t *pAsciiBuf );

uint16_t CRC16(unsigned char *pBuf,int nLength) ;


unsigned short CRC16_MODBUS(unsigned char *puchMsg, unsigned int usDataLen);

float MODBUS_ASCII_AsciiToFlaot(uint8_t *pbDest);

void MODBUS_Float_to_ASCII(float data32 ,uint8_t *pAsciiBuf );

//单字节BCD转为HEX子程序
unsigned char BCDtoHEX(unsigned char bcd_data); 

//单字节HEX转为BCD子程序
unsigned char HEXtoBCD(unsigned char hex_data); 

/********** BCD to HEX **********/
//双字节数值范围：0~9999
uint16_t BCD2HEX(uint16_t bcd);

/********** BCD to HEX **********/
//双字节数值范围：0~9999
uint16_t HEX2BCD(uint16_t hex);

#endif
