From 85bfcd181fb686cd9ac37774e508863b9461bf67 Mon Sep 17 00:00:00 2001 From: artem30801 <38689676+artem30801@users.noreply.github.com> Date: Wed, 26 Jun 2019 00:28:58 +0300 Subject: [PATCH 1/3] Quick fix (probably) --- Drone/copter_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Drone/copter_client.py b/Drone/copter_client.py index ac22c1f..7c2d680 100644 --- a/Drone/copter_client.py +++ b/Drone/copter_client.py @@ -193,7 +193,7 @@ def _play_animation(**kwargs): frame_time = rfp_time + client.active_client.RFP_TIME frame_delay = 0.125 # TODO from animation file for frame in frames: - point, color = animation.convert_frame(frame) # TODO add param to calculate delta + point, color, yaw = animation.convert_frame(frame) # TODO add param to calculate delta task_manager.add_task(frame_time, 0, animation.execute_frame, task_kwargs={ "point": point, From c04bff12ac17f30ba2cce409641101bbac86ef2a Mon Sep 17 00:00:00 2001 From: Artem30801 Date: Wed, 26 Jun 2019 20:11:01 +0300 Subject: [PATCH 2/3] added on_broadcast() for client-side --- Drone/client.py | 4 ++++ Drone/copter_client.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Drone/client.py b/Drone/client.py index 8b5d6fe..f824e5e 100644 --- a/Drone/client.py +++ b/Drone/client.py @@ -175,10 +175,14 @@ class Client(object): ConfigOption("SERVER", "port", self.server_port), ConfigOption("SERVER", "host", self.server_host)) logger.info("Binding to new IP: {}:{}".format(self.server_host, self.server_port)) + self.on_broadcast_bind() break finally: broadcast_client.close() + def on_broadcast_bind(self): + pass + def _process_connections(self): while True: events = self.selector.select(timeout=1) diff --git a/Drone/copter_client.py b/Drone/copter_client.py index 7c2d680..9c21ac5 100644 --- a/Drone/copter_client.py +++ b/Drone/copter_client.py @@ -41,6 +41,10 @@ class CopterClient(client.Client): self.USE_LEDS = self.config.getboolean('PRIVATE', 'use_leds') self.LED_PIN = self.config.getint('PRIVATE', 'led_pin') + def on_broadcast_bind(self): + #TODO change chony config + _command_service_restart(name="chrony") + def start(self, task_manager_instance): client.logger.info("Init ROS node") rospy.init_node('Swarm_client', anonymous=True) From fe76cdfe087276ce50fa0413fadad502d4707a0c Mon Sep 17 00:00:00 2001 From: Artem30801 Date: Thu, 27 Jun 2019 11:06:20 +0300 Subject: [PATCH 3/3] Added chrony ip configuration on start; close #20 --- Drone/copter_client.py | 46 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/Drone/copter_client.py b/Drone/copter_client.py index 9c21ac5..e12855f 100644 --- a/Drone/copter_client.py +++ b/Drone/copter_client.py @@ -42,8 +42,8 @@ class CopterClient(client.Client): self.LED_PIN = self.config.getint('PRIVATE', 'led_pin') def on_broadcast_bind(self): - #TODO change chony config - _command_service_restart(name="chrony") + configure_chrony_ip(self.server_host) + restart_service("chrony") def start(self, task_manager_instance): client.logger.info("Init ROS node") @@ -56,6 +56,43 @@ class CopterClient(client.Client): super(CopterClient, self).start() +def restart_service(name): + os.system("systemctl restart {}".format(name)) + + +def configure_chrony_ip(ip, path="/etc/chrony/chrony.conf", ip_index=1): + try: + with open(path, 'r') as f: + raw_content = f.read() + except IOError as e: + print("Reading error {}".format(e)) + return False + + content = raw_content.split(" ") + + try: + current_ip = content[ip_index] + except IndexError: + print("Something wrong with config") + return False + + if "." not in current_ip: + print("That's not ip!") + return False + + if current_ip != ip: + content[ip_index] = ip + + try: + with open(path, 'w') as f: + f.write(" ".join(content)) + except IOError: + print("Error writing") + return False + + return True + + @messaging.request_callback("selfcheck") def _response_selfcheck(): check = FlightLib.selfcheck() @@ -79,12 +116,13 @@ def _response_cell(): @messaging.message_callback("test") def _command_test(**kwargs): - print("test") + logger.info("logging info test") + print("stdout test") @messaging.message_callback("service_restart") def _command_service_restart(**kwargs): - os.system("systemctl restart {}".format(kwargs["name"])) + restart_service(kwargs["name"]) @messaging.message_callback("led_test")