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); }
/// <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."); }
/// <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."); }
/// <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."); }
/// <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."); } }
/// <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); }
/// <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."); } }
/// <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()); } }
/// <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); } } }
public void Fired(INaoEvent e) { events.Add(e); }
/// <summary> /// Posts the event. /// </summary> /// <param name="naoEvent">A Nao event.</param> protected virtual void PostEvent(INaoEvent naoEvent) { }
/// <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."); }
public void NewInvalidEventTest() { goalComs.SetStream(invalidInputStream); INaoEvent result = NaoEventFactory.NewEvent( invalidEventCode); }