debug_print.cc
Go to the documentation of this file.
1 /* Copyright 2017 UFACTORY Inc. All Rights Reserved.
2  *
3  * Software License Agreement (BSD License)
4  *
5  * Author: Jimy Zhang <jimy92@163.com>
6  ============================================================================*/
7 #define _CRT_SECURE_NO_WARNINGS
8 
9 #include <stdarg.h>
12 
13 #define DB_FLG "[deprint ] "
14 #define PRINTF_NUM_MAX 128
15 #define log_put printf
16 
17 void print_log(const char *format, ...) {
18  char buffer[PRINTF_NUM_MAX] = { 0 };
19  va_list arg;
20  va_start(arg, format);
21  vsnprintf(buffer, PRINTF_NUM_MAX, format, arg);
22  printf("%s", buffer);
23  va_end(arg);
24 }
25 
26 void print_nvect(const char *str, double vect[], int n) {
27  print_log("%s", str);
28  for (int i = 0; i < n; ++i) { print_log("%0.3f ", vect[i]); }
29  print_log("\n");
30 }
31 
32 void print_nvect(const char *str, float *vect, int n) {
33  print_log("%s", str);
34  for (int i = 0; i < n; ++i) { print_log("%0.3f ", vect[i]); }
35  print_log("\n");
36 }
37 
38 void print_nvect(const char *str, unsigned char vect[], int n) {
39  print_log("%s", str);
40  for (int i = 0; i < n; ++i) { print_log("%d ", vect[i]); }
41  print_log("\n");
42 }
43 
44 void print_nvect(const char *str, int vect[], int n) {
45  print_log("%s", str);
46  for (int i = 0; i < n; ++i) { print_log("%d ", vect[i]); }
47  print_log("\n");
48 }
49 
50 void print_hex(const char *str, unsigned char *hex, int len) {
51  // char buf[len * 3 + 1] = {'\0'};
52  char *buf = new char[len * 3 + 1];
53  long i;
54  for (i = 0; i < len; ++i) { sprintf((char *)&buf[i * 3], "%02x ", hex[i]); }
55 
56  printf("%s %s\n", str, buf);
57  delete buf;
58 }
void print_nvect(const char *str, double vect[], int n)
Definition: debug_print.cc:26
void print_hex(const char *str, unsigned char *hex, int len)
Definition: debug_print.cc:50
void print_log(const char *format,...)
Definition: debug_print.cc:17
#define PRINTF_NUM_MAX
Definition: debug_print.cc:14


xarm_api
Author(s):
autogenerated on Sat May 8 2021 02:51:23