Compare commits

..

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

4 changed files with 63 additions and 139 deletions

View File

@ -94,7 +94,6 @@ int main(int argc, char *argv[]) {
// TODO: // TODO:
// add some additional parameters // add some additional parameters
// --dry-run
// -d: only update device-controller firmware // -d: only update device-controller firmware
// -j: only update json-files // -j: only update json-files
// -o: only execute opkg-commnds // -o: only execute opkg-commnds

View File

@ -68,7 +68,6 @@ void atbDebugOutput(QtMsgType type, const QMessageLogContext &context, const QSt
datetime.time().toString(format).toStdString().c_str(), datetime.time().toString(format).toStdString().c_str(),
fractional_part, fractional_part,
localMsg.constData()); localMsg.constData());
fprintf(stderr, "%s\n", buf);
} }
} break; } break;
case QtInfoMsg: { case QtInfoMsg: {
@ -78,7 +77,6 @@ void atbDebugOutput(QtMsgType type, const QMessageLogContext &context, const QSt
datetime.time().toString(format).toStdString().c_str(), datetime.time().toString(format).toStdString().c_str(),
fractional_part, fractional_part,
localMsg.constData()); localMsg.constData());
fprintf(stderr, "%s\n", buf);
} }
} break; } break;
case QtWarningMsg: { case QtWarningMsg: {
@ -88,7 +86,6 @@ void atbDebugOutput(QtMsgType type, const QMessageLogContext &context, const QSt
datetime.time().toString(format).toStdString().c_str(), datetime.time().toString(format).toStdString().c_str(),
fractional_part, fractional_part,
localMsg.constData()); localMsg.constData());
fprintf(stderr, "%s\n", buf);
} }
} break; } break;
case QtCriticalMsg: { case QtCriticalMsg: {
@ -99,7 +96,6 @@ void atbDebugOutput(QtMsgType type, const QMessageLogContext &context, const QSt
datetime.time().toString(format).toStdString().c_str(), datetime.time().toString(format).toStdString().c_str(),
fractional_part, fractional_part,
localMsg.constData()); localMsg.constData());
fprintf(stderr, "%s\n", buf);
} }
} break; } break;
case QtFatalMsg: { case QtFatalMsg: {
@ -111,7 +107,6 @@ void atbDebugOutput(QtMsgType type, const QMessageLogContext &context, const QSt
datetime.time().toString(format).toStdString().c_str(), datetime.time().toString(format).toStdString().c_str(),
fractional_part, fractional_part,
localMsg.constData()); localMsg.constData());
fprintf(stderr, "%s\n", buf);
} }
} break; } break;
default: { default: {
@ -120,6 +115,7 @@ void atbDebugOutput(QtMsgType type, const QMessageLogContext &context, const QSt
msg.toStdString().c_str()); msg.toStdString().c_str());
} }
} }
fprintf(stderr, "%s\n", buf);
} }
#endif #endif

View File

