#include "log.h" #include "platform.h" #include "common.h" #include #include #include #include "pt-timer.h" #include "app.h" static char logToOutterFlag=0;//默认不打log,发RT+ROUTE=0,1 开启打印LOG static char logToUsbFlag=1; //#define NEED_TIMESTEMP //打印添加时间 #if defined NEED_TIMESTEMP #define HEAD_PART_LEN (35+2) //根据以下的snprintf(pinfo 的长度计算 再加回车换行 char timestp[25]; char *timeStmp(void){ MY_CLOCK myclock; getMyClock(&myclock); snprintf(timestp, sizeof(timestp),"%02d-%02d-%02d %02d:%02d:%02d", myclock.year%100, myclock.month, myclock.day, myclock.hour, myclock.min, myclock.sec); return timestp; } #else #define HEAD_PART_LEN (16+2) //根据以下的snprintf(pinfo 的长度计算 再加回车换行 #endif #define MAX_LOG_INFO_LEN 200 //日志打印的用户段最大有效长度 void wjlprintf(const char *level,const char *format,...){ va_list vags; char pinfo[MAX_LOG_INFO_LEN+HEAD_PART_LEN],info[MAX_LOG_INFO_LEN]; if(TRUE==app.tmMode || TRUE==app.tgMode) return;//TM/TG模式下不打印 if(logToOutterFlag==0 && logToUsbFlag==0) return;//禁止打印直接返回,省事 #if defined NEED_TIMESTEMP snprintf(pinfo, sizeof(pinfo), "<%s>[%s %03d]:",level,timeStmp(),getSysTick()%1000); //"error[20-20-20 20:20:20 000]:" max 29, make it 35 is safe #else snprintf(pinfo, sizeof(pinfo), "[%s]",level);//"Hlog info/warn/error" max 10, make it 16 is safe #endif va_start(vags, format); vsnprintf(info, sizeof(info),format, vags); va_end(vags); strcat(pinfo, info); strcat(pinfo,"\r\n"); if(0!=logToUsbFlag) ON_SHOW_INFO(pinfo); #ifndef ENABLE_UART1_MCU_CMD_ONLY if(0!=logToOutterFlag) logToOutter(pinfo); #endif #ifdef ENABLE_USB_PORT if(0!=logToOutterFlag) logToOutter(pinfo); #endif #if defined LOG_TO_WIN fflush(stdout); #endif } void setLogRoute(char typeUsb, char typeOutter){ logToOutterFlag=typeOutter; logToUsbFlag=typeUsb; }