-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlcars.py
1653 lines (1379 loc) · 54.2 KB
/
lcars.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
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
#!/usr/bin/env python
#!/usr/bin/env python
import sys
from PyQt4 import QtGui, QtCore, uic
# from PyQt4.QtGui import QPalette
from PyQt4.QtGui import *
import time
from time import strftime
import os.path
import configparser
import serial
import math
import csv
import calendar
from PyQt4.QtGui import QDialog, QVBoxLayout, QDialogButtonBox, QDateTimeEdit, QApplication
from PyQt4.QtCore import Qt, QDateTime
import fnmatch
import socket
import json
import threading
import urllib.parse
import urllib.request
import os, glob
import subprocess
Modes=[{'implicit': 0, 'coding': 8, 'bandwidth': 20.8, 'spreading': 11, 'lowopt': 1},
{'implicit': 1, 'coding': 5, 'bandwidth': 20.8, 'spreading': 6, 'lowopt': 0},
{'implicit': 0, 'coding': 8, 'bandwidth': 62.5, 'spreading': 8, 'lowopt': 0},
{'implicit': 0, 'coding': 6, 'bandwidth': 250, 'spreading': 7, 'lowopt': 0},
{'implicit': 1, 'coding': 5, 'bandwidth': 250, 'spreading': 6, 'lowopt': 0},
{'implicit': 0, 'coding': 8, 'bandwidth': 41.7, 'spreading': 11, 'lowopt': 0},
{'implicit': 1, 'coding': 5, 'bandwidth': 41.7, 'spreading': 6, 'lowopt': 0}]
# {EXPLICIT_MODE, ERROR_CODING_4_8, BANDWIDTH_20K8, SPREADING_11, 1, 60, "Telemetry"}, // 0: Normal mode for telemetry
# {IMPLICIT_MODE, ERROR_CODING_4_5, BANDWIDTH_20K8, SPREADING_6, 0, 1400, "SSDV"}, // 1: Normal mode for SSDV
# {EXPLICIT_MODE, ERROR_CODING_4_8, BANDWIDTH_62K5, SPREADING_8, 0, 2000, "Repeater"}, // 2: Normal mode for repeater network
# {EXPLICIT_MODE, ERROR_CODING_4_6, BANDWIDTH_250K, SPREADING_7, 0, 8000, "Turbo"}, // 3: Normal mode for high speed images in 868MHz band
# {IMPLICIT_MODE, ERROR_CODING_4_5, BANDWIDTH_250K, SPREADING_6, 0, 16828, "TurboX"}, // 4: Fastest mode within IR2030 in 868MHz band
# {EXPLICIT_MODE, ERROR_CODING_4_8, BANDWIDTH_41K7, SPREADING_11, 0, 200, "Calling"}, // 5: Calling mode
# {IMPLICIT_MODE, ERROR_CODING_4_5, BANDWIDTH_41K7, SPREADING_6, 0, 2800, "Uplink"} // 6: Uplink mode for 868
SettingsList=[
# LCARS settings
{
'section': 'LCARS',
'setting': 'Chase.ID',
'type': 'text',
'prompt': 'Chase Car ID',
'text': 'This is what your vehicle will appear as on the live map',
'save': 1
},
{
'setting': 'Chase.Enabled',
'type': 'check',
'prompt': 'Enable Chase Car',
'text': 'When set, your vehicle position will be uploaded every 30 seconds',
'save': 1
},
{
'setting': 'SSDV.Path',
'type': 'text',
'prompt': 'Path to SSDV Folder',
'text': 'Images in this folder can be browsed on the SSDV page',
'save': 1
},
{
'setting': 'Network.GPSServer',
'type': 'text',
'prompt': 'GPS server',
'text': 'Network location of GPS server. Expects to see a JSON feed as produced by GPSD',
'save': 1
},
{
'setting': 'Network.GatewayServer',
'type': 'text',
'prompt': 'LoRa Gateway',
'text': 'Network location of LoRa gateway. Expects to see a JSON feed as produced by the UKHAS LoRa gateway',
'save': 1
},
# Gateway generic settings
{
'section': 'LoRa',
'setting': 'gateway.tracker',
'type': 'text',
'prompt': 'LoRa Receiver Callsign',
'text': 'Name of tracker used by LoRa gateway. This is what will appear on the map in the list of receivers',
'save': 0
},
{
'setting': 'gateway.EnableHabitat',
'type': 'check',
'prompt': 'LoRa Habitat Upload',
'text': 'Enables upload of telemetry from LoRa trackers to Habitat, so the flight appears on the web map',
'save': 0
},
{
'setting': 'gateway.EnableSSDV',
'type': 'check',
'prompt': 'LoRa SSDV Upload',
'text': 'Enables upload of SSDV from LoRa trackers to the SSDV server, so that images from the flight appear on the SSDV page',
'save': 0
},
{
'setting': 'gateway.LogTelemetry',
'type': 'check',
'prompt': 'LoRa Telemetry Log',
'text': 'Enables logging of the content of telemetry packets to telemetry.txt in the gateway folder.',
'save': 0
},
{
'setting': 'gateway.LogPackets',
'type': 'check',
'prompt': 'LoRa Packet Log',
'text': 'Enables logging of all packets to packets.txt in the gateway folder.',
'save': 0
},
{
'setting': 'gateway.CallingTimeout',
'type': 'integer',
'prompt': 'LoRa Calling Timeout',
'text': 'After this period of inactivity, the gateway will retune to the configured frequency and mode',
'units': 's',
'save': 0
},
{
'setting': 'gateway.JPGFolder',
'type': 'text',
'prompt': 'LoRa JPG Folder',
'text': 'Incoming LoRa SSDV images will be stored in this folder',
'save': 0
},
# Gateway channel 0 settings
{
'section': 'LoRa 0',
'setting': 'gateway.frequency_0',
'type': 'float',
'prompt': 'LoRa Ch0 Frequency',
'text': 'Frequency for LoRa channel 0',
'units': 'MHz',
'save': 0
},
{
'setting': 'gateway.mode_0',
'type': 'list',
'prompt': 'LoRa Ch0 Mode',
'text': 'Preset Mode for LoRa channel 0',
'values': '',
'offset': 0,
'display': ['Slow','SSDV','Repeater','Turbo','TurboX','Calling'],
'function': 'loramode',
'save': 0
},
{
'setting': 'gateway.sf_0',
'type': 'list',
'prompt': 'LoRa Ch0 Spreading',
'text': 'Spreading Factor for LoRa channel 0',
'values': '',
'offset': 6,
'display': ['6', '7', '8', '9', '10', '11', '12'],
'save': 0
},
{
'setting': 'gateway.bandwidth_0',
'type': 'list',
'prompt': 'LoRa Ch0 Bandwidth',
'text': 'Bandwidth in kHz for LoRa channel 0',
'values': '',
'offset': -1,
'display': ['7.8', '10.4', '15.6k', '20.8', '31.25', '41.7', '62.5', '125', '250', '500'],
'save': 0
},
{
'setting': 'gateway.implicit_0',
'type': 'check',
'prompt': 'LoRa Ch0 Implicit',
'text': 'Implicit Mode for LoRa channel 0; uncheck to use Explicit Mode',
'save': 0
},
{
'setting': 'gateway.coding_0',
'type': 'list',
'prompt': 'LoRa Ch0 Coding',
'text': 'Error Coding for LoRa channel 0',
'values': '',
'offset': 5,
'display': ['5', '6', '7', '8'],
'save': 0
},
{
'setting': 'gateway.lowopt_0',
'type': 'check',
'prompt': 'LoRa Ch0 LDRO',
'text': 'Low Data Rate Optimisation for LoRa channel 0',
'save': 0
},
{
'setting': 'gateway.AFC_0',
'type': 'check',
'prompt': 'LoRa Ch0 AFC',
'text': 'Automatic Frequency Control for LoRa channel 0',
'save': 0
},
# Gateway channel 1 settings
{
'section': 'LoRa 0',
'setting': 'gateway.frequency_1',
'type': 'float',
'prompt': 'LoRa Ch1 Frequency',
'text': 'Frequency for LoRa channel 1',
'units': 'MHz',
'save': 0
},
{
'setting': 'gateway.mode_1',
'type': 'list',
'prompt': 'LoRa Ch1 Mode',
'text': 'Preset Mode for LoRa channel 1',
'values': '',
'offset': 0,
'display': ['Slow','SSDV','Repeater','Turbo','TurboX','Calling'],
'save': 0
},
{
'setting': 'gateway.sf_1',
'type': 'list',
'prompt': 'LoRa Ch1 Spreading',
'text': 'Spreading Factor for LoRa channel 1',
'values': '',
'offset': 6,
'display': ['6', '7', '8', '9', '10', '11', '12'],
'save': 0
},
{
'setting': 'gateway.bandwidth_1',
'type': 'list',
'prompt': 'LoRa Ch1 Bandwidth',
'text': 'Bandwidth in kHz for LoRa channel 1',
'values': '',
'offset': -1,
'display': ['7.8', '10.4', '15.6k', '20.8', '31.25', '41.7', '62.5', '125', '250', '500'],
'save': 0
},
{
'setting': 'gateway.implicit_1',
'type': 'check',
'prompt': 'LoRa Ch1 Implicit',
'text': 'Implicit Mode for LoRa channel 0; uncheck to use Explicit Mode',
'save': 0
},
{
'setting': 'gateway.coding_1',
'type': 'list',
'prompt': 'LoRa Ch1 Coding',
'text': 'Error Coding for LoRa channel 1',
'values': '',
'offset': 5,
'display': ['5', '6', '7', '8'],
'save': 0
},
{
'setting': 'gateway.lowopt_1',
'type': 'check',
'prompt': 'LoRa Ch0 LDR1',
'text': 'Low Data Rate Optimisation for LoRa channel 1',
'save': 0
},
{
'setting': 'gateway.AFC_1',
'type': 'check',
'prompt': 'LoRa Ch1 AFC',
'text': 'Automatic Frequency Control for LoRa channel 1',
'save': 0
}
]
OurStatus = {'time': '', 'lat': 51.95023, 'lon': -2.54445, 'alt': 0, 'speed': 0, 'track': 0, 'network': '', 'netcolour': 'Black', 'chasecarstatus' : 0}
ButtonText = ['PAYLOADS', 'HAB', 'CHASE', 'SOURCE', 'NAV', 'SSDV', 'BATC', 'SETTINGS']
ButtonColour = ['#FFFF33', '#98CCFF', '#FFFFCC', '#FFFF33', '#98CCFF', '#FFFFCC', '#FFFF33', '#98CCFF']
TempHABStatus = {'updatechart': 0, 'updated': 0, 'lastupdate': 0, 'payload': '', 'time': '', 'lat': 0, 'lon': 0, 'alt': 0, 'rate': 0}
TempSourceStatus = {'letter': '?', 'lastupdate': 0, 'connected': 0}
# Payloads
MAX_PAYLOADS=32
HABStatii = []
for i in range(0,MAX_PAYLOADS):
HABStatii.append(TempHABStatus.copy())
# Data sources - LoRa 1, LoRa 2, RTTY, Habitat
Sources = []
for i in range(0,4):
Sources.append(TempSourceStatus.copy())
Sources[0]['letter'] = '1'
Sources[1]['letter'] = '2'
Sources[2]['letter'] = 'R'
Sources[3]['letter'] = 'H'
SelectedPayloadIndex = 0
BATCStatus = 0
global SelectedSSDVFile
global SelectedSSDVFileName
global SSDVModificationDate
global CurrentScreen
global CurrentScreenTitle
global Settings
global EditSettings
global HABBalloonMode
global LoRaSocket
global SettingsPage, SettingsRows
def BoolToStr(value):
if value:
return '1'
else:
return '0'
def CalculateDescentRate(Weight, Density, CDTimesArea):
return math.sqrt((Weight * 9.81)/(0.5 * Density * CDTimesArea))
def CalculateAirDensity(alt):
if alt < 11000.0:
# below 11Km - Troposphere
Temperature = 15.04 - (0.00649 * alt)
Pressure = 101.29 * math.pow((Temperature + 273.1) / 288.08, 5.256)
elif alt < 25000.0:
# between 11Km and 25Km - lower Stratosphere
Temperature = -56.46
Pressure = 22.65 * math.exp(1.73 - ( 0.000157 * alt))
else:
# above 25Km - upper Stratosphere
Temperature = -131.21 + (0.00299 * alt)
Pressure = 2.488 * math.pow((Temperature + 273.1) / 216.6, -11.388)
return Pressure / (0.2869 * (Temperature + 273.1))
def CalculateCDA(Weight, Altitude, DescentRate):
Density = CalculateAirDensity(Altitude)
return (Weight * 9.81)/(0.5 * Density * DescentRate * DescentRate)
def CalculateLanding(Altitude, LandingAltitude, DescentRate):
CDTimesArea = CalculateCDA(1.0, Altitude, DescentRate);
TotalTime = 0
Step = 100
while Altitude > LandingAltitude:
Density = CalculateAirDensity(Altitude)
DescentRate = CalculateDescentRate(1.0, Density, CDTimesArea)
TimeAtAltitude = Step / DescentRate
TotalTime = TotalTime + TimeAtAltitude
Altitude = Altitude - Step
return {'landingspeed': DescentRate, 'timetilllanding': TotalTime}
class Main(QtGui.QMainWindow):
def LoadConfig(self):
global Settings, EditSettings
filename = 'lcars.txt'
print ('Loading config file ' + filename)
if os.path.isfile(filename):
# Open config file
config = configparser.RawConfigParser()
config.read(filename)
for index, item in enumerate(SettingsList):
Setting = item['setting']
words = Setting.split('.')
if len(words) == 2:
Section = words[0]
Field = words[1]
if item['save']:
if item['type'] in ['text', 'integer', 'float']:
Settings[Setting] = config.get(Section, Field)
elif item['type'] == 'check':
Settings[Setting] = config.getboolean(Section, Field)
else:
if item['type'] in ['text']:
Settings[Setting] = ''
elif item['type'] in ['check', 'integer', 'float', 'list']:
Settings[Setting] = 0
item['changed'] = 0
if len(sys.argv) >= 2:
# Override servers
Settings['Network.GPSServer'] = sys.argv[1]
Settings['Network.GatewayServer'] = sys.argv[1]
EditSettings = Settings.copy()
def SaveConfig(self):
global Settings
filename = 'lcars.txt'
print ('Saving config file ' + filename)
config = configparser.RawConfigParser()
config.read(filename)
MessageForGateway = ''
for index, item in enumerate(SettingsList):
if item['changed']:
Setting = item['setting']
words = Setting.split('.')
if len(words) == 2:
Section = words[0]
if not config.has_section(Section):
config.add_section(Section)
Field = words[1]
if item['save']:
if item['type'] in ['text', 'integer', 'float', 'list']:
config.set(Section, Field, Settings[Setting])
elif item['type'] == 'check':
config.set(Section, Field, BoolToStr(Settings[Setting]))
else:
SaveRemote = 1
try:
if item['type'] == 'text':
MessageForGateway = MessageForGateway + Field + '=' + Settings[Setting] + '\r\n'
elif item['type'] == 'integer':
MessageForGateway = MessageForGateway + Field + '=' + str(Settings[Setting]) + '\r\n'
elif item['type'] == 'float':
MessageForGateway = MessageForGateway + Field + '=' + str(Settings[Setting]) + '\r\n'
elif item['type'] == 'check':
MessageForGateway = MessageForGateway + Field + '=' + BoolToStr(Settings[Setting]) + '\r\n'
elif item['type'] == 'list':
MessageForGateway = MessageForGateway + Field + '=' + str(Settings[Setting]) + '\r\n'
except:
pass
item['changed'] = 0
with open(filename, 'wt') as configfile:
config.write(configfile)
if MessageForGateway != '':
MessageForGateway = MessageForGateway + 'SAVE\r\n'
LoRaSocket.send(MessageForGateway.encode('utf-8'))
def __init__(self):
global Settings, EditSettings, CurrentScreenTitle, SelectedSSDVFile, SSDVModificationDate, CameraMode, HABBalloonMode
CurrentScreenTitle = ''
SelectedSSDVFile = 0
SelectedSSDVFileName = ''
SSDVModificationDate = 0
CameraMode = 0
HABBalloonMode = 0
CheckCamera()
QtGui.QMainWindow.__init__(self)
# Set defaults
Settings = {'Network.GPSServer': 'localhost', 'Network.GatewayServer': 'localhost',
'Chase.ID': 'default_chase', 'Chase.Enabled': False,
'SSDV.Path': ''}
if Settings['Chase.Enabled']:
OurStatus['chasecarstatus'] = 1
# Load config
self.LoadConfig()
# Set up main window and widgets
self.initStaticUI()
# os.system("./start_dlfldigi")
# os.system("./start_gateway")
self.show()
def closeEvent(self, event):
print ("")
def handleSSDVScreenClick(self, event):
global SelectedSSDVFile
global CurrentScreen
x=event.pos().x()
if x < (self.width() / 2):
# Go further away from the last file
SelectedSSDVFile = SelectedSSDVFile + 1
elif SelectedSSDVFile > 0:
SelectedSSDVFile = SelectedSSDVFile - 1
print("SelectedSSDVFile = " + str(SelectedSSDVFile))
self.ShowSSDVFile(True)
def handlePayloadLabelClick(self, event):
global SelectedPayloadIndex
sender = self.sender()
for index, item in enumerate(self.HABPayloadLabels):
if sender is item:
PayloadIndex = index
print("Payload button " + str(PayloadIndex) + " pressed")
if HABStatii[PayloadIndex]['payload'] != '':
if PayloadIndex != SelectedPayloadIndex:
SelectedPayloadIndex = PayloadIndex;
UpdateSelectedScreen()
# Settings page signals]
def handleSettingItemSelect(self):
global EditSettings, SettingsPage, SettingsRows
# User has changed selection
sender = self.sender()
Row = sender.currentRow() + SettingsRows[SettingsPage]
screen = self.screens[7]
# Disconnect previous handler
# screen.findChild(QLineEdit, 'edtSetting').textChanged.disconnect()
# screen.findChild(QSpinBox, 'spnSetting').valueChanged.disconnect()
# screen.findChild(QDoubleSpinBox, 'spnDoubleSetting').disconnect()
# screen.findChild(QCheckBox, 'chkSetting').stateChanged.disconnect()
try:
screen.findChild(QComboBox, 'cmbSetting').currentIndexChanged.disconnect()
except Exception: pass
# Show explanation
screen.findChild(QLabel, 'lblText').setText(SettingsList[Row]['text'])
# Display and populate correct widget type
screen.findChild(QLineEdit, 'edtSetting').hide()
screen.findChild(QCheckBox, 'chkSetting').hide()
screen.findChild(QSpinBox, 'spnSetting').hide()
screen.findChild(QDoubleSpinBox, 'spnDoubleSetting').hide()
screen.findChild(QComboBox, 'cmbSetting').hide()
if 'units' in SettingsList[Row]:
screen.findChild(QLabel, 'lblUnits').setText(SettingsList[Row]['units'])
else:
screen.findChild(QLabel, 'lblUnits').setText('')
if SettingsList[Row]['type'] == 'text':
screen.findChild(QLineEdit, 'edtSetting').show()
screen.findChild(QLineEdit, 'edtSetting').setText(EditSettings[SettingsList[Row]['setting']])
screen.findChild(QLineEdit, 'edtSetting').textChanged.connect(self.handleSettingTextChanged)
elif SettingsList[Row]['type'] == 'integer':
screen.findChild(QSpinBox, 'spnSetting').show()
screen.findChild(QSpinBox, 'spnSetting').setValue(EditSettings[SettingsList[Row]['setting']])
screen.findChild(QSpinBox, 'spnSetting').valueChanged.connect(self.handleSettingSpinChanged)
elif SettingsList[Row]['type'] == 'float':
screen.findChild(QDoubleSpinBox, 'spnDoubleSetting').show()
screen.findChild(QDoubleSpinBox, 'spnDoubleSetting').setValue(EditSettings[SettingsList[Row]['setting']])
screen.findChild(QDoubleSpinBox, 'spnDoubleSetting').valueChanged.connect(self.handleSettingDoubleSpinChanged)
elif SettingsList[Row]['type'] == 'check':
screen.findChild(QCheckBox, 'chkSetting').show()
screen.findChild(QCheckBox, 'chkSetting').setText(SettingsList[Row]['prompt'])
screen.findChild(QCheckBox, 'chkSetting').setChecked(EditSettings[SettingsList[Row]['setting']])
screen.findChild(QCheckBox, 'chkSetting').stateChanged.connect(self.handleSettingCheckboxChanged)
else:
screen.findChild(QComboBox, 'cmbSetting').show()
# Populate list
screen.findChild(QComboBox, 'cmbSetting').clear()
screen.findChild(QComboBox, 'cmbSetting').addItems(SettingsList[Row]['display'])
if SettingsList[Row]['offset'] >= 0:
# We use the item index as the value
screen.findChild(QComboBox, 'cmbSetting').setCurrentIndex(EditSettings[SettingsList[Row]['setting']] - SettingsList[Row]['offset'])
else:
# We use the item itself as the value
index = screen.findChild(QComboBox, 'cmbSetting').findText(str(EditSettings[SettingsList[Row]['setting']]))
screen.findChild(QComboBox, 'cmbSetting').setCurrentIndex(index)
screen.findChild(QComboBox, 'cmbSetting').currentIndexChanged.connect(self.handleSettingComboChanged)
def handleSettingTextChanged(self):
global EditSettings, SettingsPage, SettingsRows
# User is typing into an text box setting
screen = self.screens[7]
Row = screen.findChild(QListWidget, 'lstSettings').currentRow() + SettingsRows[SettingsPage]
EditSettings[SettingsList[Row]['setting']] = screen.findChild(QLineEdit, 'edtSetting').text()
SettingsList[Row]['changed'] = 1
def handleSettingSpinChanged(self):
global EditSettings, SettingsPage, SettingsRows
# User is changing a spinbox value
screen = self.screens[7]
Row = screen.findChild(QListWidget, 'lstSettings').currentRow() + SettingsRows[SettingsPage]
EditSettings[SettingsList[Row]['setting']] = screen.findChild(QSpinBox, 'spnSetting').value()
SettingsList[Row]['changed'] = 1
def handleSettingDoubleSpinChanged(self):
global EditSettings, SettingsPage, SettingsRows
# User is changing a double spinbox value
screen = self.screens[7]
Row = screen.findChild(QListWidget, 'lstSettings').currentRow() + SettingsRows[SettingsPage]
EditSettings[SettingsList[Row]['setting']] = screen.findChild(QDoubleSpinBox, 'spnDoubleSetting').value()
SettingsList[Row]['changed'] = 1
def handleSettingCheckboxChanged(self):
global EditSettings, SettingsPage, SettingsRows
# User has changed check box value
screen = self.screens[7]
Row = screen.findChild(QListWidget, 'lstSettings').currentRow() + SettingsRows[SettingsPage]
EditSettings[SettingsList[Row]['setting']] = screen.findChild(QCheckBox, 'chkSetting').isChecked()
SettingsList[Row]['changed'] = 1
def DoSpecialFunction(self, Row):
if 'function' in SettingsList[Row]:
if SettingsList[Row]['function'] == 'loramode':
Channel = SettingsList[Row]['setting'][-1:] # channel is '0' or '1' from end of setting name
Mode = EditSettings[SettingsList[Row]['setting']]
EditSettings['gateway.implicit_' + Channel] = Modes[Mode]['implicit']
EditSettings['gateway.coding_' + Channel] = Modes[Mode]['coding']
EditSettings['gateway.bandwidth_' + Channel] = Modes[Mode]['bandwidth']
EditSettings['gateway.sf_' + Channel] = Modes[Mode]['spreading']
EditSettings['gateway.lowopt_' + Channel] = Modes[Mode]['lowopt']
def handleSettingComboChanged(self):
global EditSettings, SettingsPage, SettingsRows
# User has changed combo box value
screen = self.screens[7]
if screen.findChild(QComboBox, 'cmbSetting').currentIndex() >= 0:
Row = screen.findChild(QListWidget, 'lstSettings').currentRow() + SettingsRows[SettingsPage]
if SettingsList[Row]['offset'] >= 0:
# We use the item index as the value
EditSettings[SettingsList[Row]['setting']] = screen.findChild(QComboBox, 'cmbSetting').currentIndex() + SettingsList[Row]['offset']
else:
# We use the item itself as the value
EditSettings[SettingsList[Row]['setting']] = screen.findChild(QComboBox, 'cmbSetting').currentText()
self.DoSpecialFunction(Row)
SettingsList[Row]['changed'] = 1
def handleSaveSettingsClick(self, event):
global Settings, EditSettings
print("Settings SAVE button pressed")
Settings = EditSettings.copy()
if Settings['Chase.Enabled'] and (OurStatus['chasecarstatus'] == 0):
OurStatus['chasecarstatus'] = 1
elif not Settings['Chase.Enabled']:
OurStatus['chasecarstatus'] = 0
self.SaveConfig()
def handleCancelSettingsClick(self, event):
global Settings, EditSettings, CurrentScreen
print("Settings CANCEL button pressed")
self.InitSettingsScreen()
# EditSettings = Settings.copy()
# listView = CurrentScreen.findChild(QListWidget, 'lstSettings')
# listView.setCurrentRow(0)
def handleKeyboardClick(self, event):
os.system("killall matchbox-keyboard")
os.system("matchbox-keyboard -d &")
def handleLCARSSettingsClick(self, event):
self.ShowSettingsPage(0)
def handleLoRaSettingsClick(self, event):
self.ShowSettingsPage(1)
def handleLoRa0SettingsClick(self, event):
self.ShowSettingsPage(2)
def handleLoRa1SettingsClick(self, event):
self.ShowSettingsPage(3)
# Map/Nav page signals
def handleMapClick(self, event):
LoadMap()
def handleNavitViewClick(self, event):
LoadNavit(-1)
def handleNavitRouteClick(self, event):
LoadNavit(SelectedPayloadIndex)
def handleSourcesGatewayClick(self, event):
LoadGateway()
def handleSourcesdlfldigiClick(self, event):
Loaddlfldigi()
def handleBATCNoneClick(self, event):
global CameraMode
CameraMode = 0
CheckCamera()
def handleBATCViewClick(self, event):
global CameraMode
CameraMode = 1
CheckCamera()
def handleBATCBothClick(self, event):
global CameraMode
CameraMode = 3
CheckCamera()
def handleButton(self):
global CameraMode
# hide screens
global SelectedSSDVFile
global CurrentScreen
global CurrentScreenTitle
self.logo.hide()
for screen in self.screens:
screen.hide()
sender = self.sender()
for index, item in enumerate(self.buttons):
if sender is item:
button_index = index
CurrentScreen = self.screens[button_index]
CurrentScreenTitle = ButtonText[button_index]
if button_index == 0:
# PAYLOADS
pass
elif button_index == 1:
# HAB
pass
elif button_index == 2:
# CHASE
pass
# CurrentScreen.findChild(QPushButton, 'btnOpen').clicked.connect(self.handleMapViewClick)
elif button_index == 3:
# SOURCES
CurrentScreen.findChild(QPushButton, 'btnGateway').clicked.connect(self.handleSourcesGatewayClick)
CurrentScreen.findChild(QPushButton, 'btndlfldigi').clicked.connect(self.handleSourcesdlfldigiClick)
elif button_index == 4:
# NAV
CurrentScreen.findChild(QPushButton, 'btnMap').clicked.connect(self.handleMapClick)
CurrentScreen.findChild(QPushButton, 'btnOpen').clicked.connect(self.handleNavitViewClick)
CurrentScreen.findChild(QPushButton, 'btnRoute').clicked.connect(self.handleNavitRouteClick)
elif button_index == 5:
# SSDV
SelectedSSDVFile=0 # 0 means latest file; 1 means one before, etc
self.ShowSSDVFile(True)
CurrentScreen.setAlignment(QtCore.Qt.AlignCenter | QtCore.Qt.AlignVCenter)
CurrentScreen.mousePressEvent = self.handleSSDVScreenClick
elif button_index == 6:
# BATC
CurrentScreen.findChild(QPushButton, 'btnNone').clicked.connect(self.handleBATCNoneClick)
CurrentScreen.findChild(QPushButton, 'btnView').clicked.connect(self.handleBATCViewClick)
CurrentScreen.findChild(QPushButton, 'btnBoth').clicked.connect(self.handleBATCBothClick)
elif button_index == 7:
# SETTINGS
self.InitSettingsScreen()
# CurrentScreen.mousePressEvent = self.handleSettingsScreenClick
CurrentScreen.findChild(QPushButton, 'btnSave').clicked.connect(self.handleSaveSettingsClick)
CurrentScreen.findChild(QPushButton, 'btnCancel').clicked.connect(self.handleCancelSettingsClick)
CurrentScreen.findChild(QPushButton, 'btnKeyboard').clicked.connect(self.handleKeyboardClick)
CurrentScreen.findChild(QPushButton, 'btnLCARS').clicked.connect(self.handleLCARSSettingsClick)
CurrentScreen.findChild(QPushButton, 'btnLoRa').clicked.connect(self.handleLoRaSettingsClick)
CurrentScreen.findChild(QPushButton, 'btnLoRa0').clicked.connect(self.handleLoRa0SettingsClick)
CurrentScreen.findChild(QPushButton, 'btnLoRa1').clicked.connect(self.handleLoRa1SettingsClick)
# Switch off camera viewing
if CameraMode == 1:
CameraMode = 0
CheckCamera()
if CameraMode == 3:
CameraMode = 2
CheckCamera()
CurrentScreen.show()
self.UpdateSelectedScreen()
def UpdateSelectedScreen(self):
if CurrentScreenTitle == "HAB":
self.UpdateHABChart(1)
def initStaticUI(self):
palette = QPalette()
# Position main window top-left
self.move(0,0)
# Background
self.background = QLabel(self)
self.background.move(0,0)
self.background.resize(800,480)
pixmap = QPixmap('background.png')
self.background.setPixmap(pixmap)
# STNG font
font = QFont()
font.setFamily("Swiss911 UCm BT")
font.setPointSize(20)
# Status bar (bottom of screen - GPS mainly)
self.SourcesLabel = QLabel("", self)
self.SourcesLabel.setFont(font)
self.SourcesLabel.setFixedWidth(53)
self.SourcesLabel.setAlignment(QtCore.Qt.AlignCenter| QtCore.Qt.AlignVCenter)
self.SourcesLabel.move(128,452)
self.BCLabel = QLabel("", self)
self.BCLabel.setFont(font)
self.BCLabel.setFixedWidth(23)
self.BCLabel.setAlignment(QtCore.Qt.AlignCenter| QtCore.Qt.AlignVCenter)
self.BCLabel.move(202,452)
self.TimeLabel = QLabel("", self)
self.TimeLabel.setFont(font)
self.TimeLabel.setFixedWidth(66)
self.TimeLabel.setAlignment(QtCore.Qt.AlignCenter| QtCore.Qt.AlignVCenter)
self.TimeLabel.move(284,452)
self.LatitudeLabel = QLabel("", self)
self.LatitudeLabel.setFont(font)
self.LatitudeLabel.setFixedWidth(82)
self.LatitudeLabel.setAlignment(QtCore.Qt.AlignCenter| QtCore.Qt.AlignVCenter)
self.LatitudeLabel.move(372,452)
self.LongitudeLabel = QLabel("", self)
self.LongitudeLabel.setFont(font)
self.LongitudeLabel.setFixedWidth(72)
self.LongitudeLabel.setAlignment(QtCore.Qt.AlignCenter| QtCore.Qt.AlignVCenter)
self.LongitudeLabel.move(471,452)
self.AltitudeLabel = QLabel("", self)
self.AltitudeLabel.setFont(font)
self.AltitudeLabel.setFixedWidth(58)
self.AltitudeLabel.setAlignment(QtCore.Qt.AlignCenter | QtCore.Qt.AlignVCenter)
self.AltitudeLabel.move(560,452)
self.InternetLabel = QLabel("", self)
self.InternetLabel.setFont(font)
self.InternetLabel.setFixedWidth(65)
self.InternetLabel.setAlignment(QtCore.Qt.AlignCenter| QtCore.Qt.AlignVCenter)
self.InternetLabel.move(690,452)
# Payload bar
self.HABPayloadLabels = []
for i in range(1,4):
HABPayloadLabel = QPushButton("", self) # Payload " + str(i), self)
HABPayloadLabel.setStyleSheet("background: #F3DF6F")
HABPayloadLabel.setFont(font)
HABPayloadLabel.resize(84,25)
HABPayloadLabel.move(113 + (i-1) * 86, 2)
HABPayloadLabel.clicked.connect(self.handlePayloadLabelClick)
self.HABPayloadLabels.append(HABPayloadLabel)
self.HABTimeLabel = QLabel("", self)
self.HABTimeLabel.setFont(font)
self.HABTimeLabel.setFixedWidth(66)
self.HABTimeLabel.setAlignment(QtCore.Qt.AlignCenter| QtCore.Qt.AlignVCenter)
self.HABTimeLabel.move(405,0)
self.HABLatitudeLabel = QLabel("", self)
self.HABLatitudeLabel.setFont(font)
self.HABLatitudeLabel.setFixedWidth(82)
self.HABLatitudeLabel.setAlignment(QtCore.Qt.AlignCenter| QtCore.Qt.AlignVCenter)
self.HABLatitudeLabel.move(490,0)
self.HABLongitudeLabel = QLabel("", self)
self.HABLongitudeLabel.setFont(font)
self.HABLongitudeLabel.setFixedWidth(72)
self.HABLongitudeLabel.setAlignment(QtCore.Qt.AlignCenter| QtCore.Qt.AlignVCenter)
self.HABLongitudeLabel.move(590,0)
self.HABAltitudeLabel = QLabel("", self)
self.HABAltitudeLabel.setFont(font)
self.HABAltitudeLabel.setFixedWidth(66)
self.HABAltitudeLabel.setAlignment(QtCore.Qt.AlignCenter | QtCore.Qt.AlignVCenter)
self.HABAltitudeLabel.move(679,0)
# self.HABRateLabel = QLabel("", self)
# self.HABRateLabel.setFont(font)
# self.HABRateLabel.setFixedWidth(65)
# self.HABRateLabel.setAlignment(QtCore.Qt.AlignCenter | QtCore.Qt.AlignVCenter)
# self.HABRateLabel.move(712,0)
# Buttons
self.buttons = []
MenuTop = 36
MenuHeight = 446-MenuTop
ButtonGap = 3
ButtonTop = MenuTop + ButtonGap
ButtonHeight = (MenuHeight-ButtonGap) / len(ButtonText) - ButtonGap
for index, item in enumerate(ButtonText):
button = QtGui.QPushButton(item, self)
font.setPointSize(24)
button.setFont(font)
button.setStyleSheet("text-align: center; background-color: " + ButtonColour[index])
button.move(2,ButtonTop + index*(ButtonHeight + ButtonGap))
button.resize(96,ButtonHeight)
button.clicked.connect(self.handleButton)
self.buttons.append(button)
# logo
self.logo = QLabel(self)
self.logo.move(324,66)
self.logo.resize(251,337)
pixmap = QPixmap('logo.png')
self.logo.setPixmap(pixmap)
self.screens = []
for index, item in enumerate(ButtonText):
screen = QLabel(self)
screen.move(101,30)
screen.resize(700,420)
screen.hide()
self.screens.append(screen)
uic.loadUi('PAYLOADS.ui', self.screens[0])
uic.loadUi('HAB.ui', self.screens[1])
uic.loadUi('CHASE.ui', self.screens[2])
uic.loadUi('SOURCE.ui', self.screens[3])
uic.loadUi('NAVIT.ui', self.screens[4])
# uic.loadUi('SSDV.ui', self.screens[5])
uic.loadUi('BATC.ui', self.screens[6])
uic.loadUi('SETTINGS.ui', self.screens[7])
# SSDV image
# self.ssdvscreen = QLabel(self)
# self.ssdvscreen.hide()
timer = QtCore.QTimer(self)
timer.timeout.connect(self.Time)
timer.start(1000)
self.setWindowFlags(QtCore.Qt.CustomizeWindowHint) # Remove caption bar
self.setWindowFlags(QtCore.Qt.FramelessWindowHint) # Remove border
#palette.setBrush(QPalette.Background,QBrush(QPixmap("Background.png")))
#self.setPalette(palette)
self.resize(800, 480)
# def initDynamicUI(self):
def ShowSSDVFile(self, Always):
global SelectedSSDVFileName
global CurrentScreen
global SSDVModificationDate
# 0 means latest file; 1 onwards means 1st file (by date), 2nd etc
FileName = GetSSDVFileName()
if FileName != '':
ModificationDate = time.ctime(os.path.getmtime(FileName))
if Always or (FileName != SelectedSSDVFileName) or (ModificationDate != SSDVModificationDate):
print("Update SSDV Image")
pixmap = QPixmap(FileName)
CurrentScreen.setPixmap(pixmap.scaled(CurrentScreen.size(), QtCore.Qt.KeepAspectRatio))
SelectedSSDVFileName = FileName
SSDVModificationDate = ModificationDate
def ShowSettingsPage(self, Page):
global SettingsPage, SettingsRows
SettingsPage = Page
screen = self.screens[7]
# Populate settings list
listView = screen.findChild(QListWidget, 'lstSettings')
listView.clear()
for index in range(SettingsRows[Page], SettingsRows[Page+1]):
listView.addItem(SettingsList[index]['prompt'])
listView.itemSelectionChanged.connect(self.handleSettingItemSelect)
listView.setCurrentRow(0)
def InitSettingsScreen(self):
global Settings, EditSettings, LoRaSocket, SettingsPage, SettingsRows
try:
LoRaSocket.send('SETTINGS\r\n'.encode('utf-8'))
except:
pass
EditSettings = Settings.copy()
# Look for sections
SettingsRows = []
for index, item in enumerate(SettingsList):
if 'section' in item:
SettingsRows.append(index)
SettingsRows.append(len(SettingsList))
# Show section
self.ShowSettingsPage(0)