-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
1750 lines (1585 loc) · 74.6 KB
/
mainwindow.cpp
File metadata and controls
1750 lines (1585 loc) · 74.6 KB
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"
using namespace std;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
//glutinit
int argc = 1;
char *argv[1] = {(char*)"Something"};
glutInit(&argc, argv);//初始化glut
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);//设置显示模式
ui->setupUi(this);
//禁用全屏
this->setWindowFlags(Qt::WindowCloseButtonHint);
//禁止放大缩小
this->setFixedSize(this->width(), this->height());
//标题:卫星位置计算软件
this->setWindowTitle("卫星位置计算软件");
ui->statusbar->showMessage("欢迎使用卫星位置计算软件。本软件可解析GPS,北斗,GLONASS,Galileo卫星系统的星历数据,计算卫星位置。");
glWidget = new MyOpenGLWidget(ui->Sats);
glWidget->resize(ui->Sats->width(), ui->Sats->height());
glWidget->show();
//rnxPath只读
ui->rnxPath->setReadOnly(true);
//设置everyTable的列
ui->everyTable->setColumnCount(7);
//设置everyTable的行高为3*default
ui->everyTable->verticalHeader()->setDefaultSectionSize(3*ui->everyTable->verticalHeader()->defaultSectionSize());
//设置everyTable的行
ui->everyTable->setRowCount(0);
//设置everyTable的表头
ui->everyTable->setHorizontalHeaderLabels(QStringList()<<"卫星"<<"历元(GPST)"<<"解算坐标"<<"精密星历坐标"<<"偏差"<<"卫星方位角"<<"卫星高度角");
//取消表前的行号
ui->everyTable->verticalHeader()->setVisible(false);
//表格禁止编辑
ui->everyTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
//设置BLH默认值
ui->LInput->setText("117.14");
ui->BInput->setText("34.22");
ui->HInput->setText("10");
//取消表前的行号
ui->timeTable->verticalHeader()->setVisible(false);
//表格禁止编辑
ui->timeTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
//设置timeTable的列
ui->timeTable->setColumnCount(6);
//设置timeTable的表头
ui->timeTable->setHorizontalHeaderLabels(QStringList()<<"卫星"<<"PRN"<<"历元(GPST)"<<"解算坐标"<<"卫星方位角"<<"卫星高度角");
//设置timeTable的行高为3*default
ui->timeTable->verticalHeader()->setDefaultSectionSize(3*ui->timeTable->verticalHeader()->defaultSectionSize());
//设置timeTable的行
ui->timeTable->setRowCount(0);
//ui->startTime:9:00:00
ui->startTime->setTime(QTime(9,0,0));
//ui->endTime:10:00:00
ui->endTime->setTime(QTime(10,0,0));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_openGLWidget_resized()
{
}
void MainWindow::on_openRNX_clicked()
{
//选择文件,RINEX文件(*.rnx和*.*n)
QString fileName = QFileDialog::getOpenFileName(this, "选择文件", "", "RINEX文件(*.rnx brdc*.*n brdc*.*g brdc*.*b)");
if(fileName.isEmpty())
{
QMessageBox::warning(this, "警告", "未选择文件!");
return;
}
//打开文件
std::ifstream fin(fileName.toStdString());
if(!fin.is_open())
{
QMessageBox::warning(this, "警告", "文件打开失败!");
return;
}
ui->rnxPath->setText(fileName);
//清空sats和sat_GLOs,表格
sats.clear();
sat_GLOs.clear();
ui->everyTable->clearContents();
//读取文件
std::string line;
getline(fin, line);
double rnx_version;
//判断rnx版本
if(line.substr(60, 20) == "RINEX VERSION / TYPE"){
cout<<line.substr(5, 4)<<endl;
rnx_version = str_to_double(line.substr(5, 4));
if(rnx_version>3.04){
//alert
QMessageBox::warning(this,"警告","只支持读取RINEX版本为2至3.04,读取失败",QMessageBox::Ok);
return;
}
}else{
//alert
QMessageBox::warning(this,"警告","RINEX无效",QMessageBox::Ok);
return;
}
for(int i=0;i<10e3;i++){
getline(fin, line);
if (line.find("END OF HEADER") != std::string::npos) {
break;
}
}
if(rnx_version>=3){
//读取卫星数据
while(getline(fin, line)){
//read_rnx_GPS_BDS_GAL
if(line.substr(0, 1) == "G" || line.substr(0, 1) == "C" || line.substr(0, 1) == "E"){
Satellite sat;
//判断该行数据是否完整,若不完整则退出
if(line.length()<60){
//alert
QMessageBox::warning(this,"警告","文件数据不完整",QMessageBox::Ok);
break;
}
if(line.substr(0, 1) == "G" ){
sat.type = "GPS";
}
else if(line.substr(0, 1) == "C" ){
sat.type = "BDS";
}
else if(line.substr(0, 1) == "E" ){
sat.type = "GAL";
}
sat.prn = stoi(line.substr(1, 2)); // 提取伪随机噪声码
sat.year = stoi(line.substr(4, 4)); // 提取年份
sat.month = stoi(line.substr(9, 2)); // 提取月份
sat.day = stoi(line.substr(12, 2)); // 提取日期
sat.hour = stoi(line.substr(15, 2)); // 提取小时
sat.minute = stoi(line.substr(18, 2)); // 提取分钟
sat.second = str_to_double(line.substr(21, 2)); // 提取秒
sat.clock_bias = str_to_double(line.substr(23, 19)); // 提取钟差
sat.clock_drift = str_to_double(line.substr(42, 19)); // 提取钟偏
sat.clock_drift_rate = str_to_double(line.substr(61, 19)); // 提取钟偏变化率
std::string line;
getline(fin, line); // 读取下一行
//判断该行数据是否完整,若不完整则退出
if(line.length()<60){
//alert
QMessageBox::warning(this,"警告","文件数据不完整",QMessageBox::Ok);
break;
}
sat.iode = str_to_double(line.substr(4, 19)); // 提取数据龄期
sat.crs = str_to_double(line.substr(23, 19)); // 提取轨道半径正弦调和项
sat.delta_n = str_to_double(line.substr(42, 19)); // 提取平均角速度改正项
sat.m0 = str_to_double(line.substr(61, 19)); // 提取参考时刻平近点角
getline(fin, line); // 读取下一行
//判断该行数据是否完整,若不完整则退出
if(line.length()<60){
//alert
QMessageBox::warning(this,"警告","文件数据不完整",QMessageBox::Ok);
break;
}
sat.cuc = str_to_double(line.substr(4, 19)); // 提取升交距角余弦调和项
sat.e = str_to_double(line.substr(23, 19)); // 提取偏心率
sat.cus = str_to_double(line.substr(42, 19)); // 提取升交距角正弦调和项
sat.sqrt_a = str_to_double(line.substr(61, 19)); // 提取轨道长半轴平方根
getline(fin, line); // 读取下一行
//判断该行数据是否完整,若不完整则退出
if(line.length()<60){
//alert
QMessageBox::warning(this,"警告","文件数据不完整",QMessageBox::Ok);
break;
}
sat.toe = str_to_double(line.substr(4, 19)); // 提取参考时刻
sat.cic = str_to_double(line.substr(23, 19)); // 提取轨道倾角余弦调和项
sat.omega0 = str_to_double(line.substr(42, 19)); // 提取参考时刻升交点赤经
sat.cis = str_to_double(line.substr(61, 19)); // 提取轨道倾角正弦调和项
getline(fin, line); // 读取下一行
//判断该行数据是否完整,若不完整则退出
if(line.length()<60){
//alert
QMessageBox::warning(this,"警告","文件数据不完整",QMessageBox::Ok);
break;
}
sat.i0 = str_to_double(line.substr(4, 19)); // 提取参考时刻轨道倾角
sat.crc = str_to_double(line.substr(23, 19)); // 提取轨道半径余弦调和项
sat.omega = str_to_double(line.substr(42, 19)); // 提取近地点角距
sat.omega_dot = str_to_double(line.substr(61, 19)); // 提取升交点赤经变化率
getline(fin, line); // 读取下一行
//判断该行数据是否完整,若不完整则退出
if(line.length()<60){
//alert
QMessageBox::warning(this,"警告","文件数据不完整",QMessageBox::Ok);
break;
}
sat.idot = str_to_double(line.substr(4, 19)); // 提取轨道倾角变化率
sat.codes_l2_channel = str_to_double(line.substr(23, 19)); // 提取L2频道C/A码标识
sat.gps_week_number = str_to_double(line.substr(42, 19)); // 提取GPS周数
getline(fin, line); // 读取下一行
//判断该行数据是否完整,若不完整则退出
if(line.length()<60){
//alert
QMessageBox::warning(this,"警告","文件数据不完整",QMessageBox::Ok);
break;
}
sat.accuracy_index = str_to_double(line.substr(4, 19)); // 提取精度指数
sat.health_status_bitmask = str_to_double(line.substr(23, 19)); // 提取卫星健康状态掩码
sat.tgd = str_to_double(line.substr(42, 19)); // 提取电离层延迟
sat.iodc = str_to_double(line.substr(61, 19)); // 提取星钟数据质量
getline(fin, line); // 读取下一行
//判断该行数据是否完整,若不完整则退出
if(line.length()<30){
//alert
QMessageBox::warning(this,"警告","文件数据不完整",QMessageBox::Ok);
break;
}
sat.transmission_time_of_message_sow = str_to_double(line.substr(4, 19)); // 提取信息发射时间
sats.push_back(sat);
}
//read_rnx_GLONASS
else if(line.substr(0, 1) == "R"){
Satellite_GLO sat;
sat.type = "GLO";
sat.prn = stoi(line.substr(1, 2)); // 提取伪随机噪声码
sat.year = stoi(line.substr(4, 4)); // 提取年份
sat.month = stoi(line.substr(9, 2)); // 提取月份
sat.day = stoi(line.substr(12, 2)); // 提取日期
sat.hour = stoi(line.substr(15, 2)); // 提取小时
sat.minute = stoi(line.substr(18, 2)); // 提取分钟
sat.second = str_to_double(line.substr(21, 2)); // 提取秒
sat.clock_bias = str_to_double(line.substr(23, 19)); // 提取钟差
sat.clock_drift = str_to_double(line.substr(42, 19)); // 提取钟偏
std::string line;
getline(fin, line); // 读取下一行数据
sat.x = str_to_double(line.substr(4, 19))*1000; // 提取x
sat.x_speed = str_to_double(line.substr(23, 19))*1000; // 提取x速度
sat.x_acceleration = str_to_double(line.substr(42, 19))*1000; // 提取x加速度
getline(fin, line); // 读取下一行数据
sat.y = str_to_double(line.substr(4, 19))*1000; // 提取y
sat.y_speed = str_to_double(line.substr(23, 19))*1000; // 提取y速度
sat.y_acceleration = str_to_double(line.substr(42, 19))*1000; // 提取y加速度
getline(fin, line); // 读取下一行数据
sat.z = str_to_double(line.substr(4, 19))*1000; // 提取z
sat.z_speed = str_to_double(line.substr(23, 19))*1000; // 提取z速度
sat.z_acceleration = str_to_double(line.substr(42, 19))*1000; // 提取z加速度
const geph_t geph = ConvertToGeph(sat);
//调用geph2pos
double rs[3]; // 卫星位置
double dts[2]; // 卫星钟差
double var; // 位置和钟差的方差
gtime_t time; // 时间
//time赋值为toe-18s,转换为GPST
time = timeadd(geph.toe,-18.0);
geph2pos(time, &geph, rs, dts, &var);
sat.x = rs[0];
sat.y = rs[1];
sat.z = rs[2];
sat_GLOs.push_back(sat);
}
//不读取SBAS
else if(line.substr(0, 1) == "S" ){
for(int i=0;i<3;i++){
getline(fin, line);
}
continue;
}
//不读取QZSS和IRNSS
else if(line.substr(0, 1) == "J" ||line.substr(0, 1) == "I"){
for(int i=0;i<7;i++){
getline(fin, line);
}
continue;
}
}
}else{
//如果文件的后缀是n,则是GPS
if(fileName[fileName.length()-1] == 'n'){
//GPS
while (getline(fin, line)) {
Satellite sat;
//判断该行数据是否完整,若不完整则退出
if(line.length()<60){
//alert
QMessageBox::warning(this,"警告","文件数据不完整",QMessageBox::Ok);
break;
}
//n文件
sat.type = "GPS";
sat.prn = stoi(line.substr(0, 2)); // 提取伪随机噪声码
sat.year = stoi("20"+line.substr(3, 2)); // 提取年份
sat.month = stoi(line.substr(6, 2)); // 提取月份
sat.day = stoi(line.substr(9, 2)); // 提取日期
sat.hour = stoi(line.substr(12, 2)); // 提取小时
sat.minute = stoi(line.substr(15, 2)); // 提取分钟
sat.second = str_to_double(line.substr(18, 4)); // 提取秒
sat.clock_bias = str_to_double(line.substr(22, 19)); // 提取钟差
sat.clock_drift = str_to_double(line.substr(41, 19)); // 提取钟偏
sat.clock_drift_rate = str_to_double(line.substr(60, 19)); // 提取钟偏变化率
getline(fin, line); // 读取下一行数据
qDebug()<<QString::fromStdString(line);
if(line.length()<60){
//alert
QMessageBox::warning(this,"警告","文件数据不完整",QMessageBox::Ok);
break;
}
sat.iode = str_to_double(line.substr(3, 19)); // 提取数据龄期
sat.crs = str_to_double(line.substr(22, 19)); // 提取轨道半径正弦调和项
sat.delta_n = str_to_double(line.substr(41, 19)); // 提取平均角速度改正项
sat.m0 = str_to_double(line.substr(60, 19)); // 提取参考时刻平近点角
getline(fin, line); // 读取下一行数据
qDebug()<<QString::fromStdString(line);
if(line.length()<60){
//alert
QMessageBox::warning(this,"警告","文件数据不完整",QMessageBox::Ok);
break;
}
sat.cuc = str_to_double(line.substr(3, 19)); // 提取升交距角余弦调和项
sat.e = str_to_double(line.substr(22, 19)); // 提取偏心率
sat.cus = str_to_double(line.substr(41, 19)); // 提取升交距角正弦调和项
sat.sqrt_a = str_to_double(line.substr(60, 19)); // 提取轨道长半轴平方根
getline(fin, line); // 读取下一行数据
qDebug()<<QString::fromStdString(line);
if(line.length()<60){
//alert
QMessageBox::warning(this,"警告","文件数据不完整",QMessageBox::Ok);
break;
}
sat.toe = str_to_double(line.substr(3, 19)); // 提取参考时刻
sat.cic = str_to_double(line.substr(22, 19)); // 提取轨道倾角余弦调和项
sat.omega0 = str_to_double(line.substr(41, 19)); // 提取参考时刻升交点赤经
sat.cis = str_to_double(line.substr(60, 19)); // 提取轨道倾角正弦调和项
getline(fin, line); // 读取下一行数据
qDebug()<<QString::fromStdString(line);
if(line.length()<60){
//alert
QMessageBox::warning(this,"警告","文件数据不完整",QMessageBox::Ok);
break;
}
sat.i0 = str_to_double(line.substr(3, 19)); // 提取参考时刻轨道倾角
sat.crc = str_to_double(line.substr(22, 19)); // 提取轨道半径余弦调和项
sat.omega = str_to_double(line.substr(41, 19)); // 提取近地点角距
sat.omega_dot = str_to_double(line.substr(60, 19)); // 提取升交点赤经变化率
getline(fin, line); // 读取下一行数据
qDebug()<<QString::fromStdString(line);
if(line.length()<60){
//alert
QMessageBox::warning(this,"警告","文件数据不完整",QMessageBox::Ok);
break;
}
sat.idot = str_to_double(line.substr(3, 19)); // 提取轨道倾角变化率
sat.codes_l2_channel = str_to_double(line.substr(22, 19)); // 提取L2频道C/A码标识
sat.gps_week_number = str_to_double(line.substr(41, 19)); // 提取GPS周数
getline(fin, line); // 读取下一行数据
qDebug()<<QString::fromStdString(line);
if(line.length()<60){
//alert
QMessageBox::warning(this,"警告","文件数据不完整",QMessageBox::Ok);
break;
}
sat.accuracy_index = str_to_double(line.substr(3, 19)); // 提取精度指数
sat.health_status_bitmask = str_to_double(line.substr(22, 19)); // 提取卫星健康状态掩码
sat.tgd = str_to_double(line.substr(41, 19)); // 提取电离层延迟
sat.iodc = str_to_double(line.substr(60, 19)); // 提取星钟数据质量
getline(fin, line); // 读取下一行数据
qDebug()<<QString::fromStdString(line);
if(line.length()<30){
//alert
QMessageBox::warning(this,"警告","文件数据不完整",QMessageBox::Ok);
break;
}
sat.transmission_time_of_message_sow = str_to_double(line.substr(3, 19)); // 提取信息发射时间
// sat.fit_interval = str_to_double(line.substr(22, 19)); // 提取拟合区间
sats.push_back(sat); // 将结构体对象添加到向量中
}
}else if(fileName[fileName.length()-1] == 'g'){
//GLO
while (getline(fin, line)) {
//如果line为空行,则跳过
if(line.length()==0){
break;
}
Satellite_GLO sat;
//判断该行数据是否完整,若不完整则退出
if(line.length()<60){
//alert
QMessageBox::warning(this,"警告","文件数据不完整",QMessageBox::Ok);
break;
}
//g文件
sat.type = "GLO";
sat.prn = stoi(line.substr(0, 2)); // 提取伪随机噪声码
sat.year = stoi("20"+line.substr(3, 4)); // 提取年份
sat.month = stoi(line.substr(6, 2)); // 提取月份
sat.day = stoi(line.substr(9, 2)); // 提取日期
sat.hour = stoi(line.substr(12, 2)); // 提取小时
sat.minute = stoi(line.substr(15, 2)); // 提取分钟
sat.second = str_to_double(line.substr(18, 2)); // 提取秒
sat.clock_bias = str_to_double(line.substr(22, 19)); // 提取钟差
sat.clock_drift = str_to_double(line.substr(41, 19)); // 提取钟偏
std::string line;
getline(fin, line); // 读取下一行数据
sat.x = str_to_double(line.substr(3, 19))*1000; // 提取x
sat.x_speed = str_to_double(line.substr(22, 19))*1000; // 提取x速度
sat.x_acceleration = str_to_double(line.substr(41, 19))*1000; // 提取x加速度
getline(fin, line); // 读取下一行数据
sat.y = str_to_double(line.substr(3, 19))*1000; // 提取y
sat.y_speed = str_to_double(line.substr(22, 19))*1000; // 提取y速度
sat.y_acceleration = str_to_double(line.substr(41, 19))*1000; // 提取y加速度
getline(fin, line); // 读取下一行数据
sat.z = str_to_double(line.substr(3, 19))*1000; // 提取z
sat.z_speed = str_to_double(line.substr(22, 19))*1000; // 提取z速度
sat.z_acceleration = str_to_double(line.substr(41, 19))*1000; // 提取z加速度
const geph_t geph = ConvertToGeph(sat);
//调用geph2pos
double rs[3]; // 卫星位置
double dts[2]; // 卫星钟差
double var; // 位置和钟差的方差
gtime_t time; // 时间
//time赋值为toe-18s,转换为GPST
time = timeadd(geph.toe,-18.0);
geph2pos(time, &geph, rs, dts, &var);
sat.x = rs[0];
sat.y = rs[1];
sat.z = rs[2];
sat_GLOs.push_back(sat);
//打印sat的时间
std::cout<<"sat.year:"<<sat.year<<std::endl;
std::cout<<"sat.month:"<<sat.month<<std::endl;
std::cout<<"sat.day:"<<sat.day<<std::endl;
std::cout<<"sat.hour:"<<sat.hour<<std::endl;
std::cout<<"sat.minute:"<<sat.minute<<std::endl;
std::cout<<"sat.second:"<<sat.second<<std::endl;
}
}
}
//渲染到表格
//GPS,BDS,GAL
ui->everyTable->clearContents();
//打印sat.size()和sat_GLOs.size()
std::cout<<"sat.size():"<<sats.size()<<std::endl;
//设置行数
ui->everyTable->setRowCount(sats.size()+sat_GLOs.size());
for(int i=0;i<sats.size();i++){
//设置卫星:type+prn,历元:YYYY-MM-DD HH:mm:ss,只保留整数
ui->everyTable->setItem(i,0,new QTableWidgetItem(QString::fromStdString(sats[i].type+" "+std::to_string(sats[i].prn))));
ui->everyTable->setItem(i,1,new QTableWidgetItem(QString::fromStdString(std::to_string(sats[i].year)+"-"+std::to_string(sats[i].month)+"-"+std::to_string(sats[i].day)+" "+std::to_string(sats[i].hour)+":"+std::to_string(sats[i].minute)+":"+std::to_string(int(sats[i].second)))));
}
std::cout<<"sat_GLOs.size():"<<sat_GLOs.size()<<std::endl;
//GLO,在GPS,BDS,GAL后面
for(int i=0;i<sat_GLOs.size();i++){
//设置卫星:type+prn,历元:YYYY-MM-DD HH:mm:ss,只保留整数
ui->everyTable->setItem(i+sats.size(),0,new QTableWidgetItem(QString::fromStdString(sat_GLOs[i].type+" "+std::to_string(sat_GLOs[i].prn))));
ui->everyTable->setItem(i+sats.size(),1,new QTableWidgetItem(QString::fromStdString(std::to_string(sat_GLOs[i].year)+"-"+std::to_string(sat_GLOs[i].month)+"-"+std::to_string(sat_GLOs[i].day)+" "+std::to_string(sat_GLOs[i].hour)+":"+std::to_string(sat_GLOs[i].minute)+":"+std::to_string(int(sat_GLOs[i].second)))));
}
//表格自适应
ui->everyTable->resizeColumnsToContents();
//第一列宽+10
ui->everyTable->setColumnWidth(0,ui->everyTable->columnWidth(0)+10);
if(sats.size()!=0)
//ui->openglDate改成sats[0]的date
ui->openglDate->setDate(QDate(sats[0].year,sats[0].month,sats[0].day));
else if(sat_GLOs.size()!=0)
//ui->openglDate改成sat_GLOs[0]的date
ui->openglDate->setDate(QDate(sat_GLOs[0].year,sat_GLOs[0].month,sat_GLOs[0].day));
//禁止编辑
ui->openglDate->setReadOnly(true);
//提示:读取卫星数据完成
QMessageBox::information(this,"提示","读取卫星数据完成",QMessageBox::Ok);
//定义一个字典,包括卫星类型和该类型卫星的prn
//遍历sats
for(int i=0;i<sats.size();i++){
//如果type_prns中没有该类型,则添加
if(type_prns.find(QString::fromStdString(sats[i].type))==type_prns.end()){
std::vector<int> temp;
temp.push_back(sats[i].prn);
type_prns[QString::fromStdString(sats[i].type)] = temp;
}else{
//如果type_prns中有该类型,则添加prn
type_prns[QString::fromStdString(sats[i].type)].push_back(sats[i].prn);
}
}
//遍历sat_GLOs
for(int i=0;i<sat_GLOs.size();i++){
//如果type_prns中没有该类型,则添加
if(type_prns.find(QString::fromStdString(sat_GLOs[i].type))==type_prns.end()){
std::vector<int> temp;
temp.push_back(sat_GLOs[i].prn);
type_prns[QString::fromStdString(sat_GLOs[i].type)] = temp;
}else{
//如果type_prns中有该类型,则添加prn
type_prns[QString::fromStdString(sat_GLOs[i].type)].push_back(sat_GLOs[i].prn);
}
}
//去重
for(auto it=type_prns.begin();it!=type_prns.end();it++){
//对it->second去重
std::sort(it->second.begin(),it->second.end());
it->second.erase(std::unique(it->second.begin(),it->second.end()),it->second.end());
}
//comboBox:ui->satType设置为type_prns的key
ui->satType->clear();
for(auto it=type_prns.begin();it!=type_prns.end();it++){
ui->satType->addItem(it->first);
}
//选择satType后更新satPrn
}
void MainWindow::on_calculateBtn_clicked()
{
//判断sats和sat_GLOs是否为空
if(sats.empty()&&sat_GLOs.empty()){
QMessageBox::warning(this,"警告","请先读取卫星数据",QMessageBox::Ok);
//extern gtime_t gpst2utc(gtime_t t);
gtime_t time = timeget();
std::cout<<"time:"<<time.time<<std::endl;
time = utc2gpst(time);
//打印结果
std::cout<<"time:"<<time.time<<std::endl;
//gpst2bdt
time = gpst2bdt(time);
//打印结果
std::cout<<"time:"<<time.time<<std::endl;
//time2epoch()
double* epoch = new double[6];
time2epoch(time,epoch);
//打印结果,用逗号隔开
std::cout<<"epoch:"<<epoch[0]<<","<<epoch[1]<<","<<epoch[2]<<","<<epoch[3]<<","<<epoch[4]<<","<<epoch[5]<<std::endl;
return;
}
//遍历每一个sats
for(int i=0;i<sats.size();i++){
position rs;
rs = calculate(sats[i],timeToTimestamp(sats[i].hour,sats[i].minute,sats[i].second));
//设置解算坐标
sats[i].calculate_x = rs.x;
sats[i].calculate_y = rs.y;
sats[i].calculate_z = rs.z;
//获取BLH
double b = ui->BInput->text().toDouble();
double l = ui->LInput->text().toDouble();
double h = ui->HInput->text().toDouble();
//将BLH转换为XYZ,extern void pos2ecef(const double *pos, double *r)
double* ecef = new double[3];
double* pos = new double[3];
pos[0] = b*M_PI/180;
pos[1] = l*M_PI/180;
pos[2] = h;
pos2ecef(pos,ecef);
//GTRF转换为WGS-84
if(sats[i].type == "GAL"){
rs.x += 0.02;
rs.y -= 0.01;
rs.z += 0.01;
}
double* enu = new double[3];
double* r = new double[3];
r[0] = rs.x - ecef[0];
r[1] = rs.y - ecef[1];
r[2] = rs.z - ecef[2];
ecef2enu(pos,r,enu);
//计算方位角,方位角A范围在0~360°;若A<0,A=A+2pi;若A>2pi,A=A-2pi
double azimuth = atan2(enu[0],enu[1])*180/M_PI;
if(azimuth<0){
azimuth = azimuth + 360;
}else if(azimuth>360){
azimuth = azimuth - 360;
}
//计算高度角
double elevation = atan2(enu[2],sqrt(enu[0]*enu[0]+enu[1]*enu[1]))*180/M_PI;
//设置方位角
sats[i].azimuth = azimuth;
//设置高度角
sats[i].elevation = elevation;
}
//遍历每一个sat_GLOs
for(int i=0;i<sat_GLOs.size();i++){
//设置解算坐标
const geph_t geph = ConvertToGeph(sat_GLOs[i]);
double rs[3]; // 卫星位置
double dts[2]; // 卫星钟差
double var; // 位置和钟差的方差
gtime_t _time; // 时间
//time赋值为GPST时间
_time = timeadd(geph.toe,0.0);
geph2pos(_time, &geph, rs, dts, &var);
position result;
result.x = rs[0];
result.y = rs[1];
result.z = rs[2];
sat_GLOs[i].calculate_x = result.x;
sat_GLOs[i].calculate_y = result.y;
sat_GLOs[i].calculate_z = result.z;
//获取BLH
double b = ui->BInput->text().toDouble();
double l = ui->LInput->text().toDouble();
double h = ui->HInput->text().toDouble();
//将BLH转换为XYZ,extern void pos2ecef(const double *pos, double *r)
double* ecef = new double[3];
double* pos = new double[3];
pos[0] = b*M_PI/180;
pos[1] = l*M_PI/180;
pos[2] = h;
pos2ecef(pos,ecef);
//将XYZ转换为ENU
double* enu = new double[3];
double* r = new double[3];
//PZ-90转换为WGS-84
if(sat_GLOs[i].type == "GLO"){
Eigen::Matrix <double, 3, 3> b;
b << 1, 1.728e-6, -0.017e-6,
1.728e-6, 1, 0.076e-6,
0.0178e-6, -0.076e-6, 1;
Eigen::Matrix <double, 3, 1> c;
c << sat_GLOs[i].calculate_x, sat_GLOs[i].calculate_y, sat_GLOs[i].calculate_z;
Eigen::Matrix <double, 3, 1> a;
a << -0.47, -0.51, -1.56;
Eigen::Matrix <double, 3, 1> Rk;
Rk = a + (1+22e-9) * b * c;
sat_GLOs[i].calculate_x = Rk(0);
sat_GLOs[i].calculate_y = Rk(1);
sat_GLOs[i].calculate_z = Rk(2);
}
r[0] = sat_GLOs[i].calculate_x - ecef[0];
r[1] = sat_GLOs[i].calculate_y - ecef[1];
r[2] = sat_GLOs[i].calculate_z - ecef[2];
ecef2enu(pos,r,enu);
//计算方位角,方位角A范围在0~360°;若A<0,A=A+2pi;若A>2pi,A=A-2pi
double azimuth = atan2(enu[0],enu[1])*180/M_PI;
if(azimuth<0){
azimuth = azimuth + 360;
}else if(azimuth>360){
azimuth = azimuth - 360;
}
//计算高度角
double elevation = atan2(enu[2],sqrt(enu[0]*enu[0]+enu[1]*enu[1]))*180/M_PI;
//设置方位角
sat_GLOs[i].azimuth = azimuth;
//设置高度角
sat_GLOs[i].elevation = elevation;
//设置解算坐标
sat_GLOs[i].calculate_x = result.x;
sat_GLOs[i].calculate_y = result.y;
sat_GLOs[i].calculate_z = result.z;
}
//渲染到表格
//GPS,BDS,GAL
for(int i=0;i<sats.size();i++){
//设置解算坐标,xyz的逗号换成换行,占三行
ui->everyTable->setItem(i,2,new QTableWidgetItem(QString::fromStdString(std::to_string(sats[i].calculate_x)+"\n"+std::to_string(sats[i].calculate_y)+"\n"+std::to_string(sats[i].calculate_z))));
//设置方位角
ui->everyTable->setItem(i,5,new QTableWidgetItem(QString::fromStdString(std::to_string(sats[i].azimuth))));
//设置高度角
ui->everyTable->setItem(i,6,new QTableWidgetItem(QString::fromStdString(std::to_string(sats[i].elevation))));
//如果precise_x不为0,则设置precise_x
if(sats[i].precise_x !=0){
//设置解算坐标,xyz的逗号换成换行,占三行
ui->everyTable->setItem(i,3,new QTableWidgetItem(QString::fromStdString(std::to_string(sats[i].precise_x)+"\n"+std::to_string(sats[i].precise_y)+"\n"+std::to_string(sats[i].precise_z))));
//设置偏差,xyz的逗号换成换行,占三行
ui->everyTable->setItem(i,4,new QTableWidgetItem(QString::fromStdString(std::to_string(sats[i].calculate_x-sats[i].precise_x)+"\n"+std::to_string(sats[i].calculate_y-sats[i].precise_y)+"\n"+std::to_string(sats[i].calculate_z-sats[i].precise_z))));
}
}
//GLO,在GPS,BDS,GAL后面
for(int i=0;i<sat_GLOs.size();i++){
//设置解算坐标,xyz的逗号换成换行,占三行
ui->everyTable->setItem(i+sats.size(),2,new QTableWidgetItem(QString::fromStdString(std::to_string(sat_GLOs[i].calculate_x)+"\n"+std::to_string(sat_GLOs[i].calculate_y)+"\n"+std::to_string(sat_GLOs[i].calculate_z))));
//设置方位角
ui->everyTable->setItem(i+sats.size(),5,new QTableWidgetItem(QString::fromStdString(std::to_string(sat_GLOs[i].azimuth))));
//设置高度角
ui->everyTable->setItem(i+sats.size(),6,new QTableWidgetItem(QString::fromStdString(std::to_string(sat_GLOs[i].elevation))));
//如果precise_x不为0,则设置precise_x
if(sat_GLOs[i].precise_x!=0){
ui->everyTable->setItem(i+sats.size(),3,new QTableWidgetItem(QString::fromStdString(std::to_string(sat_GLOs[i].precise_x)+"\n"+std::to_string(sat_GLOs[i].precise_y)+"\n"+std::to_string(sat_GLOs[i].precise_z))));
//设置偏差,xyz的逗号换成换行,占三行
ui->everyTable->setItem(i+sats.size(),4,new QTableWidgetItem(QString::fromStdString(std::to_string(sat_GLOs[i].calculate_x-sat_GLOs[i].precise_x)+"\n"+std::to_string(sat_GLOs[i].calculate_y-sat_GLOs[i].precise_y)+"\n"+std::to_string(sat_GLOs[i].calculate_z-sat_GLOs[i].precise_z))));
}
}
//表格自适应
ui->everyTable->resizeColumnsToContents();
//第一列宽+10
ui->everyTable->setColumnWidth(0,ui->everyTable->columnWidth(0)+10);
//第3列宽+10
ui->everyTable->setColumnWidth(2,ui->everyTable->columnWidth(2)+10);
if(sats.size()!=0)
//ui->openglTime设置成sat[0]的time
ui->openglTime->setTime(QTime(sats[0].hour,sats[0].minute,sats[0].second));
else if(sat_GLOs.size()!=0)
//ui->openglTime设置成sat_GLOs[0]的time
ui->openglTime->setTime(QTime(sat_GLOs[0].hour,sat_GLOs[0].minute,sat_GLOs[0].second));
//提示:计算完成
QMessageBox::information(this,"提示","计算完成",QMessageBox::Ok);
}
void MainWindow::on_openglBtn_clicked()
{
//判断tabWidget当前页是否是第一页
{
//判断everytable是否为空
if(ui->everyTable->rowCount()==0){
QMessageBox::warning(this,"警告","请先读取卫星数据",QMessageBox::Ok);
return;
}
vector<Satellite> all_sats;
//GPS
{
std::vector<Satellite> gps;
//筛选出GPS
for(int i=0;i<sats.size();i++){
if(sats[i].type == "GPS"){
gps.push_back(sats[i]);
}
}
//求出gps2h中的prn的种类
std::vector<int> prns;
for(int i=0;i<gps.size();i++){
if(std::find(prns.begin(),prns.end(),gps[i].prn)==prns.end()){
prns.push_back(gps[i].prn);
}
}
//定义一个字典,将prn号相同的卫星放在一起
std::map<int,std::vector<Satellite>> gps2h_map;
for(int i=0;i<prns.size();i++){
std::vector<Satellite> temp;
for(int j=0;j<gps.size();j++){
if(gps[j].prn==prns[i]){
temp.push_back(gps[j]);
}
}
gps2h_map[prns[i]] = temp;
}
//获取时间
int hour = ui->openglTime->time().hour();
int minute = ui->openglTime->time().minute();
double second = ui->openglTime->time().second();
double target_time = timeToTimestamp(hour,minute,second);
//间接平差函数
// t0是初始时间(从0时为起点的时间戳),delt_t是时间间隔(s),satellites卫星数组,n是切比雪夫多项式阶数,slice取时间间隔的秒数(s),target是预测时间的时间戳
// position GPS_Adjust(double t0, double delt_t, vector<Satellite> satellites, int n, double slice,double target)
double t0;//起始时间
if(target_time<timeToTimestamp(1,0,0.0)){
t0 = 0;
}else{
t0 = target_time - timeToTimestamp(1,0,0.0);
}
double delt_t = 60*60*2;//时间间隔
int n = 10;//阶数
double slice = 60;//取时间间隔的秒数(s)
double target = target_time;//预测时间的时间戳
//遍历gps2h_map,调用GPS_Adjust函数
std::map<int,position> result_sats;
for(auto it=gps2h_map.begin();it!=gps2h_map.end();it++){
position rs;
rs = GPS_Adjust(t0,delt_t,it->second,n,slice,target);
result_sats[it->first] = rs;
}
//坐标转换及导入
for(auto it=result_sats.begin();it!=result_sats.end();it++){
std::cout<<it->first<<":"<<it->second.x<<","<<it->second.y<<","<<it->second.z<<std::endl;
//获取BLH
double b = ui->BInput->text().toDouble();
double l = ui->LInput->text().toDouble();
double h = ui->HInput->text().toDouble();
//将BLH转换为XYZ,extern void pos2ecef(const double *pos, double *r)
double* ecef = new double[3];
double* pos = new double[3];
pos[0] = b*M_PI/180;
pos[1] = l*M_PI/180;
pos[2] = h;
pos2ecef(pos,ecef);
double* enu = new double[3];
double* r = new double[3];
r[0] = it->second.x - ecef[0];
r[1] = it->second.y - ecef[1];
r[2] = it->second.z - ecef[2];
ecef2enu(pos,r,enu);
//计算方位角,方位角A范围在0~360°;若A<0,A=A+2pi;若A>2pi,A=A-2pi
double azimuth = atan2(enu[0],enu[1])*180/M_PI;
if(azimuth<0){
azimuth = azimuth + 360;
}else if(azimuth>360){
azimuth = azimuth - 360;
}
//计算高度角
double elevation = atan2(enu[2],sqrt(enu[0]*enu[0]+enu[1]*enu[1]))*180/M_PI;
Satellite s;
s.type = "GPS";
s.prn = it->first;
s.calculate_x = it->second.x;
s.calculate_y = it->second.y;
s.calculate_z = it->second.z;
s.azimuth = azimuth;
s.elevation = elevation;
all_sats.push_back(s);
}
}
//GAL
{
std::vector<Satellite> gal;
//筛选出GAL
for(int i=0;i<sats.size();i++){
if(sats[i].type == "GAL"){
gal.push_back(sats[i]);
}
}
//求出gal2h中的prn的种类
std::vector<int> prns2;
for(int i=0;i<gal.size();i++){
if(std::find(prns2.begin(),prns2.end(),gal[i].prn)==prns2.end()){
prns2.push_back(gal[i].prn);
}
}
//定义一个字典,将prn号相同的卫星放在一起
std::map<int,std::vector<Satellite>> gal2h_map;
for(int i=0;i<prns2.size();i++){
std::vector<Satellite> temp;
for(int j=0;j<gal.size();j++){
if(gal[j].prn==prns2[i]){
temp.push_back(gal[j]);
}
}
gal2h_map[prns2[i]] = temp;
}
//获取时间
int hour2 = ui->openglTime->time().hour();
int minute2 = ui->openglTime->time().minute();
double second2 = ui->openglTime->time().second();
double target_time2 = timeToTimestamp(hour2,minute2,second2);
//间接平差函数
// t0是初始时间(从0时为起点的时间戳),delt_t是时间间隔(s),satellites卫星数组,n是切比雪夫多项式阶数,slice取时间间隔的秒数(s),target是预测时间的时间戳
// position GPS_Adjust(double t0, double delt_t, vector<Satellite> satellites, int n, double slice,double target)
double t02;//起始时间
if(target_time2<timeToTimestamp(1,0,0.0)){
t02 = 0;
}else{
t02 = target_time2 - timeToTimestamp(1,0,0.0);
}
double delt_t2 = 60*60*2;//时间间隔
int n2 = 10;//阶数
double slice2 = 60;//取时间间隔的秒数(s)
double target2 = target_time2;//预测时间的时间戳
//遍历gal2h_map,调用GPS_Adjust函数
std::map<int,position> result_sats2;
for(auto it=gal2h_map.begin();it!=gal2h_map.end();it++){
position rs;
rs = GPS_Adjust(t02,delt_t2,it->second,n2,slice2,target2);
result_sats2[it->first] = rs;
}
//坐标转换及导入
for(auto it=result_sats2.begin();it!=result_sats2.end();it++){
std::cout<<it->first<<":"<<it->second.x<<","<<it->second.y<<","<<it->second.z<<std::endl;
//获取BLH
double b = ui->BInput->text().toDouble();
double l = ui->LInput->text().toDouble();
double h = ui->HInput->text().toDouble();
//将BLH转换为XYZ,extern void pos2ecef(const double *pos, double *r)
double* ecef = new double[3];
double* pos = new double[3];
pos[0] = b*M_PI/180;
pos[1] = l*M_PI/180;
pos[2] = h;
pos2ecef(pos,ecef);
//将second.x,second.y,second.z转换为wgs84的XYZ
it->second.x +=0.02;
it->second.y -=0.01;
it->second.z +=0.01;
double* enu = new double[3];
double* r = new double[3];
r[0] = it->second.x - ecef[0];
r[1] = it->second.y - ecef[1];
r[2] = it->second.z - ecef[2];
//计算方位角,方位角A范围在0~360°;若A<0,A=A+2pi;若A>2pi,A=A-2pi
ecef2enu(pos,r,enu);
double azimuth = atan2(enu[0],enu[1])*180/M_PI;
if(azimuth<0){
azimuth = azimuth + 360;
}else if(azimuth>360){
azimuth = azimuth - 360;
}
//计算高度角
double elevation = atan2(enu[2],sqrt(enu[0]*enu[0]+enu[1]*enu[1]))*180/M_PI;
Satellite s;
s.type = "GAL";
s.prn = it->first;
s.calculate_x = it->second.x;
s.calculate_y = it->second.y;
s.calculate_z = it->second.z;
s.azimuth = azimuth;
s.elevation = elevation;
all_sats.push_back(s);
}
}
//BDS
{
std::vector<Satellite> bds;
//筛选出BDS
for(int i=0;i<sats.size();i++){
if(sats[i].type == "BDS"){
bds.push_back(sats[i]);
}
}
//求出bds2h中的prn的种类
std::vector<int> prns3;
for(int i=0;i<bds.size();i++){