forked from GerhardHoffmann/DCLibraries
		
	Save development files.
This commit is contained in:
		@@ -93,7 +93,9 @@ HEADERS += \
 | 
			
		||||
    $${PWD}/include/sendWRcmd.h \
 | 
			
		||||
    $${PWD}/include/storeINdata.h \
 | 
			
		||||
    $${PWD}/include/tslib.h \
 | 
			
		||||
    $${PWD}/include/shared_mem_buffer.h
 | 
			
		||||
    $${PWD}/include/shared_mem_buffer.h \
 | 
			
		||||
    $${PWD}/include/download_thread.h \
 | 
			
		||||
    $${PWD}/include/reporting_thread.h
 | 
			
		||||
 | 
			
		||||
SOURCES += \
 | 
			
		||||
    $${PWD}/src/com.cpp \
 | 
			
		||||
@@ -107,7 +109,9 @@ SOURCES += \
 | 
			
		||||
    $${PWD}/src/sendWRcmd.cpp \
 | 
			
		||||
    $${PWD}/src/storeINdata.cpp \
 | 
			
		||||
    $${PWD}/src/tslib.cpp \
 | 
			
		||||
    $${PWD}/src/shared_mem_buffer.cpp
 | 
			
		||||
    $${PWD}/src/shared_mem_buffer.cpp \
 | 
			
		||||
    $${PWD}/src/download_thread.cpp \
 | 
			
		||||
    $${PWD}/src/reporting_thread.cpp
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# INTERFACE = DeviceController
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										25
									
								
								include/download_thread.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								include/download_thread.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
#ifndef DOWNLOAD_THREAD_H_INCLUDED
 | 
			
		||||
#define DOWNLOAD_THREAD_H_INCLUDED
 | 
			
		||||
 | 
			
		||||
#include <QThread>
 | 
			
		||||
#include <QString>
 | 
			
		||||
 | 
			
		||||
class hwinf;
 | 
			
		||||
class DownloadThread : public QThread {
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    DownloadThread(hwinf *hw, QString const &fileToDownload);
 | 
			
		||||
    ~DownloadThread();
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    // download thread does not have a running event queue, and therefore
 | 
			
		||||
    // no slots. signals work the usual way.
 | 
			
		||||
    void run() override;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    hwinf *m_hw;
 | 
			
		||||
    QString m_fileToDownload;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // DOWNLOAD_THREAD_H_INCLUDED
 | 
			
		||||
@@ -40,7 +40,8 @@ V4.0  6.9.2023: activating DC-Bootloader in slve-lib (SM)
 | 
			
		||||
#include "interfaces.h"
 | 
			
		||||
#include "shared_mem_buffer.h"
 | 
			
		||||
#include "runProc.h"
 | 
			
		||||
 | 
			
		||||
#include "download_thread.h"
 | 
			
		||||
#include "reporting_thread.h"
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * select Plugin Type here
 | 
			
		||||
@@ -1304,6 +1305,22 @@ public:
 | 
			
		||||
        //                                          countOfBills[1] for 10€   and so on
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    // download device controller
 | 
			
		||||
    void dcDownloadInit(QString const &fileToDownload) override;
 | 
			
		||||
    void dcDownloadStart(QString const &fileToDownload) override;
 | 
			
		||||
    void dcDownloadReportStart(QString const &fileToDownload) override;
 | 
			
		||||
    bool dcDownloadStarted() const override;
 | 
			
		||||
    bool dcDownloadRunning() const override;
 | 
			
		||||
    bool dcDownloadFinished() const override;
 | 
			
		||||
 | 
			
		||||
    void dcDownloadSetTotalBlockNumber(uint16_t totalBlockNumber) override;
 | 
			
		||||
    void dcDownloadSetCurrentBlockNumber(uint16_t currentBlockNumber) override;
 | 
			
		||||
    uint16_t dcDownloadGetTotalBlockNumber() const override;
 | 
			
