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

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

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

            Assert.IsInstanceOf(typeof(GoToEvent), result);
        }
Beispiel #4
0
 /// <summary>
 /// Posts the selected event to the Nao event-queue.
 /// </summary>
 /// <param name="naoEvent">The selected event.</param>
 protected override void PostEvent(INaoEvent naoEvent)
 {
     base.PostEvent(naoEvent);
     if (NaoState.Instance.Connected)
         EventQueue.Nao.Post(naoEvent);
     else
         Logger.Log(this,
             "Cannot post " + naoEvent + ", NaoState is not connected to any Nao.");
 }
Beispiel #5
0
 /// <summary>
 /// Posts the selected event to the Goal event-queue.
 /// </summary>
 /// <param name="goalEvent">The event to post.</param>
 protected override void PostEvent(INaoEvent goalEvent)
 {
     base.PostEvent(goalEvent);
     if (GoalCommunicator.Instance.Running)
         EventQueue.Goal.Post(goalEvent);
     else
         Logger.Log(this,
             "Cannot post " + goalEvent +
             ", goal communicator is not connected to any server.");
 }
Beispiel #6
0
 /// <summary>
 /// Fires given event.
 /// </summary>
 /// <param name="e">An event.</param>
 private void FireEvent(INaoEvent e)
 {
     Logger.Log(this, "Firing: " + e);
     if (EventFiring != null)
     {
         EventFiring(e);
     }
     e.Fire();
     eventTimer.Restart();
     Logger.Log(this, "Event " + e + " finished firing.");
 }
Beispiel #7
0
 /// <summary>
 /// Posts the selected event to the Nao event-queue.
 /// </summary>
 /// <param name="naoEvent">The selected event.</param>
 protected override void PostEvent(INaoEvent naoEvent)
 {
     base.PostEvent(naoEvent);
     if (NaoState.Instance.Connected)
     {
         EventQueue.Nao.Post(naoEvent);
     }
     else
     {
         Logger.Log(this,
                    "Cannot post " + naoEvent + ", NaoState is not connected to any Nao.");
     }
 }
Beispiel #8
0
        /// <summary>
        /// Clears the queue and returns all events that were removed.
        /// </summary>
        /// <returns>List of events.</returns>
        public List <INaoEvent> ClearAndGet()
        {
            List <INaoEvent> events = new List <INaoEvent>();

            while (!q.IsEmpty())
            {
                INaoEvent e = NextEvent;
                if (e != null)
                {
                    events.Add(e);
                }
            }
            return(events);
        }
Beispiel #9
0
 /// <summary>
 /// Posts the selected event to the Goal event-queue.
 /// </summary>
 /// <param name="goalEvent">The event to post.</param>
 protected override void PostEvent(INaoEvent goalEvent)
 {
     base.PostEvent(goalEvent);
     if (GoalCommunicator.Instance.Running)
     {
         EventQueue.Goal.Post(goalEvent);
     }
     else
     {
         Logger.Log(this,
                    "Cannot post " + goalEvent +
                    ", goal communicator is not connected to any server.");
     }
 }
Beispiel #10
0
 /// <summary>
 /// Posts an event to the queue.
 /// </summary>
 /// <param name="events">A NaoEvent.</param>
 /// <exception cref="InvalidOperationException">The queue was terminated prior to this method-invocation.</exception>
 public void Post(INaoEvent e)
 {
     if (e.ExecutionBehavior == ExecutionBehavior.Instantaneous)
     {
         FireEvent(e);
         return;
     }
     lock (q)
     {
         Logger.Log(this, "Posting event: " + e.ToString());
         q.Enqueue(e, (int)e.Priority);
     }
     locker.Set();
     // log nao events pending
     if (this == Nao)
     {
         Logger.Log(this, ToString());
     }
 }
Beispiel #11
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);
                }
            }
        }
Beispiel #12
0
 public void Fired(INaoEvent e)
 {
     events.Add(e);
 }
Beispiel #13
0
 /// <summary>
 /// Posts the event.
 /// </summary>
 /// <param name="naoEvent">A Nao event.</param>
 protected virtual void PostEvent(INaoEvent naoEvent)
 {
 }
Beispiel #14
0
 /// <summary>
 /// Fires given event.
 /// </summary>
 /// <param name="e">An event.</param>
 private void FireEvent(INaoEvent e)
 {
     Logger.Log(this, "Firing: " + e);
     if (EventFiring != null)
         EventFiring(e);
     e.Fire();
     eventTimer.Restart();
     Logger.Log(this, "Event " + e + " finished firing.");
 }
Beispiel #15
0
 /// <summary>
 /// Posts an event to the queue.
 /// </summary>
 /// <param name="events">A NaoEvent.</param>
 /// <exception cref="InvalidOperationException">The queue was terminated prior to this method-invocation.</exception>
 public void Post(INaoEvent e)
 {
     if (e.ExecutionBehavior == ExecutionBehavior.Instantaneous)
     {
         FireEvent(e);
         return;
     }
     lock (q)
     {
         Logger.Log(this, "Posting event: " + e.ToString());
         q.Enqueue(e, (int)e.Priority);
     }
     locker.Set();
     // log nao events pending
     if (this == Nao)
     {
         Logger.Log(this, ToString());
     }
 }
Beispiel #16
0
 public void Fired(INaoEvent e)
 {
     events.Add(e);
 }
Beispiel #17
0
 public void NewInvalidEventTest()
 {
     goalComs.SetStream(invalidInputStream);
     INaoEvent result = NaoEventFactory.NewEvent(
         invalidEventCode);
 }