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
64private:
65 Stream &_stream; // Reference to the stream to listen to
66 char *_buffer; // Reference to the command buffer
67 uint16_t _max_len; // Array size of the command buffer
68 uint16_t _cur_len; // Number of currently received command characters
69 bool _fTerminated; // Has a complete command been received?
70 const char *_empty = ""; // Empty reply, which is just the '\0' character
71};
72
73/*******************************************************************************
74 DvG_BinaryStreamCommand
75*******************************************************************************/
76
92public:
106 DvG_BinaryStreamCommand(Stream &stream, uint8_t *buffer, uint16_t max_len,
107 const uint8_t *EOL, uint8_t EOL_len);
108
124 int8_t available(bool debug_info = false);
125
134 uint16_t getCommandLength();
135
140 inline void reset() {
141 _found_EOL = false;
142 _cur_len = 0;
143 }
144
145private:
146 Stream &_stream; // Reference to the stream to listen to
147 uint8_t *_buffer; // Reference to the command buffer
148 uint16_t _max_len; // Array size of the command buffer
149 uint16_t _cur_len; // Number of currently received command bytes
150 const uint8_t *_EOL; // Reference to the end-of-line sentinel
151 uint16_t _EOL_len; // Array size of the end-of-line sentinel
152 bool _found_EOL; // Has a complete command been received?
153};
154
155/*******************************************************************************
156 Parse functions
157*******************************************************************************/
158
165float parseFloatInString(const char *str_in, uint16_t pos = 0);
166
178bool parseBoolInString(const char *str_in, uint16_t pos = 0);
179
186int parseIntInString(const char *str_in, uint16_t pos = 0);
187
188#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:206
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:193
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:185
Class to manage listening to a stream, such as Serial or Wire, for incoming binary commands (or binar...
Definition: DvG_StreamCommand.h:91
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:123
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:107
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:166
void reset()
TODO: descr.
Definition: DvG_StreamCommand.h:140
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:42
char * getCommand()
Return the reference to the command buffer only when a complete command has been received....
Definition: DvG_StreamCommand.cpp:92
bool available()
Poll the stream for incoming characters and append them one-by-one to the command buffer buffer....
Definition: DvG_StreamCommand.cpp:53