Esempio n. 1
0
        public Kwp2000Message SendReceive(
            Service service, byte[] body, bool excludeAddresses = false)
        {
            SendMessage(service, body, excludeAddresses);

            while (true)
            {
                var message = ReceiveMessage();

                if (message.SrcAddress.HasValue)
                {
                    if (message.SrcAddress != _controllerAddress)
                    {
                        throw new InvalidOperationException($"Unexpected SrcAddress: {message.SrcAddress:X2}");
                    }

                    if (message.DestAddress != _testerAddress)
                    {
                        throw new InvalidOperationException($"Unexpected DestAddress: {message.DestAddress:X2}");
                    }
                }

                if ((byte)message.Service == 0x7F)
                {
                    if (message.Body[0] == (byte)service &&
                        message.Body[1] == (byte)ResponseCode.reqCorrectlyRcvdRspPending)
                    {
                        continue;
                    }
                    throw new NegativeResponseException(message);
                }

                if (!message.IsPositiveResponse(service))
                {
                    throw new InvalidOperationException($"Unexpected response: {message.Service}");
                }

                return(message);
            }
        }
Esempio n. 2
0
 public void SendMessage(Service service, byte[] body, bool excludeAddresses = false)
 {