Esempio n. 1
0
        protected int getDataStartIndex(OBDParameter param, bool bIsMultiline, bool bConsecutiveLine)
        {
            if (bConsecutiveLine)
            {
                return(5);
            }
            switch (param.Service)
            {
            case 1:
                return(9);

            case 2:
                return(11);

            case 3:
            case 7:
                return(!bIsMultiline ? 9 : 11);

            case 4:
                return(7);

            case 5:
                return(11);

            case 9:
                return(13);

            default:
                return(9);
            }
        }
Esempio n. 2
0
        protected int getDataStartIndex(OBDParameter param)
        {
            switch (param.Service)
            {
            case 1:
                return(10);

            case 2:
                return(12);

            case 3:
            case 4:
                return(8);

            case 5:
                return(12);

            case 7:
                return(8);

            case 9:
                if (param.Parameter == 2)
                {
                    return(12);
                }
                else
                {
                    break;
                }
            }
            return(10);
        }
Esempio n. 3
0
        public OBDParameter GetFreezeFrameCopy(int iFrame)
        {
            OBDParameter copy = GetCopy();

            copy.Service    = 2;
            copy.OBDRequest = "02" + copy.OBDRequest.Substring(2, 2) + iFrame.ToString("D2");
            return(copy);
        }
Esempio n. 4
0
        private void ConnectThreadNew(object state)
        {
            ShowConnectingLabel();
            if (m_OBDInterface.CommSettings.AutoDetect)
            {
                if (m_OBDInterface.initDeviceAuto())
                {
                    m_OBDInterface.logItem("Connection Established!");
                    ShowConnectedLabel();
                    OBDParameter param = new OBDParameter();
                    param.OBDRequest = "0902";
                    param.Service    = 9;
                    param.Parameter  = 2;
                    param.ValueTypes = 4;
                    m_OBDInterface.getValue(param, true);
                }
                else
                {
                    MessageBox.Show("ProScan failed to find a compatible OBD-II interface attached to this computer.\r\n\r\nPlease verify that no other application is currently using the required port.", "Auto Detection Failure", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    m_OBDInterface.logItem("Failed to find a compatible OBD-II interface.");
                    ShowDisconnectedLabel();
                }
            }
            else
            {
                int baudRate = m_OBDInterface.CommSettings.BaudRate;
                int comPort  = m_OBDInterface.CommSettings.ComPort;
                if (m_OBDInterface.initDevice(
                        m_OBDInterface.CommSettings.HardwareIndex,
                        comPort,
                        baudRate,
                        m_OBDInterface.CommSettings.ProtocolIndex
                        ))
                {
                    m_OBDInterface.logItem("Connection Established!");
                    ShowConnectedLabel();
                }
                else
                {
                    MessageBox.Show(
                        string.Format(@"ProScan failed to find a compatible OBD-II interface attached to {0} at baud rate {1} bps.

Please verify that no other application is currently using the required port and that the baud rate is correct.",
                                      m_OBDInterface.CommSettings.ComPortName,
                                      m_OBDInterface.CommSettings.BaudRate
                                      ),
                        "Connection Failure",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation
                        );
                    m_OBDInterface.logItem("Failed to find a compatible OBD-II interface.");
                    ShowDisconnectedLabel();
                }
            }
        }
Esempio n. 5
0
 private void UpdateThread(object state)
 {
     if (!bRunThread)
     {
         return;
     }
     do
     {
         if (m_obdInterface.getConnectedStatus() && bLogging)
         {
             IEnumerator enumerator = panelDisplay.Controls.GetEnumerator();
             if (enumerator.MoveNext())
             {
                 do
                 {
                     SensorDisplayControl sensorDisplayControl = (SensorDisplayControl)enumerator.Current;
                     OBDParameter         obdParameter         = (OBDParameter)sensorDisplayControl.Tag;
                     OBDParameterValue    obdParameterValue    = m_obdInterface.getValue(obdParameter, radioDisplayEnglish.Checked);
                     if (!obdParameterValue.ErrorDetected)
                     {
                         string str = obdParameter.EnglishUnitLabel;
                         if (!radioDisplayEnglish.Checked)
                         {
                             str = obdParameter.MetricUnitLabel;
                         }
                         double        num1          = obdParameterValue.DoubleValue;
                         double        num2          = obdParameterValue.DoubleValue;
                         SensorLogItem sensorLogItem = new SensorLogItem(obdParameter.Name, num2.ToString(), str, num1.ToString(), str);
                         SensorMonitorForm.m_arrayListLog.Add((object)sensorLogItem);
                         scrollTime.Maximum = SensorMonitorForm.m_arrayListLog.Count - 1;
                         scrollTime.Value   = scrollTime.Maximum;
                         DateTime dateTime = new DateTime();
                         dateTime = new DateTime(0L);
                         TimeSpan timeSpan = sensorLogItem.Time.Subtract(m_dtStartTime);
                         lblTimeElapsed.Text = dateTime.Add(timeSpan).ToString("mm:ss.fff", DateTimeFormatInfo.InvariantInfo);
                         if (radioDisplayEnglish.Checked)
                         {
                             double num3 = obdParameterValue.DoubleValue;
                             sensorDisplayControl.EnglishDisplay = num3.ToString() + " " + obdParameter.EnglishUnitLabel;
                         }
                         else
                         {
                             double num3 = obdParameterValue.DoubleValue;
                             sensorDisplayControl.MetricDisplay = num3.ToString() + " " + obdParameter.MetricUnitLabel;
                         }
                     }
                 }while (enumerator.MoveNext());
             }
         }
         else
         {
             Thread.Sleep(300);
         }
     }while (bRunThread);
 }
Esempio n. 6
0
        public bool initOBD()
        {
            OBDParameter obdParameter1 = new OBDParameter(1, 0, 0);

            obdParameter1.ValueTypes = 32;
            OBDParameterValue obdParameterValue1 = getValue(obdParameter1, true);

            if (obdParameterValue1.ErrorDetected)
            {
                return(false);
            }
            IEnumerator enumerator1 = m_listAllParameters.GetEnumerator();

            if (enumerator1.MoveNext())
            {
                do
                {
                    OBDParameter obdParameter2 = (OBDParameter)enumerator1.Current;
                    if (obdParameter2.Parameter > 0 && obdParameter2.Parameter <= 32 && obdParameterValue1.getBitFlag(obdParameter2.Parameter - 1))
                    {
                        m_listSupportedParameters.Add((object)obdParameter2);
                    }
                }while (enumerator1.MoveNext());
            }
            if (!obdParameterValue1.getBitFlag(31))
            {
                return(true);
            }
            obdParameter1.Parameter = 32;
            OBDParameterValue obdParameterValue2 = getValue(obdParameter1, true);

            if (obdParameterValue2.ErrorDetected)
            {
                return(false);
            }
            IEnumerator enumerator2 = m_listAllParameters.GetEnumerator();

            if (enumerator2.MoveNext())
            {
                do
                {
                    OBDParameter obdParameter2 = (OBDParameter)enumerator2.Current;
                    if (obdParameter2.Parameter > 32 && obdParameter2.Parameter <= 64 && obdParameterValue2.getBitFlag(obdParameter2.Parameter - 33))
                    {
                        m_listSupportedParameters.Add((object)obdParameter2);
                    }
                }while (enumerator2.MoveNext());
            }
            return(true);
        }
Esempio n. 7
0
        public OBDParameterValue getValue(string strPID, bool bEnglishUnits)
        {
            OBDParameter obdParameter = lookupParameter(strPID);

            if (obdParameter != null)
            {
                return(getValue(obdParameter, bEnglishUnits));
            }

            OBDParameterValue value = new OBDParameterValue();

            value.ErrorDetected = true;
            return(value);
        }
Esempio n. 8
0
        private void UpdateThread(object state)
        {
            while (IsRunThread)
            {
                if (m_obdInterface.ConnectedStatus && IsLogging)
                {
                    foreach (SensorDisplayControl control in panelDisplay.Controls)
                    {
                        OBDParameter      param = (OBDParameter)control.Tag;
                        OBDParameterValue value = m_obdInterface.getValue(param, radioDisplayEnglish.Checked);
                        if (!value.ErrorDetected)
                        {
                            string text = param.EnglishUnitLabel;
                            if (!radioDisplayEnglish.Checked)
                            {
                                text = param.MetricUnitLabel;
                            }

                            SensorLogItem sensorLogItem = new SensorLogItem(
                                param.Name,
                                value.DoubleValue.ToString(),
                                text,
                                value.DoubleValue.ToString(),
                                text);
                            m_ListLog.Add(sensorLogItem);
                            scrollTime.Maximum = m_ListLog.Count - 1;
                            scrollTime.Value   = scrollTime.Maximum;

                            DateTime dateTime = new DateTime(0L);
                            lblTimeElapsed.Text = dateTime.Add(sensorLogItem.Time.Subtract(m_dtStartTime)).ToString("mm:ss.fff", DateTimeFormatInfo.InvariantInfo);

                            text = value.DoubleValue.ToString();
                            if (radioDisplayEnglish.Checked)
                            {
                                control.EnglishDisplay = text + " " + param.EnglishUnitLabel;
                            }
                            else
                            {
                                control.MetricDisplay = text + " " + param.MetricUnitLabel;
                            }
                        }
                    }
                }
                else
                {
                    Thread.Sleep(300);
                }
            }
        }
Esempio n. 9
0
        public bool isParameterSupported(OBDParameter param)
        {
            IEnumerator enumerator = m_listSupportedParameters.GetEnumerator();

            if (enumerator.MoveNext())
            {
                while ((OBDParameter)enumerator.Current != param)
                {
                    if (!enumerator.MoveNext())
                    {
                        return(false);
                    }
                }
                return(true);
            }
            return(false);
        }
Esempio n. 10
0
        public OBDParameterValue SpecialValue(OBDParameter param, bool bEnglishUnits)
        {
            if (param.Parameter != 0)
            {
                return(null);
            }

            OBDParameterValue value     = new OBDParameterValue();
            string            respopnse = getRawResponse("ATRV");

            m_commLog.AddItem("Response: " + respopnse);
            if (respopnse != null)
            {
                respopnse         = respopnse.Replace("V", "");
                value.DoubleValue = Utility.Text2Double(respopnse);
            }
            return(value);
        }
Esempio n. 11
0
        public ArrayList getSupportedParameterList(int valueTypes)
        {
            ArrayList   arrayList  = new ArrayList();
            IEnumerator enumerator = m_listSupportedParameters.GetEnumerator();

            if (enumerator.MoveNext())
            {
                do
                {
                    OBDParameter obdParameter = (OBDParameter)enumerator.Current;
                    if ((obdParameter.ValueTypes & valueTypes) == valueTypes)
                    {
                        arrayList.Add((object)obdParameter);
                    }
                }while (enumerator.MoveNext());
            }
            return(arrayList);
        }
Esempio n. 12
0
        public OBDParameterValue getSpecialValue(OBDParameter param, bool bEnglishUnits)
        {
            OBDParameterValue value = new OBDParameterValue();

            if (param.Parameter != 0)
            {
                return(null);
            }

            string s = getRawResponse("ATRV");

            m_commLog.AddItem("Response: " + s);
            if (s != null)
            {
                s = s.Replace("V", "");
                value.DoubleValue = double.Parse(s);
            }
            return(value);
        }
Esempio n. 13
0
        public bool InitOBD()
        {
            OBDParameter param = new OBDParameter(1, 0, 0);

            param.ValueTypes = 32;
            OBDParameterValue value = getValue(param, true);

            if (value.ErrorDetected)
            {
                return(false);
            }

            foreach (OBDParameter param2 in m_listAllParameters)
            {
                if (param2.Parameter > 0 && param2.Parameter <= 32 && value.getBitFlag(param2.Parameter - 1))
                {
                    m_listSupportedParameters.Add(param2);
                }
            }
            if (!value.getBitFlag(31))
            {
                return(true);
            }

            param.Parameter = 32;
            value           = getValue(param, true);
            if (value.ErrorDetected)
            {
                return(false);
            }
            foreach (OBDParameter param2 in m_listAllParameters)
            {
                if (param2.Parameter > 32 && param2.Parameter <= 64 && value.getBitFlag(param2.Parameter - 33))
                {
                    m_listSupportedParameters.Add(param2);
                }
            }
            return(true);
        }
Esempio n. 14
0
        private void RebuildSensorGrid()
        {
            panelDisplay.Controls.Clear();
            IEnumerator enumerator = SensorMonitorForm.m_arrayListSensors.GetEnumerator();
            int         num        = 0;

            if (!enumerator.MoveNext())
            {
                return;
            }
            do
            {
                OBDParameter         obdParameter         = (OBDParameter)enumerator.Current;
                SensorDisplayControl sensorDisplayControl = new SensorDisplayControl();
                sensorDisplayControl.Title = obdParameter.Name;
                sensorDisplayControl.Size  = new Size(panelDisplay.Width / 2 - 8, 65);
                sensorDisplayControl.Tag   = (object)obdParameter;
                if (radioDisplayEnglish.Checked)
                {
                    sensorDisplayControl.SetDisplayMode(1);
                }
                else
                {
                    sensorDisplayControl.SetDisplayMode(2);
                }
                sensorDisplayControl.Refresh();
                if (num % 2 != 0)
                {
                    sensorDisplayControl.Location = new Point(panelDisplay.Width / 2 + 3, (sensorDisplayControl.Height + 5) * (num / 2) + 5);
                }
                else
                {
                    sensorDisplayControl.Location = new Point(5, (sensorDisplayControl.Height + 5) * (num / 2) + 5);
                }
                panelDisplay.Controls.Add((Control)sensorDisplayControl);
                ++num;
            }while (enumerator.MoveNext());
        }
Esempio n. 15
0
        public OBDParameter GetCopy()
        {
            OBDParameter p = new OBDParameter();

            p.Category         = Category;
            p.ValueTypes       = ValueTypes;
            p.EnglishMaxValue  = EnglishMaxValue;
            p.EnglishMinValue  = EnglishMinValue;
            p.EnglishUnitLabel = EnglishUnitLabel;
            p.Manufacturer     = Manufacturer;
            p.MetricMaxValue   = MetricMaxValue;
            p.MetricMinValue   = MetricMinValue;
            p.MetricUnitLabel  = MetricUnitLabel;
            p.Name             = Name;
            p.OBDRequest       = OBDRequest;
            p.Parameter        = Parameter;
            p.PID          = PID;
            p.Priority     = Priority;
            p.Service      = Service;
            p.SubParameter = SubParameter;
            p.Type         = Type;
            return(p);
        }
Esempio n. 16
0
 public abstract OBDResponseList Parse(OBDParameter param, string response);
Esempio n. 17
0
        public bool LoadParameters(string fileName)
        {
            int          lineNo = 0;
            string       line;
            OBDParameter param;

            string[] tokens;
            char[]   comma = new char[] { ',' };

            try
            {
                using (StreamReader streamReader = new StreamReader(fileName))
                {
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        ++lineNo;
                        line = line.Trim();
                        // Ignore empty and comment lines
                        if (line.Length == 0 || line[0] == '#')
                        {
                            continue;
                        }

                        try
                        {
                            tokens = line.Split(comma);
                            for (int idx = 0; idx < tokens.Length; idx++)
                            {
                                tokens[idx] = (tokens[idx] ?? "").Trim();
                            }

                            param              = new OBDParameter();
                            param.PID          = tokens[0];
                            param.Name         = tokens[1];
                            param.OBDRequest   = tokens[2];
                            param.Service      = int.Parse(tokens[3]);
                            param.Parameter    = int.Parse(tokens[4]);
                            param.SubParameter = int.Parse(tokens[5]);

                            switch (tokens[6])
                            {
                            case "Airflow":
                                param.Category = 0; break;

                            case "DTC":
                                param.Category = 1; break;

                            case "Emissions":
                                param.Category = 2; break;

                            case "Fuel":
                                param.Category = 3; break;

                            case "General":
                                param.Category = 4; break;

                            case "O2":
                                param.Category = 5; break;

                            case "Powertrain":
                                param.Category = 6; break;

                            case "Speed":
                                param.Category = 7; break;

                            case "Temperature":
                                param.Category = 8; break;
                            }
                            switch (tokens[7])
                            {
                            case "Generic":
                                param.Type = 0; break;

                            case "Manufacturer":
                                param.Type = 1; break;

                            case "Scripted":
                                param.Type = 2; break;
                            }

                            switch (tokens[8])
                            {
                            case "SAE":
                                param.Manufacturer = 0; break;

                            case "GM":
                                param.Manufacturer = 1; break;

                            case "Ford":
                                param.Manufacturer = 2; break;

                            case "ProScan":
                                param.Manufacturer = 3; break;
                            }

                            param.Priority         = int.Parse(tokens[9]);
                            param.EnglishUnitLabel = tokens[10];
                            param.MetricUnitLabel  = tokens[11];

                            try
                            {
                                param.EnglishMinValue = Utility.Text2Double(tokens[12]);
                                param.EnglishMaxValue = Utility.Text2Double(tokens[13]);
                                param.MetricMinValue  = Utility.Text2Double(tokens[14]);
                                param.MetricMaxValue  = Utility.Text2Double(tokens[15]);
                            }
                            catch { }

                            int valueType = 0x00;
                            if (int.Parse(tokens[16]) > 0)
                            {
                                valueType = 0x01;
                            }
                            if (int.Parse(tokens[17]) > 0)
                            {
                                valueType |= 0x02;
                            }
                            if (int.Parse(tokens[18]) > 0)
                            {
                                valueType |= 0x04;
                            }
                            if (int.Parse(tokens[19]) > 0)
                            {
                                valueType |= 0x08;
                            }

                            param.ValueTypes = valueType;
                            m_listAllParameters.Add(param);
                        }
                        catch (Exception)
                        {
                            m_commLog.AddItem(string.Format("Failed to load parameters from {0}", fileName));
                            return(false);
                        }
                    }
                }
                m_commLog.AddItem(string.Format("Loaded {0} parameters from {1}", lineNo, fileName));
                return(true);
            }
            catch (Exception)
            {
                m_commLog.AddItem(string.Format("Failed to locate parameter file: {0}", fileName));
                return(false);
            }
        }
