Ubuntu12.04.4_lts
2023-08-01 961efe36f62f7eba688d504ec0cdf3e1daa4dd74
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
#include <QPropertyAnimation>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "Common/filemanage.h"
#include "Common/mymessagebox.h"
#include "qprocess.h"
 
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setGeometry(QRect(0,0,800,480));
 
    upLoadBattery();
 
 
    work_thread = new Work_Thread();
    work_thread->start();
    connect(work_thread,SIGNAL(SentInterface(int)),this,SLOT(UpdateInterface(int)));
    work_thread->localData.Interface = FACE_HOME;
 
    one_sub_window_exist = false;
    main_page_flag = false;
    countindex = 0;
    timedelay = 0;
 
    counttime = new QTimer(this);
    connect(counttime,SIGNAL(timeout()),this,SLOT(showtime()));
    counttime->setInterval(1000);
 
    Autobox = new MessageBox( this, QMessageBox::Question, MB_Caption, tr("是否进行续测?60秒后自动续测"),
                    QMessageBox::Yes|QMessageBox::No);
 
    QTimer::singleShot(5000,this,SLOT(welcomeToMain()));
 
    #ifdef SOFT_ARM
    this->setWindowFlags(Qt::FramelessWindowHint);
    #endif
 
    connect(ui->pushButton_test,SIGNAL(pressed()),this,SLOT(btn_beep()));
    connect(ui->pushButton_data,SIGNAL(pressed()),this,SLOT(btn_beep()));
    connect(ui->pushButton_system,SIGNAL(pressed()),this,SLOT(btn_beep()));
    //connect(ui->pushButton_welcome,SIGNAL(pressed()),this,SLOT(btn_beep()));
 
    connect(ui->pushButton_welcome,SIGNAL(released()),this,SLOT(MainBtnAction()));
    connect(ui->pushButton_test,SIGNAL(released()),this,SLOT(MainBtnAction()));
    connect(ui->pushButton_data,SIGNAL(released()),this,SLOT(MainBtnAction()));
    connect(ui->pushButton_system,SIGNAL(released()),this,SLOT(MainBtnAction()));
 
    workpage = new Working_Page(this,work_thread);
    workpage->toHide();
 
    rs485_tcp = new SlaveCtrl(workpage);
    rs485_tcp->start();
 
    rs485pc = new SlavePC(workpage);
    rs485pc->start();
 
    QProcess::startDetached("insmod /usr/test/8723ds.ko");
    logoStrSet();
    SystemTime();
}
 
MainWindow::~MainWindow()
{
    delete counttime;
    delete Autobox;
    delete ui;
}
 
void MainWindow::logoStrSet(void)
{
    if(!ClassXML::ReadLOGOXml(logo))
    {
        logo.LOGOEN = true;
        logo.ModelLogo = "IDCE-2415NT";
        logo.MachineName = "蓄电池单体活化仪";
        logo.CompanyCName = "福 州 福 光 电 子 有 限 公 司";
        logo.CompanyEName = "FUZHOU FUGUANG ELECTRONICS Co.,LTD.";
        ClassXML::CreateLOGOXml(logo);
    }
 
    if(logo.MachineName == "使用图片")
    {
        ui->label_BG->setStyleSheet("border-image:url(/app/welcome.png);");
        ui->label_logo->setText(logo.ModelLogo);
 
        ui->label_LOGO->setVisible(false);
        ui->label_Type->setVisible(false);
        ui->label_Name->setVisible(false);
        ui->label_CName->setVisible(false);
        ui->label_EName->setVisible(false);
    }
    else
    {
        ui->label_logo->setText(logo.ModelLogo);
        if(logo.LOGOEN)
        {
            ui->label_LOGO->setVisible(true);
        }
        else
        {
            ui->label_LOGO->setVisible(false);
        }
        ui->label_Type->setText(logo.ModelLogo);
        ui->label_Name->setText(logo.MachineName);
        ui->label_CName->setText(logo.CompanyCName);
        ui->label_EName->setText(logo.CompanyEName);
    }
}
 
void MainWindow::MainBtnAction()
{
    //==========================================================================
    //将sender()强制类型转换为 QToolButton 指针
    //sender()返回发送信号的对象的指针,所以必须与信号槽有关
    //在这里,这是个槽,相关连的信号由button发送,所以返回触发这个槽的信号,也就是button值;
    QPushButton *pb = dynamic_cast<QPushButton*>(sender());
    //==========================================================================
    if(ui->pushButton_test == pb)
    {
        if(true == one_sub_window_exist)
        {
            return;
        }
        work_thread->enterpage_init();
        ui->label_test->setStyleSheet("color:white;");
        Choose_Page *choose = new Choose_Page(this,work_thread);
        one_sub_window_exist = true;
        choose->execCustom();
        one_sub_window_exist = false;
        if(work_thread->openWorkPage)
        {
            work_thread->openWorkPage = false;
            workpage->toShow(FACE_DIS);
        }
    }
    else if(ui->pushButton_data == pb)
    {
        if(true == one_sub_window_exist)
        {
            return;
        }
        ui->label_data->setStyleSheet("color:white;");
        Data_Page *data = new Data_Page(this,work_thread);
        one_sub_window_exist = true;
        data->execCustom();
        one_sub_window_exist = false;
    }
    else if(ui->pushButton_system == pb)
    {
        if(true == one_sub_window_exist)
        {
            return;
        }
        ui->label_system->setStyleSheet("color:white;");
        SysSet_Page *sysset = new SysSet_Page(this,work_thread,rs485_tcp);
        one_sub_window_exist = true;
        sysset->execCustom();
        one_sub_window_exist = false;
    }
    else if(ui->pushButton_welcome == pb)
    {
        welcomeToMain();
    }
}
 
