Ejemplo n.º 1
0
        public void TestTransformStampedMessage()
        {
            Assert.True(BuiltIns.GetMessageType <MyTransformStamped>() == MyTransformStamped.RosMessageType);
            Assert.True(BuiltIns.GetMd5Sum <MyTransformStamped>() == BuiltIns.GetMd5Sum <TransformStamped>());

            time             now  = time.Now();
            TransformStamped real = new TransformStamped()
            {
                Header       = new Header(1, now, "Frame"),
                ChildFrameId = "Abcd",
                Transform    = Transform.Identity
            };

            MyTransformStamped wrapped = new MyTransformStamped()
            {
                Header       = new Header(1, now, "Frame"),
                ChildFrameId = "Abcd",
                Transform    = Transform.Identity
            };

            byte[] messageBytes      = real.SerializeToArray();
            byte[] otherMessageBytes = wrapped.SerializeToArray();

            Assert.True(messageBytes.SequenceEqual(otherMessageBytes));

            var otherWrapped = wrapped.DeserializeFromArray(messageBytes);

            Assert.True(wrapped.Header == real.Header);
            Assert.True(wrapped.ChildFrameId == real.ChildFrameId);
            Assert.True(wrapped.Transform == real.Transform);
        }
Ejemplo n.º 2
0
 public TopicInfo(string callerId, string topic, IDeserializable <T> generator)
     : this(
         BuiltIns.DecompressDependencies(generator.GetType()),
         callerId, topic,
         BuiltIns.GetMd5Sum(generator.GetType()),
         BuiltIns.GetMessageType(generator.GetType()),
         generator
         )
 {
 }
Ejemplo n.º 3
0
 public TopicInfo(string callerId, string topic)
     : this(
         BuiltIns.DecompressDependencies <T>(),
         callerId, topic,
         BuiltIns.GetMd5Sum <T>(),
         BuiltIns.GetMessageType <T>(),
         null
         )
 {
 }
Ejemplo n.º 4
0
        public Sender([NotNull] string topic)
        {
            if (string.IsNullOrWhiteSpace(topic))
            {
                throw new ArgumentException("Invalid topic!", nameof(topic));
            }

            Topic = topic;
            Type  = BuiltIns.GetMessageType(typeof(T));

            Logger.Info($"Advertising <b>{topic}</b> <i>[{Type}]</i>.");
            GameThread.EverySecond += UpdateStats;
            Connection.Advertise(this);
        }
Ejemplo n.º 5
0
        public void TestInteractiveMarkerMessage()
        {
            Assert.True(BuiltIns.GetMessageType(typeof(MyInteractiveMarker)) == MyInteractiveMarker.RosMessageType);
            Console.WriteLine(MyInteractiveMarker.RosDefinition);
            Assert.True(
                BuiltIns.GetMd5Sum(typeof(MyInteractiveMarker)) == BuiltIns.GetMd5Sum(typeof(InteractiveMarker)));

            time now  = time.Now();
            var  real = new InteractiveMarker()
            {
                Pose        = Pose.Identity,
                Name        = "Abcd",
                Description = "Efgh",
                MenuEntries = new MenuEntry[] { new(), new() },
Ejemplo n.º 6
0
        public RosSerializableDefinition()
        {
            try
            {
                RosType = typeof(IMessage).IsAssignableFrom(typeof(T))
                    ? BuiltIns.GetMessageType(typeof(T))
                    : "";
            }
            catch (RosInvalidMessageException)
            {
                throw new RosIncompleteWrapperException(
                          $"Type '{typeof(T).Name}' must have a string constant named RosMessageType. " +
                          "It should also be tagged with the attribute [MessageName].");
            }

            var bi = new BuilderInfo();

            foreach (var field in typeof(T).GetFields())
            {
                if (field.IsStatic && field.IsLiteral && !field.IsInitOnly &&
                    RosWrapperBase.BuiltInNames.TryGetValue(field.FieldType, out string?fieldType) &&
                    field.GetCustomAttribute <MessageNameAttribute>() == null)
                {
                    InitializeConstant(bi, field, fieldType);
                }
            }

            foreach (var property in typeof(T).GetProperties())
            {
                if (property.GetSetMethod() == null &&
                    !(property.GetType().IsGenericType&&
                      property.GetType().GetGenericTypeDefinition() != typeof(List <>)))
                {
                    continue;
                }

                if (property.GetGetMethod() == null ||
                    property.GetCustomAttribute <IgnoreDataMemberAttribute>() != null)
                {
                    continue;
                }

                Type propertyType = property.PropertyType;
                if (Initializers.TryGetValue(propertyType, out var initializer))
                {
                    initializer(property, bi);
                }
                else if (propertyType.IsArray)
                {
                    var elementType = propertyType.GetElementType() !;
                    if (elementType.IsEnum)
                    {
                        InitializeEnumArrayProperty(property, bi);
                    }
                    else if (typeof(IMessage).IsAssignableFrom(elementType))
                    {
                        InitializeMessageArrayProperty(property, bi);
                    }
                }
                else if (propertyType.IsEnum)
                {
                    InitializeEnumProperty(property, bi);
                }
                else if (typeof(IMessage).IsAssignableFrom(propertyType))
                {
                    InitializeMessageProperty(property, bi);
                }
            }

            RosDefinition = bi.RosDefinition.ToString();

            messageFields = bi.Fields.ToArray();

            (RosInputForMd5, RosMessageMd5) = CreateMd5(bi);

            RosDependencies = CreateDependencies(RosDefinition);
        }