Пример #1
0
        public static KWP2000Message SendRequestEraseFlashResultMessage(KWP2000Interface commInterface)
        {
            byte[] tempData = new byte[1];
            tempData[0] = (byte)KWP2000VAGLocalIdentifierRoutine.EraseFlash;

            return(commInterface.SendMessage((byte)KWP2000ServiceID.RequestRoutineResultsByLocalIdentifier, tempData));
        }
 public ExtendedDataLoggingDefineReadVariables(KWP2000Interface commInterface, Mode mode, IEnumerable <VariableDefinition> variables)
     : base(commInterface)
 {
     mVariables                 = variables;
     mMode                      = mode;
     NumVariablesDefined        = 0;
     MaxNumVariableReadsPerTick = 255;
     MaxNumBytesPerRead         = 64;
 }
Пример #3
0
        public KWP2000Interface_ViewModel()
        {
            CommInterface = new KWP2000Interface();

            CommInterface.PropertyChanged += CommInterfacePropertyChanged;
            CopyDefaultTimings();

            CommInterface.ConnectionStatusChangedEvent += ConnectionStatusChangedEvent;

            var defaultBaudRates = ECUFlasher.Properties.Settings.Default.SupportedKWP2000BaudRates;

            var savedAvailableRates = new List <uint>();

            if (defaultBaudRates != null)
            {
                foreach (var rateObj in defaultBaudRates)
                {
                    if (rateObj is uint)
                    {
                        var rate = (uint)rateObj;

                        if (!savedAvailableRates.Contains(rate))
                        {
                            savedAvailableRates.Add(rate);
                        }
                    }
                }
            }

            savedAvailableRates.Sort();

            AvailableBaudRates = new ObservableCollection <uint>(savedAvailableRates);

            if (!AvailableBaudRates.Any())
            {
                ResetAvailableBaudRatesToDefault();
                SaveAvailableBaudRates();
            }

            //get the last used baud rate
            var previousRate = ECUFlasher.Properties.Settings.Default.DesiredKWP2000BaudRate;

            //try to find the last used baud rate in the available rates list, if it isn't there, then use the last baud rate
            if (AvailableBaudRates.Contains(previousRate))
            {
                DesiredBaudRate = previousRate;
            }
            else
            {
                DesiredBaudRate = AvailableBaudRates.Last();
            }

            //get the last used connection method
            DesiredConnectionMethod = ECUFlasher.Properties.Settings.Default.DesiredKWP2000ConnectionMethod;
        }
Пример #4
0
        public string GetDataString(KWP2000Interface commInterface)
        {
            byte[] dataBytes  = GetMessageDataBytes(commInterface);
            string dataString = "";

            for (int x = 0; x < dataBytes.Length; x++)
            {
                dataString += string.Format("{0:X2}", dataBytes[x]) + ", ";
            }

            return(dataString);
        }
Пример #5
0
        public static KWP2000Message SendRequestUploadMessage(KWP2000Interface commInterface, uint address, uint size, byte format)
        {
            byte[] data = new byte[7];
            data[0] = (byte)((address >> 16) & 0xFF);
            data[1] = (byte)((address >> 8) & 0xFF);
            data[2] = (byte)(address & 0xFF);
            data[3] = format;
            data[4] = (byte)((size >> 16) & 0xFF);
            data[5] = (byte)((size >> 8) & 0xFF);
            data[6] = (byte)(size & 0xFF);

            return(commInterface.SendMessage((byte)KWP2000ServiceID.RequestUpload, data));
        }
        public ExtendedDataLoggingOperation(KWP2000Interface commInterface, List <uint> baudRates)
            : base(commInterface, baudRates)
        {
            EnableAutoStartDiagnosticSession(KWP2000DiagnosticSessionType.DevelopmentSession, baudRates);
            EnableAutoNegotiateTiming(NegotiateTimingParameters.NegotiationTarget.Limits);
            ShouldRelocateMessageHandlingTable = false;

            mState = State.DefineVariables;
            mExtendedDataLoggingSetup = false;

            mLastReadStartTime      = DateTime.Now;
            MaxReadsPerSecond       = 20;
            MaxVariableReadsPerTick = 255;
            MaxNumBytesPerRead      = 64;
        }
        public SetupExtendedDataLoggingOperation(KWP2000Interface commInterface, List <uint> baudRates)
            : base(commInterface, baudRates)
        {
            mDefineFunctionData = new byte[0x7C];
            Buffer.BlockCopy(Communication.Properties.Resources.KWP2000DataLoggingFunctions, 0, mDefineFunctionData, 0, mDefineFunctionData.Length);
            Debug.Assert(mDefineFunctionData[mDefineFunctionData.Length - 2] == 0xDB);
            Debug.Assert(mDefineFunctionData[mDefineFunctionData.Length - 1] == 0x00);

            mReadFunctionData = new byte[Communication.Properties.Resources.KWP2000DataLoggingFunctions.Length - mDefineFunctionData.Length];
            Buffer.BlockCopy(Communication.Properties.Resources.KWP2000DataLoggingFunctions, mDefineFunctionData.Length, mReadFunctionData, 0, mReadFunctionData.Length);

            mVariableDefinitionsData = new byte[257];//257 is hardcoded into the assembly function
            for (int x = 0; x < mVariableDefinitionsData.Length; x++)
            {
                mVariableDefinitionsData[x] = 0;
            }
        }
