Пример #1
0
        private OBDParameterValue GetJ1939Value(OBDParameter param, OBDResponse response)
        {
            OBDParameterValue value2 = new OBDParameterValue();

            if (response.Header.Substring(2, 2) == "E8")
            {
                // J1939的确认消息,非正确的返回值
                value2.ErrorDetected = true;
                return(value2);
            }
            switch (param.Parameter)
            {
            case 0xFECE:
                value2 = GetDM5Value(param, response);
                break;

            case 0xD300:
                value2 = GetDM19Value(param, response);
                break;

            case 0xFEEC:
                // VIN
                value2.ListStringValue = SetMode09ASCII(17 * 2, response);
                break;
            }
            return(value2);
        }
Пример #2
0
        private OBDParameterValue GetDM19Value(OBDParameter param, OBDResponse response)
        {
            OBDParameterValue value2 = new OBDParameterValue();

            if (response.GetDataByteCount() < 20)
            {
                value2.ErrorDetected = true;
                return(value2);
            }

            int    qty             = response.Data.Length / (20 * 2);
            string strData         = "";
            int    OriginalParam   = param.Parameter;
            int    OriginalService = param.Service;

            param.Service = 9;
            switch (param.SignalName)
            {
            case "CVN":
                param.Parameter = 0x06;
                for (int i = 0; i < qty; i++)
                {
                    strData += response.Data.Substring(i * 20 * 2, 4 * 2);
                }
                response.Data = strData;
                value2        = GetMode010209Value(param, response);
                for (int i = 0; i < value2.ListStringValue.Count; i++)
                {
                    string strVal = value2.ListStringValue[i];
                    value2.ListStringValue[i] = strVal.Substring(6, 2) + strVal.Substring(4, 2) + strVal.Substring(2, 2) + strVal.Substring(0, 2);
                }
                break;

            case "CAL_ID":
                param.Parameter = 0x04;
                for (int i = 0; i < qty; i++)
                {
                    strData += response.Data.Substring(4 * 2 + i * 20 * 2, 16 * 2);
                }
                response.Data = strData;
                value2        = GetMode010209Value(param, response);
                break;

            default:
                value2.ErrorDetected = true;
                break;
            }
            param.Parameter = OriginalParam;
            param.Service   = OriginalService;
            return(value2);
        }
Пример #3
0
        private OBDParameterValue GetDM5Value(OBDParameter param, OBDResponse response)
        {
            OBDParameterValue value2 = new OBDParameterValue();

            if (response.GetDataByteCount() < 8)
            {
                value2.ErrorDetected = true;
                return(value2);
            }

            switch (param.SignalName)
            {
            case "":
            case "OBDSUP":
                // OBD型式
                response.Data = response.GetDataByte(2);
                value2        = GetPIDValue(0x11C, response.Data, param.SignalName);
                break;

            case "ACT_DTC_CNT":
                // 激活的故障代码,未实现解析功能
                response.Data = response.GetDataByte(0);
                break;

            case "PRE_DTC_CNT":
                // 先前激活的诊断故障代码,未实现解析功能
                response.Data = response.GetDataByte(1);
                break;

            case "CON_MON":
                // 持续监视系统支持/状态,未实现解析功能
                response.Data = response.GetDataByte(3);
                break;

            case "NON_SUP":
                // 非持续监视系统支持,未实现解析功能
                response.Data = response.GetDataByte(4) + response.GetDataByte(5);
                break;

            case "NON_STAT":
                // 非持续监视系统状态,未实现解析功能
                response.Data = response.GetDataByte(6) + response.GetDataByte(7);
                break;

            default:
                value2.ErrorDetected = true;
                break;
            }
            return(value2);
        }
