Skip to content

Commit d4b4f51

Browse files
committed
Map batch PM correction as custom enum
1 parent 1c42ff0 commit d4b4f51

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

src/AgConfigure.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@ const char *PM_CORRECTION_ALGORITHM_NAMES[] = {
2525
[COR_ALGO_PM_UNKNOWN] = "-", // This is only to pass "non-trivial designated initializers" error
2626
[COR_ALGO_PM_NONE] = "none",
2727
[COR_ALGO_PM_EPA_2021] = "epa_2021",
28-
[COR_ALGO_PM_PMS5003_20220802] = "slr_PMS5003_20220802",
29-
[COR_ALGO_PM_PMS5003_20220803] = "slr_PMS5003_20220803",
30-
[COR_ALGO_PM_PMS5003_20220824] = "slr_PMS5003_20220824",
31-
[COR_ALGO_PM_PMS5003_20231030] = "slr_PMS5003_20231030",
32-
[COR_ALGO_PM_PMS5003_20231218] = "slr_PMS5003_20231218",
33-
[COR_ALGO_PM_PMS5003_20240104] = "slr_PMS5003_20240104",
28+
[COR_ALGO_PM_SLR_CUSTOM] = "custom",
3429
};
3530

3631
const char *TEMP_HUM_CORRECTION_ALGORITHM_NAMES[] = {
@@ -115,7 +110,7 @@ PMCorrectionAlgorithm Configuration::matchPmAlgorithm(String algorithm) {
115110
// If the input string matches an algorithm name, return the corresponding enum value
116111
// Else return Unknown
117112

118-
const size_t enumSize = COR_ALGO_PM_PMS5003_20240104 + 1; // Get the actual size of the enum
113+
const size_t enumSize = COR_ALGO_PM_SLR_CUSTOM + 1; // Get the actual size of the enum
119114
PMCorrectionAlgorithm result = COR_ALGO_PM_UNKNOWN;;
120115

121116
// Loop through enum values
@@ -125,6 +120,15 @@ PMCorrectionAlgorithm Configuration::matchPmAlgorithm(String algorithm) {
125120
}
126121
}
127122

123+
// If string not match from enum, check if correctionAlgorithm is one of the PM batch corrections
124+
if (result == COR_ALGO_PM_UNKNOWN) {
125+
// Check the substring "slr_PMS5003_xxxxxxxx"
126+
if (algorithm.substring(0, 11) == "slr_PMS5003") {
127+
// If it is, then its a custom correction
128+
result = COR_ALGO_PM_SLR_CUSTOM;
129+
}
130+
}
131+
128132
return result;
129133
}
130134

@@ -145,29 +149,27 @@ TempHumCorrectionAlgorithm Configuration::matchTempHumAlgorithm(String algorithm
145149

146150
bool Configuration::updatePmCorrection(JSONVar &json) {
147151
if (!json.hasOwnProperty("corrections")) {
148-
Serial.println("corrections not found");
152+
logInfo("corrections not found");
149153
return false;
150154
}
151155

152156
JSONVar corrections = json["corrections"];
153157
if (!corrections.hasOwnProperty("pm02")) {
154-
Serial.println("pm02 not found");
158+
logWarning("pm02 not found");
155159
return false;
156160
}
157161

158162
JSONVar pm02 = corrections["pm02"];
159163
if (!pm02.hasOwnProperty("correctionAlgorithm")) {
160-
Serial.println("correctionAlgorithm not found");
164+
logWarning("pm02 correctionAlgorithm not found");
161165
return false;
162166
}
163167

164-
// TODO: Need to have data type check, with error message response if invalid
165-
166168
// Check algorithm
167169
String algorithm = pm02["correctionAlgorithm"];
168170
PMCorrectionAlgorithm algo = matchPmAlgorithm(algorithm);
169171
if (algo == COR_ALGO_PM_UNKNOWN) {
170-
logInfo("Unknown algorithm");
172+
logWarning("Unknown algorithm");
171173
return false;
172174
}
173175
logInfo("Correction algorithm: " + algorithm);
@@ -191,7 +193,7 @@ bool Configuration::updatePmCorrection(JSONVar &json) {
191193

192194
// Check if pm02 has slr object
193195
if (!pm02.hasOwnProperty("slr")) {
194-
Serial.println("slr not found");
196+
logWarning("slr not found");
195197
return false;
196198
}
197199

@@ -200,7 +202,7 @@ bool Configuration::updatePmCorrection(JSONVar &json) {
200202
// Validate required slr properties exist
201203
if (!slr.hasOwnProperty("intercept") || !slr.hasOwnProperty("scalingFactor") ||
202204
!slr.hasOwnProperty("useEpa2021")) {
203-
Serial.println("Missing required slr properties");
205+
logWarning("Missing required slr properties");
204206
return false;
205207
}
206208

src/App/AppDef.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,7 @@ enum PMCorrectionAlgorithm {
9898
COR_ALGO_PM_UNKNOWN, // Unknown algorithm
9999
COR_ALGO_PM_NONE, // No PM correction
100100
COR_ALGO_PM_EPA_2021,
101-
COR_ALGO_PM_PMS5003_20220802,
102-
COR_ALGO_PM_PMS5003_20220803,
103-
COR_ALGO_PM_PMS5003_20220824,
104-
COR_ALGO_PM_PMS5003_20231030,
105-
COR_ALGO_PM_PMS5003_20231218,
106-
COR_ALGO_PM_PMS5003_20240104,
101+
COR_ALGO_PM_SLR_CUSTOM,
107102
};
108103

109104
// Don't change the order of the enum

0 commit comments

Comments
 (0)