From f8f73d2ccbb32b4134e441c2e8652400c1fd78ba Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 3 Jul 2022 11:05:56 +0200 Subject: [PATCH] [MOD] Added helper hexdump function --- src/Module.cpp | 20 ++++++++++++++++++++ src/Module.h | 9 +++++++++ 2 files changed, 29 insertions(+) diff --git a/src/Module.cpp b/src/Module.cpp index d430b9aa..2a6e35cd 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -445,6 +445,26 @@ uint16_t Module::flipBits16(uint16_t i) { return i; } +void Module::hexdump(uint8_t* data, size_t len) { + for(int i = 0; i < len; i+=16) { + char str[80]; + sprintf(str, "%07x ", i); + for(int j = 0; j < 16; j++) { + sprintf(&str[8 + j*3], "%02x ", data[i+j]); + } + str[56] = '|'; + str[57] = ' '; + for(int j = 0; j < 16; j++) { + char c = data[i+j]; + if((c < ' ') || (c > '~')) { + c = '.'; + } + sprintf(&str[58 + j], "%c", c); + } + RADIOLIB_DEBUG_PRINTLN(str); + } +} + void Module::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) { _useRfSwitch = true; _rxEn = rxEn; diff --git a/src/Module.h b/src/Module.h index aa38f6d4..7b93d154 100644 --- a/src/Module.h +++ b/src/Module.h @@ -377,6 +377,15 @@ class Module { */ static uint16_t flipBits16(uint16_t i); + /*! + \brief Function to dump data as hex into the debug port. + + \param data Data to dump. + + \param data Number of bytes to dump. + */ + static void hexdump(uint8_t* data, size_t len); + // hardware abstraction layer callbacks RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_PIN_MODE); RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_DIGITAL_WRITE);