/// <summary>
 /// Runs an ObdPid command and returns the result parsed by a provided parser
 /// </summary>
 /// <param name="command"></param>
 /// <param name="parser"></param>
 /// <returns></returns>
 public Task<object> Run(ObdPid command, Func<string, object> parser)
 {
     return Task.Run(async () =>
     {
         return parser.Invoke(await Run(command.StringValue()));
     });
 }
 /// <summary>
 /// Runs an ObdPid command and returns the result parsed by a provided parser
 /// </summary>
 /// <param name="command"></param>
 /// <param name="parser"></param>
 /// <returns></returns>
 public Task <object> Run(ObdPid command, Func <string, object> parser)
 {
     return(Task.Run(async() =>
     {
         return parser.Invoke(await Run(command.StringValue()));
     }));
 }
 /// <summary>
 /// Runs an ObdPid command and returns the result parsed by ObdParser
 /// </summary>
 /// <param name="command">OBDPid to send to ECU</param>
 /// <returns>ObdParser parsed response from ECU</returns>
 public Task<ObdResult> Run(ObdPid command)
 {
     return Task.Run(async () =>
     {
         return ObdParser.Parse(await Run(command.StringValue()));
     });
 }
 /// <summary>
 /// Runs an ObdPid command and returns the result parsed by ObdParser
 /// </summary>
 /// <param name="command">OBDPid to send to ECU</param>
 /// <returns>ObdParser parsed response from ECU</returns>
 public Task <ObdResult> Run(ObdPid command)
 {
     return(Task.Run(async() =>
     {
         return ObdParser.Parse(await Run(command.StringValue()));
     }));
 }
Beispiel #5
0
        public static ObdCommand GetCommand(this ObdPid pid)
        {
            var map = PidMapping[pid];

            if (null != map)
            {
                return(map.Item1);
            }
            return(0);
        }
Beispiel #6
0
        public static uint GetBitmask(this ObdPid pid)
        {
            var map = PidMapping[pid];

            if (null != map)
            {
                return(map.Item2);
            }
            return(0);
        }
        private async Task <List <ObdPid> > getReportedPids(ObdPid rangePid)
        {
            if (!rangePid.ToString().Contains("PidSupport"))
            {
                throw new ArgumentOutOfRangeException("Not a valid Pid Support OBDPid");
            }

            var reported = (await Run(rangePid)).Value as Dictionary <ObdPid, bool>;

            if (reported == null)
            {
                return(new List <ObdPid>());
            }
            else
            {
                return(reported.Keys.Where(k => reported[k]).ToList());
            }
        }
Beispiel #8
0
        private static Dictionary <ObdPid, bool> PidSupport(string[] data, ObdPid pid)
        {
            int offset;

            switch (pid)
            {
            case ObdPid.PidSupport_01_20:
                offset = 0;
                break;

            case ObdPid.PidSupport_21_40:
                offset = 32;
                break;

            case ObdPid.PidSupport_41_60:
                offset = 64;
                break;

            case ObdPid.PidSupport_61_80:
                offset = 96;
                break;

            case ObdPid.PidSupport_81_A0:
                offset = 128;
                break;

            default:
                offset = 0;
                break;
            }

            var binary = HexHelper.Sanitize(data);

            //dictionary of pids and car support for each one
            Dictionary <ObdPid, bool> pidSupport = new Dictionary <ObdPid, bool>();

            for (int i = 0; i < binary.Length; i++)
            {
                pidSupport.Add((ObdPid)(i + 1) + offset, binary[i] == '1');
            }

            return(pidSupport);
        }
        private async Task<List<ObdPid>> getReportedPids(ObdPid rangePid)
        {
            if (!rangePid.ToString().Contains("PidSupport"))
                throw new ArgumentOutOfRangeException("Not a valid Pid Support OBDPid");

            var reported = (await Run(rangePid)).Value as Dictionary<ObdPid, bool>;

            if (reported == null)
                return new List<ObdPid>();
            else
                return reported.Keys.Where(k => reported[k]).ToList();
        }
Beispiel #10
0
        private static Dictionary<ObdPid, bool> PidSupport(string[] data, ObdPid pid)
        {
            int offset;
            switch (pid)
            {
                case ObdPid.PidSupport_01_20:
                    offset = 0;
                    break;
                case ObdPid.PidSupport_21_40:
                    offset = 32;
                    break;
                case ObdPid.PidSupport_41_60:
                    offset = 64;
                    break;
                case ObdPid.PidSupport_61_80:
                    offset = 96;
                    break;
                case ObdPid.PidSupport_81_A0:
                    offset = 128;
                    break;
                default:
                    offset = 0;
                    break;
            }

            var binary = HexHelper.Sanitize(data);

            //dictionary of pids and car support for each one
            Dictionary<ObdPid, bool> pidSupport = new Dictionary<ObdPid, bool>();
            for (int i = 0; i < binary.Length; i++)
                pidSupport.Add((ObdPid)(i + 1) + offset, binary[i] == '1');

            return pidSupport;
        }
Beispiel #11
0
 public static string GetName(this ObdPid pid)
 {
     return(string.Format("PID {0}", pid.ToString().Replace("Pid", "")));
 }