From ebb14896b8054bdeb6a4bdc5fe555ba4b92163ab Mon Sep 17 00:00:00 2001 From: dario Date: Wed, 26 Jun 2024 17:41:56 +0200 Subject: [PATCH] Improved printable implementation; data reading with macro --- include/sta/debug/debug.hpp | 5 ++-- include/sta/debug/printing/printable.hpp | 26 ++++++++++++++++++- .../sta/debug/printing/printable_printf.hpp | 10 +++---- include/sta/debug/printing/printable_uart.hpp | 10 +++---- src/debug/printing/printable.cpp | 15 +++++++++++ src/debug/printing/printable_printf.cpp | 2 +- src/debug/printing/printable_uart.cpp | 4 +-- 7 files changed, 56 insertions(+), 16 deletions(-) diff --git a/include/sta/debug/debug.hpp b/include/sta/debug/debug.hpp index dec9b4c..25d757f 100644 --- a/include/sta/debug/debug.hpp +++ b/include/sta/debug/debug.hpp @@ -35,16 +35,17 @@ namespace sta * * @param fmt See @ref sta::Printable::printf * @param ... See @ref sta::Printable::printf + * + * @ingroup sta_core_debug */ # define STA_DEBUG_PRINTF(fmt, ...) sta::Debug->printf(fmt, __VA_ARGS__) /** - * @brief Read string via printable. + * @brief Read data via printable. * * @param ... See @ref sta::Printable::read * * @ingroup sta_core_debug - * */ # define STA_DEBUG_READ(buffer, length) sta::Debug->read(buffer, length) diff --git a/include/sta/debug/printing/printable.hpp b/include/sta/debug/printing/printable.hpp index 30995db..d25148b 100644 --- a/include/sta/debug/printing/printable.hpp +++ b/include/sta/debug/printing/printable.hpp @@ -170,13 +170,37 @@ namespace sta */ void println(const char * str, size_t length); public: + /** + * @brief Read bytes. + * + * @param buffer Byte buffer + * @param length Buffer length + */ + virtual void read(uint8_t * buffer, size_t length) = 0; + /** * @brief Read string. * * @param str String buffer * @param length String length */ - virtual void read(char* str, size_t length) = 0; + void read(char * str, size_t length); + + /** + * @brief Read floats. + * + * @param buffer Float buffer + * @param length Buffer length + */ + void read(float * buffer, size_t length); + + /** + * @brief Read doubles. + * + * @param buffer Double buffer + * @param length Buffer length + */ + void read(double * buffer, size_t length); private: /** diff --git a/include/sta/debug/printing/printable_printf.hpp b/include/sta/debug/printing/printable_printf.hpp index a570bd0..4f9f7e5 100644 --- a/include/sta/debug/printing/printable_printf.hpp +++ b/include/sta/debug/printing/printable_printf.hpp @@ -28,12 +28,12 @@ namespace sta void print(const char * str, size_t length, bool newline = false) override; /** - * @brief Print string. - * - * @param str String buffer - * @param length String length + * @brief Read bytes. + * + * @param buffer Byte buffer + * @param length Buffer length */ - void read(char * str, size_t length) override; + void read(uint8_t * buffer, size_t length) override; }; } // namespace sta diff --git a/include/sta/debug/printing/printable_uart.hpp b/include/sta/debug/printing/printable_uart.hpp index 0559607..e97de02 100644 --- a/include/sta/debug/printing/printable_uart.hpp +++ b/include/sta/debug/printing/printable_uart.hpp @@ -37,12 +37,12 @@ namespace sta void print(const char * str, size_t length, bool newline = false) override; /** - * @brief Read string. - * - * @param str String buffer - * @param length String length + * @brief Read bytes. + * + * @param buffer Byte buffer + * @param length Buffer length */ - void read(char * str, size_t length) override; + void read(uint8_t * str, size_t length) override; private: UART * intf_; diff --git a/src/debug/printing/printable.cpp b/src/debug/printing/printable.cpp index 73b4c5d..42b0191 100644 --- a/src/debug/printing/printable.cpp +++ b/src/debug/printing/printable.cpp @@ -193,4 +193,19 @@ namespace sta print(buffer, digits, newline); } + void Printable::read(char * str, size_t length) + { + read(reinterpret_cast(str), length * sizeof(char)); + } + + void Printable::read(float * buffer, size_t length) + { + read(reinterpret_cast(buffer), length * sizeof(float)); + } + + void Printable::read(double * buffer, size_t length) + { + read(reinterpret_cast(buffer), length * sizeof(double)); + } + } // namespace sta diff --git a/src/debug/printing/printable_printf.cpp b/src/debug/printing/printable_printf.cpp index 9c8a8d8..35872eb 100644 --- a/src/debug/printing/printable_printf.cpp +++ b/src/debug/printing/printable_printf.cpp @@ -20,7 +20,7 @@ namespace sta printf("\r\n"); } - void PrintablePrintf::read(char * str, size_t length) + void PrintablePrintf::read(uint8_t * str, size_t length) { STA_ASSERT(str != nullptr); STA_ASSERT(length > 0); diff --git a/src/debug/printing/printable_uart.cpp b/src/debug/printing/printable_uart.cpp index 2877c82..b35b376 100644 --- a/src/debug/printing/printable_uart.cpp +++ b/src/debug/printing/printable_uart.cpp @@ -27,10 +27,10 @@ namespace sta intf_->release(); } - void PrintableUART::read(char * str, size_t length) + void PrintableUART::read(uint8_t * buffer, size_t length) { intf_->acquire(); - intf_->receive(reinterpret_cast(str), length); + intf_->receive(buffer, length); intf_->release(); }