#include "stm32f10x.h"                  // Device header
#include <stdio.h>
#include "rs485.h"
//u8 rx_buf[64];

extern u8 RS485_RX_BUF_COPY[128];

void  bufcut_Init(u8 *TARGET_RX_BUF,u8 *SOURCE_CUT_RX_BUF,u8 start_index, u8 end_index)
{
   int i, j = 0;

   for (i = start_index; i < end_index; i++) 
	 {
      TARGET_RX_BUF[j] = SOURCE_CUT_RX_BUF[i];
      j++;
   }
}

void RX_BUF_Init(void)
{
  int i=0;
	for(i=0;i<128;i++)
	{
		RS485_RX_BUF[i]=0;
	}
	
}

void RX_BUF_ZERO(u8 num)// set RS485_RX_BUF_COPY to 0
{
	for(int i=0;i<num;i++)
	{
		RS485_RX_BUF_COPY[i]=0;
	}
	
}

void RX_BUF_Transfer(u8 zero,u8 transfer_num)//把未处理的数组转移到第一位
{
	int i=0;
	 
	 for (i = zero; i < 128 - transfer_num; i++)
	 {
			RS485_RX_BUF[i] = RS485_RX_BUF[i + transfer_num];
			RS485_RX_BUF_COPY[i] = RS485_RX_BUF_COPY[i + transfer_num];
	 }
	 for (i = 128 - transfer_num; i < 128; i++)
	 {
			RS485_RX_BUF[i] = 0;
			RS485_RX_BUF_COPY[i] = 0;
	 }
	 
	 RS485_RX_CNT -= transfer_num;
	 if (RS485_RX_CNT < 0) {
		RS485_RX_CNT = 0;
	 }
}


void RX_BUF_Printf(int num)
{
	int i=0;
	for(i=0;i<num;i++)
	{
		//printf("%x ",RS485_RX_BUF[i]);
	}

}
