From 1f0f7da128687daf09d065e60e254fbd24f2545d Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Thu, 13 Apr 2023 13:39:17 +0200 Subject: [PATCH] Squashed 'DCPlugin/' changes from 37f0012..ef48301 ef48301 Added dc_updatePrinterTemplate 5f7d34e implemented dc_updatePrinterTemplate 863e4b2 Added dc_updatePrinterTemplate git-subtree-dir: DCPlugin git-subtree-split: ef48301dad80ebce3db4764613bb7f183ef69485 --- include/hwapi.h | 4 ++++ include/interfaces.h | 4 ++++ src/hwapi.cpp | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/include/hwapi.h b/include/hwapi.h index 3366bdc..fff7e9d 100644 --- a/include/hwapi.h +++ b/include/hwapi.h @@ -143,6 +143,10 @@ public: bool dc_updateDC(QString binFileName, QString baudrate, QString comPort) const override; + + bool dc_updatePrinterTemplate(enum FileTypeJson type, + int templateNr, + QString const &fname) const override; // ------------------------------------------------------------------------------ // Level 1, control device-controller (functions of µC) diff --git a/include/interfaces.h b/include/interfaces.h index aba7cb7..733e3f3 100644 --- a/include/interfaces.h +++ b/include/interfaces.h @@ -305,6 +305,10 @@ public: QString baudrate, QString comPort) const = 0; // download binary file down into device controller + + virtual bool dc_updatePrinterTemplate(enum FileTypeJson type, + int templateNr, + QString const &fname) const = 0; virtual void dc_autoRequest(bool on) const =0; // on = true: select that all READ-Requests are sent automatically diff --git a/src/hwapi.cpp b/src/hwapi.cpp index 5b2017e..2d02096 100644 --- a/src/hwapi.cpp +++ b/src/hwapi.cpp @@ -11,6 +11,8 @@ #include #include +#include + #include "tslib.h" #include "hwapi.h" @@ -404,6 +406,40 @@ bool hwapi::dc_updateDC(QString bFile, QString br, QString serial) const { return true; } +/******************************************************************************/ +// +// LEVEL 3: hwapi::dc_updatePrinterTemplate +// +/******************************************************************************/ +bool hwapi::dc_updatePrinterTemplate(enum FileTypeJson type, + int nrOfTemplate, + QString const &fname) const { + if ((type == FileTypeJson::PRINTER) && + (nrOfTemplate >= 0 && nrOfTemplate <= 32)) { + + int nTry = 50; + while (!sys_ready4sending()) { // wait max. 5 seconds + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + if (--nTry <= 0) { + return false; + } + } + QFile file(fname); + if (file.exists() && file.open(QIODevice::ReadOnly)) { + QByteArray ba = file.readAll(); + if (ba.size() <= 800) { // max. size is 800 bytes + if (sys_sendJsonFileToDc((uint8_t)(type), + nrOfTemplate, + (uint8_t *)ba.data())) { + std::this_thread::sleep_for(std::chrono::seconds(1)); + return true; + } + } + } + } + + return false; +} // ------------------------------------------------------------------------------ // Level 1, control device-controller (functions of µC)