Example #1
0
        public object Clone()
        {
            RobotCommand rc = new RobotCommand();

            rc.CMD       = this.CMD;
            rc.ValueA    = this.ValueA;
            rc.ValueL    = this.ValueL;
            rc.Timestamp = this.Timestamp;
            rc.Status    = this.Status;
            rc.Positions = this.Positions;
            return(rc);
        }
Example #2
0
        public void HandleRequest()
        {
            StreamReader sr = new StreamReader(client.GetStream());
            StreamWriter sw = new StreamWriter(client.GetStream());

            try
            {
                string command = "";
                command += sr.ReadLine();
                sr.Close();
                string[] scommand = command.Split(' ');

                RobotCommand rcmd = new RobotCommand();
                rcmd.CMD = (Command)Enum.Parse(typeof(Command), scommand[0], true);
                switch (rcmd.CMD)
                {
                case Command.TrackLine:
                    rcmd.ValueL = Convert.ToDouble(scommand[1]);
                    break;

                case Command.TrackTurnLeft:
                case Command.TrackTurnRight:
                    rcmd.ValueA = Convert.ToInt32(scommand[1]);
                    break;

                case Command.TrackArcLeft:
                case Command.TrackArcRight:
                    rcmd.ValueA = Convert.ToInt32(scommand[1]);
                    rcmd.ValueL = Convert.ToDouble(scommand[2]);
                    break;

                case Command.Start:
                    RobotExecutor re = new RobotExecutor(AppData.CommandList.Clone());
                    AppData.CommandList = new List <RobotCommand>();
                    new Thread(re.Start).Start();
                    break;

                default:
                    break;
                }

                Console.WriteLine(command);

                lock (locker)
                {
                    if (rcmd.CMD != Command.Start)
                    {
                        AppData.CommandList.Add(rcmd);
                    }
                }
                sw.WriteLine("OK");
                sw.Flush();
                sw.Close();
            }
            catch (Exception e)
            {
            }
            finally
            {
                client.Close();
            }
        }