OpenCPN Partial API docs
Loading...
Searching...
No Matches
comm_buffers.h
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2024 Alec Leamas *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 **************************************************************************/
19
25#ifndef _COMM_BUFFERS_H__
26#define _COMM_BUFFERS_H__
27
28#include <deque>
29#include <mutex>
30#include <string>
31#include <vector>
32
33#ifdef _MSC_VER
34typedef unsigned __int8 uint8_t;
35#else
36#include <stdint.h>
37#endif
38
41public:
43 void Put(const std::string line);
44
49 bool Get(std::string& line);
50
51private:
52 std::deque<std::string> m_buffer;
53 std::mutex m_mutex;
54};
55
58public:
60 void Put(uint8_t ch);
61
63 bool HasLine() const;
64
66 std::vector<uint8_t> GetLine();
67
68 LineBuffer() : m_line_count(0), m_last_ch('\n') {}
69
70private:
71 std::vector<uint8_t> m_buff;
72 int m_line_count;
73 uint8_t m_last_ch;
74};
75
78public:
80 void Put(uint8_t ch);
81
83 bool HasSentence() const { return !m_lines.empty(); }
84
89 std::string GetSentence();
90
91 N0183Buffer() : m_state(State::PrefixWait) {}
92
93private:
94 std::deque<std::string> m_lines;
95 std::vector<uint8_t> m_line;
96 enum class State { PrefixWait, Data, CsDigit1, CsDigit2 } m_state;
97};
98
99#endif // _COMM_BUFFERS_H__
Assembles input characters to lines.
void Put(uint8_t ch)
Add a single character.
std::vector< uint8_t > GetLine()
Retrieve a line from buffer, return empty line if none available.
bool HasLine() const
Return true if a line is available to be returned by GetLine().
Assemble characters to NMEA0183 sentences.
bool HasSentence() const
Return true if a sentence is available to be returned by GetSentence()
std::string GetSentence()
Retrieve a sentence from buffer.
void Put(uint8_t ch)
Add a single character, possibly making a sentence available.
Synchronized buffer for outbound, line oriented data.
void Put(const std::string line)
Insert line in buffer.
bool Get(std::string &line)
Retrieve a line in buffer.