/*-------------------------------------------------------------------------
   UDP debug function copy right information

   Copyright (C) 2006-2008. Lin, Rongrong <woody@palmmicro.com>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   This software is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
-------------------------------------------------------------------------*/

#include "type.h"
#include "ar168.h"
#include "core.h"
#include "apps.h"
#include "tcpip.h"

extern BOOLEAN _bUseSyslog;

const UCHAR _cHexPrefix[3] = "0x";

void UdpDebugString(PCHAR pStr)
{
	Syslog(SYSLOG_PRI_DEBUG, pStr);
}

void UdpDebugVal(USHORT sVal, UCHAR iRadix)
{
	UCHAR pBuf[7];		// (2+4+1)
	PCHAR pCur;

	if (!_bUseSyslog)				return;

	pCur = pBuf;
	if (iRadix == 16)
	{
		strcpy(pCur, _cHexPrefix);	// 2
		pCur += 2;
	}
	itoa(sVal, pCur, iRadix);		// 4/5
	UdpDebugString(pBuf);
}

void UdpDebugVals(PCHAR pVals, USHORT sLen)
{
	USHORT s;
	UCHAR iVal;
	UCHAR p[48];	// (2+1)*15+2+1

	if (!_bUseSyslog)				return;

	p[0] = 0;
	for (s = 0; s < sLen; s++)
	{
		iVal = pVals[s];
		if (iVal < 0x10)
		{
			strcat(p, "0");
		}
		itoa(iVal, p+strlen(p), 16);	// 2
		if ((s&0x0f) == 0x0f)
		{
			UdpDebugString(p);
			p[0] = 0;
		}
		else
		{
			strcat(p, " ");				// 1
		}
	}
	UdpDebugString(p);
	UdpDebugString("");
}

void UdpDebugIDS(UCHAR iIDS)
{
	UCHAR pBuf[21];		// Max(DISPLAY_MAX_CHAR) + 1

	if (!_bUseSyslog)				return;
	
	TaskLoadString(iIDS, pBuf);
	UdpDebugString(pBuf);
}

/*
void UdpDebugChar(UCHAR iChar)
{
	UCHAR pBuf[2];

	pBuf[0] = iChar;
	pBuf[1] = 0;
	UdpDebugString(pBuf);
}

void UdpDebugInfo(PCHAR pPrefix, USHORT sAddr, USHORT sLen)
{
	UCHAR pStr[100];

	strcpy(pStr, pPrefix);
	strcat(pStr, "\taddr: 0x");
	itoa(sAddr, pStr+strlen(pStr), 16);
	strcat(pStr, "\tlen: ");
	itoa(sLen, pStr+strlen(pStr), 10);
	UdpDebugString(pStr);
}
*/
