-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCmdProcessor.h
More file actions
54 lines (44 loc) · 1.37 KB
/
CmdProcessor.h
File metadata and controls
54 lines (44 loc) · 1.37 KB
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
#ifndef CmdProcessor_h
#define CmdProcessor_h
#include "Arduino.h"
class Sumorobot;
#include "Sumorobot.h"
#define INPUT_BUFFER_LENGTH 180
typedef enum {EXPECT_ATTR, ATTR, EXPECT_VAL, VAL} parseState_t;
typedef enum {WAITING, WEBSOCKET_INIT, WEBSOCKET_RESPOND, WEBSOCKET_READY, HTTP_INIT, HTTP_RESPOND, HTTP_READY} httpState_t;
typedef enum {RAW, HTTP, WEBSOCKET} socketMode_t;
typedef void (* fp_main) (void *, char *);
typedef boolean (* fp_ready) (void *);
struct UserCmd {
const char *cmd;
byte type;
fp_main fn_main;
fp_ready fn_ready;
};
class Sumorobot;
class CmdProcessor {
public:
CmdProcessor();
void addUserCmd(char* cmd, fp_main fn, fp_ready ready);
void setup(Stream &stream, Sumorobot &sumorobot);
void process();
private:
boolean processLine();
void extractAttr(const char attr[4], char *json, char *output, char len);
void processCmd(char &cmd, char &arg, char &id);
void runCmd(char &cmd, char &arg, char &id);
void sendResponse(const char state[], const char msg[], char &id);
Stream* _stream;
Sumorobot* _sumorobot;
httpState_t httpState;
socketMode_t socketMode;
char webSocketKey[61];
char newLineCount;
char input_buffer[INPUT_BUFFER_LENGTH];
byte input_buffer_pos;
unsigned long last_char;
boolean processWSFrame();
boolean processJSON();
boolean processHeaders();
};
#endif