#include "includes.h"
#include "device.h"
#include "tax_ctrl.h"
#include "net_proc.h"
#include "uart.h"
#include "des.h"
#include "BSP.h"
#include "net_ctrl.h"

int rs485_send_flag = 0;
#define CRC_INIT_VALUE 0x0000

uint8_t XSP_ADDRESS = 0x81;



/**
  * @brief hex convert ascii
  * @par param[in] *ascii:ascii data
  * @par param[in] *hex:hex data
  * @par param[in] hexLen:length of hex
  * @retval length
  */
uint32_t Hex2Dec(uint8_t *hex, uint16_t hexLen)
{
	uint32_t data = 0;	
    uint8_t i;
	
    for(i=0;i<hexLen;i++) {
		data = data * 100;
        data += (hex[i]>>4)*10 + (hex[i]&0x0F);
    }
    return data;
}


uint16_t _crc16_get(uint8_t *_buff,uint32_t _len)
{
    uint32_t i,j;
    uint16_t crc;
    uint16_t temp;

    crc=(uint16_t)CRC_INIT_VALUE;
    for(i=0;i<_len;i++) {
        temp=_buff[i];
        temp &=0x00FF;
        crc^=temp;

        for(j=0;j<8;j++) {
            if((crc&0x0001)!=0x00) {
                crc>>=1;
                crc^=0xA001;
            } else {
                crc>>=1;
            }
        }
    }
 
    return crc;
}


static uint16_t _crc_get(uint8_t *data, uint8_t size)
{
	uint8_t i, crc = 0;
	
	for(i = 0;i < size;i++){
		crc ^=data[i];
	}
 
	return crc;
}

/////////////////////////////////////////////////////////////////////////////
//显示屏通信过程
/////////////////////////////////////////////////////////////////////////////

//取反函数
int reverse_get(uint8_t* buffer, uint8_t* result,uint8_t data_len)
{
	int ret = 0;
	int i;
	for(i = 0; i < data_len; i++)
	{
		*(result+i) = ~(*(buffer+i));
	}
	
	return ret;
}


//比较两个字符串
static int _my_strcmp(uint8_t *buff1, uint8_t *buff2, uint8_t len)
{
	int i, ret = 1;
	for(i = 0; i < len; i++)
	{
		if(buff1[i] != buff2[i])
		{
			return ret;
		}
	}
	ret = 0;
	return ret;
}



