LCOV - code coverage report
Current view: top level - AP_HAL/utility - BetterStream.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 2 2 100.0 %
Date: 2026-09-09 11:02:08 Functions: 2 2 100.0 %

          Line data    Source code
       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             : 
       7             :    This program is distributed in the hope that it will be useful,
       8             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
       9             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      10             :    GNU General Public License for more details.
      11             : 
      12             :    You should have received a copy of the GNU General Public License
      13             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      14             :  */
      15             : 
      16             : //
      17             : //      Copyright (c) 2010 Michael Smith. All rights reserved.
      18             : //
      19             : //
      20             : #pragma once
      21             : 
      22             : #include <AP_Common/AP_Common.h>
      23             : #include <AP_HAL/AP_HAL_Namespace.h>
      24             : 
      25             : #include <stdarg.h>
      26             : #include <unistd.h>
      27             : 
      28             : class AP_HAL::BetterStream {
      29             : public:
      30             : 
      31             :     virtual void printf(const char *, ...) FMT_PRINTF(2, 3);
      32             :     virtual void vprintf(const char *, va_list);
      33             : 
      34           2 :     void print(const char *str) { write(str); }
      35           2 :     void println(const char *str) { printf("%s\r\n", str); }
      36             : 
      37             :     virtual size_t write(uint8_t) = 0;
      38             :     virtual size_t write(const uint8_t *buffer, size_t size) = 0;
      39             :     virtual size_t write(const char *str);
      40             : 
      41             :     virtual uint32_t available() = 0;
      42             : 
      43             :     virtual int16_t read(void);
      44             :     virtual bool read(uint8_t &b) WARN_IF_UNUSED = 0;
      45             : 
      46             :     // no base-class implementation to force descendants to
      47             :     // do things efficiently.  Looping over 2^32-1 bytes would be bad.
      48             :     // returns false if discard failed (e.g. port locked)
      49             :     virtual bool discard_input() = 0; // discard all bytes available for reading
      50             : 
      51             :     // returns -1 on error (e.g. port locked), number of bytes read
      52             :     // otherwise
      53             :     virtual ssize_t read(uint8_t *buffer, uint16_t count);
      54             : 
      55             :     /* NB txspace was traditionally a member of BetterStream in the
      56             :      * FastSerial library. As far as concerns go, it belongs with available() */
      57             :     virtual uint32_t txspace() = 0;
      58             : };

Generated by: LCOV version 1.14