#ifndef __IEC104_CREATE_H__
#define __IEC104_CREATE_H__

#include "north_automatic.h"

#define IEC104_NORTH_MAP_FILE "iec104_north_map.json"

extern char *type_string[];
extern char *order_string[];
extern const char *property_name[];

typedef enum
{
    N_CODE = 0,
    RP_CODE,     
    RM_CODE, 
    RC_CODE,  
    RR_CODE, 
} iec_code_t;

typedef struct
{
    char **compatible;
	int str_addr;
	int end_addr;
	//------------------------------------此4个参数，仅多个设备用一个asdu addr时使用，记录信息对象的个数 (无效)
    unsigned short nb_rp;
	unsigned short nb_rm;
	unsigned short nb_rc;
	unsigned short nb_rr;
	//------------------------------------NOUSER
} iec_class_info_t;

typedef struct
{
    char ver;
	int server_port; 
	int periodReportEnable;
	int reportInterval;
	unsigned short start_RemotePoint;    // 遥信起始地址
	unsigned short start_RemoteMeas;     // 遥测起始地址
	unsigned short start_RemoteCtrl;     // 遥控起始地址
	unsigned short start_RemoteRegu;     // 遥调起始地址
	iec_class_info_t iec_class_info[CLASS_NUM];
} iec_proto_info_t;

typedef struct
{
	unsigned int addr;
	unsigned int addr_S;
	DATA_TYPE data_type;
    double coefficient; //1.0

} iec_xlsx_item_t;

typedef struct
{
	unsigned short addr;
	struct mq_north_tag *rp_tag[TAG_NUM];
	unsigned short nb_rp;
	struct mq_north_tag *rm_tag[TAG_NUM];
	unsigned short nb_rm;
	struct mq_north_tag *rc_tag[TAG_NUM];
	unsigned short nb_rc;
	struct mq_north_tag *rr_tag[TAG_NUM];
	unsigned short nb_rr;
} iec_xlsx_dev_t;

typedef struct
{

} iec_xlsx_sheet_t;


typedef struct
{
	unsigned int addr;
	unsigned int addr_S; // 遥测地址（）
	unsigned int addr_P; // 遥信地址（）
	DATA_TYPE data_type;
	unsigned int changeReport;
	double coefficient; //1.0
} iec_north_tag_t;

typedef struct
{
	unsigned short addr;
	struct mq_north_tag *rp_tag[TAG_NUM];
	unsigned short nb_rp;    // 遥信点位个数  addr
	struct mq_north_tag *rm_tag[TAG_NUM];
	unsigned short nb_rm;    // 遥测点位个数
	struct mq_north_tag *rc_tag[TAG_NUM];
	unsigned short nb_rc;    // 遥控点位个数
	struct mq_north_tag *rr_tag[TAG_NUM];
	unsigned short nb_rr;    // 遥调点位个数

	unsigned short section_indx; // 分段索引
} iec_north_dev_t;

typedef struct
{    
    iec_class_info_t *iec_class_info;
} iec_north_class_t;

iec_proto_info_t *get_iec104_proto_info(void); //

int iec_match_by_class_type(char **class_type, iec_class_info_t *iec_class_info, int *p_compatible_id, int log_flag); // -1，匹配失败，其他匹配成功

char *create_iec_relate_file(mq_north_inside_t *mq_north_inside, mq_xlsx_book_t *mq_xlsx_book);

void init_iec_north_dev(iec_north_dev_t *dev);
void init_iec_xlsx_dev(iec_xlsx_dev_t *dev);
void clear_iec104_class_nb(iec_class_info_t *iec_class_info); // iec104清零类，遥信、遥测、遥控、遥调个数

#endif
