Example #1
0
        public bool Connect(int port, string IP, short ID, string Logfile)
        {
            mLogFileName = Logfile;
            mID          = ID;
            mIP          = IP;
            mPort        = port;

            #region logger
            try
            {
                if (mLogger == null)
                {
                    // instantiate the logger
                    mLogger = Logger.Logger.Instance;

                    // instantiate the log observer that will write to disk
                    mFileLogger = new FileLogger(this.mLogFileName);
                    mFileLogger.Init();

                    // Add mFileLogger to the Logger.
                    mLogger.RegisterObserver(mFileLogger);
                    mLogger.AddLogMessage("******* NEW RUN OF THE AGENT! *******");
                }
            }
            catch (Exception)
            {
                Clean();
                return(false);
            }
            #endregion logger

            #region Communication
            try
            {
                IPAddress ipAddress = IPAddress.Parse(mIP);
                mComm.Init(mID, ipAddress, mPort);
                mComm.SendMessage(Command.Login, mID.ToString());
                mComm.Listen();
            }
            catch (Exception ex)
            {
                mLogger.AddLogMessage("Communication Init: " + ex.Message);
                if (mLogger != null)
                {
                    mFileLogger.Terminate();
                }
                return(false);
            }
            #endregion Communication

            // connection established successfully
            AHStateManager(GameState.Idle);

            return(true);
        }
Example #2
0
 public override void MotionGuidance()
 {
     while (internalState == ModuleState.Active)
     {
         communicator.SendMessage(Command.Message, DoubleToString(commandsQueue.GetNext(QueueType.Velocity)));
         Thread.Sleep(Ts);
     }
 }