Beispiel #1
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);
        }
Beispiel #2
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);
                }
            }
        }
        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);
        }
Beispiel #4
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);
            }
        }
Beispiel #5
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);
            }
        }