From c42364c9fade1b3805fbf602b83b7c1b19a5cd96 Mon Sep 17 00:00:00 2001 From: RangeOfGlitching Date: Mon, 20 Mar 2023 01:10:32 +0800 Subject: [PATCH] up to date --- Stream/measure_rtl/delayClientA_PUB.py | 15 ++- Stream/measure_rtl/delayClientA_SUB.py | 15 ++- Stream/measure_rtl/delayClientB.py | 17 ++- .../measure_rtl/delayData/Mosquitto/testf.py | 13 --- Stream/measure_rtl/delayData/measureDelay.py | 7 +- Stream/measure_rtl/ex | 3 + .../utils/mqttConfig_delayA_PUB.yml | 6 +- .../utils/mqttConfig_delayA_SUB.yml | 6 +- .../utils/mqttConfig_delayB_SUB.yml | 6 +- Stream/uav_proto_msg/mqttPubMain.py | 16 +-- Stream/uav_proto_msg/mqttSubMain.py | 10 +- Stream/uav_proto_msg/mqttSub_changeLeader.py | 109 ++++++++++++++++++ Stream/uav_proto_msg/protomsg/Data/sizeData | 2 +- .../JsonProtosize/timestamp_info_message | 2 +- .../JsonProtosize/timestamp_info_message.bin | 2 +- Stream/uav_proto_msg/utils/mqttConfig_PUB.yml | 2 +- Stream/uav_proto_msg/utils/mqttConfig_SUB.yml | 2 +- .../utils/protoJson_mqtt_pub_data_to_ros.py | 66 +++++------ 18 files changed, 216 insertions(+), 83 deletions(-) delete mode 100644 Stream/measure_rtl/delayData/Mosquitto/testf.py create mode 100644 Stream/measure_rtl/ex create mode 100644 Stream/uav_proto_msg/mqttSub_changeLeader.py diff --git a/Stream/measure_rtl/delayClientA_PUB.py b/Stream/measure_rtl/delayClientA_PUB.py index 26e4351..5abb38c 100644 --- a/Stream/measure_rtl/delayClientA_PUB.py +++ b/Stream/measure_rtl/delayClientA_PUB.py @@ -5,7 +5,7 @@ import os import sys import time import utils - +import argparse import proto.flyformatioln_pb2 as flyformatioln_pb2 import logging from utils.protoJson_delayClientA_PUB import Json_msg @@ -41,9 +41,22 @@ def on_publish(self, userdata, mid): if __name__ == '__main__': time.sleep(0.25) + + parser = argparse.ArgumentParser() + parser.add_argument("-q", "--qos", type=int, help="qos") + parser.add_argument("-p", "--port", type=int, help="port") + parser.add_argument("-f", "--format", type=str, help="format") + args = parser.parse_args() # Read Config FilePath = os.path.join(os.path.dirname(__file__),"utils","mqttConfig_delayA_PUB.yml") cfg = utils.Read_delayA_PUB_Config(FilePath) + + if args.qos != None: + cfg.qos = args.qos + if args.port != None: + cfg.port = args.port + if args.format != None: + cfg.msg_format = args.format # Mqtt client = utils.MQTTClient(cfg.MQTTClientNamePub) pubFun = None diff --git a/Stream/measure_rtl/delayClientA_SUB.py b/Stream/measure_rtl/delayClientA_SUB.py index 0903987..80240ec 100644 --- a/Stream/measure_rtl/delayClientA_SUB.py +++ b/Stream/measure_rtl/delayClientA_SUB.py @@ -9,7 +9,7 @@ import logging import utils from utils.protoJson_delayClientA_SUB import Json_msg from utils.protoJson_delayClientA_SUB import Proto_msg - +import argparse def init_dataFormat(cfg:utils.Read_delayB_SUB_Config): if cfg.msg_format == "Proto": @@ -35,11 +35,22 @@ def on_publish(self, userdata, mid): pass if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("-q", "--qos", type=int, help="qos") + parser.add_argument("-p", "--port", type=int, help="port") + parser.add_argument("-f", "--format", type=str, help="format") + args = parser.parse_args() # Read Config FilePath = os.path.join(os.path.dirname(__file__),"utils","mqttConfig_delayA_SUB.yml") cfg = utils.Read_delayA_SUB_Config(FilePath) client = utils.MQTTClient(cfg.MQTTClientNameSub) - + + if args.qos != None: + cfg.qos = args.qos + if args.port != None: + cfg.port = args.port + if args.format != None: + cfg.msg_format = args.format init_dataFormat(cfg) # set log diff --git a/Stream/measure_rtl/delayClientB.py b/Stream/measure_rtl/delayClientB.py index abac703..38a7e39 100644 --- a/Stream/measure_rtl/delayClientB.py +++ b/Stream/measure_rtl/delayClientB.py @@ -3,6 +3,7 @@ import paho.mqtt.client as mqtt import os import sys +import argparse import utils import proto.flight_information_pb2 as flight_information_pb2 import proto.flyformatioln_pb2 as flyformatioln_pb2 @@ -44,11 +45,25 @@ def on_publish(self, userdata, mid): if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("-q", "--qos", type=int, help="qos") + parser.add_argument("-p", "--port", type=int, help="port") + parser.add_argument("-f", "--format", type=str, help="format") + args = parser.parse_args() + # Read Config FilePath = os.path.join(os.path.dirname(__file__),"utils","mqttConfig_delayB_SUB.yml") cfg = utils.Read_delayB_SUB_Config(FilePath) + + if args.qos != None: + cfg.qos = args.qos + if args.port != None: + cfg.port = args.port + if args.format != None: + cfg.msg_format = args.format + + client = utils.MQTTClient(cfg.MQTTClientNameSub) - # Mqtt client = utils.MQTTClient(cfg.MQTTClientNameSub) client.on_connect = on_connect diff --git a/Stream/measure_rtl/delayData/Mosquitto/testf.py b/Stream/measure_rtl/delayData/Mosquitto/testf.py deleted file mode 100644 index 89867a1..0000000 --- a/Stream/measure_rtl/delayData/Mosquitto/testf.py +++ /dev/null @@ -1,13 +0,0 @@ -from pathlib import Path - -# Get the path to the directory to traverse -directory = Path.cwd() -Protodir = [] -Jsondir = [] -# Iterate over the files and directories in the directory tree -for path in directory.glob('**/*.log'): - if "Proto" in str(path): - Protodir.append(path) - elif "Json" in str(path): - Jsondir.append(path) - print(Protodir) \ No newline at end of file diff --git a/Stream/measure_rtl/delayData/measureDelay.py b/Stream/measure_rtl/delayData/measureDelay.py index 0652286..bc85422 100644 --- a/Stream/measure_rtl/delayData/measureDelay.py +++ b/Stream/measure_rtl/delayData/measureDelay.py @@ -15,8 +15,9 @@ def checkNumberofLines(df): if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("-q", "--qos", type=int, default=0, help="qos", required=True) - parser.add_argument("-b", "--broker", type=str, default="{}", help="Broker", required=True) + parser.add_argument("-b", "--broker", type=str, default="HiveMQ", help="Broker", required=True) args = parser.parse_args() + # read in the log file df_Proto_delayA_PUB = pd.read_csv(f"{args.broker}/qos{args.qos}/ProtodelayA_PUB.log", delim_whitespace=True, header=None, names=["count", "time"]) @@ -47,8 +48,8 @@ if __name__ == "__main__": avg_Json = np.average(array_Json) fig = plt.figure() - plt.plot(array_Proto, color="blue", label=f"Proto: {avg_Proto}") - plt.plot(array_Json, color="red", label=f"Json: {avg_Json}") + # plt.plot(array_Proto, color="blue", label=f"Proto: {avg_Proto}") + plt.plot(array_Json, color="red", label=f"qos0: {avg_Json}") plt.legend() plt.xlabel("Number of messages") plt.ylabel("Delay (s)") diff --git a/Stream/measure_rtl/ex b/Stream/measure_rtl/ex new file mode 100644 index 0000000..bcfdac3 --- /dev/null +++ b/Stream/measure_rtl/ex @@ -0,0 +1,3 @@ +python delayClientA_PUB.py -q 0 -p 1884 -f Json + + diff --git a/Stream/measure_rtl/utils/mqttConfig_delayA_PUB.yml b/Stream/measure_rtl/utils/mqttConfig_delayA_PUB.yml index 19586f5..6140524 100644 --- a/Stream/measure_rtl/utils/mqttConfig_delayA_PUB.yml +++ b/Stream/measure_rtl/utils/mqttConfig_delayA_PUB.yml @@ -1,7 +1,7 @@ MQTT: - msg_format: Proto - # msg_format: Json - qos: 1 + # msg_format: Proto + msg_format: Json + qos: 0 MQTTClientNamePub: delayA_PUB host: 192.168.50.117 port: 1883 diff --git a/Stream/measure_rtl/utils/mqttConfig_delayA_SUB.yml b/Stream/measure_rtl/utils/mqttConfig_delayA_SUB.yml index 4872643..b6d1b20 100644 --- a/Stream/measure_rtl/utils/mqttConfig_delayA_SUB.yml +++ b/Stream/measure_rtl/utils/mqttConfig_delayA_SUB.yml @@ -1,7 +1,7 @@ MQTT: - msg_format: Proto - # msg_format: Json - qos: 1 + # msg_format: Proto + msg_format: Json + qos: 0 MQTTClientNameSub: delayA_SUB host: 192.168.50.117 port: 1883 diff --git a/Stream/measure_rtl/utils/mqttConfig_delayB_SUB.yml b/Stream/measure_rtl/utils/mqttConfig_delayB_SUB.yml index bb00d06..0336d3c 100644 --- a/Stream/measure_rtl/utils/mqttConfig_delayB_SUB.yml +++ b/Stream/measure_rtl/utils/mqttConfig_delayB_SUB.yml @@ -1,7 +1,7 @@ MQTT: - msg_format: Proto - # msg_format: Json - qos: 1 + # msg_format: Proto + msg_format: Json + qos: 0 MQTTClientNameSub: delayB_SUB host: 192.168.50.117 port: 1883 diff --git a/Stream/uav_proto_msg/mqttPubMain.py b/Stream/uav_proto_msg/mqttPubMain.py index 2729d37..9a1c393 100644 --- a/Stream/uav_proto_msg/mqttPubMain.py +++ b/Stream/uav_proto_msg/mqttPubMain.py @@ -25,9 +25,9 @@ import random class fakeGps(): def __init__(self): - self.latitude = 0.0 - self.longitude = 20 - self.altitude = 30 + self.latitude = 8.0 + self.longitude = 8.1 + self.altitude = 8.88 class fake_hdg(): def __init__(self): @@ -99,7 +99,7 @@ if __name__ == '__main__': file_handler.setLevel(logging.INFO) logger = logging.getLogger("__PUB__") - logger.setLevel(logging.CRITICAL) + logger.setLevel(logging.DEBUG) logger.addHandler(file_handler) logger.addHandler(stream_handler) @@ -128,10 +128,10 @@ if __name__ == '__main__': # formation = fake_formation() while True: # test proto - gps.latitude = random.uniform(0, 10) - gps.longitude = random.uniform(0, 10) - gps.altitude = random.uniform(0, 10) - hdg.data = random.uniform(0, 10) + # gps.latitude = random.uniform(10, 100) + # gps.longitude = random.uniform(10, 100) + # gps.altitude = random.uniform(10, 100) + # hdg.data = random.uniform(0, 10) # formation.velocity = random.uniform(0, 10) try: diff --git a/Stream/uav_proto_msg/mqttSubMain.py b/Stream/uav_proto_msg/mqttSubMain.py index d065601..cd88833 100644 --- a/Stream/uav_proto_msg/mqttSubMain.py +++ b/Stream/uav_proto_msg/mqttSubMain.py @@ -20,7 +20,8 @@ def init_dataFormat(cfg:utils.Read_SUB_Config): utils.Proto_msg_to_ros.flight_information_msg = flight_information_pb2.flight_information_message() utils.Proto_msg_to_ros.fly_formation_msg = flyformatioln_pb2.fly_formation_message() - client.on_message = utils.Proto_msg_to_ros.on_message + client.message_callback_add(cfg.Flight_Information_topicToMqtt, utils.Proto_msg_to_ros.on_message_Flight_Information) + client.message_callback_add(cfg.Fly_Formation_topicToMqtt, utils.Proto_msg_to_ros.on_message_Fly_Formation) utils.Proto_msg_to_ros.Flight_Information_topicToMqtt = cfg.Flight_Information_topicToMqtt utils.Proto_msg_to_ros.Fly_Formation_topicToMqtt = cfg.Fly_Formation_topicToMqtt @@ -28,20 +29,21 @@ def init_dataFormat(cfg:utils.Read_SUB_Config): # utils.Json_msg_to_ros.rate = rospy.Rate(10) # utils.Json_msg_to_ros.publisher_Flight_Information = rospy.Publisher(cfg.ROStopicName_Flight_Information,String,queue_size=10) # utils.Json_msg_to_ros.publisher_Fly_Formation = rospy.Publisher(cfg.ROStopicName_Fly_Formation,String,queue_size=10) + + client.message_callback_add(cfg.Flight_Information_topicToMqtt, utils.Json_msg_to_ros.on_message_Flight_Information) + client.message_callback_add(cfg.Fly_Formation_topicToMqtt, utils.Json_msg_to_ros.on_message_Fly_Formation) - client.on_message = utils.Json_msg_to_ros.on_message utils.Json_msg_to_ros.Flight_Information_topicToMqtt = cfg.Flight_Information_topicToMqtt utils.Json_msg_to_ros.Fly_Formation_topicToMqtt = cfg.Fly_Formation_topicToMqtt else: logging.debug("msg_format not found") -# def on_message(client, userdata, msg): -# utils.Json_msg_to_ros.ros_pub(msg) def on_connect(self, userdata, flags, rc): logger.info("Connected with result code " + str(rc)) client.subscribe(cfg.Flight_Information_topicToMqtt) client.subscribe(cfg.Fly_Formation_topicToMqtt) + def on_disconnect(client, userdata, rc): # logger.info("disconnecting reason " +str(rc)) diff --git a/Stream/uav_proto_msg/mqttSub_changeLeader.py b/Stream/uav_proto_msg/mqttSub_changeLeader.py new file mode 100644 index 0000000..2ebe215 --- /dev/null +++ b/Stream/uav_proto_msg/mqttSub_changeLeader.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python3 +#coding:utf-8 +import paho.mqtt.client as mqtt +import os +import sys +import time +import utils +import proto.flight_information_pb2 as flight_information_pb2 +import proto.flyformatioln_pb2 as flyformatioln_pb2 +import rospy +from std_msgs.msg import String +import logging + +def init_dataFormat(cfg:utils.Read_SUB_Config): + if cfg.msg_format == "Proto": + # utils.Proto_msg_to_ros.rate = rospy.Rate(10) + # utils.Proto_msg_to_ros.publisher_Flight_Information = rospy.Publisher(cfg.ROStopicName_Flight_Information,String,queue_size=10) + # utils.Proto_msg_to_ros.publisher_Fly_Formation = rospy.Publisher(cfg.ROStopicName_Fly_Formation,String,queue_size=10) + + utils.Proto_msg_to_ros.flight_information_msg = flight_information_pb2.flight_information_message() + utils.Proto_msg_to_ros.fly_formation_msg = flyformatioln_pb2.fly_formation_message() + + client.on_message = utils.Proto_msg_to_ros.on_message + + utils.Proto_msg_to_ros.Flight_Information_topicToMqtt = cfg.Flight_Information_topicToMqtt + utils.Proto_msg_to_ros.Fly_Formation_topicToMqtt = cfg.Fly_Formation_topicToMqtt + elif cfg.msg_format == "Json": + # utils.Json_msg_to_ros.rate = rospy.Rate(10) + # utils.Json_msg_to_ros.publisher_Flight_Information = rospy.Publisher(cfg.ROStopicName_Flight_Information,String,queue_size=10) + # utils.Json_msg_to_ros.publisher_Fly_Formation = rospy.Publisher(cfg.ROStopicName_Fly_Formation,String,queue_size=10) + + client.on_message = utils.Json_msg_to_ros.on_message + utils.Json_msg_to_ros.Flight_Information_topicToMqtt = cfg.Flight_Information_topicToMqtt + utils.Json_msg_to_ros.Fly_Formation_topicToMqtt = cfg.Fly_Formation_topicToMqtt + else: + logging.debug("msg_format not found") + +# def on_message(client, userdata, msg): +# utils.Json_msg_to_ros.ros_pub(msg) + +def on_connect(self, userdata, flags, rc): + logger.info("Connected with result code " + str(rc)) + client.subscribe(cfg.Flight_Information_topicToMqtt) + # client.subscribe(cfg.Fly_Formation_topicToMqtt) + client.subscribe("cmd/Change_Leader") + client.message_callback_add("cmd/Change_Leader", on_message_ChangLeader) + +def on_message_ChangLeader(client, userdata, msg): + client.unsubscribe(cfg.Flight_Information_topicToMqtt) + cfg.Flight_Information_topicToMqtt = "Drone650/Flight_Information" + client.subscribe(cfg.Flight_Information_topicToMqtt) + +def on_disconnect(client, userdata, rc): + # logger.info("disconnecting reason " +str(rc)) + client.connected_flag=False + client.disconnect_flag=True + +def on_publish(self, userdata, mid): + pass + + +if __name__ == '__main__': + # Read Config + FilePath = os.path.join(os.path.dirname(__file__),"utils","mqttConfig_SUB.yml") + cfg = utils.Read_SUB_Config(FilePath) + client = utils.MQTTClient(cfg.MQTTClientNameSub) + + # set log + log_format = "%(asctime)s - %(levelname)s - %(message)s" + formatter = logging.Formatter(log_format) + + stream_handler = logging.StreamHandler() + stream_handler.setFormatter(formatter) + stream_handler.setLevel(logging.DEBUG) + + + file_handler = logging.FileHandler(cfg.logFileName) + file_handler.setFormatter(formatter) + file_handler.setLevel(logging.INFO) + + logger = logging.getLogger("__SUB__") + logger.setLevel(logging.DEBUG) + logger.addHandler(file_handler) + logger.addHandler(stream_handler) + + logger.info(cfg) + + # Mqtt + client = utils.MQTTClient(cfg.MQTTClientNameSub) + client.on_connect = on_connect + client.on_publish = on_publish + client.on_disconnect = on_disconnect + client.connect(host=cfg.host, port=cfg.port, keepalive=cfg.keepalive) + + + # Ros + # rospy.init_node(cfg.ROSClientNameSub) + # initialize + init_dataFormat(cfg) + try: + client.loop_forever() + # rospy.spin() + except KeyboardInterrupt as e: + client.loop_stop() + client.disconnect() + logger.info("End of program") + sys.exit() + + diff --git a/Stream/uav_proto_msg/protomsg/Data/sizeData b/Stream/uav_proto_msg/protomsg/Data/sizeData index c961a57..63acdde 100644 --- a/Stream/uav_proto_msg/protomsg/Data/sizeData +++ b/Stream/uav_proto_msg/protomsg/Data/sizeData @@ -1 +1 @@ -{"flight_info_message":{"json":85,"proto":22},"fly_format_message":{"json":55,"proto":7},"imu_info_message":{"json":130,"proto":34},"odom_info_message":{"json":59,"proto":17},"flymode_info_message":{"json":38,"proto":2},"duration_info_message":{"json":8,"proto":4},"timestamp_info_message":{"json":29,"proto":11},"Total":{"json":404,"proto":97}} \ No newline at end of file +{"flight_info_message":{"json":85,"proto":22},"fly_format_message":{"json":55,"proto":7},"imu_info_message":{"json":130,"proto":34},"odom_info_message":{"json":59,"proto":17},"flymode_info_message":{"json":38,"proto":2},"duration_info_message":{"json":8,"proto":4},"timestamp_info_message":{"json":29,"proto":12},"Total":{"json":404,"proto":98}} \ No newline at end of file diff --git a/Stream/uav_proto_msg/protomsg/JsonProtosize/timestamp_info_message b/Stream/uav_proto_msg/protomsg/JsonProtosize/timestamp_info_message index 53a2984..42b2c60 100644 --- a/Stream/uav_proto_msg/protomsg/JsonProtosize/timestamp_info_message +++ b/Stream/uav_proto_msg/protomsg/JsonProtosize/timestamp_info_message @@ -1 +1 @@ -"2022-12-08T16:44:17.067479Z" \ No newline at end of file +"2023-02-20T17:27:58.498239Z" \ No newline at end of file diff --git a/Stream/uav_proto_msg/protomsg/JsonProtosize/timestamp_info_message.bin b/Stream/uav_proto_msg/protomsg/JsonProtosize/timestamp_info_message.bin index e5a6744..42d9191 100644 --- a/Stream/uav_proto_msg/protomsg/JsonProtosize/timestamp_info_message.bin +++ b/Stream/uav_proto_msg/protomsg/JsonProtosize/timestamp_info_message.bin @@ -1 +1 @@ -á¨ÈœÀ³÷ \ No newline at end of file +žÛΟÈýŸí \ No newline at end of file diff --git a/Stream/uav_proto_msg/utils/mqttConfig_PUB.yml b/Stream/uav_proto_msg/utils/mqttConfig_PUB.yml index f4b79f7..6a665e4 100644 --- a/Stream/uav_proto_msg/utils/mqttConfig_PUB.yml +++ b/Stream/uav_proto_msg/utils/mqttConfig_PUB.yml @@ -1,7 +1,7 @@ MQTT: msg_format: Json MQTTClientNamePub: Drone550Pub - host: 192.168.50.118 + host: 192.168.50.117 port: 1883 keepalive: 60 willTopic: CheckDoneConnect diff --git a/Stream/uav_proto_msg/utils/mqttConfig_SUB.yml b/Stream/uav_proto_msg/utils/mqttConfig_SUB.yml index ec37b3d..9e3feaa 100644 --- a/Stream/uav_proto_msg/utils/mqttConfig_SUB.yml +++ b/Stream/uav_proto_msg/utils/mqttConfig_SUB.yml @@ -1,7 +1,7 @@ MQTT: msg_format: Json MQTTClientNameSub: Drone550Sub - host: 192.168.50.118 + host: 192.168.50.117 port: 1883 keepalive: 60 willTopic: CheckDoneConnect diff --git a/Stream/uav_proto_msg/utils/protoJson_mqtt_pub_data_to_ros.py b/Stream/uav_proto_msg/utils/protoJson_mqtt_pub_data_to_ros.py index 6ed5970..3f3742e 100644 --- a/Stream/uav_proto_msg/utils/protoJson_mqtt_pub_data_to_ros.py +++ b/Stream/uav_proto_msg/utils/protoJson_mqtt_pub_data_to_ros.py @@ -24,29 +24,23 @@ class Proto_msg_to_ros: Fly_Formation_topicToMqtt = None #Proto - @classmethod - def ros_pub(cls, dataProto): - if dataProto.topic == cls.Flight_Information_topicToMqtt: - proto_msg = cls.flight_information_msg.FromString(dataProto.payload) - protoTOJson_msg = json_format.MessageToJson(proto_msg, indent=None, preserving_proto_field_name=True) - logger.info(protoTOJson_msg) - # cls.publisher_Flight_Information.publish(protoTOJson_msg) - # cls.rate.sleep() - elif dataProto.topic == cls.Fly_Formation_topicToMqtt: - proto_msg = cls.fly_formation_msg.FromString(dataProto.payload) - protoTOJson_msg = json_format.MessageToJson(proto_msg, indent=None, preserving_proto_field_name=True) - # protoTOJson_msg = json_format.MessageToJson(proto_msg, indent=None, preserving_proto_field_name=True, use_integers_for_enums=True) - logger.info(protoTOJson_msg) - # cls.publisher_Fly_Formation.publish(protoTOJson_msg) - # cls.rate.sleep() - else: - logger.info("topic not found") - - - @staticmethod - def on_message(client, userdata, msg): - Proto_msg_to_ros.ros_pub(msg) + def on_message_Flight_Information(cls, client, userdata, msg): + proto_msg = cls.flight_information_msg.FromString(msg.payload) + protoTOJson_msg = json_format.MessageToJson(proto_msg, indent=None, preserving_proto_field_name=True) + logger.info(protoTOJson_msg) + # cls.publisher_Flight_Information.publish(protoTOJson_msg) + # cls.rate.sleep() + + @classmethod + def on_message_Fly_Formation(cls, client, userdata, msg): + proto_msg = cls.fly_formation_msg.FromString(msg.payload) + protoTOJson_msg = json_format.MessageToJson(proto_msg, indent=None, preserving_proto_field_name=True) + # protoTOJson_msg = json_format.MessageToJson(proto_msg, indent=None, preserving_proto_field_name=True, use_integers_for_enums=True) + logger.info(protoTOJson_msg) + # cls.publisher_Fly_Formation.publish(protoTOJson_msg) + # cls.rate.sleep() + class Json_msg_to_ros: @@ -59,19 +53,17 @@ class Json_msg_to_ros: Fly_Formation_topicToMqtt = None @classmethod - def ros_pub(cls, dataJson): - if dataJson.topic == cls.Flight_Information_topicToMqtt: - logger.info(dataJson.payload.decode("UTF-8")) - # cls.publisher_Flight_Information.publish(dataJson.payload.decode("UTF-8")) - # cls.rate.sleep() - elif dataJson.topic == cls.Fly_Formation_topicToMqtt: - logger.info(dataJson.payload.decode("UTF-8")) - # cls.publisher_Fly_Formation.publish(dataJson.payload.decode("UTF-8")) - # cls.rate.sleep() - else: - logger.info("topic not found") - + def on_message_Flight_Information(cls, client, userdata, msg): + logger.info(msg.payload.decode("UTF-8")) + # cls.publisher_Flight_Information.publish(dataJson.payload.decode("UTF-8")) + #cls.rate.sleep() + + @classmethod + def on_message_Fly_Formation(cls, client, userdata, msg): + logger.info(msg.payload.decode("UTF-8")) + # cls.publisher_Fly_Formation.publish(dataJson.payload.decode("UTF-8")) + # cls.rate.sleep() + + + - @staticmethod - def on_message(client, userdata, msg): - Json_msg_to_ros.ros_pub(msg) \ No newline at end of file