#ifndef __DY_DS_H_
#define __DY_DS_H_

#include "dy_common.h"
#include "dy_pp.h"

typedef struct
{
    uint8_t protocol_ver;
    uint16_t soft_ver;
    uint16_t hardware_ver;
    uint32_t sn;
    uint8_t class;
}register_info_t;

typedef struct
{
    int count;
    char *p_instr_code;
}lora_subscrib_t;


typedef enum
{
	ACTION_NULL,
    ACTION_LOGIN,
    ACTION_SND,
    ACTION_RETRY,
	ACTION_RCV,
	ACTION_SOFT_INFO,
    ACTION_DISCONN,
}node_action_e;

typedef struct {
	unsigned char addr[8];
    unsigned char port;
	unsigned char action;
	char sub_template_id[16];///<下挂设备协议模板
	char res[64];
    char sn[SN_MAX_LEN];
}node_message_action_t;

typedef struct
{
    unsigned char addr[8];
    char sn[SN_MAX_LEN];
    int port;
    int depth;
    int class;
    int pak_rssi;
    int tx;
    int rx;
    int retry;
    int loss;
    bool online;
    bool online_status_changed;
    int proto_ver;
    int hard_ver;
    int soft_ver;
    time_t login_time;
    time_t last_rcv_time;
    unsigned int offline_times;
    unsigned int logout_times;
    char protocol; ///<设备协议
} node_status_t;

typedef struct
{
    int node_cnt;
    bool online_status_changed;
    node_status_t status[0];
} dev_status_table_t;
int flush_device_status_soft_info_by_sn(dev_status_table_t *ns_table, void *info,int len,char *sn);
int flush_device_status_by_sn(dev_status_table_t *ns_table, node_action_e action, char *sn);
int ds_flush_status_action(dev_status_table_t *ns_table, node_message_action_t *nm_action);
char *ds_print(dev_status_table_t *ns_table);
int dev_status_init(dev_status_table_t **p_ns_table, nodes_cfg_table_t *nodes, template_table_t *template_table, gw_port_e *ports, int cnt);
int dev_status_init_by_app_key(dev_status_table_t **p_ns_table, nodes_cfg_table_t *nodes, template_table_t *template_table, char *app_key);
int node_sta_recovery(dev_status_table_t *tab, char *bak_file);
int node_sta_backup(dev_status_table_t *tab, char *bak_file);

#endif
