コード例 #1
0
        public List <tclsUDSFrame> lstSegmentData(byte[] au8InputData)
        {
            int iSourceIDX;
            int iDestIDX;
            int iFrameIDX;
            int iTXBytesRequired;
            int iTXPayloadBytes;

            byte[] au8TempData = new byte[7];
            byte   u8Seq;

            if (7 < au8InputData.Length)
            {
                iTXBytesRequired = 8 + (8 * (((au8InputData.Length - 7) / 7) + 1));
            }
            else
            {
                iTXBytesRequired = 8;
            }

            byte[] au8OutputData = new byte[iTXBytesRequired];

            mTransmitFrameList.Clear();

            if (8 > au8InputData.Length)
            {
                tclsUDSFrame clsOutputFrame = new tclsUDSFrame();
                Array.Copy(au8TempData, 0, clsOutputFrame.au8Data, 1, au8InputData.Length);
                clsOutputFrame.au8Data[0] = (byte)au8InputData.Length;
                mTransmitFrameList.Add(clsOutputFrame);
            }
            else
            {
                iFrameIDX  = au8InputData.Length / 7;
                iDestIDX   = 9 + 8 * (iFrameIDX - 1);
                iSourceIDX = 6 + 7 * (iFrameIDX - 1);

                /* Copy data */
                for (; iFrameIDX >= 1; iFrameIDX--)
                {
                    Array.Copy(au8InputData, iSourceIDX,
                               au8TempData, 0, Math.Min(au8InputData.Length - iSourceIDX, 7));
                    Array.Copy(au8TempData, 0, au8OutputData, iDestIDX, 7);
                    iDestIDX   -= 8;
                    iSourceIDX -= 7;
                }
                Array.Copy(au8InputData, 0, au8OutputData, iDestIDX + 1, 6);

                /* Write sequence numbers */
                iFrameIDX = au8InputData.Length / 7;
                u8Seq     = (byte)((iFrameIDX - 1) & 0x0f);
                iDestIDX  = 8 + 8 * (iFrameIDX - 1);
                for (; iFrameIDX >= 1; iFrameIDX--)
                {
                    au8OutputData[iDestIDX] = (byte)(0x20 + u8Seq--);
                    u8Seq    &= 0x0f;
                    iDestIDX -= 8;
                }

                iTXPayloadBytes = 7 * (((iTXBytesRequired - 8) / 8)) + 6;

                au8OutputData[iDestIDX + 1] = (byte)(iTXPayloadBytes & 0xff);
                au8OutputData[iDestIDX]     = (byte)(0x10 + ((iTXPayloadBytes & 0xf00) >> 8));

                for (iFrameIDX = 0; iFrameIDX < (iTXBytesRequired / 8); iFrameIDX++)
                {
                    tclsUDSFrame clsOutputFrame = new tclsUDSFrame();
                    Array.Copy(au8OutputData, 8 * iFrameIDX, clsOutputFrame.au8Data, 0, 8);
                    mTransmitFrameList.Add(clsOutputFrame);
                }
            }

            return(mTransmitFrameList);
        }
