2018-03-22 03:53:32 -03:00
|
|
|
#include "BetterStream.h"
|
|
|
|
|
|
|
|
#include "print_vprintf.h"
|
|
|
|
|
|
|
|
void AP_HAL::BetterStream::printf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vprintf(fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AP_HAL::BetterStream::vprintf(const char *fmt, va_list ap)
|
|
|
|
{
|
|
|
|
print_vprintf(this, fmt, ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t AP_HAL::BetterStream::write(const char *str)
|
|
|
|
{
|
|
|
|
return write((const uint8_t *)str, strlen(str));
|
|
|
|
}
|
2019-09-30 11:05:32 -03:00
|
|
|
|
2023-02-21 05:35:57 -04:00
|
|
|
int16_t AP_HAL::BetterStream::read()
|
|
|
|
{
|
|
|
|
uint8_t b;
|
|
|
|
if (!read(b)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
2023-06-26 06:51:48 -03:00
|
|
|
ssize_t AP_HAL::BetterStream::read(uint8_t *buffer, uint16_t count)
|
|
|
|
{
|
|
|
|
size_t offset = 0;
|
2019-09-30 11:05:32 -03:00
|
|
|
while (count--) {
|
|
|
|
const int16_t x = read();
|
|
|
|
if (x == -1) {
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
buffer[offset++] = (uint8_t)x;
|
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|