From ca3c40e2c353d9a0c97b7b56941d1dd90892a684 Mon Sep 17 00:00:00 2001 From: Artem30801 Date: Mon, 25 Mar 2019 15:16:34 +0300 Subject: [PATCH] Little fixes --- Drone/client.py | 13 +++++++++---- Drone/play_animation.py | 1 + Server/server.py | 6 ++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Drone/client.py b/Drone/client.py index de352ed..feb0cfe 100644 --- a/Drone/client.py +++ b/Drone/client.py @@ -207,7 +207,7 @@ def selfcheck(): def write_to_config(section, option, value): config.set(section, option, value) - with open(CONFIG_PATH, 'w') as file: + with open(CONFIG_PATH, 'w') as file: # TODO as separate function config.write(file) @@ -272,14 +272,14 @@ try: command, args = parse_message(message) print("Command from server:", command, args) if command == "writefile": - recive_file(list(args.values())[0]) + recive_file(args['filename']) elif command == 'config_write': write_to_config(args['section'], args['option'], args['value']) elif command == 'config_reload': load_config() elif command == "starttime": global starttime - starttime = float(list(args.values())[0]) + starttime = float(args['time']) print("Starting on:", time.ctime(starttime)) dt = starttime - time.time() if USE_NTP: @@ -310,8 +310,13 @@ try: response = COPTER_ID elif request_target == 'selfcheck': response = selfcheck() - send_all(bytes(form_message("response", {"status": "ok", "value": response}))) + elif request_target == 'batt_voltage': + pass # TODO + + send_all(bytes(form_message("response", + {"status": "ok", "value": response, "value_name": request_target}))) print("Request responded with:", response) + except socket.error as e: if e.errno != errno.EINTR: print("Connection lost due error:", e) diff --git a/Drone/play_animation.py b/Drone/play_animation.py index 288dc86..2077f28 100644 --- a/Drone/play_animation.py +++ b/Drone/play_animation.py @@ -31,6 +31,7 @@ def animate_frame(current_frame, x0=0.0, y0=0.0): if USE_LEDS: LedLib.fill(current_frame['red'], current_frame['green'], current_frame['blue']) + def reach_frame(current_frame, x0=0.0, y0=0.0, timeout=5000): FlightLib.reach_point(current_frame['x']+x0, current_frame['y']+y0, current_frame['z'], yaw=1.57, timeout=timeout) # TODO yaw if USE_LEDS: diff --git a/Server/server.py b/Server/server.py index d6f9439..815131b 100644 --- a/Server/server.py +++ b/Server/server.py @@ -17,7 +17,7 @@ random.seed() logging.basicConfig( # TODO all prints as logs level=logging.INFO, - format="%(asctime)s [%(name)-7.7s] [%(threadName)-18.18s] [%(levelname)-7.7s] %(message)s", + format="%(asctime)s [%(name)-7.7s] [%(threadName)-19.19s] [%(levelname)-7.7s] %(message)s", handlers=[ logging.FileHandler("server_logs.log"), logging.StreamHandler() @@ -283,10 +283,12 @@ class Client: command, args = Client.parse_message(received) if command == "response": for key, value in self._request_queue.items(): - if not value: # TODO redo to value name + if not value and key == args["value_name"]: self._request_queue[key] = args['value'] print("Request successfully closed") break + else: + print("Unexpected request") else: self._received_queue.appendleft(received) except socket.error: