Added helper-function downloadJson() to implement downloadinf print/conf/cash/device.json. Added some compile time flags used for testing.
This commit is contained in:
parent
f66ae498ce
commit
0668ab65be
178
update.cpp
178
update.cpp
@ -19,10 +19,17 @@
|
|||||||
#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},
|
||||||
@ -282,6 +289,8 @@ 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";
|
||||||
@ -324,7 +333,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
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
|
QThread::msleep(1500);
|
||||||
qInfo() << "resetting device controller...OK";
|
qInfo() << "resetting device controller...OK";
|
||||||
return true;
|
return true;
|
||||||
//}
|
//}
|
||||||
@ -371,17 +380,11 @@ 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";
|
||||||
}
|
}
|
||||||
@ -412,65 +415,88 @@ bool Update::updateDC(QString bFile) const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Update::updatePrinterTemplate(enum FileTypeJson type,
|
QString Update::jsonType(enum FileTypeJson type) {
|
||||||
int templateIdx,
|
switch (type) {
|
||||||
QString fname) const { // name of the json-file
|
case FileTypeJson::CASH: return "CASH";
|
||||||
// sanity checks
|
case FileTypeJson::CONFIG: return "CONFIG";
|
||||||
if (type != FileTypeJson::PRINTER) {
|
case FileTypeJson::PRINTER: return "PRINTER";
|
||||||
qCritical() << "wrong file type" << (uint8_t)type;
|
case FileTypeJson::SERIAL: return "SERIAL";
|
||||||
return false;
|
case FileTypeJson::DEVICE: return "DEVICE";
|
||||||
|
case FileTypeJson::TIME: return "TIME";
|
||||||
}
|
}
|
||||||
|
return "N/A";
|
||||||
|
}
|
||||||
|
|
||||||
qInfo() << "updating printer template:" << fname << "...";
|
bool Update::downloadJson(enum FileTypeJson type,
|
||||||
qInfo() << " printer-template-index:" << templateIdx;
|
int templateIdx,
|
||||||
|
QString jsFileToSendToDC) const {
|
||||||
|
|
||||||
int nTry = 10;
|
qDebug() << "updating json-file:" << jsFileToSendToDC << "...";
|
||||||
while (!m_hw->sys_ready4sending()) { // wait max. 5 seconds
|
qDebug() << " template-index:" << templateIdx;
|
||||||
QThread::sleep(1);
|
qDebug() << " json-type:" << jsonType(type);
|
||||||
|
|
||||||
|
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 10 SECONDS";
|
qCritical() << "SYS NOT READY FOR SENDING AFTER 5 SECONDS";
|
||||||
return false;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
QFile file(fname);
|
if (ready) {
|
||||||
QFileInfo fi(fname); // max. size of template file is 800 bytes
|
QFile file(jsFileToSendToDC);
|
||||||
if (file.exists()) {
|
QFileInfo fi(jsFileToSendToDC); // max. size of template file is 800 bytes
|
||||||
if (file.open(QIODevice::ReadOnly)) {
|
if (file.exists()) {
|
||||||
if (fi.size() <= 800) {
|
if (file.open(QIODevice::ReadOnly)) {
|
||||||
QByteArray ba = file.readAll();
|
if (fi.size() <= 800) {
|
||||||
if (m_hw->sys_sendJsonFileToDc((uint8_t)(type),
|
QByteArray ba = file.readAll();
|
||||||
templateIdx,
|
if (m_hw->sys_sendJsonFileToDc((uint8_t)(type),
|
||||||
(uint8_t *)ba.data())) {
|
templateIdx,
|
||||||
QThread::sleep(1);
|
(uint8_t *)ba.data())) {
|
||||||
qInfo() << "sent file" << fname << "to dc";
|
QThread::sleep(1);
|
||||||
ret = true;
|
qDebug() << "SENT" << jsFileToSendToDC;
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qCritical() << "SIZE OF" << jsFileToSendToDC
|
||||||
|
<< "TOO BIG (" << fi.size() << "BYTES)";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qCritical() << "SIZE OF" << fname
|
qCritical() << "CANNOT OPEN" << jsFileToSendToDC << "FOR READING";
|
||||||
<< "TOO BIG (" << fi.size() << "BYTES)";
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qCritical() << "CANNOT OPEN" << fname << "FOR READING";
|
qCritical() << jsFileToSendToDC << "DOES NOT EXIST";
|
||||||
}
|
}
|
||||||
} 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::updatePrinterConf(int templateIdx, QString fileToSendToDC) {
|
bool Update::updatePrinterTemplate(int templateIdx, QString jsFile) const {
|
||||||
return updatePrinterTemplate(FileTypeJson::PRINTER,
|
return downloadJson(FileTypeJson::PRINTER, templateIdx, jsFile);
|
||||||
templateIdx,
|
|
||||||
fileToSendToDC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Update::updateConf(QString fileToSendToDC) {
|
bool Update::updateConfig(QString jsFile) {
|
||||||
return false;
|
return downloadJson(FileTypeJson::CONFIG, 0, jsFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Update::updateCashConf(QString fileToSendToDC) {
|
bool Update::updateCashConf(QString jsFile) {
|
||||||
return false;
|
return downloadJson(FileTypeJson::CASH, 0, jsFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Update::updateDeviceConf(QString jsFile) {
|
||||||
|
return downloadJson(FileTypeJson::DEVICE, 0, jsFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList Update::getLinesToWorkOn() {
|
QStringList Update::getLinesToWorkOn() {
|
||||||
@ -533,9 +559,17 @@ bool Update::doUpdate() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_hw->dc_autoRequest(false);
|
QString fwVersion = m_hw->dc_getSWversion();
|
||||||
QThread::sleep(3); // wait to be sure that there are no more commands sent
|
QString const hwVersion = m_hw->dc_getHWversion();
|
||||||
// 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();
|
||||||
@ -568,31 +602,59 @@ 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 = updatePrinterConf(templateIdx, name)) == true) {
|
if ((res = updatePrinterTemplate(templateIdx, name))) {
|
||||||
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());
|
||||||
@ -620,6 +682,7 @@ bool Update::doUpdate() {
|
|||||||
} else {
|
} else {
|
||||||
qCritical() << "PROCESS" << name << "TIMEOUT AT START";
|
qCritical() << "PROCESS" << name << "TIMEOUT AT START";
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
@ -634,6 +697,11 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user