Exemple #1
0
        public string testStrados(string testdata)
        {
            try
            {
                Debug.WriteLine("Strados string input:" + testdata);
                string ParsableTestdata = TestDeviceOutput(testdata);

                if (!string.IsNullOrEmpty(ParsableTestdata))
                {
                    Debug.WriteLine("Parsable string input:" + ParsableTestdata);
                    ObdResult obdResult = ObdParser.Parse(ParsableTestdata);
                    Debug.WriteLine(obdResult.Mode);
                    Debug.WriteLine(obdResult.Command);
                    Debug.WriteLine(obdResult.Name);
                    Debug.WriteLine(obdResult.Value);
                    return(obdResult.Value.ToString());
                }
                else
                {
                    Debug.WriteLine("***** UNParseable data *****" + testdata);
                    return("UnParseable data");
                }
            }
            catch (Exception ex)
            {
                if (ex is System.ArgumentException || ex is Strados.Obd.Exceptions.ObdBadCommandException)
                {
                    Debug.WriteLine("Strados Exception: " + ex.Message);
                }

                throw;
            }
        }
Exemple #2
0
        public async void StateUpdate(ObdResult result, Action legCompleted = null, Action driveCompleted = null)
        {
            if (Car == null)
            {
                throw new Exception("Car details need to be set first");
            }
            if (Current == null)
            {
                Current = new Leg(Car, DrivePath);
            }
            else if (Current.Completed)
            {
                //raise leg completed event
                if (legCompleted != null)
                {
                    legCompleted.Invoke();
                }

                var legPath = Current.Save();
                Current.Dispose();
                Current = new Leg(Car, DrivePath);

                //TODO: do something with the trouble codes
                await service.Run(ObdPid.PendingTroubleCodes);
            }

            string cmd   = result.Name;
            string value = result.Value == null ? "NODATA" : result.Value.ToString();

            try
            {
                if (cmd.Contains(ObdPid.VehicleSpeed.ToString()))
                {
                    if (value != "NODATA")
                    {
                        var speed = (double)result.Value;
                        Current.UpdateSpeed(speed);
                        lastSpeed = speed;
                    }
                    else
                    {
                        lastSpeed = 0;
                    }
                }
                else if (cmd.Contains(ObdPid.EngineRPM.ToString()))
                {
                    if (value != "NODATA")
                    {
                        var rpm = (double)result.Value;
                        Current.UpdateRPM(rpm);
                        lastRPM = rpm;
                    }
                    else
                    {
                        lastRPM = 0;
                    }

                    if (lastSpeed == 0 && lastRPM == 0)
                    {
                        End       = DateTimeOffset.UtcNow;
                        Completed = true;

                        if (driveCompleted != null)
                        {
                            driveCompleted.Invoke();
                        }

                        SaveDrive();
                    }
                }
                else if (cmd.Contains(ObdPid.PendingTroubleCodes.ToString()))
                {
                    var codes = (int)result.Value;
                    if (codes > 0)
                    {
                        //TODO: store the trouble code results or do something with it
                        await service.Run(ObdPid.RequestTroubleCodes);
                    }
                }
                else if (cmd.Contains(ObdPid.RequestTroubleCodes.ToString()))
                {
                    var codes = (List <DiagnosticTroubleCode>)result.Value;
                    foreach (var code in codes)
                    {
                        Current.UpdateTroubleCode(code);
                    }
                }
                else
                {
                    Debug.WriteLine(string.Format("{0} -> {1}", cmd, value));
                }
            }
            catch (System.Exception err)
            {
                Debug.WriteLine("Parse Error: {0} -> {1}", cmd, value);
                Debug.WriteLine("{0}\n{1}", err.Message, err.StackTrace);
            }
        }