public void Execute(Behavior behavior) { try { if (!(behavior is NullBehavior)) { Stopwatch bsw = new Stopwatch(); bsw.Reset(); bsw.Start(); // execute operational behavior operationalFacade.ExecuteBehavior(behavior); bsw.Stop(); if (bsw.ElapsedMilliseconds > 50) { ArbiterOutput.Output("Delay: Operational Execution Time: " + bsw.ElapsedMilliseconds.ToString()); } } } catch (Exception e) { // Notify ArbiterOutput.Output("Errror executing operational behavior: " + e.ToString()); } }
/// <summary> /// Sends road network projection to the operational layer /// </summary> public void SendProjection() { try { if (CoreCommon.RoadNetwork != null) { if (this.operationalFacade != null) { this.testComponentNeedsRoadNetwork = true; this.operationalFacade.SetRoadNetwork(CoreCommon.RoadNetwork); } else { ArbiterOutput.Output("Need to connect to operational before can send road network"); } } else { ArbiterOutput.Output("Road network cannot be null to send to operational"); } } catch (Exception e) { ArbiterOutput.Output("Error setting road network in operational, sending projection"); this.operationalFacade.SetProjection(CoreCommon.RoadNetwork.PlanarProjection); Console.WriteLine(e.ToString()); } }
/// <summary> /// Clear all old completion reports /// </summary> public void ClearCompletionReports() { try { this.recentReports = new List <KeyValuePair <CompletionReport, DateTime> >(); ArbiterOutput.Output("Cleared Completion Reports"); } catch (Exception) { } }
/// <summary> /// Called when message sent to us /// </summary> /// <param name="channelName"></param> /// <param name="message"></param> public void MessageArrived(string channelName, object message) { try { if (channelName == "ArbiterSceneEstimatorPositionChannel" + this.remotingSuffix && message is VehicleState) { // cast and set vehicleState = (VehicleState)message; } else if (channelName == "ObservedObstacleChannel" + this.remotingSuffix && message is SceneEstimatorUntrackedClusterCollection) { // cast and set observedObstacles = (SceneEstimatorUntrackedClusterCollection)message; } else if (channelName == "ObservedVehicleChannel" + this.remotingSuffix && message is SceneEstimatorTrackedClusterCollection) { // check if not ignoring vehicles if (!Arbiter.Core.ArbiterSettings.Default.IgnoreVehicles) { // cast and set observedVehicles = (SceneEstimatorTrackedClusterCollection)message; } } else if (channelName == "VehicleSpeedChannel" + this.remotingSuffix && message is double) { // cast and set vehicleSpeed = (double)message; } else if (channelName == "SideObstacleChannel" + this.remotingSuffix && message is SideObstacles) { SideObstacles sideSickObstacles = (SideObstacles)message; if (sideSickObstacles.side == SideObstacleSide.Driver) { this.sideSickObstaclesDriver = sideSickObstacles; } else { this.sideSickObstaclesPass = sideSickObstacles; } } } catch (Exception ex) { ArbiterOutput.Output("Error receiving message: " + ex.ToString()); } }
/// <summary> /// Sends road network projection to the operational layer /// </summary> public void TrySendProjection() { ArbiterOutput.Output("Attempting to set Operational Road Network"); if (CoreCommon.RoadNetwork != null) { if (this.operationalFacade != null) { try { this.operationalFacade.SetRoadNetwork(CoreCommon.RoadNetwork); } catch (Exception ex) { ArbiterOutput.Output("Error setting road network in operational, sending projection"); Console.WriteLine(ex.ToString()); try { this.operationalFacade.SetProjection(CoreCommon.RoadNetwork.PlanarProjection); } catch (Exception e) { Console.WriteLine("error setting projection in op"); } } } else { ArbiterOutput.Output("Need to connect to operational before can send road network"); } } else { ArbiterOutput.Output("Road network cannot be null to send to operational"); } ArbiterOutput.Output("Leaving TrySendOperationalProjection"); }
/// <summary> /// Shuts down the communicator and unsubscribes from channels, whatnot /// </summary> public void Shutdown() { try { if (vehicleStateChannel != null) { // unsubscribe from channels vehicleStateChannel.Unsubscribe(vehicleStateChannelToken); observedObstacleChannel.Unsubscribe(observedObstacleChannelToken); observedVehicleChannel.Unsubscribe(observedVehicleChannelToken); vehicleSpeedChannel.Unsubscribe(vehicleSpeedChannelToken); sideObstacleChannel.Unsubscribe(sideObstacleChannelToken); } // notify ArbiterOutput.Output("Unsubscribed from channels"); } catch (Exception e) { // notify ArbiterOutput.Output("Error in shutting down registered channels"); ArbiterOutput.WriteToLog(e.ToString()); } }
/// <summary> /// Try to reconnect to stuff /// </summary> public void TryReconnect() { this.CommunicationsReady = false; ArbiterOutput.Output("Set comms ready flag to false"); }
/// <summary> /// Keeps watch over communications components and determines if any need to be restarted /// </summary> public void Watchdog() { // always loop while (true) { try { if (Arbiter.Core.ArbiterSettings.Default.IgnoreVehicles) { ArbiterOutput.Output("Ignoring Tracked Clusters"); } #region Update Completion reports with 3 Sec Timeout lock (this.recentReports) { List <KeyValuePair <CompletionReport, DateTime> > crs = new List <KeyValuePair <CompletionReport, DateTime> >(); foreach (KeyValuePair <CompletionReport, DateTime> cr in this.recentReports) { TimeSpan diff = DateTime.Now.Subtract(cr.Value); ArbiterOutput.WriteToLog("Comm line 263 test diff.ToString: " + diff.ToString()); if (diff.Seconds < 2 && cr.Value.Date.Equals(DateTime.Now.Date)) { crs.Add(cr); } else { ArbiterOutput.WriteToLog("Removed Completion Report: " + cr.Key.BehaviorType.ToString() + ", " + cr.Key.Result.ToString()); } } this.recentReports = crs; } #endregion #region Check for communications readiness if (!this.CommunicationsReady) { try { // configure this.Configure(); } catch (Exception e) { // notify ArbiterOutput.Output("Error in communications watchdog, configuration"); ArbiterOutput.WriteToLog(e.ToString()); } } if (!this.CommunicationsReady) { try { // make sure nothing else registered this.Shutdown(); // register services this.Register(); } catch (Exception e) { // notify ArbiterOutput.Output("Error in communications watchdog, registration"); ArbiterOutput.WriteToLog(e.ToString()); } } #endregion #region Get Car Mode (Acts as Operational Ping and know then Comms Ready) try { if (this.operationalFacade != null) { // update the car mode this.carMode = this.operationalFacade.GetCarMode(); // set comms ready as true given success if (!this.CommunicationsReady) { this.CommunicationsReady = true; } } else { this.CommunicationsReady = false; } } catch (Exception e) { // notify ArbiterOutput.Output("Error retreiving car mode from operational in watchdog, attempting to reconnect"); // log ArbiterOutput.WriteToLog(e.ToString()); // set comms ready as false this.CommunicationsReady = false; } #endregion } catch (Exception e) { ArbiterOutput.Output("Error in communications watchdog", e); } // wait for cycle time Thread.Sleep(1000); } }