/*************************************************
File name:	cdrdebug.c
Author: 	
Version:	9:00:00 
Date:  		2002-5-7
Description:该文件定义了调试的函数
			

			
			
												
History:               
No. 		
Author:		  
Date:		 
Version:	   
Description:
*************************************************/

#include "cdr.h"
#if CDR_LINK_DEBUG
extern cdr_src CdrSet[CDR_SRC_NUM];
extern BYTE iCdrNum;

static char debug_buf[4096];
//static char           asc_in[256];
void cdr_debug_info(BYTE npage, BYTE nline, BYTE * pt, BYTE len);

/*************************************************
Function:        // cdrdebug_init
Description:     // 初始化调试模块
Calls:           // 
Called By:       // 
Table Accessed:  // 
Table Updated:   // 
Input:           // 
Output:          // 
Return:          // 
Others:          // 
*************************************************/
void cdrdebug_init()
{
	DWORD asc_id[20] = { 1, 3, 6, 1, 4, 1, 1373, 1, 3, 2, 3, 1, 2, 16, 4 };
	DWORD status_id[20] =
		{ 1, 3, 6, 1, 4, 1, 1373, 1, 3, 2, 3, 1, 2, 16, 1 };
	DWORD name_id[20] =
		{ 1, 3, 6, 1, 4, 1, 1373, 1, 3, 2, 3, 1, 2, 16, 2 };

	DWORD title_id[20] =
		{ 1, 3, 6, 1, 4, 1, 1373, 1, 3, 2, 3, 1, 2, 16, 6, 1 };

	static char module_name[16] = "CDR";
	static BYTE debug_status = 1;
	cdr_src *pcdr;
	BYTE i;
	char title[320], info[320] = {
		"1  2\r\n"
			"IP\r\n"
			"Port\r\n"
			"receive\r\n"
			"record\r\n"
			"lost\r\n"
			"tail\r\n"
			"head\r\n"
			"bind num\r\n"
			"get state\r\n" "get timeout\r\n" "set state\r\n" "set timeout"
	};

	debug_set_response(15, asc_id, debug_buf, 1);
	debug_set_response(15, status_id, &debug_status, 1);
	debug_set_response(15, name_id, module_name, strlen(module_name));

	for (i = 0; i < iCdrNum; i++) {
		pcdr = &CdrSet[i];
		sprintf(title, "\tCDR Collector\tPage %02d\t\tMessage\r\n%s",
				i + 1, info);
		title_id[14] = i + 6;
		debug_set_response(15, title_id, title, strlen(title));
		cdr_debug_info(i + 1, 2, (BYTE *) & pcdr->addr.remote_ip, 4);
		cdr_debug_info(i + 1, 3, (BYTE *) & pcdr->addr.remote_port, 2);
		cdr_debug_info(i + 1, 4, (BYTE *) & pcdr->recv, 4);
		cdr_debug_info(i + 1, 5, (BYTE *) & pcdr->recd, 4);
		cdr_debug_info(i + 1, 6, (BYTE *) & pcdr->loss, 4);
		cdr_debug_info(i + 1, 7, (BYTE *) & pcdr->instance, 4);
		cdr_debug_info(i + 1, 8, (BYTE *) & pcdr->head, 4);
		cdr_debug_info(i + 1, 9, (BYTE *) & pcdr->maxbind, 4);
		cdr_debug_info(i + 1, 10, (BYTE *) & pcdr->get_state, 1);
		cdr_debug_info(i + 1, 11, (BYTE *) & pcdr->get_timeout, 4);
		cdr_debug_info(i + 1, 12, (BYTE *) & pcdr->set_state, 1);
		cdr_debug_info(i + 1, 13, (BYTE *) & pcdr->set_timeout, 4);
	}
}

/*************************************************
Function:        // cdr_debug_info
Description:     // 显示调试信息
Calls:           // 
Called By:       // 
Table Accessed:  // 
Table Updated:   // 
Input:           // npage; nline; pt; len;
Output:          // 
Return:          // 
Others:          // 
*************************************************/
void cdr_debug_info(BYTE npage, BYTE nline, BYTE * pt, BYTE len)
{
	DWORD oid[20] =
		{ 1, 3, 6, 1, 4, 1, 1373, 1, 3, 2, 3, 1, 2, 16, 5, 2, 2 };
	oid[14] = 5 + npage;
	oid[15] = nline;
	debug_set_response(17, oid, pt, len);
}

#endif
