Ejemplo n.º 1
0
        /// <summary>
        /// Load supported PIds
        /// </summary>
        /// <returns></returns>
        private async Task LoadSupportedProtocols(OdbProtocol protocolType = OdbProtocol.Unknown, int protocolNumber = 0)
        {
            var selectedProtocol = -1;

            if (protocolType == OdbProtocol.Unknown)
            {
                OdbPid protocol = null;
                for (selectedProtocol = 0; selectedProtocol <= 9; selectedProtocol++)
                {
                    protocol = OdbPids.GetPidForProtocolNumber(selectedProtocol);
                    try
                    {
                        OdbResponse response = await this.socket.SendAndCheck(protocol);

                        if (response.IsValid)
                        {
                            break;
                        }
                    }
                    catch
                    {
                        reporter.ReportInfo("Protocol ATSP" + protocol.Description + " is not supported.");
                    }
                }

                if (selectedProtocol == 10)
                {
                    throw new OdbException(OdbError.CouldNotFindCompatibleProtocol);
                }

                this.socket.SelectedProtocol = protocol;
            }
            else if (protocolType == OdbProtocol.Specified && protocolNumber > 0 && protocolNumber < 10)
            {
                OdbPid protocol = OdbPids.GetPidForProtocolNumber(selectedProtocol);
                await this.socket.SendAndCheck(protocol);

                this.socket.SelectedProtocol = protocol;
            }
            else
            {
                throw new OdbException(OdbError.WrongProtocolNumber);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Resolve incoming data and setup odb data
        /// </summary>
        /// <param name="response"></param>
        /// <param name="what"></param>
        /// <returns></returns>
        public OdbData ResolveData(String response, OdbPid what)
        {
            int counter = 0;

            String[] bytes = response.Split(' ');
            bytes = this.validateReponseBytes(bytes);
            OdbData data = OdbPids.GetResponseFormatForProtocolNumber(bytes.Length, what.ByteCount);

            if (bytes.Length < what.ByteCount)
            {
                return(null);
            }

            try
            {
                data.Protocol = this.SelectedProtocol;
                for (int i = 0; i < data.Header.Length; i++)
                {
                    data.Header[i] = bytes[counter];
                    counter++;
                }
                for (int i = 0; i < data.Info.Length; i++)
                {
                    data.Info[i] = bytes[counter];
                    counter++;
                }
                for (int i = 0; i < data.Data.Length; i++)
                {
                    data.Data[i] = bytes[counter];
                    counter++;
                }
                for (int i = 0; i < data.Ender.Length; i++)
                {
                    data.Ender[i] = bytes[counter];
                    counter++;
                }
            }
            catch
            {
                return(null);
            }
            return(data);
        }