-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_05_SerialProcess.ino
208 lines (158 loc) · 4.22 KB
/
_05_SerialProcess.ino
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
* Serial operations happen here. Reads incoming lines (terminated by "\0")
* Depending on the tag string is routed to different functions.
*
* Note: Maximum lenght of incoming string is 64 bytes
*
* TODO:
* -Needs some tidying up. While performance is pretty good, style and readability
* could be better.
*
* -Maybe implement a parity check? Current sanity checks are quite effective
* but there may be need for a more robust system down the line
*
*
* 20/05/2016
* Flanker
*/
void SerialRead() {
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (recvInProgress == true && rc != startMarker) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= NUMCHARS) {
ndx = NUMCHARS - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker) {
memset(receivedChars, 0, 100);
ndx = 0;
recvInProgress = true;
}
}
}
void showNewData() {
if (newData == true && !recvInProgress) {
//debug(receivedChars);
typeSelect(receivedChars);
newData = false;
}
}
void typeSelect(char data[NUMCHARS]) {
char * strtokIndx; // this is used by strtok() as an index
strtokIndx = strtok(data, ","); // get the first part - the string
DataType = String(strtokIndx);
//debug("Type: " + DataType) ;
lastStatus = millis();//Heathbeat functions variable. Marks when the last packet was received.
if (DataType == "CON") {
Serial.println("<pong>\n");
cDebug = true;
}
if (DataType == "STP") {
cDebug = false;
Serial.flush();
delay(1000);
cDebug = true;
}
//CPU and RAM LOAD
if (DataType == "LOD") {
strtokIndx = strtok(NULL, ",");
byte CPU_Load = atoi(strtokIndx);
strtokIndx = strtok(NULL, ",");
byte CPU1_Load = atoi(strtokIndx);
strtokIndx = strtok(NULL, ",");
byte CPU2_Load = atoi(strtokIndx);
strtokIndx = strtok(NULL, ",");
byte CPU3_Load = atoi(strtokIndx);
strtokIndx = strtok(NULL, ",");
byte CPU4_Load = atoi(strtokIndx);
strtokIndx = strtok(NULL, ",");
byte RAM_Load = atoi(strtokIndx);
// Draw_Ram();
CPU_Load_Draw(CPU_Load, CPU1_Load, CPU2_Load, CPU3_Load, CPU4_Load, RAM_Load);
}
else if (DataType == "CTM") {// CPU Temperature
strtokIndx = strtok(NULL, ",");
CPU_Temp = atoi(strtokIndx);
strtokIndx = strtok(NULL, ",");
CPU1_Temp = atoi(strtokIndx);
strtokIndx = strtok(NULL, ",");
CPU2_Temp = atoi(strtokIndx);
strtokIndx = strtok(NULL, ",");
CPU3_Temp = atoi(strtokIndx);
strtokIndx = strtok(NULL, ",");
CPU4_Temp = atoi(strtokIndx);
// CPU_Temp_Draw();
//debug (String(CPU_Temp));
}
else if (DataType == "NTW")//Download And Upload Speed
{
strtokIndx = strtok(NULL, ",");
int downSpeed = atoi(strtokIndx);
strtokIndx = strtok(NULL, ",");
int upSpeed = atoi(strtokIndx);
Net_Draw(upSpeed, downSpeed);
}
else if (DataType == "IPA")
{
strtokIndx = strtok(NULL, ",");
bool stat(strtokIndx);
strtokIndx = strtok(NULL, ",");
String ip(strtokIndx);
IP_Draw(stat, ip);
}
//DATE
else if (DataType == "TME")
{
strtokIndx = strtok(NULL, ",");
String date(strtokIndx);
strtokIndx = strtok(NULL, ",");
String day(strtokIndx);
DateDraw(date, day);
}
//HOUR
else if (DataType == "HOR")
{
strtokIndx = strtok(NULL, ",");
String hour(strtokIndx);
HourDraw(hour);
}
/*
else if (DataType == "VOL")
{ //Get sound information
bool Mute;
strtokIndx = strtok(NULL, ",");
int Volume = atoi(strtokIndx);
strtokIndx = strtok(NULL, ",");
if (String(strtokIndx) == "True")
{
Mute = true;
}
else
{
Mute = false;
}
strtokIndx = strtok(NULL, ",");
int Peak = atoi(strtokIndx);
VolumeDraw(Mute, Volume, Peak);
}
}
*/
else
{
//debug("Unrecognized packet received: " + DataType);
}
}