Пример #8
0
        public static KWP2000Message SendValidateFlashChecksumMessage(KWP2000Interface commInterface, uint startAddress, uint endAddress, ushort checksum)
        {
            Debug.Assert(startAddress % 2 == 0);
            Debug.Assert(endAddress % 2 == 1);

            byte[] tempData = new byte[9];
            tempData[0] = (byte)KWP2000VAGLocalIdentifierRoutine.ValidateFlashChecksum;
            tempData[1] = (byte)((startAddress >> 16) & 0xFF);
            tempData[2] = (byte)((startAddress >> 8) & 0xFF);
            tempData[3] = (byte)((startAddress) & 0xFF);
            tempData[4] = (byte)((endAddress >> 16) & 0xFF);
            tempData[5] = (byte)((endAddress >> 8) & 0xFF);
            tempData[6] = (byte)((endAddress) & 0xFF);
            tempData[7] = (byte)((checksum >> 8) & 0xFF);
            tempData[8] = (byte)((checksum) & 0xFF);

            return(commInterface.SendMessage((byte)KWP2000ServiceID.StartRoutineByLocalIdentifier, tempData));
        }
Пример #9
0
        public static KWP2000Message SendRequestEraseFlashMessage(KWP2000Interface commInterface, uint startAddress, uint endAddress, string flashToolCode)
        {
            Debug.Assert(flashToolCode != null);
            Debug.Assert(flashToolCode.Length <= 6);
            char[] FTC = flashToolCode.ToCharArray();

            byte[] tempData = new byte[13];
            tempData[0]  = (byte)KWP2000VAGLocalIdentifierRoutine.EraseFlash;
            tempData[1]  = (byte)((startAddress >> 16) & 0xFF);
            tempData[2]  = (byte)((startAddress >> 8) & 0xFF);
            tempData[3]  = (byte)((startAddress) & 0xFF);
            tempData[4]  = (byte)((endAddress >> 16) & 0xFF);
            tempData[5]  = (byte)((endAddress >> 8) & 0xFF);
            tempData[6]  = (byte)((endAddress) & 0xFF);
            tempData[7]  = (byte)FTC[0];
            tempData[8]  = (byte)FTC[1];
            tempData[9]  = (byte)FTC[2];
            tempData[10] = (byte)FTC[3];
            tempData[11] = (byte)FTC[4];
            tempData[12] = (byte)FTC[5];

            return(commInterface.SendMessage((byte)KWP2000ServiceID.StartRoutineByLocalIdentifier, tempData));
        }
