8c2952457
김태훈
응용 프로그램 추가
|
1
|
#include "cook.h"
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
2
|
#include <QErrorMessage>
|
99b8066f4
김태훈
V0.1.1
|
3
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
4
5
|
static QErrorMessage *errorDialog = NULL;
static void showError(QString errorMessage)
|
99b8066f4
김태훈
V0.1.1
|
6
|
{
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
7
8
9
10
|
if (errorDialog == NULL)
{
errorDialog = new QErrorMessage;
errorDialog->setWindowModality(Qt::ApplicationModal);
|
b3e47756e
김태훈
소스 파일 일괄 변경
|
11
|
errorDialog->setGeometry(QRect(0, 511, 1080, 511));
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
12
|
}
|
99b8066f4
김태훈
V0.1.1
|
13
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
14
15
|
errorDialog->showMessage(errorMessage);
errorDialog->exec();
|
99b8066f4
김태훈
V0.1.1
|
16
|
}
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
17
18
19
20
|
Cook::Cook()
: type(Define::InvalidCookType),
isInitialized_(false), isLoaded_(false), isCoreTempValid_(false),
time_(0), coreTemp_(0)
|
99b8066f4
김태훈
V0.1.1
|
21
|
{
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
22
23
|
for (int i = 0; i < 5; i++)
configs[i].type = Define::InvalidConfig;
|
99b8066f4
김태훈
V0.1.1
|
24
|
}
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
25
26
|
Cook::Cook(Define::CookType type, QString root, QString name)
: Cook()
|
99b8066f4
김태훈
V0.1.1
|
27
|
{
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
28
29
|
if (!root.endsWith("/"))
root += "/";
|
99b8066f4
김태훈
V0.1.1
|
30
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
31
32
33
|
this->type = type;
this->root = root;
this->name = name;
|
99b8066f4
김태훈
V0.1.1
|
34
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
35
|
initialize();
|
6f96c947a
김태훈
GUI 0.1.4
|
36
|
}
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
37
|
void Cook::initialize()
|
99b8066f4
김태훈
V0.1.1
|
38
|
{
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
39
40
|
if (type == Define::InvalidCookType || root.isEmpty() || name.isEmpty())
return;
|
99b8066f4
김태훈
V0.1.1
|
41
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
42
43
44
45
46
47
|
QFile file(root + "config.csv");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
showError("File not found: " + file.fileName());
return;
}
|
99b8066f4
김태훈
V0.1.1
|
48
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
49
50
51
52
53
54
|
int lineCount = 0;
int configIndex = 0;
while (!file.atEnd())
{
if (configIndex == 5)
break;
|
99b8066f4
김태훈
V0.1.1
|
55
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
56
|
lineCount++;
|
99b8066f4
김태훈
V0.1.1
|
57
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
58
59
60
|
QString line = QString::fromUtf8(file.readLine()).trimmed();
if (line.isEmpty())
continue;
|
99b8066f4
김태훈
V0.1.1
|
61
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
62
63
|
if (line.startsWith("use"))
continue;
|
99b8066f4
김태훈
V0.1.1
|
64
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
65
|
QString errorMessage = QString("%3: %1, line %2").arg(file.fileName()).arg(lineCount);
|
99b8066f4
김태훈
V0.1.1
|
66
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
67
68
69
70
71
72
73
|
QString use = line.section(',', 0, 0).trimmed();
if (use.isEmpty())
{
showError(errorMessage.arg("Use column must be filled"));
file.close();
return;
}
|
99b8066f4
김태훈
V0.1.1
|
74
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
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
|
if (use == "yes")
{
CookConfig config;
config.type = Define::identifyConfigType(line.section(',', 1, 1).trimmed());
if (config.type == Define::InvalidConfig)
{
showError(errorMessage.arg("Invalid configuration type"));
file.close();
return;
}
bool ok;
config.maximum = line.section(',', 2, 2).trimmed().toInt(&ok);
if (!ok)
{
showError(errorMessage.arg("Invalid count"));
file.close();
return;
}
config.current = line.section(',', 3, 3).trimmed().toInt(&ok);
if (!ok)
{
showError(errorMessage.arg("Invalid default"));
file.close();
return;
}
configs[configIndex++] = config;
}
else
configs[configIndex++] = CookConfig { Define::ConfigNotUsed, 0, 0 };
|
99b8066f4
김태훈
V0.1.1
|
108
|
}
|
99b8066f4
김태훈
V0.1.1
|
109
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
110
|
file.close();
|
99b8066f4
김태훈
V0.1.1
|
111
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
112
113
|
for (int i = configIndex; i < 5; i++)
configs[configIndex++] = CookConfig { Define::ConfigNotUsed, 0, 0 };
|
99b8066f4
김태훈
V0.1.1
|
114
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
115
|
isInitialized_ = true;
|
99b8066f4
김태훈
V0.1.1
|
116
|
}
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
117
|
void Cook::setConfig(int first, int second, int third, int fourth, int fifth)
|
99b8066f4
김태훈
V0.1.1
|
118
|
{
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
119
120
|
if (!isInitialized())
return;
|
99b8066f4
김태훈
V0.1.1
|
121
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
122
123
124
125
126
|
int currents[5] = { first, second, third, fourth, fifth };
for (int i = 0; i < 5; i++)
{
if (configs[i].type == Define::ConfigNotUsed)
continue;
|
99b8066f4
김태훈
V0.1.1
|
127
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
128
129
130
131
132
133
|
if (configs[i].current != currents[i])
{
configs[i].current = currents[i];
isLoaded_ = false;
}
}
|
99b8066f4
김태훈
V0.1.1
|
134
|
}
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
135
|
void Cook::load()
|
99b8066f4
김태훈
V0.1.1
|
136
|
{
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
137
138
|
if (!isInitialized())
return;
|
99b8066f4
김태훈
V0.1.1
|
139
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
140
141
142
143
144
|
QString selection;
for (int i = 0; i < 5; i++)
{
if (configs[i].type == Define::ConfigNotUsed)
continue;
|
99b8066f4
김태훈
V0.1.1
|
145
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
146
147
|
selection += QString::number(configs[i].current);
}
|
99b8066f4
김태훈
V0.1.1
|
148
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
149
150
151
152
153
154
|
QFile dataFile(root + "data." + selection + ".csv");
if (!dataFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
showError("File not found: " + dataFile.fileName());
return;
}
|
99b8066f4
김태훈
V0.1.1
|
155
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
156
|
steps.clear();
|
99b8066f4
김태훈
V0.1.1
|
157
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
158
159
160
161
|
int lineCount = 0;
while (!dataFile.atEnd())
{
lineCount++;
|
99b8066f4
김태훈
V0.1.1
|
162
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
163
164
165
|
QString line = QString::fromUtf8(dataFile.readLine()).trimmed();
if (line.isEmpty())
continue;
|
99b8066f4
김태훈
V0.1.1
|
166
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
167
168
|
if (line.startsWith("type"))
continue;
|
99b8066f4
김태훈
V0.1.1
|
169
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
170
|
QString errorMessage = QString("%3: %1, line %2").arg(dataFile.fileName()).arg(lineCount);
|
99b8066f4
김태훈
V0.1.1
|
171
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
172
173
|
CookStep step;
bzero(&step, sizeof(step));
|
99b8066f4
김태훈
V0.1.1
|
174
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
175
176
177
178
179
180
181
182
183
184
185
186
|
step.type = Define::identifyStepType(line.section(',', 0, 0).trimmed());
switch (Define::classify(step.type))
{
case Define::InvalidClass:
showError(errorMessage.arg("Invalid type"));
continue;
case Define::DoorClass:
steps.append(step);
continue;
default:
break;
}
|
99b8066f4
김태훈
V0.1.1
|
187
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
188
189
190
191
192
193
|
step.mode = Define::identifyMode(line.section(',', 1, 1).trimmed());
if (step.mode == Define::InvalidMode)
{
showError(errorMessage.arg("Invalid mode"));
continue;
}
|
99b8066f4
김태훈
V0.1.1
|
194
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
195
|
bool ok;
|
99b8066f4
김태훈
V0.1.1
|
196
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
197
198
199
200
201
202
|
step.humidity = line.section(',', 3, 3).trimmed().toInt(&ok);
if (!ok || step.humidity < 0 || step.humidity > 100)
{
showError(errorMessage.arg("Invalid humidity"));
continue;
}
|
99b8066f4
김태훈
V0.1.1
|
203
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
204
205
206
207
208
209
|
step.temp = line.section(',', 4, 4).trimmed().toInt(&ok);
if (!ok || step.temp < 30 || step.temp > 300)
{
showError(errorMessage.arg("Invalid temperature"));
continue;
}
|
99b8066f4
김태훈
V0.1.1
|
210
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
211
212
213
214
215
216
|
step.fan = line.section(',', 6, 6).trimmed().toInt(&ok);
if (!ok || step.fan < 1 || step.fan > 5)
{
showError(errorMessage.arg("Invalid fan level"));
continue;
}
|
99b8066f4
김태훈
V0.1.1
|
217
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
218
219
220
221
222
|
if (step.type == Define::Preheat)
{
steps.append(step);
continue;
}
|
99b8066f4
김태훈
V0.1.1
|
223
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
224
225
226
227
228
229
|
step.time = line.section(',', 2, 2).trimmed().toInt(&ok);
if (!ok || step.time <= 0)
{
showError(errorMessage.arg("Invalid time"));
continue;
}
|
99b8066f4
김태훈
V0.1.1
|
230
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
231
232
233
234
235
236
237
238
|
int tInt = line.section(',', 5, 5).trimmed().toInt(&ok);
if (ok)
{
if (tInt < 0 || tInt > 100)
{
showError(errorMessage.arg("Invalid coreTemperature"));
continue;
}
|
99b8066f4
김태훈
V0.1.1
|
239
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
240
241
|
step.coreTemp = tInt;
}
|
99b8066f4
김태훈
V0.1.1
|
242
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
tInt = line.section(',', 7, 7).trimmed().toInt(&ok);
if (ok)
{
if (tInt < 0)
{
showError(errorMessage.arg("Invalid damper"));
continue;
}
step.dehumidification = tInt;
tInt = line.section(',', 9, 9).trimmed().toInt(&ok);
if (ok)
{
if (tInt < 0)
{
showError(errorMessage.arg("Invalid damperRepeat"));
continue;
}
step.dehumidificationRepeatDelay = tInt;
tInt = line.section(',', 11, 11).trimmed().toInt(&ok);
if (ok)
{
if (tInt < 0)
{
showError(errorMessage.arg("Invalid damperRepeatCount"));
continue;
}
step.dehumidificationRepeatCount = tInt;
}
}
}
|
99b8066f4
김태훈
V0.1.1
|
278
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
tInt = line.section(',', 8, 8).trimmed().toInt(&ok);
if (ok)
{
if (tInt < 0)
{
showError(errorMessage.arg("Invalid sideNozzle"));
continue;
}
step.humidification = tInt;
tInt = line.section(',', 10, 10).trimmed().toInt(&ok);
if (ok)
{
if (tInt < 0)
{
showError(errorMessage.arg("Invalid sideNozzleRepeat"));
continue;
}
step.humidificationRepeatDelay = tInt;
tInt = line.section(',', 12, 12).trimmed().toInt(&ok);
if (ok)
{
if (tInt < 0)
{
showError(errorMessage.arg("Invalid sideNozzleRepeatCount"));
continue;
}
step.humidificationRepeatCount = tInt;
}
}
}
|
99b8066f4
김태훈
V0.1.1
|
314
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
315
316
|
steps.append(step);
}
|
99b8066f4
김태훈
V0.1.1
|
317
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
318
|
dataFile.close();
|
99b8066f4
김태훈
V0.1.1
|
319
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
320
321
|
QFile processFile(root + "process.csv");
if (!processFile.open(QIODevice::ReadOnly | QIODevice::Text))
|
99b8066f4
김태훈
V0.1.1
|
322
|
{
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
323
324
|
showError("File not found: " + processFile.fileName());
return;
|
99b8066f4
김태훈
V0.1.1
|
325
|
}
|
99b8066f4
김태훈
V0.1.1
|
326
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
327
328
|
lineCount = 0;
while (!processFile.atEnd())
|
99b8066f4
김태훈
V0.1.1
|
329
|
{
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
lineCount++;
QString line = QString::fromUtf8(processFile.readLine()).trimmed();
if (line.isEmpty())
continue;
if (line.startsWith("type"))
continue;
QString errorMessage = QString("%3: %1, line %2").arg(processFile.fileName()).arg(lineCount);
Define::Process process = Define::identifyProcess(line);
if (process == Define::InvalidProcess)
{
showError(errorMessage.arg("Invalid type"));
continue;
}
processes.append(process);
|
99b8066f4
김태훈
V0.1.1
|
349
|
}
|
99b8066f4
김태훈
V0.1.1
|
350
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
351
352
353
354
355
356
|
isLoaded_ = true;
isCoreTempValid_ = false;
time_ = 0;
coreTemp_ = 0;
foreach (CookStep s, steps)
|
99b8066f4
김태훈
V0.1.1
|
357
|
{
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
358
359
360
361
362
363
364
|
if (s.coreTemp)
{
isCoreTempValid_ = true;
coreTemp_ = s.coreTemp;
}
time_ += s.time;
|
99b8066f4
김태훈
V0.1.1
|
365
366
|
}
}
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
367
|
bool Cook::isCoreTempValid()
|
99b8066f4
김태훈
V0.1.1
|
368
|
{
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
369
370
|
if (!isLoaded())
load();
|
99b8066f4
김태훈
V0.1.1
|
371
|
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
372
|
return isCoreTempValid_;
|
99b8066f4
김태훈
V0.1.1
|
373
|
}
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
374
|
int Cook::time()
|
99b8066f4
김태훈
V0.1.1
|
375
|
{
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
376
377
378
379
|
if (!isLoaded())
load();
return time_;
|
99b8066f4
김태훈
V0.1.1
|
380
|
}
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
381
|
int Cook::coreTemp()
|
99b8066f4
김태훈
V0.1.1
|
382
|
{
|
6a81d38e4
김태훈
자동 요리 관련 로직 전면 재작성
|
383
384
385
386
|
if (!isLoaded())
load();
return coreTemp_;
|
8c2952457
김태훈
응용 프로그램 추가
|
387
|
}
|