#include "p_apps.h"
#include "p_sip.h"
#include "v_task.h"
#include "my_sip.h"

BOOLEAN Sip_bUsingUdp = TRUE;
XSHORT Sip_iSendLen;
PXCHAR Sip_pDataOut;

/**********************************************************************************
****** SIP functions **********************************************************
***********************************************************************************/

void SipTspStartup()
{
	if (Sip_bUsingUdp)	Sip_pDataOut = (PXCHAR)Adapter_pSendUdpData;
	else				Sip_pDataOut = (PXCHAR)Adapter_pSendTcpData;	
	Sip_iSendLen = 0;
}
/*
void SipCopyUdpHead(UCHAR iDstIndex, UCHAR iSrcIndex)
{
	SdramReadData(OPTIONS_SDRAM_POS+iSrcIndex);
	SdramWriteData(OPTIONS_SDRAM_POS+iDstIndex, UDP_HEAD_LEN);
}
*/
void SipUdpSend(UCHAR iHeadIndex)
{
	OutputPXCHAR((PXCHAR)Adapter_pSendUdpData, Sip_iSendLen);
	UdpSend(Sip_iSendLen, iHeadIndex);
}

/**********************************************************************************
****** SIP API functions **********************************************************
***********************************************************************************/

/*
 BOOLEAN SipRunTcp()
{
	if (Sip_bUsingUdp)		return FALSE;

	return TRUE;
}
*/

 BOOLEAN SipRunUdp()
{
	if (!Sip_bUsingUdp || Adapter_iReceiveUdpPort != Sys_iRegisterPort)
		return FALSE;

	OutputPXCHAR((PXCHAR)Adapter_pReceiveUdpData, Adapter_iReceiveLen);
	// send to Sys_iServicePort is the right way
	SipRunData();
	return TRUE;
}