@ -19,17 +19,10 @@
#include <QPluginLoader> #include <QPluginLoader>
#include <QMap> #include <QMap>
#define COLUMN_REQUEST (0) #define COLUMN_REQUEST (0)
#define COLUMN_NAME (1) #define COLUMN_NAME (1)
#define COLUMN_DATE_TIME (2) #define COLUMN_DATE_TIME (2)
#define COLUMN_RESULT (3) #define COLUMN_RESULT (3)
#define UPDATE_OPKG (0)
#define UPDATE_DC (1)
#define UPDATE_PRINTER_TEMPLATES (0)
#define UPDATE_CASH_TEMPLATE (0)
#define UPDATE_CONF_TEMPLATE (0)
#define UPDATE_DEVICE_TEMPLATE (0)
static const QMap<QString, int> baudrateMap = { static const QMap<QString, int> baudrateMap = {
{"1200" , 0}, {"9600" , 1}, {"19200" , 2}, {"38400" , 3}, {"1200" , 0}, {"9600" , 1}, {"19200" , 2}, {"38400" , 3},
@ -289,8 +282,6 @@ bool Update::startBootloader() const {
qInfo() << "starting bootloader...OK"; qInfo() << "starting bootloader...OK";
std::this_thread::sleep_for(std::chrono::milliseconds(500)); std::this_thread::sleep_for(std::chrono::milliseconds(500));
return true; return true;
} else {
qCritical() << "bootloader not up (" << nTry << ")";
} }
} }
qCritical() << "starting bootloader...FAILED"; qCritical() << "starting bootloader...FAILED";
@ -333,7 +324,7 @@ bool Update::resetDeviceController() const {
// std::this_thread::sleep_for(std::chrono::milliseconds(1000)); // std::this_thread::sleep_for(std::chrono::milliseconds(1000));
m_hw->bl_rebootDC(); m_hw->bl_rebootDC();
// wait maximally 3 seconds, before starting bootloader // wait maximally 3 seconds, before starting bootloader
QThread::msleep(1500); std::this_thread::sleep_for(std::chrono::milliseconds(1500));
qInfo() << "resetting device controller...OK"; qInfo() << "resetting device controller...OK";
return true; return true;
//} //}
@ -380,11 +371,17 @@ bool Update::updateBinary(char const *fileToSendToDC) {
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();
QFileInfo fi(linkTarget); QFileInfo fi(linkTarget);
qInfo() << " updating binary (size=" << linkTarget << fi.size() << ")"; qInfo() << " updating binary (size=" << linkTarget << fi.size() << ")";
qInfo() << " dc-hardware-version" << hwVersion;
qInfo() << "previous dc-firmware-version" << fwVersion;
if ((r = updateDC(linkTarget)) == true) { if ((r = updateDC(linkTarget)) == true) {
fwVersion = m_hw->dc_getSWversion();
qInfo() << " updating binary (size=" << linkTarget << fi.size() << ") done"; qInfo() << " updating binary (size=" << linkTarget << fi.size() << ") done";
qInfo() << "current dc-firmware-version" << fwVersion;
} else { } else {
qCritical() << "updating binary (size=" << linkTarget << fi.size() << ")... FAILED"; qCritical() << "updating binary (size=" << linkTarget << fi.size() << ")... FAILED";
} }
@ -415,88 +412,65 @@ bool Update::updateDC(QString bFile) const {
return true; return true;
} }
QString Update::jsonType(enum FileTypeJson type) { bool Update::updatePrinterTemplate(enum FileTypeJson type,
switch (type) { int templateIdx,
case FileTypeJson::CASH: return "CASH"; QString fname) const { // name of the json-file
case FileTypeJson::CONFIG: return "CONFIG"; // sanity checks
case FileTypeJson::PRINTER: return "PRINTER"; if (type != FileTypeJson::PRINTER) {
case FileTypeJson::SERIAL: return "SERIAL"; qCritical() << "wrong file type" << (uint8_t)type;
case FileTypeJson::DEVICE: return "DEVICE"; return false;
case FileTypeJson::TIME: return "TIME";
} }
return "N/A";
}
bool Update::downloadJson(enum FileTypeJson type, qInfo() << "updating printer template:" << fname << "...";
int templateIdx, qInfo() << " printer-template-index:" << templateIdx;
QString jsFileToSendToDC) const {
qDebug() << "updating json-file:" << jsFileToSendToDC << "..."; int nTry = 10;
qDebug() << " template-index:" << templateIdx; while (!m_hw->sys_ready4sending()) { // wait max. 5 seconds
qDebug() << " json-type:" << jsonType(type); QThread::sleep(1);
m_hw->dc_autoRequest(true); // downloading Json needs the AutoEmission flag
qDebug() << "SET AUTO-REQUEST=TRUE";
QThread::sleep(1); // make sure the auto-request flag is acknowledged
bool ready = false;
int nTry = 25;
while ((ready = m_hw->sys_ready4sending()) == false) {
QThread::msleep(200);
if (--nTry <= 0) { if (--nTry <= 0) {
qCritical() << "SYS NOT READY FOR SENDING AFTER 5 SECONDS"; qCritical() << "SYS NOT READY FOR SENDING AFTER 10 SECONDS";
break; return false;
} }
} }
bool ret = false; bool ret = false;
if (ready) { QFile file(fname);
QFile file(jsFileToSendToDC); QFileInfo fi(fname); // max. size of template file is 800 bytes
QFileInfo fi(jsFileToSendToDC); // max. size of template file is 800 bytes if (file.exists()) {
if (file.exists()) { if (file.open(QIODevice::ReadOnly)) {
if (file.open(QIODevice::ReadOnly)) { if (fi.size() <= 800) {
if (fi.size() <= 800) { QByteArray ba = file.readAll();
QByteArray ba = file.readAll(); 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())) { QThread::sleep(1);
QThread::sleep(1); qInfo() << "sent file" << fname << "to dc";
qDebug() << "SENT" << jsFileToSendToDC; ret = true;
ret = true;
}
} else {
qCritical() << "SIZE OF" << jsFileToSendToDC
<< "TOO BIG (" << fi.size() << "BYTES)";
} }
} else { } else {
qCritical() << "CANNOT OPEN" << jsFileToSendToDC << "FOR READING"; qCritical() << "SIZE OF" << fname
<< "TOO BIG (" << fi.size() << "BYTES)";
} }
} else { } else {
qCritical() << jsFileToSendToDC << "DOES NOT EXIST"; qCritical() << "CANNOT OPEN" << fname << "FOR READING";
} }
} else {
qCritical() << fname << "DOES NOT EXIST";
} }
m_hw->dc_autoRequest(false);
qDebug() << "SET AUTO-REQUEST=FALSE";
QThread::sleep(1); // make sure the auto-request flag is acknowledged
return ret; return ret;
} }
bool Update::updatePrinterTemplate(int templateIdx, QString jsFile) const { bool Update::updatePrinterConf(int templateIdx, QString fileToSendToDC) {
return downloadJson(FileTypeJson::PRINTER, templateIdx, jsFile); return updatePrinterTemplate(FileTypeJson::PRINTER,
templateIdx,
fileToSendToDC);
} }
bool Update::updateConfig(QString jsFile) { bool Update::updateConf(QString fileToSendToDC) {
return downloadJson(FileTypeJson::CONFIG, 0, jsFile); return false;
} }
bool Update::updateCashConf(QString jsFile) { bool Update::updateCashConf(QString fileToSendToDC) {
return downloadJson(FileTypeJson::CASH, 0, jsFile); return false;
}
bool Update::updateDeviceConf(QString jsFile) {
return downloadJson(FileTypeJson::DEVICE, 0, jsFile);
} }
QStringList Update::getLinesToWorkOn() { QStringList Update::getLinesToWorkOn() {
@ -559,17 +533,9 @@ bool Update::doUpdate() {
return false; return false;
} }
QString fwVersion = m_hw->dc_getSWversion(); m_hw->dc_autoRequest(false);
QString const hwVersion = m_hw->dc_getHWversion(); QThread::sleep(3); // wait to be sure that there are no more commands sent
// to dc-hardware
qInfo() << "current dc-hardware-version" << hwVersion;
qInfo() << "current dc-firmware-version" << fwVersion;
m_hw->dc_autoRequest(false);// default: turn auto-request setting off
QThread::sleep(3); // wait to be sure that there are no more
// commands sent to dc-hardware
qDebug() << "SET AUTO-REQUEST=FALSE";
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();
@ -602,59 +568,31 @@ bool Update::doUpdate() {
if (name.contains("dc2c", Qt::CaseInsensitive) && if (name.contains("dc2c", Qt::CaseInsensitive) &&
name.endsWith(".bin", Qt::CaseInsensitive)) { name.endsWith(".bin", Qt::CaseInsensitive)) {
qInfo() << "downloading" << name.trimmed() << "to DC"; qInfo() << "downloading" << name.trimmed() << "to DC";
res = true;
#if UPDATE_DC == 1
if ((res = updateBinary(name.toStdString().c_str())) == true) { if ((res = updateBinary(name.toStdString().c_str())) == true) {
qInfo() << "downloaded binary" << name; qInfo() << "downloaded binary" << name;
} }
#endif
} else if (name.contains("DC2C_print", Qt::CaseInsensitive) } else if (name.contains("DC2C_print", Qt::CaseInsensitive)
&& name.endsWith(".json", Qt::CaseInsensitive)) { && name.endsWith(".json", Qt::CaseInsensitive)) {
res = true;
#if UPDATE_PRINTER_TEMPLATES == 1
int i = name.indexOf("DC2C_print", Qt::CaseInsensitive); int i = name.indexOf("DC2C_print", Qt::CaseInsensitive);
int const templateIdx = name.mid(i).midRef(10, 2).toInt(); int const templateIdx = name.mid(i).midRef(10, 2).toInt();
if ((templateIdx < 1) || (templateIdx > 32)) { if ((templateIdx < 1) || (templateIdx > 32)) {
qCritical() << "WRONG TEMPLATE INDEX" << templateIdx; qCritical() << "WRONG TEMPLATE INDEX" << templateIdx;
res = false; res = false;
} else { } else {
if ((res = updatePrinterTemplate(templateIdx, name))) { if ((res = updatePrinterConf(templateIdx, name)) == true) {
qInfo() << "downloaded printer template"<< name; qInfo() << "downloaded printer template" << name;
} }
} }
#endif
} else if (name.contains("DC2C_cash", Qt::CaseInsensitive) } else if (name.contains("DC2C_cash", Qt::CaseInsensitive)
&& name.endsWith(".json", Qt::CaseInsensitive)) { && name.endsWith(".json", Qt::CaseInsensitive)) {
res = true;
#if UPDATE_CASH_TEMPLATE
if ((res = updateCashConf(name))) {
qInfo() << "downloaded cash template"<< name;
}
#endif
} else if (name.contains("DC2C_conf", Qt::CaseInsensitive) } else if (name.contains("DC2C_conf", Qt::CaseInsensitive)
&& name.endsWith(".json", Qt::CaseInsensitive)) { && name.endsWith(".json", Qt::CaseInsensitive)) {
res = true;
#if UPDATE_CONF_TEMPLATE
if ((res= updateConfig(name))) {
qInfo() << "downloaded config template"<< name;
}
#endif
} else if (name.contains("DC2C_device", Qt::CaseInsensitive)
&& name.endsWith(".json", Qt::CaseInsensitive)) {
res = true;
#if UPDATE_DEVICE_TEMPLATE
if ((res = updateDeviceConf(name))) {
qInfo() << "downloaded device template"<< name;
}
#endif
} else { } else {
qCritical() << "UNKNOWN JSON FILE NAME" << name; qCritical() << "UNKNOWN JSON FILE NAME" << name;
res = false; res = false;
} }
} else if (request == "EXECUTE" && name.contains("opkg")) { } else if (request == "EXECUTE" && name.contains("opkg")) {
qInfo() << "starting" << name.trimmed(); qInfo() << "starting" << name.trimmed();
res = true;
#if UPDATE_OPKG == 1
QScopedPointer<QProcess> p(new QProcess(this)); QScopedPointer<QProcess> p(new QProcess(this));
p->setProcessChannelMode(QProcess::MergedChannels); p->setProcessChannelMode(QProcess::MergedChannels);
p->start(name.trimmed()); p->start(name.trimmed());
@ -682,7 +620,6 @@ bool Update::doUpdate() {
} else { } else {
qCritical() << "PROCESS" << name << "TIMEOUT AT START"; qCritical() << "PROCESS" << name << "TIMEOUT AT START";
} }
#endif
} else { } else {
// TODO // TODO
} }
@ -697,11 +634,6 @@ bool Update::doUpdate() {
closeSerial(); closeSerial();
m_hw->dc_autoRequest(true); m_hw->dc_autoRequest(true);
qDebug() << "SET AUTO-REQUEST=TRUE";
qInfo() << "current dc-hardware-version" << m_hw->dc_getHWversion();
qInfo() << "current dc-firmware-version" << m_hw->dc_getSWversion();
return finishUpdate(linesToWorkOn.size() > 0); return finishUpdate(linesToWorkOn.size() > 0);
} }

