Improved printable implementation; data reading with macro

This commit is contained in:
dario 2024-06-26 17:41:56 +02:00 committed by dario
parent b9ccb2d65f
commit ebb14896b8
7 changed files with 56 additions and 16 deletions

View File

@ -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)

View File

@ -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:
/**

View File

@ -28,12 +28,12 @@ namespace sta
void print(const char * str, size_t length, bool newline = false) override;
/**
* @brief Print string.
* @brief Read bytes.
*
* @param str String buffer
* @param length String length
* @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

View File

@ -37,12 +37,12 @@ namespace sta
void print(const char * str, size_t length, bool newline = false) override;
/**
* @brief Read string.
* @brief Read bytes.
*
* @param str String buffer
* @param length String length
* @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_;

View File

@ -193,4 +193,19 @@ namespace sta
print(buffer, digits, newline);
}
void Printable::read(char * str, size_t length)
{
read(reinterpret_cast<uint8_t*>(str), length * sizeof(char));
}
void Printable::read(float * buffer, size_t length)
{
read(reinterpret_cast<uint8_t*>(buffer), length * sizeof(float));
}
void Printable::read(double * buffer, size_t length)
{
read(reinterpret_cast<uint8_t*>(buffer), length * sizeof(double));
}
} // namespace sta

View File

@ -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);

View File

@ -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<uint8_t *>(str), length);
intf_->receive(buffer, length);
intf_->release();
}