log.c 952 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "includes.h"
  2. void ologShow(char level, char fa, char * fmt, ...){
  3. static char info[512];
  4. static nwy_osiMutex_t *echo_mutex = NULL;
  5. va_list va;
  6. int len,i;
  7. char buf[10];
  8. if(sutApp.authReady==0) return;
  9. if(usb_log_status==false) return;
  10. if(NULL==echo_mutex) echo_mutex = nwy_create_mutex();
  11. if(NULL==echo_mutex) return;
  12. nwy_lock_mutex(echo_mutex, 0);
  13. va_start(va, fmt);
  14. vsnprintf(info, sizeof(info), fmt, va);
  15. va_end(va);
  16. //输出
  17. memset(buf,0,sizeof(buf));
  18. switch(level){
  19. case LINFO:strcpy(buf, "[AP_INFO]");break;
  20. case LWARN:strcpy(buf, "[AP_WARN]");break;
  21. case LERR:strcpy(buf, "[AP_ERR]");break;
  22. default:break;
  23. }
  24. len=strlen(buf);
  25. if(len>0) nwy_usb_serial_send(buf,len);
  26. len=strlen(info);
  27. i=0;
  28. while(1){
  29. int txsize = nwy_usb_serial_send(info+i, len-i);
  30. if(txsize<=0) break;
  31. i += txsize;
  32. if(i<len) nwy_sleep(10);
  33. else break;
  34. }
  35. if(fa) nwy_usb_serial_send("\r\n", 2);
  36. nwy_unlock_mutex(echo_mutex);
  37. }