因为串口打印速度慢,调试程序会影响程序的真正效果,所以引入网络打印
debug_manager.h
#ifndef _DEBUG_MANAGER_H #define _DEBUG_MANAGER_H #define APP_EMERG "<0>" /* system is unusable */ #define APP_ALERT "<1>" /* action must be taken immediately */ #define APP_CRIT "<2>" /* critical conditions */ #define APP_ERR "<3>" /* error conditions */ #define APP_WARNING "<4>" /* warning conditions */ #define APP_NOTICE "<5>" /* normal but significant condition */ #define APP_INFO "<6>" /* informational */ #define APP_DEBUG "<7>" /* debug-level messages */ #define DEFAULT_DBGLEVEL 4 typedef struct DebugOpr { char *name; int isCanUse; int (*DebugInit)(void); int (*DebugExit)(void); int (*DebugPrint)(char *strData); struct DebugOpr *ptNext; }T_DebugOpr, *PT_DebugOpr; int RegisterDebugOpr(PT_DebugOpr ptDebugOpr); void ShowDebugOpr(void); PT_DebugOpr GetDebugOpr(char *pcName); int SetDbgLevel(char *strBuf); int SetDbgChanel(char *strBuf); int DebugInit(void); int DebugPrint(const char *pcFormat, ...); int InitDebugChanel(void); int NetPrintInit(void); int StdoutInit(void); #endif /* _DEBUG_MANAGER_H */
debug_manager.c
#include <config.h> #include <debug_manager.h> #include <string.h> #include <stdio.h> #include <stdarg.h> static PT_DebugOpr g_ptDebugOprHead; static int g_iDbgLevelLimit = 8; //允许所有级别打印信息 int RegisterDebugOpr(PT_DebugOpr ptDebugOpr) { PT_DebugOpr ptTmp; if (!g_ptDebugOprHead) { g_ptDebugOprHead = ptDebugOpr; ptDebugOpr->ptNext = NULL; } else { ptTmp = g_ptDebugOprHead; while (ptTmp->ptNext) { ptTmp = ptTmp->ptNext; } ptTmp->ptNext = ptDebugOpr; ptDebugOpr->ptNext = NULL; } return 0; } void ShowDebugOpr(void) { int i = 0; PT_DebugOpr ptTmp = g_ptDebugOprHead; while (ptTmp) { printf("%02d %s ", i++, ptTmp->name); ptTmp = ptTmp->ptNext; } } PT_DebugOpr GetDebugOpr(char *pcName) { PT_DebugOpr ptTmp = g_ptDebugOprHead; while (ptTmp) { if (strcmp(ptTmp->name, pcName) == 0) { return ptTmp; } ptTmp = ptTmp->ptNext; } return NULL; } /* strBuf = "dbglevel=<0-7>" */ int SetDbgLevel(char *strBuf) { g_iDbgLevelLimit = strBuf[9] - '0'; return 0; } /* *stdout = 0 :关闭stdout打印 *stdout = 1 :打开staout打印 *netprint = 0 :关闭netprint打印 *netprint = 1 :打开netprint打印 */ int SetDbgChanel(char *strBuf) { char *pStrTmp; char strName[100]; PT_DebugOpr ptTmp; pStrTmp = strchr(strBuf,'='); //返回指向‘=’的指针 if(!pStrTmp) { return -1; } else { strncpy(strName, strBuf, pStrTmp-strBuf); strName[pStrTmp-strBuf] = '