Compare commits

..

No commits in common. "c6ea94e24991eee079626557bc2f7be4326cbcbb" and "e79d6c6fefdb46c531de7fd66c57c441e49ad32e" have entirely different histories.

3 changed files with 90 additions and 102 deletions

View File

@ -92,12 +92,6 @@ int main(int argc, char *argv[]) {
QCoreApplication::translate("main", "Maintenance mode for underlying script"));
parser.addOption(maintenanceOption);
// TODO:
// add some additional parameters
// -d: only update device-controller firmware
// -j: only update json-files
// -o: only execute opkg-commnds
// Process the actual command line arguments given by the user
parser.process(a);
QString plugInDir = parser.value(pluginDirectoryOption);

View File

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

View File

@ -35,8 +35,6 @@ class Update : public QObject {
bool updateBinary(char const *fileToSendToDC);
bool updatePrinterConf(int templateIdx, QString fileToSendToDC);
bool updateConf(QString fileToSendToDC);
bool updateCashConf(QString fileToSendToDC);
bool finishUpdate(bool finish);
QStringList getLinesToWorkOn();
QStringList split(QString line, QChar sep = ',');
@ -73,8 +71,8 @@ private:
bool resetDeviceController() const;
QByteArray loadBinaryDCFile(QString filename) const;
bool downloadBinaryToDC(QString const &bFile) const;
bool updateDC(QString bFile) const;
bool updateDC(QString bFile, QString br, QString serial) const;
bool updatePrinterTemplate(enum FileTypeJson type, int templateIdx,
QString fname) const;
QString fname, QString br, QString serial) const;
};
#endif // UPDATE_H_INCLUDED