-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathtsi_component.py
1804 lines (1518 loc) · 88.8 KB
/
tsi_component.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
import time
import random
import yaml
import zmq
import threading
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '/Flow Graph Library/TSI Flow Graphs')
# from gnuradio import blocks
# from gnuradio import gr
# from gnuradio import uhd
# from gnuradio import zeromq
# from gnuradio import audio
import inspect,types
import csv
from fissureclass import fissure_listener
from fissureclass import fissure_server
import subprocess
import struct
import numpy as np
from scipy.fftpack import fft,fftfreq,next_fast_len
import scipy.stats as stats
# Insert Any Argument While Executing to Run Locally
try:
run_local = sys.argv[1]
except:
run_local = None
class TSI_Component:
""" Class that contains the functions for the TSI component.
"""
####################### FISSURE Functions ########################
def __init__(self):
""" The start of the TSI component.
"""
self.dashboard_connected = False
self.hiprfisr_connected = False
self.heartbeat_interval = 5
self.tsi_heartbeat_time = 0
self.running_TSI = False
self.running_TSI_simulator = False
self.blacklist = []
self.running_TSI_wideband = False
self.configuration_update = False
self.detector_script_name = ""
# Create the TSI ZMQ Sockets
self.connect()
# Main Event Loop
try:
while True:
#print("TSI LOOPING")
# TSI Activated
if self.running_TSI == True:
# Add Messages Randomly (For Testing)
if (self.dashboard_connected | self.hiprfisr_connected) == True:
pass
#self.addRandomTSI_Message(random.random())
#self.addRandomAMC_Message(random.random())
# Read Messages in the ZMQ Queues
if self.hiprfisr_connected == True:
self.readHIPRFISR_Messages()
self.readSUB_Messages()
# Send the TSI Heartbeat if Interval Time has Elapsed
self.sendHeartbeat()
# Check for Received Heartbeats
#self.checkHeartbeats() # TSI Error Handling
time.sleep(1)
except KeyboardInterrupt:
pass
def connect(self):
""" Connects all the 0MQ Servers and Listeners
"""
# Load Settings from YAML File
self.loadConfiguration()
# Create Connections
hiprfisr_ip_address = "127.0.0.1"
# TSI Dealer
tsi_dealer_port = int(self.settings_dictionary['tsi_hiprfisr_dealer_port'])
self.tsi_hiprfisr_listener = fissure_listener(os.path.dirname(os.path.realpath(__file__)) + '/YAML/tsi.yaml','localhost',tsi_dealer_port,zmq.DEALER, logcfg = os.path.dirname(os.path.realpath(__file__)) + "/YAML/logging.yaml", logsource = "tsi")
# TSI PUB
tsi_pub_port = int(self.settings_dictionary['tsi_pub_port'])
self.tsi_pub_server = fissure_server(os.path.dirname(os.path.realpath(__file__)) + '/YAML/tsi.yaml','*',tsi_pub_port,zmq.PUB, logcfg = os.path.dirname(os.path.realpath(__file__)) + "/YAML/logging.yaml", logsource = "tsi")
# TSI SUB
dashboard_pub_port = int(self.settings_dictionary['dashboard_pub_port'])
hiprfisr_pub_port = int(self.settings_dictionary['hiprfisr_pub_port'])
# TSI SUB to HIPRFISR PUB
try:
self.tsi_sub_listener = fissure_listener(os.path.dirname(os.path.realpath(__file__)) + '/YAML/tsi.yaml',hiprfisr_ip_address,hiprfisr_pub_port,zmq.SUB, logcfg = os.path.dirname(os.path.realpath(__file__)) + "/YAML/logging.yaml", logsource = "tsi")
sub_connected = True
except:
print("Error creating TSI SUB and connecting to HIPRFISR PUB")
# TSI SUB to Dashboard PUB
try:
self.tsi_sub_listener.initialize_port(hiprfisr_ip_address,dashboard_pub_port)
except:
print("Unable to connect TSI SUB to Dashboard PUB")
def readSUB_Messages(self):
""" Read all the messages in the self.tsi_sub_listener and handle accordingly
"""
# Check for Messages
parsed = ''
while parsed != None:
parsed = self.tsi_sub_listener.recvmsg()
if parsed != None:
# Check for Heartbeats
if parsed['Identifier'] == 'Dashboard':
self.dashboard_connected = True
elif parsed['Identifier'] == 'HIPRFISR':
self.hiprfisr_connected = True
if parsed['Type'] == 'Status':
if parsed['MessageName'] == 'Full Library':
pass
#self.pd_library = yaml.load(parsed['Parameters'], yaml.FullLoader) # Not used for anything yet
# Handle Messages/Execute Callbacks as Usual
else:
if parsed['Type'] == 'Heartbeats':
# Update Heartbeat Related Variables
pass
def readHIPRFISR_Messages(self):
""" Sort through any HIPRFISR messages
"""
# Check for Messages
parsed = ''
while parsed != None:
parsed = self.tsi_hiprfisr_listener.recvmsg()
if parsed != None:
# Handle Messages/Execute Callbacks
self.tsi_hiprfisr_listener.runcallback(self,parsed) # Calls the function associated with the callback
def sendHeartbeat(self):
""" Sends the heartbeat to all subscribers
"""
current_time = time.time()
if self.tsi_heartbeat_time < current_time - self.heartbeat_interval:
self.tsi_heartbeat_time = current_time
self.tsi_pub_server.sendmsg('Heartbeats', Identifier = 'TSI', MessageName='Heartbeat', Time=current_time)
def loadConfiguration(self):
""" Loads a configuration YAML file with all the FISSURE user settings.
"""
# Load Settings from YAML File
filename = os.path.dirname(os.path.realpath(__file__)) + "/YAML/fissure_config.yaml"
yaml_config_file = open(filename)
self.settings_dictionary = yaml.load(yaml_config_file, yaml.FullLoader)
yaml_config_file.close()
####################### Generic Functions ########################
def updateFISSURE_Configuration(self):
""" Reload fissure_config.yaml after changes.
"""
# Update FGE Dictionary
self.settings_dictionary = self.loadConfiguration()
def isFloat(self, x):
""" Returns "True" if the input is a Float. Returns "False" otherwise.
"""
try:
float(x)
except ValueError:
return False
return True
def overwriteFlowGraphVariables(self, flow_graph_filename, variable_names, variable_values):
# Check for string_variables
for n in range(0,len(variable_names)):
if variable_names[n] == "string_variables":
fix_strings = True
fix_strings_index = n
break
else:
fix_strings = False
fix_strings_index = None
# Load New Flow Graph
flow_graph_filename = flow_graph_filename.rsplit("/",1)[-1]
flow_graph_filename = flow_graph_filename.replace(".py","")
loadedmod = __import__(flow_graph_filename) # Don't need to reload() because the original never changes
# Update the Text in the Code
stistr = inspect.getsource(loadedmod)
variable_line_position = 0
new_stistr = ""
for line in iter(stistr.splitlines()):
if len(variable_names) > 0:
# Change Variable Values
if variable_line_position == 2:
# Reached the End of the Variables Section
if line.strip() == "":
variable_line_position = 3
# Change Value
else:
variable_name = line.split("=",2)[1] # Only the first two '=' in case value has '='
# Ignore Notes
if variable_name.replace(' ','') != "notes":
old_value = line.split("=",2)[-1]
index = variable_names.index(variable_name.replace(" ",""))
new_value = variable_values[index]
# A Number
if self.isFloat(new_value):
# Make Numerical Value a String
if fix_strings == True:
if variable_name.strip() in variable_values[fix_strings_index]:
new_value = '"' + new_value + '"'
# A String
else:
new_value = '"' + new_value + '"'
new_line = line.split("=",2)[0] + " = " + line.split("=",2)[1] + ' = ' + new_value + "\n"
new_stistr += new_line
# Write Unreplaced Contents
if variable_line_position != 2:
new_stistr += line + "\n"
# Skip "#################################" Line after "# Variables"
if variable_line_position == 1:
variable_line_position = 2
# Find Line Containing "# Variables"
if "# Variables" in line:
variable_line_position = 1
# Find Class Name
if "class " in line and "(gr." in line:
class_name = line.split(" ")[1]
class_name = class_name.split("(")[0]
# Compile
sticode=compile(new_stistr,'<string>','exec')
loadedmod = types.ModuleType('stiimp')
exec(sticode, loadedmod.__dict__)
return loadedmod, class_name
def setVariable(self, flow_graph, variable, value):
""" Sets a variable of a specified running flow graph.
"""
# Make it Match GNU Radio Format
formatted_name = "set_" + variable
isNumber = self.isFloat(value)
if isNumber:
if flow_graph == "Wideband":
getattr(self.wideband_flowtoexec,formatted_name)(float(value))
else:
if flow_graph == "Wideband":
getattr(self.wideband_flowtoexec,formatted_name)(value)
####################### TSI Detector Flow Graphs ##########################
def startTSI_Detector(self, detector, variable_names, variable_values):
""" Begins TSI processing of signals after receiving the command from the HIPRFISR
"""
self.running_TSI = True
print("TSI: Starting TSI Detector...")
# Make a New Wideband Thread
if len(detector) > 0:
if detector == "wideband_x3x0.py":
flow_graph_filename = "wideband_x3x0.py"
elif detector == "wideband_b2x0.py":
flow_graph_filename = "wideband_b2x0.py"
elif detector == "wideband_hackrf.py":
flow_graph_filename = "wideband_hackrf.py"
elif detector == "wideband_b20xmini.py":
flow_graph_filename = "wideband_b20xmini.py"
elif detector == "wideband_rtl2832u.py":
flow_graph_filename = "wideband_rtl2832u.py"
elif detector == "wideband_limesdr.py":
flow_graph_filename = "wideband_limesdr.py"
elif detector == "wideband_bladerf.py":
flow_graph_filename = "wideband_bladerf.py"
elif detector == "wideband_plutosdr.py":
flow_graph_filename = "wideband_plutosdr.py"
elif detector == "wideband_usrp2.py":
flow_graph_filename = "wideband_usrp2.py"
elif detector == "wideband_usrp_n2xx.py":
flow_graph_filename = "wideband_usrp_n2xx.py"
elif detector == "wideband_bladerf2.py":
flow_graph_filename = "wideband_bladerf2.py"
elif detector == "wideband_usrp_x410.py":
flow_graph_filename = "wideband_usrp_x410.py"
elif detector == "IQ File":
flow_graph_filename = "iq_file.py"
elif "fixed_threshold" in detector:
if detector == "fixed_threshold_x3x0.py":
flow_graph_filename = "fixed_threshold_x3x0.py"
elif detector == "fixed_threshold_b2x0.py":
flow_graph_filename = "fixed_threshold_b2x0.py"
elif detector == "fixed_threshold_hackrf.py":
flow_graph_filename = "fixed_threshold_hackrf.py"
elif detector == "fixed_threshold_b20xmini.py":
flow_graph_filename = "fixed_threshold_b20xmini.py"
elif detector == "fixed_threshold_rtl2832u.py":
flow_graph_filename = "fixed_threshold_rtl2832u.py"
elif detector == "fixed_threshold_limesdr.py":
flow_graph_filename = "fixed_threshold_limesdr.py"
elif detector == "fixed_threshold_bladerf.py":
flow_graph_filename = "fixed_threshold_bladerf.py"
elif detector == "fixed_threshold_plutosdr.py":
flow_graph_filename = "fixed_threshold_plutosdr.py"
elif detector == "fixed_threshold_usrp2.py":
flow_graph_filename = "fixed_threshold_usrp2.py"
elif detector == "fixed_threshold_usrp_n2xx.py":
flow_graph_filename = "fixed_threshold_usrp_n2xx.py"
elif detector == "fixed_threshold_bladerf2.py":
flow_graph_filename = "fixed_threshold_bladerf2.py"
elif detector == "fixed_threshold_usrp_x410.py":
flow_graph_filename = "fixed_threshold_usrp_x410.py"
elif detector == "fixed_threshold_simulator.py":
flow_graph_filename = "fixed_threshold_simulator.py"
stop_event = threading.Event()
c_thread = threading.Thread(target=self.detectorFlowGraphGUI_Thread, args=(stop_event,flow_graph_filename,variable_names,variable_values))
c_thread.daemon = True
c_thread.start()
return
# Simulator Detector Thread
if detector == "Simulator":
stop_event = threading.Event()
c_thread = threading.Thread(target=self.runDetectorSimulatorThread, args=(variable_names,variable_values))
c_thread.start()
# Flow Graph Detector Thread
else:
class_name = flow_graph_filename.replace(".py","")
stop_event = threading.Event()
c_thread = threading.Thread(target=self.runWidebandThread, args=(stop_event,class_name,variable_names,variable_values))
c_thread.start()
def startWidebandThread(self):
""" Begins TSI wideband sweeping
"""
self.running_TSI_wideband = True
variable_names = []
variable_values = []
class_name = []
# Make a New Wideband Update Thread
stop_event2 = threading.Event()
c_thread2 = threading.Thread(target=self.widebandUpdateThread, args=(stop_event2,class_name,variable_names,variable_values))
c_thread2.start()
def stopWidebandThread(self):
""" Stops TSI wideband sweeping
"""
# Make a New Wideband Update Thread
self.running_TSI_wideband = False
def runWidebandThread(self, stop_event, flow_graph_filename, variable_names, variable_values):
""" Runs the flow graph in the new thread.
"""
# Stop Any Running Wideband Flow Graphs
try:
self.wideband_flowtoexec.stop()
self.wideband_flowtoexec.wait()
del self.wideband_flowtoexec # Free up the ports
except:
pass
# Overwrite Variables
loadedmod, class_name = self.overwriteFlowGraphVariables(flow_graph_filename, variable_names, variable_values)
# Call the "__init__" Function
self.wideband_flowtoexec = getattr(loadedmod,class_name)()
# Start it
self.wideband_flowtoexec.start()
self.wideband_flowtoexec.wait()
# # Error Loading Flow Graph
# except Exception as e:
# print("Error: " + str(e))
# self.running_TSI = False
# self.running_wideband = False
# self.tsi_pub_server.sendmsg('Status', Identifier = 'TSI', MessageName = 'Detector Flow Graph Error', Parameters = e)
def runDetectorSimulatorThread(self, variable_names, variable_values):
""" Runs the simulator in the new thread.
"""
print("SIMULATOR THREAD STARTED")
self.running_TSI_simulator = True
while self.running_TSI_simulator == True:
# Open CSV Simulator File
with open(variable_values[0], "r") as f:
reader = csv.reader(f, delimiter=",")
for i, line in enumerate(reader):
# Skip First Row
if int(i) > 0:
self.tsi_pub_server.sendmsg('Wideband', Identifier = 'TSI', MessageName = 'Signal Found', Frequency = int(line[0]), Power = int(line[1]), Timestamp = time.time())
time.sleep(float(line[2]))
def widebandUpdateThread(self, stop_event, class_name, variable_names, variable_values):
""" Updates the wideband flow graph parameters in the new thread.
"""
print("WIDEBAND UPDATE THREAD STARTED!!!")
#print(self.running_TSI_wideband)
#print(self.wideband_band)
#print(self.wideband_start_freq[self.wideband_band])
# Wideband Sweep Logic
new_freq = self.wideband_start_freq[self.wideband_band]
while self.running_TSI_wideband == True:
try:
# Check for Configuration Update
if self.configuration_updated == True:
new_freq = self.wideband_start_freq[0]
self.configuration_updated = False
# Update Flow Graph
self.setVariable("Wideband","rx_freq",new_freq)
# Send Frequency and Band Status to Dashboard
self.tsi_pub_server.sendmsg('Status', Identifier = 'TSI', MessageName = 'BandID', Parameters = [self.wideband_band+1,new_freq])
# Step Frequency
new_freq = new_freq + self.wideband_step_size[self.wideband_band]
# Passed Stop Frequency
if new_freq > self.wideband_stop_freq[self.wideband_band]:
# Increase Band
self.wideband_band = self.wideband_band + 1
# Reset Band
if self.wideband_band >= len(self.wideband_start_freq):
self.wideband_band = 0
# Begin at Start Frequency
new_freq = self.wideband_start_freq[self.wideband_band]
# Check Blacklist
not_in_blacklist = False
while not_in_blacklist == False:
not_in_blacklist = True
for n in range(0,len(self.blacklist)):
if self.blacklist[n][0] <= new_freq <= self.blacklist[n][1]:
not_in_blacklist = False
# Step Frequency
new_freq = new_freq + self.wideband_step_size[self.wideband_band]
# Passed Stop Frequency
if new_freq > self.wideband_stop_freq[self.wideband_band]:
# Increase Band
self.wideband_band = self.wideband_band + 1
# Reset Band
if self.wideband_band >= len(self.wideband_start_freq):
self.wideband_band = 0
# Begin at Start Frequency
new_freq = self.wideband_start_freq[self.wideband_band]
except:
pass
# Dwell on Frequency
time.sleep(self.wideband_dwell[self.wideband_band])
def stopTSI_Detector(self):
""" Pauses TSI processing of signals after receiving the command from the HIPRFISR
"""
print("TSI: Stopping TSI Detector...")
self.running_TSI = False
self.running_TSI_wideband = False
if self.running_TSI_simulator == True:
self.running_TSI_simulator = False
elif len(self.detector_script_name) > 0:
self.detectorFlowGraphStop('Flow Graph - GUI')
else:
try:
# Stop Flow Graphs
self.wideband_flowtoexec.stop()
self.wideband_flowtoexec.wait()
del self.wideband_flowtoexec # Free up the ports
except:
pass
########################################################################
def detectorFlowGraphStop(self, parameter):
""" Stop the currently running detector flow graph.
"""
# Only Supports Flow Graphs with GUIs
if (parameter == "Flow Graph - GUI") and (len(self.detector_script_name) > 0):
os.system("pkill -f " + '"' + self.detector_script_name +'"')
self.detector_script_name = ""
def detectorFlowGraphGUI_Thread(self, stop_event, flow_graph_filename, variable_names, variable_values):
""" Runs the detector flow graph in the new thread.
"""
try:
# Start it
filepath = os.path.dirname(os.path.realpath(__file__)) + '/Flow Graph Library/TSI Flow Graphs/' + flow_graph_filename
arguments = ""
for n in range(0,len(variable_names)):
arguments = arguments + '--' + variable_names[n] + '="' + variable_values[n] + '" '
osCommandString = "python3 " + '"' + filepath + '" ' + arguments
proc = subprocess.Popen(osCommandString + " &", shell=True)
#self.flowGraphStarted("Inspection") # Signals to other components
self.detector_script_name = flow_graph_filename
# Error Loading Flow Graph
except Exception as e:
print(str(e))
print("ERROR")
#self.flowGraphStarted("Inspection")
#self.flowGraphFinished("Inspection")
# ~ self.fge_pub_server.sendmsg('Status', Identifier = 'FGE', MessageName = 'Flow Graph Error', Parameters = e) # Custom error message if necessary
#~ #raise e
########################################################################
def startTSI_Conditioner(self, common_parameter_names, common_parameter_values, method_parameter_names, method_parameter_values):
""" Accepts a Start message from the HIPRFISR and begins the new thread.
"""
# Create a New Thread
self.conditioner_stop_event = threading.Event()
c_thread = threading.Thread(target=self.startTSI_ConditionerThread, args=(self.conditioner_stop_event, common_parameter_names, common_parameter_values, method_parameter_names, method_parameter_values))
c_thread.start()
def startTSI_ConditionerThread(self, stop_event, common_parameter_names, common_parameter_values, method_parameter_names, method_parameter_values):
""" Performs the signal conditioning actions.
"""
# Common Parameters
for n in range(len(common_parameter_names)):
if common_parameter_names[n] == 'category':
get_category = common_parameter_values[n]
elif common_parameter_names[n] == 'method':
get_method = common_parameter_values[n]
elif common_parameter_names[n] == 'output_directory':
get_output_directory = common_parameter_values[n]
elif common_parameter_names[n] == 'prefix':
get_prefix = common_parameter_values[n]
elif common_parameter_names[n] == 'sample_rate':
get_sample_rate = common_parameter_values[n]
elif common_parameter_names[n] == 'tuned_frequency':
get_tuned_freq = common_parameter_values[n]
elif common_parameter_names[n] == 'data_type':
get_type = common_parameter_values[n]
elif common_parameter_names[n] == 'max_files':
get_max_files = common_parameter_values[n]
elif common_parameter_names[n] == 'min_samples':
get_min_samples = common_parameter_values[n]
elif common_parameter_names[n] == 'all_filepaths':
get_all_filepaths = common_parameter_values[n]
elif common_parameter_names[n] == 'detect_saturation':
get_detect_saturation = common_parameter_values[n]
elif common_parameter_names[n] == 'saturation_min':
get_saturation_min = common_parameter_values[n]
elif common_parameter_names[n] == 'saturation_max':
get_saturation_max = common_parameter_values[n]
elif common_parameter_names[n] == 'normalize_output':
get_normalize_output = common_parameter_values[n]
elif common_parameter_names[n] == 'normalize_min':
try:
get_normalize_min = float(common_parameter_values[n])
except:
get_normalize_min = ''
elif common_parameter_names[n] == 'normalize_max':
try:
get_normalize_max = float(common_parameter_values[n])
except:
get_normalize_max = ''
# Flow Graph Directory
if get_type == "Complex Float 32":
fg_directory = os.path.dirname(os.path.realpath(__file__)) + "/Flow\ Graph\ Library/TSI\ Flow\ Graphs/Conditioner/Flow_Graphs/ComplexFloat32"
elif get_type == "Complex Int 16":
fg_directory = os.path.dirname(os.path.realpath(__file__)) + "/Flow\ Graph\ Library/TSI\ Flow\ Graphs/Conditioner/Flow_Graphs/ComplexInt16"
# Method1: burst_tagger
if (get_category == "Energy - Burst Tagger") and (get_method == "Normal"):
count = 0
new_files = []
original_filenames = []
# Create a List of Files in Output Directory
if get_output_directory != "":
file_names = []
for fname in os.listdir(get_output_directory):
if os.path.isfile(get_output_directory+"/"+fname):
file_names.append(fname)
for n in range(0,len(get_all_filepaths)):
# Stop Conditioner Triggered
if self.conditioner_stop_event.is_set():
print("TSI Conditioner Stopped")
return
# Update Progress Bar
progress_value = 1+int((float((n+1)/len(get_all_filepaths))*90))
self.tsi_pub_server.sendmsg('Status', Identifier = 'TSI', MessageName = 'Conditioner Progress Bar', Parameters = [progress_value,n])
# Method Parameters
for m in range(len(method_parameter_names)):
if method_parameter_names[m] == 'threshold':
get_threshold = method_parameter_values[m]
# Run the Flow Graph
cmd = "python3 " + fg_directory + "/burst_tagger/normal.py --filepath '" + get_all_filepaths[n] \
+ "' --sample-rate " + get_sample_rate + " --threshold " + get_threshold
p1 = subprocess.Popen(cmd, shell=True, cwd=get_output_directory)
(output, err) = p1.communicate()
p1.wait()
# Rename the New Files
if get_output_directory != "":
for fname in os.listdir(get_output_directory):
if os.path.isfile(get_output_directory + "/" + fname):
if fname not in file_names:
count = count + 1
os.rename(get_output_directory + "/" + fname, get_output_directory + "/" + get_prefix + str(count).zfill(5) + ".iq")
new_files.append(get_prefix + str(count).zfill(5) + ".iq")
file_names.append(get_prefix + str(count).zfill(5) + ".iq")
original_filenames.append(get_all_filepaths[n])
# Update Progress Bar
progress_value = 95
self.tsi_pub_server.sendmsg('Status', Identifier = 'TSI', MessageName = 'Conditioner Progress Bar', Parameters = [progress_value,n])
# Method2: burst_tagger with Decay
elif (get_category == "Energy - Burst Tagger") and (get_method == "Normal Decay"):
count = 0
new_files = []
original_filenames = []
# Create a List of Files in Output Directory
if get_output_directory != "":
file_names = []
for fname in os.listdir(get_output_directory):
if os.path.isfile(get_output_directory+"/"+fname):
file_names.append(fname)
for n in range(0,len(get_all_filepaths)):
# Stop Conditioner Triggered
if self.conditioner_stop_event.is_set():
print("TSI Conditioner Stopped")
return
# Update Progress Bar
progress_value = 1+int((float((n+1)/len(get_all_filepaths))*90))
self.tsi_pub_server.sendmsg('Status', Identifier = 'TSI', MessageName = 'Conditioner Progress Bar', Parameters = [progress_value,n])
# Method Parameters
for m in range(len(method_parameter_names)):
if method_parameter_names[m] == 'threshold':
get_threshold = method_parameter_values[m]
elif method_parameter_names[m] == 'decay':
get_decay = method_parameter_values[m]
# Run the Flow Graph
cmd = "python3 " + fg_directory + "/burst_tagger/normal_decay.py --filepath '" + get_all_filepaths[n] \
+ "' --sample-rate " + get_sample_rate + " --threshold " + get_threshold + " --decay " + get_decay
p1 = subprocess.Popen(cmd, shell=True, cwd=get_output_directory)
(output, err) = p1.communicate()
p1.wait()
# Rename the New Files
if get_output_directory != "":
for fname in os.listdir(get_output_directory):
if os.path.isfile(get_output_directory + "/" + fname):
if fname not in file_names:
count = count + 1
os.rename(get_output_directory + "/" + fname, get_output_directory + "/" + get_prefix + str(count).zfill(5) + ".iq")
new_files.append(get_prefix + str(count).zfill(5) + ".iq")
file_names.append(get_prefix + str(count).zfill(5) + ".iq")
original_filenames.append(get_all_filepaths[n])
# Update Progress Bar
progress_value = 95
self.tsi_pub_server.sendmsg('Status', Identifier = 'TSI', MessageName = 'Conditioner Progress Bar', Parameters = [progress_value,n])
# Method3: power_squelch_with_burst_tagger
elif (get_category == "Energy - Burst Tagger") and (get_method == "Power Squelch"):
count = 0
new_files = []
original_filenames = []
# Create a List of Files in Output Directory
if get_output_directory != "":
file_names = []
for fname in os.listdir(get_output_directory):
if os.path.isfile(get_output_directory+"/"+fname):
file_names.append(fname)
for n in range(0,len(get_all_filepaths)):
# Stop Conditioner Triggered
if self.conditioner_stop_event.is_set():
print("TSI Conditioner Stopped")
return
# Update Progress Bar
progress_value = 1+int((float((n+1)/len(get_all_filepaths))*90))
self.tsi_pub_server.sendmsg('Status', Identifier = 'TSI', MessageName = 'Conditioner Progress Bar', Parameters = [progress_value,n])
# Method Parameters
for m in range(len(method_parameter_names)):
if method_parameter_names[m] == 'squelch':
get_squelch = method_parameter_values[m]
elif method_parameter_names[m] == 'threshold':
get_threshold = method_parameter_values[m]
# Run the Flow Graph
cmd = "python3 " + fg_directory + "/burst_tagger/power_squelch.py --filepath '" + get_all_filepaths[n] \
+ "' --sample-rate " + get_sample_rate + " --threshold " + get_threshold + " --squelch " + get_squelch
p1 = subprocess.Popen(cmd, shell=True, cwd=get_output_directory)
(output, err) = p1.communicate()
p1.wait()
# Rename the New Files
if get_output_directory != "":
for fname in os.listdir(get_output_directory):
if os.path.isfile(get_output_directory + "/" + fname):
if fname not in file_names:
count = count + 1
os.rename(get_output_directory + "/" + fname, get_output_directory + "/" + get_prefix + str(count).zfill(5) + ".iq")
new_files.append(get_prefix + str(count).zfill(5) + ".iq")
file_names.append(get_prefix + str(count).zfill(5) + ".iq")
original_filenames.append(get_all_filepaths[n])
# Update Progress Bar
progress_value = 95
self.tsi_pub_server.sendmsg('Status', Identifier = 'TSI', MessageName = 'Conditioner Progress Bar', Parameters = [progress_value,n])
# Method4: lowpass_filter
elif (get_category == "Energy - Burst Tagger") and (get_method == "Lowpass"):
count = 0
new_files = []
original_filenames = []
# Create a List of Files in Output Directory
if get_output_directory != "":
file_names = []
for fname in os.listdir(get_output_directory):
if os.path.isfile(get_output_directory+"/"+fname):
file_names.append(fname)
for n in range(0,len(get_all_filepaths)):
# Stop Conditioner Triggered
if self.conditioner_stop_event.is_set():
print("TSI Conditioner Stopped")
return
# Update Progress Bar
progress_value = 1+int((float((n+1)/len(get_all_filepaths))*90))
self.tsi_pub_server.sendmsg('Status', Identifier = 'TSI', MessageName = 'Conditioner Progress Bar', Parameters = [progress_value,n])
# Method Parameters
for m in range(len(method_parameter_names)):
if method_parameter_names[m] == 'threshold':
get_threshold = method_parameter_values[m]
elif method_parameter_names[m] == 'cutoff':
get_cutoff = method_parameter_values[m]
elif method_parameter_names[m] == 'transition':
get_transition = method_parameter_values[m]
elif method_parameter_names[m] == 'beta':
get_beta = method_parameter_values[m]
# Run the Flow Graph
cmd = "python3 " + fg_directory + "/burst_tagger/lowpass.py --filepath '" + get_all_filepaths[n] \
+ "' --sample-rate " + get_sample_rate + " --threshold " + get_threshold + " --cutoff-freq " + get_cutoff + " --transition-width " + get_transition \
+ " --beta " + get_beta
p1 = subprocess.Popen(cmd, shell=True, cwd=get_output_directory)
(output, err) = p1.communicate()
p1.wait()
# Rename the New Files
if get_output_directory != "":
for fname in os.listdir(get_output_directory):
if os.path.isfile(get_output_directory + "/" + fname):
if fname not in file_names:
count = count + 1
os.rename(get_output_directory + "/" + fname, get_output_directory + "/" + get_prefix + str(count).zfill(5) + ".iq")
new_files.append(get_prefix + str(count).zfill(5) + ".iq")
file_names.append(get_prefix + str(count).zfill(5) + ".iq")
original_filenames.append(get_all_filepaths[n])
# Update Progress Bar
progress_value = 95
self.tsi_pub_server.sendmsg('Status', Identifier = 'TSI', MessageName = 'Conditioner Progress Bar', Parameters = [progress_value,n])
# Method5: power_squelch_lowpass
elif (get_category == "Energy - Burst Tagger") and (get_method == "Power Squelch then Lowpass"):
count = 0
new_files = []
original_filenames = []
# Create a List of Files in Output Directory
if get_output_directory != "":
file_names = []
for fname in os.listdir(get_output_directory):
if os.path.isfile(get_output_directory+"/"+fname):
file_names.append(fname)
for n in range(0,len(get_all_filepaths)):
# Stop Conditioner Triggered
if self.conditioner_stop_event.is_set():
print("TSI Conditioner Stopped")
return
# Update Progress Bar
progress_value = 1+int((float((n+1)/len(get_all_filepaths))*90))
self.tsi_pub_server.sendmsg('Status', Identifier = 'TSI', MessageName = 'Conditioner Progress Bar', Parameters = [progress_value,n])
# Method Parameters
for m in range(len(method_parameter_names)):
if method_parameter_names[m] == 'squelch':
get_squelch = method_parameter_values[m]
elif method_parameter_names[m] == 'cutoff':
get_cutoff = method_parameter_values[m]
elif method_parameter_names[m] == 'transition':
get_transition = method_parameter_values[m]
elif method_parameter_names[m] == 'beta':
get_beta = method_parameter_values[m]
elif method_parameter_names[m] == 'threshold':
get_threshold = method_parameter_values[m]
# Run the Flow Graph
cmd = "python3 " + fg_directory + "/burst_tagger/power_squelch_lowpass.py --filepath '" + get_all_filepaths[n] \
+ "' --sample-rate " + get_sample_rate + " --threshold " + get_threshold + " --cutoff-freq " + get_cutoff + " --transition-width " + get_transition \
+ " --beta " + get_beta + " --squelch " + get_squelch
p1 = subprocess.Popen(cmd, shell=True, cwd=get_output_directory)
(output, err) = p1.communicate()
p1.wait()
# Rename the New Files
if get_output_directory != "":
for fname in os.listdir(get_output_directory):
if os.path.isfile(get_output_directory + "/" + fname):
if fname not in file_names:
count = count + 1
os.rename(get_output_directory + "/" + fname, get_output_directory + "/" + get_prefix + str(count).zfill(5) + ".iq")
new_files.append(get_prefix + str(count).zfill(5) + ".iq")
file_names.append(get_prefix + str(count).zfill(5) + ".iq")
original_filenames.append(get_all_filepaths[n])
# Update Progress Bar
progress_value = 95
self.tsi_pub_server.sendmsg('Status', Identifier = 'TSI', MessageName = 'Conditioner Progress Bar', Parameters = [progress_value,n])
# Method6: bandpass_filter
elif (get_category == "Energy - Burst Tagger") and (get_method == "Bandpass"):
count = 0
new_files = []
original_filenames = []
# Create a List of Files in Output Directory
if get_output_directory != "":
file_names = []
for fname in os.listdir(get_output_directory):
if os.path.isfile(get_output_directory+"/"+fname):
file_names.append(fname)
for n in range(0,len(get_all_filepaths)):
# Stop Conditioner Triggered
if self.conditioner_stop_event.is_set():
print("TSI Conditioner Stopped")
return
# Update Progress Bar
progress_value = 1+int((float((n+1)/len(get_all_filepaths))*90))
self.tsi_pub_server.sendmsg('Status', Identifier = 'TSI', MessageName = 'Conditioner Progress Bar', Parameters = [progress_value,n])
# Method Parameters
for m in range(len(method_parameter_names)):
if method_parameter_names[m] == 'bandpass_frequency':
get_bandpass_freq = method_parameter_values[m]
elif method_parameter_names[m] == 'bandpass_width':
get_bandpass_width = method_parameter_values[m]
elif method_parameter_names[m] == 'transition':
get_transition = method_parameter_values[m]
elif method_parameter_names[m] == 'beta':
get_beta = method_parameter_values[m]
elif method_parameter_names[m] == 'threshold':
get_threshold = method_parameter_values[m]
# Run the Flow Graph
cmd = "python3 " + fg_directory + "/burst_tagger/bandpass.py --filepath '" + get_all_filepaths[n] \
+ "' --sample-rate " + get_sample_rate + " --threshold " + get_threshold + " --bandpass-freq " + get_bandpass_freq + " --transition-width " + get_transition \
+ " --beta " + get_beta + " --bandpass-width " + get_bandpass_width
p1 = subprocess.Popen(cmd, shell=True, cwd=get_output_directory)
(output, err) = p1.communicate()
p1.wait()
# Rename the New Files
if get_output_directory != "":
for fname in os.listdir(get_output_directory):
if os.path.isfile(get_output_directory + "/" + fname):
if fname not in file_names:
count = count + 1
os.rename(get_output_directory + "/" + fname, get_output_directory + "/" + get_prefix + str(count).zfill(5) + ".iq")
new_files.append(get_prefix + str(count).zfill(5) + ".iq")
file_names.append(get_prefix + str(count).zfill(5) + ".iq")
original_filenames.append(get_all_filepaths[n])
# Update Progress Bar
progress_value = 95
self.tsi_pub_server.sendmsg('Status', Identifier = 'TSI', MessageName = 'Conditioner Progress Bar', Parameters = [progress_value,n])
# Method7: strongest
elif (get_category == "Energy - Burst Tagger") and (get_method == "Strongest Frequency then Bandpass"):
#self.textEdit_tsi_settings_bt_sfb_freq.setPlainText("?")
#self.textEdit_tsi_settings_bt_sfb_freq.setAlignment(QtCore.Qt.AlignCenter)
count = 0
new_files = []
original_filenames = []
# Create a List of Files in Output Directory
if get_output_directory != "":
file_names = []
for fname in os.listdir(get_output_directory):
if os.path.isfile(get_output_directory+"/"+fname):
file_names.append(fname)
for n in range(0,len(get_all_filepaths)):
# Stop Conditioner Triggered
if self.conditioner_stop_event.is_set():
print("TSI Conditioner Stopped")
return
# Update Progress Bar
progress_value = 1+int((float((n+1)/len(get_all_filepaths))*90))
self.tsi_pub_server.sendmsg('Status', Identifier = 'TSI', MessageName = 'Conditioner Progress Bar', Parameters = [progress_value,n])
# Method Parameters
for m in range(len(method_parameter_names)):
if method_parameter_names[m] == 'fft_size':
get_fft_size = method_parameter_values[m]
elif method_parameter_names[m] == 'fft_threshold':
get_fft_threshold = method_parameter_values[m]
elif method_parameter_names[m] == 'bandpass_width':
get_bandpass_width = method_parameter_values[m]
elif method_parameter_names[m] == 'transition':
get_transition = method_parameter_values[m]
elif method_parameter_names[m] == 'beta':
get_beta = method_parameter_values[m]
elif method_parameter_names[m] == 'threshold':
get_threshold = method_parameter_values[m]
# Acquire Number of Samples
file_bytes = os.path.getsize(get_all_filepaths[n])
file_samples = "-1"
if file_bytes > 0:
if get_type == "Complex Float 32":
file_samples = str(int(file_bytes/8))
elif get_type == "Float/Float 32":
file_samples = str(int(file_bytes/4))
elif get_type == "Short/Int 16":
file_samples = str(int(file_bytes/2))
elif get_type == "Int/Int 32":
file_samples = str(int(file_bytes/4))
elif get_type == "Byte/Int 8":
file_samples = str(int(file_bytes/1))
elif get_type == "Complex Int 16":
file_samples = str(int(file_bytes/4))