#ifndef _M2UA__H
#define _M2UA__H

typedef struct _m2ua_up_msg
{
	BYTE 	link						__attribute__((packed));
	BYTE 	len						__attribute__((packed));
	BYTE 	sio						__attribute__((packed));
	
	union
	{
		struct
		{
			BYTE 	content[256]	__attribute__((packed));
		}mtp3						__attribute__((packed));
	
		struct
		{
			BYTE	mtp3_ip			__attribute__((packed));
			BYTE	opercode		__attribute__((packed));
			BYTE	alarmcode		__attribute__((packed));
		}lm							__attribute__((packed));
	}msg							__attribute__((packed));
	
}m2ua_up_msg_t;

void m2ua_init(BYTE);
void m2ua_timer(void);

int get_m2ua_msg(m2ua_up_msg_t **data_ptr);
int put_m2ua_msg(m2ua_up_msg_t *data_ptr);
int set_m2ua_link(BYTE link, BYTE *data_ptr);
int set_m2ua_sg(WORD sg, BYTE *data_ptr);
int m2ua_restart();

//add by yizane
typedef struct _xua_lm_lk
{	
	BYTE 	link					__attribute__((packed));
	BYTE	len						__attribute__((packed)); /* len = 3 */
	BYTE	mtp3_ip				__attribute__((packed));
	BYTE	opercode			__attribute__((packed));
	BYTE	alarmcode			__attribute__((packed));
}xua_lm_lk;

typedef struct _xua_iua_msg
{	
	BYTE 	link						__attribute__((packed));
	BYTE	len							__attribute__((packed)); /* len for content */
	BYTE 	content[256]		__attribute__((packed));
}xua_iua_msg;

typedef struct _xua_m2ua_msg
{	
	BYTE 	link						__attribute__((packed));
	BYTE	len						__attribute__((packed)); /* len for content */
	BYTE 	content[256]		__attribute__((packed));
}xua_m2ua_msg;

typedef struct _xua_up_msg
{	
	BYTE		msg_class								__attribute__((packed));
	union                       		
	{  
		xua_lm_lk						lm_lk			__attribute__((packed)); 
		xua_m2ua_msg				m2ua   	    __attribute__((packed));
		xua_iua_msg					iua				__attribute__((packed));		
	}msg														__attribute__((packed));
}xua_up_msg_t;


int get_xua_msg(BYTE xUA_type, xua_up_msg_t **data_ptr);
int put_xua_msg(xua_up_msg_t *data_ptr);

#define	XUAHEADOFFSET						3
#define	RESERVE_FOR_IUAHEAD			(28 - XUAHEADOFFSET)
#define	RESERVE_FOR_M2UAHEAD		(20 - XUAHEADOFFSET)

//msg_class
#define	IUA_QPTM_MSG				0x05
#define	M2UA_MAUP_MSG			0x06
#define	IUA_MGMT_CMD				0xA5
#define	M2UA_MGMT_CMD			0xA6

#define 	IUA_APP					1
#define 	M2UA_APP				0
//add by yizane
#endif
