BetterStream.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. //
  14. // Copyright (c) 2010 Michael Smith. All rights reserved.
  15. //
  16. //
  17. #pragma once
  18. #include <stdarg.h>
  19. #include <AP_Common/AP_Common.h>
  20. #include <AP_HAL/AP_HAL_Namespace.h>
  21. class AP_HAL::BetterStream {
  22. public:
  23. virtual void printf(const char *, ...) FMT_PRINTF(2, 3);
  24. virtual void vprintf(const char *, va_list);
  25. void print(const char *str) { write(str); }
  26. void println(const char *str) { printf("%s\r\n", str); }
  27. virtual size_t write(uint8_t) = 0;
  28. virtual size_t write(const uint8_t *buffer, size_t size) = 0;
  29. size_t write(const char *str);
  30. virtual uint32_t available() = 0;
  31. /* return value for read():
  32. * -1 if nothing available, uint8_t value otherwise. */
  33. virtual int16_t read() = 0;
  34. /* NB txspace was traditionally a member of BetterStream in the
  35. * FastSerial library. As far as concerns go, it belongs with available() */
  36. virtual uint32_t txspace() = 0;
  37. };