Пример #4
0
        private string GetLogString(OBDParameter param, OBDParameterValue obdValue)
        {
            string strRet = "Values: ";

            if ((param.ValueTypes & (int)OBDParameter.EnumValueTypes.Double) == (int)OBDParameter.EnumValueTypes.Double)
            {
                strRet += string.Format("[ECU: {1}, Double: {0}] ", obdValue.DoubleValue.ToString(), obdValue.ECUResponseID);
            }
            if ((param.ValueTypes & (int)OBDParameter.EnumValueTypes.Bool) == (int)OBDParameter.EnumValueTypes.Bool)
            {
                strRet += string.Format("[ECU: {1}, Bool: {0}] ", obdValue.BoolValue.ToString(), obdValue.ECUResponseID);
            }
            if ((param.ValueTypes & (int)OBDParameter.EnumValueTypes.String) == (int)OBDParameter.EnumValueTypes.String)
            {
                strRet += string.Format("[ECU: {1}, String: {0}] ", obdValue.StringValue, obdValue.ECUResponseID);
            }
            if ((param.ValueTypes & (int)OBDParameter.EnumValueTypes.ListString) == (int)OBDParameter.EnumValueTypes.ListString)
            {
                strRet += string.Format("[ECU: {0}, ListString: ", obdValue.ECUResponseID);
                if (obdValue.ListStringValue != null && obdValue.ListStringValue.Count > 0)
                {
                    foreach (string strx in obdValue.ListStringValue)
                    {
                        strRet = string.Concat(strRet, strx + ", ");
                    }
                    strRet = strRet.Substring(0, strRet.Length - 2);
                }
                strRet += "]";
            }
            if ((param.ValueTypes & (int)OBDParameter.EnumValueTypes.ShortString) == (int)OBDParameter.EnumValueTypes.ShortString)
            {
                strRet += string.Format("[ECU: {1}, ShortString: {0}] ", obdValue.ShortStringValue, obdValue.ECUResponseID);
            }
            if ((param.ValueTypes & (int)OBDParameter.EnumValueTypes.BitFlags) == (int)OBDParameter.EnumValueTypes.BitFlags)
            {
                strRet += string.Format("[ECU: {0}, BitFlags: ", obdValue.ECUResponseID);
                for (int idx = 0; idx < 32; idx++)
                {
                    strRet += (obdValue.GetBitFlag(idx) ? "1" : "0");
                    if (idx % 8 == 7)
                    {
                        strRet += " ";
                    }
                }
                strRet = strRet.TrimEnd() + "]";
            }
            strRet = strRet.TrimEnd();
            return(strRet);
        }
Пример #5
0
        public OBDParameterValue GetMode03070AValue(OBDResponse response)
        {
            OBDParameterValue value2  = new OBDParameterValue();
            List <string>     strings = new List <string>();

            for (int i = 0; i <= response.Data.Length - 4; i += 4)
            {
                string str = GetDTCName(response.Data.Substring(i, 4));
                if (str.CompareTo("P0000") != 0)
                {
                    strings.Add(str);
                }
            }
            value2.ListStringValue = strings;
            return(value2);
        }
Пример #6
0
        public OBDParameterValue GetPIDSupport(OBDResponse response)
        {
            OBDParameterValue value2 = new OBDParameterValue();

            if (response.GetDataByteCount() < 4)
            {
                value2.ErrorDetected = true;
                return(value2);
            }
            int dataA = Utility.Hex2Int(response.GetDataByte(0));
            int dataB = Utility.Hex2Int(response.GetDataByte(1));
            int dataC = Utility.Hex2Int(response.GetDataByte(2));
            int dataD = Utility.Hex2Int(response.GetDataByte(3));

            value2.SetBitFlagBAT(dataA, dataB, dataC, dataD);
            return(value2);
        }
Пример #7
0
        public OBDParameterValue GetPIDValue(uint ID, string strData, string signalName)
        {
            OBDParameterValue value2 = new OBDParameterValue();
            Message           msg    = _netWork.GetMessage(ID);

            if (msg == null && ID < 0x80000000)
            {
                msg = _netWork.GetMessage(ID + 0x80000000);
            }
            if (msg == null)
            {
                value2.ErrorDetected = true;
            }
            else
            {
                if (msg.SetSignalRawValue(strData))
                {
                    value2.Message = msg;
                    foreach (Signal signal in msg.Signals.Values)
                    {
                        signal.DisplayString = _dbc.GetDisplayString(signal, "不适用");
                        if (signalName == signal.Name || signalName.Length == 0)
                        {
                            int iUsed = signal.TestSignalUesed();
                            if (iUsed > 0)
                            {
                                value2.DoubleValue = Math.Round(signal.Value, 2);
                                value2.BoolValue   = signal.RawValue > 0;
                                foreach (string item in signal.ListString)
                                {
                                    value2.ListStringValue.Add(item);
                                }
                                value2.ShortStringValue = signal.DisplayString;
                                value2.StringValue      = value2.ShortStringValue;
                            }
                        }
                    }
                }
                else
                {
                    value2.ErrorDetected = true;
                }
            }
            return(value2);
        }
