﻿#ifndef __HUAYUN_COMMON_H
#define __HUAYUN_COMMON_H

/***************HEADER FILES****************/
#include <string.h>
#include <syslog.h>
#include "ipc_session.h"
#include "dy_utils/dy_db.h"
#include "lnxall_list.h"
#include "dy_utils/dy_common.h"
#include "dy_utils/dy_ds.h"
#include "dy_utils/kv_array.h"
#include "dy_utils/dy_ipc.h"

#include "Iec104.h"

extern pthread_mutex_t mutex;

#if 1
#define IEC104_SERVER_IP "183.134.216.94"//"183.134.216.94"//"183.134.216.97"
#define IEC104_PORT 15021//19812
#else
#define IEC104_SERVER_IP "172.16.253.225"
#define IEC104_PORT 2404
#endif

#define IEC104_REPORT_PERIOD 900
#define HUAYUN_DB		"/app/huayun.db"
#define MAXLINE     1500
#define IEC104_STR		"IEC104_"


/******************************************/

typedef struct
{
	char identifier[64];
	uint16_t	info_addr;
	float val;
	uint8_t quality;
	time_t time_stamp;
}tag_info_t;

typedef struct _node_tag_t {
	int tag_cnt;
	tag_info_t *tag_info;
}node_tag_t;


typedef struct
{
    struct list_head list;
	node_cfg_t node_info;
    node_tag_t node_tag;
}node_info_list_t;

typedef struct
{
    struct list_head list;
	int type;
    ipc_msg_t mqtt;
}data_list_t;

typedef struct _huayun_var_t
{
	int iec104_start;
	int iec104_fd;
	pthread_t iec104_task;
	char server_ip[32];
	int port;
	int period;

	int period_timer;
	int connect;
	int alive_timer;
	int iec104_alive;

    int node_cnt;
    struct list_head node_list;

	int data_flag;
	int data_cnt;
	struct list_head data_list;
	time_t dev_info_time;
	int mqtt_list_cnt;
	struct list_head send_mqtt_list;
	dy_db_session_t* db;
	
	ipc_session_t* session; //内部broker的MQTT client，用于进程间通信
    nodes_cfg_table_t *nodes_cfg_table; //节点信息
    template_table_t *template_table; //模板信息
    object_table_t *object_table; //物模型信息
    char sn_str[SN_MAX_LEN];
    char proc_name[PROGRAM_NAME_LEN];
    kv_array_t identifier_backup;
}huayun_var_t;


#endif /* __HUAYUN_COMMON_H */
