Skip to content

Commit 66abe11

Browse files
committed
Merge branch 'GUI'
# Conflicts: # controller/controller_toolbar_marcos.py
2 parents d2b3275 + d733a95 commit 66abe11

File tree

3 files changed

+88
-16
lines changed

3 files changed

+88
-16
lines changed

controller/controller_figures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def wellcomeMessage():
3434
Note:
3535
The method does not return any value.
3636
"""
37-
print("Graphical User Interface for MaRCoS")
37+
print("\nGraphical User Interface for MaRCoS")
3838
print("J.M. Algarín, PhD")
3939
print("josalggui@i3m.upv.es")
4040
print("mriLab @ i3M, CSIC, Valencia, Spain")

controller/controller_main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ def closeEvent(self, event):
4949
sys.stdout = sys.__stdout__
5050
if not self.demo:
5151
# Close server
52-
subprocess.run([hw.bash_path, "--", "./communicateRP.sh", hw.rp_ip_address, "killall marcos_server"])
52+
try:
53+
subprocess.run([hw.bash_path, "--", "./communicateRP.sh", hw.rp_ip_address, "killall marcos_server"])
54+
except:
55+
print("\nERROR: Server connection not found! Please verify if the blue LED is illuminated on the Red Pitaya.")
5356

5457
# Disable power modules
5558
self.toolbar_marcos.arduino.send("GPA_ON 0;")

controller/controller_toolbar_marcos.py

Lines changed: 83 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88

99
from widgets.widget_toolbar_marcos import MarcosToolBar
1010
import subprocess
11+
import platform
1112
import experiment as ex
1213
import numpy as np
1314
import shutil
1415
import configs.hw_config as hw
15-
import autotuning.autotuning as autotuning # Just to use an arduino
16+
import autotuning.autotuning as autotuning # Just to use an arduino
17+
import threading
1618

1719

1820
class MarcosController(MarcosToolBar):
@@ -51,21 +53,69 @@ def __init__(self, *args, **kwargs):
5153
self.action_copybitstream.triggered.connect(self.copyBitStream)
5254
self.action_gpa_init.triggered.connect(self.initgpa)
5355

56+
thread = threading.Thread(target=self.search_sdrlab)
57+
thread.start()
58+
5459
# Arduino to control the interlock
5560
self.arduino = autotuning.Arduino(baudrate=19200, name="interlock", serial_number=hw.ard_sn_interlock)
5661
self.arduino.connect()
5762

63+
def search_sdrlab(self):
64+
# Get the IP of the SDRLab
65+
if not self.demo:
66+
try:
67+
hw.rp_ip_address = self.get_sdrlab_ip()[0]
68+
except:
69+
print("No SDRLab found.")
70+
try:
71+
hw.rp_ip_address = self.get_sdrlab_ip()[0]
72+
except:
73+
print("No communication with SDRLab.")
74+
print("Try manually.")
75+
76+
77+
78+
@staticmethod
79+
def get_sdrlab_ip():
80+
print("\nSearching for SDRLabs...")
81+
82+
ip_addresses = []
83+
subnet = '192.168.1.'
84+
timeout = 0.1 # Adjust timeout value as needed
85+
86+
for i in range(101, 132): # Scan IP range 192.168.1.101 to 192.168.1.132
87+
ip = subnet + str(i)
88+
try:
89+
if platform.system() == 'Linux':
90+
subprocess.run(['ping', '-c', '1', ip], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
91+
timeout=timeout)
92+
elif platform.system() == 'Windows':
93+
subprocess.run(['ping', '-n', '1', ip], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
94+
timeout=timeout)
95+
ip_addresses.append(ip)
96+
except:
97+
pass
98+
99+
for ip in ip_addresses:
100+
print("SDRLab found at IP " + ip)
101+
102+
return ip_addresses
103+
58104
def startMaRCoS(self):
59105
"""
60106
Starts the MaRCoS system.
61107
62108
Executes startRP.sh: copy_bitstream.sh & marcos_server.
63109
"""
64110
if not self.demo:
65-
subprocess.run([hw.bash_path, "--", "./communicateRP.sh", hw.rp_ip_address, "killall marcos_server"])
66-
subprocess.run([hw.bash_path, "--", "./startRP.sh", hw.rp_ip_address, hw.rp_version])
67-
self.initgpa()
68-
print("\nMaRCoS updated, server connected, gpa initialized.")
111+
112+
try:
113+
subprocess.run([hw.bash_path, "--", "./communicateRP.sh", hw.rp_ip_address, "killall marcos_server"])
114+
subprocess.run([hw.bash_path, "--", "./startRP.sh", hw.rp_ip_address, hw.rp_version])
115+
self.initgpa()
116+
print("\nMaRCoS updated, server connected, gpa initialized.")
117+
except:
118+
print("\nERROR: Server connection not found! Please verify if the blue LED is illuminated on the Red Pitaya.")
69119
else:
70120
print("\nThis is a demo")
71121
self.action_server.setChecked(True)
@@ -79,16 +129,31 @@ def controlMarcosServer(self):
79129
"""
80130
if not self.demo:
81131
if not self.action_server.isChecked():
132+
subprocess.run([hw.bash_path, "--", "./communicateRP.sh", hw.rp_ip_address, "killall marcos_server"])
82133
self.action_server.setStatusTip('Connect to marcos server')
83134
self.action_server.setToolTip('Connect to marcos server')
84-
subprocess.run([hw.bash_path, "--", "./communicateRP.sh", hw.rp_ip_address, "killall marcos_server"])
85135
print("\nServer disconnected")
86136
else:
87-
self.action_server.setStatusTip('Kill marcos server')
88-
self.action_server.setToolTip('Kill marcos server')
89137
subprocess.run([hw.bash_path, "--", "./communicateRP.sh", hw.rp_ip_address, "killall marcos_server"])
138+
time.sleep(1.5)
90139
subprocess.run([hw.bash_path, "--", "./communicateRP.sh", hw.rp_ip_address, "~/marcos_server"])
91-
print("\nServer connected")
140+
time.sleep(1.5)
141+
self.action_server.setStatusTip('Kill marcos server')
142+
self.action_server.setToolTip('Kill marcos server')
143+
144+
# Run tiny sequence to check connection to the server
145+
try:
146+
expt = ex.Experiment(init_gpa=False)
147+
expt.add_flodict({
148+
'grad_vx': (np.array([100]), np.array([0])),
149+
})
150+
expt.run()
151+
expt.__del__()
152+
print("\nServer connected!")
153+
except Exception as e:
154+
print("\nServer not connected!")
155+
print("Try to connect to the server again.")
156+
print("Error details:", e)
92157
else:
93158
print("\nThis is a demo")
94159

