#ifndef _AT24C128OPT_H_
#define _AT24C128OPT_H_

#include "../../User/includes.h"
#include "../../User/stm32f10x_it.h"
#include "AT24C128.h"
#include "../globalDef.h"


#define GATEWAY_DEVICE_TYPE 0x0301
#define GATEWAY_APP_TYPE 0x03
#define GATEWAY_APP_VERSION 0x009

#define GATEWAY_UPDATE_FLAG  0x55

#define FRAM_FIRST_PWERUP 0x55AA

#define FRAM_TOTAL_SIZE  (256*64)
/*分配ATC128的空间使用*/
/* 共有16K， 每页64个字节  共有256页 */

#define FRAM_ALLOC_START (0)
/*第一页 基本信息  占用1页*/
#define FRAM_FIRST_POWER_ON     (FRAM_ALLOC_START) // 是否是第一次上电 2个字节
#define FRAM_VERSION            (FRAM_FIRST_POWER_ON+sizeof(uint16_t)) // EEPROM 版本 1个字节
#define FRAM_GATWAY_RESETNUM    (FRAM_VERSION+sizeof(uint8_t))  // 复位次数  4个字节
#define FRAM_UPDATE_FLAG        (FRAM_GATWAY_RESETNUM+sizeof(uint32_t)) // 升级标志 1个字节
#define FRAM_UPDATE_STATUS      (FRAM_UPDATE_FLAG+sizeof(uint8_t)) // 升级状态 1个字节
#define FRAM_UPDATE_1_REVER     (FRAM_UPDATE_STATUS+sizeof(uint8_t)) // 预留4个字节
#define FRAM_GATWAY_HARDWARE_MSG (FRAM_UPDATE_1_REVER+sizeof(uint32_t)) // 网关硬件信息 GateHareWareMsg
#define FRAM_GATWAY_VER_MSG       (FRAM_GATWAY_HARDWARE_MSG+sizeof(GateHareWareMsg)) // 网关的软件版本信息
#define FRAM_NEXT_1_PRE             (FRAM_GATWAY_VER_MSG+sizeof(GateVersionMsg) // 下一个的地址

/*第二页  LORA 的信息*/
#define FRAM_SECOND_PAGE_ADDR     (1*64)

/*第三页 网关要存储的MQTT的信息 */
#define FRAM_THIRD_PAGE_ADDR      (2*64)
#define FRAM_MQTT_MSG           (FRAM_THIRD_PAGE_ADDR+0) //大小为 MqttIdPort的大小
#define FRAM_NEXT_3_PRE         (FRAM_MQTT_MSG + sizeof(MqttIdPort)) // 下一个要写入的地址


/*第四页 液位仪要存储的信息 */

#define FRAM_FOUR_PAGE_ADDR (3*64)
#define FRAM_CONFIG_MSG     (FRAM_FOUR_PAGE_ADDR+0) // 网关的有关采集器的配置信息 GateConfigMsg
#define FRAM_OILINIT_MSG    (FRAM_CONFIG_MSG+sizeof(GateConfigMsg)) // 液位仪的信息

extern void fram_init(void);
extern void fram_write_eeprom_powerUpFlag(void);
extern uint16_t fram_read_eeprom_powerUpFlag(void);

extern void fram_write_eeprom_version(void);
extern uint8_t fram_read_eeprom_version(void);
extern void fram_write_update_flag(void);

extern void fram_init_config_msg(void);
extern void fram_write_config_msg(uint16_t flag);
extern uint8_t fram_read_config_msg(void);

extern void fram_init_gateway_msg(void);



extern void fram_init_collect_msg(void);
extern void fram_write_collect_msg(void);
extern void fram_read_collect_msg(void);

extern void fram_init_gateway_resetnum(void);
extern void fram_wirte_gateway_resetnum(void);
extern void fram_read_gateway_resetnum(void);

extern void fram_init_gateway_version(void);
extern void fram_read_gateway_version(void);
extern void fram_write_gateway_version(void);

extern void fram_read_gateway_hardware_msg(void);
extern void fram_write_gateway_hardware_msg(void);

extern void fram_init_mqtt_msg(void);
extern void fram_write_mqtt_msg(void);
extern void fram_read_mqtt_msg(void);


extern void fram_init_oil_msg(void);
extern void fram_write_oil_msg(void);
extern void fram_read_oil_msg(void);
#endif