コード例 #2
0
        public tclsASCParser(string szASCPath)
        {
            mlstCANMessages     = new List <tclsUDSFrame>();
            mlstUDSFramesReplay = new List <tclsUDSFrame>();
            TextReader ASCFile = null;
            String     strLine = null;

            miReplayListIndex = 0;
            int iDLC = 0;

            mboHoldList = false;

            mu64StartTimeuS     = (UInt64)(DateTime.Now.Ticks / 10L);
            mu32EndTimeFileuS   = 0;
            mu32StartTimeFileuS = 0xffffffff;

            if (File.Exists(szASCPath))
            {
                try
                {
                    ASCFile = new StreamReader(szASCPath);

                    strLine = ASCFile.ReadLine();

                    while (strLine != null)
                    {
                        if (strLine != "")
                        {
                            strLine = strLine.Trim();

                            while (true == strLine.Contains("  "))
                            {
                                strLine = strLine.Replace("  ", " ");
                            }

                            string[] aszLineArray = strLine.Split(' ');

                            if (6 < aszLineArray.Length)
                            {
                                if ((0 == String.Compare("Tx", aszLineArray[3], true)) &&
                                    (0 == String.Compare("d", aszLineArray[4], true)))
                                {
                                    try
                                    {
                                        iDLC = Convert.ToInt16(aszLineArray[5]);
                                        iDLC = 9 > iDLC ? iDLC : (int)8;
                                    }
                                    catch
                                    {
                                        /* force fail at check enough string array tokens */
                                        iDLC = 1000;
                                    }

                                    if ((6 + iDLC) <= aszLineArray.Length)
                                    {
                                        tclsUDSFrame clsUDSFrame =
                                            new tclsUDSFrame();

                                        try
                                        {
                                            clsUDSFrame.u8ByteCount = (byte)iDLC;

                                            for (int iDataIDX = 0; iDataIDX < iDLC; iDataIDX++)
                                            {
                                                clsUDSFrame.au8Data[iDataIDX] =
                                                    byte.Parse(aszLineArray[6 + iDataIDX], System.Globalization.NumberStyles.HexNumber);
                                            }

                                            Single fTimeStamp = Convert.ToSingle(aszLineArray[0]);
                                            fTimeStamp /= 4;

                                            if (4295 > fTimeStamp)
                                            {
                                                clsUDSFrame.u32TimeStamp =
                                                    (UInt32)(1000000 * fTimeStamp);

                                                if (clsUDSFrame.u32TimeStamp
                                                    > mu32EndTimeFileuS)
                                                {
                                                    mu32EndTimeFileuS = clsUDSFrame.u32TimeStamp;
                                                }

                                                if (clsUDSFrame.u32TimeStamp
                                                    < mu32StartTimeFileuS)
                                                {
                                                    mu32StartTimeFileuS = clsUDSFrame.u32TimeStamp;
                                                }
                                            }

                                            mlstCANMessages.Add(clsUDSFrame);
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                            }
                        }

                        strLine = ASCFile.ReadLine();
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    if (ASCFile != null)
                    {
                        ASCFile.Close();
                    }
                }
            }
            else
            {
                throw new FileNotFoundException("Unable to locate " + szASCPath);
            }
        }
コード例 #3
0
        public void vStartRPC(byte u8SID, byte u8SSID, UInt32 u32Arg1, Int32 i32Arg2, byte[] au8Data)
        {
            byte[]       au8Temp;
            tclsUDSFrame clsUDSFrame = new tclsUDSFrame();

            List <tclsUDSFrame> lUDSFrameList;

            switch (u8SID)
            {
            case ConstantData.UDS.ru8SID_DSC:
            {
                clsUDSFrame.au8Data[0]  = 2;
                clsUDSFrame.au8Data[1]  = ConstantData.UDS.ru8SID_DSC;
                clsUDSFrame.au8Data[2]  = u8SSID;
                clsUDSFrame.u8ByteCount = 3;
                mclsOutputQueue.Enqueue(clsUDSFrame);
                break;
            }

            case ConstantData.UDS.ru8SID_TP:
            {
                clsUDSFrame.au8Data[0]  = 2;
                clsUDSFrame.au8Data[1]  = ConstantData.UDS.ru8SID_TP;
                clsUDSFrame.au8Data[2]  = 0;
                clsUDSFrame.u8ByteCount = 3;
                mclsOutputQueue.Enqueue(clsUDSFrame);
                break;
            }

            case ConstantData.UDS.ru8SID_RDBI:
            {
                clsUDSFrame.au8Data[0] = 3;
                clsUDSFrame.au8Data[1] = ConstantData.UDS.ru8SID_RDBI;
                au8Temp = BitConverter.GetBytes((UInt16)u32Arg1);
                Array.Copy(au8Temp, 0, clsUDSFrame.au8Data, 2, 2);
                clsUDSFrame.u8ByteCount = 4;
                mclsOutputQueue.Enqueue(clsUDSFrame);
                break;
            }

            case ConstantData.UDS.ru8SID_RMBA:
            {
                au8RMBA[0] = ConstantData.UDS.ru8SID_RMBA;
                au8RMBA[1] = ConstantData.UDS.ru8RMBA_ALFID;

                switch (ConstantData.UDS.ru8RMBA_MA_LENGTH)
                {
                /* TODO as needed
                 * case 2:
                 * {
                 *  au8Temp = BitConverter.GetBytes((UInt16)u32Arg1);
                 *  Array.Copy(au8Temp, 0, au8RMBA, ConstantData.UDS.ru8RMBA_MA_OFFSET, ConstantData.UDS.ru8RMBA_MA_LENGTH);
                 *  break;
                 * }
                 */
                case 4:
                {
                    au8Temp = BitConverter.GetBytes(u32Arg1);
                    Array.Copy(au8Temp, 0, au8RMBA, ConstantData.UDS.ru8RMBA_MA_OFFSET, ConstantData.UDS.ru8RMBA_MA_LENGTH);
                    break;
                }

                    /* TODO as needed
                     * default:
                     * {
                     *  au8RMBA[ConstantData.UDS.ru8RMBA_MA_OFFSET] = (byte)(u32Arg1 & 0xff);
                     *  break;
                     * }
                     */
                }


                switch (ConstantData.UDS.ru8RMBA_MS_LENGTH)
                {
                case 2:
                {
                    au8Temp = BitConverter.GetBytes((UInt16)i32Arg2);
                    Array.Copy(au8Temp, 0, au8RMBA, ConstantData.UDS.ru8RMBA_MS_OFFSET, ConstantData.UDS.ru8RMBA_MS_LENGTH);
                    break;
                }

                    /* TODO as needed
                     * default:
                     *  {
                     *      au8RMBA[ConstantData.UDS.ru8RMBA_MS_OFFSET] = (byte)(i32Arg2 & 0xff);
                     *      break;
                     *  }
                     */
                }

                lUDSFrameList = mclsISO15765.lstSegmentData(au8RMBA);

                foreach (tclsUDSFrame clsSegUDSFrame in lUDSFrameList)
                {
                    mclsOutputQueue.Enqueue(clsSegUDSFrame);
                }

                break;
            }

            case ConstantData.UDS.ru8SID_WMBA:
            {
                au8WMBA[0] = ConstantData.UDS.ru8SID_WMBA;
                au8WMBA[1] = ConstantData.UDS.ru8WMBA_ALFID;

                switch (ConstantData.UDS.ru8WMBA_MA_LENGTH)
                {
                /* TODO as needed
                 * case 2:
                 *  {
                 *      au8Temp = BitConverter.GetBytes((UInt16)u32Arg1);
                 *      Array.Copy(au8Temp, 0, au8WMBA, ConstantData.UDS.ru8WMBA_MA_OFFSET, ConstantData.UDS.ru8WMBA_MA_LENGTH);
                 *      break;
                 *  }
                 */
                case 4:
                {
                    au8Temp = BitConverter.GetBytes(u32Arg1);
                    Array.Copy(au8Temp, 0, au8WMBA, ConstantData.UDS.ru8WMBA_MA_OFFSET, ConstantData.UDS.ru8WMBA_MA_LENGTH);
                    break;
                }

                    /* TODO as needed
                     * default:
                     *  {
                     *      au8WMBA[ConstantData.UDS.ru8WMBA_MA_OFFSET] = (byte)(u32Arg1 & 0xff);
                     *      break;
                     *  }
                     */
                }

                switch (ConstantData.UDS.ru8WMBA_MS_LENGTH)
                {
                case 2:
                {
                    au8Temp = BitConverter.GetBytes((UInt16)i32Arg2);
                    Array.Copy(au8Temp, 0, au8WMBA, ConstantData.UDS.ru8WMBA_MS_OFFSET, ConstantData.UDS.ru8WMBA_MS_LENGTH);
                    break;
                }

                    /* TODO as needed
                     * default:
                     *  {
                     *      au8WMBA[ConstantData.UDS.ru8WMBA_MS_OFFSET] = (byte)(i32Arg2 & 0xff);
                     *      break;
                     *  }
                     */
                }

                byte[] au8WMBAWithData = new byte[au8WMBA.Length + au8Data.Length];

                Array.Copy(au8WMBA, au8WMBAWithData, au8WMBA.Length);
                Array.Copy(au8Data, 0, au8WMBAWithData, au8WMBA.Length, au8Data.Length);

                lUDSFrameList = mclsISO15765.lstSegmentData(au8WMBAWithData);

                foreach (tclsUDSFrame clsSegUDSFrame in lUDSFrameList)
                {
                    mclsOutputQueue.Enqueue(clsSegUDSFrame);
                }

                break;
            }

            case ConstantData.UDS.ru8SID_DDDI:
            {
                byte[] au8DDDIWithData = new byte[au8DDDI.Length + au8Data.Length];

                au8DDDI[0] = ConstantData.UDS.ru8SID_DDDI;
                au8DDDI[1] = ConstantData.UDS.ru8SFID_DDDI_DMBA;
                au8DDDI[2] = (byte)(u32Arg1 & 0xff);
                au8DDDI[3] = (byte)((u32Arg1 >> 8) & 0xff);
                au8DDDI[4] = ConstantData.UDS.ru8DDDI_ALFID;

                Array.Copy(au8DDDI, au8DDDIWithData, au8DDDI.Length);
                Array.Copy(au8Data, 0, au8DDDIWithData, au8DDDI.Length, au8Data.Length);

                lUDSFrameList = mclsISO15765.lstSegmentData(au8DDDIWithData);

                foreach (tclsUDSFrame clsSegUDSFrame in lUDSFrameList)
                {
                    mclsOutputQueue.Enqueue(clsSegUDSFrame);
                }

                break;
            }

            case ConstantData.UDS.ru8SID_RC:
            {
                clsUDSFrame.au8Data[0]  = 4;
                clsUDSFrame.au8Data[1]  = ConstantData.UDS.ru8SID_RC;
                clsUDSFrame.au8Data[2]  = (byte)u32Arg1;
                clsUDSFrame.au8Data[3]  = ConstantData.UDS.ru8RCID_HighByte;
                clsUDSFrame.au8Data[4]  = u8SSID;
                clsUDSFrame.u8ByteCount = 5;
                mclsOutputQueue.Enqueue(clsUDSFrame);
                break;
            }
            }
        }
コード例 #4
0
 public tclsTransferData()
 {
     mau8Data     = new byte[65536];
     mclsUDSFrame = new tclsUDSFrame();
 }