DownloadThread: add real dc-download implementation.
This commit is contained in:
		@@ -99,32 +99,41 @@ DownloadThread::~DownloadThread() {
 | 
				
			|||||||
                        // bootloader is really not running anymore.
 | 
					                        // bootloader is really not running anymore.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void DownloadThread::run() {
 | 
					void DownloadThread::run() {
 | 
				
			||||||
// download thread running in ca-master sends the dc-file down to firmware
 | 
					    // download thread running in ca-master sends the dc-file down to firmware
 | 
				
			||||||
#if 0
 | 
					    // TODO: send the json files as well
 | 
				
			||||||
    Update::DownloadResult Update::dc_downloadBinary(QByteArray const &b) const {
 | 
					 | 
				
			||||||
        int const nBlocks = (((b.size())%64)==0) ? (b.size()/64) : (b.size()/64)+1;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // fill lst block of data to be sent with 0xFF
 | 
					    m_hw->dcDownloadRequestAck();
 | 
				
			||||||
        QByteArray ba = b.leftJustified(nBlocks*64, (char)(0xFF));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        qInfo() << "total number of bytes to send to dc" << ba.size();
 | 
					    qCritical() << "DownloadThread::run(): DOWNLOAD THREAD STARTED";
 | 
				
			||||||
        qInfo() << "total number of blocks to send to dc" << nBlocks;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        int bNum = 0;
 | 
					    // load binary device controller file into memory
 | 
				
			||||||
 | 
					    QByteArray ba = loadBinaryDCFile(m_hw->dcDownloadFileName());
 | 
				
			||||||
 | 
					    if (ba.size() > 0) {
 | 
				
			||||||
 | 
					        uint16_t const totalBlocks = (((ba.size())%64)==0) ? (ba.size()/64) : (ba.size()/64)+1;
 | 
				
			||||||
 | 
					        m_hw->dcDownloadSetTotalBlockNumber(totalBlocks);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // fill last block of data to be sent with 0xFF
 | 
				
			||||||
 | 
					        ba = ba.leftJustified(totalBlocks*64, (char)(0xFF));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        resetDeviceController();
 | 
				
			||||||
 | 
					        if (startBootloader()) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            qCritical() << "DownloadThread::run(): TOTAL NUMBER OF BYTES TO SEND TO DC" << ba.size();
 | 
				
			||||||
 | 
					            qCritical() << "DownloadThread::run(): TOTAL NUMBER OF BLOCKS" << totalBlocks;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            int currentBlock = 0;
 | 
				
			||||||
            DownloadResult res = DownloadResult::OK;
 | 
					            DownloadResult res = DownloadResult::OK;
 | 
				
			||||||
        fprintf(stderr, "\n64-byte block %04d ", bNum);
 | 
					            qCritical() << "64-byte block " << currentBlock;
 | 
				
			||||||
        while (res != DownloadResult::ERROR &&  bNum < nBlocks) {
 | 
					            while (res != DownloadResult::ERROR &&  currentBlock < totalBlocks) {
 | 
				
			||||||
            if ((res = sendNextAddress(bNum)) != DownloadResult::ERROR) {
 | 
					                if ((res = sendNextAddress(currentBlock)) != DownloadResult::ERROR) {
 | 
				
			||||||
                if ((res = sendNextDataBlock(ba, bNum)) != DownloadResult::ERROR) {
 | 
					                    if ((res = sendNextDataBlock(ba, currentBlock)) != DownloadResult::ERROR) {
 | 
				
			||||||
                    bNum += 1;
 | 
					                        m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
 | 
				
			||||||
                    fprintf(stderr, ".");
 | 
					                        currentBlock += 1;
 | 
				
			||||||
                    if ((bNum % 80) == 0) {
 | 
					 | 
				
			||||||
                        fprintf(stderr, "\n64-byte block %04d ", bNum);
 | 
					 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					
 | 
				
			||||||
        fprintf(stderr, "\nlast 64-byte block %04d\n", bNum);
 | 
					            qCritical() << "DownloadThread::run(): last 64-byte block %04d" << currentBlock;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            int const rest = ba.size() % 64;
 | 
					            int const rest = ba.size() % 64;
 | 
				
			||||||
            int const offset = ba.size() - rest;
 | 
					            int const offset = ba.size() - rest;
 | 
				
			||||||
@@ -135,21 +144,18 @@ void DownloadThread::run() {
 | 
				
			|||||||
                uint8_t local[66];
 | 
					                uint8_t local[66];
 | 
				
			||||||
                memset(local, 0xFF, sizeof(local));
 | 
					                memset(local, 0xFF, sizeof(local));
 | 
				
			||||||
                memcpy(local, startAddress, rest);
 | 
					                memcpy(local, startAddress, rest);
 | 
				
			||||||
            qCritical() << "ERROR SEND REMAINING" << rest << "BYTES";
 | 
					                qCritical() << "DownloadThread::run(): ERROR SEND REMAINING" << rest << "BYTES";
 | 
				
			||||||
                m_hw->bl_sendDataBlock(64, local);
 | 
					                m_hw->bl_sendDataBlock(64, local);
 | 
				
			||||||
        }
 | 
					            } else {
 | 
				
			||||||
 | 
					 | 
				
			||||||
                m_hw->bl_sendLastBlock();
 | 
					                m_hw->bl_sendLastBlock();
 | 
				
			||||||
        qInfo() << "last result" << (int)sendStatus(m_hw->bl_wasSendingDataOK());
 | 
					                m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
 | 
				
			||||||
        return res;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            qCritical() << "DownloadThread::run(): last result" << (int)sendStatus(m_hw->bl_wasSendingDataOK());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        stopBootloader();   // there is no harm in stopping the bootloader even
 | 
				
			||||||
 | 
					    }                       // if it was not started at all
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#if 0
 | 
				
			||||||
 | 
					 | 
				
			||||||
    m_hw->dcDownloadRequestAck();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    qCritical() << QDateTime::currentDateTime().toString(Qt::ISODate) + "DOWNLOAD THREAD STARTED";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // test code:
 | 
					    // test code:
 | 
				
			||||||
    uint16_t const totalBlocks = 100;
 | 
					    uint16_t const totalBlocks = 100;
 | 
				
			||||||
    m_hw->dcDownloadSetTotalBlockNumber(totalBlocks);
 | 
					    m_hw->dcDownloadSetTotalBlockNumber(totalBlocks);
 | 
				
			||||||
@@ -158,6 +164,7 @@ void DownloadThread::run() {
 | 
				
			|||||||
        m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
 | 
					        m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
 | 
				
			||||||
        QThread::msleep(100);
 | 
					        QThread::msleep(100);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    m_hw->dcDownloadSetRunning(false);
 | 
					    m_hw->dcDownloadSetRunning(false);
 | 
				
			||||||
    m_hw->dcDownloadSetFinished(true);
 | 
					    m_hw->dcDownloadSetFinished(true);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user