-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConsoleHandler.cpp
executable file
·57 lines (53 loc) · 1.6 KB
/
ConsoleHandler.cpp
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
#ifndef CONSOLE_HANDLER_h
#define CONSOLE_HANDLER_h
#include "ConsoleCommandHandler.h"
#include "EspSaveCrash.h"
class ConsoleHandler {
private:
Stream *stream;
EspSaveCrash SaveCrash;
char* theVersion;
char* componentName;
//#define DEBUG_OUTPUT_SIZE 2048
int DEBUG_OUTPUT_SIZE;
char *_debugOutputBuffer = (char *)calloc(DEBUG_OUTPUT_SIZE, sizeof(char));
public:
ConsoleHandler(char* componentName, char* theVersion, Stream *stream)
: theVersion(theVersion), stream(stream) {};
void handle() {
if (this->stream->available() > 0) {
char inChar = stream->read();
switch (inChar) {
case 'r':
stream->println(F("Restarting......."));
stream->flush();
ESP.restart();
break;
case 'i':
SaveCrash.print(_debugOutputBuffer, DEBUG_OUTPUT_SIZE);
stream->println(F("--- BEGIN of crash info from buffer ---"));
stream->print(_debugOutputBuffer);
stream->println(F("--- END of crash info from buffer ---"));
break;
case 'c':
SaveCrash.clear();
stream->println(F("Crash information cleared"));
break;
case 'o':
stream->print(F("I am the"));
stream->print(componentName);
stream->print(F(" in version "));
stream->println(theVersion);
break;
case 0xa:
case 0xd:
// skip newline and carriage return
break;
default:
stream->printf("%c typed\n", inChar);
break;
}
}
}
};
#endif