/*
 * message_list.h
 *
 *  Created on: Oct 9, 2018
 *      Author: zgh
 */

#ifndef LORA_PROTOCOL_STACK_MESSAGE_LIST_H_
#define LORA_PROTOCOL_STACK_MESSAGE_LIST_H_

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <time.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <linux/rtc.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sched.h>
#include <assert.h>
#include <pthread.h>
/***************HEADER FILES****************/
#include <string.h>
#include <syslog.h>
#include "ipc_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"
/******************************************/

#define VALID_TIME_DEFAULT 0	//default time out
#define MAX_MSG_BUFFER 255

typedef struct
{
    uint8_t a;
    uint8_t b;
}lora_addr_t;

typedef struct {
	list_t list;
	lora_addr_t addr;
	uint8_t code;
	uint8_t data[MAX_MSG_BUFFER];
	uint8_t len;
	uint8_t retry;
	time_t times;
//    uint32_t mi;	///<流水号
//    uint8_t  src_identifier[64];///<原服务名称
} msg_list_t;

typedef struct {
    lora_addr_t addr;
    uint8_t code;
    uint8_t data[MAX_MSG_BUFFER];
    uint8_t len;
    uint8_t retry;
    uint32_t times;

//    uint32_t mi;	///<流水号s
//    uint8_t  src_identifier[64];///<原服务名称
}exp_lora_msg_t;


typedef enum
{
    GENERAL_DOWNLINK_LIST,
    GENERAL_DOWNLINK_RESP_LIST,
    DELAY_MSG_LIST,
    GENERAL_UPLINK_LIST,
	SEND_LIST_DEPTH,
}send_type_t;

void msg_list_init(void);

int list_size(send_type_t type);

int msg_timeout_del(send_type_t type);

int msg_get_compare(send_type_t type,	lora_addr_t addr,exp_lora_msg_t *pram);

int msg_get_first(send_type_t type,	exp_lora_msg_t *pram);

int msg_add_tail(send_type_t type,	exp_lora_msg_t *pram);

int msg_add_head(send_type_t type,	exp_lora_msg_t *pram);

#endif /* LORA_PROTOCOL_STACK_MESSAGE_LIST_H_ */
