Example #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);
        }
Example #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);
            }

            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);
        }
Example #3
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);
                }
            }
        }
Example #4
0
 public void AddOBDResponse(OBDResponse response)
 {
     m_Responses.Add(response);
 }