-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
741 lines (618 loc) · 25 KB
/
mainwindow.cpp
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
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
278
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <unistd.h>
#include <QWSServer>
#include <QDateTime>
#include <QDebug>
#include <QPainter>
#include <QMetaType> //注册元类型
//注册元类型
Q_DECLARE_METATYPE(UART_SAMPLE_START)
Q_DECLARE_METATYPE(PRU_SAMPLE_START)
Q_DECLARE_METATYPE(SHT21_AIR_SAMPLE_START)
//读取界面参数并发通知逻辑线程开始数据采集
GUI_Para gui_para;
//该全局变量向逻辑线程表明,当前应该发send_to_GUI_enbale_start()通知GUI
//线程使能start按钮,准备下一次采样,还是发send_to_GUI_quit_application()
//通知GUI线程退出应用程序。
bool quit_flag = false;
//队列最大长度
extern int compress_data_queue_max_len;
extern int upload_file_queue_max_len;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//界面控件初始化
GUI_init();
/* 隐藏鼠标 */
QWSServer::setCursorVisible(false);
/* 启动程序时总是显示第一个选项卡 */
ui->tabWidget->setCurrentIndex(0);
/* 实例化一个tab页用于绘图 */
uart_plot_widget = new Uart_Plot_Widget(this);
ui->tabWidget->addTab(uart_plot_widget, "uart");
/* 实例化一个tab页用于绘图 */
pru_plot_widget = new PRU_Plot_Widget(this);
ui->tabWidget->addTab(pru_plot_widget, "pru");
/* 实例化一个tab页用于绘图 */
air_plot_widget = new Air_Plot_Widget(this);
ui->tabWidget->addTab(air_plot_widget, "air");
/* 实例化一个tab页用于绘图 */
sht21_plot_widget = new Sht21_Plot_Widget(this);
ui->tabWidget->addTab(sht21_plot_widget, "sht21");
/* 开机显示时间 */
QDateTime datetime = QDateTime::currentDateTime();
ui->datetime->setText(datetime.toString("yyyy.MM.dd hh:mm"));
/* 实例化一个定时器并启动,用于更新时间 */
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(timerUpdate()));
timer->start(1000 * 60);//一分钟更新一次时间
//将参数界面2中的checkbox的槽函数连接
connect(ui->checkBox, SIGNAL(stateChanged(int)), SLOT(checkbox_changed(int)));
connect(ui->checkBox_2, SIGNAL(stateChanged(int)), SLOT(checkbox_2_changed(int)));
connect(ui->checkBox_3, SIGNAL(stateChanged(int)), SLOT(checkbox_3_changed(int)));
connect(ui->checkBox_4, SIGNAL(stateChanged(int)), SLOT(checkbox_4_changed(int)));
connect(ui->checkBox_5, SIGNAL(stateChanged(int)), SLOT(checkbox_5_changed(int)));
connect(ui->checkBox_6, SIGNAL(stateChanged(int)), SLOT(checkbox_6_changed(int)));
connect(ui->checkBox_7, SIGNAL(stateChanged(int)), SLOT(checkbox_7_changed(int)));
connect(ui->checkBox_8, SIGNAL(stateChanged(int)), SLOT(checkbox_8_changed(int)));
connect(ui->checkBox_9, SIGNAL(stateChanged(int)), SLOT(checkbox_9_changed(int)));
connect(ui->checkBox_10, SIGNAL(stateChanged(int)), SLOT(checkbox_10_changed(int)));
connect(ui->checkBox_11, SIGNAL(stateChanged(int)), SLOT(checkbox_11_changed(int)));
connect(ui->checkBox_13, SIGNAL(stateChanged(int)), SLOT(checkbox_13_changed(int)), Qt::QueuedConnection);
//使能START按钮,禁能STOP按钮
ui->pushButton->setEnabled(true);
ui->pushButton_2->setEnabled(false);
/* 注册元类型 */
qRegisterMetaType <UART_SAMPLE_START>("UART_SAMPLE_START");
qRegisterMetaType <PRU_SAMPLE_START>("PRU_SAMPLE_START");
qRegisterMetaType <SHT21_AIR_SAMPLE_START>("SHT21_AIR_SAMPLE_START");
/* 实例化三个线程并启动,将三个子线程相关的信号关联到GUI主线程的槽函数 */
uartthread = new UartThread ();
logicthread = new LogicThread ();
pruthread = new PRUThread ();
sht21_air_thread = new Sht21_Air_Thread ();//用于采集温湿度数据和空气质量数据
/* GUI线程发送信号通知逻辑线程开始解析数据并启动其他线程的采集任务 */
connect(this, SIGNAL(send_to_logic_GUI_data()), logicthread, SLOT(recei_parse_GUI_data()), Qt::QueuedConnection);
/* 逻辑线程发送信号通知串口线程开始采集数据 */
connect(logicthread, SIGNAL(send_to_uartthread_sample_start(UART_SAMPLE_START)), uartthread, SLOT(recei_fro_logicthread_sample_start(UART_SAMPLE_START)), Qt::QueuedConnection);
/* 逻辑线程发送信号通知串口线程停止采集数据 */
connect(logicthread, SIGNAL(send_to_uartthread_sample_stop()), uartthread, SLOT(recei_fro_logicthread_sample_stop()), Qt::QueuedConnection);
/* 串口线程通知逻辑线程数据采集完成 */
connect(uartthread, SIGNAL(send_to_logic_uart_sample_complete(int)), logicthread, SLOT(receive_task_report(int)), Qt::QueuedConnection);
connect(pruthread, SIGNAL(send_to_logic_pru_sample_complete(int)), logicthread, SLOT(receive_task_report(int)), Qt::QueuedConnection);
/* 串口线程通知绘图选项卡进行绘图 */
connect(uartthread, SIGNAL(send_to_plot_uart_curve()), uart_plot_widget, SLOT(recei_fro_uartthread()), Qt::QueuedConnection);
/* pru线程通知绘图选项卡进行绘图 */
connect(pruthread, SIGNAL(send_to_plot_pru_curve()), pru_plot_widget, SLOT(recei_fro_pruthread()), Qt::QueuedConnection);
/* sht21_air线程通知sht21绘图选项卡进行绘图 */
connect(sht21_air_thread, SIGNAL(send_to_plot_sht21_curve()), sht21_plot_widget, SLOT(recei_fro_sht21_air_thread_sht21_plot()), Qt::QueuedConnection);
connect(sht21_air_thread, SIGNAL(send_to_plot_air_curve()), air_plot_widget, SLOT(recei_fro_sht21_air_thread_air_plot()), Qt::QueuedConnection);
/* 逻辑线程通知pru线程开始采集数据 */
connect(logicthread, SIGNAL(send_to_pruthread_pru_sample_start(PRU_SAMPLE_START)), pruthread, SLOT(recei_fro_logicthread_pru_sample_start(PRU_SAMPLE_START)), Qt::QueuedConnection);
/* GUI线程通知逻辑线程stop按钮被按下 */
connect(this, SIGNAL(send_to_logic_stop_pressed()), logicthread, SLOT(logictimer_timeout()), Qt::QueuedConnection);
/* pru线程收到逻辑线程的信号后,执行结束pru采样任务的槽函数 */
connect(logicthread, SIGNAL(send_to_pruthread_sample_stop()), pruthread, SLOT(recei_fro_logicthread_pru_sample_stop()), Qt::QueuedConnection);
/* 逻辑线程发送信号给GUI线程,所有任务已经结束,并通知其使能start按钮 */
connect(logicthread, SIGNAL(send_to_GUI_enbale_start()), this, SLOT(recei_fro_logicthread_enable_start()), Qt::QueuedConnection);
/* 逻辑线程通知sht21_air线程开始采集数据 */
connect(logicthread, SIGNAL(send_to_sht21_air_thread_sample_start(SHT21_AIR_SAMPLE_START)), sht21_air_thread, SLOT(recei_fro_logicthread_sht21_air_sample_start(SHT21_AIR_SAMPLE_START)), Qt::QueuedConnection);
/* 逻辑线程通知sht21_air线程停止采集数据 */
connect(logicthread, SIGNAL(send_to_sht21_air_thread_sample_stop()), sht21_air_thread, SLOT(recei_fro_logicthread_sht21_air_sample_stop()), Qt::QueuedConnection);
/* sht21_air线程通知逻辑线程采样结束 */
connect(sht21_air_thread, SIGNAL(send_to_logic_sht21_air_sample_complete(int)), logicthread, SLOT(receive_task_report(int)), Qt::QueuedConnection);
/* quit按钮按下通知逻辑线程结束其他线程的采集任务 */
connect(this, SIGNAL(send_to_logicthread_abort_sample_tasks()), logicthread, SLOT(logictimer_timeout()), Qt::QueuedConnection);
connect(logicthread, SIGNAL(send_to_GUI_quit_application()), this, SLOT(recei_fro_logicthread_quit_application()), Qt::QueuedConnection);
connect(this, SIGNAL(quit_application()), this, SLOT(recei_fro_logicthread_quit_application()), Qt::QueuedConnection);
/* PRU线程可以启动数据压缩进程 */
connect(pruthread, SIGNAL(send_to_logicthread_start_compress_data()), logicthread, SLOT(compress_queue_check()), Qt::QueuedConnection);
/* 从逻辑线程接收数据,根据数据确定upload复选框状态以及label内容 */
connect(logicthread, SIGNAL(send_to_GUI_netreport(int)), this, SLOT(recei_fro_logicthread_netreport(int)), Qt::QueuedConnection);
//GUI线程上的upload复选框状态控制逻辑线程中上传文件的功能的开启与关闭
connect(this, SIGNAL(control_upload_script(int)), logicthread, SLOT(upload_queue_check(int)), Qt::QueuedConnection);
uartthread->start();
logicthread->start();
pruthread->start();
sht21_air_thread->start();
/*
逻辑线程根据脚本返回的代码获知网络状态,从而要从软件内部更新upload复选框状态,
而upload复选框状态的变化会触发槽函数checkbox_13_changed(int state)中再次发出
信号触发逻辑线程的槽函数进行关闭或者打开上传功能,为了避免连环触发,设置此变量。
*/
upload_checkbox_13_trige_from_software = false;
}
MainWindow::~MainWindow()
{
delete ui;
delete uartthread;
delete logicthread;
delete sht21_air_thread;
}
void MainWindow::on_quit_clicked()
{
ui->quit->setEnabled(false);
if(ui->pushButton->isEnabled())//如果start按钮处于使能状态说明,当前没有采样任务,quit按钮按下后可以直接退出程序
{
emit quit_application();
qDebug("quit application");
}
else//如果start按钮处于禁能状态说明,当前有采样任务正在进行,quit按钮按下后应该先通知逻辑线程终止各采集任务
{
quit_flag = true;
emit send_to_logicthread_abort_sample_tasks();
qDebug("abort sample tasks, then quit application");
}
}
void MainWindow::recei_fro_logicthread_quit_application()
{
//检查线程是否为运行状态
if(uartthread->isRunning())
uartthread->stop();
while(!uartthread->isFinished());//确认线程是否停止
if(pruthread->isRunning())
pruthread->stop();
while(!pruthread->isFinished());
if(sht21_air_thread->isRunning())
sht21_air_thread->stop();
while(!sht21_air_thread->isFinished());
if(logicthread->isRunning())
logicthread->stop();
while(!logicthread->isFinished());
pid_t new_pid;
char *const arg_shutdown[] = {"shutdown","-h","now",NULL};
if(ui->checkBox_12->isChecked())//如果勾选了quit按钮旁边的复选框则退出应用程序后会自动关机
{
new_pid = fork();
if(new_pid < 0)
qDebug("fork() failed!\n");
else if(new_pid == 0)//子进程运行内容
{
sleep(5);//seconds秒钟后关机
if(execve("/sbin/shutdown", arg_shutdown, NULL) == -1)
{
qDebug("shutdown in 5 seconds");
}
}
else//主进程运行内容
{
qDebug("Application quit!\n");
}
}
/* 退出事件循环,结束程序 */
QApplication *p;
p->quit();
}
void MainWindow::timerUpdate()
{
QDateTime datetime = QDateTime::currentDateTime();
ui->datetime->setText(datetime.toString("yyyy.MM.dd hh:mm"));
}
//参数解析,读取界面参数并发通知逻辑线程开始数据采集
void MainWindow::on_pushButton_clicked()
{
//采样模式解析
if(ui->radioButton_3->isChecked())
{
gui_para.sample_mode = TIMING;
qDebug() << "sample mode = TIMING";
}
if(ui->radioButton_4->isChecked())
{
gui_para.sample_mode = MONITOR;
qDebug() << "sample mode = MONITOR";
}
gui_para.sample_time_hours = ui->spinBox->value();
gui_para.sample_time_minutes = ui->spinBox_3->value();
gui_para.sample_time_seconds = ui->spinBox_2->value();
qDebug() << "sample time: "
<< gui_para.sample_time_hours << "hours "
<< gui_para.sample_time_minutes << "minutes "
<< gui_para.sample_time_seconds << "seconds";
gui_para.plot_data_num_dust = ui->spinBox_8->value();
gui_para.plot_data_num_air = ui->spinBox_9->value();
gui_para.plot_data_num_sht21 = ui->spinBox_10->value();
gui_para.plot_data_num_sensor = ui->spinBox_11->value();
qDebug() << "plot_data_num_dust = " << gui_para.plot_data_num_dust;
qDebug() << "plot_data_num_air = " << gui_para.plot_data_num_air;
qDebug() << "plot_data_num_sht21 = " << gui_para.plot_data_num_sht21;
qDebug() << "plot_data_num_sensor = " << gui_para.plot_data_num_sensor;
gui_para.sample_period_air_ms = ui->spinBox_5->value();
gui_para.sample_period_sht21_s = ui->spinBox_6->value();
gui_para.sample_freq_sensor = ui->doubleSpinBox->value();
qDebug() << "sample_period_air_ms = " << gui_para.sample_period_air_ms;
qDebug() << "sample_period_sht21_s = " << gui_para.sample_period_sht21_s;
qDebug() << "sample_freq_sensor = " << gui_para.sample_freq_sensor;
gui_para.user_string = ui->lineEdit->text();
qDebug() << "user_string = " << gui_para.user_string;
if(ui->radioButton_5->isChecked())
{
gui_para.data_save_mode = LOCAL_HOST;
qDebug() << "data save mode = LOCAL_HOST";
}
if(ui->radioButton->isChecked())
{
gui_para.data_save_mode = USB_DEVICE;
qDebug() << "data save mode = USB_DEVICE";
}
emit send_to_logic_GUI_data();
ui->pushButton->setEnabled(false);//禁能start按钮
ui->pushButton_2->setEnabled(true);//使能stop按钮
}
//如果选择了定时模式,则要把hours minutes, seconds输入框使能
void MainWindow::on_radioButton_3_clicked()
{
qDebug() << "H:M:S is enabled";
ui->spinBox->setEnabled(true);
ui->spinBox_2->setEnabled(true);
ui->spinBox_3->setEnabled(true);
}
//如果选择了监测模式,则要把hours minutes, seconds输入框禁能
void MainWindow::on_radioButton_4_clicked()
{
qDebug() << "H:M:S is disabled";
ui->spinBox->setEnabled(false);
ui->spinBox_2->setEnabled(false);
ui->spinBox_3->setEnabled(false);
}
//将参数界面2中的checkbox的槽函数连接
void MainWindow::checkbox_changed(int state)
{
if(state == Qt::Unchecked)
{
gui_para.AIN[7] = false;
}
else if(state == Qt::Checked)
{
gui_para.AIN[7] = true;
}
}
void MainWindow::checkbox_2_changed(int state)
{
if(state == Qt::Unchecked)
{
gui_para.AIN[5] = false;
}
else if(state == Qt::Checked)
{
gui_para.AIN[5] = true;
}
}
void MainWindow::checkbox_3_changed(int state)
{
if(state == Qt::Unchecked)
{
gui_para.AIN[0] = false;
}
else if(state == Qt::Checked)
{
gui_para.AIN[0] = true;
}
}
void MainWindow::checkbox_4_changed(int state)
{
if(state == Qt::Unchecked)
{
gui_para.AIN[1] = false;
}
else if(state == Qt::Checked)
{
gui_para.AIN[1] = true;
}
}
void MainWindow::checkbox_5_changed(int state)
{
if(state == Qt::Unchecked)
{
gui_para.AIN[2] = false;
}
else if(state == Qt::Checked)
{
gui_para.AIN[2] = true;
}
}
void MainWindow::checkbox_6_changed(int state)
{
if(state == Qt::Unchecked)
{
gui_para.AIN[6] = false;
}
else if(state == Qt::Checked)
{
gui_para.AIN[6] = true;
}
}
void MainWindow::checkbox_7_changed(int state)
{
if(state == Qt::Unchecked)
{
gui_para.AIN[3] = false;
}
else if(state == Qt::Checked)
{
gui_para.AIN[3] = true;
}
}
void MainWindow::checkbox_8_changed(int state)
{
if(state == Qt::Unchecked)
{
gui_para.AIN[4] = false;
}
else if(state == Qt::Checked)
{
gui_para.AIN[4] = true;
}
}
void MainWindow::checkbox_9_changed(int state)
{
if(state == Qt::Unchecked)
{
gui_para.AIN[8] = false;
}
else if(state == Qt::Checked)
{
gui_para.AIN[8] = true;
}
}
void MainWindow::checkbox_10_changed(int state)
{
if(state == Qt::Unchecked)
{
gui_para.AIN[9] = false;
}
else if(state == Qt::Checked)
{
gui_para.AIN[9] = true;
}
}
void MainWindow::checkbox_11_changed(int state)
{
if(state == Qt::Unchecked)
{
gui_para.AIN[10] = false;
}
else if(state == Qt::Checked)
{
gui_para.AIN[10] = true;
}
}
//此函数会被用户在界面上勾选upload复选框而触发以及
//软件内部对upload复选框的状态更改的触发
void MainWindow::checkbox_13_changed(int state)
{
if(!upload_checkbox_13_trige_from_software)//如果外部触发
{
int mode;
if(state == Qt::Unchecked)
{
//关闭文件上传
qDebug() << "upload close";
ui->label_16->setText(QString("Upload close"));
mode = UPLOAD_CLOSE;
emit control_upload_script(mode);
}
else if(state == Qt::Checked)
{
//启动文件上传
qDebug() << "upload open";
ui->label_16->setText(QString("Upload is openning"));
mode = UPLOAD_OPEN;
emit control_upload_script(mode);
}
}
else//如果软件内部触发
upload_checkbox_13_trige_from_software = false;
}
void MainWindow::on_pushButton_2_clicked()
{
//通知逻辑线程stop按钮被按下
emit send_to_logic_stop_pressed();
//同时禁能stop按钮
ui->pushButton_2->setEnabled(false);
}
void MainWindow::recei_fro_logicthread_enable_start()
{
//使能start按钮
ui->pushButton->setEnabled(true);
ui->pushButton_2->setEnabled(false);
qDebug("enable start button, and disable stop button");
}
void MainWindow::GUI_init()//从默认参数文件读取参数初始化界面
{
FILE *fp_default_para = NULL;
char temp_str[50] = {0};
char str[1024] = {0};
unsigned int i = 0;
//1、程序使用内置参数配置GUI_para或者使用默认参数文件来配置GUI_para
if((fp_default_para = fopen(DEFAULT_PARA_FILE, "r")) != NULL)//使用默认参数文件来配置GUI_para
{
fscanf(fp_default_para, "sample_time_hours =\t%d\n", &gui_para.sample_time_hours);
fscanf(fp_default_para, "sample_time_minutes =\t%d\n", &gui_para.sample_time_minutes);
fscanf(fp_default_para, "sample_time_seconds =\t%d\n\n", &gui_para.sample_time_seconds);
fscanf(fp_default_para, "plot_data_num_dust =\t%d\n", &gui_para.plot_data_num_dust);
fscanf(fp_default_para, "plot_data_num_air =\t%d\n", &gui_para.plot_data_num_air);
fscanf(fp_default_para, "plot_data_num_sht21 =\t%d\n", &gui_para.plot_data_num_sht21);
fscanf(fp_default_para, "plot_data_num_sensor =\t%d\n\n", &gui_para.plot_data_num_sensor);
fscanf(fp_default_para, "sample_period_air_ms =\t%d\n", &gui_para.sample_period_air_ms);
fscanf(fp_default_para, "sample_period_sht21_s =\t%d\n", &gui_para.sample_period_sht21_s);
fscanf(fp_default_para, "sample_freq_sensor =\t%lf\n\n", &gui_para.sample_freq_sensor);
fscanf(fp_default_para, "user_string =\t%s\n", str);
gui_para.user_string = str;
fscanf(fp_default_para, "data_save_mode =\t%d\n\n", &gui_para.data_save_mode);
for(i = 0; i < 11; i++)
{
fscanf(fp_default_para, "%s =\t%u\n", temp_str, &gui_para.AIN[i]);
}
fscanf(fp_default_para, "\nsample_mode =\t%d\n\n", &gui_para.sample_mode);
fscanf(fp_default_para, "compress_data_queue_max_len =\t%u\n", &compress_data_queue_max_len);
fscanf(fp_default_para, "upload_file_queue_max_len =\t%u\n\n", &upload_file_queue_max_len);
fclose(fp_default_para);
}
else//程序使用内置参数配置GUI_para
{
gui_para.sample_time_hours = 0;
gui_para.sample_time_minutes = 3;
gui_para.sample_time_seconds = 5;
gui_para.plot_data_num_dust = 300;
gui_para.plot_data_num_air = 600;
gui_para.plot_data_num_sht21 = 100;
gui_para.plot_data_num_sensor = 1000;
gui_para.sample_period_air_ms = 100;
gui_para.sample_period_sht21_s = 1;
gui_para.sample_freq_sensor = 5000.0;
gui_para.user_string = QString("zhouyu");
gui_para.data_save_mode = 0;
gui_para.AIN[0] = 0;
gui_para.AIN[1] = 0;
gui_para.AIN[2] = 1;
gui_para.AIN[3] = 1;
gui_para.AIN[4] = 1;
gui_para.AIN[5] = 1;
gui_para.AIN[6] = 1;
gui_para.AIN[7] = 1;
gui_para.AIN[8] = 1;
gui_para.AIN[9] = 0;
gui_para.AIN[10] = 1;
gui_para.sample_mode = 0;
compress_data_queue_max_len = 1;
upload_file_queue_max_len = 5;
}
//2、根据GUI_para来设置GUI控件参数
ui->spinBox->setValue(gui_para.sample_time_hours);
ui->spinBox_3->setValue(gui_para.sample_time_minutes);
ui->spinBox_2->setValue(gui_para.sample_time_seconds);
ui->spinBox_8->setValue(gui_para.plot_data_num_dust);
ui->spinBox_9->setValue(gui_para.plot_data_num_air);
ui->spinBox_10->setValue(gui_para.plot_data_num_sht21);
ui->spinBox_11->setValue(gui_para.plot_data_num_sensor);
ui->spinBox_5->setValue(gui_para.sample_period_air_ms);
ui->spinBox_6->setValue(gui_para.sample_period_sht21_s);
//doublespinbox补充配置代码
ui->doubleSpinBox->setMinimum(0.0);
ui->doubleSpinBox->setMaximum(5000);
ui->doubleSpinBox->setSingleStep(0.01);
ui->doubleSpinBox->setValue(gui_para.sample_freq_sensor);
ui->lineEdit->setText(gui_para.user_string);
if(gui_para.data_save_mode == LOCAL_HOST)
{
ui->radioButton_5->setChecked(true);
ui->radioButton->setChecked(false);
}
if(gui_para.data_save_mode == USB_DEVICE)
{
ui->radioButton_5->setChecked(false);
ui->radioButton->setChecked(true);
}
if(gui_para.AIN[0] == 1)
ui->checkBox_3->setChecked(true);
else
ui->checkBox_3->setChecked(false);
if(gui_para.AIN[1] == 1)
ui->checkBox_4->setChecked(true);
else
ui->checkBox_4->setChecked(false);
if(gui_para.AIN[2] == 1)
ui->checkBox_5->setChecked(true);
else
ui->checkBox_5->setChecked(false);
if(gui_para.AIN[3] == 1)
ui->checkBox_7->setChecked(true);
else
ui->checkBox_7->setChecked(false);
if(gui_para.AIN[4] == 1)
ui->checkBox_8->setChecked(true);
else
ui->checkBox_8->setChecked(false);
if(gui_para.AIN[5] == 1)
ui->checkBox_2->setChecked(true);
else
ui->checkBox_2->setChecked(false);
if(gui_para.AIN[6] == 1)
ui->checkBox_6->setChecked(true);
else
ui->checkBox_6->setChecked(false);
if(gui_para.AIN[7] == 1)
ui->checkBox->setChecked(true);
else
ui->checkBox->setChecked(false);
if(gui_para.AIN[8] == 1)
ui->checkBox_9->setChecked(true);
else
ui->checkBox_9->setChecked(false);
if(gui_para.AIN[9] == 1)
ui->checkBox_10->setChecked(true);
else
ui->checkBox_10->setChecked(false);
if(gui_para.AIN[10] == 1)
ui->checkBox_11->setChecked(true);
else
ui->checkBox_11->setChecked(false);
if(gui_para.sample_mode == TIMING)
{
ui->radioButton_3->setChecked(true);
ui->radioButton_4->setChecked(false);
}
if(gui_para.sample_mode == MONITOR)
{
ui->radioButton_3->setChecked(false);
ui->radioButton_4->setChecked(true);
}
}
//从逻辑线程接收数据,根据数据确定upload复选框状态以及label内容
void MainWindow::recei_fro_logicthread_netreport(int exit_code)
{
if(exit_code == 0)
{
//upload复选框的状态是否要变更
if(!(ui->checkBox_13->isChecked()))//如果当前的状态为false
upload_checkbox_13_trige_from_software = true;
else
upload_checkbox_13_trige_from_software = false;
ui->checkBox_13->setChecked(true);
ui->label_16->setText(QString("scp succeed, network active"));
}
else if(exit_code == 1)
{
//upload复选框的状态是否要变更
if(ui->checkBox_13->isChecked())//如果当前的状态为true
upload_checkbox_13_trige_from_software = true;
else
upload_checkbox_13_trige_from_software = false;
ui->checkBox_13->setChecked(false);
ui->label_16->setText(QString("ping failed, Host not exist"));
}
else if(exit_code == 2)
{
//upload复选框的状态是否要变更
if(ui->checkBox_13->isChecked())//如果当前的状态为true
upload_checkbox_13_trige_from_software = true;
else
upload_checkbox_13_trige_from_software = false;
ui->checkBox_13->setChecked(false);
ui->label_16->setText(QString("scp failed, File not exist"));
}
else if(exit_code == 3)
{
//upload复选框的状态是否要变更
if(ui->checkBox_13->isChecked())//如果当前的状态为true
upload_checkbox_13_trige_from_software = true;
else
upload_checkbox_13_trige_from_software = false;
ui->checkBox_13->setChecked(false);
ui->label_16->setText(QString("scp failed, Acc or Path error"));
}
else if(exit_code == 4)
{
//upload复选框的状态是否要变更
if(!(ui->checkBox_13->isChecked()))//如果当前的状态为false
upload_checkbox_13_trige_from_software = true;
else
upload_checkbox_13_trige_from_software = false;
ui->checkBox_13->setChecked(true);
ui->label_16->setText(QString("ping succeed, network active"));
}
}