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
148
update.cpp
148
update.cpp
@ -24,6 +24,13 @@
|
|||||||
#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},
|
||||||
{"57600" , 4}, {"115200" , 5}
|
{"57600" , 4}, {"115200" , 5}
|
||||||
@ -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,29 +415,44 @@ bool Update::updateDC(QString bFile) const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Update::updatePrinterTemplate(enum FileTypeJson type,
|
QString Update::jsonType(enum FileTypeJson type) {
|
||||||
|
switch (type) {
|
||||||
|
case FileTypeJson::CASH: return "CASH";
|
||||||
|
case FileTypeJson::CONFIG: return "CONFIG";
|
||||||
|
case FileTypeJson::PRINTER: return "PRINTER";
|
||||||
|
case FileTypeJson::SERIAL: return "SERIAL";
|
||||||
|
case FileTypeJson::DEVICE: return "DEVICE";
|
||||||
|
case FileTypeJson::TIME: return "TIME";
|
||||||
|
}
|
||||||
|
return "N/A";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Update::downloadJson(enum FileTypeJson type,
|
||||||
int templateIdx,
|
int templateIdx,
|
||||||
QString fname) const { // name of the json-file
|
QString jsFileToSendToDC) const {
|
||||||
// sanity checks
|
|
||||||
if (type != FileTypeJson::PRINTER) {
|
|
||||||
qCritical() << "wrong file type" << (uint8_t)type;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
qInfo() << "updating printer template:" << fname << "...";
|
qDebug() << "updating json-file:" << jsFileToSendToDC << "...";
|
||||||
qInfo() << " printer-template-index:" << templateIdx;
|
qDebug() << " template-index:" << templateIdx;
|
||||||
|
qDebug() << " json-type:" << jsonType(type);
|
||||||
|
|
||||||
int nTry = 10;
|
m_hw->dc_autoRequest(true); // downloading Json needs the AutoEmission flag
|
||||||
while (!m_hw->sys_ready4sending()) { // wait max. 5 seconds
|
qDebug() << "SET AUTO-REQUEST=TRUE";
|
||||||
QThread::sleep(1);
|
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);
|
||||||
|
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) {
|
||||||
@ -443,34 +461,42 @@ bool Update::updatePrinterTemplate(enum FileTypeJson 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 {
|
} else {
|
||||||
qCritical() << "SIZE OF" << fname
|
qCritical() << "SIZE OF" << jsFileToSendToDC
|
||||||
<< "TOO BIG (" << fi.size() << "BYTES)";
|
<< "TOO BIG (" << fi.size() << "BYTES)";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qCritical() << "CANNOT OPEN" << fname << "FOR READING";
|
qCritical() << "CANNOT OPEN" << jsFileToSendToDC << "FOR READING";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qCritical() << fname << "DOES NOT EXIST";
|
qCritical() << jsFileToSendToDC << "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