コード例 #1
0
        public OBDResponseList GetResponseList(OBDParameter param)
        {
            OBDResponseList responses = m_obdDevice.Query(param);
            string          strItem   = "Responses: ";

            for (int i = 0; i < responses.ResponseCount; i++)
            {
                strItem += string.Format("[{0}] ", responses.GetOBDResponse(i).Data);
            }
            m_log.TraceInfo(strItem);
            return(responses);
        }
コード例 #2
0
        public List <OBDParameterValue> GetValueList(OBDParameter param, bool bEnglishUnits = false)
        {
            List <OBDParameterValue> ValueList = new List <OBDParameterValue>();

            if (param.PID.Length > 0)
            {
                m_log.TraceInfo("Requesting: " + param.PID);
            }
            else
            {
                m_log.TraceInfo("Requesting: " + param.OBDRequest);
            }
            OBDResponseList responses = m_obdDevice.Query(param);
            string          strItem   = "Responses: ";

            if (responses.ErrorDetected)
            {
                strItem += "Error Detected!";
                OBDParameterValue value = new OBDParameterValue {
                    ErrorDetected    = true,
                    StringValue      = "Error Detected in OBDResponseList!",
                    ShortStringValue = "ERROR_RESP"
                };
                ValueList.Add(value);
                m_log.TraceInfo(strItem);
                return(ValueList);
            }
            else
            {
                for (int i = 0; i < responses.ResponseCount; i++)
                {
                    strItem += string.Format("[{0}] ", responses.GetOBDResponse(i).Data);
                }
                strItem = strItem.TrimEnd();
                m_log.TraceInfo(strItem);
            }

            for (int i = 0; i < responses.ResponseCount; i++)
            {
                OBDParameterValue obdValue = m_obdInterpreter.GetValue(param, responses.GetOBDResponse(i), bEnglishUnits);
                if (obdValue.ErrorDetected)
                {
                    m_log.TraceError("Error Detected in OBDParameterValue!");
                }
                else
                {
                    m_log.TraceInfo(GetLogString(param, obdValue));
                }
                ValueList.Add(obdValue);
            }
            return(ValueList);
        }
コード例 #3
0
        public OBDParameterValue GetValue(OBDParameter param, bool bEnglishUnits = false)
        {
            if (param.PID.Length > 0)
            {
                m_log.TraceInfo("Requesting: " + param.PID);
            }
            else
            {
                m_log.TraceInfo("Requesting: " + param.OBDRequest);
            }
            if (param.Service == 0)
            {
                return(SpecialValue(param));
            }

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

            if (responses.ErrorDetected)
            {
                strItem += "Error Detected!";
                m_log.TraceInfo(strItem);
                return(new OBDParameterValue {
                    ErrorDetected = true
                });
            }
            else
            {
                for (int i = 0; i < responses.ResponseCount; i++)
                {
                    strItem += string.Format("[{0}] ", responses.GetOBDResponse(i).Data);
                }
            }
            m_log.TraceInfo(strItem);
            OBDParameterValue obdValue = m_obdInterpreter.GetValue(param, responses, bEnglishUnits);

            if (obdValue.ErrorDetected)
            {
                m_log.TraceError("Error Detected in OBDParameterValue!");
            }
            else
            {
                m_log.TraceInfo(GetLogString(param, obdValue));
            }
            return(obdValue);
        }
コード例 #4
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);
        }