Exemplo n.º 1
0
        private void ExecuteCommand(Command cmd)
        {
            StreamWriter writer = null;
            try
            {
                String path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase), "htdocs");
                path = Path.Combine(path, "drive.txt");
                writer = File.AppendText(path);

                Drive drive = World.Robot.drv;
                MethodInfo methodInfo = drive.GetType().GetMethod(cmd.Method, cmd.GetTypes().ToArray());
                if (methodInfo != null && methodInfo.GetCustomAttributes(typeof(RunMethod), false).Length == 1)
                {
                    methodInfo.Invoke(drive, cmd.GetValues().ToArray());
                    while (!drive.Done) { Thread.Sleep(20); }
                    writer.WriteLine(cmd.ToString());
                }
                else
                {
                    Console.WriteLine("could not interpret command");
                }
            }
            finally
            {
                if (writer != null)
                {
                    writer.Flush();
                    writer.Close();
                }
            }
        }
Exemplo n.º 2
0
        public void CommandTest()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Command));
            StringWriter stringWriter = new StringWriter();
            XmlWriter xmlWriter = XmlWriter.Create(stringWriter);
            Command cmd = new Command(); // TODO: Initialize to an appropriate value
            cmd.Method = "RunLine";//RunLine(float length, float speed, float acceleration)
            cmd.Parameters.Add(1.0f);
            cmd.Parameters.Add(1.0f);
            cmd.Parameters.Add(1.0f);

            serializer.Serialize(xmlWriter, cmd);
            xmlWriter.Flush();

            Debug.WriteLine(stringWriter.ToString());

            //XmlSerializer serializer = new XmlSerializer(typeof(Command));
            StringReader stringReader = new StringReader(stringWriter.ToString());
            XmlReader xmlReader = XmlReader.Create(stringReader);
            if (serializer.CanDeserialize(xmlReader))
            {
                object o = serializer.Deserialize(xmlReader);
                if (o is Command)
                {
                    Command cmdDeserialized = (Command)o;
                    Debug.WriteLine(cmdDeserialized.ToString());
                }
            }
        }
Exemplo n.º 3
0
        public void InterpretCommandTest()
        {
            RunMode actualMode = Constants.IsWinCE ? RunMode.Real : RunMode.Virtual;
            Drive drv = new Drive(actualMode);
            Robot r = new Robot(actualMode);
            World.Robot = r;

            Interpreter interpreter = new Interpreter();
            //Interpreter_Accessor target = new Interpreter_Accessor(); // TODO: Initialize to an appropriate value
            Command cmd = new Command(); // TODO: Initialize to an appropriate value
            cmd.Method = "RunLine";//RunLine(float length, float speed, float acceleration)
            //cmd.Parameters.Add(new CommandParam() { Type = typeof(float), Parameter = 1 });
            //cmd.Parameters.Add(new CommandParam() { Type = typeof(float), Parameter = 1 });
            //cmd.Parameters.Add(new CommandParam() { Type = typeof(float), Parameter = 1 });
            ////cmd.Parameters.Add(new CommandParam() { Type = typeof(float), Parameter = 1 });

            //interpreter.InterpretCommand(cmd);

            //target.InterpretCommand(cmd);

            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }