Ejemplo n.º 1
0
        public static List <string> GenerateSingleAction(string inPath, string outPath, string rosPackageName = "", bool verbose = false)
        {
            // If no ROS package name is provided, extract from path
            if (rosPackageName.Equals(""))
            {
                string[] hierarchy = inPath.Split(new char[] { '/', '\\' });
                rosPackageName = hierarchy[hierarchy.Length - 3];
            }

            outPath = Path.Combine(outPath, MsgAutoGenUtilities.ResolvePackageName(rosPackageName));

            string inFileName = Path.GetFileNameWithoutExtension(inPath);

            if (verbose)
            {
                Console.WriteLine("Parsing: " + inPath);
                Console.WriteLine("Output Location: " + outPath);
            }

            MessageTokenizer            tokenizer     = new MessageTokenizer(inPath, new HashSet <string>(MsgAutoGenUtilities.builtInTypesMapping.Keys));
            List <List <MessageToken> > listsOfTokens = tokenizer.Tokenize();

            if (listsOfTokens.Count != 3)
            {
                throw new MessageParserException("Unexpected number of sections. Action should have 3 sections.");
            }

            List <string> warnings = new List <string>();

            ActionWrapper actionWrapper = new ActionWrapper(inPath, rosPackageName, outPath);

            for (int i = 0; i < listsOfTokens.Count; i++)
            {
                List <MessageToken> tokens = listsOfTokens[i];

                // Action is made up of goal, result, feedback
                string className = inFileName + types[i];

                // Parse and generate goal, result, feedback messages
                MessageParser parser = new MessageParser(tokens, outPath, rosPackageName, "action", MsgAutoGenUtilities.builtInTypesMapping, MsgAutoGenUtilities.builtInTypesDefaultInitialValues, MsgAutoGenUtilities.numericTypeDeserializationFunctions, MsgAutoGenUtilities.numericTypeByteSize, className);
                parser.Parse();
                warnings.AddRange(parser.GetWarnings());

                // Generate action section wrapper messages
                actionWrapper.WrapActionSections(types[i]);
            }

            // Generate action wrapper
            actionWrapper.WrapAction();

            return(warnings);
        }
Ejemplo n.º 2
0
        public static List <string> GenerateSingleService(string inPath, string outPath, string rosPackageName = "", bool verbose = false)
        {
            // If no ROS package name is provided, extract from path
            if (rosPackageName.Equals(""))
            {
                string[] hierarchy = inPath.Split(new char[] { '/', '\\' });
                rosPackageName = hierarchy[hierarchy.Length - 3];
            }

            outPath = Path.Combine(outPath, MsgAutoGenUtilities.ResolvePackageName(rosPackageName));

            string inFileName = Path.GetFileNameWithoutExtension(inPath);

            if (verbose)
            {
                Console.WriteLine("Parsing: " + inPath);
                Console.WriteLine("Output Location: " + outPath);
            }

            MessageTokenizer            tokenizer     = new MessageTokenizer(inPath, new HashSet <string>(MsgAutoGenUtilities.builtInTypesMapping.Keys));
            List <List <MessageToken> > listsOfTokens = tokenizer.Tokenize();

            if (listsOfTokens.Count != 2)
            {
                throw new MessageParserException("Unexpected number of sections. Service should have 2 sections.");
            }

            List <string> warnings = new List <string>();

            for (int i = 0; i < listsOfTokens.Count; i++)
            {
                List <MessageToken> tokens = listsOfTokens[i];

                // Service is made up of request and response
                string className = inFileName + MsgAutoGenUtilities.ServiceClassSuffix + types[i];

                MessageParser parser = new MessageParser(
                    tokens,
                    outPath,
                    rosPackageName,
                    "srv",
                    MsgAutoGenUtilities.builtInTypesMapping,
                    MsgAutoGenUtilities.builtInTypesDefaultInitialValues,
                    className,
                    subtopic: i == 0 ? MessageSubtopic.Default : MessageSubtopic.Response);
                parser.Parse();
                warnings.AddRange(parser.GetWarnings());
            }
            return(warnings);
        }
Ejemplo n.º 3
0
        public static List <string> GenerateSingleMessage(string inPath, string outPath, string rosPackageName = "", bool verbose = false)
        {
            // If no ROS package name is provided, extract from path
            if (rosPackageName == "")
            {
                rosPackageName = GetRosPackageName(inPath);
            }
            outPath = GetMessageOutFolder(outPath, rosPackageName);

            string inFileName = Path.GetFileNameWithoutExtension(inPath);

            if (MsgAutoGenUtilities.HasHandwrittenMessage(rosPackageName, inFileName))
            {
                // don't generate! we have a handwritten message for this one
                if (verbose)
                {
                    Console.WriteLine(inFileName + " will not be generated");
                }
                return(new List <string>());
            }
            else
            {
                if (verbose)
                {
                    Console.WriteLine("Parsing: " + inPath);
                    Console.WriteLine("Output Location: " + outPath);
                }

                MessageTokenizer            tokenizer    = new MessageTokenizer(inPath, new HashSet <string>(MsgAutoGenUtilities.builtInTypesMapping.Keys));
                List <List <MessageToken> > listOfTokens = tokenizer.Tokenize();

                if (listOfTokens.Count != 1)
                {
                    throw new MessageParserException("Unexpected number of sections. Simple message should have 1 section.");
                }

                MessageParser parser = new MessageParser(listOfTokens[0], outPath, rosPackageName, "msg", MsgAutoGenUtilities.builtInTypesMapping, MsgAutoGenUtilities.builtInTypesDefaultInitialValues);
                parser.Parse();
                return(parser.GetWarnings());
            }
        }