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

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

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

            Assert.IsInstanceOf(typeof(GoToEvent), result);
        }
Ejemplo n.º 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.");
 }
Ejemplo n.º 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.");
 }
Ejemplo n.º 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.");
 }
Ejemplo n.º 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.");
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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.");
     }
 }
Ejemplo n.º 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());
     }
 }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 12
0
 public void Fired(INaoEvent e)
 {
     events.Add(e);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Posts the event.
 /// </summary>
 /// <param name="naoEvent">A Nao event.</param>
 protected virtual void PostEvent(INaoEvent naoEvent)
 {
 }
Ejemplo n.º 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.");
 }
Ejemplo n.º 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());
     }
 }
Ejemplo n.º 16
0
 public void Fired(INaoEvent e)
 {
     events.Add(e);
 }
Ejemplo n.º 17
0
 public void NewInvalidEventTest()
 {
     goalComs.SetStream(invalidInputStream);
     INaoEvent result = NaoEventFactory.NewEvent(
         invalidEventCode);
 }