-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
861 lines (778 loc) · 38.1 KB
/
main.py
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
from __future__ import annotations
from datetime import datetime
import math
import os
import platform
import subprocess
import time
import shutil
import serial
from PyQt5.QtGui import QStandardItemModel, QStandardItem
from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog
from modules.BackendHandler import Handler
from modules.UBXMessage import UBXMessage
from modules.Utils import msg2bits, splitBytes, strfind, find, decode_RXM_RAWX
# RTKLib tool configuration for both unix and windowsnt
# from WindowsNT
if os.name == 'nt':
from serial.tools.list_ports_windows import comports
rtklibPath = os.path.dirname(os.path.abspath(__file__)) + "/RTKLIB-master/bin/"
rtklibConvbin = rtklibPath + "convbin.exe"
# Mac & Linux are POSIX compliant (UNIX like systems)
elif os.name == 'posix':
from serial.tools.list_ports_posix import comports
rtklibPath = os.path.dirname(os.path.abspath(__file__)) + "/RTKLIB-master/app/convbin/gcc/"
rtklibConvbin = rtklibPath + "convbin"
else:
raise ImportError("OS Platform not properly detected")
BAUDRATES = ['9600', '57600']
CONSTELLATIONS = ["GPS","SBAS","Galileo","BeiDou","IMES","QZSS","GLONASS"]
# PARAMS to Configure
TIMEOUT = 10
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow():
"""
Classe che inizializza la GUI.
"""
def __init__(self, MainWindow):
"""
Configura la UI preparando gli elementi grafici, bloccandoli e riempendoli.
:param MainWindow: finestra in cui lavorare
"""
self.HANDLERS = {}
self.CONNECTED_PORTS = []
self.MainWindow = MainWindow
self.setupUi()
self.MainWindow.show()
# blocco tutto
self.sourcesGroupBox.setEnabled(False)
self.rinexGroupBox.setEnabled(False)
# aggiungo i baudrates
self.cmbBaudRateUBX.clear()
for b in BAUDRATES:
self.cmbBaudRateUBX.addItem(b)
# aggiungo le costellazioni
self.modelCostellazioni = QStandardItemModel()
for c in range(len(CONSTELLATIONS)):
item = QStandardItem(CONSTELLATIONS[c])
item.setCheckable(True)
checked = False # di default non sono selezionati
check = QtCore.Qt.Checked if checked else QtCore.Qt.Unchecked
item.setCheckState(check)
self.modelCostellazioni.appendRow(item)
self.constellationsListView.setModel(self.modelCostellazioni)
# seleziono "Serial Port" come default tab
self.tabWidget.setCurrentIndex(0)
# handle events
self.btnChooseUBXPath.clicked.connect(self.chooseFolder)
self.btnDiscoverUBXDevices.clicked.connect(self.discoverDevices)
self.btnRecordUBX.clicked.connect(self.recordUBXs)
self.btnStopUBX.clicked.connect(self.stopUBXs)
self.ubxDevicesListView.clicked.connect(self.toggleUBXControl)
self.btnRunRINEX.clicked.connect(self.startRinex)
self.btnAddFile.clicked.connect(self.loadFiles)
self.btnRemoveSelectedFile.clicked.connect(self.removeFiles)
self.recordTS = ""
def setupUi(self):
"""
Metodo che costruisce gli elementi aggiungendoli ai vari elementi contenitori. Aggiunge i contenitori alla GUI.
:return:
"""
MainWindow = self.MainWindow
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1023, 589)
MainWindow.setContextMenuPolicy(QtCore.Qt.NoContextMenu)
MainWindow.setStatusTip("")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout_13 = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout_13.setObjectName("gridLayout_13")
self.gridLayout_12 = QtWidgets.QGridLayout()
self.gridLayout_12.setObjectName("gridLayout_12")
self.gridLayout_5 = QtWidgets.QGridLayout()
self.gridLayout_5.setObjectName("gridLayout_5")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label.setObjectName("label")
self.gridLayout_5.addWidget(self.label, 0, 0, 1, 1)
self.txtUBXPath = QtWidgets.QLineEdit(self.centralwidget)
self.txtUBXPath.setReadOnly(True)
self.txtUBXPath.setObjectName("txtUBXPath")
self.gridLayout_5.addWidget(self.txtUBXPath, 0, 1, 1, 1)
self.btnChooseUBXPath = QtWidgets.QPushButton(self.centralwidget)
self.btnChooseUBXPath.setObjectName("btnChooseUBXPath")
self.gridLayout_5.addWidget(self.btnChooseUBXPath, 0, 2, 1, 1)
self.gridLayout_12.addLayout(self.gridLayout_5, 0, 0, 1, 2)
self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox.setObjectName("groupBox")
self.gridLayout_11 = QtWidgets.QGridLayout(self.groupBox)
self.gridLayout_11.setObjectName("gridLayout_11")
self.txtLogs = QtWidgets.QTextEdit(self.groupBox)
self.txtLogs.setReadOnly(True)
self.txtLogs.setObjectName("txtLogs")
self.gridLayout_11.addWidget(self.txtLogs, 0, 0, 1, 1)
self.gridLayout_12.addWidget(self.groupBox, 0, 2, 2, 1)
self.sourcesGroupBox = QtWidgets.QGroupBox(self.centralwidget)
self.sourcesGroupBox.setObjectName("sourcesGroupBox")
self.gridLayout_4 = QtWidgets.QGridLayout(self.sourcesGroupBox)
self.gridLayout_4.setObjectName("gridLayout_4")
self.tabWidget = QtWidgets.QTabWidget(self.sourcesGroupBox)
self.tabWidget.setObjectName("tabWidget")
self.tab = QtWidgets.QWidget()
self.tab.setObjectName("tab")
self.gridLayout_3 = QtWidgets.QGridLayout(self.tab)
self.gridLayout_3.setObjectName("gridLayout_3")
self.gridLayout = QtWidgets.QGridLayout()
self.gridLayout.setObjectName("gridLayout")
self.ubxDevicesListView = QtWidgets.QListView(self.tab)
self.ubxDevicesListView.setObjectName("ubxDevicesListView")
self.gridLayout.addWidget(self.ubxDevicesListView, 0, 0, 5, 1)
self.btnDiscoverUBXDevices = QtWidgets.QPushButton(self.tab)
font = QtGui.QFont()
font.setStrikeOut(False)
font.setKerning(True)
self.btnDiscoverUBXDevices.setFont(font)
self.btnDiscoverUBXDevices.setAcceptDrops(False)
self.btnDiscoverUBXDevices.setObjectName("btnDiscoverUBXDevices")
self.gridLayout.addWidget(self.btnDiscoverUBXDevices, 0, 1, 1, 3)
self.label_3 = QtWidgets.QLabel(self.tab)
self.label_3.setObjectName("label_3")
self.gridLayout.addWidget(self.label_3, 1, 1, 1, 1)
self.cmbBaudRateUBX = QtWidgets.QComboBox(self.tab)
self.cmbBaudRateUBX.setObjectName("cmbBaudRateUBX")
self.gridLayout.addWidget(self.cmbBaudRateUBX, 1, 2, 1, 2)
#self.chkStartRecordingOnConnection = QtWidgets.QCheckBox(self.tab)
font = QtGui.QFont()
font.setPointSize(8)
#self.chkStartRecordingOnConnection.setFont(font)
#self.chkStartRecordingOnConnection.setObjectName("chkStartRecordingOnConnection")
#self.gridLayout.addWidget(self.chkStartRecordingOnConnection, 2, 1, 1, 2)
#self.btnStartUBXDevicesConnection = QtWidgets.QPushButton(self.tab)
#self.btnStartUBXDevicesConnection.setObjectName("btnStartUBXDevicesConnection")
#self.gridLayout.addWidget(self.btnStartUBXDevicesConnection, 2, 3, 1, 1)
self.btnRecordUBX = QtWidgets.QPushButton(self.tab)
self.btnRecordUBX.setObjectName("btnRecordUBX")
self.gridLayout.addWidget(self.btnRecordUBX, 3, 1, 1, 3)
self.btnStopUBX = QtWidgets.QPushButton(self.tab)
self.btnStopUBX.setObjectName("btnStopUBX")
self.gridLayout.addWidget(self.btnStopUBX, 4, 1, 1, 3)
self.gridLayout_3.addLayout(self.gridLayout, 0, 0, 1, 1)
self.tabWidget.addTab(self.tab, "")
self.tab_2 = QtWidgets.QWidget()
self.tab_2.setObjectName("tab_2")
self.gridLayout_14 = QtWidgets.QGridLayout(self.tab_2)
self.gridLayout_14.setObjectName("gridLayout_14")
self.gridLayout_2 = QtWidgets.QGridLayout()
self.gridLayout_2.setObjectName("gridLayout_2")
self.filesListView = QtWidgets.QListView(self.tab_2)
self.filesListView.setObjectName("filesListView")
self.gridLayout_2.addWidget(self.filesListView, 0, 0, 2, 1)
self.btnAddFile = QtWidgets.QPushButton(self.tab_2)
font = QtGui.QFont()
font.setStrikeOut(False)
font.setKerning(True)
self.btnAddFile.setFont(font)
self.btnAddFile.setAcceptDrops(False)
self.btnAddFile.setObjectName("btnAddFile")
self.gridLayout_2.addWidget(self.btnAddFile, 0, 1, 1, 1)
self.btnRemoveSelectedFile = QtWidgets.QPushButton(self.tab_2)
font = QtGui.QFont()
font.setPointSize(7)
font.setStrikeOut(False)
font.setKerning(True)
self.btnRemoveSelectedFile.setFont(font)
self.btnRemoveSelectedFile.setAcceptDrops(False)
self.btnRemoveSelectedFile.setObjectName("btnRemoveSelectedFile")
self.gridLayout_2.addWidget(self.btnRemoveSelectedFile, 1, 1, 1, 1)
self.gridLayout_14.addLayout(self.gridLayout_2, 0, 0, 1, 1)
self.tabWidget.addTab(self.tab_2, "")
self.gridLayout_4.addWidget(self.tabWidget, 0, 0, 1, 1)
self.gridLayout_12.addWidget(self.sourcesGroupBox, 1, 0, 1, 2)
self.groupBox_3 = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox_3.setObjectName("groupBox_3")
self.gridLayout_10 = QtWidgets.QGridLayout(self.groupBox_3)
self.gridLayout_10.setObjectName("gridLayout_10")
self.constellationsListView = QtWidgets.QListView(self.groupBox_3)
self.constellationsListView.setObjectName("constellationsListView")
self.gridLayout_10.addWidget(self.constellationsListView, 0, 0, 1, 1)
self.gridLayout_12.addWidget(self.groupBox_3, 2, 0, 1, 1)
self.rinexGroupBox = QtWidgets.QGroupBox(self.centralwidget)
self.rinexGroupBox.setObjectName("rinexGroupBox")
self.gridLayout_9 = QtWidgets.QGridLayout(self.rinexGroupBox)
self.gridLayout_9.setObjectName("gridLayout_9")
self.gridLayout_8 = QtWidgets.QGridLayout()
self.gridLayout_8.setVerticalSpacing(40)
self.gridLayout_8.setObjectName("gridLayout_8")
self.groupBox_4 = QtWidgets.QGroupBox(self.rinexGroupBox)
self.groupBox_4.setObjectName("groupBox_4")
self.gridLayout_7 = QtWidgets.QGridLayout(self.groupBox_4)
self.gridLayout_7.setObjectName("gridLayout_7")
self.gridLayout_6 = QtWidgets.QGridLayout()
self.gridLayout_6.setObjectName("gridLayout_6")
self.rinexVersion212_radio = QtWidgets.QRadioButton(self.groupBox_4)
self.rinexVersion212_radio.setChecked(True)
self.rinexVersion212_radio.setObjectName("rinexVersion212_radio")
self.gridLayout_6.addWidget(self.rinexVersion212_radio, 0, 0, 1, 1)
self.rinexVersion302_radio = QtWidgets.QRadioButton(self.groupBox_4)
self.rinexVersion302_radio.setObjectName("rinexVersion302_radio")
self.gridLayout_6.addWidget(self.rinexVersion302_radio, 0, 1, 1, 1)
self.gridLayout_7.addLayout(self.gridLayout_6, 0, 0, 1, 1)
self.gridLayout_8.addWidget(self.groupBox_4, 0, 0, 1, 1)
self.btnRunRINEX = QtWidgets.QPushButton(self.rinexGroupBox)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.btnRunRINEX.sizePolicy().hasHeightForWidth())
self.btnRunRINEX.setSizePolicy(sizePolicy)
self.btnRunRINEX.setObjectName("btnRunRINEX")
self.gridLayout_8.addWidget(self.btnRunRINEX, 1, 0, 1, 1)
self.chkSplitRinexNav = QtWidgets.QCheckBox(self.rinexGroupBox)
self.chkSplitRinexNav.setObjectName("chkSplitRinexNav")
self.gridLayout_8.addWidget(self.chkSplitRinexNav, 2, 0, 1, 1)
self.gridLayout_9.addLayout(self.gridLayout_8, 0, 0, 1, 1)
self.gridLayout_12.addWidget(self.rinexGroupBox, 2, 1, 1, 2)
self.gridLayout_13.addLayout(self.gridLayout_12, 0, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1023, 20))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
self.tabWidget.setCurrentIndex(1)
self.tabWidget.removeTab(1)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.modelFiles = None
self.model = None
def retranslateUi(self, MainWindow):
"""
Metodo che imposta le stringhe relative ai testi e titoli dei vari elementi creati.
:param MainWindow:
:return:
"""
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "GPSDataLoggerParser"))
self.label.setText(_translate("MainWindow", "NMEA and RINEX\noutput path:"))
self.txtUBXPath.setPlaceholderText(_translate("MainWindow", "press \"Choose\" button to select the path where to save collected datas"))
self.btnChooseUBXPath.setText(_translate("MainWindow", "Choose"))
self.groupBox.setTitle(_translate("MainWindow", "Messages and Logs"))
self.sourcesGroupBox.setTitle(_translate("MainWindow", "Sources"))
self.btnDiscoverUBXDevices.setText(_translate("MainWindow", "Discover Devices"))
self.label_3.setText(_translate("MainWindow", "Baud Rate:"))
#self.chkStartRecordingOnConnection.setText(_translate("MainWindow", "Start Recording\non Connection"))
#self.btnStartUBXDevicesConnection.setText(_translate("MainWindow", "Connect"))
self.btnRecordUBX.setText(_translate("MainWindow", "Record"))
self.btnStopUBX.setText(_translate("MainWindow", "Stop"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("MainWindow", "Serial Port"))
self.btnAddFile.setText(_translate("MainWindow", "Add File(s)"))
self.btnRemoveSelectedFile.setText(_translate("MainWindow", "Remove Selected Files"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("MainWindow", "UBX Files"))
self.groupBox_3.setTitle(_translate("MainWindow", "GNSS"))
self.rinexGroupBox.setTitle(_translate("MainWindow", "RINEX Conversion"))
self.groupBox_4.setTitle(_translate("MainWindow", "RINEX Version"))
self.rinexVersion212_radio.setText(_translate("MainWindow", "2.12"))
self.rinexVersion302_radio.setText(_translate("MainWindow", "3.02"))
self.btnRunRINEX.setText(_translate("MainWindow", "Run Conversion"))
self.chkSplitRinexNav.setText(_translate("MainWindow", "Split .nav in different files per constellation"))
# EVENTS
def chooseFolder(self):
"""
Metodo invocato su pressione del pulsante per la scelta della directory di lavoro.
:return:
"""
# scelgo la cartella
folder = QFileDialog.getExistingDirectory(self.MainWindow, "Select Folder")
self.txtUBXPath.setText(folder)
# sblocco il pannello dei devices
self.sourcesGroupBox.setEnabled(True)
# ma blocco il connect, record e lo stop
self.btnRecordUBX.setEnabled(False)
self.btnStopUBX.setEnabled(False)
def discoverDevices(self):
"""
Metodo che ricerca gli ublox connessi alle porte COM e li aggiunge alla checklist.
:return:
"""
self.cmbBaudRateUBX.setEnabled(False)
ports = self.getPorts()
self.model = QStandardItemModel()
for p in ports:
item = QStandardItem(p)
item.setCheckable(True)
checked = False # di default non sono selezionati
check = QtCore.Qt.Checked if checked else QtCore.Qt.Unchecked
item.setCheckState(check)
self.model.appendRow(item)
self.ubxDevicesListView.setModel(self.model)
self.cmbBaudRateUBX.setEnabled(True)
def recordUBXs(self):
"""
Metodo che si occupa di avviare il processo di registrazione degli stream realtime e multithreading. Viene invocato su pressione del pulsante "Record".
:return:
"""
# salvo il timestamp attuale, così da nominare i files ed evitare duplicati
self.recordTS = datetime.now().strftime("%Y%m%d_%H%M%S")
new_GNSS = {
"GPS": 0,
"SBAS": 0,
"Galileo": 0,
"BeiDou": 0,
"IMES": 0,
"QZSS": 0,
"GLONASS": 0
}
enabledGNSS = 0
for c in range(self.modelCostellazioni.rowCount()):
if self.modelCostellazioni.item(c).checkState() == QtCore.Qt.Checked:
new_GNSS[self.modelCostellazioni.item(c).text()] = 1
enabledGNSS += 1
else:
new_GNSS[self.modelCostellazioni.item(c).text()] = 0
if enabledGNSS > 0:
# faccio partire la registrazione dello stream.
# blocco la possibilità di scegliere le costellazioni e i dispositivi e abilito il pulsante di stop
self.btnDiscoverUBXDevices.setEnabled(False)
self.constellationsListView.setEnabled(False)
self.ubxDevicesListView.setEnabled(False)
self.btnStopUBX.setEnabled(True)
self.btnRecordUBX.setEnabled(False)
self.cmbBaudRateUBX.setEnabled(False)
weekField = False
qm = QtWidgets.QMessageBox
r = qm.question(self.MainWindow, "[UBX-RXM-RAWX] 'week' field", "Do you want to have GPS week number in receiver local time reported in the UBX/PC time sync file?",
qm.Yes | qm.No)
if r == qm.Yes:
weekField = True
leapSField = False
qm = QtWidgets.QMessageBox
r = qm.question(self.MainWindow, "[UBX-RXM-RAWX] 'leapS' field",
"Do you want to have GPS leap seconds (GPS-UTC) reported in the UBX/PC time sync file?",
qm.Yes | qm.No)
if r == qm.Yes:
leapSField = True
for d in range(self.model.rowCount()):
if self.model.item(d).checkState() == QtCore.Qt.Checked:
new_connection = self.model.item(d).text()
new_handler = Handler(self, new_connection, self.cmbBaudRateUBX.currentText(), TIMEOUT, new_GNSS, self.txtUBXPath.text(), weekField, leapSField)
if new_handler.isActive():
self.CONNECTED_PORTS.append(new_connection)
self.HANDLERS[new_connection] = new_handler
self.HANDLERS[new_connection].handleData()
else:
QtWidgets.QMessageBox.about(self.MainWindow, "Error", f"Cannot connect to {new_connection}")
else:
QtWidgets.QMessageBox.about(self.MainWindow, "Error", "You don't have selected any GNSS.")
def stopUBXs(self):
"""
Metodo che interrompe la registrazione degli stream e quindi richiede la terminazione dei thread.
:return:
"""
inactive = []
handler_keys = list(self.HANDLERS.keys())
if len(handler_keys) > 0:
for key in handler_keys:
self.HANDLERS[key].stop(self.recordTS)
#if not self.HANDLERS[key].logger.is_active:
self.HANDLERS.pop(key, "")
inactive.append(key)
# Remove corresponding table element
for port in inactive:
self.printLog(f"[LOGGER] {port} disconnected")
index = self.CONNECTED_PORTS.index(port)
self.CONNECTED_PORTS.pop(index)
self.btnDiscoverUBXDevices.setEnabled(True)
self.constellationsListView.setEnabled(True)
self.ubxDevicesListView.setEnabled(True)
self.btnStopUBX.setEnabled(False)
self.btnRecordUBX.setEnabled(True)
self.cmbBaudRateUBX.setEnabled(True)
#se l'acquisizioni è valida, posso procedere alla conversione
valid = True
if valid:
self.rinexGroupBox.setEnabled(True)
def loadFiles(self):
"""
Metodo che apre un prompt per la raccolta dei files da aggiungere alla checklist.
:return:
"""
filter = "UBX (*.ubx)"
file_name = QtWidgets.QFileDialog()
file_name.setFileMode(QFileDialog.ExistingFiles)
names, _ = file_name.getOpenFileNames(self.MainWindow, "Open files", ".", filter)
self.modelFiles = QStandardItemModel()
for n in names:
self.rinexGroupBox.setEnabled(True)
item = QStandardItem(n)
item.setCheckable(False)
checked = True # di default non sono selezionati
check = QtCore.Qt.Checked if checked else QtCore.Qt.Unchecked
item.setCheckState(check)
self.modelFiles.appendRow(item)
# leggo il file
self.printLog("Reading file \"%s\". " % (n))
dr = open(n, "rb")
data_rover = bytearray()
byte = dr.read(1)
while byte:
data_rover.append(byte[0])
byte = dr.read(1)
(ubxData, nmeaData) = decode_ublox_file(data_rover)
nmeaFile = open(self.txtUBXPath.text() + "/" + os.path.basename(n) + "_NMEA.txt", "wb")
type = ""
if (nmeaData is not None or ubxData is not None) and (len(nmeaData) > 0 or len(ubxData) > 0):
if nmeaData is not None and len(nmeaData) > 0:
type += " NMEA"
for n in nmeaData:
nmeaFile.write(bytes(n.encode()))
self.printLog("Decoded %s message(s)" % type)
nmeaFile.close()
self.filesListView.setModel(self.modelFiles)
self.printLog("Files correctly loaded. Ready for RINEX conversion.")
def removeFiles(self):
"""
Metodo che elimina i files dalla checklist.
:return:
"""
selected = 0
r2del = []
for f in range(self.modelFiles.rowCount()):
if self.modelFiles.item(f).checkState() == QtCore.Qt.Checked:
r2del.append(self.modelFiles.item(f).row())
selected += 1
if not selected > 0:
QtWidgets.QMessageBox.about(self.MainWindow, "Error", "No selected files to delete.")
else:
for r in r2del:
self.modelFiles.removeRow(r)
self.filesListView.setModel(self.modelFiles)
def startRinex(self):
"""
Metodo che avvia il processo di generazione dei files RINEX eseguendo CONVBIN.
:return:
"""
self.btnRunRINEX.setEnabled(False)
self.chkSplitRinexNav.setEnabled(False)
self.rinexVersion212_radio.setEnabled(False)
self.rinexVersion302_radio.setEnabled(False)
self.btnDiscoverUBXDevices.setEnabled(False)
self.constellationsListView.setEnabled(False)
self.ubxDevicesListView.setEnabled(False)
self.btnStopUBX.setEnabled(False)
self.btnRecordUBX.setEnabled(False)
self.cmbBaudRateUBX.setEnabled(False)
self.txtLogs.clear()
# serial devices
if self.model is not None:
for d in range(self.model.rowCount()):
if self.model.item(d).checkState() == QtCore.Qt.Checked:
new_connection = self.model.item(d).text().replace("/","_")
infile = self.txtUBXPath.text() + "/" + new_connection + "_" + self.recordTS + "_rover.ubx"
infile = infile.replace("/","/")
outfile_obs = new_connection + "_" + self.recordTS + "_rinex.obs"
outfile_nav = new_connection + "_" + self.recordTS + "_rinex.nav"
convbin_path = rtklibPath
version = "2.12"
if self.rinexVersion302_radio.isChecked():
version = "3.02"
if self.chkSplitRinexNav.checkState() == QtCore.Qt.Checked:
run_convbin_obs = "%s %s -od -os -oi -ot -ol -v %s -d %s" % (rtklibConvbin, infile, version, self.txtUBXPath.text())
else:
run_convbin_obs = "%s %s -od -os -oi -ot -ol -o %s -n %s -v %s -d %s" % (rtklibConvbin, infile, outfile_obs, outfile_nav, version, self.txtUBXPath.text())
# TODO: check if initial rtklibPath modification works on both linux and windows system (I modified on windows...)
self.printLog("[RINEX " + new_connection + "] " + run_convbin_obs)
print("[RINEX " + new_connection + "] " + "************* Conversion ubx --> RINEX *************")
os.chdir(convbin_path)
print(run_convbin_obs)
proc = subprocess.Popen(run_convbin_obs, stdout=subprocess.PIPE, shell=True)
# os.system(run_convbin_obs)
print(proc.communicate())
print("[RINEX " + new_connection + "] " + "************* Done! *************")
# ubx files
if self.modelFiles is not None:
for f in range(self.modelFiles.rowCount()):
if self.modelFiles.item(f).checkState() == QtCore.Qt.Checked:
ubxFile = self.modelFiles.item(f).text()
# copio il file nella working dir
pathname_old, extension_old = os.path.splitext(ubxFile)
targetUBXFile = self.txtUBXPath.text() + "/" + pathname_old.split('/')[-1] + extension_old
shutil.copy(ubxFile, targetUBXFile)
pathname, extension = os.path.splitext(targetUBXFile)
# passo questo a convbin, così da avere i file elaborati direttamente nella working dir
# targetUBXFile = targetUBXFile.replace("/","/")
outfile_obs = pathname.split('/')[-1] + "_rinex.obs"
outfile_nav = pathname.split('/')[-1] + "_rinex.nav"
convbin_path = rtklibPath
version = "2.12"
if self.rinexVersion302_radio.isChecked():
version = "3.02"
if self.chkSplitRinexNav.checkState() == QtCore.Qt.Checked:
run_convbin_obs = "%s %s -od -os -oi -ot -ol -v %s" % (rtklibConvbin, targetUBXFile, version)
else:
run_convbin_obs = "%s %s -od -os -oi -ot -ol -v %s" % (rtklibConvbin, targetUBXFile, version)
self.printLog("[RINEX " + pathname.split('/')[-1] + "] " + run_convbin_obs)
print("[RINEX " + pathname.split('/')[-1] + "] " + "************* Conversion ubx --> RINEX *************")
os.chdir(convbin_path)
print(run_convbin_obs)
os.system(run_convbin_obs)
print("[RINEX " + pathname.split('/')[-1] + "] " + "************* Done! *************")
self.btnRunRINEX.setEnabled(True)
self.chkSplitRinexNav.setEnabled(True)
self.chkSplitRinexNav.setVisible(False) # TODO: sistemare questo
self.rinexVersion212_radio.setEnabled(True)
self.rinexVersion302_radio.setEnabled(True)
self.btnDiscoverUBXDevices.setEnabled(True)
self.constellationsListView.setEnabled(True)
self.ubxDevicesListView.setEnabled(True)
self.btnStopUBX.setEnabled(False)
self.btnRecordUBX.setEnabled(True)
self.cmbBaudRateUBX.setEnabled(True)
qm = QtWidgets.QMessageBox
r = qm.question(self.MainWindow, "RINEX Conversion", "RINEX Conversion has been ended. Open folder with all sources and RINEX files?", qm.Yes | qm.No)
if r == qm.Yes:
self.openFile(self.txtUBXPath.text())
def openFile(self, path):
"""
Metodo usato per l'apertura di un percorso nell'esplora risorse.
:param path:
:return:
"""
if platform.system() == "Windows":
os.startfile(path)
elif platform.system() == "Darwin":
subprocess.Popen(["open", path])
else:
subprocess.Popen(["xdg-open", path])
def getPorts(self) -> list:
"""
Metodo che ritorna tutte le porte COM del pc a cui sono connessi ricevitori ublox.
:return:
"""
serial_objects = comports()
total = len(serial_objects)
active_ports = []
# -------------------------------------------------------------------
self.printLog("Detecting u-blox(s) connected to COM ports...")
for idx in range(total):
so = serial_objects[idx]
s = serial.Serial(so.device, int(self.cmbBaudRateUBX.currentText()))
try:
if s.is_open == False:
s.open()
# libero i bytes letti
bytes2read = s.in_waiting
if bytes2read > 0:
s.read(bytes2read)
# poll for UBX-RXM-RAWX
s.write(b"\xb5\x62\x02\x15\x00\x00\x17\x47")
time.sleep(3)
bytes_1 = s.in_waiting
# bytes_1 = 0
# bytes_2 = 0
# while (bytes_1 != bytes_2 or bytes_1 == 0):
# bytes_1 = s.in_waiting
# time.sleep(0.5)
# bytes_2 = s.in_waiting
replyBIN = ''.join(msg2bits(splitBytes(s.read(bytes_1))))
msgBIN = ''.join(msg2bits([b"\xb5", b"\x62", b"\x02", b"\x15"]))
pos = strfind(msgBIN, replyBIN)
if len(pos) > 0:
l = int(replyBIN[(pos[0] + 32):(pos[0] + 39)], 2) + (
int(replyBIN[(pos[0] + 40):(pos[0] + 47)], 2) * pow(2, 8))
if l != 0:
self.printLog("u-blox receiver detected on port " + so.device)
active_ports.append(so.device)
# break
s.close()
del s
except serial.SerialException as e:
self.printLog("SERIAL ERROR on opening serial port: " + so.device)
break
# -------------------------------------------------------------------
if len(active_ports) == 0:
self.printLog("No u-blox(s) device detected...")
return active_ports
def toggleUBXControl(self):
"""
Metodo che abilita e disabilita le checkbox di checklist.
:return:
"""
selected = 0
for c in range(self.model.rowCount()):
item = self.model.item(c)
if item.checkState() == QtCore.Qt.Checked:
selected += 1
if selected > 0:
self.btnRecordUBX.setEnabled(True)
self.btnStopUBX.setEnabled(False)
else:
self.btnRecordUBX.setEnabled(False)
self.btnStopUBX.setEnabled(False)
def printLog(self, msg: str):
"""
Metodo che si occupa di stampare un messaggio nella console aggiungengolo in coda.
:param msg: messaggio da stampare
:return:
"""
test = GUIUpdater(msg)
test.start()
test.mySignal.connect(self.txtLogs.append)
# self.test.finished.connect(thread_finished)
test.stop()
del test
def decode_ublox_file(msg):
"""
Funzione che decodifica lo stream di file caricati. Costruisce soltanto il file NMEA.
:param msg:
:return:
"""
msg = "".join(msg2bits(splitBytes(msg)))
messaggioUBX = "".join(msg2bits([UBXMessage.SYNC_CHAR_1, UBXMessage.SYNC_CHAR_2])) # b5 62
posUBX = strfind(messaggioUBX, msg)
messaggioNMEA = "".join(msg2bits([b"\x24", b"\x47", b"\x4e"])) # $ G N
posNMEA = strfind(messaggioNMEA, msg)
# variabili che conterranno quello che andrò ad esportare
data = []
NMEA_sentences = []
NMEA_string = ""
# il messaggio che ho è misto: occorre capire l'indice da cui partire a decodificare
if len(posUBX) > 0 and len(posNMEA) > 0:
if posUBX[0] < posNMEA[0]:
pos = posUBX[0]
else:
pos = posNMEA[0]
elif len(posUBX) > 0:
pos = posUBX[0]
elif len(posNMEA) > 0:
pos = posNMEA[0]
else:
return (None, None)
# inizio la fase di decodifica del messaggio
i = 0
# controllo che io abbia UBX o NMEA nei primi 2/3 frammenti
while (pos + 16) <= len(msg):
# controllo se ho l'header UBX
if msg[pos:(pos + 16)] == messaggioUBX:
# aumento il contatore
i += 1
# salto i primi due bytes di intestazione del messaggio
pos += 16
# ora dovrei avere classe, id e lunghezza del payload
if (pos + 32) <= len(msg):
# prendo la classe
classId = int(msg[pos:(pos + 8)], 2).to_bytes(1, byteorder='big')
pos += 8
# prendo l'id
msgId = int(msg[pos:(pos + 8)], 2).to_bytes(1, byteorder='big')
pos += 8
# controllo che il messaggio non sia troncato
if (len(find(posUBX, pos, 1)) > 0):
f = find(posUBX, pos, 1)[0]
else:
f = 0
posNext = posUBX[f]
posRem = posNext - pos
# estraggo la lunghezza del payload (2 byte)
LEN1 = int(msg[pos:(pos + 8)], 2)
pos += 8
LEN2 = int(msg[pos:(pos + 8)], 2)
pos += 8
LEN = LEN1 + (LEN2 * pow(2, 8))
if LEN != 0:
# subito dopo la lunghezza ho il payload lungo LEN, poi due byte di fine stream (checksum)
if (pos + (8 * LEN) + 16) <= len(msg):
# calcolo il checksum
CK_A = 0
CK_B = 0
slices = []
j = pos - 32
while j < (pos + 8 * LEN):
t = msg[j:(j + 8)]
slices.append(int(msg[j:(j + 8)], 2))
j += 8
for r in range(len(slices)):
CK_A = CK_A + slices[r]
CK_B = CK_B + CK_A
CK_A = CK_A % 256
CK_B = CK_B % 256
CK_A_rec = int(msg[(pos + 8 * LEN):(pos + 8 * LEN + 8)], 2)
CK_B_rec = int(msg[(pos + 8 * LEN + 8):(pos + 8 * LEN + 16)], 2)
# controllo se il checksum corrisponde
if CK_A == CK_A_rec and CK_B == CK_B_rec:
s = msg[pos:(pos + (8 * LEN))]
nB = math.ceil(len(s) / 8)
MSG = int(s, 2).to_bytes(nB, 'little')
MSG = splitBytes(MSG)
# posso analizzare il messaggio nel dettaglio, esaminando il payload con l'opportuna funzione in base a id, classe
if classId == b"\x02": # RXM
if msgId == b"\x15": # RXM-RAWX
data.append(decode_RXM_RAWX(MSG))
else:
#printLog("Checksum error.")
# salto il messaggio troncato
if posRem > 0 and (posRem % 8) != 0 and 8 * (LEN + 4) > posRem:
#self.printLog("Truncated UBX message, detected and skipped")
pos = posNext
continue
pos += 8 * LEN
pos += 16
else:
break
else:
break
# controllo se ho l'header NMEA
elif (pos + 24) <= len(msg) and msg[pos:(pos + 24)] == messaggioNMEA:
# cerco la fine del messaggio (CRLF)
# NMEA0183 solitamente è lungo 82, ma al fine di evitare lunghezze non valide sono usati un massimo di 100 caratteri.
if (len(msg) - pos) < 800:
posFineNMEA = strfind("".join(msg2bits(splitBytes(b"\x0d\x0a"))), msg[pos:])
else:
posFineNMEA = strfind("".join(msg2bits(splitBytes(b"\x0d\x0a"))), msg[pos:(pos + 800)])
if len(posFineNMEA) > 0:
# salvo la stringa
while msg[pos:(pos + 8)] != "00001101":
NMEA_string += chr(int(msg[pos:(pos + 8)], 2))
pos += 8
# salvo soltanto l'\n
pos += 8
NMEA_string += chr(int(msg[pos:(pos + 8)], 2))
pos += 8
NMEA_sentences.append(NMEA_string)
NMEA_string = ""
else:
# la sentence NMEA è iniziata, ma non è disponibile.
# scorro l'header e continuo
pos += 24
else:
# controllo se ci sono altri pacchetti
# pos = pos_UBX(find(pos_UBX > pos, 1));
# if (isempty(pos)), break, end;
if len(find(posUBX, pos, 1)) > 0:
p = find(posUBX, pos, 1)[0]
if len(posUBX) >= p:
pos = posUBX[p]
else:
break
return (data, NMEA_sentences)
class GUIUpdater(QtCore.QThread):
"""
Classe che si occupa di registrare un log in una queue al fine di evitare corse critiche tra i thread che acquisiscono dai device in parallelo e l'unico thread che gestisce la gui.
"""
mySignal = QtCore.pyqtSignal(str)
def __init__(self, msg):
super().__init__()
self.msg = msg
def run(self):
# self.setPriority(QtCore.QThread.HighPriority)
#while True:
self.mySignal.emit(self.msg)
def stop(self):
self.is_running = False
# print("Stop Thread")
self.wait()
if __name__ == "__main__":
app = QApplication([])
window = QMainWindow()
ui = Ui_MainWindow(window)
exit(app.exec())