diff --git a/class_model/src/utils/protoJson_mqtt_pub_data_to_ros.py b/class_model/src/utils/protoJson_mqtt_pub_data_to_ros.py index 35c08bc..13bea22 100644 --- a/class_model/src/utils/protoJson_mqtt_pub_data_to_ros.py +++ b/class_model/src/utils/protoJson_mqtt_pub_data_to_ros.py @@ -4,6 +4,7 @@ import time import proto.flight_information_pb2 as flight_information_pb2 import proto.flyformatioln_pb2 as flyformatioln_pb2 import google.protobuf.json_format as json_format +import threading class Proto_msg_to_ros: #Protobuf @@ -50,15 +51,29 @@ class Json_msg_to_ros: @classmethod def Drone550_on_message_Flight_Information(cls, client, userdata, msg): - cls.Drone550_publisher_Flight_Information.publish(msg.payload.decode("UTF-8")) - cls.rate.sleep() + # define a function for handling the data from mqtt + def thread_function(): + cls.Drone550_publisher_Flight_Information.publish(msg.payload.decode("UTF-8")) + cls.rate.sleep() + + # create a new thread to process the data + t = threading.Thread(target=thread_function) + t.start() @classmethod def Drone380_on_message_Flight_Information(cls, client, userdata, msg): - cls.Drone380_publisher_Flight_Information.publish(msg.payload.decode("UTF-8")) - cls.rate.sleep() + def thread_function(): + cls.Drone380_publisher_Flight_Information.publish(msg.payload.decode("UTF-8")) + cls.rate.sleep() + + t = threading.Thread(target=thread_function) + t.start() @classmethod def Drone650_on_message_Flight_Information(cls, client, userdata, msg): - cls.Drone650_publisher_Flight_Information.publish(msg.payload.decode("UTF-8")) - cls.rate.sleep() + def thread_function(): + cls.Drone650_publisher_Flight_Information.publish(msg.payload.decode("UTF-8")) + cls.rate.sleep() + + t = threading.Thread(target=thread_function) + t.start()