• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 ///////////////////////////////////////////////////////////////
18 /*
19  * Logging macros for printing user-debug messages.
20  */
21 ///////////////////////////////////////////////////////////////
22 #ifndef LOCATION_LBS_CONTEXTHUB_NANOAPPS_CALIBRATION_UTIL_CAL_LOG_H_
23 #define LOCATION_LBS_CONTEXTHUB_NANOAPPS_CALIBRATION_UTIL_CAL_LOG_H_
24 
25 // clang-format off
26 #ifdef GCC_DEBUG_LOG
27 # include <stdio.h>
28 # define CAL_DEBUG_LOG(tag, fmt, ...) \
29    printf("%s " fmt "\n", tag, ##__VA_ARGS__);
30 #elif _OS_BUILD_
31 # include <seos.h>
32 # ifndef LOG_FUNC
33 #  define LOG_FUNC(level, fmt, ...) osLog(level, fmt, ##__VA_ARGS__)
34 # endif  // LOG_FUNC
35 # define LOGD_TAG(tag, fmt, ...) \
36    LOG_FUNC(LOG_DEBUG, "%s " fmt "\n", tag, ##__VA_ARGS__)
37 # define CAL_DEBUG_LOG(tag, fmt, ...) \
38    osLog(LOG_DEBUG, "%s " fmt, tag, ##__VA_ARGS__);
39 #elif NANOHUB_DEBUG_LOG
40 # include <chre.h>
41 # define CAL_DEBUG_LOG(tag, fmt, ...) \
42    chreLog(CHRE_LOG_INFO, "%s " fmt, tag, ##__VA_ARGS__)
43 #else
44 // CHRE/SLPI Nanoapp Logging.
45 # include "chre/util/nanoapp/log.h"
46 # ifndef LOG_TAG
47 #  define LOG_TAG ""
48 # endif  // LOG_TAG
49 # define CAL_DEBUG_LOG(tag, format, ...) \
50    LOGI("%s " format, tag, ##__VA_ARGS__)
51 #endif  // GCC_DEBUG_LOG
52 // clang-format on
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 // Floor macro implementation for platforms that do not supply the standard
59 // floorf() math function.
60 #define CAL_FLOOR(x) ((int)(x) - ((x) < (int)(x)))  // NOLINT
61 
62 /*
63  * On some embedded software platforms numerical string formatting is not fully
64  * supported. Defining CAL_NO_FLOAT_FORMAT_STRINGS will enable a workaround that
65  * prints floating-point values having a specified number of digits using the
66  * CAL_ENCODE_FLOAT macro.
67  *   Examples:
68  *     - Nanohub does not support floating-point format strings.
69  *     - CHRE/SLPI allows %.Xf for printing float values.
70  */
71 #ifdef CAL_NO_FLOAT_FORMAT_STRINGS
72 // Macro used to print floating point numbers with a specified number of digits.
73 # define CAL_ENCODE_FLOAT(x, num_digits)           \
74   ((x < 0) ? "-" : ""), (int)CAL_FLOOR(fabsf(x)),  \
75       (int)((fabsf(x) - CAL_FLOOR(fabsf(x))) *     \
76             powf(10, num_digits))  // NOLINT
77 
78 // Helper definitions for CAL_ENCODE_FLOAT to specify the print format with
79 // desired significant digits.
80 # define CAL_FORMAT_3DIGITS "%s%d.%03d"
81 # define CAL_FORMAT_6DIGITS "%s%d.%06d"
82 # define CAL_FORMAT_3DIGITS_TRIPLET "%s%d.%03d, %s%d.%03d, %s%d.%03d"
83 # define CAL_FORMAT_6DIGITS_TRIPLET "%s%d.%06d, %s%d.%06d, %s%d.%06d"
84 #else
85 // Pass-through when float string formatting (e.g., %.6f) is available.
86 # define CAL_ENCODE_FLOAT(x, num_digits) (x)
87 
88 // Float string formatting helpers.
89 # define CAL_FORMAT_3DIGITS "%.3f"
90 # define CAL_FORMAT_6DIGITS "%.6f"
91 # define CAL_FORMAT_3DIGITS_TRIPLET "%.3f, %.3f, %.3f"
92 # define CAL_FORMAT_6DIGITS_TRIPLET "%.6f, %.6f, %.6f"
93 #endif  // CAL_NO_FLOAT_FORMAT_STRINGS
94 
95 #ifdef __cplusplus
96 }
97 #endif
98 
99 #endif  // LOCATION_LBS_CONTEXTHUB_NANOAPPS_CALIBRATION_UTIL_CAL_LOG_H_
100