//************更新时间*****************//
void MainWindow::SystemTime(void)
{
    checkIcon();
    QDateTime time = QDateTime::currentDateTime();//获取系统现在的时间
    QString str = time.toString("yyyy-MM-dd hh:mm:ss"); //设置显示格式
    ui->label_Time->setText(str);
    if(IF_RESTART){
        if((countindex++) > 57){//60 30s
            work_thread->set_app_checkcount();
            countindex = 0;
        }
    }
    QTimer::singleShot(500, this, SLOT(SystemTime()));
}
 
void MainWindow::checkIcon()
{
    if(work_thread->iconState.monomerState){
        if(work_thread->get_mon_source()==MONO_TYPE_WIRED)
        {
            ui->label_MON->setStyleSheet("image: url(:/new/prefix1/1.png);");
        }
        else
        {
            if(mon_use_type == 2)
                ui->label_MON->setStyleSheet("border-image: url(:/new/prefix1/lora_mon.png);");
            else
                ui->label_MON->setStyleSheet("border-image: url(:/new/prefix1/mon.png);");
        }
    }
    else
        ui->label_MON->setStyleSheet("");
 
    if(work_thread->iconState.usbState)
        ui->label_USB->setPixmap(QPixmap(":new/prefix1/usb.png"));
    else
        ui->label_USB->setPixmap(QPixmap(""));
    if(work_thread->iconState.wifiState)
        ui->label_WIFI->setStyleSheet("border-image: url(:/new/prefix1/wificonnect.png);");
    else
        ui->label_WIFI->setStyleSheet("");
}
 
void MainWindow::btn_beep(void)
{
    BuzzerDrv BD;
    BD.BuzzerBeep(50);
    QPushButton *pb = dynamic_cast<QPushButton*>(sender());
    //==========================================================================
    if(ui->pushButton_test == pb)
    {
        ui->label_test->setStyleSheet("color:yellow;");
    }
    else if(ui->pushButton_data == pb)
    {
        ui->label_data->setStyleSheet("color:yellow;");
    }
    else if(ui->pushButton_system == pb)
    {
        ui->label_system->setStyleSheet("color:yellow;");
    }
}
 
void MainWindow::welcomeToMain(void)
{
    if(!main_page_flag) //未点击屏幕,自动进入主界面
    {
        main_page_flag = true;
 
        BuzzerDrv BD;
        BD.BuzzerBeep(50);
        WidgetHorizontalScroll(ui->widget_3,1);
 
        QTimer::singleShot(100,this,SLOT(checkROM()));
 
        if(IF_RESTART)
            continuetestCheck();
        else
            work_thread->set_ifinit(true);
    }
}
 
void MainWindow::checkROM(void)
{
    int filecount = filemanage->FindLocalFileFromPath(dataDir,dataType);
    if(filecount>=MaxDataNum)
        popBox(tr("内存已满,请及时清理!"));
}
 
void MainWindow::upLoadBattery()
{
    TEST_PARAM_XML test_param_xml;
#if PageType == FBI48CT //FBI机型没有放电模式,但有充电功能,需把test_mode置为ONline_working
    test_param_xml.test_mode = ONline_working;
#else
    test_param_xml.test_mode = OFFline_working;
#endif
    test_param_xml.acstop_op = ACOFF_CONTINUE;
    test_param_xml.nominal_cap = 1000;
    test_param_xml.hourly_rate = 10;
    test_param_xml.preset_cur = 100;
    test_param_xml.preset_cap = 1000;
    test_param_xml.preset_time = 600;
    test_param_xml.mon_vol = 20;
    test_param_xml.mon_lower = 180;
    test_param_xml.group_lower = VolTooLow;
 
    test_param_xml.mon_number = 108;
    test_param_xml.group_number = 1;
    test_param_xml.lower_number = 1;
    test_param_xml.onlinevol_lowlimit = onlinevollow;
    test_param_xml.booster_ceiling = 552;
    test_param_xml.charge_limit = 300;
    test_param_xml.temp_High = 500;
 
    test_param_xml.discharge_mode = 0;
    test_param_xml.preset_power = MinPower;
 
    ClassXML::CreateTestParamXml(Default_Battery,test_param_xml);
}
 
void MainWindow::WidgetHorizontalScroll(QWidget *widget, int index)
{
    QPropertyAnimation *animation = new QPropertyAnimation(widget, "geometry");
    animation->setDuration(10);
    QRect rect = widget->geometry();
    animation->setEndValue(QRect((0-index)*800, rect.y(),
                                 widget->width(), widget->height()));
    animation->start(QPropertyAnimation::DeleteWhenStopped);
}
 
