/**
 * @file      xieneng_can_comm.h
 * @brief     description about xieneng car BMS
 * @details  e.g. xieneng CAR BMS
 * @author   xianpeng.zhao@lnxall.com
 * @date     2020.03.25
 * @version  A001
 * @par Copyright (c):
 *       LNXALL
 * @par History:
 *   version: draft\n
 */
#ifndef __xieneng_can_COMMON_H
#define __xieneng_can_COMMON_H

/***************HEADER FILES****************/
#include <string.h>
#include <syslog.h>
#include <modbus/modbus.h>

#include "ipc_session.h"
#include "mqtt_session.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 "dy_utils/dy_can.h"
#include "dy_utils/modbus_utils.h"
#include "dy_utils/period_service.h"
#include "modbus/modbus.h"
#include "dy_utils/bitmap.h"

#include "common.h"
/******************MACRO********************/
#define NB_CONNECTION 5
/******************************************/

/*************ENUM*************************/

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

/*******************STRUCTURE**************/

typedef struct
{
    int size;
    unsigned short term_addr;
    modbus_mapping_t *mb_mapping;
    unsigned char *data;
} reg_data_t;

typedef struct
{
    char *identifier;
    int offset;
    tag_data_format_e format;
} prop_info_t;

typedef struct
{
    node_cfg_t *node;
    reg_data_t reg_data;
    prop_info_t *prop_info;
    int prop_cnt;
} node_data_t;

typedef struct
{
    ipc_session_t *session;             //内部broker的MQTT client，用于进程间通信
    char sn_str[SN_MAX_LEN];
    nodes_cfg_table_t *nodes_cfg_table; //节点信息
    template_table_t *template_table;   //模板信息
    object_table_t *object_table;       //物模型信息
    node_data_t *node;
    modbus_t *ctx;
} var_t;

/******************************************/
extern int __init_modbus_tcp_slave(var_t *var);
#endif /* __xieneng_can_COMMON_H */
