#ifndef _SPIFFS_H_
#define _SPIFFS_H_

#include "list.h"
#include "stdbool.h"

#define PERSON_MAX_NAME     10
#define PERSON_NAME_MAX_LEN  10

typedef enum
{
      Administrator                     = 0,               //管理员
      product_person                    = 1,               //生产责任人
      repair_person                     = 2,               //维修责任人
      Maintenance_person                = 3,               //保养责任人
      check_person                      = 4,               //巡检责任人

}Person_type_t;

typedef struct
{
    uint16_t   person_num;  //序号
    uint8_t person_name[PERSON_NAME_MAX_LEN]; //人员名称
}Person_Name_t;
///////////////////////////////////////////
typedef struct
{
    uint8_t    person_type;  //人员类型
    Person_Name_t  person_name[PERSON_MAX_NAME];
    char string_name[100];
    bool Charge_close;//为真关闭责任人显示
    uint8_t other_name[16];//右屏第二部分责任人显示
}Person_t;




typedef struct
{
    uint8_t button_info;  //当前按键状态

    uint16_t Year;
    uint8_t Month;
    uint8_t Day;
    uint8_t Hour;
    uint8_t Minute;
    uint8_t Second;
    
    uint32_t time_min;
}Button_Time_t;


typedef struct
{
    bool checkIn_close;//为真关闭打卡
    uint32_t number;//只加不减，用于左屏图标数据
    uint8_t real_number;//真实签到人数，用于右屏
    uint8_t other_name[10];//四类打卡类型   限制四个字
}CheckIn_Setting_t;

typedef struct
{    
    //所有要保存的数据

    char terminal_name[20];
    char terminal_number[20];
    char station_name[20];
    char station_number[20];

    char btn_operation[6];
    char btn_breakDown_info[6];
    char btn_upKeep_info[6];
    char btn_shutDown_info[6];
    char btn_safeKeep_info[6];
    char btn_waitMaterials_info[6];
    //保存按键信息以及是否按键显示显示
    //0表示关闭，1表示开启
    bool btn_dis_flag[6];

    uint8_t lora_factory_channel;
    uint8_t lora_new_channel;
    uint8_t eflagID;         //本机组内编号
    unsigned char cid[20];   //设备ID  CID flash中获取的ID
    uint8_t paired;          //是否配网
    uint8_t power_status;    //当前系统的状态  开机或者关机
    // uint8_t is_setting;      //设置当前是否为设置模式


    Node *Send_list;
    uint16_t msg_id;        //添加消息发送设备ID 唯一性分配

    Button_Time_t  last_button;         //上次按键状态
    Button_Time_t  current_button;      //当前按键状态
    uint32_t Duration_time;             //持续的时间

    uint8_t left_max_Quick_refresh_time;     //最大快刷次数
    uint8_t left_current_Quick_refresh_time; //当前已经快刷的次数  当前快刷的次数大于设置 慢刷一次

    uint8_t right_max_Quick_refresh_time;     //最大快刷次数
    uint8_t right_current_Quick_refresh_time; //当前已经快刷的次数  当前快刷的次数大于设置 慢刷一次



    
    int batt_precent;       //当前显示的电量
    int last_batt_precent;  //记录上次显示的电量

    uint16_t year;
    uint8_t month;
    uint8_t day;
    uint8_t hour;
    uint8_t min;
    uint8_t sec;

    uint8_t rssi;

    uint8_t left_state;//左屏的模式  --> Machine_state_t
    uint8_t left_display_mode;//cmd 0x07 
    uint8_t right_display_mode;//cmd 0x08

#if 0
    uint8_t personnel_check_in[4];//存签到人数。
    uint8_t person_in_charge_name[4][12];//责任人名称
#else
    CheckIn_Setting_t checkIn_set[4];//签到相关
#endif

    uint8_t mac_addr[6];
    // uint8_t p_name[32];//未使用
    uint8_t refresh_cycle;
  
    uint8_t announcement[120];  //公告
    uint8_t systemMessage[120];  //系统消息
    Person_t  person[5];//

    uint8_t gateway_mac[6];  //网关的mac地址


  

    //保存右屏图表信息
    uint32_t num_goodProducts[8];
    uint32_t num_badProducts[8];

    uint8_t scale_UR_int[8];
    uint8_t scale_UR_dec[8];
    uint8_t scale_YR_int[8];
    uint8_t scale_YR_dec[8];

    uint16_t num_manHour[8];
    uint16_t num_people[8];

    uint16_t num_production[8];
    uint16_t num_repair[8];
    uint16_t num_inspection[8];
    uint16_t num_upkeep[8];

    uint8_t wait_send_rssi_bat;

    bool is_charge;      //判断是否充电
    bool is_charge_full; //判断是否充满

    char timestamp[20];   //当前时间戳
    int time_offset;      //时区偏移

}Machine_info_t;//所有要保存的数据

extern Machine_info_t Machine_info;
extern  Node *Send_list;  //发送数据链表


void spiffs_init(void);
void spiffs_write(Machine_info_t* info);
void spiffs_read(Machine_info_t* info);




void left_spiffs_write(uint8_t *buffer,unsigned int  size);
void left_spiffs_read(uint8_t *buffer,unsigned int  size);


void right_spiffs_write(uint8_t *buffer,unsigned int  size);

void right_spiffs_read(uint8_t *buffer,unsigned int  size);


size_t spiffs_read_powerOn(Machine_info_t* info);




#endif/*_SPIFFS_H_*/
