From 5f88c8f856e197d8fca064aa5c7becaeb3f1372d Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Fri, 8 Dec 2023 13:01:47 +0100 Subject: [PATCH] Test implementation of download thread without an actual download of dc. --- src/download_thread.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/download_thread.cpp b/src/download_thread.cpp index 194d91d..9dc82a7 100644 --- a/src/download_thread.cpp +++ b/src/download_thread.cpp @@ -2,9 +2,15 @@ #include "shared_mem_buffer.h" #include "hwapi.h" +#include +#include + + DownloadThread::DownloadThread(hwinf *hw) : m_hw(hw) , m_fileToDownload(m_hw->dcDownloadFileName()) { + // connect(this, &QThread::finished, + // dynamic_cast(m_hw), &QThread::deleteLater); } DownloadThread::~DownloadThread() { @@ -12,10 +18,26 @@ DownloadThread::~DownloadThread() { // download thread running in ca-master sends the dc-file down to firmware void DownloadThread::run() { - // m_hw->dcDownloadInit(m_fileToDownload); - // hier dann den eigentlichen download-process eintragen + m_hw->dcDownloadRequestAck(); - // m_hw->dcDownloadGetCurrentBlockNumber(currentBlockNumber); - // m_hw->dcDownloadGetTotalBlockNumber(totalBlockNumber); + qCritical() << QDateTime::currentDateTime().toString(Qt::ISODate) + "DOWNLOAD THREAD STARTED"; + + // test code: + uint16_t const totalBlocks = 100; + m_hw->dcDownloadSetTotalBlockNumber(totalBlocks); + + for (uint16_t currentBlock = 0; currentBlock <= totalBlocks; ++currentBlock) { + m_hw->dcDownloadSetCurrentBlockNumber(currentBlock); + QThread::msleep(100); + } + + m_hw->dcDownloadSetRunning(false); + m_hw->dcDownloadSetFinished(true); + + qCritical() << QDateTime::currentDateTime().toString(Qt::ISODate) + "DOWNLOAD THREAD FINISHED"; + + // the object deletes itself ! This is the last line in run(). + // Never touch the object after this statement + // m_hw->dcDownloadThreadFinalize(this); }