public void Execute(CarSignalInfo signalInfo) { if (LastSignal == null) { LastSignal = signalInfo; return; } if (!signalInfo.IsSensorValid) { return; } try { HandleMessages(signalInfo); } catch (Exception exp) { Logger.ErrorFormat("执行信号改变命令出现异常,原因:{0}", exp, exp); } finally { LastSignal = signalInfo; } }
public void Enqueue(CarSignalInfo signal) { lock (SyncRoot) { _signalInfoNodes.Enqueue(signal); RemoveOldGps(); } }
private void ExecuteExamItems(CarSignalInfo signalInfo) { var activedItems = ExamItems.Where(x => x.State == ExamItemState.Progressing).ToArray(); foreach (var examItem in activedItems.OrderBy(x => x.Order)) { try { examItem.Execute(signalInfo); } catch (Exception exp) { Logger.ErrorFormat("接收到信号后执行考试项目{0}发生异常,原因:{1}", examItem.ItemCode, exp, exp); } } }
/// <summary> /// 获取灯光改变的属性名称 /// </summary> /// <param name="oldSignal">老的信号</param> /// <param name="newSignal">新的传感器信号</param> /// <returns></returns> public IList <string> GetLightChangedProperties(CarSignalInfo oldSignal, CarSignalInfo newSignal) { var oldSensor = oldSignal.Sensor; var newSensor = newSignal.Sensor; List <string> propertyNames = new List <string>(); if (oldSensor == null) { return(propertyNames); } //灯光被改变 if (oldSensor.CautionLight != newSensor.CautionLight && newSensor.CautionLight) { propertyNames.Add("CautionLight"); } if (oldSensor.LeftIndicatorLight != newSensor.LeftIndicatorLight && newSensor.LeftIndicatorLight) { propertyNames.Add("LeftIndicatorLight"); } if (oldSensor.RightIndicatorLight != newSensor.RightIndicatorLight && newSensor.RightIndicatorLight) { propertyNames.Add("RightIndicatorLight"); } if (oldSensor.FogLight != newSensor.FogLight && newSensor.FogLight) { propertyNames.Add("FogLight"); } if (oldSensor.HighBeam != newSensor.HighBeam && newSensor.HighBeam) { propertyNames.Add("HighBeam"); } if (oldSensor.LowBeam != newSensor.LowBeam && newSensor.LowBeam) { propertyNames.Add("LowBeam"); } if (oldSensor.OutlineLight != newSensor.OutlineLight && newSensor.OutlineLight) { propertyNames.Add("OutlineLight"); } return(propertyNames); }
public void Execute(CarSignalInfo signalInfo) { //加入队列 try { CarSignalProcessors.Execute(signalInfo); } catch (Exception exp) { Logger.ErrorFormat("执行任务 {0} 发生异常,原因: {1}", "CarSignalProcessors", exp.Message); } try { CarSignalMonitor.Execute(signalInfo); } catch (Exception exp) { Logger.ErrorFormat("处理任务 {0} 发生异常,原因: {1}", "CarSignalMonitor", exp.Message); } //加入队列 CarSignalSet.Enqueue(signalInfo); }
//泸州特殊项目过滤完成了就不在自动触发 protected override async Task MatchMapPointsAsync(CarSignalInfo signalInfo) { //只是一个条件 if (Settings.PullOverStartFlage == false && Settings.EndExamByDistance && IsTriggerPullOver == false) { if (signalInfo.Distance >= Settings.ExamDistance) { IsTriggerPullOver = true; Logger.Info("里程达到三公里自动触发考试项目"); Messenger.Send <PullOverTriggerMessage>(new PullOverTriggerMessage()); return; } } //直线行驶路段忽略其它的考试项目 if (ExamItems.Any(d => d.ItemCode == ExamItemCodes.StraightDriving && d.State != ExamItemState.Finished)) { return; } var points = PointSearcher.Search(signalInfo); //对解除限速进行 if (points.Any(d => d.PointType == MapPointType.UnfreezeSpeedLimit)) { Messenger.Send(new EndSpeedLimitMessage()); } var query = from p in points where !ExamItems.Any(x => x.State != ExamItemState.Finished && x.TriggerPoint != null && x.TriggerPoint.PointType == p.PointType) && _mapTriggerPoints.All(x => x.Index != p.Index) select p; foreach (var mapPoint in query) { var context = new ExamItemExecutionContext(Context); var item = DataService.AllExamItems.FirstOrDefault(x => x.MapPointType == mapPoint.PointType); if (item != null) { if (Settings.PullOverStartFlage && InitPointList.Count > 0 && context.ExamMode == ExamMode.Examming) { Constants.IsExamMode_Luzhou = true; if (item.MapPointType != MapPointType.TurnLeft && item.MapPointType != MapPointType.TurnRight) { //只报一次,除了左,右转 if (!FinishedPointList.Contains(item.MapPointType)) { FinishedPointList.Add(item.MapPointType); } else { //播报过的项目,直接返回 return; } } //////左转,右转,直行路口不过滤 ////if (FinishedPointList.Contains(item.MapPointType)) ////{ //// //泸州过滤掉所有考试项目 //// //if (item.ItemCode != ExamItemCodes.TurnLeft && item.ItemCode != ExamItemCodes.TurnRight && //// // item.ItemCode != ExamItemCodes.StraightThrough && item.ItemCode != ExamItemCodes.TurnRound //// // && item.ItemCode != ExamItemCodes.SchoolArea && item.ItemCode != ExamItemCodes.BusArea && item.ItemCode != ExamItemCodes.PedestrianCrossing && item.ItemCode != ExamItemCodes.PedestrianCrossingHasPeople) //// { //// Logger.Info("跳过项目:" + item.ItemCode); //// continue; //// } ////} ////if (!FinishedPointList.Contains(item.MapPointType) && item.MapPointType != MapPointType.PullOver) ////{ //// FinishedPointList.Add(item.MapPointType); //// Logger.Info(item.MapPointType.ToString() + ":" + FinishedPointList.Count.ToString()); ////} } context.ItemCode = item.ItemCode; ///超变会处理,相应的点位随机触发超车,变道,会车 if (item.ItemCode == ExamItemCodes.OvertakeChangeMeeting) { context.ItemCode = ExamItemCodes.GetRandomExamItemFromOvertakeChangeMeeting(); } context.TriggerSource = ExamItemTriggerSource.Map; context.Properties = mapPoint.Properties; context.TriggerPoint = mapPoint; Logger.InfoFormat("当前GPS:{0}-{1}-{2}", signalInfo.Gps.LatitudeDegrees, signalInfo.Gps.LongitudeDegrees, signalInfo.Gps.SpeedInKmh); Logger.InfoFormat("点位GPS:{0}-{1}", mapPoint.Point.Latitude, mapPoint.Point.Longitude); Logger.InfoFormat("相距位置:{0}米", GeoHelper.GetDistance(mapPoint.Point.Longitude, mapPoint.Point.Latitude, signalInfo.Gps.LongitudeDegrees, signalInfo.Gps.LatitudeDegrees)); Logger.InfoFormat("点位触发项目:{0}", item.ItemName); await StartItemAsync(context, CancellationToken.None); } _mapTriggerPoints.Enqueue(mapPoint); } while (_mapTriggerPoints.Count > 2) { _mapTriggerPoints.Dequeue(); } }
private void HandleMessages(CarSignalInfo signalInfo) { //对无效的信号进行过滤 if (signalInfo == null || LastSignal == null) { return; } var sensorInfo = signalInfo.Sensor; var lastSensorInfo = LastSignal.Sensor; //手刹 if (lastSensorInfo.Handbrake != sensorInfo.Handbrake) { Messenger.Send(new HandBreakChangedMessage(sensorInfo.Handbrake) { SignalInfo = signalInfo }); } //喇叭 if (lastSensorInfo.Loudspeaker != sensorInfo.Loudspeaker) { Messenger.Send(new LoudspeakerChangedMessage(sensorInfo.Loudspeaker) { SignalInfo = signalInfo }); } //发动机 消息机制 if (lastSensorInfo.Engine != sensorInfo.Engine) { Messenger.Send(new EngineChangedMessage(sensorInfo.Engine) { SignalInfo = signalInfo }); if (sensorInfo.Engine) { Messenger.Send(new EngineStartMessage()); } else { //打印出原始信号 // Logger.Error("SendEngineStopMessage", string.Join(",", signalInfo.commands)); Messenger.Send(new EngineStopMessage()); } } //指纹仪 if (lastSensorInfo.Fingerprint != sensorInfo.Fingerprint) { if (sensorInfo.Fingerprint) { Messenger.Send(new FingerprintMessage()); } } if (lastSensorInfo.SafetyBelt != sensorInfo.SafetyBelt) { if (sensorInfo.SafetyBelt) { Messenger.Send(new SafetyBeltMessage()); } } //车门 if (lastSensorInfo.Door != sensorInfo.Door) { Messenger.Send(new DoorChangedMessage(sensorInfo.Door) { SignalInfo = signalInfo }); if (sensorInfo.Door) { Messenger.Send(new OpenDoorMessage()); } else { Messenger.Send(new CloseDoorMessage()); } } //档位变换 if (lastSensorInfo.Gear != sensorInfo.Gear) { Messenger.Send(new SwitchGearMessage(sensorInfo.Gear, lastSensorInfo.Gear) { SignalInfo = signalInfo }); } //刹车 if (lastSensorInfo.Brake != sensorInfo.Brake) { Messenger.Send(new BrakingChangedMessage(sensorInfo.Brake) { SignalInfo = signalInfo }); } //车辆状态 if (signalInfo.CarState != LastSignal.CarState) { Messenger.Send(new CarStateChangedMessage(signalInfo.CarState, LastSignal.CarState) { SignalInfo = signalInfo }); } //是否空挡 if (lastSensorInfo.IsNeutral != sensorInfo.IsNeutral) { Messenger.Send(new IsNeutralChangedMessage(sensorInfo.IsNeutral) { SignalInfo = signalInfo }); } //if (dataService.GetSettings().EndExamByDistance&&signalInfo.Distance>= dataService.GetSettings().ExamDistance&&IsTriggerPullOver==false) //{ // //发送靠边停车消息,系统触发靠边停车 // Messenger.Send(new PullOverTriggerMessage()); // IsTriggerPullOver = true; //} //判断一下 是否自动触发靠边停车 }
protected override async Task MatchMapPointsAsync(CarSignalInfo signalInfo) { //只是一个条件 if (Settings.EndExamByDistance && IsTriggerPullOver == false) { if (signalInfo.Distance >= Settings.ExamDistance) { IsTriggerPullOver = true; Logger.Info("@@里程达到三公里自动触发考试项目"); Messenger.Send <PullOverTriggerMessage>(new PullOverTriggerMessage()); return; } } //直线行驶路段忽略其它的考试项目 if (ExamItems.Any(d => d.ItemCode == ExamItemCodes.StraightDriving && d.State != ExamItemState.Finished)) { return; } var points = PointSearcher.Search(signalInfo); //对解除限速进行 if (points.Any(d => d.PointType == MapPointType.UnfreezeSpeedLimit)) { Messenger.Send(new EndSpeedLimitMessage()); } var query = from p in points where !ExamItems.Any(x => x.State != ExamItemState.Finished && x.TriggerPoint != null && x.TriggerPoint.PointType == p.PointType) && _mapTriggerPoints.All(x => x.Index != p.Index) select p; foreach (var mapPoint in query) { var context = new ExamItemExecutionContext(Context); var item = DataService.AllExamItems.FirstOrDefault(x => x.MapPointType == mapPoint.PointType); //其实最简单还是要在这里处理 if (item != null) { //排除语音点和起步 if (InitPointList.Count > 0 && !item.ItemName.Contains("点")) { if (!examingItem.Any(x => x.Equals(item.MapPointType)) && item.MapPointType != MapPointType.VehicleStarting) { examingItem.Enqueue(item.MapPointType); FinishedPointList.Add(item.MapPointType); Logger.Info("@@加入队列项目:{0}", item.ItemName); } if (examingItem.Count > 1) { examingItem.Dequeue(); } } context.ItemCode = item.ItemCode; ///超变会处理,相应的点位随机触发超车,变道,会车 if (item.ItemCode == ExamItemCodes.OvertakeChangeMeeting) { context.ItemCode = ExamItemCodes.GetRandomExamItemFromOvertakeChangeMeeting(); } context.TriggerSource = ExamItemTriggerSource.Map; context.Properties = mapPoint.Properties; context.TriggerPoint = mapPoint; Logger.InfoFormat("当前GPS:{0}-{1}-{2}", signalInfo.Gps.LatitudeDegrees, signalInfo.Gps.LongitudeDegrees, signalInfo.Gps.SpeedInKmh); Logger.InfoFormat("点位GPS:{0}-{1}", mapPoint.Point.Latitude, mapPoint.Point.Longitude); Logger.InfoFormat("相距位置:{0}米", GeoHelper.GetDistance(mapPoint.Point.Longitude, mapPoint.Point.Latitude, signalInfo.Gps.LongitudeDegrees, signalInfo.Gps.LatitudeDegrees)); Logger.InfoFormat("点位触发项目:{0}", item.ItemName); await StartItemAsync(context, CancellationToken.None); } _mapTriggerPoints.Enqueue(mapPoint); } while (_mapTriggerPoints.Count > 2) { _mapTriggerPoints.Dequeue(); } }