Exemple #1
0
        public bool testSRAMWrite(/*int address, byte[] data*/)
        {
            StartSession10();
            CastInfoEvent("Requesting mandatory data", ActivityType.UploadingBootloader);

            RequestECUInfo(0x90);
            RequestECUInfo(0x97);
            RequestECUInfo(0x92);
            RequestECUInfo(0xB4);
            RequestECUInfo(0xC1);
            RequestECUInfo(0xC2);
            RequestECUInfo(0xC3);
            RequestECUInfo(0xC4);
            RequestECUInfo(0xC5);
            RequestECUInfo(0xC6);
            Send0120();
            Thread.Sleep(1000);

            StartSession1081();

            StartSession10();
            CastInfoEvent("Telling ECU to clear CANbus", ActivityType.UploadingBootloader);
            SendShutup();
            SendA2();
            SendA5();
            SendA503();
            Thread.Sleep(500);
            SendKeepAlive();
            _securityLevel = AccessLevel.AccessLevel01;
            CastInfoEvent("Requesting security access", ActivityType.UploadingBootloader);
            RequestSecurityAccess(2000);
            Thread.Sleep(500);
            CastInfoEvent("Uploading data", ActivityType.UploadingBootloader);

            int startAddress = 0x102400;
            int saved_progress = 0;
            Bootloader btloaderdata = new Bootloader();
            if (requestDownload())
            {
                for (int i = 0; i < 0x46; i++)
                {
                    //10 F0 36 00 00 10 24 00
                    //Console.WriteLine("Sending bootloader: " + startAddress.ToString("X8"));
                    // cast event
                    int percentage = (int)(((float)i * 100) / 70F);
                    if (percentage > saved_progress)
                    {
                        CastProgressWriteEvent(percentage);
                        saved_progress = percentage;
                    }

                    byte iFrameNumber = 0x21;
                    if (SendTransferData(0xF0, startAddress, 0x7E8))
                    {
                        // send 0x22 (34) frames with data from bootloader
                        CANMessage msg = new CANMessage(0x7E0, 0, 8);
                        for (int j = 0; j < 0x22; j++)
                        {
                            ulong cmd = 0x0000000000000000; // 0x34 = upload data to ECU
                            msg.setData(cmd);
                            msg.setCanData(iFrameNumber, 0);
                            msg.setCanData(0x00, 1);
                            msg.setCanData(0x01, 2);
                            msg.setCanData(0x02, 3);
                            msg.setCanData(0x03, 4);
                            msg.setCanData(0x04, 5);
                            msg.setCanData(0x05, 6);
                            msg.setCanData(0x06, 7);
                            iFrameNumber++;
                            if (iFrameNumber > 0x2F) iFrameNumber = 0x20;
                            if (!canUsbDevice.sendMessage(msg))
                            {
                                logger.Debug("Couldn't send message");
                            }
                            Thread.Sleep(1);
                        }
                        // send the remaining data
                        m_canListener.setupWaitMessage(0x7E8);
                        // now wait for 01 76 00 00 00 00 00 00
                        CANMessage response = new CANMessage();
                        response = new CANMessage();
                        response = m_canListener.waitMessage(timeoutP2ct);
                        ulong datax = response.getData();
                        if (getCanData(datax, 0) != 0x01 || getCanData(datax, 1) != 0x76)
                        {
                            return false;
                        }
                        SendKeepAlive();
                        startAddress += 0xEA;

                    }
                    else
                    {
                        Console.WriteLine("Did not receive correct response from SendTransferData");
                    }
                }
            }
            return true;
        }
