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