Пример #8
0
        public List <OBDParameterValue> GetValueList(OBDParameter param)
        {
            List <OBDParameterValue> ValueList = new List <OBDParameterValue>();

            _log.TraceInfo("Requesting: " + param.OBDRequest);
            OBDResponseList responses = _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);
                _log.TraceInfo(strItem);
                return(ValueList);
            }
            else
            {
                for (int i = 0; i < responses.ResponseCount; i++)
                {
                    strItem += string.Format("[{0}] ", Utility.GetReadableHexString(0, responses.GetOBDResponse(i).Data));
                }
                strItem = strItem.TrimEnd();
                _log.TraceInfo(strItem);
            }

            for (int i = 0; i < responses.ResponseCount; i++)
            {
                OBDParameterValue obdValue = _obdInterpreter.GetValue(param, responses.GetOBDResponse(i));
                if (obdValue.ErrorDetected)
                {
                    _log.TraceError(string.Format("Values: [ECU: {0}, Error Detected!]", obdValue.ECUResponseID));
                }
                else
                {
                    _log.TraceInfo(GetLogString(param, obdValue));
                }
                ValueList.Add(obdValue);
            }
            return(ValueList);
        }
Пример #9
0
        private OBDParameterValue Get19DTCValue(OBDResponse response, int offset, int WholeDTCLenInByte = 4)
        {
            if (offset - WholeDTCLenInByte * 2 < 0)
            {
                return(null);
            }
            OBDParameterValue value2  = new OBDParameterValue();
            List <string>     strings = new List <string>();

            for (int i = 0; i <= response.Data.Length - offset; i += offset)
            {
                string str = GetDTCName(response.Data.Substring(i + offset - WholeDTCLenInByte * 2, 6));
                if (!str.StartsWith("P0000"))
                {
                    strings.Add(str);
                }
            }
            value2.ListStringValue = strings;
            return(value2);
        }
Пример #10
0
        public OBDParameterValue GetValue(OBDParameter param, OBDResponse response)
        {
            OBDParameterValue value2 = new OBDParameterValue();

            if (response == null)
            {
                value2.ErrorDetected = true;
                return(value2);
            }
            switch (param.Service)
            {
            case 0:
                // SAE J1939
                value2 = GetJ1939Value(param, response);
                break;

            case 1:
            case 2:
                value2 = GetMode010209Value(param, response);
                break;

            case 3:
            case 7:
            case 0x0A:
                value2 = GetMode03070AValue(response);
                break;

            case 9:
                value2 = GetMode010209Value(param, response);
                break;

            case 0x19:
                // ISO 27145 ReadDTCInformation
                string reportType = param.OBDRequest.Substring(2, 2);
                if (reportType == "42")
                {
                    value2 = Get42DTCValue(response);
                }
                else if (reportType == "55")
                {
                    value2 = Get55DTCValue(response);
                }
                break;

            case 0x22:
                // ISO 27145 ReadDataByIdentifer
                int HByte           = (param.Parameter >> 8) & 0xFF;
                int LByte           = param.Parameter & 0x00FF;
                int OriginalParam   = param.Parameter;
                int OriginalService = param.Service;
                param.Parameter = LByte;
                if (HByte == 0xF4)
                {
                    param.Service = 1;
                    value2        = GetMode010209Value(param, response);
                }
                else if (HByte == 0xF8)
                {
                    param.Service = 9;
                    value2        = GetMode010209Value(param, response);
                }
                param.Parameter = OriginalParam;
                param.Service   = OriginalService;
                break;

            default:
                value2.ErrorDetected = true;
                break;
            }
            value2.ECUResponseID = response.Header;
            if (value2.ECUResponseID.Length == 6)
            {
                // 如果是K线协议的话ECUResponseID取最后2个字节
                value2.ECUResponseID = value2.ECUResponseID.Substring(2);
            }
            else if (value2.ECUResponseID.Length == 8 && param.Service == 0)
            {
                // 如果是J1939协议的话ECUResponseID取最后1个字节
                value2.ECUResponseID = value2.ECUResponseID.Substring(6);
            }
            return(value2);
        }