-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcc_functions.pde
115 lines (101 loc) · 2.31 KB
/
cc_functions.pde
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
// Functions to get data from CC128
int parseDataTmpr(int oldstate, char chr) {
newstate = oldstate;
if (newstate > 0) {
if (chr == startTmpr[sizeTmpr-newstate]) {
newstate--;
}
else {
newstate = sizeTmpr;
}
}
else if (newstate <= 0) {
newstate--;
if (chr == endChar) {
newstate = sizeTmpr;
}
}
return newstate;
}
int parseDataPwr(int oldstate, char chr) {
newstate = oldstate;
if (newstate > 0) {
if (chr == startPwr[sizePwr-newstate]) {
newstate--;
}
else {
newstate = sizePwr;
}
}
else if (newstate <= 0) {
newstate--;
if (chr == endChar) {
newstate = sizePwr;
}
}
return newstate;
}
int parseDataTime(int oldstate, char chr) {
newstate = oldstate;
if (newstate > 0) {
if (chr == startTime[sizeTime-newstate]) {
newstate--;
}
else {
newstate = sizeTime;
}
}
else if (newstate <= 0) {
newstate--;
if (chr == endChar) {
newstate = sizeTime;
}
}
return newstate;
}
void cc_read(){
readChar = currentcost.read();
// get data from CC128
if (readChar > 31) {
stateTime = parseDataTime(stateTime, readChar);
if (stateTime < 0) {
Time[abs(stateTime)-1] = readChar;
}
stateTmpr = parseDataTmpr(stateTmpr, readChar);
if (stateTmpr < 0) {
Tmpr[abs(stateTmpr)-1] = readChar;
}
statePwr = parseDataPwr(statePwr, readChar);
if (statePwr < 0) {
Pwr[abs(statePwr)-1] = readChar;
}
}
// finished collecting data from CC128
else if (readChar == 13) {
PwrNum = atol(Pwr);
TmprNum = atol(Tmpr);
Serial.print("################################## ");
Serial.println(Time);
strcpy(TimeChr, Time);
TmprDouble = strtod(Tmpr,NULL);
TmprDecimal = abs((TmprDouble - (int)TmprDouble) * 100); // convert decimal data to integer
// print debug information
Serial.flush();
Serial.println(" ");
Serial.print("Time: ");
Serial.print(TimeChr);
Serial.println(" ");
Serial.print("Pwr: ");
Serial.print(PwrNum);
Serial.print(" ");
Serial.print(" Tmpr: ");
Serial.print(" ");
Serial.print(TmprDouble);
Serial.print(" / ");
Serial.print(TmprNum);
Serial.print(" ");
Serial.print(TmprDecimal);
Serial.println(" ");
Serial.flush();
}
}