-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessageProcessing.cpp
More file actions
212 lines (193 loc) · 4.45 KB
/
messageProcessing.cpp
File metadata and controls
212 lines (193 loc) · 4.45 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
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
208
209
210
211
212
/*
* messageProcessing.cpp
*
* Created on: Jan 15, 2011
* Author: Andy
*/
#include "MessageProcessing.h"
// Local function prototypes
void ProcessERSMsg(char* msg);
void ProcessEGTMsg(char* msg);
void ProcessUNKNOWNMsg(char* msg);
void ProcessMessages()
{
for (int i = 0; i < msgCount; i++)
{
LogLine("Processing...", strlen("Processing..."));
LogLine(messages[i], strlen(messages[i]));
msgTypes_E t = GetMsgType(messages[i]);
switch(t)
{
// report a TEMP, TMPXYTTTTT X=Destination address, Y=Sensor #, TTTTT=(Temp in K)*100
case e_TMP:
Serial.println(strlen("TMP message received: "));
LogLine("TMP message received: ", strlen("TMP message received: "));
ProcessTMPMsg(messages[i]);
break;
// reset EEPROM logging back to starting address
case e_ERS:
LogLine("ERS message received: ", strlen("ERS message received: "));
ProcessERSMsg(messages[i]);
break;
// Get EEPROM
case e_EGT:
LogLine("EGT message received: ", strlen("EGT message received: "));
ProcessEGTMsg(messages[i]);
break;
case e_UNKNOWN:
LogLine("UNKNOWN message received: ", strlen("UNKNOWN message received: "));
LogLine(messages[i], VW_MAX_MESSAGE_LEN);
ProcessUNKNOWNMsg(messages[i]);
break;
}
msgCount--;
}
}
msgTypes_E GetMsgType(char *p)
{
if (p[0] == 'T')
{
if(p[1] == 'M')
{
if(p[2] == 'P')
{
return e_TMP;
}
}
}
if (p[0] == 'E')
{
if(p[1] == 'R')
{
if(p[2] == 'S')
{
return e_ERS;
}
}
}
if (p[0] == 'E')
{
if(p[1] == 'G')
{
if(p[2] == 'T')
{
return e_EGT;
}
}
}
return e_UNKNOWN;
}
// As of Dec 25-2011, all future messages will be passed through to the PC server without any processing.
// this will eliminate the need to crack this code open when new messages are added
// going to do the time stamp on the PC too so I don't need to worry about this falling out of sync.
void ProcessUNKNOWNMsg(char* msg)
{
SendMsgToServer (msg);
}
void ProcessTMPMsg(char* msg)
{
char kelvin[6];
int t = 0;
for (int i = 5; i < strlen(msg); i++)
{
kelvin[t++] = msg[i];
}
kelvin[t] = '\0';
for (int k = 0; k < 5; k++)
{
//LogLine(kelvin[k]);
}
LogLine(kelvin, t);
int kelvInt = atoi(kelvin);
double Kelv = kelvInt/100;
double Fahr = (Kelv -273.15) *((double)9/5)+ 32;
char lcdMsg[16];
int fAsInt = (int)Fahr;
if (msg[4] == 49)
{
//lcd.setCursor(0,0);
//sprintf(lcdMsg,"Outside: %dF",fAsInt);
//lcd.print(lcdMsg);
sprintf(lcdMsg,"%dF", fAsInt);
Serial1.println(lcdMsg);
SetTemp(lcdMsg,0);
}
else if (msg[4] == 48)
{
//lcd.setCursor(0,1);
//sprintf(lcdMsg,"Garage: %dF",fAsInt);
//lcd.print(lcdMsg);
sprintf(lcdMsg,"%dF", fAsInt);
Serial1.println(lcdMsg);
SetTemp(lcdMsg,1);
}
LogTemp(msg[4], kelvInt);
}
void ProcessERSMsg(char* msg)
{
ResetEEProm();
}
void ProcessEGTMsg(char* msg)
{
DisplayEEProm();
}
// get any messages that may be waiting on the virtual wire
void ServiceVirtualWire()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
char str[VW_MAX_MESSAGE_LEN];
LogLine("Msg Received From Virtual Wire...", strlen("Msg Received From Virtual Wire..."));
for (int i = 0; i < buflen; i++)
{
str[i] = buf[i];
//Serial.print(buf[i]);
}
str[buflen] = '\0';
//messages[msgCount] = str;
strcpy(messages[msgCount],str);
msgCount++;
LogLine(str, buflen);
}
}
void ServiceSerial()
{
static uint8_t buf[MAX_MSG_LENGTH_SERIAL];
static uint8_t index = 0;
while(Serial.available())
{
//Serial.println("serialAvail");
//Serial.println(Serial.read(), DEC);
if (index > MAX_MSG_LENGTH_SERIAL)
{
LogLine("Max Serial buffer reached... Flushing UART", strlen("Max Serial buffer reached... Flushing UART"));
Serial.flush();
index = 0;
}
else
{
buf[index] = Serial.read();
if (buf[index] == 13)
{
char str[MAX_MSG_LENGTH_SERIAL];
LogLine("Msg Received From Serial...", strlen("Msg Received From Serial..."));
for (int i = 0; i < index; i++)
{
str[i] = buf[i];
//Serial.print(buf[i]);
}
str[index] = '\0';
strcpy(messages[msgCount],str);
msgCount++;
LogLine(str, index);
index = 0;
}
else
{
index++;
}
}
}
}