Home | History | Annotate | Download | only in util
      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 formatted strings to Nanohub.
     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 #ifdef GCC_DEBUG_LOG
     26 # include <stdio.h>
     27 # define CAL_DEBUG_LOG(tag, fmt, ...) \
     28    printf("%s " fmt "\n", tag, ##__VA_ARGS__);
     29 #elif _OS_BUILD_
     30 # include <seos.h>
     31 # ifndef LOG_FUNC
     32 #  define LOG_FUNC(level, fmt, ...) osLog(level, fmt, ##__VA_ARGS__)
     33 # endif  // LOG_FUNC
     34 # define LOGD_TAG(tag, fmt, ...) \
     35    LOG_FUNC(LOG_DEBUG, "%s " fmt "\n", tag, ##__VA_ARGS__)
     36 # define CAL_DEBUG_LOG(tag, fmt, ...) \
     37    osLog(LOG_DEBUG, "%s " fmt, tag, ##__VA_ARGS__);
     38 #else  // _OS_BUILD_
     39 # include <chre.h>
     40 # define CAL_DEBUG_LOG(tag, fmt, ...) \
     41    chreLog(CHRE_LOG_INFO, "%s " fmt, tag, ##__VA_ARGS__)
     42 #endif  // GCC_DEBUG_LOG
     43 
     44 #ifdef __cplusplus
     45 extern "C" {
     46 #endif
     47 
     48 // Using this macro because floorf() is not currently implemented by the Nanohub
     49 // firmware.
     50 #define CAL_FLOOR(x) ((int)(x) - ((x) < (int)(x)))  // NOLINT
     51 
     52 // Macro used to print floating point numbers with a specified number of digits.
     53 #define CAL_ENCODE_FLOAT(x, num_digits) \
     54   ((x < 0) ? "-" : ""),                 \
     55   (int)CAL_FLOOR(fabsf(x)), (int)((fabsf(x) - CAL_FLOOR(fabsf(x))) * powf(10, num_digits))  // NOLINT
     56 
     57 #ifdef __cplusplus
     58 }
     59 #endif
     60 
     61 #endif  // LOCATION_LBS_CONTEXTHUB_NANOAPPS_CALIBRATION_UTIL_CAL_LOG_H_
     62