#ifndef DEBUG_H
#define DEBUG_H
#include <stdio.h>
//Usage:
//just include this file and define MYDEBUG_PART like
//
//int MYDEBUG_PART=MYDEBUG_CAN
//
//in the program use the command by
//mydebug(can, "test %d with %s\n", 100, "hello,world");
//mydebug_can("test %d with %s\n", 100, "hello,world");
//#define MYDEBUG_PREFIX "--wuyq:can--"
#define MYDEBUG_PREFIX __FILE__
#define MYDEBUG_OFF 0
#define MYDEBUG_CAN 1
#define MYDEBUG_GPS_ON 2
#define MYDEBUG_GSM 3
#ifdef DEBUG_CAN_ON
#define mydebug_can(msg...) \
do{ \
if (MYDEBUG_CAN>=MYDEBUG_OFF) { \
printf(MYDEBUG_PREFIX msg); \
} \
}while(0)
#else
#define mydebug_can(msg...)
#endif
#define mydebug_gps(msg...) \
do{ \
if (MYDEBUG_GPS_ON>=MYDEBUG_OFF) { \
printf(MYDEBUG_PREFIX msg); \
} \
else{\
/*空函数*/\
} \
}while(0)
#define mydebug_gsm(msg...) \
do{ \
if (MYDEBUG_GSM>=MYDEBUG_OFF) { \
printf(MYDEBUG_PREFIX msg); \
} \
}while(0)
#define mydebug(part, msg...) mydebug_##part(msg)
#endif
gps.c:
#include "debug.h"
int main()
{
mydebug(gps, "gps program is running\n");
mydebug_gps(" hello gps.c----\n");
return 0;
}
#include "debug.h"
int main()
{
mydebug_can(" hello can.c!!!\n");
return 0;
}
gcc - can.c -DDEBUG_CAN_ON -o can