public void StartCore(object a)
        {
            try
            {
                var rawItems = ReadCommands().ToArray();

                if (rawItems.Count() == 0)
                {
                    return;
                }

                var lines = rawItems.SelectMany(SpiltCommand).ToArray();
                if (lines.Length > 2)
                {
                    var carSignalInfo = SensorParser.Parse(lines);
                    SignalHandler.Execute(carSignalInfo);
                    //TOOD:由于模拟Gps数据没有数据,所以给一个默认20的速度!
                    carSignalInfo.Sensor.SpeedInKmh = 20;
                    carSignalInfo.SpeedInKmh        = 20;
                    carSignalInfo.BearingAngle      = carSignalInfo.AngleZ + 180;
                    OnCarSignalRecevied(carSignalInfo);
                }
                if (lines.Length <= 2)
                {
                }
            }
            catch (Exception exp)
            {
                string ex = exp.Message;
            }
        }
Beispiel #2
0
 public void StartCore()
 {
     try
     {
         while (true)
         {
             var rawItems = ReadCommands().ToArray();
             if (rawItems.Length == 0)
             {
                 continue;
             }
             var lines = rawItems.SelectMany(SpiltCommand).ToArray();
             if (lines.Length > 2)
             {
                 var carSignalInfo = SensorParser.Parse(lines);
                 SignalHandler.Execute(carSignalInfo);
                 if (Settings.AngleSource == AngleSource.Gyroscope)
                 {
                     carSignalInfo.BearingAngle = carSignalInfo.AngleZ + 180;
                 }
                 OnCarSignalRecevied(carSignalInfo);
                 LogCommands(rawItems);
             }
         }
     }
     catch (Exception exp)
     {
         Logger.Error("BluetoothStartCore", exp.Message);
     }
 }
