#include "DBG.h"
#include <stdarg.h>

long long SysTick_Now = 0, SysTick_Last = 0, SysTick_Diff = 0;
char  Dbg_Buffer[100];

uint32_t Dbg_Switch = (DBG_OPT_ActCond_STATUS << DBG_BIT_ActCond_STATUS_bit) + \
        (DBG_OPT_MQTT_STATUS << DBG_BIT_MQTT_STATUS_bit) + \
				(DBG_OPT_Debug_STATUS << DBG_BIT_Debug_STATUS_bit) + \
				(DBG_OPT_LOGIC_STATUS << DBG_BIT_LOGIC_STATUS_bit) + \
				(DBG_OPT_DEVICE_STATUS << DBG_BIT_DEVICE_STATUS_bit) + \
				(DBG_OPT_NET_STATUS << DBG_BIT_NET_STATUS_bit) + \
				(DBG_OPT_SYS_STATUS << DBG_BIT_SYS_STATUS_bit);

/*******************************************************************************
* Function Name  : Dbg_NoTick_Print 
* Description    : DEBUG调试信息输出 - 不带时间戳打印
* Input          : 
* Return         :
*******************************************************************************/
void Dbg_NoTick_Print(int DbgOptBit ,const char *cmd, ...)
{
	if (DBG_LOG_EN && (Dbg_Switch & (1 << DbgOptBit ))) 
    {
		SysTick_Now  = SysTick_1ms;
        SysTick_Diff = SysTick_Now - SysTick_Last ;
        SysTick_Last = SysTick_Now;
		
        va_list args;       //定义一个va_list类型的变量，用来储存单个参数
        va_start(args,cmd); //使args指向可变参数的第一个参数
        vprintf(cmd,args);  //必须用vprintf等带V的
        va_end(args);       //结束可变参数的获取
    }
}

void Dbg_Print(int DbgOptBit ,const char *cmd, ...)
{
    if (DBG_LOG_EN && (Dbg_Switch & (1 << DbgOptBit ))) 
    {
        SysTick_Now  = SysTick_1ms;
        SysTick_Diff = SysTick_Now - SysTick_Last ;
        SysTick_Last = SysTick_Now;
        sprintf(Dbg_Buffer,"%8.lld [%6.lld]: ",SysTick_Now,SysTick_Diff);
        DBG_Printf("%s",Dbg_Buffer);
        va_list args;       //定义一个va_list类型的变量，用来储存单个参数
        va_start(args,cmd); //使args指向可变参数的第一个参数
        vprintf(cmd,args);  //必须用vprintf等带V的
        va_end(args);       //结束可变参数的获取        
    }
}

void Dbg_Println(int DbgOptBit ,const char *cmd, ...)
{
    if (DBG_LOG_EN && (Dbg_Switch & (1 << DbgOptBit ))) 
    {
        SysTick_Now  = SysTick_1ms;
        SysTick_Diff = SysTick_Now - SysTick_Last;		//上一次打印时间差
        SysTick_Last = SysTick_Now;
        sprintf(Dbg_Buffer,"%8.lld [%6.lld]: ",SysTick_Now,SysTick_Diff);
        DBG_Printf("%s",Dbg_Buffer);
        va_list args;       //定义一个va_list类型的变量，用来储存单个参数
        va_start(args,cmd); //使args指向可变参数的第一个参数
        vprintf(cmd,args);  //必须用vprintf等带V的
        va_end(args);       //结束可变参数的获取
        DBG_Printf("\n\r");
        
    }
}

void Dbg_Print_Buff(int DbgOptBit ,const char *cmd ,uint8_t *buff,uint32_t len)
{
    if (DBG_LOG_EN && (Dbg_Switch & (1 << DbgOptBit ))) 
    {
        SysTick_Now  = SysTick_1ms;
        SysTick_Diff = SysTick_Now - SysTick_Last;		//上一次打印时间差
        SysTick_Last = SysTick_Now;
        sprintf(Dbg_Buffer,"%8.lld [%6.lld]: ",SysTick_Now,SysTick_Diff);
        DBG_Printf("%s%s",Dbg_Buffer,cmd);
		for(uint32_t i=0;i<len;i++)
		{
			DBG_Printf("%02X ",buff[i]);
		}
        DBG_Printf("\n\r");
    }
}