Esempio n. 18
0
        public override OBDResponseList Parse(OBDParameter param, string response)
        {
            if (string.IsNullOrEmpty(response))
            {
                response = "";
            }

            OBDResponseList responseList = new OBDResponseList(response);

            response = Strip(response);
            if (ErrorCheck(response))
            {
                responseList.ErrorDetected = true;
                return(responseList);
            }

            List <string> lines = SplitByCR(response);

            lines.Sort();
            List <List <string> > groups = new List <List <string> >();
            List <string>         group  = new List <string>();
            string line0 = lines[0];

            group.Add(line0);
            groups.Add(group);
            if (line0.Length < OBDParser_ISO15765_4_CAN11.HEADER_LENGTH)
            {
                responseList.ErrorDetected = true;
                return(responseList);
            }

            string header = line0.Substring(0, OBDParser_ISO15765_4_CAN11.HEADER_LENGTH);
            int    idx    = 1;

            while (idx < lines.Count)
            {
                string line = lines[idx];
                if (line.Length >= OBDParser_ISO15765_4_CAN11.HEADER_LENGTH)
                {
                    if (line.Substring(0, OBDParser_ISO15765_4_CAN11.HEADER_LENGTH).CompareTo(header) == 0)
                    {
                        group.Add(line);
                    }
                    else
                    {
                        group = new List <string>();
                        group.Add(lines[idx]);
                        groups.Add(group);
                        header = line.Substring(0, OBDParser_ISO15765_4_CAN11.HEADER_LENGTH);
                    }
                    ++idx;
                }
                else
                {
                    responseList.ErrorDetected = true;
                    return(responseList);
                }
            }

            idx = 0;
            while (idx < groups.Count)
            {
                OBDResponse obd_response = new OBDResponse();
                bool        bIsMultiline = false;
                group = groups[idx];
                if (group.Count > 1)
                {
                    bIsMultiline = true;
                }
                int    dataStartIndex1 = getDataStartIndex(param, bIsMultiline, false);
                string str2            = group[0];
                int    length1         = str2.Length - dataStartIndex1;
                obd_response.Header = str2.Substring(0, OBDParser_ISO15765_4_CAN11.HEADER_LENGTH);
                obd_response.Data   = length1 > 0 ? str2.Substring(dataStartIndex1, length1) : "";
                int dataStartIndex2 = getDataStartIndex(param, bIsMultiline, true);
                int sub_idx         = 1;
                while (sub_idx < group.Count)
                {
                    string str3    = group[sub_idx];
                    int    length2 = str3.Length - dataStartIndex2;
                    obd_response.Data = obd_response.Data + (length2 > 0 ? str3.Substring(dataStartIndex2, length2) : "");
                    ++sub_idx;
                }
                responseList.AddOBDResponse(obd_response);
                ++idx;
            }
            return(responseList);
        }
