/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include "cmsis_os.h"
#include "main.h"

#define  USE_RAM_RECORD    0

#if USE_RAM_RECORD==0
void 		 func_ram_record_init(void)											//记录文件初始化
{
	return;
}
uint32_t func_ram_record_write(uint8_t *buf ,uint32_t len)
{
	return 0;
}
uint32_t func_ram_record_read(uint8_t *buf ,uint32_t len)
{
	return 0;
}
uint32_t func_ram_record_delete(uint8_t *buf,uint32_t len)
{
	return 0;
}

#else

#include "Data_deal.h"
/* Private includes ----------------------------------------------------------*/
#include "lib_buffer.h"


#include "func_ram_record.h"
/* Private typedef -----------------------------------------------------------*/


/* Private define ------------------------------------------------------------*/


/* Private macro -------------------------------------------------------------*/

/* Private variables ---------------------------------------------------------*/
uint8_t  			ram_record_buf[DATA_UNIT_NUM][DATA_UNIT_SIZE] = {0};
TBuffferOBJ 	ram_record_obj 					= {0};
TBufffer 			ram_record_handle 			= {0}; 
/* Private function prototypes -----------------------------------------------*/


/* Private user code ---------------------------------------------------------*/



/**
  * @brief  指定长度len,buf内容写入文件
  * @retval int
  */
uint32_t func_ram_record_write(uint8_t *buf ,uint32_t len)
{
	uint32_t 		data_len = TBuffer_Push(ram_record_handle, (void *)buf, (int) len);
	return data_len;

}


/**
  * @brief  The application entry point.
  * @retval int
  */
uint32_t func_ram_record_read(uint8_t *buf, uint32_t len)
{
	uint32_t 		data_len = TBuffer_Peek(ram_record_handle, (void *)buf, (int) len);
	
	return data_len;
}


uint32_t func_ram_record_delete(uint8_t *buf,uint32_t len)
{
	uint32_t 		read_len = TBuffer_Pop(ram_record_handle, (void *)buf, (int) len);
	return read_len;
}


void func_ram_record_init(void)
{	
	ram_record_handle = TBuffer_Init(&ram_record_obj, ram_record_buf, sizeof(ram_record_buf));
}


typedef struct record_test_object
{
	uint32_t 	cnts;
	uint8_t 	test_flag;
	char 			buf[32];
}record_test_OBJ;
	
record_test_OBJ record_test_obj;

void func_ram_record_test(void)
{	
	
	record_test_obj.cnts++;
	sprintf(record_test_obj.buf,"XX%08xXX",record_test_obj.cnts);
	switch(record_test_obj.test_flag)
	{
		case 0:
		{
			func_ram_record_write((uint8_t *)record_test_obj.buf ,strlen(record_test_obj.buf));
		}break;
		case 1:
		{
			func_ram_record_read((uint8_t *)record_test_obj.buf ,sizeof(record_test_obj.buf));
			func_ram_record_delete((uint8_t *)record_test_obj.buf ,sizeof(record_test_obj.buf));
			func_ram_record_read((uint8_t *)record_test_obj.buf ,sizeof(record_test_obj.buf));
		}break;
		default:
		{
			func_ram_record_read((uint8_t *)record_test_obj.buf ,sizeof(record_test_obj.buf));
		}break;
		
	}
	
}

void func_ram_record_main(void const *argument)
{
	osDelay(1000);//
	func_ram_record_init();
	while(1)
	{
		func_ram_record_test();
		osDelay(1000);
	}
}

#endif //------------------------USE_RAM_RECORD----------------------------
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
