-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDynamicCommandParser.h
More file actions
55 lines (43 loc) · 935 Bytes
/
DynamicCommandParser.h
File metadata and controls
55 lines (43 loc) · 935 Bytes
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
#ifndef SERIALDATAPARSER_H
#define SERIALDATAPARSER_H
#include <stdlib.h>
#include <string.h>
#define BUFFER_SIZE 64
typedef void (* ParserFunction)(char **values, int valueCount);
typedef struct
{
char *command;
ParserFunction function;
} ParserFunctionLookup;
class DynamicCommandParser
{
public:
DynamicCommandParser(char start, char end, char delim)
{
mInCommand = false;
mStart = start;
mEnd = end;
mDelimiter = delim;
mParserLookup = NULL;
mParserLookupSize = 0;
buffer[0] = '\0';
}
~DynamicCommandParser()
{
free(mParserLookup);
}
void addParser(char *cmd, ParserFunction function);
void append(char *str);
void appendChar(char c);
private:
bool mInCommand;
char buffer[BUFFER_SIZE];
char mStart;
char mEnd;
char mDelimiter;
size_t mParserLookupSize;
ParserFunctionLookup *mParserLookup;
void parseBuffer();
int getBufferPartCount();
};
#endif