Exemple #1
0
        public OBDResponseList Parse(OBDParameter param, string response, int headLen)
        {
            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> {
                lines[0]
            };

            groups.Add(group);
            if (lines[0].Length < headLen)
            {
                responseList.ErrorDetected = true;
                return(responseList);
            }

            string header = lines[0].Substring(0, headLen);

            for (int i = 1; i < lines.Count; i++)
            {
                if (lines[i].Length >= headLen)
                {
                    if (lines[i].Substring(0, headLen).CompareTo(header) == 0)
                    {
                        group.Add(lines[i]);
                    }
                    else
                    {
                        group = new List <string> {
                            lines[i]
                        };
                        groups.Add(group);
                        header = lines[i].Substring(0, headLen);
                    }
                }
                else
                {
                    responseList.ErrorDetected = true;
                    return(responseList);
                }
            }
            for (int i = 0; i < groups.Count; i++)
            {
                OBDResponse obd_response = new OBDResponse();
                bool        bIsMultiline = false;
                if (groups[i].Count > 1)
                {
                    bIsMultiline = true;
                }
                int dataStartIndex1 = GetDataStartIndex(headLen, param, bIsMultiline, false);
                int length1         = groups[i][0].Length - dataStartIndex1;
                obd_response.Header = groups[i][0].Substring(0, headLen);
                obd_response.Data   = length1 > 0 ? groups[i][0].Substring(dataStartIndex1, length1) : "";
                int dataStartIndex2 = GetDataStartIndex(headLen, param, bIsMultiline, true);
                for (int j = 1; j < groups[i].Count; j++)
                {
                    int length2 = groups[i][j].Length - dataStartIndex2;
                    obd_response.Data += (length2 > 0 ? groups[i][j].Substring(dataStartIndex2, length2) : "");
                }
                responseList.AddOBDResponse(obd_response);
            }
            return(responseList);
        }
Exemple #2
0
 public void AddOBDResponse(OBDResponse response)
 {
     m_Responses.Add(response);
 }