protected virtual string ResolveFullQualifiedTypeName(RosTypeInfo type, bool useInterface) { string typeString; if (type.IsBuiltInType) { var typeMapper = BuiltInTypeMapping.Create(type); typeString = typeMapper.Type.ToString(); } else { var rosPackageName = type.PackageName ?? _packageName; var rosTypeName = type.TypeName; typeString = ResolveFullQualifiedTypeName(rosPackageName, rosTypeName); } if (type.IsArray) { if (useInterface) { typeString = $"System.Collections.Generic.IList<{typeString}>"; } else { typeString = $"System.Collections.Generic.List<{typeString}>"; } } return(typeString); }
public void Can_parse_rosbag_with_nested_message() { var input = @"byte DEBUG=1 byte INFO=2 byte WARN=4 byte ERROR=8 byte FATAL=16 Header header byte level string name string msg string file string function uint32 line string[] topics ================================================================================ MSG: std_msgs/Header uint32 seq time stamp string frame_id"; var actual = new RosbagMessageDefinitionParser(input).Parse(); Assert.NotNull(actual); Assert.NotNull(actual.Message); Assert.Single(actual.NestedMessages); var nestedMessage = actual.NestedMessages[RosTypeInfo.CreateRosType("std_msgs", "Header")]; Assert.NotNull(nestedMessage); Assert.False(nestedMessage.IsEmpty); }
public override void OnVisitRosType(RosTypeInfo typeInfo) { if (typeInfo.HasPackage && !_ignoredPackages.Contains(typeInfo.PackageName)) { _dependencies.Add(typeInfo); } }
public FieldTypeTemplateData(string interfaceName, string concreteName, RosTypeInfo typeInfo) { InterfaceName = interfaceName; ConcreteName = concreteName; TypeInfo = typeInfo; }
private void ParseMessagesInternal() { var packageDependencyCollector = new PackageDependencyCollector(new [] { Package.Name }); var typeDependencyCollector = new TypeDependencyCollector(new [] { Package.Name }); var collectors = new RosMessageVisitorListenerCollection(new IRosMessageVisitorListener[] { packageDependencyCollector, typeDependencyCollector }); var messages = new List <KeyValuePair <RosTypeInfo, MessageDescriptor> >(); var actions = new List <KeyValuePair <RosTypeInfo, ActionDescriptor> >(); var services = new List <KeyValuePair <RosTypeInfo, ServiceDescriptor> >(); foreach (var messageFile in Package.Messages) { using (var fileStream = File.OpenRead(messageFile.FullName)) { var rosType = RosTypeInfo.CreateRosType(Package.Name, messageFile.NameWithoutExtension()); switch (messageFile.GetRosMessageType()) { case RosMessageType.Message: var messageParser = new RobSharper.Ros.MessageParser.MessageParser(fileStream); var messageDescriptor = messageParser.Parse(collectors); messages.Add( new KeyValuePair <RosTypeInfo, MessageDescriptor>(rosType, messageDescriptor)); break; case RosMessageType.Service: var serviceParser = new ServiceParser(fileStream); var serviceDescriptor = serviceParser.Parse(collectors); services.Add( new KeyValuePair <RosTypeInfo, ServiceDescriptor>(rosType, serviceDescriptor)); break; case RosMessageType.Action: var actionParser = new ActionParser(fileStream); var actionDescriptor = actionParser.Parse(collectors); actions.Add( new KeyValuePair <RosTypeInfo, ActionDescriptor>(rosType, actionDescriptor)); break; } } } // Add actionlib dependency if (actions.Any() && !packageDependencyCollector.Dependencies.Contains("actionlib_msgs")) { packageDependencyCollector.Dependencies.Add("actionlib_msgs"); } _packageDependencies = packageDependencyCollector.Dependencies; _externalTypeDependencies = typeDependencyCollector.Dependencies; _messages = messages; _actions = actions; _services = services; }
protected virtual void CreateAction(RosTypeInfo rosType, ActionDescriptor action) { WriteActionInternal(rosType); WriteMessageInternal(rosType, DetailedRosMessageType.ActionGoal, action.Goal); WriteMessageInternal(rosType, DetailedRosMessageType.ActionResult, action.Result); WriteMessageInternal(rosType, DetailedRosMessageType.ActionFeedback, action.Feedback); }
private void WriteActionInternal(RosTypeInfo actionType) { if (!GenerateActionFile) { return; } throw new NotSupportedException("No need for this until now"); }
public virtual bool IsBuiltInType(RosTypeInfo rosType) { if (rosType == null) { throw new ArgumentNullException(nameof(rosType)); } return(rosType.IsBuiltInType); }
public override bool IsBuiltInType(RosTypeInfo rosType) { var builtIn = base.IsBuiltInType(rosType); if (builtIn) { return(true); } // Uml.Robotics.ROS has more types already defined in its libraries (e.g. Header) return(SpecialRosTypeMappings.ContainsKey(rosType.ToString())); }
protected virtual void CreateService(RosTypeInfo rosType, ServiceDescriptor service) { if (NameMapper.IsBuiltInType(rosType)) { return; } WriteServiceInternal(rosType); WriteMessageInternal(rosType, DetailedRosMessageType.ServiceRequest, service.Request); WriteMessageInternal(rosType, DetailedRosMessageType.ServiceResponse, service.Response); }
private void WriteServiceInternal(RosTypeInfo serviceType) { if (!GenerateServiceFile) { return; } var data = GetServiceTemplateData(serviceType); var filePath = _directories.TempDirectory.GetFilePath($"{data.ServiceType.TypeName}.cs"); var content = _templateEngine.Format(ServiceTemplateFile, data); WriteFile(filePath, content); }
public override string ResolveNugetPackageName(RosTypeInfo rosType) { if (rosType == null) { throw new ArgumentNullException(nameof(rosType)); } if (TryGetTypeMapping(rosType.PackageName, rosType.TypeName, out var mapping)) { return(mapping.NugetPackageName); } return(base.ResolveNugetPackageName(rosType)); }
protected virtual MessageTemplateData GetMessageTemplateData(RosTypeInfo rosType, DetailedRosMessageType messageType, MessageDescriptor message) { var fields = message.Fields .Select(x => new FieldTemplateData { Index = message.Items .Select((item, index) => new { Item = item, Index = index }) .First(f => f.Item == x) .Index + 1, // Index of this field in serialized message (starting at 1) RosType = x.TypeInfo, RosIdentifier = x.Identifier, Type = new FieldTypeTemplateData(NameMapper.ResolveFullQualifiedInterfaceName(x.TypeInfo), NameMapper.ResolveFullQualifiedTypeName(x.TypeInfo), x.TypeInfo) , Identifier = NameMapper.GetFieldName(x.Identifier) }) .ToList(); var constants = message.Constants .Select(c => new ConstantTemplateData { Index = message.Items .Select((item, index) => new { item, index }) .First(x => x.item == c) .index + 1, RosType = c.TypeInfo, RosIdentifier = c.Identifier, TypeName = NameMapper.ResolveFullQualifiedTypeName(c.TypeInfo), Identifier = NameMapper.GetConstantName(c.Identifier), Value = c.Value }) .ToList(); var data = new MessageTemplateData { Package = PackageTemplateData, RosTypeName = NameMapper.GetRosTypeName(rosType.TypeName, messageType), RosAbstractTypeName = rosType.TypeName, TypeName = NameMapper.GetTypeName(rosType.TypeName, messageType), AbstractTypeName = NameMapper.GetTypeName(rosType.TypeName, DetailedRosMessageType.None), Fields = fields, Constants = constants, MessageType = new MessageTypeTemplateData(messageType) }; return(data); }
public void OnVisitRosType_called_in_constant_decalaration_for_external_type() { var message = $"std_msgs/Bool CONST = True"; var expectedTypeDescriptor = RosTypeInfo.CreateRosType("std_msgs", "Bool"); var messageParser = ParserHelper.CreateParserForMessage(message); var context = messageParser.ros_message(); var mock = new Mock <IRosMessageVisitorListener>(); var visitor = new RosMessageVisitor(mock.Object); visitor.Visit(context); mock.Verify(x => x.OnVisitRosType(expectedTypeDescriptor)); }
public void OnVisitBuiltInType_called_infield_declaration(string dataType) { var message = $"{dataType} fieldName"; var expectedBuiltInType = RosTypeInfo.CreateBuiltIn(dataType);; var messageParser = ParserHelper.CreateParserForMessage(message); var context = messageParser.ros_message(); var mock = new Mock <IRosMessageVisitorListener>(); var visitor = new RosMessageVisitor(mock.Object); visitor.Visit(context); mock.Verify(x => x.OnVisitBuiltInType(expectedBuiltInType)); }
public void OnVisitBuiltInType_called_in_constant_declaration(string dataType, object value) { var message = $"{dataType} CONST = {value}"; var expectedPrimitiveType = RosTypeInfo.CreateBuiltIn(dataType); var messageParser = ParserHelper.CreateParserForMessage(message); var context = messageParser.ros_message(); var mock = new Mock <IRosMessageVisitorListener>(); var visitor = new RosMessageVisitor(mock.Object); visitor.Visit(context); mock.Verify(x => x.OnVisitBuiltInType(expectedPrimitiveType)); }
public void OnVisitRosType_called_in_field_decalaration_for_header_type() { var message = $"Header fieldName"; var expectedTypeDescriptor = RosTypeInfo.CreateRosType("std_msgs", "Header"); var messageParser = ParserHelper.CreateParserForMessage(message); var context = messageParser.ros_message(); var mock = new Mock <IRosMessageVisitorListener>(); var visitor = new RosMessageVisitor(mock.Object); visitor.Visit(context); mock.Verify(x => x.OnVisitRosType(expectedTypeDescriptor)); }
public static bool IsType(this RosTypeInfo rosType, Type expectedType) { if (rosType.IsArray || !rosType.IsBuiltInType) { return(false); } try { var typeMapper = BuiltInTypeMapping.Create(rosType); return(typeMapper.Type == expectedType); } catch (NotSupportedException) { return(false); } }
public static bool IsValueType(this RosTypeInfo type) { if (type.IsArray || !type.IsBuiltInType) { return(false); } try { var typeMapper = BuiltInTypeMapping.Create(type); return(typeMapper.Type.IsValueType); } catch (NotSupportedException) { return(false); } }
public static bool SupportsEqualityComparer(this RosTypeInfo type) { if (type.IsArray || !type.IsBuiltInType) { return(false); } try { var typeMapper = BuiltInTypeMapping.Create(type); return(typeMapper.Type == typeof(string) || (typeMapper.Type != typeof(double) && typeMapper.Type != typeof(float))); } catch (NotSupportedException) { return(false); } }
private void WriteMessageInternal(RosTypeInfo rosType, DetailedRosMessageType messageType, MessageDescriptor message) { if (messageType == DetailedRosMessageType.None || messageType == DetailedRosMessageType.Action || messageType == DetailedRosMessageType.Service) { throw new ArgumentException($"message type is not detailed enough", nameof(messageType)); } if (NameMapper.IsBuiltInType(rosType)) { return; } var data = GetMessageTemplateData(rosType, messageType, message); SanitizeMessageTemplateData(data); var filePath = _directories.TempDirectory.GetFilePath($"{data.TypeName}.cs"); var content = _templateEngine.Format(MessageTemplateFile, data); WriteFile(filePath, content); }
protected virtual ServiceTemplateData GetServiceTemplateData(RosTypeInfo serviceType) { var data = new ServiceTemplateData { Package = PackageTemplateData, ServiceType = new ConcreteTypeTemplateData { RosTypeName = NameMapper.GetRosTypeName(serviceType.TypeName, DetailedRosMessageType.Service), TypeName = NameMapper.GetTypeName(serviceType.TypeName, DetailedRosMessageType.Service) }, RequestType = new ConcreteTypeTemplateData { RosTypeName = NameMapper.GetRosTypeName(serviceType.TypeName, DetailedRosMessageType.ServiceRequest), TypeName = NameMapper.GetTypeName(serviceType.TypeName, DetailedRosMessageType.ServiceRequest) }, ResponseType = new ConcreteTypeTemplateData { RosTypeName = NameMapper.GetRosTypeName(serviceType.TypeName, DetailedRosMessageType.ServiceResponse), TypeName = NameMapper.GetTypeName(serviceType.TypeName, DetailedRosMessageType.ServiceResponse) } }; return(data); }
public virtual void OnVisitArrayType(RosTypeInfo typeInfo) { }
public virtual string ResolveNugetPackageName(RosTypeInfo rosType) { return(ResolveNugetPackageName(rosType.PackageName)); }
public void Can_parse_rosbag_with_multiple_nested_messages() { var input = @"# ====== DO NOT MODIFY! AUTOGENERATED FROM AN ACTION DEFINITION ====== Header header actionlib_msgs/GoalStatus status MoveArmOnTrajectoryResult result ================================================================================ MSG: std_msgs/Header # Standard metadata for higher-level stamped data types. # This is generally used to communicate timestamped data # in a particular coordinate frame. # # sequence ID: consecutively increasing ID uint32 seq #Two-integer timestamp that is expressed as: # * stamp.sec: seconds (stamp_secs) since epoch (in Python the variable is called 'secs') # * stamp.nsec: nanoseconds since stamp_secs (in Python the variable is called 'nsecs') # time-handling sugar is provided by the client library time stamp #Frame this data is associated with # 0: no frame # 1: global frame string frame_id ================================================================================ MSG: actionlib_msgs/GoalStatus GoalID goal_id uint8 status uint8 PENDING = 0 # The goal has yet to be processed by the action server uint8 ACTIVE = 1 # The goal is currently being processed by the action server uint8 PREEMPTED = 2 # The goal received a cancel request after it started executing # and has since completed its execution (Terminal State) uint8 SUCCEEDED = 3 # The goal was achieved successfully by the action server (Terminal State) uint8 ABORTED = 4 # The goal was aborted during execution by the action server due # to some failure (Terminal State) uint8 REJECTED = 5 # The goal was rejected by the action server without being processed, # because the goal was unattainable or invalid (Terminal State) uint8 PREEMPTING = 6 # The goal received a cancel request after it started executing # and has not yet completed execution uint8 RECALLING = 7 # The goal received a cancel request before it started executing, # but the action server has not yet confirmed that the goal is canceled uint8 RECALLED = 8 # The goal received a cancel request before it started executing # and was successfully cancelled (Terminal State) uint8 LOST = 9 # An action client can determine that a goal is LOST. This should not be # sent over the wire by an action server #Allow for the user to associate a string with GoalStatus for debugging string text ================================================================================ MSG: actionlib_msgs/GoalID # The stamp should store the time at which this goal was requested. # It is used by an action server when it tries to preempt all # goals that were requested before a certain time time stamp # The id provides a way to associate feedback and # result message with specific goal requests. The id # specified must be unique. string id ================================================================================ MSG: robot_msgs/MoveArmOnTrajectoryResult # ====== DO NOT MODIFY! AUTOGENERATED FROM AN ACTION DEFINITION ====== geometry_msgs/Pose resultPose string resultMessage ================================================================================ MSG: geometry_msgs/Pose # A representation of pose in free space, composed of position and orientation. Point position Quaternion orientation ================================================================================ MSG: geometry_msgs/Point # This contains the position of a point in free space float64 x float64 y float64 z ================================================================================ MSG: geometry_msgs/Quaternion # This represents an orientation in free space in quaternion form. float64 x float64 y float64 z float64 w"; var actual = new RosbagMessageDefinitionParser(input).Parse(); Assert.NotNull(actual); Assert.NotNull(actual.Message); Assert.Equal(7, actual.NestedMessages.Count); Assert.True(actual.NestedMessages.ContainsKey(RosTypeInfo.CreateRosType("std_msgs", "Header")), "Nested message std_msgs/Header not found"); Assert.True(actual.NestedMessages.ContainsKey(RosTypeInfo.CreateRosType("actionlib_msgs", "GoalStatus")), "Nested message actionlib_msgs/GoalStatus not found"); Assert.True(actual.NestedMessages.ContainsKey(RosTypeInfo.CreateRosType("actionlib_msgs", "GoalID")), "Nested message actionlib_msgs/GoalID not found"); Assert.True(actual.NestedMessages.ContainsKey(RosTypeInfo.CreateRosType("robot_msgs", "MoveArmOnTrajectoryResult")), "Nested message robot_msgs/MoveArmOnTrajectoryResult not found"); Assert.True(actual.NestedMessages.ContainsKey(RosTypeInfo.CreateRosType("geometry_msgs", "Pose")), "Nested message geometry_msgs/Pose not found"); Assert.True(actual.NestedMessages.ContainsKey(RosTypeInfo.CreateRosType("geometry_msgs", "Point")), "Nested message geometry_msgs/Point not found"); Assert.True(actual.NestedMessages.ContainsKey(RosTypeInfo.CreateRosType("geometry_msgs", "Quaternion")), "Nested message geometry_msgs/Quaternion not found"); }
public static bool IsType <TExpected>(this RosTypeInfo rosType) { return(IsType(rosType, typeof(TExpected))); }
public string ResolveFullQualifiedInterfaceName(RosTypeInfo type) { return(ResolveFullQualifiedTypeName(type, true)); }
public virtual void OnVisitBuiltInType(RosTypeInfo typeInfo) { }
public string ResolveFullQualifiedTypeName(RosTypeInfo type) { return(ResolveFullQualifiedTypeName(type, false)); }
protected virtual void CreateMessage(RosTypeInfo rosType, MessageDescriptor message) { WriteMessageInternal(rosType, DetailedRosMessageType.Message, message); }