Esempio n. 19
0
        public override OBDResponseList Parse(OBDParameter param, string response)
        {
            if (string.IsNullOrEmpty(response))
            {
                response = "";
            }

            OBDResponseList responseList = new OBDResponseList(response);

            response = Strip(response);
            if (ErrorCheck(response))
            {
                responseList.ErrorDetected = true;
                return(responseList);
            }
            else
            {
                List <string> list1 = SplitByCR(response);
                list1.Sort();
                List <List <string> > list2 = new List <List <string> >();
                List <string>         list3 = new List <string>();
                string str1 = list1[0];
                list3.Add(str1);
                list2.Add(list3);
                if (str1.Length < OBDParser_ISO14230_4_KWP.HEADER_LENGTH)
                {
                    responseList.ErrorDetected = true;
                    return(responseList);
                }
                else
                {
                    string strB   = str1.Substring(0, OBDParser_ISO14230_4_KWP.HEADER_LENGTH);
                    int    index1 = 1;
                    if (1 < list1.Count)
                    {
                        do
                        {
                            string str2 = list1[index1];
                            if (str2.Length >= OBDParser_ISO14230_4_KWP.HEADER_LENGTH)
                            {
                                if (str2.Substring(0, OBDParser_ISO14230_4_KWP.HEADER_LENGTH).CompareTo(strB) == 0)
                                {
                                    list3.Add(str2);
                                }
                                else
                                {
                                    list3 = new List <string>();
                                    list3.Add(list1[index1]);
                                    list2.Add(list3);
                                    strB = str2.Substring(0, OBDParser_ISO14230_4_KWP.HEADER_LENGTH);
                                }
                                ++index1;
                            }
                            else
                            {
                                goto label_14;
                            }
                        }while (index1 < list1.Count);
                        goto label_15;
label_14:
                        responseList.ErrorDetected = true;
                        return(responseList);
                    }
label_15:
                    int index2 = 0;
                    if (0 < list2.Count)
                    {
                        do
                        {
                            OBDResponse   response1      = new OBDResponse();
                            List <string> list4          = list2[index2];
                            int           dataStartIndex = getDataStartIndex(param);
                            string        str2           = list4[0];
                            int           num1           = -2 - dataStartIndex;
                            int           length1        = str2.Length + num1;
                            response1.Header = str2.Substring(0, OBDParser_ISO14230_4_KWP.HEADER_LENGTH);
                            response1.Data   = length1 > 0 ? str2.Substring(dataStartIndex, length1) : "";
                            int index3 = 1;
                            if (1 < list4.Count)
                            {
                                int num2 = num1;
                                do
                                {
                                    string str3    = list4[index3];
                                    int    length2 = str3.Length + num2;
                                    string str4    = length2 > 0 ? str3.Substring(dataStartIndex, length2) : "";
                                    response1.Data = response1.Data + str4;
                                    ++index3;
                                }while (index3 < list4.Count);
                            }
                            responseList.AddOBDResponse(response1);
                            ++index2;
                        }while (index2 < list2.Count);
                    }
                    return(responseList);
                }
            }
        }
