/// <summary> /// get response formater /// </summary> /// <param name="responseLength"></param> /// <param name="dataLength"></param> /// <returns></returns> public static OdbData GetResponseFormatForProtocolNumber(int responseLength, int dataLength) { OdbData data = new OdbData(); var added = responseLength - dataLength; switch (added) { case 6: data.Header = new string[3]; data.Info = new string[2]; data.Data = new string[dataLength]; data.Ender = new string[1]; break; case 5: data.Header = new string[3]; data.Info = new string[2]; data.Data = new string[dataLength]; data.Ender = new string[0]; break; case 3: data.Header = new string[0]; data.Info = new string[2]; data.Data = new string[dataLength]; data.Ender = new string[1]; break; case 2: data.Header = new string[0]; data.Info = new string[2]; data.Data = new string[dataLength]; data.Ender = new string[0]; break; case 1: data.Header = new string[0]; data.Info = new string[0]; data.Data = new string[dataLength]; data.Ender = new string[1]; break; case 0: data.Header = new string[0]; data.Info = new string[0]; data.Data = new string[dataLength]; data.Ender = new string[0]; break; default: data.Header = new string[0]; data.Info = new string[0]; data.Data = new string[0]; data.Ender = new string[0]; break; } //calculate full length data.DataLength = data.Data.Length + data.Header.Length + data.Info.Length + data.Ender.Length; return data; }
/// <summary> /// Decode supported pids and register it /// </summary> /// <param name="what"></param> /// <param name="data"></param> private void decodeSupportedPidsAndRegisterIt(OdbPid what, OdbData data) { List<int> pids = new List<int>(); int pid = Convert.ToInt32(what.Pid.Split(' ')[1], 16); for (int i = 0; i < data.Data.Length; i++) { char[] binary = Convert.ToString(Convert.ToInt32(data.Data[i], 16), 2).ToCharArray(); for (int j = 0; j < binary.Length; j++) { pid++; if (binary[j] == '1') { pids.Add(pid); } } } this.RegisterSupportedPids(data.EcuIdentifier(), data.Protocol, pids); }
/// <summary> /// get response formater /// </summary> /// <param name="protocolNumber"></param> /// <param name="dataLength"></param> /// <returns></returns> public static OdbData GetResponseFormatForProtocolNumber(int protocolNumber, int dataLength) { OdbData data = new OdbData(); switch (protocolNumber) { case 1: data.Header = new string[3]; data.Info = new string[2]; data.Data = new string[dataLength]; data.Ender = new string[1]; data.DataLength = dataLength + 6; break; default: data.Header = new string[0]; data.Info = new string[0]; data.Data = new string[0]; data.Ender = new string[0]; data.DataLength = 0; break; } return data; }
/// <summary> /// Parse data for specified pid /// </summary> /// <param name="odbPid"></param> /// <param name="data"></param> /// <returns></returns> private Double parseDataForSpecifiedPid(OdbPid odbPid, OdbData data) { int A = -1, B = -1, C = -1, D = -1; int length = data.Data.Length; if (length > 4 || length == 0) { throw new OdbException(OdbError.IncorrectDataLength); } if (length >= 4) { D = Convert.ToInt32(data.Data[3], 16); } if (length >= 3) { C = Convert.ToInt32(data.Data[2], 16); } if (length >= 2) { B = Convert.ToInt32(data.Data[1], 16); } if (length >= 1) { A = Convert.ToInt32(data.Data[0], 16); } return odbPid.Compute(A, B, C, D); }