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, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
24#ifndef COMM_BUFFERS_H_
25#define COMM_BUFFERS_H_
26
27#include <deque>
28#include <mutex>
29#include <string>
30#include <vector>
31
32#ifdef _MSC_VER
33typedef unsigned __int8 uint8_t;
34#else
35#include <stdint.h>
36#endif
37
40public:
42 void Put(const std::string line);
43
48 bool Get(std::string& line);
49
50private:
51 std::deque<std::string> m_buffer;
52 std::mutex m_mutex;
53};
54
57public:
59 void Put(uint8_t ch);
60
62 bool HasLine() const;
63
65 std::vector<uint8_t> GetLine();
66
67 LineBuffer() : m_line_count(0), m_last_ch('\n') {}
68
69private:
70 std::vector<uint8_t> m_buff;
71 int m_line_count;
72 uint8_t m_last_ch;
73};
74
77public:
79 void Put(uint8_t ch);
80
82 bool HasSentence() const { return !m_lines.empty(); }
83
88 std::string GetSentence();
89
90 N0183Buffer() : m_state(State::PrefixWait) {}
91
92private:
93 std::deque<std::string> m_lines;
94 std::vector<uint8_t> m_line;
95 enum class State { PrefixWait, Data, CsDigit1, CsDigit2 } m_state;
96};
97
98#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.