예제 #1
0
        void sendCan()
        {
            try
            {
                processStr = sequence[processIndex.ToString()].ToString();
            }
            catch (NullReferenceException)
            {
                flashFlag = false;
                return;
            }

            mainSendData.Clear();
            mainSendData.AddRange(CanControl.canStringToByte(flashProcess[processStr].ToString()));
            ServiceIdentifier = mainSendData[0];

            switch (processStr)
            {
            case "SeedRequest":
                mainSendData.Add(securityAccess[0]);
                break;

            case "KeySend":
                byte[] seed = new byte[4];
                Array.Copy(CanControl.Rev, 3, seed, 0, 4);
                byte[] key = sec.seedToKey(seed);
                mainSendData.Add(securityAccess[1]);
                mainSendData.AddRange(key);
                break;

            case "DownloadRequest":
                if (s19File == null)
                {
                    s19File = s19.getS19File();
                    s19FileDataCRC32Value = CRC32.GetCRC_Custom(s19File);
                }
                s19Block = s19File[s19BlockIndex];
                mainSendData.AddRange(s19Block.StartAddress);
                mainSendData.AddRange(s19Block.DataLength);
                break;

            case "DataTransfer":
                int bootCacheBlockDataIndex = bootCacheBlockSequenceIndex * (bootCacheLength - 2);
                mainSendData.Add(bootCacheBlockSequenceCounter);
                for (int i = 0; i < bootCacheLength - 2; i++)
                {
                    int indexTmp = bootCacheBlockDataIndex + i;
                    if (indexTmp >= s19Block.Data.Length)
                    {
                        break;
                    }
                    mainSendData.Add(s19Block.Data[indexTmp]);
                }
                bootCacheBlockSequenceCounter = (byte)((bootCacheBlockSequenceCounter + 1) & 0xFF);
                bootCacheBlockSequenceIndex++;
                break;

            case "RoutineIdentifier":
                byte[] crc32Byte = new byte[4];
                for (int i = 0; i < 4; i++)
                {
                    crc32Byte[i] = (byte)(s19FileDataCRC32Value >> (8 * (3 - i)));
                }
                mainSendData.AddRange(crc32Byte);
                break;

            case "MemoryErase":
                mainSendData.Add(0x44);
                if (s19File == null)
                {
                    s19File = s19.getS19File();
                    s19FileDataCRC32Value = CRC32.GetCRC_Custom(s19File);
                }
                mainSendData.AddRange(s19File[s19BlockIndex].StartAddress);
                mainSendData.AddRange(s19File[s19BlockIndex].DataLength);
                break;

            default:
                break;
            }

            sendResult = CanControl.sendFrame(physicalID, receiveID, mainSendData.ToArray());
        }
예제 #2
0
파일: CRC32.cs 프로젝트: cwbhhjl/USBCAN
 internal static uint GetCRC_Custom(S19Block[] s19File)
 {
     GetCrcCustomTable();
     List<byte> byteList = new List<byte>();
     Array.ForEach(s19File, block => byteList.AddRange(block.Data));
     uint crc = 0xFFFFFFFF;
     foreach (byte b in byteList)
     {
         crc = (crc << 8) ^ CrcCustomTable[((crc >> 24) ^ b) & 0xFF];
     }
     return crc ^ 0xFFFFFFFF;
 }
예제 #3
0
파일: Flash.cs 프로젝트: cwbhhjl/USBCAN
        void sendCan()
        {
            try
            {
                processStr = sequence[processIndex.ToString()].ToString();
            }
            catch(NullReferenceException)
            {
                flashFlag = false;
                return;
            }

            mainSendData.Clear();
            mainSendData.AddRange(CanControl.canStringToByte(flashProcess[processStr].ToString()));
            ServiceIdentifier = mainSendData[0];

            switch (processStr)
            {
                case "SeedRequest":
                    mainSendData.Add(securityAccess[0]);
                    break;

                case "KeySend":
                    byte[] seed = new byte[4];
                    Array.Copy(CanControl.Rev, 3, seed, 0, 4);
                    byte[] key = sec.seedToKey(seed);
                    mainSendData.Add(securityAccess[1]);
                    mainSendData.AddRange(key);
                    break;

                case "DownloadRequest":
                    if (s19File == null)
                    {
                        s19File = s19.getS19File();
                        s19FileDataCRC32Value = CRC32.GetCRC_Custom(s19File);
                    }
                    s19Block = s19File[s19BlockIndex];
                    mainSendData.AddRange(s19Block.StartAddress);
                    mainSendData.AddRange(s19Block.DataLength);
                    break;

                case "DataTransfer":
                    int bootCacheBlockDataIndex = bootCacheBlockSequenceIndex * (bootCacheLength - 2);
                    mainSendData.Add(bootCacheBlockSequenceCounter);
                    for (int i = 0; i < bootCacheLength - 2; i++)
                    {
                        int indexTmp = bootCacheBlockDataIndex + i;
                        if (indexTmp >= s19Block.Data.Length)
                        {
                            break;
                        }
                        mainSendData.Add(s19Block.Data[indexTmp]);
                    }
                    bootCacheBlockSequenceCounter = (byte)((bootCacheBlockSequenceCounter + 1) & 0xFF);
                    bootCacheBlockSequenceIndex++;
                    break;

                case "RoutineIdentifier":
                    byte[] crc32Byte = new byte[4];
                    for (int i = 0; i < 4; i++)
                    {
                        crc32Byte[i] = (byte)(s19FileDataCRC32Value >> (8 * (3 - i)));
                    }
                    mainSendData.AddRange(crc32Byte);
                    break;

                case "MemoryErase":
                    mainSendData.Add(0x44);
                    if (s19File == null)
                    {
                        s19File = s19.getS19File();
                        s19FileDataCRC32Value = CRC32.GetCRC_Custom(s19File);
                    }
                    mainSendData.AddRange(s19File[s19BlockIndex].StartAddress);
                    mainSendData.AddRange(s19File[s19BlockIndex].DataLength);
                    break;

                default:
                    break;
            }

            sendResult = CanControl.sendFrame(physicalID, receiveID, mainSendData.ToArray());
        }