/*----------------------------------------------------------------
* FileName    : bms_debug.h
* Create Date : 2014-02-09
*
*---------------------------------------------------------------*/

#ifndef BMS_DEBUG_H__
#define BMS_DEBUG_H__

#include "toolkit.h"


/*-------------------------------------------------------------------------------*/

#ifdef  WIN32
#define Debug_Printf printf
#else
#define Debug_Printf printf

/*#define Debug_Printf printf*/
void UsartPrintf(char *fmt, ...);
#endif

#define __DEBUG_MODE

#define LOG_CLOSE 0u
#define LOG_ERROR 1u
#define LOG_WAEN  2u
#define LOG_INFO  3u
#define LOG_DEBUG 4u
#define LOG_DUMP  5u
#define LOG_TRACE 6u

#define LOG_SWITCH_FLAG_DEBUG       (0x01u)
#define LOG_SWITCH_FLAG_CAN         (0x01u<<1)
#define LOG_SWITCH_FLAG_CANOPEN     (0x01u<<2)
#define LOG_SWITCH_FLAG_485         (0x01u<<3)
#define LOG_SWITCH_FLAG_TIMER       (0x01u<<4)
#define LOG_SWITCH_FLAG_MMC         (0x01u<<5)
#define LOG_SWITCH_FLAG_DATA_PROC   (0x01u<<6)
#define LOG_SWITCH_FLAG_HAEDWARE    (0x01u<<7)
#define LOG_SWITCH_FLAG_DB          (0x01u<<8)
#define LOG_SWITCH_FLAG_MODBUS      (0x01u<<9)
#define LOG_SWITCH_FLAG_CANRBUS     (0x01u<<10)
#define LOG_SWITCH_FLAG_DATAHUB     (0x01u<<11)
#define LOG_SWITCH_FLAG_MAINCTRL    (0x01u<<12)
#define LOG_SWITCH_FLAG_SOC         (0x01u<<13)
#define LOG_SWITCH_FLAG_SLAVE       (0x01u<<14)
#define LOG_SWITCH_FLAG_BALANCE     (0x01u<<15)
#define LOG_SWITCH_FLAG_CURRENT     (0x01u<<16)
#define LOG_SWITCH_FLAG_HVB         (0x01u<<17)
#define LOG_SWITCH_FLAG_PCS         (0x01u<<18)
#define LOG_SWITCH_FLAG_UPDATE      (0x01u<<19)
#define LOG_SWITCH_FLAG_BALANCE_ALG (0x01u<<20)
#define LOG_SWITCH_FLAG_STRATEGY    (0x01u<<21)
#define LOG_SWITCH_FLAG_COMPROL     (0x01u<<22)
#define LOG_SWITCH_FLAG_STORAGE     (0x01u<<23)
#define LOG_SWITCH_FLAG_KEY         (0x01u<<24)
#define LOG_SWITCH_FLAG_PROTOCOL    (0x01u<<25)
#define LOG_SWITCH_FLAG_ALARM       (0x01u<<26)
#define LOG_SWITCH_FLAG_SAMPLE      (0x01u<<27)
#define LOG_SWITCH_FLAG_CHARGER     (0x01u<<28)
#define LOG_SWITCH_FLAG_PROJECT_FUNC (0x01u<<29)
#define LOG_SWITCH_FLAG_LCC          (0x01u<<30)
#define LOG_SWITCH_FLAG_WAKEUP      (0x01u<<31)

extern uint32_t g_debugLevel;
extern uint32_t g_debugMask;
extern uint32_t g_printEnable;

#ifdef __DEBUG_MODE