@@ -99,9 +164,13 @@ def copyBitStream(self):
99164
Executes copy_bitstream.sh.
100165
"""
101166
if not self.demo:
102-
subprocess.run([hw.bash_path, "--", "./communicateRP.sh", hw.rp_ip_address, "killall marcos_server"])
103-
subprocess.run([hw.bash_path, '--', './copy_bitstream.sh', '192.168.1.101', 'rp-122'])
104-
print("\nMaRCoS updated")
167+
try:
168+
subprocess.run([hw.bash_path, "--", "./communicateRP.sh", hw.rp_ip_address, "killall marcos_server"])
169+
subprocess.run([hw.bash_path, '--', './copy_bitstream.sh', hw.rp_ip_address, 'rp-122'], timeout=10)
170+
print("\nMaRCoS updated")
171+
except subprocess.TimeoutExpired as e:
172+
print("\nTimeout error.")
173+
print("Error details:", e)
105174
else:
106175
print("\nThis is a demo.")
107176
self.action_server.setChecked(False)
@@ -114,7 +183,7 @@ def initgpa(self):
114183
if self.action_server.isChecked():
115184
if not self.demo:
116185
link = False
117-
while link == False:
186+
while not link:
118187
try:
119188
# Check if GPA available
120189
received_string = self.arduino.send("GPA_VERB 1;").decode()
@@ -157,7 +226,7 @@ def initgpa(self):
157226
expt.__del__()
158227
link = True
159228
print("\nGPA init done!")
160-
229+
161230
# Enable power modules
162231
# Enable GPA module
163232
received_string = self.arduino.send("GPA_ON 1;").decode() # Enable power module

0 commit comments

Comments
 (0)