Skip to content

Commit

Permalink
serial_panel: improved delay handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tridge committed Jul 17, 2023
1 parent 3bec887 commit 9343e58
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions dronecan_gui_tool/panels/serial_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,12 +451,8 @@ def change_baud(self):
'''callback when selected baud rate changes'''
if self.tunnel:
baud = self.get_baudrate()
self.tunnel.baudrate = baud
print("change baudrate to %u" % baud)
if self.ublox_handling.checkState():
for b in [9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600]:
self.send_ublox_baud(b, baud)
time.sleep(0.01)
self.tunnel.baudrate = baud

def update_locked(self):
'''callback when locked state changes'''
Expand Down Expand Up @@ -504,6 +500,13 @@ def handle_ublox_data_out(self, buf):
self.handle_ublox_message_out()
self.ublox_msg_out = UBloxMessage()

def delay(self, delay_s):
t0 = time.time()
while time.time() - t0 < delay_s:
# keep the link alive
self.tunnel.send_bytes(bytearray())
time.sleep(0.01)

def handle_ublox_message_in(self):
'''handle a uBlox message from uCenter'''
mbuf = self.ublox_msg_in.raw()
Expand All @@ -513,7 +516,7 @@ def handle_ublox_message_in(self):
# getting data from uCenter faster than the serial port can handle it
port_rate = self.tunnel.baudrate / 10.0
delay_needed = mlen / port_rate
time.sleep(delay_needed)
self.delay(delay_needed)

# write message to the tunnel
self.tunnel.write(mbuf)
Expand Down

0 comments on commit 9343e58

Please sign in to comment.