Exemple #2
0
        private bool UploadBootloaderWrite()
        {
            int startAddress = 0x102400;
            #if (DEBUG)
            BootloaderFromFile btloaderdata = new BootloaderFromFile();
            #else
            Bootloader btloaderdata = new Bootloader();
            #endif
            int txpnt = 0;
            byte iFrameNumber = 0x21;
            int saved_progress = 0;
            if (requestDownload())
            {
                for (int i = 0; i < 0x46; i++)
                {
                    iFrameNumber = 0x21;
                    //10 F0 36 00 00 10 24 00
                    //Console.WriteLine("Sending bootloader: " + startAddress.ToString("X8"));
                    // cast event
                    int percentage = (int)(((float)i * 100) / 70F);
                    if (percentage > saved_progress)
                    {
                        CastProgressWriteEvent(percentage);
                        saved_progress = percentage;
                    }

                    if (SendTransferData(0xF0, startAddress, 0x7E8))
                    {
                        canUsbDevice.RequestDeviceReady();
                        // send 0x22 (34) frames with data from bootloader
                        CANMessage msg = new CANMessage(0x7E0, 0, 8);
                        for (int j = 0; j < 0x22; j++)
                        {
                            var cmd = BitTools.GetFrameBytes(iFrameNumber, btloaderdata.BootloaderProgBytes, txpnt);
                            msg.setData(cmd);
                            txpnt += 7;
                            iFrameNumber++;

                            if (iFrameNumber > 0x2F) iFrameNumber = 0x20;
                            msg.elmExpectedResponses = j == 0x21 ? 1 : 0;//on last command (iFrameNumber 22 expect 1 message)
                            if (j == 0x21)
                                m_canListener.ClearQueue();

                            if (!canUsbDevice.sendMessage(msg))
                            {
                                logger.Debug("Couldn't send message");
                            }
                            Thread.Sleep(m_sleepTime);
                        }
                        // now wait for 01 76 00 00 00 00 00 00
                        ulong data = m_canListener.waitMessage(timeoutP2ct, 0x7E8).getData();
                        if (getCanData(data, 0) != 0x01 || getCanData(data, 1) != 0x76)
                        {
                            return false;
                        }
                        canUsbDevice.RequestDeviceReady();
                        SendKeepAlive();
                        startAddress += 0xEA;

                    }
                    else
                    {
                        Console.WriteLine("Did not receive correct response from SendTransferData");
                    }
                }

                iFrameNumber = 0x21;
                if (SendTransferData(0x0A, startAddress, 0x7E8))
                {
                    // send 0x22 (34) frames with data from bootloader
                    CANMessage msg = new CANMessage(0x7E0, 0, 8);
                    var cmd = BitTools.GetFrameBytes(iFrameNumber, btloaderdata.BootloaderBytes, txpnt);
                    msg.setData(cmd);
                    txpnt += 7;
                    iFrameNumber++;
                    if (iFrameNumber > 0x2F) iFrameNumber = 0x20;
                    if (!canUsbDevice.sendMessage(msg))
                    {
                        logger.Debug("Couldn't send message");
                    }
                    if (m_sleepTime > 0)
                        Thread.Sleep(m_sleepTime);

                    ulong data = m_canListener.waitMessage(timeoutP2ct, 0x7E8).getData();
                    if (getCanData(data, 0) != 0x01 || getCanData(data, 1) != 0x76)
                    {
                        return false;
                    }
                    SendKeepAlive();
                    startAddress += 0x06;
                }
                else
                {
                    Console.WriteLine("Did not receive correct response from SendTransferData");
                }

                CastProgressWriteEvent(100);
            }
            else
            {
                Console.WriteLine("requestDownload() failed");
                return false;
            }
            return true;
        }
Exemple #3
0
        private bool UploadBootloaderT8Recover()
        {
            int startAddress = 0x102400;
            Bootloader btloaderdata = new Bootloader();
            int txpnt = 0;
            byte iFrameNumber = 0x21;
            if (requestDownload011())
            {
                for (int i = 0; i < 0x46; i++)
                {
                    iFrameNumber = 0x21;
                    //10 F0 36 00 00 10 24 00
                    //Console.WriteLine("Sending bootloader: " + startAddress.ToString("X8"));
                    // cast event
                    float percentage = ((float)i * 100) / 70F;
                    CastProgressWriteEvent(percentage);

                    if (SendTransferData011(0xF0, startAddress, 0x311))
                    {
                        //canUsbDevice.RequestDeviceReady();
                        // send 0x22 (34) frames with data from bootloader
                        CANMessage msg = new CANMessage(0x11, 0, 8);
                        for (int j = 0; j < 0x22; j++)
                        {
                            var cmd = BitTools.GetFrameBytes(iFrameNumber, btloaderdata.BootloaderProgBytes, txpnt);
                            msg.setData(cmd);
                            txpnt += 7;
                            iFrameNumber++;
                            if (iFrameNumber > 0x2F) iFrameNumber = 0x20;
                            msg.elmExpectedResponses = j == 0x21 ? 1 : 0;//on last command (iFrameNumber 22 expect 1 message)
                            if (!canUsbDevice.sendMessage(msg))
                            {
                                AddToCanTrace("Couldn't send message");
                            }
                            Application.DoEvents();
                            if (m_sleepTime > 0)
                                Thread.Sleep(m_sleepTime);
                        }
                        // now wait for 01 76 00 00 00 00 00 00
                        ulong data = m_canListener.waitMessage(1000, 0x311).getData();
                        if (getCanData(data, 0) != 0x01 || getCanData(data, 1) != 0x76)
                        {
                            return false;
                        }
                        //canUsbDevice.RequestDeviceReady();
                        BroadcastKeepAlive();
                        startAddress += 0xEA;

                    }
                    else
                    {
                        Console.WriteLine("Did not receive correct response from SendTransferData");
                    }
                }

                iFrameNumber = 0x21;
                if (SendTransferData011(0x0A, startAddress, 0x311))
                {
                    // send 0x22 (34) frames with data from bootloader
                    CANMessage msg = new CANMessage(0x11, 0, 8);

                    var cmd = BitTools.GetFrameBytes(iFrameNumber, btloaderdata.BootloaderProgBytes, txpnt);
                    msg.setData(cmd);
                    txpnt += 7;
                    iFrameNumber++;
                    if (iFrameNumber > 0x2F) iFrameNumber = 0x20;
                    if (!canUsbDevice.sendMessage(msg))
                    {
                        AddToCanTrace("Couldn't send message");
                    }
                    if (m_sleepTime > 0)
                        Thread.Sleep(m_sleepTime);

                    // now wait for 01 76 00 00 00 00 00 00
                    ulong data = m_canListener.waitMessage(1000, 0x311).getData();
                    if (getCanData(data, 0) != 0x01 || getCanData(data, 1) != 0x76)
                    {
                        return false;
                    }
                    BroadcastKeepAlive();
                    startAddress += 0x06;
                }
                else
                {
                    Console.WriteLine("Did not receive correct response from SendTransferData");
                }

                CastProgressWriteEvent(100);
            }
            return true;
        }