/*  Header file for Node adapter V05.xx and V04.22 or later */
/*  				Satoshi Yasuda	 */
 

#define	SET_AD_INIT		0x00
#define	SET_TimeOut		0x01
#define	SET_DelayTime		0x02
#define	SET_KeepAlive		0x03
#define	SET_RESYNC_ERROR_BITS	0x04
#define	SET_PTT			0x05
#define	SET_COS_CHECK		0x06
#define	SET_CRC_CHECK		0x07
#define	SET_LastFrame		0x0a
#define	SET_SD_CONV		0x0b
#define	SET_DEBUG		0x0d
#define	SET_HalfFull		0x0e
#define	SET_AD_RESET		0x0f
#define	PUT_DATA		0x10
#define	GET_DATA		0x11
#define	GET_HEADER		0x21
#define	GET_AD_STATUS		0x30
#define	SET_MyCALL		0x40
#define	SET_MyCALL2		0x41
#define	SET_YourCALL		0x42
#define	SET_RPT1CALL		0x43
#define	SET_RPT2CALL		0x44
#define	SET_FLAGS		0x45
#define	SET_MyRPTCALL		0x46
#define	SET_TXCALL		0x47
#define	SET_JitterBufferSize 0x4a
#define	GET_REMAINSPACE		0x50
#define	GET_TimeOut		0x51
#define	GET_DelayTime		0x52
#define	GET_KeepAlive		0x53
#define	GET_MyRPTCALL		0x55
#define	GET_MODE		0x56
#define	GET_MODE2		0x57
#define	GET_JitterBufferSize 0x58
#define	SET_SN_SQ		0x71
#define	GET_SN_SQ		0x72
#define	GET_SERIAL_NO		0xFD
#define	GET_USERID		0xFE
#define	GET_VERSION		0xFF

#define	GET_SN_VALUE	0x70	/* CMX589A S/N   V05.xx or Later version only */

/*---- Repeater Mode  ---*/

#define	SET_RepCallCheck	0x90
#define	SET_RepDupCheck		0x91
#define	SET_RepDupClear		0x92
#define	SET_AltMyCallSet	0x93
#define	SET_AltMyCall2Set	0x94
#define	SET_AltYourCallSet	0x95
#define	SET_AltRPT1CallSet	0x96
#define	SET_AltRPT2CallSet	0x97

#define	SET_AltMyCall		0xa0
#define	SET_AltMyCall2		0xa1
#define	SET_AltYourCall		0xa2
#define	SET_AltRPT1Call		0xa3
#define	SET_AltRPT2Call		0xa4

#define	GET_AltMyCall		0xa8
#define	GET_AltMyCall2		0xa9
#define	GET_AltYourCall		0xaa
#define	GET_AltRPT1Call		0xab
#define	GET_AltRPT2Call		0xac
#define	GET_RepeaterMode	0xaf

#define	GET_INVERT_STATUS	0xd0
#define	SET_RX_Invert		0xd1
#define	SET_TX_Invert		0xd2
#define	SET_AutoRxDetect	0xd3

#define SET_HeaderGen		0xe0
#define SET_HeaderGenType	0xe1

#define	ON	1
#define	OFF	0

/* Mode definition	*/
#define	CRC_SW		0x02
#define	COS_SW		0x04
#define	LastFrame_SW	0x08
#define HalfFukk_SW	0x80


/* AD_STATUS definition	*/
#define	READ_RF_HEADER	0x10
#define	COS_OnOff 	0x02
#define	CRC_ERROR 	0x04
#define	LastFrameRead	0x04
#define	HeaderDecodeDone	0x10
#define PTT_OnOff	0x20

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

typedef	struct
{
	BYTE	UpdateFlag;
//	BYTE	Reserve;
	BYTE	DelayTime;
	BYTE	TimeOut;
	BYTE	KeepAlive;
	BYTE	JitterSize;
	BYTE	Mode;
	BYTE	Mode2;
	BYTE	Invert;
	WORD	SN_Squelch;	
} AD_PARAM;

AD_PARAM AdParam;

typedef struct{		
	BYTE	id[4];
	BYTE	flags[2];
	BYTE	reserve[2];
	BYTE	type_id;
	BYTE	dest_repeater_id;
	BYTE	send_repeater_id;
	BYTE	send_terminal_id;
	BYTE	seq_high;
	BYTE	seq_low;
	BYTE	control;
	BYTE	body[41];
} packet;

typedef struct{		
	unsigned char	id[4];
	unsigned char	flags[2];
	unsigned char	reserve[2];
	unsigned char	type_id;
	unsigned char	dest_repeater_id;
	unsigned char	send_repeater_id;
	unsigned char	send_terminal_id;
	unsigned char	seq_high;
	unsigned char	seq_low;
	unsigned char	control;
	unsigned char	voice[12];
} voice_pkt;


typedef struct
{
	BYTE	req_id[2];
	BYTE	flags[2];
	BYTE	PicVer[2];
	BYTE	reserve[2];
	BYTE	req_callsign[8];
	BYTE	zone[8];
	BYTE	area[8];
	DWORD	ip_address;
	DWORD	ssn;
	DWORD	port;
} call_table;
