#ifndef __IEC104_SERVER_H__
#define __IEC104_SERVER_H__

#include "../tag.h"
#include "../common.h"
#include "cs104_slave.h"


//#define CP56_IRG_INV //带时间的周期上报
//#define CP56_IRG     //带时间的总召响应
//#define CP56_SPON    //带时间的变化上报
#define TAG_EX_PR_INDEX 0 //tag中扩展指针数组的索引
#define COUNTER_TAGS_MAX 256

#define DATA_CALSS 4
#define IEC104_CONFIG_FILE "/app/config/north/iec104_north_map.json"
#define IEC104 "IEC104"
typedef struct point_info_104_t
{
    tag_t *tag;
    int addr;
    DATA_TYPE data_type;
    bool changeReport;
    float coefficient;
	void *ptr;
}point_info_104;

typedef struct point_param_t
{
    char *point_type;
	void *ptr;
    int point_num;
    point_info_104 point_info[0]; //普通点位
}point_param;

typedef struct iec104_param_t
{
    int ca;//the common address

    // int counter_point_num;
    // point_info_104 counter_point_info[COUNTER_TAGS_MAX]; //电度量点位
    hash_intptr_t *point_map_hash;  //地址（point_info_104中的addr）和 point_info_104 的映射关系

    point_param *point_param_arry[DATA_CALSS];
}iec104_param;

typedef struct iec104_info_t
{
    CS104_Slave slave;
    int control;
    int periodRepEn;    //是否开启周期上报
    int reportInterval;     //周期上报间隔，单位s
    iec104_param *param;
    int cacnt;  //记录不同ASDU地址数量
}iec104_info;

iec104_info *iec104_server_init(void); //初始化要放在所有数采点位加载完毕后再初始化，否则会造成点位无法找到
void iec104_server_start(iec104_info *var);
#endif
