📄 debug.h
字号:
#ifndef _DEBUG_
#define _DEBUG_ 1
#include <stdarg.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdint.h>
#include <sys/file.h>
#include <sys/vfs.h>
#include <sys/stat.h>
#include <ctype.h>
#define DEBUG_MODE_UART 1
#define DEBUG_MODE_NET 2
#define DEBUG_MODE_NONE 0
#define DEBUG_MODE_SET DEBUG_MODE_UART
#define DEBUG_NORMALNFO debug_normal
#define DEBUG_INFO_ARGV debug_showargv
/*
DEBUG_NORMALNFO("%s: start main, pid=%d, ppid=%d.\t%s[%d]%s\n", argv[0],getpid(),getppid(),__FILE__,__LINE__,__FUNCTION__);
DEBUG_INFO_ARGV(argc,argv);
*/
#if(DEBUG_MODE_SET == DEBUG_MODE_NONE)
static void debug_normal (const char* va, ...)
{
}
static void debug_showargv(int argc, char** argv)
{
}
#elif(DEBUG_MODE_SET == DEBUG_MODE_NET)
static void debug_normal (const char* va, ...)
{
int info_udp_socket_fd=0;
struct sockaddr_in info_udp_sout;
int info_opt;
info_opt = 1;
memset(&info_udp_sout,0,sizeof(info_udp_sout));
info_udp_sout.sin_family = AF_INET;
info_udp_sout.sin_addr.s_addr=INADDR_BROADCAST;
info_udp_sout.sin_port = htons(8888);
info_udp_socket_fd=(int)socket(AF_INET,SOCK_DGRAM,0);
if(info_udp_socket_fd == -1)
{
return;
}
setsockopt(info_udp_socket_fd,SOL_SOCKET,SO_BROADCAST,(char*)&info_opt,sizeof(info_opt));
char info[1024];
va_list ap;
va_start(ap, va);
vsprintf(info,va, ap);
sendto(info_udp_socket_fd,info,strlen(info),0,(struct sockaddr *)&info_udp_sout,sizeof(info_udp_sout));
va_end(ap);
shutdown(info_udp_socket_fd,SHUT_RDWR);
close(info_udp_socket_fd);
}
static void debug_showargv(int argc, char** argv)
{
char info[1024];
int j=0;
int i;
j+=sprintf(info,"\t\targv in main(): ");
for (i=0;i<argc;i++)
j+=sprintf(info+j," %s",argv[i]);
strcat(info,"\n");
debug_normal(info);
}
#elif(DEBUG_MODE_SET == DEBUG_MODE_UART)
static void debug_normal (const char* va, ...)
{
char info[1024];
va_list ap;
va_start(ap, va);
vsprintf(info,va, ap);
printf("%s",info);
va_end(ap);
}
static void debug_showargv(int argc, char** argv)
{
char info[1024];
int j=0;
int i;
j+=sprintf(info,"\t\targv in main(): ");
for (i=0;i<argc;i++)
j+=sprintf(info+j," %s",argv[i]);
strcat(info,"\n");
debug_normal(info);
}
#endif
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -