Merge commit '1f0f7da128687daf09d065e60e254fbd24f2545d'

Added dc_updatePrinterTemplate.
This commit is contained in:
2023-04-13 13:39:17 +02:00
3 changed files with 44 additions and 0 deletions

View File

@@ -11,6 +11,8 @@
#include <unistd.h>
#include <thread>
#include <QFileInfo>
#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)