Merge commit 'a9e69cd0c4ad3477a99becaf87b84e0d9b23538f'
This commit is contained in:
		@@ -10,6 +10,7 @@
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#include <thread>
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
 | 
			
		||||
#include <QFileInfo>
 | 
			
		||||
 | 
			
		||||
@@ -412,33 +413,116 @@ bool hwapi::dc_updateDC(QString bFile, QString br, QString serial) const {
 | 
			
		||||
//
 | 
			
		||||
/******************************************************************************/
 | 
			
		||||
bool hwapi::dc_updatePrinterTemplate(enum FileTypeJson type,
 | 
			
		||||
                                     int nrOfTemplate,
 | 
			
		||||
                                     QString const &fname) const {
 | 
			
		||||
    if ((type == FileTypeJson::PRINTER) &&
 | 
			
		||||
        (nrOfTemplate >= 1 && nrOfTemplate <= 32)) {
 | 
			
		||||
                                     QVector<int> templatesIdx,
 | 
			
		||||
                                     QVector<QString> fnames,
 | 
			
		||||
                                     QString br,
 | 
			
		||||
                                     QString serial) const {
 | 
			
		||||
    // sanity checks
 | 
			
		||||
    if (!baudrateMap.contains(br)) {
 | 
			
		||||
        qCritical() << "passed wrong baudrate" << br;
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    if (templatesIdx.size() != fnames.size()) {
 | 
			
		||||
        qCritical() << "list sizes must be equal" << br;
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    if (!std::all_of(templatesIdx.cbegin(), templatesIdx.cend(),
 | 
			
		||||
                    [](int i) { return i >= 1 && i <= 32; })) {
 | 
			
		||||
        qCritical() << "wrong template indices";
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    if (type != FileTypeJson::PRINTER) {
 | 
			
		||||
        qCritical() << "wrong file type" << (uint8_t)type;
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        int nTry = 50;
 | 
			
		||||
        while (!sys_ready4sending()) { // wait max. 5 seconds
 | 
			
		||||
            std::this_thread::sleep_for(std::chrono::milliseconds(100));
 | 
			
		||||
            if (--nTry <= 0) {
 | 
			
		||||
                return false;
 | 
			
		||||
            } 
 | 
			
		||||
    qDebug() << "updating: " << fnames << br << serial << "...";
 | 
			
		||||
 | 
			
		||||
    if (!openSerial(baudrateMap.value(br), br, serial)) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int nTry = 50;
 | 
			
		||||
    while (!sys_ready4sending()) { // wait max. 5 seconds
 | 
			
		||||
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
 | 
			
		||||
        if (--nTry <= 0) {
 | 
			
		||||
            qCritical() << "sys not ready for sending";
 | 
			
		||||
            closeSerial(serial);
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        QFile file(fname);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool ret = true;
 | 
			
		||||
    for (int i = 0; i < fnames.size(); ++i) {
 | 
			
		||||
        QFile file(fnames[i]);
 | 
			
		||||
        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,
 | 
			
		||||
                                          templatesIdx[i],
 | 
			
		||||
                                          (uint8_t *)ba.data())) {
 | 
			
		||||
                    std::this_thread::sleep_for(std::chrono::seconds(1));
 | 
			
		||||
                    return true;
 | 
			
		||||
                    qInfo() << "sent file" << fnames[i] << "to dc";
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            qCritical() << fnames[i] << "!!! does not exist!!!";
 | 
			
		||||
            ret = false;
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    closeSerial(serial);
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool hwapi::dc_printTemplate(enum FileTypeJson type,
 | 
			
		||||
                             QVector<int> templateIdx,
 | 
			
		||||
                             QString br,
 | 
			
		||||
                             QString serial) const {
 | 
			
		||||
    // sanity checks
 | 
			
		||||
    if (!baudrateMap.contains(br)) {
 | 
			
		||||
        qCritical() << "passed wrong baudrate" << br;
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    if (!std::all_of(templateIdx.cbegin(), templateIdx.cend(),
 | 
			
		||||
                    [](int i) { return i >= 1 && i <= 32; })) {
 | 
			
		||||
        qCritical() << "wrong template indices";
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    if (type != FileTypeJson::PRINTER) {
 | 
			
		||||
        qCritical() << "wrong file type" << (uint8_t)type;
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    qDebug() << "printing: " << templateIdx << br << serial << "...";
 | 
			
		||||
 | 
			
		||||
    if (!openSerial(baudrateMap.value(br), br, serial)) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int nTry = 50;
 | 
			
		||||
    while (!sys_ready4sending()) { // wait max. 5 seconds
 | 
			
		||||
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
 | 
			
		||||
        if (--nTry <= 0) {
 | 
			
		||||
            qCritical() << "sys not ready for sending";
 | 
			
		||||
            closeSerial(serial);
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return false;
 | 
			
		||||
    bool ret = true;
 | 
			
		||||
    for (int i = 0; i < templateIdx.size(); ++i) {
 | 
			
		||||
        if (prn_printTemplate(templateIdx[i])) {
 | 
			
		||||
            qDebug() << "printing template" << templateIdx[i];
 | 
			
		||||
            std::this_thread::sleep_for(std::chrono::seconds(3));
 | 
			
		||||
        } else {
 | 
			
		||||
            ret = false;
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    closeSerial(serial);
 | 
			
		||||
    return ret;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------
 | 
			
		||||
@@ -3284,7 +3368,8 @@ bool hwapi::sys_sendJsonFileToDc(uint8_t kindOfFile, uint8_t nrOfTemplate, uint8
 | 
			
		||||
    {
 | 
			
		||||
        biox_CopyBlock(inhaltOfJson, uitmp, temp, 0, 64);
 | 
			
		||||
        longFDcmd_set(31,0, bn++, 64, temp);
 | 
			
		||||
        uitmp<<=6;
 | 
			
		||||
        uitmp += 64;
 | 
			
		||||
        // uitmp<<=6;
 | 
			
		||||
    } while(uitmp < dateiLang);
 | 
			
		||||
 | 
			
		||||
    longFDcmd_set(32, 0,0, 0,temp);       // Abschluss
 | 
			
		||||
 
 | 
			
		||||
@@ -602,7 +602,7 @@ bool longFDcmd_set(uint8_t nextWrCmd, uint8_t nextRdCmd, uint8_t blockNum, uint8
 | 
			
		||||
    uint8_t nn;
 | 
			
		||||
    if (p_longFDcmdsInQueue>=FDLONG_STACKDEPTH)
 | 
			
		||||
    {
 | 
			
		||||
        qDebug() << "cannot save cmd because stack is full";
 | 
			
		||||
        qCritical() << "cannot save cmd because stack is full";
 | 
			
		||||
        return false;           // not possible
 | 
			
		||||
    }
 | 
			
		||||
    longFDwrCmd[p_longFDcmdsInQueue]=nextWrCmd;
 | 
			
		||||
@@ -613,6 +613,7 @@ bool longFDcmd_set(uint8_t nextWrCmd, uint8_t nextRdCmd, uint8_t blockNum, uint8
 | 
			
		||||
        longFDpara[p_longFDcmdsInQueue][nn]=data[nn];
 | 
			
		||||
 | 
			
		||||
    p_longFDcmdsInQueue++;
 | 
			
		||||
 | 
			
		||||
    return true;                // ok, will be sent
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user