-
Notifications
You must be signed in to change notification settings - Fork 2
/
TokenProcessor.h
86 lines (70 loc) · 2.08 KB
/
TokenProcessor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Library Name: TokenProcessor
*
* Filename: TokenProcessor.h
* Description: library TokenProcessor interface
*
* Version: 1.0.0
* Author: Joao Alves <[email protected]>
* Required files: TokenProcessor.cpp, TokenProcessor.h
*
* History:
* 1.0.0 - 2017-03-14 - Initial Version
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TOKENPROCESSOR_H
#define TOKENPROCESSOR_H
#include <stddef.h>
#include <stdint.h>
#if (defined(__AVR__))
#include <avr/pgmspace.h>
#else
#include <pgmspace.h>
#endif
#include "Arduino.h"
#include "WString.h"
#include "Stream.h"
//#define DEBUGCODE
class TokenProcessor {
public:
TokenProcessor(Stream& , int, char , int, const char *, void(**)(TokenProcessor *), void (*)(TokenProcessor *));
~TokenProcessor();
TokenProcessor(const TokenProcessor&);
TokenProcessor& operator=(const TokenProcessor&);
char *nextToken();
void clearBuffer();
char getCommand() { return lastCommand; }
void process();
Stream *Channel() {
return stream;
}
void processCommand(char *);
uint16_t size() {
return commandListSize;
};
void getCommand(int, char &);
private:
Stream* const stream;
int bufferSize;
int commandListSize = 0;
const char *commandList;
void(**callbackFunctions)(TokenProcessor *);
char *buffer;
int bufferPos;
void (*defaultHandler)(TokenProcessor *) = NULL;
char _delim[2];
char *token;
char *save_ptr;
char lastCommand = 0;
};
#endif