Exemple #1
0
        private bool WriteFlashRecover(BlockManager bm)
        {
            int startAddress = 0x020000;
            int saved_progress = 0;
            for (int blockNumber = 0; blockNumber <= 0xF50; blockNumber++)
            {
                int percentage = (int)(((float)blockNumber * 100) / 3920F);
                if (percentage > saved_progress)
                {
                    CastProgressWriteEvent(percentage);
                    saved_progress = percentage;
                }
                byte[] data2Send = bm.GetNextBlock();
                int length = 0xF0;
                if (blockNumber == 0xF50) length = 0xE6;
                if (SendTransferData(length, startAddress + (blockNumber * 0xEA), 0x311))
                {
                    //canUsbDevice.RequestDeviceReady();
                    // send the data from the block
                    // calculate number of frames
                    int numberOfFrames = (int)data2Send.Length / 7; // remnants?
                    if (((int)data2Send.Length % 7) > 0) numberOfFrames++;
                    byte iFrameNumber = 0x21;
                    int txpnt = 0;
                    CANMessage msg = new CANMessage(0x7E0, 0, 8);
                    for (int frame = 0; frame < numberOfFrames; frame++)
                    {
                        var cmd = BitTools.GetFrameBytes(iFrameNumber, data2Send, txpnt);
                        msg.setData(cmd);
                        txpnt += 7;
                        iFrameNumber++;
                        if (iFrameNumber > 0x2F) iFrameNumber = 0x20;
                        msg.elmExpectedResponses = frame == numberOfFrames - 1 ? 1 : 0;

                        if (frame == numberOfFrames - 1)
                            m_canListener.ClearQueue();
                        if (!canUsbDevice.sendMessage(msg))
                        {
                            logger.Debug("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(timeoutP2ct, 0x7E8).getData();
                    if (getCanData(data, 0) != 0x01 || getCanData(data, 1) != 0x76)
                    {
                        _stallKeepAlive = false;
                        return false;
                    }
                    //canUsbDevice.RequestDeviceReady();
                    BroadcastKeepAlive();

                }
            }
            return true;
        }
Exemple #2
0
        /// <summary>
        /// Send ONLY the erase and write commands, ECU is already in running bootloader
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public bool RecoverECUOLD(string filename)
        {
            if (!canUsbDevice.isOpen()) return false;
            _stallKeepAlive = true;
            BlockManager bm = new BlockManager();
            bm.SetFilename(filename);
            int startAddress = 0x020000;
            int saved_progress = 0;

            SendKeepAlive();
            _securityLevel = AccessLevel.AccessLevel01;
            CastInfoEvent("Erasing FLASH", ActivityType.StartErasingFlash);
            if (SendrequestDownload(true))
            {
                CastInfoEvent("Programming FLASH", ActivityType.UploadingFlash);
                for (int blockNumber = 0; blockNumber <= 0xF50; blockNumber++)
                {
                    int percentage = (int)(((float)blockNumber * 100) / 3920F);
                    if (percentage > saved_progress)
                    {
                        CastProgressWriteEvent(percentage);
                        saved_progress = percentage;
                    }
                    byte[] data2Send = bm.GetNextBlock();
                    int length = 0xF0;
                    if (blockNumber == 0xF50) length = 0xE6;
                    if (SendTransferData(length, startAddress + (blockNumber * 0xEA), 0x311))
                    {
                        // send the data from the block

                        // calculate number of frames
                        int numberOfFrames = (int)data2Send.Length / 7; // remnants?
                        if (((int)data2Send.Length % 7) > 0) numberOfFrames++;
                        byte iFrameNumber = 0x21;
                        int txpnt = 0;
                        CANMessage msg = new CANMessage(0x7E0, 0, 8);
                        for (int frame = 0; frame < numberOfFrames; frame++)
                        {
                            ulong cmd = 0x0000000000000000; // 0x34 = upload data to ECU
                            msg.setData(cmd);
                            msg.setCanData(iFrameNumber, 0);
                            msg.setCanData(data2Send[txpnt++], 1);
                            msg.setCanData(data2Send[txpnt++], 2);
                            msg.setCanData(data2Send[txpnt++], 3);
                            msg.setCanData(data2Send[txpnt++], 4);
                            msg.setCanData(data2Send[txpnt++], 5);
                            msg.setCanData(data2Send[txpnt++], 6);
                            msg.setCanData(data2Send[txpnt++], 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 data = response.getData();
                        if (getCanData(data, 0) != 0x01 || getCanData(data, 1) != 0x76)
                        {
                            return false;
                        }
                        SendKeepAlive();
                    }
                }
                sw.Stop();
                CastInfoEvent("FLASH upload completed", ActivityType.ConvertingFile);
                // what else to do?
                Send0120();
                CastInfoEvent("Session ended", ActivityType.FinishedFlashing);
            }
            else
            {
                sw.Stop();
                CastInfoEvent("Failed to erase FLASH", ActivityType.ConvertingFile);
                Send0120();
                CastInfoEvent("Session ended", ActivityType.FinishedFlashing);
                return false;

            }
            _stallKeepAlive = false;
            return true;
        }
Exemple #3
0
        private bool ProgramFlash(BlockManager bm)
        {
            const int startAddress = 0x020000;
            int lastBlockNumber = bm.GetLastBlockNumber();
            int saved_progress = 0;

            for (int blockNumber = 0; blockNumber <= lastBlockNumber; blockNumber++) // All blocks == 0xF50
            {
                int percentage = (int)(((float)blockNumber * 100) / (float)lastBlockNumber);
                if (percentage > saved_progress)
                {
                    CastProgressWriteEvent(percentage);
                    saved_progress = percentage;
                }
                byte[] data2Send = bm.GetNextBlock();
                int length = 0xF0;
                if (blockNumber == 0xF50) length = 0xE6;

                int currentAddress = startAddress + (blockNumber * 0xEA);
                sw.Reset();
                sw.Start();
                if (SendTransferData(length, currentAddress, 0x7E8))
                {
                    canUsbDevice.RequestDeviceReady();
                    // calculate number of frames
                    int numberOfFrames = (int)data2Send.Length / 7; // remnants?
                    if (((int)data2Send.Length % 7) > 0) numberOfFrames++;
                    byte iFrameNumber = 0x21;
                    int txpnt = 0;
                    CANMessage msg = new CANMessage(0x7E0, 0, 8);
                    for (int frame = 0; frame < numberOfFrames; frame++)
                    {
                        var cmd = BitTools.GetFrameBytes(iFrameNumber, data2Send, txpnt);
                        msg.setData(cmd);
                        txpnt += 7;
                        iFrameNumber++;
                        if (iFrameNumber > 0x2F) iFrameNumber = 0x20;
                        msg.elmExpectedResponses = (frame == numberOfFrames - 1) ? 1 : 0;

                        if (frame == numberOfFrames - 1)
                            m_canListener.ClearQueue();

                        if (!canUsbDevice.sendMessage(msg))
                        {
                            logger.Debug("Couldn't send message");
                        }
                        if (m_sleepTime > 0)
                            Thread.Sleep(m_sleepTime);
                    }
                    Application.DoEvents();

                    // 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)
                    {
                        CastInfoEvent("Got incorrect response " + data.ToString("X16"), ActivityType.UploadingFlash);
                        _stallKeepAlive = false;
                        return false;
                    }
                    canUsbDevice.RequestDeviceReady();
                    SendKeepAlive();
                }
                sw.Stop();
            }
            return true;
        }
Exemple #4
0
        private bool ProgramFlashT8(BlockManager bm)
        {
            int startAddress = 0x020000;

            for (int blockNumber = 0; blockNumber <= 0xF50; blockNumber++)
            {
                float percentage = ((float)blockNumber * 100) / 3920F;
                CastProgressWriteEvent(percentage);
                bool canSkip = bm.CanSkipCurrentBlock();
                byte[] data2Send = bm.GetNextBlock();
                int length = 0xF0;
                if (blockNumber == 0xF50) length = 0xE6;

                Stopwatch blockSw = new Stopwatch();
                int currentAddress = startAddress + (blockNumber * 0xEA);
                if (!canSkip)
                {
                    sw.Reset();
                    sw.Start();
                    if (SendTransferData(length, currentAddress, 0x7E8))
                    {
                        canUsbDevice.RequestDeviceReady();
                        // calculate number of frames
                        int numberOfFrames = (int)data2Send.Length / 7; // remnants?
                        if (((int)data2Send.Length % 7) > 0) numberOfFrames++;
                        byte iFrameNumber = 0x21;
                        int txpnt = 0;
                        CANMessage msg = new CANMessage(0x7E0, 0, 8);
                        for (int frame = 0; frame < numberOfFrames; frame++)
                        {
                            var cmd = BitTools.GetFrameBytes(iFrameNumber, data2Send, txpnt);
                            msg.setData(cmd);
                            txpnt += 7;
                            iFrameNumber++;
                            if (iFrameNumber > 0x2F) iFrameNumber = 0x20;
                            msg.elmExpectedResponses = (frame == numberOfFrames - 1) ? 1 : 0;

                            if (frame == numberOfFrames - 1)
                                m_canListener.ClearQueue();

                            if (!canUsbDevice.sendMessage(msg))
                            {
                                AddToCanTrace("Couldn't send message");
                            }
                            if (m_sleepTime > 0)
                                Thread.Sleep(m_sleepTime);
                        }
                        Application.DoEvents();

                        // now wait for 01 76 00 00 00 00 00 00
                        ulong data = m_canListener.waitMessage(1000, 0x7E8).getData();
                        if (getCanData(data, 0) != 0x01 || getCanData(data, 1) != 0x76)
                        {
                            CastInfoEvent("Got incorrect response " + data.ToString("X16"), ActivityType.UploadingFlash);
                            _stallKeepAlive = false;
                            return false;
                        }
                        canUsbDevice.RequestDeviceReady();
                        SendKeepAlive();
                    }
                    sw.Stop();
                    //Console.WriteLine(string.Format("Programming block {0} took {1}", blockNumber, sw.Elapsed),ActivityType.UploadingFlash);
                }
                else
                {
                    Console.WriteLine("Skipping block at " + currentAddress);
                }
            }
            return true;
        }