Esempio n. 20
0
        public override OBDResponseList Parse(OBDParameter param, string response)
        {
            if (string.IsNullOrEmpty(response))
            {
                response = "";
            }

            OBDResponseList responseList = new OBDResponseList(response);

            response = Strip(response);
            if (ErrorCheck(response))
            {
                responseList.ErrorDetected = true;
                return(responseList);
            }

            List <string> lines = SplitByCR(response);

            lines.Sort();

            List <List <string> > groups = new List <List <string> >();
            List <string>         group  = new List <string>();
            string line0 = lines[0];

            group.Add(line0);
            groups.Add(group);

            if (line0.Length < OBDParser_J1850_VPW.HEADER_LENGTH)
            {
                responseList.ErrorDetected = true;
                return(responseList);
            }

            string header = line0.Substring(0, OBDParser_J1850_VPW.HEADER_LENGTH);
            int    idx    = 1;

            while (idx < lines.Count)
            {
                string line = lines[idx];
                if (line.Length >= OBDParser_J1850_VPW.HEADER_LENGTH)
                {
                    if (line.Substring(0, OBDParser_J1850_VPW.HEADER_LENGTH).CompareTo(header) == 0)
                    {
                        group.Add(line);
                    }
                    else
                    {
                        group = new List <string>();
                        group.Add(lines[idx]);
                        groups.Add(group);
                        header = line.Substring(0, OBDParser_J1850_VPW.HEADER_LENGTH);
                    }
                    ++idx;
                }
                else
                {
                    responseList.ErrorDetected = true;
                    return(responseList);
                }
            }

            idx = 0;
            while (idx < groups.Count)
            {
                OBDResponse obd_response = new OBDResponse();
                group = groups[idx];
                int dataStartIndex = getDataStartIndex(param);
                header = group[0];
                int num1        = -2 - dataStartIndex;
                int data_length = header.Length + num1;
                obd_response.Header = header.Substring(0, OBDParser_J1850_VPW.HEADER_LENGTH);
                obd_response.Data   = data_length > 0 ? header.Substring(dataStartIndex, data_length) : "";
                int sub_idx = 1;
                while (sub_idx < group.Count)
                {
                    string line    = group[sub_idx];
                    int    length2 = line.Length + num1;
                    obd_response.Data = obd_response.Data + (length2 > 0 ? line.Substring(dataStartIndex, length2) : "");
                    ++sub_idx;
                }
                responseList.AddOBDResponse(obd_response);
                ++idx;
            }
            return(responseList);
        }
