-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
2480 lines (2188 loc) · 70.2 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
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QByteArray>
#include <QSerialPortInfo>
#include <QDataStream>
#include <QFile>
#include <QBuffer>
#include <QElapsedTimer>
#include <QDebug>
#include <QFileDialog>
#include <QMessageBox>
#define EPSINON 0.000001
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
setWindowTitle("上位机 version:2023/10/9");
// loadFile(); //放开以后自动加载data
initUI();
m_reSendTimer.setInterval(1000);
connect(&m_reSendTimer,&QTimer::timeout,this,&MainWindow::slot_timeout);
// setAllBtnEnable(); //放开以后自动加载data
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::slot_recvData()
{
if(!m_pSerialPort->isOpen())
{
return;
}
QByteArray readData = m_pSerialPort->readAll();
qDebug()<<"RecvBuff:"<<readData.toHex().toUpper() <<"RecvSize:"<<readData.size();
if(readData.size() > 0)
{
//校验CRC
bool bAuthCRC = authCrc(readData);
if(!bAuthCRC)
{
return;
}
//protocol1
if(readData.size() == 10)
{
decodeProtocol1(readData);
}
//protocol2
else if(readData.size() == 6)
{
//解析返回数据包地址
decodeFlashAddr(readData);
}
//protocol2 read
else if(readData.size() == 26)
{
//解析返回数据包地址
decodeReadProtocol2Data(readData);
}
//身份认证权限
else if(readData.size() == 4)
{
decodeAuth(readData);
}
//退出
else if(readData.size() == 8)
{
decodeExit(readData);
}
}
}
void MainWindow::slot_errorOccurred(QSerialPort::SerialPortError error)
{
if(error != QSerialPort::NoError)
{
qDebug()<<error;
ui->statusbar->showMessage(QString("连接失败:Error Code %1").arg(error),5000);
}
}
void MainWindow::on_btnConnect_clicked()
{
if(ui->btnConnect->text() == "连接")
{
QString strPortName = ui->comboBox_port->currentText(); //端口
QString strBaud = ui->comboBox_baud->currentText(); //波特率
QString strDataBit = ui->comboBox_dataBit->currentText(); //数据位
QString strStopBit = ui->comboBox_stopBit->currentText(); //停止位
QString strParityBit = ui->comboBox_parityBit->currentText(); //校验位
QString strFlowControl = ui->comboBox_flowControl->currentText(); //控制流
int setBaud = strBaud.toInt(); //波特率
QSerialPort::DataBits setDataBits; //数据位
QSerialPort::StopBits setStopBits; //停止位
QSerialPort::Parity setParityBits; //校验位
QSerialPort::FlowControl setFlowControl;//控制流
if(strDataBit == "5")
{
setDataBits = QSerialPort::Data5;
}else if(strDataBit == "6")
{
setDataBits = QSerialPort::Data6;
}else if(strDataBit == "7")
{
setDataBits = QSerialPort::Data7;
}else{
setDataBits = QSerialPort::Data8;
}
if(strStopBit == "1")
{
setStopBits = QSerialPort::OneStop;
}else if(strStopBit == "2"){
setStopBits = QSerialPort::TwoStop;
}else{
setStopBits = QSerialPort::OneAndHalfStop;
}
if(strParityBit == "None")
{
setParityBits = QSerialPort::NoParity;
}else if(strParityBit == "Odd"){
setParityBits = QSerialPort::OddParity;
}else if(strParityBit == "Even"){
setParityBits = QSerialPort::EvenParity;
}else if(strParityBit == "Mark"){
setParityBits = QSerialPort::MarkParity;
}else /*if(parityBits == "Space")*/{
setParityBits = QSerialPort::SpaceParity;
}
if(strFlowControl == "HardWare"){
setFlowControl = QSerialPort::HardwareControl;
}else if(strFlowControl == "SoftWare"){
setFlowControl = QSerialPort::SoftwareControl;
}else /*if(flowControl == "None")*/{
setFlowControl = QSerialPort::NoFlowControl;
}
m_pSerialPort->setPortName(strPortName);
m_pSerialPort->setBaudRate(setBaud);
m_pSerialPort->setDataBits(setDataBits);
m_pSerialPort->setStopBits(setStopBits);
m_pSerialPort->setParity(setParityBits);
m_pSerialPort->setFlowControl(setFlowControl);
if(!m_pSerialPort->open(QIODevice::ReadWrite))
{
return;
}
ui->btnConnect->setText("断开连接");
ui->statusbar->showMessage("串口连接成功!",5000);
}
else
{
if(m_pSerialPort->isOpen())
{
m_pSerialPort->clear();
m_pSerialPort->close();
ui->btnConnect->setText("连接");
}
}
}
void MainWindow::on_btnSend_clicked()
{
if(!m_pSerialPort->isOpen())
return;
encodeProtocol1();
}
void MainWindow::on_btnRead_clicked()
{
if(!m_pSerialPort->isOpen())
return;
//读取设备数据
readProtocol1();
}
void MainWindow::on_btnAuth_clicked()
{
if(!m_pSerialPort->isOpen())
return;
QByteArray writeData;
QList<quint8> password;
password.append((quint8)ui->ID1->text().toUInt(nullptr,16));
password.append((quint8)ui->ID2->text().toUInt(nullptr,16));
password.append((quint8)ui->ID3->text().toUInt(nullptr,16));
password.append((quint8)ui->ID4->text().toUInt(nullptr,16));
password.append((quint8)ui->ID5->text().toUInt(nullptr,16));
password.append((quint8)ui->ID6->text().toUInt(nullptr,16));
password.append((quint8)ui->ID7->text().toUInt(nullptr,16));
password.append((quint8)ui->ID8->text().toUInt(nullptr,16));
packingAuth(password,writeData);
sendData(writeData);
}
void MainWindow::on_btnExit_clicked()
{
if(!m_pSerialPort->isOpen())
return;
QByteArray writeData;
packingExit(writeData);
sendData(writeData);
}
void MainWindow::slot_timeout()
{
m_timeoutCounts++;
if(m_timeoutCounts > 3)
{
m_reSendTimer.stop();
//清除队列
m_sendingPackageData.clear();
endProgress();
qDebug()<<QStringLiteral("ReSend 3 times, end");
ui->statusbar->showMessage("已重试3次没有回应,结束本次发送",5000);
return;
}
sendData(m_sendingBuff);
qDebug()<<QStringLiteral("ReSendCounts:")<<m_timeoutCounts;
ui->statusbar->showMessage(QString("重发次数:%1").arg(m_timeoutCounts),5000);
}
void MainWindow::on_btnSend1_clicked()
{
if(!m_pSerialPort->isOpen())
return;
encodeProtocol2(packingData1());
}
void MainWindow::on_btnSend2_clicked()
{
if(!m_pSerialPort->isOpen())
return;
encodeProtocol2(packingData2());
}
void MainWindow::on_btnSend3_clicked()
{
if(!m_pSerialPort->isOpen())
return;
encodeProtocol2(packingData3());
}
void MainWindow::on_btnSend4_clicked()
{
if(!m_pSerialPort->isOpen())
return;
encodeProtocol2(packingData4());
}
void MainWindow::on_btnSend5_clicked()
{
if(!m_pSerialPort->isOpen())
return;
encodeProtocol2(packingData5());
}
void MainWindow::on_btnSend6_clicked()
{
if(!m_pSerialPort->isOpen())
return;
encodeProtocol2(packingData6());
}
void MainWindow::on_btnSend7_clicked()
{
if(!m_pSerialPort->isOpen())
return;
encodeProtocol2(packingData7());
}
void MainWindow::on_btnAuth1_clicked()
{
if(!m_pSerialPort->isOpen())
return;
readData1();
}
void MainWindow::on_btnAuth2_clicked()
{
if(!m_pSerialPort->isOpen())
return;
readData2();
}
void MainWindow::on_btnAuth3_clicked()
{
if(!m_pSerialPort->isOpen())
return;
readData3();
}
void MainWindow::on_btnAuth4_clicked()
{
if(!m_pSerialPort->isOpen())
return;
readData4();
}
void MainWindow::on_btnAuth5_clicked()
{
if(!m_pSerialPort->isOpen())
return;
readData5();
}
void MainWindow::on_btnAuth6_clicked()
{
if(!m_pSerialPort->isOpen())
return;
readData6();
}
void MainWindow::on_btnAuth7_clicked()
{
if(!m_pSerialPort->isOpen())
return;
readData7();
}
void MainWindow::on_btnReload_clicked()
{
// loadFile();
QString filePathHver;
QString filePathAlphaRad;
QString filePathdHC;
QString filePathVRSBeta;
QString filePathVRCBeta;
QString filePathRTSBeta;
QString filePathRTCBeta;
QString defaultDir = qApp->applicationDirPath() + "/../";
QString pathDir = QFileDialog::getExistingDirectory(this, tr("开打文件夹"),
defaultDir,
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
QDir dir(pathDir);
if(!dir.exists())
{
QMessageBox msgBox(this);
msgBox.setWindowTitle("提示");
msgBox.setText("打开文件失败!");
msgBox.exec();
return;
}
int authCounts = 0;
dir.setFilter(QDir::Files | QDir::NoSymLinks);
QFileInfoList list = dir.entryInfoList();
for(int i = 0; i < list.size(); i++)
{
QFileInfo fileInfo = list.at(i);
QString curFileName = fileInfo.fileName();
// qDebug() << fileInfo.fileName();
if(curFileName == "Hver.dat")
{
filePathHver = fileInfo.absoluteFilePath();
authCounts++;
}
if(curFileName == "AlphaRad.dat")
{
filePathAlphaRad = fileInfo.absoluteFilePath();
authCounts++;
}
if(curFileName == "dHC.dat")
{
filePathdHC = fileInfo.absoluteFilePath();
authCounts++;
}
if(curFileName == "VRSBeta.dat")
{
filePathVRSBeta = fileInfo.absoluteFilePath();
authCounts++;
}
if(curFileName == "VRCBeta.dat")
{
filePathVRCBeta = fileInfo.absoluteFilePath();
authCounts++;
}
if(curFileName == "RTSBeta.dat")
{
filePathRTSBeta = fileInfo.absoluteFilePath();
authCounts++;
}
if(curFileName == "RTCBeta.dat")
{
filePathRTCBeta = fileInfo.absoluteFilePath();
authCounts++;
}
}
if(authCounts < 7)
{
QMessageBox msgBox(this);
msgBox.setWindowTitle("提示");
msgBox.setText("文件名校验失败!");
setAllBtnUnenable();
clearAllData();
msgBox.exec();
return;
}
loadFile(filePathHver,filePathAlphaRad,filePathdHC,filePathVRSBeta,filePathVRCBeta,filePathRTSBeta,filePathRTCBeta);
setAllBtnEnable();
}
void MainWindow::sendData(QByteArray arrayData)
{
if(m_pSerialPort->isOpen())
{
m_pSerialPort->write(arrayData.constData(),arrayData.size());
qDebug()<<"SendBuff:"<<arrayData.toHex().toUpper() <<"SendSize:"<<arrayData.size();
delayTime(50);
}
}
void MainWindow::decodeProtocol1(QByteArray readData)
{
QDataStream in(&readData,QIODevice::ReadWrite);
quint32 nValue = 0;
if(m_readP1Addr == 520)
{
//uint32_t nMiuS
in >> nValue;
ui->R_1->setText(QString::number(revert32(nValue)));
//uint32_t nPhiS
in >> nValue;
ui->R_2->setText(QString::number(revert32(nValue)));
}
else if(m_readP1Addr == 528)
{
//uint32_t ndPS
in >> nValue;
ui->R_3->setText(QString::number(revert32(nValue)));
//uint32_t nLstaS
in >> nValue;
ui->R_4->setText(QString::number(revert32(nValue)));
}
else if(m_readP1Addr == 536)
{
//uint32_t nLstaW
in >> nValue;
ui->R_5->setText(QString::number(revert32(nValue)));
//float K_trc
in >> nValue;
ui->R_6->setText(QString::number(Byte4ToFloat(revert32(nValue))));
}
else if(m_readP1Addr == 544)
{
//float TkR
in >> nValue;
ui->R_7->setText(QString::number(Byte4ToFloat(revert32(nValue))));
//float TkR1;
in >> nValue;
ui->R_8->setText(QString::number(Byte4ToFloat(revert32(nValue))));
}
else if(m_readP1Addr == 552)
{
//float TkR2
in >> nValue;
ui->R_9->setText(QString::number(Byte4ToFloat(revert32(nValue))));
//float PhiRa
in >> nValue;
ui->R_11->setText(QString::number(Byte4ToFloat(revert32(nValue))));
}
else if(m_readP1Addr == 560)
{
//uint32_t PhiWS
in >> nValue;
ui->R_12->setText(QString::number(revert32(nValue)));
//uint32_t nLvalS
in >> nValue;
ui->R_13->setText(QString::number(revert32(nValue)));
}
else if(m_readP1Addr == 568)
{
//uint32_t Kc
in >> nValue;
ui->R_14->setText(QString::number(revert32(nValue)));
//uint32_t Kc1
in >> nValue;
ui->R_15->setText(QString::number(revert32(nValue)));
}
else if(m_readP1Addr == 576)
{
//float THver
in >> nValue;
ui->R_16->setText(QString::number(Byte4ToFloat(revert32(nValue))));
//uint32_t Kcal1
in >> nValue;
ui->R_17->setText(QString::number(revert32(nValue)));
}
else if(m_readP1Addr == 584)
{
//uint32_t Kcal2
in >> nValue;
ui->R_18->setText(QString::number(revert32(nValue)));
//uint32_t Kcal3
in >> nValue;
ui->R_19->setText(QString::number(revert32(nValue)));
}
else if(m_readP1Addr == 592)
{
//uint32_t xhx_err_time
in >> nValue;
ui->R_20->setText(QString::number(revert32(nValue)));
//uint32_t RowBin_SIZE_par
in >> nValue;
ui->R_10->setText(QString::number(revert32(nValue)));
}
else if(m_readP1Addr == 600)
{
//uint32_t ColBin_SIZE_par
in >> nValue;
ui->R_21->setText(QString::number(revert32(nValue)));
//float k_phi_xz1
in >> nValue;
ui->R_22->setText(QString::number(Byte4ToFloat(revert32(nValue))));
}
else if(m_readP1Addr == 608)
{
//float k_phi_xz2
in >> nValue;
ui->R_23->setText(QString::number(Byte4ToFloat(revert32(nValue))));
//float k_phi_yz1
in >> nValue;
ui->R_24->setText(QString::number(Byte4ToFloat(revert32(nValue))));
}
else if(m_readP1Addr == 616)
{
//float k_phi_yz2
in >> nValue;
ui->R_25->setText(QString::number(Byte4ToFloat(revert32(nValue))));
//float beta_0
in >> nValue;
ui->R_26->setText(QString::number(Byte4ToFloat(revert32(nValue))));
}
else if(m_readP1Addr == 624)
{
//uint32_t R
in >> nValue;
ui->R_27->setText(QString::number(revert32(nValue)));
//float Kcor
in >> nValue;
ui->R_28->setText(QString::number(Byte4ToFloat(revert32(nValue))));
}
else if(m_readP1Addr == 632)
{
//uint32_t Queue_Size_Lval
in >> nValue;
ui->R_29->setText(QString::number(revert32(nValue)));
//float MiuAst_PH
in >> nValue;
ui->R_30->setText(QString::number(Byte4ToFloat(revert32(nValue))));
}
else if(m_readP1Addr == 640)
{
//uint32_t LsuK
in >> nValue;
ui->R_31->setText(QString::number(revert32(nValue)));
//float K
in >> nValue;
ui->R_32->setText(QString::number(Byte4ToFloat(revert32(nValue))));
}
else if(m_readP1Addr == 648)
{
//float Alpha_0
in >> nValue;
ui->R_33->setText(QString::number(Byte4ToFloat(revert32(nValue))));
//float Alpha_1
in >> nValue;
ui->R_34->setText(QString::number(Byte4ToFloat(revert32(nValue))));
}
}
void MainWindow::decodeReadProtocol2Data(QByteArray readData)
{
QDataStream in(&readData,QIODevice::ReadWrite);
quint8 deviceAddr; //设备地址
in >> deviceAddr;
quint8 funcCode; //功能码
in >> funcCode;
quint16 regAddr;
in >> regAddr; //寄存器地址
QList<float> numDataList;
quint32 num;
in >> num;
numDataList.append(Byte4ToFloat(num));
in >> num;
numDataList.append(Byte4ToFloat(num));
in >> num;
numDataList.append(Byte4ToFloat(num));
in >> num;
numDataList.append(Byte4ToFloat(num));
in >> num;
numDataList.append(Byte4ToFloat(num));
quint16 addrType = regAddr & 0xF000;
switch(addrType)
{
case 0x5000: authData1(addrType, regAddr, numDataList);break;
case 0x6000: authData2(addrType, regAddr, numDataList);break;
case 0x7000: authData3(addrType, regAddr, numDataList);break;
case 0x8000: authData4(addrType, regAddr, numDataList);break;
case 0x9000: authData5(addrType, regAddr, numDataList);break;
case 0xA000: authData6(addrType, regAddr, numDataList);break;
case 0xB000: authData7(addrType, regAddr, numDataList);break;
default: break;
}
}
void MainWindow::decodeAuth(QByteArray readData)
{
QString strHex = readData.toHex().toUpper();
//读写权限
if(strHex == "8866E79A")
{
ui->id_status->setText("已认证(读写权限)");
}
//只读权限
else if(strHex == "443372A5")
{
ui->id_status->setText("已认证(只读权限)");
}
else
{
ui->id_status->setText("未认证");
}
}
void MainWindow::decodeExit(QByteArray readData)
{
QString strHex = readData.toHex().toUpper();
//退出
if(strHex == "66882A76")
{
ui->id_status->setText("未认证");
}
}
void MainWindow::encodeProtocol1()
{
int nCount = 0;
startProgress(0,10);
QByteArray writeData;
quint16 regAddr = 0;
quint32 value1 = 0;
quint32 value2 = 0;
//uint32_t nMiuS; // 默认31
//uint32_t nPhiS; // 默认2000
regAddr = 520;
value1 = ui->W_1->text().toUInt();
value2 = ui->W_2->text().toUInt();
packingProtocol1(regAddr,value1,value2,writeData);
sendData(writeData);
writeData.clear();
setProgress(++nCount);
//uint32_t ndPS; // 默认20
//uint32_t nLstaS; // 默认20
regAddr = 528;
value1 = ui->W_3->text().toUInt();
value2 = ui->W_4->text().toUInt();
packingProtocol1(regAddr,value1,value2,writeData);
sendData(writeData);
writeData.clear();
setProgress(++nCount);
//uint32_t nLstaW; // 默认20
//float K_trc; // 默认 0.5
regAddr = 536;
value1 = ui->W_5->text().toUInt();
value2 = FloatToByte4(ui->W_6->text().toFloat());
packingProtocol1(regAddr,value1,value2,writeData);
sendData(writeData);
writeData.clear();
setProgress(++nCount);
//float TkR; // 默认0.86
//float TkR1; // 默认0.86
regAddr = 544;
value1 = FloatToByte4(ui->W_7->text().toFloat());
value2 = FloatToByte4(ui->W_8->text().toFloat());
packingProtocol1(regAddr,value1,value2,writeData);
sendData(writeData);
writeData.clear();
setProgress(++nCount);
//float TkR2; // 默认0.86
//float PhiRa; // 默认0.1
regAddr = 552;
value1 = FloatToByte4(ui->W_9->text().toFloat());
value2 = FloatToByte4(ui->W_11->text().toFloat());
packingProtocol1(regAddr,value1,value2,writeData);
sendData(writeData);
writeData.clear();
setProgress(++nCount);
//uint32_t PhiWS; // 默认200
//uint32_t nLvalS; // 默认200
regAddr = 560;
value1 = ui->W_12->text().toUInt();
value2 = ui->W_13->text().toUInt();
packingProtocol1(regAddr,value1,value2,writeData);
sendData(writeData);
writeData.clear();
setProgress(++nCount);
//uint32_t Kc; // 默认 1000
//uint32_t Kc1; // 默认 3079
regAddr = 568;
value1 = ui->W_14->text().toUInt();
value2 = ui->W_15->text().toUInt();
packingProtocol1(regAddr,value1,value2,writeData);
sendData(writeData);
writeData.clear();
setProgress(++nCount);
//float THver; // 默认 0.647
//uint32_t Kcal1; // 默认 1000
regAddr = 576;
value1 = FloatToByte4(ui->W_16->text().toFloat());
value2 = ui->W_17->text().toUInt();
packingProtocol1(regAddr,value1,value2,writeData);
sendData(writeData);
writeData.clear();
setProgress(++nCount);
//uint32_t Kcal2; // 默认 1000
//uint32_t Kcal3; // 默认 1000
regAddr = 584;
value1 = ui->W_18->text().toUInt();
value2 = ui->W_19->text().toUInt();
packingProtocol1(regAddr,value1,value2,writeData);
sendData(writeData);
writeData.clear();
setProgress(++nCount);
//uint32_t xhx_err_time; // 默认10次,超过这个
//uint32_t RowBin_SIZE_par; // 50-60 默认55
regAddr = 592;
value1 = ui->W_20->text().toUInt();
value2 = ui->W_10->text().toUInt();
packingProtocol1(regAddr,value1,value2,writeData);
sendData(writeData);
writeData.clear();
setProgress(++nCount);
//uint32_t ColBin_SIZE_par; // 50-60 默认55
//float k_phi_xz1;
regAddr = 600;
value1 = ui->W_21->text().toUInt();
value2 = FloatToByte4(ui->W_22->text().toFloat());
packingProtocol1(regAddr,value1,value2,writeData);
sendData(writeData);
writeData.clear();
setProgress(++nCount);
//float k_phi_xz2;
//float k_phi_yz1;
regAddr = 608;
value1 = FloatToByte4(ui->W_23->text().toFloat());
value2 = FloatToByte4(ui->W_24->text().toFloat());
packingProtocol1(regAddr,value1,value2,writeData);
sendData(writeData);
writeData.clear();
setProgress(++nCount);
//float k_phi_yz2;
//float beta_0;
regAddr = 616;
value1 = FloatToByte4(ui->W_25->text().toFloat());
value2 = FloatToByte4(ui->W_26->text().toFloat());
packingProtocol1(regAddr,value1,value2,writeData);
sendData(writeData);
writeData.clear();
setProgress(++nCount);
//uint32_t R; // 默认 564mm
//float Kcor; // 默认 0.0505
regAddr = 624;
value1 = ui->W_27->text().toUInt();
value2 = FloatToByte4(ui->W_28->text().toFloat());
packingProtocol1(regAddr,value1,value2,writeData);
sendData(writeData);
writeData.clear();
setProgress(++nCount);
//uint32_t Queue_Size_Lval; // 不能超过30默认21
//float MiuAst_PH;
regAddr = 632;
value1 = ui->W_29->text().toUInt();
value2 = FloatToByte4(ui->W_30->text().toFloat());
packingProtocol1(regAddr,value1,value2,writeData);
sendData(writeData);
writeData.clear();
setProgress(++nCount);
//uint32_t LsuK; // 默认20
//float K; // 默认0.1
regAddr = 640;
value1 = ui->W_31->text().toUInt();
value2 = FloatToByte4(ui->W_32->text().toFloat());
packingProtocol1(regAddr,value1,value2,writeData);
sendData(writeData);
writeData.clear();
setProgress(++nCount);
//float Alpha_0;
//float Alpha_1;
regAddr = 648;
value1 = FloatToByte4(ui->W_33->text().toFloat());
value2 = FloatToByte4(ui->W_34->text().toFloat());
packingProtocol1(regAddr,value1,value2,writeData);
sendData(writeData);
writeData.clear();
setProgress(++nCount);
endProgress();
//读取设备数据
readProtocol1();
}
void MainWindow::readProtocol1()
{
m_readP1Addr = 520;
QByteArray writeReadData;
packingReadProtocol1(m_readP1Addr, writeReadData);
sendData(writeReadData);
writeReadData.clear();
m_readP1Addr = 528;
packingReadProtocol1(m_readP1Addr, writeReadData);
sendData(writeReadData);
writeReadData.clear();
m_readP1Addr = 536;
packingReadProtocol1(m_readP1Addr, writeReadData);
sendData(writeReadData);
writeReadData.clear();
m_readP1Addr = 544;
packingReadProtocol1(m_readP1Addr, writeReadData);
sendData(writeReadData);
writeReadData.clear();
m_readP1Addr = 552;
packingReadProtocol1(m_readP1Addr, writeReadData);
sendData(writeReadData);
writeReadData.clear();
m_readP1Addr = 560;
packingReadProtocol1(m_readP1Addr, writeReadData);
sendData(writeReadData);
writeReadData.clear();
m_readP1Addr = 568;
packingReadProtocol1(m_readP1Addr, writeReadData);
sendData(writeReadData);
writeReadData.clear();
m_readP1Addr = 576;
packingReadProtocol1(m_readP1Addr, writeReadData);
sendData(writeReadData);
writeReadData.clear();
m_readP1Addr = 584;
packingReadProtocol1(m_readP1Addr, writeReadData);
sendData(writeReadData);
writeReadData.clear();
m_readP1Addr = 592;
packingReadProtocol1(m_readP1Addr, writeReadData);
sendData(writeReadData);
writeReadData.clear();
m_readP1Addr = 600;
packingReadProtocol1(m_readP1Addr, writeReadData);
sendData(writeReadData);
writeReadData.clear();
m_readP1Addr = 608;
packingReadProtocol1(m_readP1Addr, writeReadData);
sendData(writeReadData);
writeReadData.clear();
m_readP1Addr = 616;
packingReadProtocol1(m_readP1Addr, writeReadData);
sendData(writeReadData);
writeReadData.clear();
m_readP1Addr = 624;
packingReadProtocol1(m_readP1Addr, writeReadData);
sendData(writeReadData);
writeReadData.clear();
m_readP1Addr = 632;
packingReadProtocol1(m_readP1Addr, writeReadData);
sendData(writeReadData);
writeReadData.clear();
m_readP1Addr = 640;
packingReadProtocol1(m_readP1Addr, writeReadData);
sendData(writeReadData);
writeReadData.clear();
m_readP1Addr = 648;
packingReadProtocol1(m_readP1Addr, writeReadData);
sendData(writeReadData);
writeReadData.clear();
}
void MainWindow::encodeProtocol2(QQueue<QByteArray> packageQueue)
{
m_sendFlashAddr.clear();
m_recvFlashAddr.clear();
m_sendingPackageData.clear();
m_sendingPackageData = packageQueue;
startProgress(0,m_sendingPackageData.size());
int counts = 0;
while(m_sendingPackageData.size() > 0)
{
qDebug()<<"PackList:"<<m_sendingPackageData.size();
QByteArray writeData = m_sendingPackageData.dequeue();
m_sendFlashAddr = getFlashAddr(writeData);
sendData(writeData);
//test recvFlashAddr
// m_recvFlashAddr = getFlashAddr(writeData);
m_sendingBuff = writeData;
m_reSendTimer.start();
m_timeoutCounts = 0;
while(m_reSendTimer.isActive())
{
if(m_sendFlashAddr == m_recvFlashAddr)
{
// qDebug()<<"sendFlashAddr:"<<m_sendFlashAddr.toHex().toUpper()
// <<"recvFlashAddr:"<<m_recvFlashAddr.toHex().toUpper();
m_reSendTimer.stop();
setProgress(++counts);
break;
}
//阻塞等待
QCoreApplication::processEvents();