1 /** @file 2 High-level utility functions for decoders. 3 4 Copyright (C) 2018 Christian Zuckschwerdt 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at your option) any later version. 10 */ 11 12 #ifndef INCLUDE_DECODER_UTIL_H_ 13 #define INCLUDE_DECODER_UTIL_H_ 14 15 #include <stdarg.h> 16 #include "bitbuffer.h" 17 #include "data.h" 18 #include "r_device.h" 19 20 #if defined _MSC_VER || defined ESP32 // Microsoft Visual Studio or ESP32 21 // MSC and ESP32 have something like C99 restrict as __restrict 22 #ifndef restrict 23 #define restrict __restrict 24 #endif 25 #endif 26 // Defined in newer <sal.h> for MSVC. 27 #ifndef _Printf_format_string_ 28 #define _Printf_format_string_ 29 #endif 30 31 /// Create a new r_device, copy from dev_template if not NULL. 32 r_device *create_device(r_device *dev_template); 33 34 /// Output data. 35 void decoder_output_data(r_device *decoder, data_t *data); 36 37 // be terse, a maximum msg length of 60 characters is supported on the decoder_output_ functions 38 // e.g. "FoobarCorp-XY3000: unexpected type code %02x" 39 40 /// Output a message. 41 void decoder_output_message(r_device *decoder, char const *msg); 42 43 /// Output a message and the content of a bitbuffer. 44 void decoder_output_bitbuffer(r_device *decoder, bitbuffer_t const *bitbuffer, char const *msg); 45 46 /// Output a message and the content of a bitbuffer. 47 /// Usage not recommended. 48 void decoder_output_bitbuffer_array(r_device *decoder, bitbuffer_t const *bitbuffer, char const *msg); 49 50 /// Output a message and the content of a bit row (byte buffer). 51 void decoder_output_bitrow(r_device *decoder, uint8_t const *bitrow, unsigned bit_len, char const *msg); 52 53 // print helpers 54 55 /// Output a message with args. 56 void decoder_output_messagef(r_device *decoder, _Printf_format_string_ char const *restrict format, ...) 57 #if defined(__GNUC__) || defined(__clang__) 58 __attribute__((format(printf, 2, 3))) 59 #endif 60 ; 61 62 /// Output a message with args and the content of a bitbuffer. 63 void decoder_output_bitbufferf(r_device *decoder, bitbuffer_t const *bitbuffer, _Printf_format_string_ char const *restrict format, ...) 64 #if defined(__GNUC__) || defined(__clang__) 65 __attribute__((format(printf, 3, 4))) 66 #endif 67 ; 68 69 /// Output a message with args and the content of a bitbuffer. 70 void decoder_output_bitbuffer_arrayf(r_device *decoder, bitbuffer_t const *bitbuffer, _Printf_format_string_ char const *restrict format, ...) 71 #if defined(__GNUC__) || defined(__clang__) 72 __attribute__((format(printf, 3, 4))) 73 #endif 74 ; 75 76 /// Output a message with args and the content of a bit row (byte buffer). 77 void decoder_output_bitrowf(r_device *decoder, uint8_t const *bitrow, unsigned bit_len, _Printf_format_string_ char const *restrict format, ...) 78 #if defined(__GNUC__) || defined(__clang__) 79 __attribute__((format(printf, 4, 5))) 80 #endif 81 ; 82 83 /// Print the content of the bitbuffer. 84 void bitbuffer_printf(const bitbuffer_t *bitbuffer, _Printf_format_string_ char const *restrict format, ...) 85 #if defined(__GNUC__) || defined(__clang__) 86 __attribute__((format(printf, 2, 3))) 87 #endif 88 ; 89 90 /// Debug print the content of the bitbuffer. 91 /// For quick and easy debugging, not for regular usage. 92 void bitbuffer_debugf(const bitbuffer_t *bitbuffer, _Printf_format_string_ char const *restrict format, ...) 93 #if defined(__GNUC__) || defined(__clang__) 94 __attribute__((format(printf, 2, 3))) 95 #endif 96 ; 97 98 /// Print the content of a bit row (byte buffer). 99 void bitrow_printf(uint8_t const *bitrow, unsigned bit_len, _Printf_format_string_ char const *restrict format, ...) 100 #if defined(__GNUC__) || defined(__clang__) 101 __attribute__((format(printf, 3, 4))) 102 #endif 103 ; 104 105 /// Debug print the content of a bit row (byte buffer). 106 /// For quick and easy debugging, not for regular usage. 107 void bitrow_debugf(uint8_t const *bitrow, unsigned bit_len, _Printf_format_string_ char const *restrict format, ...) 108 #if defined(__GNUC__) || defined(__clang__) 109 __attribute__((format(printf, 3, 4))) 110 #endif 111 ; 112 113 #endif /* INCLUDE_DECODER_UTIL_H_ */ 114