Exemple #1
0
 protected void CacheTransmission(byte[] request, byte[] response, EdiabasNet.ErrorCodes errorCode)
 {
     if (!EnableTransmitCache)
     {
         return;
     }
     if (errorCode == EdiabasNet.ErrorCodes.EDIABAS_IFH_0003)
     {
         return;
     }
     if (request.Length > 0)
     {
         StoreWriteTransaction();
         WriteTransaction = new TransmitStorage(request, response, errorCode);
     }
     else
     {
         if (WriteTransaction != null)
         {
             if (response != null && response.Length > 0)
             {
                 byte[] buffer = new byte[response.Length];
                 Array.Copy(response, buffer, response.Length);
                 WriteTransaction.ResponseList.Add(buffer);
             }
             if (errorCode != EdiabasNet.ErrorCodes.EDIABAS_ERR_NONE && WriteTransaction.ErrorCode == EdiabasNet.ErrorCodes.EDIABAS_ERR_NONE)
             {
                 WriteTransaction.ErrorCode = errorCode;
             }
         }
     }
 }
        protected EdiabasNet.ErrorCodes ObdTrans(byte[] sendData, int sendDataLength, ref byte[] receiveData, out int receiveLength)
        {
            receiveLength = 0;
            if (TcpDiagStream == null)
            {
                return(EdiabasNet.ErrorCodes.EDIABAS_IFH_0019);
            }

            EdiabasNet.ErrorCodes errorCode = EdiabasNet.ErrorCodes.EDIABAS_ERR_NONE;
            UInt32 retries   = CommRepeatsProtected;
            string retryComm = EdiabasProtected.GetConfigProperty("RetryComm");

            if (retryComm != null)
            {
                if (EdiabasNet.StringToValue(retryComm) == 0)
                {
                    retries = 0;
                }
            }
            for (int i = 0; i < retries + 1; i++)
            {
                errorCode = ParTransmitFunc(sendData, sendDataLength, ref receiveData, out receiveLength);
                if (errorCode == EdiabasNet.ErrorCodes.EDIABAS_ERR_NONE)
                {
                    return(errorCode);
                }
                if (errorCode == EdiabasNet.ErrorCodes.EDIABAS_IFH_0003)
                {   // interface error
                    break;
                }
            }
            return(errorCode);
        }
        private static void ErrorRaisedFunc(EdiabasNet.ErrorCodes error)
        {
            string errorDescription = EdiabasNet.GetErrorDescription(error);

            System.Diagnostics.Debug.WriteLine("Error occured: 0x{0:X08} {1}", new object[]
            {
                (uint)error,
                errorDescription
            });
        }
Exemple #4
0
 public TransmitStorage(byte[] request, byte[] response, EdiabasNet.ErrorCodes errorCode)
 {
     Request      = request;
     ResponseList = new List <byte[]>();
     if (response != null && response.Length > 0)
     {
         byte[] buffer = new byte[response.Length];
         Array.Copy(response, buffer, response.Length);
         ResponseList.Add(buffer);
     }
     ErrorCode = errorCode;
 }
        public override bool TransmitData(byte[] sendData, out byte[] receiveData)
        {
            receiveData = null;
            if (CommParameterProtected == null)
            {
                EdiabasProtected.SetError(EdiabasNet.ErrorCodes.EDIABAS_IFH_0006);
                return(false);
            }
            EdiabasNet.ErrorCodes cachedErrorCode;
            byte[] cachedResponse;
            if (ReadCachedTransmission(sendData, out cachedResponse, out cachedErrorCode))
            {
                if (cachedErrorCode != EdiabasNet.ErrorCodes.EDIABAS_ERR_NONE)
                {
                    EdiabasProtected.SetError(cachedErrorCode);
                    return(false);
                }
                receiveData = cachedResponse;
                return(true);
            }
            if (ReconnectRequired)
            {
                InterfaceDisconnect();
                if (!InterfaceConnect())
                {
                    ReconnectRequired = true;
                    EdiabasProtected.SetError(EdiabasNet.ErrorCodes.EDIABAS_IFH_0003);
                    return(false);
                }
            }
            int recLength;

            EdiabasNet.ErrorCodes errorCode = ObdTrans(sendData, sendData.Length, ref RecBuffer, out recLength);
            if (errorCode != EdiabasNet.ErrorCodes.EDIABAS_ERR_NONE)
            {
                if (errorCode == EdiabasNet.ErrorCodes.EDIABAS_IFH_0003)
                {
                    ReconnectRequired = true;
                }
                CacheTransmission(sendData, null, errorCode);
                EdiabasProtected.SetError(errorCode);
                return(false);
            }
            receiveData = new byte[recLength];
            Array.Copy(RecBuffer, receiveData, recLength);
            CacheTransmission(sendData, receiveData, EdiabasNet.ErrorCodes.EDIABAS_ERR_NONE);
            return(true);
        }
Exemple #6
0
 protected bool ReadCachedTransmission(byte[] request, out byte[] response, out EdiabasNet.ErrorCodes errorCode)
 {
     response  = null;
     errorCode = EdiabasNet.ErrorCodes.EDIABAS_IFH_0009;
     if (!EnableTransmitCache)
     {
         return(false);
     }
     if (request.Length > 0)
     {
         StoreWriteTransaction();
         ReadTransaction    = null;
         ReadTransactionPos = 0;
         TransmitCacheDict.TryGetValue(BitConverter.ToString(request), out ReadTransaction);
     }
     if (ReadTransaction == null)
     {
         return(false);
     }
     if (request.Length > 0)
     {
         Ediabas.LogData(EdiabasNet.EdLogLevel.Ifh, request, 0, request.Length, "Send Cache");
     }
     if ((ReadTransaction.Request.Length > 0) && ((ReadTransaction.Request[0] & 0xC0) == 0xC0))
     {     // functional address
         if (ReadTransaction.ErrorCode == EdiabasNet.ErrorCodes.EDIABAS_ERR_NONE)
         { // transmission not completed
             Ediabas.LogString(EdiabasNet.EdLogLevel.Ifh, "Incomplete cached response");
             return(false);
         }
     }
     if (ReadTransaction.ResponseList.Count > ReadTransactionPos)
     {
         response  = ReadTransaction.ResponseList[ReadTransactionPos++];
         errorCode = EdiabasNet.ErrorCodes.EDIABAS_ERR_NONE;
         Ediabas.LogData(EdiabasNet.EdLogLevel.Ifh, response, 0, response.Length, "Resp Cache");
     }
     else
     {
         if (ReadTransaction.ErrorCode != EdiabasNet.ErrorCodes.EDIABAS_ERR_NONE)
         {
             errorCode = ReadTransaction.ErrorCode;
         }
     }
     return(true);
 }
Exemple #7
0
        static void ErrorRaisedFunc(EdiabasNet.ErrorCodes error)
        {
            string errorText = EdiabasNet.GetErrorDescription(error);

            _outputWriter.WriteLine(string.Format(Culture, "Error occured: 0x{0:X08} {1}", (UInt32)error, errorText));
        }