Esempio n. 21
0
        public bool loadParameters(string fileName)
        {
            try
            {
                int    lineNo = 0;
                string line;
                char[] chArray = new char[] { ',' };

                using (StreamReader streamReader = new StreamReader(fileName))
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        try
                        {
                            string[] strArray = line.Split(chArray);

                            OBDParameter obdParameter = new OBDParameter();
                            obdParameter.PID          = strArray[0];
                            obdParameter.Name         = strArray[1];
                            obdParameter.OBDRequest   = strArray[2];
                            obdParameter.Service      = int.Parse(strArray[3]);
                            obdParameter.Parameter    = int.Parse(strArray[4]);
                            obdParameter.SubParameter = int.Parse(strArray[5]);

                            if (strArray[6].CompareTo("Airflow") == 0)
                            {
                                obdParameter.Category = 0;
                            }
                            else if (strArray[6].CompareTo("DTC") == 0)
                            {
                                obdParameter.Category = 1;
                            }
                            else if (strArray[6].CompareTo("Emissions") == 0)
                            {
                                obdParameter.Category = 2;
                            }
                            else if (strArray[6].CompareTo("Fuel") == 0)
                            {
                                obdParameter.Category = 3;
                            }
                            else if (strArray[6].CompareTo("General") == 0)
                            {
                                obdParameter.Category = 4;
                            }
                            else if (strArray[6].CompareTo("O2") == 0)
                            {
                                obdParameter.Category = 5;
                            }
                            else if (strArray[6].CompareTo("Powertrain") == 0)
                            {
                                obdParameter.Category = 6;
                            }
                            else if (strArray[6].CompareTo("Speed") == 0)
                            {
                                obdParameter.Category = 7;
                            }
                            else if (strArray[6].CompareTo("Temperature") == 0)
                            {
                                obdParameter.Category = 8;
                            }

                            if (strArray[7].CompareTo("Generic") == 0)
                            {
                                obdParameter.Type = 0;
                            }
                            else if (strArray[7].CompareTo("Manufacturer") == 0)
                            {
                                obdParameter.Type = 1;
                            }
                            else if (strArray[7].CompareTo("Scripted") == 0)
                            {
                                obdParameter.Type = 2;
                            }

                            if (strArray[8].CompareTo("SAE") == 0)
                            {
                                obdParameter.Manufacturer = 0;
                            }
                            else if (strArray[8].CompareTo("GM") == 0)
                            {
                                obdParameter.Manufacturer = 1;
                            }
                            else if (strArray[8].CompareTo("Ford") == 0)
                            {
                                obdParameter.Manufacturer = 2;
                            }
                            else if (strArray[8].CompareTo("ProScan") == 0)
                            {
                                obdParameter.Manufacturer = 3;
                            }

                            obdParameter.Priority         = int.Parse(strArray[9]);
                            obdParameter.EnglishUnitLabel = strArray[10];
                            obdParameter.MetricUnitLabel  = strArray[11];

                            try
                            {
                                obdParameter.EnglishMinValue = double.Parse(strArray[12]);
                                obdParameter.EnglishMaxValue = double.Parse(strArray[13]);
                                obdParameter.MetricMinValue  = double.Parse(strArray[14]);
                                obdParameter.MetricMaxValue  = double.Parse(strArray[15]);
                            }
                            catch { }

                            int valueType = 0;
                            if (int.Parse(strArray[16]) > 0)
                            {
                                valueType = 1;
                            }
                            if (int.Parse(strArray[17]) > 0)
                            {
                                valueType |= 2;
                            }
                            if (int.Parse(strArray[18]) > 0)
                            {
                                valueType |= 4;
                            }
                            if (int.Parse(strArray[19]) > 0)
                            {
                                valueType |= 8;
                            }

                            obdParameter.ValueTypes = valueType;
                            m_listAllParameters.Add(obdParameter);
                            ++lineNo;
                        }
                        catch (Exception)
                        {
                            m_commLog.AddItem(string.Format("Failed to load parameters from {0}", fileName));
                            return(false);
                        }
                    }
                m_commLog.AddItem(string.Format("Loaded {0} parameters from {1}", lineNo.ToString(), fileName));
                return(true);
            }
            catch (Exception)
            {
                m_commLog.AddItem(string.Format("Failed to locate parameter file: {0}", fileName));
                return(false);
            }
        }
Esempio n. 22
0
 public abstract OBDResponseList Query(OBDParameter param);
Esempio n. 23
0
 public override OBDResponseList Query(OBDParameter param)
 {
     return(m_Parser.Parse(param, getOBDResponse(param.OBDRequest)));
 }