Beispiel #3
0
        private void OnCarSensorBthMessageReceived(CarSensorBthMessage message)
        {
            var lineslst = new List <string>();
            var line     = message.Sensor;

            if (!string.IsNullOrEmpty(line) && line.Length >= 10)
            {
                lineslst.Add(line);
            }
            var cmd = line.GetCommand();

            if (cmd != null && cmd.Equals(SensorCommand, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var lines = lineslst.ToArray().SelectMany(SpiltCommand).ToArray();

            if (lines.Length > 2)
            {
                var carSignalInfo = SensorParser.Parse(lines);
                SignalHandler.Execute(carSignalInfo);
                if (Settings.AngleSource == AngleSource.Gyroscope)
                {
                    carSignalInfo.BearingAngle = carSignalInfo.AngleZ + 180;
                }
                OnCarSignalRecevied(carSignalInfo);
            }
        }
Beispiel #4
0
 public void OnCarSensorMessageReceive(BinaryCarSensorMessage carSensorMessage)
 {
     try
     {
         var Buffer        = carSensorMessage.Sensor;
         var carSignalInfo = SensorParser.Parse(Buffer);
         SignalHandler.Execute(carSignalInfo);
         if (Settings.AngleSource == AngleSource.Gyroscope)
         {
             carSignalInfo.BearingAngle = carSignalInfo.AngleZ + 180;
         }
         OnCarSignalRecevied(carSignalInfo);
     }
     catch (Exception exp)
     {
         Logger.Error("OnCarSensorMessageReceive:" + exp.Message);
     }
 }
Beispiel #5
0
        protected virtual void StartCore()
        {
            try
            {
                //if (!IsInnerGyro.HasValue)
                //{
                //    IsInnerGyro = DetectGyroSource();
                //    //Logger.InfoFormat("信号中是否包含陀螺仪信息:{0}", IsInnerGyro);
                //}

                var rawItems = ReadCommands().ToArray();
                var lines    = rawItems.SelectMany(SpiltCommand).ToArray();

                if (lines.Length > 2)
                {
                    var carSignalInfo = SensorParser.Parse(lines);
                    SignalHandler.Execute(carSignalInfo);
                    //方向角
                    if (Settings.AngleSource == AngleSource.Gyroscope || Settings.AngleSource == AngleSource.ExternalGyroscope)
                    {
                        if (IsInnerGyro.Value)
                        {
                            carSignalInfo.BearingAngle = carSignalInfo.AngleZ + 180;
                        }
                        else
                        {
                            ProcessCarDirection(carSignalInfo);
                        }
                    }
                    OnCarSignalRecevied(carSignalInfo);
                }
                //if (lines.Length <= 2 || lines.Any(x => x.StartsWith("$D")))
                if (lines.Length <= 2)
                {
                    //Logger.WarnFormat("信号异常:{0}", string.Join(Environment.NewLine, rawItems));
                }

                LogCommands(rawItems);
            }
            catch (Exception exp)
            {
                //Logger.ErrorFormat("读取数据发生异常,原因:{0}", exp, exp);
            }
        }
 public void OnCarSensorMessageReceive(CarSensorMessage carSensorMessage)
 {
     try
     {
         var rawItems = carSensorMessage.Sensor;
         var lines    = rawItems.SelectMany(SpiltCommand).ToArray();
         if (lines.Length > 2)
         {
             var carSignalInfo = SensorParser.Parse(lines);
             SignalHandler.Execute(carSignalInfo);
             if (Settings.AngleSource == AngleSource.Gyroscope)
             {
                 carSignalInfo.BearingAngle = carSignalInfo.AngleZ + 180;
             }
             OnCarSignalRecevied(carSignalInfo);
             LogCommands(rawItems);
         }
     }
     catch (Exception exp)
     {
         Logger.Error("OnCarSensorMessageReceive:" + exp.Message);
     }
 }
 public void StartCore()
 {
     while (true)
     {
         try
         {
             rawItems = ReadToCommand();
             if (rawItems.Length == 0)
             {
                 continue;
             }
             if (rawItems.Where(s => s.Contains("?")).Count() >= 1)
             {
                 Logger.Error("rawItems contains ?", string.Join("|", rawItems));
                 continue;
             }
             var lines = rawItems.SelectMany(SpiltCommand).ToArray();
             if (lines.Length > 2)
             {
                 var carSignalInfo = SensorParser.Parse(lines);
                 //直接对无效信号进行过滤处理!
                 if (!carSignalInfo.IsSensorValid)
                 {
                     Logger.Error("carSignalInfo.IsSensorValid", string.Join("|", rawItems));
                     continue;
                 }
                 SignalHandler.Execute(carSignalInfo);
                 if (Settings.AngleSource == AngleSource.Gyroscope)
                 {
                     carSignalInfo.BearingAngle = carSignalInfo.AngleZ + 180;
                     if (carSignalInfo.BearingAngle != 180)
                     {
                         Angle = carSignalInfo.BearingAngle;
                     }
                     else
                     {
                         carSignalInfo.BearingAngle = Angle;
                     }
                 }
                 else
                 {
                     if (carSignalInfo.Gps != null)
                     {
                         carSignalInfo.BearingAngle = carSignalInfo.Gps.AngleDegrees;
                         //TODO:其实在这点处理不合适
                         if (carSignalInfo.BearingAngle != 0)
                         {
                             Angle = carSignalInfo.BearingAngle;
                         }
                         else
                         {
                             carSignalInfo.BearingAngle = Angle;
                         }
                     }
                     else
                     {
                         Logger.Info("carSignalInfo Gps is null");
                     }
                 }
                 //把原始信号记录器
                 carSignalInfo.commands = rawItems;
                 OnCarSignalRecevied(carSignalInfo);
                 LogCommands(rawItems);
             }
         }
         catch (Exception exp)
         {
             Logger.ErrorFormat("SerialStartCorte发生异常,原因:{0} 原始信号{1}", exp.Message, string.Join(",", rawItems));
             //Logger.Error("USBSerialStartCorte",exp.Message);
         }
     }
 }
        public void StartCore()
        {
            while (true)
            {
                try
                {
                    var rawItems = ReadToCommand();
                    if (rawItems.Length == 0)
                    {
                        continue;
                    }
                    var lines = rawItems.SelectMany(SpiltCommand).ToArray();
                    if (lines.Length > 2)
                    {
                        var carSignalInfo = SensorParser.Parse(lines);
                        SignalHandler.Execute(carSignalInfo);
                        if (Settings.AngleSource == AngleSource.Gyroscope)
                        {
                            carSignalInfo.BearingAngle = carSignalInfo.AngleZ + 180;

                            if (carSignalInfo.BearingAngle != 180)
                            {
                                Angle = carSignalInfo.BearingAngle;
                            }
                            else
                            {
                                carSignalInfo.BearingAngle = Angle;
                            }
                        }
                        else
                        {
                            if (carSignalInfo.Gps != null)
                            {
                                carSignalInfo.BearingAngle = carSignalInfo.Gps.AngleDegrees;
                                //需要处理一下如果角度是0,则使用上一个值
                                //就是Gps的输出频率和主机信号输出的频率不一致
                                if (carSignalInfo.BearingAngle != 0)
                                {
                                    Angle = carSignalInfo.BearingAngle;
                                }
                                else
                                {
                                    carSignalInfo.BearingAngle = Angle;
                                }
                                // Logger.Info("Gps Angle:" + Angle.ToString());
                            }
                            else
                            {
                                Logger.Info("carSignalInfo Gps is null");
                            }
                        }
                        OnCarSignalRecevied(carSignalInfo);
                        LogCommands(rawItems);
                    }
                }
                catch (Exception exp)
                {
                    Logger.Error("USBSerialStartCorte", exp.Message);
                }
            }
        }