DvG_StreamCommand
DvG_StreamCommand.h
Go to the documentation of this file.
1
9#ifndef DVG_STREAMCOMMAND_H_
10#define DVG_STREAMCOMMAND_H_
11
12#include <Arduino.h>
13
14/*******************************************************************************
15 DvG_StreamCommand
16*******************************************************************************/
17
33public:
45 DvG_StreamCommand(Stream &stream, char *buffer, uint16_t max_len);
46
54 bool available();
55
62 char *getCommand();
63
67 inline void reset() {
68 _fTerminated = false;
69 _buffer[0] = '\0';
70 _cur_len = 0;
71 }
72
73private:
74 Stream &_stream; // Reference to the stream to listen to
75 char *_buffer; // Reference to the command buffer
76 uint16_t _max_len; // Array size of the command buffer
77 uint16_t _cur_len; // Number of currently received command characters
78 bool _fTerminated; // Has a complete command been received?
79 const char *_empty = ""; // Empty reply, which is just the '\0' character
80};
81
82/*******************************************************************************
83 DvG_BinaryStreamCommand
84*******************************************************************************/
85
101public:
115 DvG_BinaryStreamCommand(Stream &stream, uint8_t *buffer, uint16_t max_len,
116 const uint8_t *EOL, uint8_t EOL_len);
117
133 int8_t available(bool debug_info = false);
134
143 uint16_t getCommandLength();
144
148 inline void reset() {
149 for (uint16_t i = 0; i < _max_len; ++i) {
150 _buffer[i] = 0;
151 }
152 _found_EOL = false;
153 _cur_len = 0;
154 }
155
156private:
157 Stream &_stream; // Reference to the stream to listen to
158 uint8_t *_buffer; // Reference to the command buffer
159 uint16_t _max_len; // Array size of the command buffer
160 uint16_t _cur_len; // Number of currently received command bytes
161 const uint8_t *_EOL; // Reference to the end-of-line sentinel
162 uint16_t _EOL_len; // Array size of the end-of-line sentinel
163 bool _found_EOL; // Has a complete command been received?
164};
165
166/*******************************************************************************
167 Parse functions
168*******************************************************************************/
169
176float parseFloatInString(const char *str_in, uint16_t pos = 0);
177
189bool parseBoolInString(const char *str_in, uint16_t pos = 0);
190
197int parseIntInString(const char *str_in, uint16_t pos = 0);
198
199#endif
int parseIntInString(const char *str_in, uint16_t pos=0)
Safely parse an integer value in C-string str_in from of position pos.
Definition: DvG_StreamCommand.cpp:203
bool parseBoolInString(const char *str_in, uint16_t pos=0)
Safely parse a boolean value in C-string str_in from of position pos.
Definition: DvG_StreamCommand.cpp:190
float parseFloatInString(const char *str_in, uint16_t pos=0)
Safely parse a float value in C-string str_in from of position pos.
Definition: DvG_StreamCommand.cpp:182
Class to manage listening to a stream, such as Serial or Wire, for incoming binary commands (or binar...
Definition: DvG_StreamCommand.h:100
int8_t available(bool debug_info=false)
Poll the stream for incoming bytes and append them one-by-one to the command buffer buffer....
Definition: DvG_StreamCommand.cpp:120
DvG_BinaryStreamCommand(Stream &stream, uint8_t *buffer, uint16_t max_len, const uint8_t *EOL, uint8_t EOL_len)
Construct a new DvG_BinaryStreamCommand object.
Definition: DvG_StreamCommand.cpp:106
uint16_t getCommandLength()
Return the length of the command without the EOL sentinel in bytes, only when a complete command has ...
Definition: DvG_StreamCommand.cpp:163
void reset()
Empty the command buffer.
Definition: DvG_StreamCommand.h:148
Class to manage listening to a stream, such as Serial or Wire, for incoming ASCII commands (or ASCII ...
Definition: DvG_StreamCommand.h:32
DvG_StreamCommand(Stream &stream, char *buffer, uint16_t max_len)
Construct a new DvG_StreamCommand object.
Definition: DvG_StreamCommand.cpp:43
void reset()
Empty the command buffer.
Definition: DvG_StreamCommand.h:67
char * getCommand()
Return the reference to the command buffer only when a complete command has been received....
Definition: DvG_StreamCommand.cpp:91
bool available()
Poll the stream for incoming characters and append them one-by-one to the command buffer buffer....
Definition: DvG_StreamCommand.cpp:52