102 lines
2.7 KiB
C
102 lines
2.7 KiB
C
/****************************************************************************
|
|
|
|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
|
|
|
|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
|
|
be copied by any method or incorporated into another program without
|
|
the express written consent of Aerospace C.Power. This Information or any portion
|
|
thereof remains the property of Aerospace C.Power. The Information contained herein
|
|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
|
|
liability for its use in any way and conveys no license or title under
|
|
any patent or copyright and makes no representation or warranty that this
|
|
Information is free from patent or copyright infringement.
|
|
|
|
****************************************************************************/
|
|
|
|
#include <windows.h>
|
|
|
|
/* os shim includes */
|
|
#include "os_types.h"
|
|
#include "os_lock.h"
|
|
|
|
/* common includes */
|
|
#include "iot_module.h"
|
|
#include "iot_io.h"
|
|
|
|
extern uint8_t g_ucMACAddress[6];
|
|
os_mutex_h plc_log_mutex = NULL;
|
|
char __plc_log_buf[520];
|
|
char *plc_log_buf;
|
|
extern void vLoggingPrintf(const char *pcFormatString, ...);
|
|
|
|
uint8_t g_print_enable = 0;
|
|
uint8_t g_app_print_enable = 1;
|
|
|
|
void cpl_utils_init()
|
|
{
|
|
if (plc_log_mutex == NULL) {
|
|
plc_log_mutex = os_create_mutex(CPL_UTILS_MID);
|
|
iot_sprintf(__plc_log_buf, "iotelic-%02x:%02x", g_ucMACAddress[4],
|
|
g_ucMACAddress[5]);
|
|
__plc_log_buf[13] = ' ';
|
|
__plc_log_buf[519] = '\0';
|
|
plc_log_buf = &__plc_log_buf[14];
|
|
}
|
|
}
|
|
|
|
|
|
#if IOT_PRINTF_DEBUG
|
|
int32_t iot_printf(const char *fmt, ...)
|
|
{
|
|
if (g_print_enable == 0)
|
|
return 0;
|
|
|
|
if (plc_log_mutex) {
|
|
va_list args;
|
|
os_acquire_mutex(plc_log_mutex);
|
|
va_start(args, fmt);
|
|
iot_vsnprintf(plc_log_buf, 500, fmt, args);
|
|
OutputDebugStringA(__plc_log_buf);
|
|
// vLoggingPrintf("%s", plc_log_buf);
|
|
va_end(args);
|
|
os_release_mutex(plc_log_mutex);
|
|
}
|
|
return 0;
|
|
}
|
|
#endif
|
|
|
|
int32_t iot_cus_printf(const char *fmt, ...)
|
|
{
|
|
if (g_app_print_enable == 0)
|
|
return 0;
|
|
|
|
if (plc_log_mutex) {
|
|
va_list args;
|
|
os_acquire_mutex(plc_log_mutex);
|
|
va_start(args, fmt);
|
|
iot_vsnprintf(plc_log_buf, 500, fmt, args);
|
|
OutputDebugStringA(__plc_log_buf);
|
|
// vLoggingPrintf("%s", plc_log_buf);
|
|
va_end(args);
|
|
os_release_mutex(plc_log_mutex);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int32_t __iot_printf(uint8_t dummy, ...)
|
|
{
|
|
(void)dummy;
|
|
return 0;
|
|
}
|
|
|
|
void iot_print_config(bool_t enable)
|
|
{
|
|
g_print_enable = enable;
|
|
}
|
|
|
|
void iot_cus_print_config(bool_t enable)
|
|
{
|
|
g_app_print_enable = enable;
|
|
}
|
|
|