From: Inga Stotland <inga.stotland@xxxxxxxxx> Centralized some frequently used functionaility for logging and save/retrieve of long (128+ bit) hexidecimal data. --- mesh/util.c | 27 ++++++++++++++++++++++++++- mesh/util.h | 2 +- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/mesh/util.c b/mesh/util.c index 2cdcdf37d..b3ce1ce5f 100644 --- a/mesh/util.c +++ b/mesh/util.c @@ -15,7 +15,6 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * */ #ifdef HAVE_CONFIG_H @@ -26,10 +25,36 @@ #include <stdbool.h> #include <stdint.h> #include <stdio.h> +#include <unistd.h> +#include <termios.h> #include <time.h> +#include <sys/ioctl.h> +#include <sys/time.h> + +#include <ell/ell.h> #include "mesh/util.h" +void print_packet(const char *label, const void *data, uint16_t size) +{ + struct timeval pkt_time; + + gettimeofday(&pkt_time, NULL); + + if (size > 0) { + char *str; + + str = l_util_hexstring(data, size); + l_debug("%05d.%03d %s: %s", + (uint32_t) pkt_time.tv_sec % 100000, + (uint32_t) pkt_time.tv_usec/1000, label, str); + l_free(str); + } else + l_debug("%05d.%03d %s: empty", + (uint32_t) pkt_time.tv_sec % 100000, + (uint32_t) pkt_time.tv_usec/1000, label); +} + uint32_t get_timestamp_secs(void) { struct timespec ts; diff --git a/mesh/util.h b/mesh/util.h index 61110104a..007ea368e 100644 --- a/mesh/util.h +++ b/mesh/util.h @@ -15,10 +15,10 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * */ uint32_t get_timestamp_secs(void); bool str2hex(const char *str, uint16_t in_len, uint8_t *out, uint16_t out_len); size_t hex2str(uint8_t *in, size_t in_len, char *out, size_t out_len); +void print_packet(const char *label, const void *data, uint16_t size); -- 2.14.5