#ifndef _MESSAGE_H
#define _MESSAGE_H

#include "stdio.h"
#include "stdint.h"
#include "string.h"

#define	MAX_FIFO_DEPTH							20			//消息缓存区宽度	

typedef enum
{
	FALSE = 0,
	TRUE = !FALSE
}_bool;

typedef enum {
	_ERROR = 0, 
	OK = !_ERROR
}_ErrStatus;

//消息结构体
typedef struct _ControlMessage
{
	uint16_t         		    msgType;					//协议类型	
	uint8_t 								msgData;					//消息的内容
	uint8_t 								msgQos;						//消息的传输等级
	uint16_t								msgLen;						//附加消息内容指针指向的数据长度
	uint8_t* 								msgDataPrt;				//附加消息内容指针
}	MESSAGE;


//消息FIFO结构体
typedef struct _MESSAGE_FIFO
{
 	uint8_t									IndexHead;
	uint8_t									Count;
	MESSAGE 								Buf[MAX_FIFO_DEPTH];			//消息对列

} MESSAGE_FIFO;

//消息类型定义
typedef enum _MSG_FIFO_INDEX
{
	MSG_FIFO_PROTOCOL = 0,										//后台通讯协议消息
	MSG_FIFO_RS485_PROTOCOL,									//RS485通讯协议消息
	MSG_FIFO_PC_CMD,													//上位机接口通讯协议消息
	MSG_FIFO_COUNT														//消息fifo存储区计数

} MSG_FIFO_INDEX;

extern MESSAGE sendMsg;
extern MESSAGE pcCmdMsg;				//上位机接口信息

void MessageInit(void);
_ErrStatus MessageSend(uint8_t MsgFifoIndex, MESSAGE event);
MESSAGE *MessageGet(uint8_t MsgFifoIndex);
uint8_t GetMessageRemainingSpace(uint8_t MsgFifoIndex);

#endif