Esempio n. 24
0
        private void ReadFreezeFrameData(object state)
        {
            freezeFrame.Reset();
            progressBar.Value = 0;
            OBDParameter parameter = m_obdInterface.lookupParameter("SAE.FF_DTC");

            if (parameter != null)
            {
                OBDParameter      freezeFrameCopy = parameter.GetFreezeFrameCopy(m_iFrameNumber);
                OBDParameterValue value2          = m_obdInterface.getValue(freezeFrameCopy, true);
                if (value2.ErrorDetected)
                {
                    MessageBox.Show("An error was encountered while requesting SAE.FF_DTC", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    m_obdInterface.logItem("Error while requesting SAE.FF_DTC");
                    progressBar.Value = progressBar.Maximum;
                }
                else
                {
                    bool flag = false;
                    if (string.Compare(value2.StringValue, "P0000") != 0)
                    {
                        freezeFrame.DTC = value2.StringValue;
                        flag            = true;
                    }
                    progressBar.Increment(progressBar.Step);
                    if (m_bKeepReading)
                    {
                        if (flag)
                        {
                            parameter = m_obdInterface.lookupParameter("SAE.FUEL1_STATUS");
                            if (parameter == null)
                            {
                                return;
                            }
                            OBDParameter      param   = parameter.GetFreezeFrameCopy(m_iFrameNumber);
                            OBDParameterValue value17 = m_obdInterface.getValue(param, true);
                            if (!value17.ErrorDetected)
                            {
                                freezeFrame.FuelSystem1Status = value17.StringValue;
                            }
                            parameter = m_obdInterface.lookupParameter("SAE.FUEL2_STATUS");
                            if (parameter == null)
                            {
                                return;
                            }
                            OBDParameter      parameter16 = parameter.GetFreezeFrameCopy(m_iFrameNumber);
                            OBDParameterValue value16     = m_obdInterface.getValue(parameter16, true);
                            if (!value16.ErrorDetected)
                            {
                                freezeFrame.FuelSystem2Status = value16.StringValue;
                            }
                            progressBar.Increment(progressBar.Step);
                            if (!m_bKeepReading)
                            {
                                return;
                            }
                            parameter = m_obdInterface.lookupParameter("SAE.LOAD_CALC");
                            if (parameter == null)
                            {
                                return;
                            }
                            OBDParameter      parameter15 = parameter.GetFreezeFrameCopy(m_iFrameNumber);
                            OBDParameterValue value15     = m_obdInterface.getValue(parameter15, true);
                            if (!value15.ErrorDetected)
                            {
                                freezeFrame.CalculatedLoad = value15.DoubleValue;
                            }
                            progressBar.Increment(progressBar.Step);
                            if (!m_bKeepReading)
                            {
                                return;
                            }
                            parameter = m_obdInterface.lookupParameter("SAE.ECT");
                            if (parameter == null)
                            {
                                return;
                            }
                            OBDParameter      parameter14 = parameter.GetFreezeFrameCopy(m_iFrameNumber);
                            OBDParameterValue value14     = m_obdInterface.getValue(parameter14, true);
                            if (!value14.ErrorDetected)
                            {
                                freezeFrame.EngineCoolantTemp = value14.DoubleValue;
                            }
                            progressBar.Increment(progressBar.Step);
                            if (!m_bKeepReading)
                            {
                                return;
                            }
                            parameter = m_obdInterface.lookupParameter("SAE.STFT1");
                            if (parameter == null)
                            {
                                return;
                            }
                            OBDParameter      parameter13 = parameter.GetFreezeFrameCopy(m_iFrameNumber);
                            OBDParameterValue value13     = m_obdInterface.getValue(parameter13, true);
                            if (!value13.ErrorDetected)
                            {
                                freezeFrame.STFT1 = value13.DoubleValue;
                            }
                            parameter = m_obdInterface.lookupParameter("SAE.STFT3");
                            if (parameter == null)
                            {
                                return;
                            }
                            OBDParameter      parameter12 = parameter.GetFreezeFrameCopy(m_iFrameNumber);
                            OBDParameterValue value12     = m_obdInterface.getValue(parameter12, true);
                            if (!value12.ErrorDetected)
                            {
                                freezeFrame.STFT3 = value12.DoubleValue;
                            }
                            progressBar.Increment(progressBar.Step);
                            if (!m_bKeepReading)
                            {
                                return;
                            }
                            parameter = m_obdInterface.lookupParameter("SAE.LTFT1");
                            if (parameter == null)
                            {
                                return;
                            }
                            OBDParameter      parameter11 = parameter.GetFreezeFrameCopy(m_iFrameNumber);
                            OBDParameterValue value11     = m_obdInterface.getValue(parameter11, true);
                            if (!value11.ErrorDetected)
                            {
                                freezeFrame.LTFT1 = value11.DoubleValue;
                            }
                            parameter = m_obdInterface.lookupParameter("SAE.LTFT3");
                            if (parameter == null)
                            {
                                return;
                            }
                            OBDParameter      parameter10 = parameter.GetFreezeFrameCopy(m_iFrameNumber);
                            OBDParameterValue value10     = m_obdInterface.getValue(parameter10, true);
                            if (!value10.ErrorDetected)
                            {
                                freezeFrame.LTFT3 = value10.DoubleValue;
                            }
                            progressBar.Increment(progressBar.Step);
                            if (!m_bKeepReading)
                            {
                                return;
                            }
                            parameter = m_obdInterface.lookupParameter("SAE.STFT2");
                            if (parameter == null)
                            {
                                return;
                            }
                            OBDParameter      parameter9 = parameter.GetFreezeFrameCopy(m_iFrameNumber);
                            OBDParameterValue value9     = m_obdInterface.getValue(parameter9, true);
                            if (!value9.ErrorDetected)
                            {
                                freezeFrame.STFT2 = value9.DoubleValue;
                            }
                            parameter = m_obdInterface.lookupParameter("SAE.STFT4");
                            if (parameter == null)
                            {
                                return;
                            }
                            OBDParameter      parameter8 = parameter.GetFreezeFrameCopy(m_iFrameNumber);
                            OBDParameterValue value8     = m_obdInterface.getValue(parameter8, true);
                            if (!value8.ErrorDetected)
                            {
                                freezeFrame.STFT4 = value8.DoubleValue;
                            }
                            progressBar.Increment(progressBar.Step);
                            if (!m_bKeepReading)
                            {
                                return;
                            }
                            parameter = m_obdInterface.lookupParameter("SAE.LTFT2");
                            if (parameter == null)
                            {
                                return;
                            }
                            OBDParameter      parameter7 = parameter.GetFreezeFrameCopy(m_iFrameNumber);
                            OBDParameterValue value7     = m_obdInterface.getValue(parameter7, true);
                            if (!value7.ErrorDetected)
                            {
                                freezeFrame.LTFT2 = value7.DoubleValue;
                            }
                            parameter = m_obdInterface.lookupParameter("SAE.LTFT4");
                            if (parameter == null)
                            {
                                return;
                            }
                            OBDParameter      parameter6 = parameter.GetFreezeFrameCopy(m_iFrameNumber);
                            OBDParameterValue value6     = m_obdInterface.getValue(parameter6, true);
                            if (!value6.ErrorDetected)
                            {
                                freezeFrame.LTFT4 = value6.DoubleValue;
                            }
                            progressBar.Increment(progressBar.Step);
                            if (!m_bKeepReading)
                            {
                                return;
                            }
                            parameter = m_obdInterface.lookupParameter("SAE.MAP");
                            if (parameter == null)
                            {
                                return;
                            }
                            OBDParameter      parameter5 = parameter.GetFreezeFrameCopy(m_iFrameNumber);
                            OBDParameterValue value5     = m_obdInterface.getValue(parameter5, true);
                            if (!value5.ErrorDetected)
                            {
                                freezeFrame.IntakePressure = value5.DoubleValue;
                            }
                            progressBar.Increment(progressBar.Step);
                            if (!m_bKeepReading)
                            {
                                return;
                            }
                            parameter = m_obdInterface.lookupParameter("SAE.RPM");
                            if (parameter == null)
                            {
                                return;
                            }
                            OBDParameter      parameter4 = parameter.GetFreezeFrameCopy(m_iFrameNumber);
                            OBDParameterValue value4     = m_obdInterface.getValue(parameter4, true);
                            if (!value4.ErrorDetected)
                            {
                                freezeFrame.EngineRPM = value4.DoubleValue;
                            }
                            progressBar.Increment(progressBar.Step);
                            if (!m_bKeepReading)
                            {
                                return;
                            }
                            parameter = m_obdInterface.lookupParameter("SAE.VSS");
                            if (parameter == null)
                            {
                                return;
                            }
                            OBDParameter      parameter3 = parameter.GetFreezeFrameCopy(m_iFrameNumber);
                            OBDParameterValue value3     = m_obdInterface.getValue(parameter3, true);
                            if (!value3.ErrorDetected)
                            {
                                freezeFrame.VehicleSpeed = value3.DoubleValue;
                            }
                            progressBar.Increment(progressBar.Step);
                            if (!m_bKeepReading)
                            {
                                return;
                            }
                            parameter = m_obdInterface.lookupParameter("SAE.SPARKADV");
                            if (parameter == null)
                            {
                                return;
                            }
                            freezeFrameCopy = parameter.GetFreezeFrameCopy(m_iFrameNumber);
                            value2          = m_obdInterface.getValue(freezeFrameCopy, true);
                            if (!value2.ErrorDetected)
                            {
                                freezeFrame.SparkAdvance = value2.DoubleValue;
                            }
                            progressBar.Increment(progressBar.Step);
                        }
                        else
                        {
                            MessageBox.Show(string.Format("No freeze frame information found at frame #{0}.", m_iFrameNumber), "Information", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }
                        progressBar.Value  = progressBar.Maximum;
                        btnRefresh.Enabled = true;
                        btnCancel.Enabled  = false;
                    }
                }
            }
        }
Esempio n. 25
0
        private void ReadFreezeFrameData(object state)
        {
            for (; ;)
            {
                freezeFrame.Reset();
                OBDParameter parameter = m_obdInterface.LookupParameter("SAE.FF_DTC");
                if (parameter == null)
                {
                    MessageBox.Show(
                        "An error was encountered while requesting SAE.FF_DTC",
                        "Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Hand
                        );
                    break;
                }

                OBDParameterValue value = m_obdInterface.getValue(parameter.GetFreezeFrameCopy(m_FrameNumber), true);
                if (value.ErrorDetected)
                {
                    MessageBox.Show(
                        "An error was encountered while requesting SAE.FF_DTC",
                        "Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Hand
                        );
                    m_obdInterface.logItem("Error while requesting SAE.FF_DTC");
                    break;
                }

                if (string.Compare(value.StringValue, "P0000") == 0)
                {
                    MessageBox.Show(
                        string.Format("No freeze frame information found at frame #{0}.", m_FrameNumber),
                        "Information",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Asterisk
                        );
                    break;
                }

                progressBar.Value = 0;
                freezeFrame.DTC   = value.StringValue;

                parameter = m_obdInterface.LookupParameter("SAE.FUEL1_STATUS");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.getValue(parameter.GetFreezeFrameCopy(m_FrameNumber), true);
                if (!value.ErrorDetected)
                {
                    freezeFrame.FuelSystem1Status = value.StringValue;
                }

                parameter = m_obdInterface.LookupParameter("SAE.FUEL2_STATUS");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.getValue(parameter.GetFreezeFrameCopy(m_FrameNumber), true);
                if (!value.ErrorDetected)
                {
                    freezeFrame.FuelSystem2Status = value.StringValue;
                }

                progressBar.Increment(progressBar.Step);
                if (!m_KeepReading)
                {
                    break;
                }

                parameter = m_obdInterface.LookupParameter("SAE.LOAD_CALC");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.getValue(parameter.GetFreezeFrameCopy(m_FrameNumber), true);
                if (!value.ErrorDetected)
                {
                    freezeFrame.CalculatedLoad = value.DoubleValue;
                }

                progressBar.Increment(progressBar.Step);
                if (!m_KeepReading)
                {
                    break;
                }

                parameter = m_obdInterface.LookupParameter("SAE.ECT");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.getValue(parameter.GetFreezeFrameCopy(m_FrameNumber), true);
                if (!value.ErrorDetected)
                {
                    freezeFrame.EngineCoolantTemp = value.DoubleValue;
                }

                progressBar.Increment(progressBar.Step);
                if (!m_KeepReading)
                {
                    break;
                }

                parameter = m_obdInterface.LookupParameter("SAE.STFT1");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.getValue(parameter.GetFreezeFrameCopy(m_FrameNumber), true);
                if (!value.ErrorDetected)
                {
                    freezeFrame.STFT1 = value.DoubleValue;
                }

                parameter = m_obdInterface.LookupParameter("SAE.STFT3");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.getValue(parameter.GetFreezeFrameCopy(m_FrameNumber), true);
                if (!value.ErrorDetected)
                {
                    freezeFrame.STFT3 = value.DoubleValue;
                }

                progressBar.Increment(progressBar.Step);
                if (!m_KeepReading)
                {
                    break;
                }

                parameter = m_obdInterface.LookupParameter("SAE.LTFT1");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.getValue(parameter.GetFreezeFrameCopy(m_FrameNumber), true);
                if (!value.ErrorDetected)
                {
                    freezeFrame.LTFT1 = value.DoubleValue;
                }

                parameter = m_obdInterface.LookupParameter("SAE.LTFT3");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.getValue(parameter.GetFreezeFrameCopy(m_FrameNumber), true);
                if (!value.ErrorDetected)
                {
                    freezeFrame.LTFT3 = value.DoubleValue;
                }

                progressBar.Increment(progressBar.Step);
                if (!m_KeepReading)
                {
                    break;
                }

                parameter = m_obdInterface.LookupParameter("SAE.STFT2");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.getValue(parameter.GetFreezeFrameCopy(m_FrameNumber), true);
                if (!value.ErrorDetected)
                {
                    freezeFrame.STFT2 = value.DoubleValue;
                }

                parameter = m_obdInterface.LookupParameter("SAE.STFT4");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.getValue(parameter.GetFreezeFrameCopy(m_FrameNumber), true);
                if (!value.ErrorDetected)
                {
                    freezeFrame.STFT4 = value.DoubleValue;
                }

                progressBar.Increment(progressBar.Step);
                if (!m_KeepReading)
                {
                    break;
                }

                parameter = m_obdInterface.LookupParameter("SAE.LTFT2");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.getValue(parameter.GetFreezeFrameCopy(m_FrameNumber), true);
                if (!value.ErrorDetected)
                {
                    freezeFrame.LTFT2 = value.DoubleValue;
                }

                parameter = m_obdInterface.LookupParameter("SAE.LTFT4");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.getValue(parameter.GetFreezeFrameCopy(m_FrameNumber), true);
                if (!value.ErrorDetected)
                {
                    freezeFrame.LTFT4 = value.DoubleValue;
                }

                progressBar.Increment(progressBar.Step);
                if (!m_KeepReading)
                {
                    break;
                }

                parameter = m_obdInterface.LookupParameter("SAE.MAP");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.getValue(parameter.GetFreezeFrameCopy(m_FrameNumber), true);
                if (!value.ErrorDetected)
                {
                    freezeFrame.IntakePressure = value.DoubleValue;
                }

                progressBar.Increment(progressBar.Step);
                if (!m_KeepReading)
                {
                    break;
                }

                parameter = m_obdInterface.LookupParameter("SAE.RPM");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.getValue(parameter.GetFreezeFrameCopy(m_FrameNumber), true);
                if (!value.ErrorDetected)
                {
                    freezeFrame.EngineRPM = value.DoubleValue;
                }

                progressBar.Increment(progressBar.Step);
                if (!m_KeepReading)
                {
                    break;
                }

                parameter = m_obdInterface.LookupParameter("SAE.VSS");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.getValue(parameter.GetFreezeFrameCopy(m_FrameNumber), true);
                if (!value.ErrorDetected)
                {
                    freezeFrame.VehicleSpeed = value.DoubleValue;
                }

                progressBar.Increment(progressBar.Step);
                if (!m_KeepReading)
                {
                    break;
                }

                parameter = m_obdInterface.LookupParameter("SAE.SPARKADV");
                if (parameter == null)
                {
                    break;
                }

                value = m_obdInterface.getValue(parameter.GetFreezeFrameCopy(m_FrameNumber), true);
                if (!value.ErrorDetected)
                {
                    freezeFrame.SparkAdvance = value.DoubleValue;
                }

                break;
            }
            progressBar.Value  = progressBar.Maximum;
            btnRefresh.Enabled = true;
            btnCancel.Enabled  = false;
        }
Esempio n. 26
0
        public override OBDResponseList query(OBDParameter param)
        {
            string obdResponse = getOBDResponse(param.OBDRequest);

            return(m_Parser.parse(param, obdResponse));
        }
Esempio n. 27
0
        public OBDParameterValue getValue(OBDParameter param, bool bEnglishUnits)
        {
            if (param.PID.Length > 0)
            {
                m_commLog.AddItem("Requesting " + param.PID);
            }
            else
            {
                m_commLog.AddItem("Requesting " + param.OBDRequest);
            }

            if (param.Service == 0)
            {
                return(getSpecialValue(param, bEnglishUnits));
            }

            OBDResponseList responses = m_obdDevice.query(param);
            string          strItem1  = "Responses: ";
            int             index1    = 0;

            if (0 < responses.ResponseCount)
            {
                do
                {
                    strItem1 = strItem1 + string.Format("[{0}] ", responses.GetOBDResponse(index1).Data);
                    ++index1;
                }while (index1 < responses.ResponseCount);
            }
            m_commLog.AddItem(strItem1);
            OBDParameterValue obdParameterValue = OBDInterpretter.getValue(param, responses, bEnglishUnits);

            if (obdParameterValue.ErrorDetected)
            {
                m_commLog.AddItem("Error Detected!");
                return(obdParameterValue);
            }
            else
            {
                string strItem2 = "Values: ";
                if ((param.ValueTypes & 2) == 2)
                {
                    bool num = obdParameterValue.BoolValue;
                    strItem2 = strItem2 + string.Format("[Bool: {0}] ", num.ToString());
                }
                if ((param.ValueTypes & 1) == 1)
                {
                    double num = obdParameterValue.DoubleValue;
                    strItem2 = strItem2 + string.Format("[Double: {0}] ", num.ToString());
                }
                if ((param.ValueTypes & 4) == 4)
                {
                    strItem2 += string.Format("[String: {0} / {1}] ", obdParameterValue.StringValue, obdParameterValue.ShortStringValue);
                }
                if ((param.ValueTypes & 8) == 8)
                {
                    string           str        = strItem2 + "[StringCollection: ";
                    StringEnumerator enumerator = obdParameterValue.StringCollectionValue.GetEnumerator();
                    if (enumerator.MoveNext())
                    {
                        do
                        {
                            str = str + enumerator.Current + ", ";
                        }while (enumerator.MoveNext());
                    }
                    strItem2 = str + "]";
                }
                if ((param.ValueTypes & 32) == 32)
                {
                    string str    = strItem2 + "[BitFlags: ";
                    int    index2 = 0;
                    do
                    {
                        str += obdParameterValue.getBitFlag(index2) ? "T" : "F";
                        ++index2;
                    }while (index2 < 32);
                    strItem2 = str + " ]";
                }
                m_commLog.AddItem(strItem2);
                return(obdParameterValue);
            }
        }
Esempio n. 28
0
 public override OBDResponseList Parse(OBDParameter param, string response)
 {
     return(new OBDResponseList(response));
 }
Esempio n. 29
0
        public OBDParameterValue getValue(OBDParameter param, bool bEnglishUnits)
        {
            if (param.PID.Length > 0)
            {
                m_commLog.AddItem("Requesting " + param.PID);
            }
            else
            {
                m_commLog.AddItem("Requesting " + param.OBDRequest);
            }

            if (param.Service == 0)
            {
                return(SpecialValue(param, bEnglishUnits));
            }

            OBDResponseList responses = m_obdDevice.Query(param);
            string          strItem1  = "Responses: ";

            if (responses.ResponseCount > 0)
            {
                int count = 0;
                do
                {
                    strItem1 = strItem1 + string.Format("[{0}] ", responses.GetOBDResponse(count).Data);
                    ++count;
                }while (count < responses.ResponseCount);
            }
            m_commLog.AddItem(strItem1);
            OBDParameterValue obdParameterValue = OBDInterpretter.getValue(param, responses, bEnglishUnits);

            if (obdParameterValue.ErrorDetected)
            {
                m_commLog.AddItem("Error Detected!");
                return(obdParameterValue);
            }
            else
            {
                string values = "Values: ";
                if ((param.ValueTypes & 0x01) == 0x01)
                {
                    values = values + string.Format("[Double: {0}] ", obdParameterValue.DoubleValue.ToString());
                }
                if ((param.ValueTypes & 0x02) == 0x02)
                {
                    values = values + string.Format("[Bool: {0}] ", obdParameterValue.BoolValue.ToString());
                }
                if ((param.ValueTypes & 0x04) == 0x04)
                {
                    values += string.Format("[String: {0} / {1}] ", obdParameterValue.StringValue, obdParameterValue.ShortStringValue);
                }
                if ((param.ValueTypes & 0x08) == 0x08)
                {
                    values += "[StringCollection: ";
                    foreach (string strx in obdParameterValue.StringCollectionValue)
                    {
                        values = string.Concat(values, strx + ", ");
                    }
                    values += "]";
                }
                if ((param.ValueTypes & 0x20) == 0x20)
                {
                    values += "[BitFlags: ";
                    for (int idx = 0; idx < 32; idx++)
                    {
                        values += (obdParameterValue.getBitFlag(idx) ? "T" : "F");
                    }
                    values += " ]";
                }
                m_commLog.AddItem(values);
                return(obdParameterValue);
            }
        }