#ifndef WIN32
#define BMS_RAW_PRINT(switchFalg, msg, arg...) \
    do{ \
    if((switchFalg&g_debugMask)>0u)\
      {Debug_Printf(msg, ##arg);} \
    }while(0)

#define BMS_LOG_ERROR(switchFalg, msg, arg...) \
    do{ \
        if(g_debugLevel >= LOG_ERROR){ \
            if((switchFalg&g_debugMask)>0u){Debug_Printf(msg, ##arg);} \
        }\
    }while(0)

#define BMS_LOG_WAEN(switchFalg, msg, arg...)\
    do{ \
        if(g_debugLevel >= LOG_WAEN){ \
            if((switchFalg&g_debugMask)>0u){Debug_Printf(msg, ##arg);} \
        }\
    }while(0)

#define BMS_LOG_INFO(switchFalg, msg, arg...) \
    do{ \
        if(g_debugLevel >= LOG_INFO){ \
            if((switchFalg&g_debugMask)>0u){Debug_Printf(msg, ##arg);} \
        }\
    }while(0)

#define BMS_LOG_DEBUG(switchFalg, msg, arg...) \
    do{ \
        if(g_debugLevel >= LOG_DEBUG){ \
            if((switchFalg&g_debugMask)>0u){Debug_Printf(msg, ##arg);} \
        }\
    }while(0)

#define BMS_LOG_TRACE(switchFalg, msg, arg...)  \
    do{ \
        if(g_debugLevel >= LOG_TRACE){ \
            if((switchFalg&g_debugMask)>0u){Debug_Printf(msg, ##arg);} \
        }\
    }while(0)

#define BMS_LOG_DUMP(switchFalg, msg, arg...)  \
    do{ \
        if(g_debugLevel >= LOG_DUMP){ \
            if((switchFalg&g_debugMask)>0u){Debug_Printf(msg, ##arg);} \
        }\
    }while(0)
#else
#ifdef UNIT_TEST
#define BMS_RAW_PRINT(switchFalg, msg, ...)
#define BMS_LOG_ERROR(switchFalg, msg, ...)
#define BMS_LOG_WAEN(switchFalg, msg, ...)
#define BMS_LOG_INFO(switchFalg, msg, ...)
#define BMS_LOG_DEBUG(switchFalg, msg, ...)
#define BMS_LOG_TRACE(switchFalg, msg, ...)
#define BMS_LOG_DUMP(switchFalg, msg, ...)
#else
#define BMS_RAW_PRINT(switchFalg, msg, ...) \
    do{ \
    if((switchFalg&g_debugMask)>0u)Debug_Printf(msg, ##__VA_ARGS__); \
    }while(0)

#define BMS_LOG_ERROR(switchFalg, msg, ...) \
    do{ \
        if(g_debugLevel >= LOG_ERROR){ \
            if((switchFalg&g_debugMask)>0u)Debug_Printf(msg, ##__VA_ARGS__); \
        }\
    }while(0)

#define BMS_LOG_WAEN(switchFalg, msg, ...)\
    do{ \
        if(g_debugLevel >= LOG_WAEN){ \
            if((switchFalg&g_debugMask)>0u)Debug_Printf(msg, ##__VA_ARGS__); \
        }\
    }while(0)

#define BMS_LOG_INFO(switchFalg, msg, ...) \
    do{ \
        if(g_debugLevel >= LOG_INFO){ \
            if((switchFalg&g_debugMask)>0u)Debug_Printf(msg, ##__VA_ARGS__); \
        }\
    }while(0)

#define BMS_LOG_DEBUG(switchFalg, msg, ...) \
    do{ \
        if(g_debugLevel >= LOG_DEBUG){ \
            if((switchFalg&g_debugMask)>0u)Debug_Printf(msg, ##__VA_ARGS__); \
        }\
    }while(0)

#define BMS_LOG_TRACE(switchFalg, msg, ...)  \
    do{ \
        if(g_debugLevel >= LOG_TRACE){ \
            if((switchFalg&g_debugMask)>0u)Debug_Printf(msg, ##__VA_ARGS__); \
        }\
    }while(0)

#define BMS_LOG_DUMP(switchFalg, msg, ...)  \
    do{ \
        if(g_debugLevel >= LOG_DUMP){ \
            if((switchFalg&g_debugMask)>0u)Debug_Printf(msg, ##__VA_ARGS__); \
        }\
    }while(0)
#endif
#endif

#else
#define BMS_RAW_PRINT(switchFalg, msg, arg...)
#define BMS_LOG_ERROR(switchFalg, msg, arg...)
#define BMS_LOG_WAEN(switchFalg, msg, arg...)
#define BMS_LOG_INFO(switchFalg, msg, arg...)
#define BMS_LOG_DEBUG(switchFalg, msg, arg...)
#define BMS_LOG_TRACE(switchFalg, msg, arg...)
#define BMS_LOG_DUMP(switchFalg, msg, arg...)

#endif


#endif /* __BMS_DEBUG_H__ */

