stream_console.cpp
1 /*
2  * uuid-console - Microcontroller console shell
3  * Copyright 2019 Simon Arlott
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include <uuid/console.h>
20 
21 #include <Arduino.h>
22 
23 #include <memory>
24 #include <string>
25 
26 namespace uuid {
27 
28 namespace console {
29 
31  : Shell(), stream_(stream) {
32 
33 }
34 
35 // cppcheck-suppress passedByValue
36 StreamConsole::StreamConsole(std::shared_ptr<Commands> commands, Stream &stream, unsigned int context, unsigned int flags)
37  : Shell(std::move(commands), context, flags), stream_(stream) {
38 
39 }
40 
41 size_t StreamConsole::write(uint8_t data) {
42  return stream_.write(data);
43 }
44 
45 size_t StreamConsole::write(const uint8_t *buffer, size_t size) {
46  return stream_.write(buffer, size);
47 }
48 
50  return stream_.available() > 0;
51 }
52 
54  return stream_.read();
55 }
56 
58  return stream_.peek();
59 }
60 
61 } // namespace console
62 
63 } // namespace uuid
int read_one_char() override
Read one character from the available input.
unsigned int context() const
Get the context at the top of the stack.
Definition: console.h:965
Base class for a command shell.
Definition: console.h:776
STL namespace.
bool available_char() override
Check for at least one character of available input.
StreamConsole(std::shared_ptr< Commands > commands, Stream &stream, unsigned int context=0, unsigned int flags=0)
Create a new StreamConsole shell with the given commands, default context and initial flags...
size_t write(uint8_t data) override
Write one byte to the output stream.
Common utilities.
int peek_one_char() override
Read one character from the available input without advancing to the next one.