1 /* 2 Copyright (c) 2021 Fraunhofer AISEC. See the COPYRIGHT 3 file at the top-level directory of this distribution. 4 5 Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or 6 http://www.apache.org/licenses/LICENSE-2.0> or the MIT license 7 <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your 8 option. This file may not be copied, modified, or distributed 9 except according to those terms. 10 */ 11 12 #ifndef PRINT_UTIL_H 13 #define PRINT_UTIL_H 14 15 #include <stdint.h> 16 #include <stdio.h> 17 18 /** 19 *@brief Prints an array for debug purposes. 20 *@param[in] in_data The array to be printed. 21 *@param in_len The length of the array. 22 */ 23 void print_array(const uint8_t *in_data, uint32_t in_len); 24 25 /** 26 * @brief In case of an error this function prints where 27 * the error occurred. 28 * 29 * @param error_code The error code to be printed. 30 * @param file_name The file name where the error occurred. 31 * @param line The line at which the error occurred. 32 */ 33 void handle_runtime_error(int error_code, const char *file_name, 34 const int line); 35 36 /** 37 * @brief In case of an error in a function belonging to 38 * an external library this function prints where 39 * the error occurred. 40 * 41 * @param error_code The error code to be printed. 42 * @param file_name The file name where the error occurred. 43 * @param line The line at which the error occurred. 44 */ 45 void handle_external_runtime_error(int error_code, const char *file_name, 46 const int line); 47 48 #ifdef DEBUG_PRINT 49 #define RED "\x1B[31m" 50 #define RESET "\033[0m" 51 static const char transport_deinit_message[] = { 52 RESET "Transport deinitialized at %s:%d\n\n" 53 }; 54 static const char runtime_error_message[] = { 55 RED "Runtime error: code %d at %s:%d\n\n" RESET 56 }; 57 static const char external_runtime_error_message[] = { 58 RED "External lib runtime error: code %d at %s:%d\n\n" RESET 59 }; 60 61 #define PRINT_ARRAY(msg, a, a_len) \ 62 printf(msg); \ 63 print_array(a, a_len); 64 #define PRINT_MSG(msg) printf(msg); 65 #define PRINTF(f_, ...) printf((f_), ##__VA_ARGS__); 66 #else 67 #define PRINT_ARRAY(msg, a, a_len) {}; 68 #define PRINT_MSG(msg) {}; 69 #define PRINTF(f_, ...) {}; 70 #endif 71 72 #endif 73