Пример #10
0
        public byte[] GetMessageDataBytes(KWP2000Interface commInterface)
        {
            bool   useOneByteHeader  = false;
            UInt32 numHeaderBytes    = 3;
            var    actualAddressMode = mAddressMode;

            if (commInterface.IsOneByteHeaderSupported())
            {
                useOneByteHeader  = true;
                numHeaderBytes    = 1;
                actualAddressMode = KWP2000AddressMode.None;
            }
            else
            {
                //if one byte headers aren't supported, then use three byte headers.
                //if key bytes don't allow any address info, then just use three byte headers.
                useOneByteHeader  = false;
                numHeaderBytes    = 3;
                actualAddressMode = mAddressMode;
            }

            byte format = (byte)actualAddressMode;

            bool extraDataLengthByteNeeded = false;
            byte dataLength = 1;            //one for the service ID

            if (mData != null)
            {
                Debug.Assert(dataLength + mData.Length <= 255);
                dataLength += (byte)mData.Length;
            }

            //if key bytes don't allow any length info, then just ignore them
            bool keyBytesDontSpecifyAnyLengthInfo = !commInterface.IsAdditionalLengthByteSupported() && !commInterface.IsLengthInfoInFormatByteSupported();

            if ((dataLength <= KWP2000Interface.MAX_MESSAGE_DATA_SIZE_WITHOUT_LENGTH_BYTE) && (commInterface.IsLengthInfoInFormatByteSupported() || keyBytesDontSpecifyAnyLengthInfo))
            {
                format |= dataLength;
            }
            else
            {
                extraDataLengthByteNeeded = true;
            }

            if (extraDataLengthByteNeeded)
            {
                numHeaderBytes += 1;
            }

            uint totalNumBytesInMessage = numHeaderBytes + dataLength + 1;            //data bytes, format byte, target byte, source byte, checksum byte

            byte[] messageBuffer = new byte[totalNumBytesInMessage];

            if (useOneByteHeader)
            {
                messageBuffer[0] = format;
            }
            else
            {
                messageBuffer[0] = format;
                messageBuffer[1] = mDestination;
                messageBuffer[2] = mSource;
            }

            if (extraDataLengthByteNeeded)
            {
                messageBuffer[numHeaderBytes - 1] = dataLength;
            }

            messageBuffer[numHeaderBytes] = (byte)mServiceID;

            if (mData != null)
            {
                Buffer.BlockCopy(mData, 0, messageBuffer, (int)numHeaderBytes + 1, mData.Length);
            }

            byte checksum = 0;

            for (int x = 0; x < (numHeaderBytes + dataLength); x++)
            {
                checksum += messageBuffer[x];
            }

            messageBuffer[totalNumBytesInMessage - 1] = checksum;

            return(messageBuffer);
        }
        protected override bool MessageHandler(KWP2000Interface commInterface, KWP2000Message message)
        {
            bool handled = base.MessageHandler(commInterface, message);

            if (!handled)
            {
                if (mMode == Mode.Define)
                {
                    if (KWP2000Interface.IsPositiveResponseToRequest(DefineVariablesID, message))
                    {
                        NumVariablesDefined = message.mData[0];

                        ActionCompleted(true);
                        handled = true;
                    }
                    else
                    {
                        KWP2000Interface.IsNegativeResponseToRequest(DefineVariablesID, message, out DefineFailureResponseCode);
                    }
                }
                else
                {
                    if (KWP2000Interface.IsPositiveResponseToRequest(ReadVariablesID, message))
                    {
                        int dataIndex = 0;

                        byte readVariablesEndIndex = (byte)(mReadVariableIndexLastRead + mNumReadVariablesLastRead);

                        for (var curVarIndex = mReadVariableIndexLastRead; curVarIndex < readVariablesEndIndex; ++curVarIndex)
                        {
                            var curVariable = mVariables.ElementAt(curVarIndex);

                            var dataSize = (curVariable.VarType == VariableDefinition.VariableType.Byte) ? 1 : 2;

                            if (dataIndex + dataSize > message.DataLength)
                            {
                                break;
                            }

                            var variableData = new byte[dataSize];
                            Buffer.BlockCopy(message.mData, dataIndex, variableData, 0, dataSize);

                            mReadVariableData.Add(variableData);

                            dataIndex += dataSize;
                        }

                        mReadVariableIndexLastRead = readVariablesEndIndex;

                        if (mReadVariableIndexLastRead >= NumVariablesDefined)
                        {
                            ActionCompleted(true);
                        }
                        else
                        {
                            SendReadMessage();
                        }

                        handled = true;
                    }
                }

                if (!handled)
                {
                    ActionCompleted(false);
                }
            }

            return(handled);
        }