
#ifndef _LINE_LOSS_H
#define _LINE_LOSS_H

#define ADD_POWER_REVERSE_EVENT_FULL_FUN   //潮流反向完整功能（若无潮流反向开始，产生了潮流反向结束则不写入事件数据）

struct ll_file_info
{
    struct  rtc_time_t  time_bk;    //定点时刻
    u32 len;                        //一条记录的长度
    u32 rcd_num;                    //记录行总数
    u16 part_id;                    //节点索引
   
    bool b_err;                     //错误标志
    bool b_frz;                     //冻结
    bool b_new;
	bool b_first;
	
};


struct ll_element
{
    u16 ti;
    char *unit;
    float *p_val;
};

struct ll_eventd_element
{
    u16 ti;
    float val;
};


struct eventd_content_st
{
    struct  rtc_time_t tm;          //事件时间信息
    struct ll_eventd_element ele[8];    //正向有功电能、正向无功电能、一象限无功电能、四象限无功电能、
    //反向有功电能、反向无功电能、二象限无功电能、三象限无功电能
};

struct eventd_format_st //事件记录格式
{
    u8 type;                                //类型编号
    u32 times;                              //记录总次数
    struct eventd_content_st start;         //起始信息内容
    struct eventd_content_st end;           //结束信息内容
};


typedef struct LL_FILE_ST
{
    const char *file_name;
    struct history_rcd_file *p_file;
    struct ll_file_info *p_info;
    fileInfo  *p_list;
    const struct ll_element *p_element;
    const char *file_head;
    const char *file_dir;
    const int dataNum;
    const int sectNum;  //最大节点数
    bool refresh;

} LL_FILE_ST;



enum
{
    ID_LL_FILE_FIXD=0,
    ID_LL_FILE_RAND,
    ID_LL_FILE_FRZD,
    ID_LL_FILE_SHARPD,
    ID_LL_FILE_MONTHD,
    ID_LL_FILE_EVENTD,
      
    ID_LL_FILE_NUM,
};


#define FIXD_LL_ID_OFFSET       strlen("fixd01.msg,v1.0\r\nD30XXXXZN000201703100002,")

#define FIXD_LL_HEAD            "fixd01.msg,v1.0\r\nD30XXXXZN000201703100002,005,02\r\n"
#define RAND_LL_HEAD            "rand01.msg,v1.0\r\nD30XXXXZN000201703100002,005,02\r\n"
#define FRZD_LL_HEAD            "frzd01.msg,v1.0\r\nD30XXXXZN000201703100002,005,02\r\n"
#define SHARPD_LL_HEAD          "sharpd01.msg,v1.0\r\nD30XXXXZN000201703100002,005,02\r\n"
#define MONTHD_LL_HEAD          "monthd01.msg,v1.0\r\nD30XXXXZN000201703100002,005,02\r\n"
#define EVENTD_LL_HEAD          "D30XXXXZN000201703100002,70\r\n"



#define LL_RCD_HEAD             "12,2020-02-27 16:30:00,"
#define LL_RCD                  "6401,+000000.00,"  //电能信息元素值固定为 8 字节,功率信息元素值固定为 10 字节

extern DWORD us0_ll;
extern bool ll_file_set;
extern fileInfo fixdList;       //线损模块定时冻结
extern fileInfo randList;       //线损模块瞬时冻结
extern fileInfo frzdList;       //线损模块日冻结
extern fileInfo sharpdList;     //线损模块整点冻结
extern fileInfo monthdList;     //线损模块考核日冻结
extern LL_FILE_ST ll_file_st[];

extern struct ll_file_info  fixd_file_info;
extern struct ll_file_info  rand_file_info;
extern struct ll_file_info  frzd_file_info;
extern struct ll_file_info  sharpd_file_info;
extern struct ll_file_info  monthd_file_info;
extern struct ll_file_info  eventd_file_info;

extern fileInfo eventd_pnaList; //A 相有功功率反向
extern fileInfo eventd_pnbList; //B 相有功功率反向
extern fileInfo eventd_pncList; //C 相有功功率反向
extern fileInfo eventd_flownList;   //潮流方向改变
extern fileInfo eventd_llclrList;   //线损模块清零
extern fileInfo eventd_soeclrList;  //事件清零
extern fileInfo eventd_syntList;    //校时




extern int fresh_eventd_file(struct eventd_format_st *p,BYTE opt);

int  ll_read_file(u8 file_id);
int create_ll_file(u8 file_id);
int init_ll_file(void);
void ll_file_app(void);
int delete_ll_file(u8 file_id);
void refresh_month_file(void);
void init_ll_db_file(fileInfo *p_db,char *file_name,int sectNum,int listSize);






#endif