View File

@ -33,6 +33,10 @@ class Update : public QObject {
bool m_init; bool m_init;
bool updateBinary(char const *fileToSendToDC);
bool updatePrinterConf(int templateIdx, QString fileToSendToDC);
bool updateConf(QString fileToSendToDC);
bool updateCashConf(QString fileToSendToDC);
bool finishUpdate(bool finish); bool finishUpdate(bool finish);
QStringList getLinesToWorkOn(); QStringList getLinesToWorkOn();
QStringList split(QString line, QChar sep = ','); QStringList split(QString line, QChar sep = ',');
@ -41,7 +45,7 @@ class Update : public QObject {
public: public:
enum class DownloadResult {OK, ERROR, TIMEOUT, NOP}; enum class DownloadResult {OK, ERROR, TIMEOUT, NOP};
enum class FileTypeJson {CONFIG=1, DEVICE=2, CASH=3, SERIAL=4, TIME=5, PRINTER=6}; enum class FileTypeJson {CONFIG=1, DEVICE, CASH, SERIAL, TIME, PRINTER};
static hwinf *loadDCPlugin(QDir const &plugInDir, QString const &fn); static hwinf *loadDCPlugin(QDir const &plugInDir, QString const &fn);
@ -57,8 +61,6 @@ public:
bool doUpdate(); bool doUpdate();
private: private:
static QString jsonType(enum FileTypeJson type);
DownloadResult sendStatus(int ret) const; DownloadResult sendStatus(int ret) const;
DownloadResult sendNextAddress(int bNum) const; DownloadResult sendNextAddress(int bNum) const;
DownloadResult sendNextDataBlock(QByteArray const &b, int bNum) const; DownloadResult sendNextDataBlock(QByteArray const &b, int bNum) const;
@ -72,12 +74,7 @@ private:
QByteArray loadBinaryDCFile(QString filename) const; QByteArray loadBinaryDCFile(QString filename) const;
bool downloadBinaryToDC(QString const &bFile) const; bool downloadBinaryToDC(QString const &bFile) const;
bool updateDC(QString bFile) const; bool updateDC(QString bFile) const;
bool updatePrinterTemplate(int templateIdx, QString fname) const; bool updatePrinterTemplate(enum FileTypeJson type, int templateIdx,
bool updateBinary(char const *fileToSendToDC); QString fname) const;
bool updateConfig(QString jsFileToSendToDC);
bool updateCashConf(QString jsFileToSendToDC);
bool updateDeviceConf(QString jsFileToSendToDC);
bool downloadJson(enum FileTypeJson type, int templateIdx,
QString jsFileToSendToDC) const;
}; };
#endif // UPDATE_H_INCLUDED #endif // UPDATE_H_INCLUDED