From 18e4811d57672b9a5a9c266d0905328787cc3460 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Thu, 18 May 2023 14:26:23 +0200 Subject: [PATCH] Added some debug output. Send only one DC_print-template. Tested again downloading dc-firmware and printer-templates. --- main.cpp | 52 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/main.cpp b/main.cpp index 4783aea..a925bc3 100644 --- a/main.cpp +++ b/main.cpp @@ -25,6 +25,9 @@ static void updateBinary(std::unique_ptr hw, // update d2dc*.bin char const *baudrate, char const *serialInterface) { for (int i=0; i < 1;++i) { + qDebug() << "file to send to DC ..." << fileToSendToDC; + qDebug() << "baudrate ............." << baudrate; + qDebug() << "serial interface ....." << serialInterface; hw->dc_updateDC(fileToSendToDC, baudrate, serialInterface); std::this_thread::sleep_for(std::chrono::milliseconds(3000)); } @@ -35,13 +38,14 @@ static void updatePrinterConf(std::unique_ptr hw, // update printer-file QVector nrOfTemplate, QVector fileToSendToDC, QString br, QString serial) { - for (int i=0; i < 1;++i) { - //hw->dc_updatePrinterTemplate(hwapi::FileTypeJson::PRINTER, - // nrOfTemplate, fileToSendToDC, - // br, serial); + // for (int i = 0; i < 1; ++i) { + if (nrOfTemplate.size() == 1 && fileToSendToDC.size() == 1) { + hw->dc_updatePrinterTemplate(hwapi::FileTypeJson::PRINTER, + nrOfTemplate, fileToSendToDC, + br, serial); - hw->dc_printTemplate(hwapi::FileTypeJson::PRINTER, - nrOfTemplate, br, serial); + // hw->dc_printTemplate(hwapi::FileTypeJson::PRINTER, + // nrOfTemplate, br, serial); } QCoreApplication::quit(); } @@ -56,7 +60,7 @@ int main(int argc, char *argv[]) { //setDebugLevel(QtMsgType::QtDebugMsg); } - if (argc > 2) { + if (argc != 2) { qCritical() << "Usage: " << argv[0] << ""; return -1; } @@ -72,17 +76,29 @@ int main(int argc, char *argv[]) { ret = a.exec(); t.join(); } else { - QVector fnames{"DC2C_print01.json", - "DC2C_print02.json", - "DC2C_print03.json"}; - QVector templateIdx{1,2,3}; - //if (fname.startsWith("DC2C_print") && fname.endsWith(".json")) { - //int const nrOfTemplate = fname.midRef(10, 2).toInt(); - std::thread t(updatePrinterConf, std::move(hw), templateIdx, fnames, - "115200", SERIAL_PORT); - ret = a.exec(); - t.join(); - //} + if (fname.startsWith("DC2C_print") && fname.endsWith(".json")) { + qDebug() << "downloading" << fname << "to dc..."; + + QVector fnames; + QVector templateIdx; + + int const nrOfTemplate = fname.midRef(10, 2).toInt(); + if (nrOfTemplate <= 0 && nrOfTemplate > 32) { + qCritical() << "wrong template number" << nrOfTemplate; + return -1; + } + + fnames.append(fname); + templateIdx.append(nrOfTemplate); + + std::thread t(updatePrinterConf, std::move(hw), + templateIdx, + fnames, + "115200", SERIAL_PORT); + + ret = a.exec(); + t.join(); + } } return ret;