#include "dualsrv_pub.h"

extern _config_info config_info;

char debug_asciiIn[MAX_ASCIN_BUF_LEN];
char debug_asciiOut[MAX_ASCOUT_BUF_LEN];
char debug_message[MAX_ASCOUT_BUF_LEN];
extern int dualsrv_status;
static DWORD status_id[20]	= {1,3,6,1,4,1,1373,1,1,2,3,1,2,DUALSRV_DEBUG_ID+2,1};
static DWORD version_id[20] = {1,3,6,1,4,1,1373,1,1,2,3,1,2,DUALSRV_DEBUG_ID+2,2};
static DWORD ascii_in_id[20] = {1,3,6,1,4,1,1373,1,1,2,3,1,2,DUALSRV_DEBUG_ID+2,3};
static DWORD ascii_out_id[20] = {1,3,6,1,4,1,1373,1,1,2,3,1,2,DUALSRV_DEBUG_ID+2,4};

const static BYTE	PAGE_POINT 	= 14;
const static BYTE LINE_POINT 	= 15;
const static BYTE	BASE_ID_LEN = 15;


static BYTE debug_status=1;
int ems_debug_flag=0;

int dualsrv_debug_init()
{
	//int page;
	//char* ptr;
	
	debug_set_response(15, status_id, &debug_status, 1);//smpp status
	debug_set_response(15, version_id, (BYTE*)DUALSRV_MODULE_VERSION, strlen(DUALSRV_MODULE_VERSION));
	debug_set_response(15, ascii_in_id, (BYTE*)debug_asciiIn, MAX_ASCIN_BUF_LEN);
	debug_set_response(15, ascii_out_id, (BYTE*)debug_asciiOut, MAX_ASCOUT_BUF_LEN);

	debug_init_wxc2_ver(DUALSRV_SOFTER_VERSION);
	
	return 1;
}

void dualsrv_debug_timer()
{
	if (strlen((char*)debug_asciiIn) > 0)
	{
		if (strcmp((char*)debug_asciiIn+1, "help") == 0)
		{
			send_ascout("EMS Debug Monitor Help:\n\r\n\r");
			send_ascout("log none               Turn off all log items\n\r");
			send_ascout("log all                Turn on all log items\n\r");
			send_ascout("list ems status\n\r");
		}
		else if(strcmp((char*)debug_asciiIn+1, "list ems status") == 0)
		{
			send_ascout(debug_message);
		}
		else if(strcmp((char*)debug_asciiIn+1, "log all") == 0)
		{
			ems_debug_flag=1;
			send_ascout("Command OK\n\r");
		}
		else if(strcmp((char*)debug_asciiIn+1, "log none") == 0)
		{
			ems_debug_flag=0;
			send_ascout("Command OK\n\r");
		}
		else
		{
			send_ascout("Invalid Command\n\r");
		}
		debug_asciiIn[0]='\0';
	}
}

void send_ascout(char *sdBuf)
{
	if (strlen(sdBuf)+strlen(debug_asciiOut) < MAX_ASCOUT_BUF_LEN)
	{
		strcat(debug_asciiOut, sdBuf);
	}
}

void send_error(char *sdBuf)
{
	
	send_ascout("\x1b[31m");
	send_ascout(sdBuf);
	send_ascout("\x1b[0m");
}

void send_vital_ascount(char *sdBuf)
{
	send_ascout("\x1b[33m");
	send_ascout(sdBuf);
	send_ascout("\x1b[0m");
}


