Beispiel #1
0
            public UDSPacket(byte [] data, UDScmd.Mode mode)
            {
                if (data == null)
                {
                    return;
                }
                if (data.Length < 1)
                {
                    return;
                }
                if ((UDScmd.Response)data[0] != UDScmd.Response.NEGATIVE_RESPONSE)
                {
                    Response = (UDScmd.Response)(data[0] - (byte)mode);
                }
                else
                {
                    Response = UDScmd.Response.NEGATIVE_RESPONSE;
                }
                if (data.Length < 2)
                {
                    return;
                }
                Mode = (UDScmd.Mode)data[1];
                int payloadLength = 0;

                switch (mode)
                {
                case UDScmd.Mode.TRANSFER_DATA:
                case UDScmd.Mode.DIAGNOSTIC_COMMAND:
                case UDScmd.Mode.READ_MEMORY_BY_ADDRESS:
                    if (Response == UDScmd.Response.NEGATIVE_RESPONSE)
                    {
                        NegativeResponse = (UDScmd.NegativeResponse)data[2];
                    }
                    payloadLength = data.Length - 1;
                    if (payloadLength < 1)
                    {
                        return;
                    }
                    Payload = new byte[payloadLength];
                    Buffer.BlockCopy(data, 1, Payload, 0, payloadLength);
                    break;

                case UDScmd.Mode.REQUEST_DOWNLOAD:
                    if (Response == UDScmd.Response.NEGATIVE_RESPONSE)
                    {
                        NegativeResponse = (UDScmd.NegativeResponse)data[2];
                        return;
                    }
                    if (data.Length < 3)
                    {
                        return;
                    }
                    LengthFormatIdentifier = data[1];
                    MaxNumberOfBlockLength = data[2];
                    break;

                case UDScmd.Mode.SECURITY_ACCESS:
                    int offset;
                    if (Response == UDScmd.Response.NEGATIVE_RESPONSE)
                    {
                        offset = 3;
                        if (data.Length < 3)
                        {
                            return;
                        }
                        NegativeResponse = (UDScmd.NegativeResponse)data[2];
                    }
                    else
                    {
                        offset      = 2;
                        SubFunction = data[1];
                    }
                    payloadLength = data.Length - offset;
                    if (payloadLength < 1)
                    {
                        return;
                    }
                    Payload = new byte[payloadLength];
                    Buffer.BlockCopy(data, offset, Payload, 0, payloadLength);
                    break;

                default:
                    break;
                }
            }
Beispiel #2
0
 public UDSException(UDScmd.NegativeResponse response) : base(Exceptions.GetDescription(response))
 {
     _response = response;
 }