		||||
    uint16_t dcDownloadGetCurrentBlockNumber() const override;
 | 
			
		||||
signals:    // for download
 | 
			
		||||
    void hwapi_reportDCDownloadStatus(QString const &status);
 | 
			
		||||
    void hwapi_reportDCDownloadSuccess(QString const &msg);
 | 
			
		||||
    void hwapi_reportDCDownloadFailure(QString const &errorMsg);
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
    // already declared in interfaces.h
 | 
			
		||||
 
 | 
			
		||||
@@ -2273,7 +2273,33 @@ public:
 | 
			
		||||
    //                                          countOfBills[1] for 10€   and so on
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    // download device controller
 | 
			
		||||
    virtual void dcDownloadInit(QString const &fileToDownload) {
 | 
			
		||||
       Q_UNUSED(fileToDownload);
 | 
			
		||||
    }
 | 
			
		||||
    virtual void dcDownloadStart(QString const &fileToDownload) {
 | 
			
		||||
       Q_UNUSED(fileToDownload);
 | 
			
		||||
    }
 | 
			
		||||
    virtual void dcDownloadReportStart(QString const &fileToDownload) {
 | 
			
		||||
       Q_UNUSED(fileToDownload);
 | 
			
		||||
    }
 | 
			
		||||
    virtual void dcDownloadSetTotalBlockNumber(uint16_t totalBlockNumber) {
 | 
			
		||||
       Q_UNUSED(totalBlockNumber);
 | 
			
		||||
    }
 | 
			
		||||
    virtual void dcDownloadSetCurrentBlockNumber(uint16_t currentBlockNumber) {
 | 
			
		||||
       Q_UNUSED(currentBlockNumber);
 | 
			
		||||
    }
 | 
			
		||||
    virtual uint16_t dcDownloadGetTotalBlockNumber() const { return 0; }
 | 
			
		||||
    virtual uint16_t dcDownloadGetCurrentBlockNumber() const { return 0; }
 | 
			
		||||
 | 
			
		||||
    virtual bool dcDownloadStarted() const { return false; }
 | 
			
		||||
    virtual bool dcDownloadRunning() const { return false; }
 | 
			
		||||
    virtual bool dcDownloadFinished() const { return false; }
 | 
			
		||||
 | 
			
		||||
signals:    // for download
 | 
			
		||||
    void hwapi_reportDCDownloadStatus(QString const &status);
 | 
			
		||||
    void hwapi_reportDCDownloadSuccess(QString const &msg);
 | 
			
		||||
    void hwapi_reportDCDownloadFailure(QString const &errorMsg);
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
    // NOTE: declaring a "pure virtual" "signal" should be an error and thus not valid.
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										25
									
								
								include/reporting_thread.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								include/reporting_thread.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
#ifndef REPORTING_THREAD_H_INCLUDED
 | 
			
		||||
#define REPORTING_THREAD_H_INCLUDED
 | 
			
		||||
 | 
			
		||||
#include <QThread>
 | 
			
		||||
#include <QString>
 | 
			
		||||
 | 
			
		||||
class hwinf;
 | 
			
		||||
class ReportingThread : public QThread {
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    ReportingThread(hwinf *hw, QString const &fileToDownload);
 | 
			
		||||
    ~ReportingThread();
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    // reporting thread does not have a running event queue, and therefore
 | 
			
		||||
    // no slots. signals work the usual way.
 | 
			
		||||
    void run() override;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    hwinf *m_hw;
 | 
			
		||||
    QString m_fileToDownload;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // REPORTING_THREAD_H_INCLUDED
 | 
			
		||||
@@ -301,8 +301,15 @@ struct SharedMem
 | 
			
		||||
    uint8_t  p_nextFDcmdsInQueue;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    // download of device controller and json files
 | 
			
		||||
    struct DCDownload {
 | 
			
