Example #1
0
        public void NewHaltEventTest()
        {
            goalComs.SetStream(haltInputStream);
            INaoEvent result = NaoEventFactory.NewEvent(
                (byte)EventCode.Halt);

            Assert.IsInstanceOf(typeof(HaltEvent), result);
        }
Example #2
0
        public void NewPickupEventTest()
        {
            goalComs.SetStream(pickupInputStream);
            INaoEvent result = NaoEventFactory.NewEvent(
                (byte)EventCode.Pickup);

            Assert.IsInstanceOf(typeof(PickupEvent), result);
        }
Example #3
0
        public void NewGoToEventTest()
        {
            goalComs.SetStream(goToInputStream);
            INaoEvent result = NaoEventFactory.NewEvent(
                (byte)EventCode.GoTo);

            Assert.IsInstanceOf(typeof(GoToEvent), result);
        }
Example #4
0
        /// <summary>
        /// Attempts to read incoming data from the server.
        /// </summary>
        private void ReceiveData()
        {
            if (!Running)
            {
                return;
            }
            byte code = 0;

            try
            {
                code = communicationStream.ReadByte();
                if (!Running)
                {
                    return;
                }
                INaoEvent naoEvent = NaoEventFactory.NewEvent(code);
                EventQueue.Nao.Post(naoEvent);
            }
            catch (InvalidEventCodeException e)
            {
                Logger.Except(e);
                Logger.Log(this, "Invalid event code received: " + code);
                INaoEvent failureEvent = new FailureEvent(code);
                EventQueue.Goal.Post(failureEvent);
            }
            catch (Exception e)
            {
                if (e is InvalidOperationException || e is IOException)
                {
                    Logger.Log(this, "Communication stream got closed.");
                    communicationStream.Open = false;
                }
                else
                {
                    Logger.Log(this, "Unexpected exception occurred while processing incoming data: " + e);
                }
            }
        }
Example #5
0
 public void NewInvalidEventTest()
 {
     goalComs.SetStream(invalidInputStream);
     INaoEvent result = NaoEventFactory.NewEvent(
         invalidEventCode);
 }