NMEA2000 Library  0.1
Library to handle NMEA 2000 Communication written in C++
N2kStream.h
Go to the documentation of this file.
1/* N2kStream.h
2 * Copyright (c) 2015-2024 Timo Lappalainen, Kave Oy, www.kave.fi
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 * SOFTWARE.
20*/
21
22/**************************************************************************/
36#ifndef _tN2kStream_H_
37#define _tN2kStream_H_
38
39#include "N2kDef.h"
40#include <stdint.h>
41#include <stddef.h>
42
43#ifdef ARDUINO
44// Arduino users get away with using the standard Stream class and its
45// subclasses. Forward declare the Stream class here and include Arduino.h in
46// the application.
47#include <Arduino.h>
49typedef Stream N2kStream;
50#else
51
52/**************************************************************************/
60class N2kStream {
61 public:
62 /************************************************************************/
68 virtual int read() = 0;
69 /***********************************************************************/
74 virtual int peek() = 0;
75
76 /***********************************************************************/
83 virtual size_t write(const uint8_t* data, size_t size) = 0;
84
85 /***********************************************************************/
91 size_t print(const char* str);
92
93#if defined(__AVR__)
94 // Flash stored string stream for AVR platforms.
95 size_t print(const __FlashStringHelper* str);
96 size_t println(const __FlashStringHelper* str);
97#endif
98
99 /***********************************************************************/
106 size_t print(int val, uint8_t radix = 10);
107
108 /***********************************************************************/
114 size_t println(const char *str);
115
116 /***********************************************************************/
123 size_t println(int val, uint8_t radix = 10);
124};
125#endif
126
127#endif
Type definitions and utility macros used in the NMEA2000 libraries.
Streaming Class to handle all Streams generated by the Library.
Definition: N2kStream.h:60
virtual int peek()=0
reads a byte from the file without advancing to the next one
virtual int read()=0
reads characters from an incoming stream to the buffer
size_t print(const char *str)
Print string to stream.
Definition: N2kStream.cpp:32
virtual size_t write(const uint8_t *data, size_t size)=0
Write data to stream.
size_t println(const char *str)
Print string and newline to stream.
Definition: N2kStream.cpp:75