From e5379683c8e3eb34c0c571ae52e70b3a3111b03c Mon Sep 17 00:00:00 2001 From: "artem30801@gmail.com" Date: Thu, 28 Mar 2019 18:12:39 +0300 Subject: [PATCH 1/2] Fixed selfcheck --- Drone/FlightLib2/FlightLib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Drone/FlightLib2/FlightLib.py b/Drone/FlightLib2/FlightLib.py index 7fa797a..16c67c7 100644 --- a/Drone/FlightLib2/FlightLib.py +++ b/Drone/FlightLib2/FlightLib.py @@ -49,7 +49,7 @@ def get_distance3d(x1, y1, z1, x2, y2, z2): def check(check_name): def inner(f): def wrapper(*args, **kwargs): - result, failures = f(*args, **kwargs) + failures = f(*args, **kwargs) if failures: msgs = [] for failure in failures: From 4e4102e65698f353c9fadbbddebf79f1be3100ac Mon Sep 17 00:00:00 2001 From: "artem30801@gmail.com" Date: Thu, 28 Mar 2019 18:22:03 +0300 Subject: [PATCH 2/2] Writing received broadcast to config Shutdown on keyboard interrupt in reconnect --- Drone/client.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Drone/client.py b/Drone/client.py index 297658c..4421255 100644 --- a/Drone/client.py +++ b/Drone/client.py @@ -43,7 +43,7 @@ def get_ntp_time(ntp_host, ntp_port): return unpacked[10] + float(unpacked[11]) / 2**32 - NTP_DELTA -def reconnect(timeout=2, attempt_limit=10): +def reconnect(timeout=2, attempt_limit=5): global clientSocket, host, port print("Trying to connect to", host, ":", port, "...") connected = False @@ -58,8 +58,12 @@ def reconnect(timeout=2, attempt_limit=10): print("Connection successful") clientSocket.settimeout(None) except socket.error as e: - print("Waiting for connection, can not connect:", e) - time.sleep(timeout) + if e.errno != errno.EINTR: + print("Waiting for connection, can not connect:", e) + time.sleep(timeout) + else: + print("Shutting down on keyboard interrupt") + raise KeyboardInterrupt attempt_count += 1 if attempt_count >= attempt_limit: @@ -75,6 +79,8 @@ def reconnect(timeout=2, attempt_limit=10): host, port = args["host"], int(args["port"]) print("Binding to new IP: ", host, port) broadcast_client.close() + write_to_config("SERVER", "port", port) + write_to_config("SERVER", "host", host) attempt_count = 0 break