From 1743846f315fbf43ffde6a9d9989575e4ef981d0 Mon Sep 17 00:00:00 2001 From: RangeOfGlitching Date: Sun, 4 Dec 2022 23:55:03 +0800 Subject: [PATCH] proto msg example --- Stream/uav_proto_msg/protomsg/protoMsg.py | 92 +++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 Stream/uav_proto_msg/protomsg/protoMsg.py diff --git a/Stream/uav_proto_msg/protomsg/protoMsg.py b/Stream/uav_proto_msg/protomsg/protoMsg.py new file mode 100644 index 0000000..8502593 --- /dev/null +++ b/Stream/uav_proto_msg/protomsg/protoMsg.py @@ -0,0 +1,92 @@ +import proto.flyformatioln_pb2 as flyformatioln_pb2 +import proto.flight_information_pb2 as flight_information_pb2 +import proto.imu_pb2 as imu_pb2 +import proto.odom_pb2 as odom_pb2 +import proto.duration_pb2 as duration_pb2 +import proto.flymode_pb2 as flymode_pb2 +import proto.timestamp_pb2 as timestamp_pb2 +import google.protobuf.json_format as json_format + + +class protoMsgWrapper: + + @staticmethod + def flight_information(serialized=False, tojson=False): + flight_information_msg = flight_information_pb2.flight_information_message() + flight_information_msg.gps.LAT = 34123.1231515 + flight_information_msg.gps.LON = 23423.1231515 + flight_information_msg.gps.ALT = 12123.1231515 + flight_information_msg.heading = 155.12215 + if serialized: + return flight_information_msg.SerializeToString() + if tojson: + return json_format.MessageToJson(flight_information_msg, indent=None, preserving_proto_field_name=True) + return flight_information_msg + + @staticmethod + def fly_formation(serialized=False, tojson=False): + fly_formation_msg = flyformatioln_pb2.fly_formation_message() + fly_formation_msg.velocity = 128 + fly_formation_msg.fly_formation = flyformatioln_pb2.FLY_FORMATION_v + if serialized: + return fly_formation_msg.SerializeToString() + if tojson: + return json_format.MessageToJson(fly_formation_msg, indent=None, preserving_proto_field_name=True) + return fly_formation_msg + + @staticmethod + def imu_information(serialized=False, tojson=False): + imu_information_msg = imu_pb2.IMU_message() + imu_information_msg.IMU_Gyro_msg.Gyro_x = 1.0 + imu_information_msg.IMU_Gyro_msg.Gyro_y = 2.0 + imu_information_msg.IMU_Gyro_msg.Gyro_z = 3.0 + imu_information_msg.IMU_Accel_msg.Accel_x = 4.0 + imu_information_msg.IMU_Accel_msg.Accel_y = 5.0 + imu_information_msg.IMU_Accel_msg.Accel_z = 6.0 + if serialized: + return imu_information_msg.SerializeToString() + if tojson: + return json_format.MessageToJson(imu_information_msg, indent=None, preserving_proto_field_name=True) + return imu_information_msg + + @staticmethod + def odom_information(serialized=False, tojson=False): + odom_information_msg = odom_pb2.odem_message() + odom_information_msg.odem_msg.ODOM_x = 1.0 + odom_information_msg.odem_msg.ODOM_y = 2.0 + odom_information_msg.odem_msg.ODOM_z = 3.0 + if serialized: + return odom_information_msg.SerializeToString() + if tojson: + return json_format.MessageToJson(odom_information_msg, indent=None, preserving_proto_field_name=True) + return odom_information_msg + + @staticmethod + def flymode_information(serialized=False, tojson=False): + flymode_information_msg = flymode_pb2.flymode_message() + flymode_information_msg.fly_mode_msg = flymode_pb2.FLY_MODE_STABILIZE + if serialized: + return flymode_information_msg.SerializeToString() + if tojson: + return json_format.MessageToJson(flymode_information_msg, indent=None, preserving_proto_field_name=True) + return flymode_information_msg + + @staticmethod + def duration_information(serialized=False, tojson=False): + duration_information_msg = duration_pb2.Duration() + duration_information_msg.FromNanoseconds(1000000) + if serialized: + return duration_information_msg.SerializeToString() + if tojson: + return json_format.MessageToJson(duration_information_msg, indent=None, preserving_proto_field_name=True) + return duration_information_msg + + @staticmethod + def timestamp_information(serialized=False, tojson=False): + timestamp_meg = timestamp_pb2.Timestamp() + timestamp_meg.GetCurrentTime() + if serialized: + return timestamp_meg.SerializeToString() + if tojson: + return json_format.MessageToJson(timestamp_meg, indent=None, preserving_proto_field_name=True) + return timestamp_meg \ No newline at end of file