		||||
        char m_filename[512];
 | 
			
		||||
        uint16_t m_totalBlocks;
 | 
			
		||||
        uint16_t m_currentblockNumber;
 | 
			
		||||
        bool m_running;
 | 
			
		||||
        bool m_started;
 | 
			
		||||
        bool m_finished;
 | 
			
		||||
    } m_downLoadDC;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    static QSharedMemory *getShm(std::size_t s = 0);
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@ VERSION="1.0.0"
 | 
			
		||||
include(../DCLibraries.pri)
 | 
			
		||||
 | 
			
		||||
DEFINES+=THIS_IS_CA_MASTER
 | 
			
		||||
DEFINES-=THIS_IS_CA_SLAVE
 | 
			
		||||
DESTDIR=$${_PRO_FILE_PWD_}/../build
 | 
			
		||||
 | 
			
		||||
unix {
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,8 @@ VERSION="1.0.0"
 | 
			
		||||
include(../DCLibraries.pri)
 | 
			
		||||
 | 
			
		||||
DEFINES+=THIS_IS_CA_SLAVE
 | 
			
		||||
DEFINES-=THIS_IS_CA_MASTER
 | 
			
		||||
 | 
			
		||||
DESTDIR=$${_PRO_FILE_PWD_}/../build
 | 
			
		||||
 | 
			
		||||
unix {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										21
									
								
								src/download_thread.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/download_thread.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
#include "download_thread.h"
 | 
			
		||||
#include "shared_mem_buffer.h"
 | 
			
		||||
#include "hwapi.h"
 | 
			
		||||
 | 
			
		||||
DownloadThread::DownloadThread(hwinf *hw, QString const &fileToDownload)
 | 
			
		||||
  : m_hw(hw)
 | 
			
		||||
  , m_fileToDownload(fileToDownload) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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->dcDownloadGetCurrentBlockNumber(currentBlockNumber);
 | 
			
		||||
    // m_hw->dcDownloadGetTotalBlockNumber(totalBlockNumber);
 | 
			
		||||
}
 | 
			
		||||
@@ -20,6 +20,8 @@
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
#include "hwapi.h"
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
#include <cstring>
 | 
			
		||||
 | 
			
		||||
static uint32_t hwapi_lastStartAmount;
 | 
			
		||||
static uint32_t hwapi_lastTotalAmount;
 | 
			
		||||
@@ -4371,4 +4373,53 @@ uint16_t hwapi::bna_getStackerLevel(uint32_t *amountInStacker, uint16_t *countOf
 | 
			
		||||
    return anzahl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void hwapi::dcDownloadInit(QString const &dcFileToDownload) {
 | 
			
		||||
    char *fNameBuffer = SharedMem::getData()->m_downLoadDC.m_filename;
 | 
			
		||||
    size_t const size = sizeof(SharedMem::getData()->m_downLoadDC.m_filename);
 | 
			
		||||
 | 
			
		||||
    std::memset(fNameBuffer, 0x00, size);
 | 
			
		||||
    std::memcpy(fNameBuffer, dcFileToDownload.toStdString().c_str(),
 | 
			
		||||
                std::min(size, strlen(fNameBuffer)-1));
 | 
			
		||||
 | 
			
		||||
    SharedMem::getData()->m_downLoadDC.m_totalBlocks = 0;
 | 
			
		||||
    SharedMem::getData()->m_downLoadDC.m_currentblockNumber = 0;
 | 
			
		||||
    SharedMem::getData()->m_downLoadDC.m_started = false;
 | 
			
		||||
    SharedMem::getData()->m_downLoadDC.m_running = false;
 | 
			
		||||
    SharedMem::getData()->m_downLoadDC.m_finished = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void hwapi::dcDownloadStart() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void hwapi::dcDownloadReportStart() {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void hwapi::dcDownloadSetTotalBlockNumber(uint16_t totalBlockNumber) {
 | 
			
		||||
    SharedMem::getData()->m_downLoadDC.m_totalBlocks = totalBlockNumber;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void hwapi::dcDownloadSetCurrentBlockNumber(uint16_t currentBlockNumber) {
 | 
			
		||||
    SharedMem::getData()->m_downLoadDC.m_currentblockNumber = currentBlockNumber;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint16_t hwapi::dcDownloadGetTotalBlockNumber() const {
 | 
			
		||||
    return SharedMem::getDataConst()->m_downLoadDC.m_totalBlocks;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint16_t hwapi::dcDownloadGetCurrentBlockNumber() const {
 | 
			
		||||
    return SharedMem::getDataConst()->m_downLoadDC.m_currentblockNumber;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool hwapi::dcDownloadStarted() const {
 | 
			
		||||
    return SharedMem::getDataConst()->m_downLoadDC.m_started;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool hwapi::dcDownloadRunning() const {
 | 
			
		||||
    return SharedMem::getDataConst()->m_downLoadDC.m_running;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool hwapi::dcDownloadFinished() const {
 | 
			
		||||
    return SharedMem::getDataConst()->m_downLoadDC.m_finished;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										55
									
								
								src/reporting_thread.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								src/reporting_thread.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,55 @@
 | 
			
		||||
#include "reporting_thread.h"
 | 
			
		||||
#include "shared_mem_buffer.h"
 | 
			
		||||
#include "hwapi.h"
 | 
			
		||||
 | 
			
		||||
ReportingThread::ReportingThread(hwinf *hw, QString const &fileToDownload)
 | 
			
		||||
  : m_hw(hw)
 | 
			
		||||
  , m_fileToDownload(fileToDownload) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ReportingThread::~ReportingThread() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// download thread running in ca-slave sends reports download process to
 | 
			
		||||
// update tool
 | 
			
		||||
void ReportingThread::run() {
 | 
			
		||||
 | 
			
		||||
    int cnt = 10;
 | 
			
		||||
    while (!m_hw->dcDownloadRunning()) {
 | 
			
		||||
        if (--cnt > 0) {
 | 
			
		||||
            QThread::sleep(1);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if (cnt == 0) {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    while (m_hw->dcDownloadRunning()) {
 | 
			
		||||
        uint16_t const cnr = m_hw->dcDownloadGetCurrentBlockNumber();
 | 
			
		||||
        uint16_t const tnr = m_hw->dcDownloadGetTotalBlockNumber();
 | 
			
		||||
 | 
			
		||||
        QString report("");
 | 
			
		||||
 | 
			
		||||
        if (cnr > 0) {
 | 
			
		||||
            report = QString("total blocks %1, current block %2 [%3]")
 | 
			
		||||
                    .arg(tnr).arg(cnr).arg((double)(tnr)/(double(cnr)));
 | 
			
		||||
        } else {
 | 
			
		||||
            report = QString("total blocks %1, current block %2 [0]")
 | 
			
		||||
                    .arg(tnr).arg(cnr);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        emit m_hw->hwapi_reportDCDownloadStatus(report);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    uint16_t const cnr = m_hw->dcDownloadGetCurrentBlockNumber();
 | 
			
		||||
    uint16_t const tnr = m_hw->dcDownloadGetTotalBlockNumber();
 | 
			
		||||
 | 
			
		||||
    if (tnr == cnr) {
 | 
			
		||||
        m_hw->hwapi_reportDCDownloadSuccess(
 | 
			
		||||
            QString("SUCCESS DOWNLOADING") + m_fileToDownload);
 | 
			
		||||
    } else {
 | 
			
		||||
        m_hw->hwapi_reportDCDownloadFailure(
 | 
			
		||||
            QString("ERROR DOWNLOADING %1 (total blocks=%2, sent blocks=%3)")
 | 
			
		||||
                .arg(m_fileToDownload).arg(tnr).arg(cnr));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user