amiro-lld / include / VL53L0X / v1 / Api_vl53l0x / platform / src / vl53l0x_platform_log.c @ 6ebebd4d
History | View | Annotate | Download (2.82 KB)
1 | 6ebebd4d | Andre Raming | /*
|
---|---|---|---|
2 | * COPYRIGHT (C) STMicroelectronics 2015. All rights reserved.
|
||
3 | *
|
||
4 | * This software is the confidential and proprietary information of
|
||
5 | * STMicroelectronics ("Confidential Information"). You shall not
|
||
6 | * disclose such Confidential Information and shall use it only in
|
||
7 | * accordance with the terms of the license agreement you entered into
|
||
8 | * with STMicroelectronics
|
||
9 | *
|
||
10 | * Programming Golden Rule: Keep it Simple!
|
||
11 | *
|
||
12 | */
|
||
13 | |||
14 | /*!
|
||
15 | * \file VL53L0X_platform_log.c
|
||
16 | * \brief Code function defintions for Ewok Platform Layer
|
||
17 | *
|
||
18 | */
|
||
19 | |||
20 | |||
21 | |||
22 | #include <stdio.h> // sprintf(), vsnprintf(), printf() |
||
23 | |||
24 | #ifdef _MSC_VER
|
||
25 | #define snprintf _snprintf
|
||
26 | #endif
|
||
27 | |||
28 | #include "vl53l0x_i2c_platform.h" |
||
29 | #include "vl53l0x_def.h" |
||
30 | #include "vl53l0x_platform_log.h" |
||
31 | |||
32 | #define trace_print(level, ...) trace_print_module_function(TRACE_MODULE_PLATFORM, level, TRACE_FUNCTION_NONE, ##__VA_ARGS__) |
||
33 | //#define trace_i2c(...) trace_print_module_function(TRACE_MODULE_NONE, TRACE_LEVEL_NONE, TRACE_FUNCTION_I2C, ##__VA_ARGS__)
|
||
34 | |||
35 | //#define trace_i2c(ftm,...) apalDbgPrintf(ftm, ##__VA_ARGS__)
|
||
36 | |||
37 | char debug_string[VL53L0X_MAX_STRING_LENGTH_PLT];
|
||
38 | |||
39 | |||
40 | char * _trace_filename = NULL; |
||
41 | FILE *_tracefile = NULL;
|
||
42 | |||
43 | uint32_t _trace_level = TRACE_LEVEL_WARNING; |
||
44 | uint32_t _trace_modules = TRACE_MODULE_NONE; |
||
45 | uint32_t _trace_functions = TRACE_FUNCTION_NONE; |
||
46 | |||
47 | |||
48 | int32_t VL53L0X_trace_config(char *filename, uint32_t modules, uint32_t level, uint32_t functions)
|
||
49 | { |
||
50 | int STATUS = 0; |
||
51 | |||
52 | if ((_trace_filename != NULL) && (_trace_filename != filename)) |
||
53 | { |
||
54 | if ( _tracefile != NULL ) |
||
55 | { |
||
56 | fclose(_tracefile); |
||
57 | _tracefile = NULL;
|
||
58 | } |
||
59 | free(_trace_filename); |
||
60 | _trace_filename = NULL;
|
||
61 | } |
||
62 | |||
63 | if ((filename != NULL) && (_tracefile == NULL)) |
||
64 | { |
||
65 | _tracefile = fopen(filename, "w+");
|
||
66 | |||
67 | //TODO: Add time and header banner to the log file to indicate we've just opened a new log session
|
||
68 | |||
69 | if ( _tracefile != NULL ) |
||
70 | { |
||
71 | _trace_filename = (char*)malloc((strlen(filename) + 1) * sizeof(char)); |
||
72 | strcpy(_trace_filename, filename); |
||
73 | } else
|
||
74 | STATUS = 1;
|
||
75 | } |
||
76 | |||
77 | _trace_functions = functions; |
||
78 | _trace_level = level; |
||
79 | _trace_modules = modules; |
||
80 | |||
81 | return STATUS;
|
||
82 | } |
||
83 | |||
84 | // error if enabled_log us enabled
|
||
85 | void trace_print_module_function(uint32_t module, uint32_t level, uint32_t function, const char *format, ...) |
||
86 | { |
||
87 | if ( ((level <=_trace_level) && ((module & _trace_modules) > 0)) |
||
88 | || ((function & _trace_functions) > 0) )
|
||
89 | { |
||
90 | va_list arg_list; |
||
91 | char message[VL53L0X_MAX_STRING_LENGTH_PLT];
|
||
92 | |||
93 | va_start(arg_list, format); |
||
94 | vsnprintf(message, VL53L0X_MAX_STRING_LENGTH_PLT, format, arg_list); |
||
95 | |||
96 | va_end(arg_list); |
||
97 | |||
98 | //apalDbgPrintf(message);
|
||
99 | |||
100 | // if (_tracefile != NULL)
|
||
101 | // fprintf(_tracefile, message);
|
||
102 | // else
|
||
103 | // printf(message);
|
||
104 | } |
||
105 | } |