executeUpdateScript: set timeout to 200 secs. Open serial port only once for the whole loop handling the lines in update_log.csv. Sending of device controller in Debug-setting worked. Execution of opkg-commnds worked. Sending of JSON files needs further testing: sys_readyForSending failes sometimes after 5 seconds.

This commit is contained in:
Gerhard Hoffmann 2023-06-21 16:25:21 +02:00
parent 9c343f3eeb
commit 4cee0e37da

View File

@ -130,7 +130,8 @@ bool Update::execUpdateScript() {
p->start(update_psa); p->start(update_psa);
if (p->waitForStarted(1000)) { if (p->waitForStarted(1000)) {
if (p->state() == QProcess::ProcessState::Running) { if (p->state() == QProcess::ProcessState::Running) {
if (p->waitForFinished(60000)) { int const timeout = 200000; // sometimes signal strength of modem is quite low
if (p->waitForFinished(timeout)) {
QString output = p->readAllStandardOutput().toStdString().c_str(); QString output = p->readAllStandardOutput().toStdString().c_str();
QStringList lst = output.split('\n'); QStringList lst = output.split('\n');
for (int i = 0; i < lst.size(); ++i) { for (int i = 0; i < lst.size(); ++i) {
@ -139,6 +140,9 @@ bool Update::execUpdateScript() {
qInfo() << "EXECUTED" << update_psa; qInfo() << "EXECUTED" << update_psa;
return ((p->exitStatus() == QProcess::NormalExit) return ((p->exitStatus() == QProcess::NormalExit)
&& (p->exitCode() == 0)); && (p->exitCode() == 0));
} else {
qCritical() << "update-script TIMEDOUT after"
<< timeout/1000 << "seconds";
} }
} }
} }
@ -363,127 +367,110 @@ bool Update::downloadBinaryToDC(QString const &bFile) const {
} }
bool Update::updateBinary(char const *fileToSendToDC) { bool Update::updateBinary(char const *fileToSendToDC) {
return true; qInfo() << "updating device controller binary" << fileToSendToDC;
// TODO
QFile fn(fileToSendToDC); QFile fn(fileToSendToDC);
bool r; bool r;
if ((r = fn.exists()) == true) { if ((r = fn.exists()) == true) {
QString fwVersion = m_hw->dc_getSWversion();
QString const hwVersion = m_hw->dc_getHWversion();
QString const linkTarget = fn.symLinkTarget(); QString const linkTarget = fn.symLinkTarget();
qInfo() << "updating binary (dc)" << linkTarget << "..."; QFileInfo fi(linkTarget);
if ((r = updateDC(linkTarget, m_baudrate, m_serialInterface)) == true) { qInfo() << " updating binary (size=" << linkTarget << fi.size() << ")";
qInfo() << "updating binary (dc)" << linkTarget << "... done"; qInfo() << " dc-hardware-version" << hwVersion;
qInfo() << "previous dc-firmware-version" << fwVersion;
if ((r = updateDC(linkTarget)) == true) {
fwVersion = m_hw->dc_getSWversion();
qInfo() << " updating binary (size=" << linkTarget << fi.size() << ") done";
qInfo() << "current dc-firmware-version" << fwVersion;
} else { } else {
qCritical() << "updating binary (dc)" << linkTarget << "... FAILED"; qCritical() << "updating binary (size=" << linkTarget << fi.size() << ")... FAILED";
} }
} else { } else {
qCritical() << "symlink" << fileToSendToDC << "does not exist"; qCritical() << "symlink" << fileToSendToDC
<< "does not exist -> NO UPDATE OF DC FIRMWARE";
} }
return r; return r;
} }
bool Update::updateDC(QString bFile, QString br, QString serial) const { bool Update::updateDC(QString bFile) const {
if (!baudrateMap.contains(br)) { // sanity check qDebug() << "updating dc...";
qCritical() << "passed wrong baudrate" << br; qDebug() << "updating dc: file to send" << bFile;
return false;
}
m_hw->dc_autoRequest(false);
qDebug() << "updating dc: " << bFile << br << serial << "...";
return true;
if (!openSerial(baudrateMap.value(br), br, serial)) {
return false;
}
if (!resetDeviceController()) { if (!resetDeviceController()) {
closeSerial();
return false; return false;
} }
if (!startBootloader()) { if (!startBootloader()) {
closeSerial();
return false; return false;
} }
if (!downloadBinaryToDC(bFile)) { if (!downloadBinaryToDC(bFile)) {
stopBootloader(); stopBootloader();
closeSerial(); qCritical() << "updating dc: " << bFile << "...FAILED";
qCritical() << "updating dc: " << bFile << br << serial << "...FAILED";
return false; return false;
} }
qInfo() << "updating dc: " << bFile << "...OK";
qInfo() << "updating dc: " << bFile << br << serial << "...OK";
stopBootloader(); stopBootloader();
QThread::sleep(3); QThread::sleep(3);
closeSerial();
return true; return true;
} }
bool Update::updatePrinterTemplate(enum FileTypeJson type, bool Update::updatePrinterTemplate(enum FileTypeJson type,
int templateIdx, int templateIdx,
QString fname, QString fname) const { // name of the json-file
QString br,
QString serial) const {
// sanity checks // sanity checks
if (!baudrateMap.contains(br)) {
qCritical() << "passed wrong baudrate" << br;
return false;
}
if (type != FileTypeJson::PRINTER) { if (type != FileTypeJson::PRINTER) {
qCritical() << "wrong file type" << (uint8_t)type; qCritical() << "wrong file type" << (uint8_t)type;
return false; return false;
} }
qDebug() << "updating: " << fname << br << serial << "...";
return true; qInfo() << "updating printer template:" << fname << "...";
qInfo() << " printer-template-index:" << templateIdx;
if (!serial.isNull()) { int nTry = 10;
if (!openSerial(baudrateMap.value(br), br, serial)) {
return false;
}
}
int nTry = 50;
while (!m_hw->sys_ready4sending()) { // wait max. 5 seconds while (!m_hw->sys_ready4sending()) { // wait max. 5 seconds
std::this_thread::sleep_for(std::chrono::milliseconds(100)); QThread::sleep(1);
if (--nTry <= 0) { if (--nTry <= 0) {
qCritical() << "sys not ready for sending"; qCritical() << "SYS NOT READY FOR SENDING AFTER 10 SECONDS";
if (!serial.isNull()) {
closeSerial();
}
return false; return false;
} }
} }
bool ret = true; bool ret = false;
QFile file(fname); QFile file(fname);
if (file.exists() && file.open(QIODevice::ReadOnly)) { QFileInfo fi(fname); // max. size of template file is 800 bytes
if (file.exists()) {
if (file.open(QIODevice::ReadOnly)) {
if (fi.size() <= 800) {
QByteArray ba = file.readAll(); QByteArray ba = file.readAll();
if (ba.size() <= 800) { // max. size is 800 bytes
if (m_hw->sys_sendJsonFileToDc((uint8_t)(type), if (m_hw->sys_sendJsonFileToDc((uint8_t)(type),
templateIdx, templateIdx,
(uint8_t *)ba.data())) { (uint8_t *)ba.data())) {
std::this_thread::sleep_for(std::chrono::seconds(1)); QThread::sleep(1);
qInfo() << "sent file" << fname << "to dc"; qInfo() << "sent file" << fname << "to dc";
} ret = true;
} }
} else { } else {
qCritical() << fname << "!!! does not exist!!!"; qCritical() << "SIZE OF" << fname
ret = false; << "TOO BIG (" << fi.size() << "BYTES)";
} }
if (!serial.isNull()) { } else {
closeSerial(); qCritical() << "CANNOT OPEN" << fname << "FOR READING";
}
} else {
qCritical() << fname << "DOES NOT EXIST";
} }
return ret; return ret;
} }
bool Update::updatePrinterConf(int templateIdx, QString fileToSendToDC) { bool Update::updatePrinterConf(int templateIdx, QString fileToSendToDC) {
return true;
// TODO
qCritical() << "updating printer template: " << fileToSendToDC;
return updatePrinterTemplate(FileTypeJson::PRINTER, return updatePrinterTemplate(FileTypeJson::PRINTER,
templateIdx, templateIdx,
fileToSendToDC, fileToSendToDC);
QString(m_baudrate), }
QString(m_serialInterface));
bool Update::updateConf(QString fileToSendToDC) {
return false;
}
bool Update::updateCashConf(QString fileToSendToDC) {
return false;
} }
QStringList Update::getLinesToWorkOn() { QStringList Update::getLinesToWorkOn() {
@ -540,12 +527,20 @@ bool Update::doUpdate() {
return false; return false;
} }
if (!openSerial(baudrateMap.value(m_baudrate), m_baudrate, m_serialInterface)) {
qCritical() << "CANNOT OPEN" << m_serialInterface << "(BAUDRATE="
<< m_baudrate << ")";
return false;
}
m_hw->dc_autoRequest(false);
QThread::sleep(3); // wait to be sure that there are no more commands sent
// to dc-hardware
QStringList linesToWorkOn = getLinesToWorkOn(); QStringList linesToWorkOn = getLinesToWorkOn();
if (linesToWorkOn.size() == 0) { if (linesToWorkOn.size() == 0) {
qCritical() << "No lines to handle in" << m_update_ctrl_file.fileName(); qCritical() << "No lines to handle in" << m_update_ctrl_file.fileName();
return true; return true;
} }
qDebug() << "open lines..."; qDebug() << "open lines...";
for (int i=0; i< linesToWorkOn.size(); ++i) { for (int i=0; i< linesToWorkOn.size(); ++i) {
qDebug() << "line" << i << ":" << linesToWorkOn.at(i).trimmed(); qDebug() << "line" << i << ":" << linesToWorkOn.at(i).trimmed();
@ -560,8 +555,9 @@ bool Update::doUpdate() {
} }
QStringList lst = split(line.trimmed()); QStringList lst = split(line.trimmed());
if (lst.size() != 4) { if (lst.size() != 4) {
qCritical() << "Parsing error for" << m_update_ctrl_file.fileName(); qCritical() << "PARSING ERROR FOR LINE"
return false; << line << "IN" << m_update_ctrl_file.fileName();
continue;
} }
QString const &request = lst[COLUMN_REQUEST]; QString const &request = lst[COLUMN_REQUEST];
QString const &name = lst[COLUMN_NAME]; QString const &name = lst[COLUMN_NAME];
@ -569,24 +565,31 @@ bool Update::doUpdate() {
// QString const &result = lst[COLUMN_RESULT]; // QString const &result = lst[COLUMN_RESULT];
qDebug() << "request=" << request << ", name=" << name; qDebug() << "request=" << request << ", name=" << name;
if (request.trimmed() == "DOWNLOAD") { if (request.trimmed() == "DOWNLOAD") {
if (name.contains("dc2c") && name.endsWith(".bin")) { if (name.contains("dc2c", Qt::CaseInsensitive) &&
name.endsWith(".bin", Qt::CaseInsensitive)) {
qInfo() << "downloading" << name.trimmed() << "to DC"; qInfo() << "downloading" << name.trimmed() << "to DC";
if ((res = updateBinary(name.toStdString().c_str())) == true) { if ((res = updateBinary(name.toStdString().c_str())) == true) {
qInfo() << "downloaded binary" << name; qInfo() << "downloaded binary" << name;
} }
} else if (name.contains("DC2C_print") && name.endsWith(".json")) { } else if (name.contains("DC2C_print", Qt::CaseInsensitive)
int i = name.indexOf("DC2C_print"); && name.endsWith(".json", Qt::CaseInsensitive)) {
int templateIdx = name.mid(i).midRef(10, 2).toInt(); int i = name.indexOf("DC2C_print", Qt::CaseInsensitive);
int const templateIdx = name.mid(i).midRef(10, 2).toInt();
if ((templateIdx < 1) || (templateIdx > 32)) { if ((templateIdx < 1) || (templateIdx > 32)) {
qCritical() << "wrong template index"; qCritical() << "WRONG TEMPLATE INDEX" << templateIdx;
res = false; res = false;
} else { } else {
if ((res = updatePrinterConf(templateIdx, name)) == true) { if ((res = updatePrinterConf(templateIdx, name)) == true) {
qInfo() << "downloaded printer template" << name; qInfo() << "downloaded printer template" << name;
} }
} }
} else if (name.contains("DC2C_cash", Qt::CaseInsensitive)
&& name.endsWith(".json", Qt::CaseInsensitive)) {
} else if (name.contains("DC2C_conf", Qt::CaseInsensitive)
&& name.endsWith(".json", Qt::CaseInsensitive)) {
} else { } else {
// TODO qCritical() << "UNKNOWN JSON FILE NAME" << name;
res = false;
} }
} else if (request == "EXECUTE" && name.contains("opkg")) { } else if (request == "EXECUTE" && name.contains("opkg")) {
qInfo() << "starting" << name.trimmed(); qInfo() << "starting" << name.trimmed();
@ -622,7 +625,6 @@ bool Update::doUpdate() {
} }
char buf[128]; char buf[128];
memset(buf, 0x00, sizeof(buf)); memset(buf, 0x00, sizeof(buf));
int const bytesWritten =
snprintf(buf, sizeof(buf)-1, "DONE, %*.*s, %*.*s, %*.*s\n", snprintf(buf, sizeof(buf)-1, "DONE, %*.*s, %*.*s, %*.*s\n",
35, 35, name.toStdString().c_str(), 35, 35, name.toStdString().c_str(),
20, 20, QDateTime::currentDateTime().toString(Qt::ISODate).toStdString().c_str(), 20, 20, QDateTime::currentDateTime().toString(Qt::ISODate).toStdString().c_str(),
@ -630,6 +632,8 @@ bool Update::doUpdate() {
m_update_ctrl_file_copy.write(buf); m_update_ctrl_file_copy.write(buf);
} // for (it = openLines.cbegin(); it != openLines.end(); ++it) { } // for (it = openLines.cbegin(); it != openLines.end(); ++it) {
closeSerial();
m_hw->dc_autoRequest(true);
return finishUpdate(linesToWorkOn.size() > 0); return finishUpdate(linesToWorkOn.size() > 0);
} }