//************告警窗口*****************//
void MainWindow::popBox(QString msg)
{
    MessageBox box( this, QMessageBox::Warning,MB_Caption, msg,
            QMessageBox::Ok,
            QMessageBox::Ok,
            work_thread);
    box.exec();
}
 
void MainWindow::UpdateInterface(int interface)
{
    if(work_thread->localData.Interface != interface)
    {
        switch(work_thread->localData.Interface)
        {
            case FACE_CHAR:
            case FACE_DIS:
                workpage->toHide();
                one_sub_window_exist = false;
                break;
            default:
                one_sub_window_exist = false;
                break;
        }
    }
    if(interface == FACE_DIS)
    {
        if(work_thread->iconState.wifiState)
            work_thread->enterpage_init();
        workpage->toShow(FACE_DIS);
    }
    else if(interface == FACE_CHAR)
    {
        if(work_thread->iconState.wifiState)
            work_thread->enterpage_init();
        workpage->toShow(FACE_CHAR);
    }
}
 
void MainWindow::continuetestCheck(){
    CHECK_DATA check_data;
    int page_index = FACE_HOME;
    if(Check_Obj::RTest_Data(check_data)){//读取成功
        if(check_data.workstate!=WorkStopped){
            if(check_data.workstate == Charging || check_data.workstate == Paused_charge){
                page_index = FACE_CHAR;
            }
            else {
                page_index = FACE_DIS;
            }
        }
        else {
            work_thread->setPowerCtrl(POWER_CTRL_INIT);
            work_thread->set_ifinit(true);
        }
    }
    else {//读取失败
        work_thread->setPowerCtrl(POWER_CTRL_INIT);
        work_thread->set_ifinit(true);
    }
    if(page_index != FACE_HOME){
//        qDebug()<<"工作状态:"<<work_thread->localData.Work_State;
        if(work_thread->localData.Work_State == 0){//接触器已断开
//            qDebug()<<"接触器已断开";
            work_thread->setPowerCtrl(POWER_CTRL_INIT);
            if(check_data.workstate == Discharging || (check_data.workstate == Paused_charge && PageType!=IDCE48CT && check_data.alarmstate!=CPPauseNullCharging)|| check_data.workstate == Paused_Dischg  || check_data.workstate == WaitForCharging ||
              (check_data.workstate == Charging  && check_data.alarmstate != CPNullCharging)){
                work_thread->RecvSysCtrlCMD(work_thread->CMD_StartFanWork,NULL);//开风扇
                if(check_data.workstate == Discharging)
                    work_thread->ctrlJDQ();
            }
            work_thread->set_ifinit(true);
            Autobox->setText(tr("是否进行续测?60秒后自动续测"));
            Autobox->set_yes_btn_text(false,(tr("是(")+QString::number(5-timedelay)+")"));
            counttime->start();
            Autobox->exec();
            if(Autobox == NULL)//不点击自动进入
            {
                FBO_DATA fbo_data;
                if(Check_Obj::Read_Fbo_Data(check_data.testfilename,fbo_data)){
                    UpdateInterface(page_index);
                    workpage->ContinueTest(check_data,fbo_data);
                }
            }
            else
            {
                counttime->stop();//2019-12-17
                if(Autobox->result()!=QMessageBox::Yes)
                {
                    check_data.workstate = WorkStopped;
                    Check_Obj::MTest_Data(check_data,false);
                    FBO_DATA fbo_data;
                    if(Check_Obj::Read_Fbo_Data(check_data.testfilename,fbo_data)){
                        work_thread->WriteEndFile(check_data.testfilename,fbo_data);
                    }
                }
                else
                {
                    FBO_DATA fbo_data;
                    if(Check_Obj::Read_Fbo_Data(check_data.testfilename,fbo_data)){
                        UpdateInterface(page_index);
                        workpage->ContinueTest(check_data,fbo_data);
                    }
                }
            }
        }
        else {//接触器未断开,直接开始
//            qDebug()<<"接触器未断开,直接开始";
            work_thread->setPowerCtrl(check_data.PowerCtrl);
            work_thread->set_ifinit(false);
            FBO_DATA fbo_data;
            if(Check_Obj::Read_Fbo_Data(check_data.testfilename,fbo_data)){
                UpdateInterface(page_index);
                workpage->ContinueTest(check_data,fbo_data);
            }
            work_thread->set_ifinit(true);
        }
    }
}
 
void MainWindow::showtime()
{
    if(timedelay == 59)
    {
        counttime->stop();
        Autobox->accept();
        Autobox = NULL;
        return;
    }
 
    Autobox->setText(tr("是否进行续测?")+QString::number(59-timedelay)+tr("秒后自动续测"));
 
    if(timedelay<=3){
        Autobox->set_yes_btn_text(false,(tr("是(")+QString::number(4-timedelay)+")"));
    }
    else
    {
        Autobox->set_yes_btn_text(true,tr("是"));
        Autobox->setDefaultButton(QMessageBox::Yes);
    }
 
    timedelay++;
}