Compare commits

...

16 Commits

Author SHA1 Message Date
f6a8059e2d Activated downloading of json to device 2023-11-21 15:25:20 +01:00
4372cb578b Added additional output to CONSOLE() and ISMAS(). 2023-11-21 15:23:28 +01:00
d683a8fc32 Added some comments. 2023-11-21 10:09:52 +01:00
4e92522578 Activate downloading device controller. 2023-11-21 10:09:04 +01:00
b45f3a04b4 Add debug output (for testing, and commented out) in downloadJson(). 2023-11-21 10:08:31 +01:00
0db39746db Aupdate updateBinary() to download device controller using new library fucntions. 2023-11-21 10:07:50 +01:00
f2844aa4d9 Remove obsolete functions: sendStatus(), sendNextAddress(), sendNextDataBlock(),
dc_downloadBinary(), startBootloader(), stopBootloader().
2023-11-21 10:01:11 +01:00
d4043bd7d2 Remove obsolete functions:
DownloadResult sendStatus(int ret) const;
    DownloadResult sendNextAddress(int bNum) const;
    DownloadResult sendNextDataBlock(QByteArray const &b, int bNum) const;
    DownloadResult dc_downloadBinary(QByteArray const &binary) const;

    bool startBootloader() const;
    bool stopBootloader() const;

and updateDC().
2023-11-21 09:56:36 +01:00
89b639c0ed Add handling of alwaysDownloadConfig and alwaysDownloadDC.
Not tested and commnetd out.
2023-11-21 09:54:57 +01:00
1ad13d9a8a Add:
bool const m_alwaysDownloadConfig;
    bool const m_alwaysDownloadDC;
2023-11-21 09:53:28 +01:00
6f2cbb0a26 Set default values for boolean flags. 2023-11-21 09:50:40 +01:00
c15cebf503 Add parsing for alwaysDownloadConfig and alwaysDownloadDC. 2023-11-21 09:49:47 +01:00
5ee1308c9d Add parsing for alwaysDownloadConfig and alwaysDownloadDC. 2023-11-21 09:48:23 +01:00
746d96ca7c Add parsing for flags: alwaysDownLoadDC and alwaysDownloadConfig. 2023-11-21 09:46:11 +01:00
f387eaedea Added flags: always-download-config and always-download-dc.
Download DC and Json files even without any change in customer-repository.
Not tested by now.
2023-11-21 09:44:15 +01:00
0fd977c399 Fix copy-paste-error: set working-directory 2023-11-20 13:49:48 +01:00
9 changed files with 284 additions and 400 deletions

View File

@ -14,3 +14,5 @@ dry-run=false
extended-version=false
yocto-version=false
yocto-install=false
always-download-config=false
always-download-dc=false

View File

@ -82,6 +82,15 @@ VERSION="1.3.17"
# installieren, sodass zumnidest SEND-LAST-VERSION mit rausgeht.
# 6: rsync: explizites Binary, nicht das in busybox enthaltene.
# 7: Versionen der Json-Files lassen sich auslesen.
# Problem: Einstellungen in den Json-Files lassen sich auch mittels
# Funktionen in der CD-Library ueberschreiben. Damit ist dann wieder nicht
# mehr so klar, was jetzt eigentlich aktiv ist.
# 8: m_alwaysDownloadConfig und m_alwaysDownloadDC: vorbereitet: man koennte
# es so arrangieren, dass der DC plus die Json-files im Repository immer
# runtergeladen werden, obwohl sich im Repository gar nicts veraendert
# hat. Eeventuell nuetzlich beim initialen Setuo eines PSA.
win32 {
BUILD_DATE=$$system("date /t")

View File

@ -45,6 +45,14 @@ CommandLineParser::CommandLineParser()
QCommandLineOption(
"no-psa-hardware-update",
QCoreApplication::translate("main", "Do not update the PSA firmware (json, device-controller).")))
, m_alwaysDownloadConfigOption(
QCommandLineOption(
"always-download-config",
QCoreApplication::translate("main", "Always download the (json-)configs to DC).")))
, m_alwaysDownloadDCOption(
QCommandLineOption(
"always-download-dc",
QCoreApplication::translate("main", "Always download the dc-bin-file to DC).")))
, m_workingDirectoryOption(
QCommandLineOption(
QStringList() << "working-directory" << "working-directory",
@ -83,20 +91,34 @@ void CommandLineParser::configure() {
m_iniFileNameOption.setDefaultValue("ATBUpdateTool.ini");
m_parser.addOption(m_iniFileNameOption);
m_pluginDirectoryOption.setDefaultValue("/usr/lib");
m_pluginDirectoryOption.setDefaultValue("/usr/lib/");
m_parser.addOption(m_pluginDirectoryOption);
m_pluginNameOption.setDefaultValue("libCAslave.so");
m_parser.addOption(m_pluginNameOption);
m_alwaysDownloadConfigOption.setDefaultValue("false");
m_parser.addOption(m_alwaysDownloadConfigOption);
m_alwaysDownloadDCOption.setDefaultValue("false");
m_parser.addOption(m_alwaysDownloadDCOption);
m_noDownloadOption.setDefaultValue("false");
m_parser.addOption(m_noDownloadOption);
m_workingDirectoryOption.setDefaultValue("/opt/app/tools/atbupdate");
m_workingDirectoryOption.setDefaultValue("/opt/app/tools/atbupdate/");
m_parser.addOption(m_workingDirectoryOption);
m_dryRunOption.setDefaultValue("false");
m_parser.addOption(m_dryRunOption);
m_extendedVersionOption.setDefaultValue("false");
m_parser.addOption(m_extendedVersionOption);
m_yoctoVersionOption .setDefaultValue("false");
m_parser.addOption(m_yoctoVersionOption);
m_yoctoInstallStatusOption .setDefaultValue("false");
m_parser.addOption(m_yoctoInstallStatusOption);
}
@ -118,7 +140,7 @@ void CommandLineParser::readSettings() {
m_plugInDir = v.toString();
} else
if (key.contains("working-directory")) {
m_plugInName = v.toString();
m_workingDir = v.toString();
} else
if (key.contains("dry-run")) {
m_dryRun = (v.toBool() ? "true" : "false");
@ -129,6 +151,12 @@ void CommandLineParser::readSettings() {
if (key.contains("no-psa-hardware-update")) {
m_noUpdatePsaHardware = (v.toBool() ? "true" : "false");
} else
if (key.contains("always-download-config")) {
m_alwaysDownloadConfig = (v.toBool() ? "true" : "false");
} else
if (key.contains("always-download-dc")) {
m_alwaysDownloadDC = (v.toBool() ? "true" : "false");
} else
if (key.contains("yocto-install")) {
m_showYoctoInstallStatus = (v.toBool() ? "true" : "false");
} else
@ -205,3 +233,17 @@ bool CommandLineParser::extendedVersion() {
}
return m_showExtendedVersion == "false" ? false : true;
}
bool CommandLineParser::alwaysDownloadConfig() {
if (m_parser.isSet(m_alwaysDownloadConfigOption)) {
m_alwaysDownloadConfig = m_parser.value(m_alwaysDownloadConfigOption);
}
return m_alwaysDownloadConfig == "false" ? false : true;
}
bool CommandLineParser::alwaysDownloadDC() {
if (m_parser.isSet(m_alwaysDownloadDCOption)) {
m_alwaysDownloadDC = m_parser.value(m_alwaysDownloadDCOption);
}
return m_alwaysDownloadDC == "false" ? false : true;
}

View File

@ -17,6 +17,8 @@ class CommandLineParser : public QCommandLineParser {
QString m_showYoctoInstallStatus;
QString m_showExtendedVersion;
QString m_iniFileName;
QString m_alwaysDownloadConfig;
QString m_alwaysDownloadDC;
QCommandLineOption m_repositoryUrlOption;
QCommandLineOption m_iniFileDirectoryOption;
@ -24,6 +26,8 @@ class CommandLineParser : public QCommandLineParser {
QCommandLineOption m_pluginDirectoryOption;
QCommandLineOption m_pluginNameOption;
QCommandLineOption m_noDownloadOption;
QCommandLineOption m_alwaysDownloadConfigOption;
QCommandLineOption m_alwaysDownloadDCOption;
QCommandLineOption m_workingDirectoryOption;
QCommandLineOption m_dryRunOption;
QCommandLineOption m_extendedVersionOption;
@ -53,5 +57,7 @@ public:
bool yoctoVersion();
bool yoctoInstallStatus();
bool extendedVersion();
bool alwaysDownloadConfig();
bool alwaysDownloadDC();
};
#endif // COMMAND_LINE_PARSER_H_INCLUDED

View File

@ -79,6 +79,8 @@ int main(int argc, char *argv[]) {
bool const showYoctoVersion = parser.yoctoVersion();
bool const showYoctoInstallStatus = parser.yoctoInstallStatus();
bool const showExtendedVersion = parser.extendedVersion();
bool const alwaysDownloadConfig = parser.alwaysDownloadConfig();
bool const alwaysDownloadDC = parser.alwaysDownloadDC();
QString const rtPath = QCoreApplication::applicationDirPath();
@ -89,6 +91,8 @@ int main(int argc, char *argv[]) {
qInfo() << "workingDir ..............." << workingDir;
qInfo() << "dryRun ..................." << dryRun;
qInfo() << "noUpdatePsaHardware ......" << noUpdatePsaHardware;
qInfo() << "alwaysDownloadConfig ....." << alwaysDownloadConfig;
qInfo() << "alwaysDownloadDC ........." << alwaysDownloadDC;
qInfo() << "extended-version ........." << APP_EXTENDED_VERSION;
if (showExtendedVersion) {
@ -136,6 +140,8 @@ int main(int argc, char *argv[]) {
plugInName,
workingDir,
noUpdatePsaHardware,
alwaysDownloadConfig,
alwaysDownloadDC,
dryRun);
MainWindow mw(&worker);

View File

@ -129,200 +129,6 @@ Update::Update(Worker *worker,
Update::~Update() {
}
Update::DownloadResult Update::sendStatus(int ret) const {
switch (ret) { // return values of dc are:
case 0: // 0: no answer by now
return DownloadResult::NOP; // 1: error
case 10: // 10: success
return DownloadResult::OK;
default:;
}
return DownloadResult::ERROR;
}
Update::DownloadResult Update::sendNextAddress(int bNum) const {
// sends address only if blockNumber is one of 0, 1024, 2048, 3072, 4096
int noAnswerCount = 0;
int errorCount = 0;
if ( bNum==0 || bNum==1024 || bNum==2048 || bNum==3072 || bNum==4096 ) {
// qDebug() << "addr-block" << bNum << "...";
while (noAnswerCount <= 250) {
m_hw->bl_sendAddress(bNum);
QThread::msleep(100);
DownloadResult const res = sendStatus(m_hw->bl_wasSendingAddOK());
if (res != DownloadResult::NOP) {
if (res == DownloadResult::ERROR) {
if (++errorCount >= 10) {
qCritical() << "addr-block" << bNum << "...FAILED";
return res;
}
} else { // res == DownloadResult::OK
// qInfo() << "addr-block" << bNum << "...OK";
return res;
}
} else {
noAnswerCount += 1; // no answer by now
}
}
// wait max. about 3 seconds
return DownloadResult::TIMEOUT;
}
// blockNumber is not one of 0, 1024, 2048, 3072, 4096 -> do nothing
return DownloadResult::NOP;
}
Update::DownloadResult Update::sendNextDataBlock(QByteArray const &binary,
int bNum) const {
uint8_t local[66];
int const bAddr = bNum * 64;
int noAnswerCount = 0;
int errorCount = 0;
memcpy(local, binary.constData() + bAddr, 64);
local[64] = local[65] = 0x00;
// QByteArray b((const char *)(&local[0]), 64);
// qCritical() << "SNDB" << bNum << b.size() << b.toHex();
while (noAnswerCount <= 250) {
m_hw->bl_sendDataBlock(64, local);
QThread::msleep(10);
DownloadResult const res = sendStatus(m_hw->bl_wasSendingDataOK());
if (res != DownloadResult::NOP) {
if (res == DownloadResult::ERROR) {
if (++errorCount >= 10) {
qCritical() << "data for block" << bNum << "...FAILED";
return res;
}
} else {
// qInfo() << "data for block" << bNum << "OK";
return res;
}
} else {
noAnswerCount += 1; // no answer by now
}
}
// wait max. about 3 seconds
return DownloadResult::TIMEOUT;
}
Update::DownloadResult Update::dc_downloadBinary(QByteArray const &b) const {
int const nBlocks = (((b.size())%64)==0) ? (b.size()/64) : (b.size()/64)+1;
// fill lst block of data to be sent with 0xFF
QByteArray ba = b.leftJustified(nBlocks*64, (char)(0xFF));
qInfo() << "total number of bytes to send to dc" << ba.size();
qInfo() << "total number of blocks to send to dc" << nBlocks;
int bNum = 0;
DownloadResult res = DownloadResult::OK;
fprintf(stderr, "\n64-byte block %04d ", bNum);
while (res != DownloadResult::ERROR && bNum < nBlocks) {
if ((res = sendNextAddress(bNum)) != DownloadResult::ERROR) {
if ((res = sendNextDataBlock(ba, bNum)) != DownloadResult::ERROR) {
bNum += 1;
fprintf(stderr, ".");
if ((bNum % 80) == 0) {
fprintf(stderr, "\n64-byte block %04d ", bNum);
}
}
}
}
fprintf(stderr, "\nlast 64-byte block %04d\n", bNum);
int const rest = ba.size() % 64;
int const offset = ba.size() - rest;
char const *startAddress = ba.constData() + offset;
if (rest > 0) {
// SHOULD NEVER HAPPEN !!!
uint8_t local[66];
memset(local, 0xFF, sizeof(local));
memcpy(local, startAddress, rest);
qCritical() << "ERROR SEND REMAINING" << rest << "BYTES";
m_hw->bl_sendDataBlock(64, local);
}
m_hw->bl_sendLastBlock();
qInfo() << "last result" << (int)sendStatus(m_hw->bl_wasSendingDataOK());
return res;
}
bool Update::startBootloader() const { // deprecated
return false;
#if 0
int nStartTry = 5;
while (--nStartTry >= 0) {
m_hw->bl_startBL();
QThread::msleep(500);
int nCheckTry = 10;
while (--nCheckTry >= 0) {
m_hw->bl_checkBL();
QThread::msleep(500);
if (m_hw->bl_isUp()) {
qInfo() << "starting bootloader...OK";
return true;
} else {
qCritical() << "bootloader not up ("
<< nStartTry << "," << nCheckTry << ")" << QThread::currentThread();
}
}
}
qCritical() << "starting bootloader...FAILED" << QThread::currentThread();
return false;
#endif
}
bool Update::stopBootloader() const {
// stop bootloader: this MUST work -> otherwise the PSA has to be restarted
// manually
emit m_worker->showErrorMessage("dc update", "stopping bootloader...");
int nTryFinalize = 1; // could do this in an endless loop
do {
// in principle, any value except BL_STOP will do, as we want to detect
// change to BL_STOP
m_worker->mainWindow()->setUpdateStep(UpdateDcEvent::UpdateStep::BL_CHECK);
QApplication::postEvent(
m_worker->mainWindow(),
new UpdateDcEvent(m_worker, UpdateDcEvent::UpdateStep::BL_STOP, nTryFinalize));
QThread::sleep(1);
int const cntLimit = 20;
int cnt = 0;
while (++cnt < cntLimit &&
m_worker->mainWindow()->updateStep() != UpdateDcEvent::UpdateStep::BL_STOP) {
// wait until bl_stopBL() has been sent
QThread::msleep(500);
}
QApplication::postEvent(
m_worker->mainWindow(),
new UpdateDcEvent(m_worker, UpdateDcEvent::UpdateStep::BL_CHECK, nTryFinalize));
QThread::sleep(1);
QApplication::postEvent(
m_worker->mainWindow(),
new UpdateDcEvent(m_worker, UpdateDcEvent::UpdateStep::BL_IS_UP, nTryFinalize));
QThread::sleep(1);
cnt = 0;
while (++cnt < cntLimit &&
m_worker->mainWindow()->updateStep() != UpdateDcEvent::UpdateStep::BL_IS_DOWN) {
// wait until done
QThread::msleep(200);
}
} while (++nTryFinalize <= MainWindow::BL_STOP_COUNT &&
m_worker->mainWindow()->updateStep() != UpdateDcEvent::UpdateStep::BL_IS_DOWN);
return (m_worker->mainWindow()->updateStep() == UpdateDcEvent::UpdateStep::BL_IS_DOWN);
}
// br is a index into a table, used for historical reasons.
bool Update::openSerial(int br, QString baudrate, QString comPort) const {
qDebug() << "opening serial" << br << baudrate << comPort << "...";
@ -354,51 +160,6 @@ bool Update::isSerialOpen() const {
return m_hw->dc_isPortOpen();
}
bool Update::resetDeviceController() const { // deprecated
return false;
#if 0
qDebug() << "resetting device controller...";
m_hw->bl_rebootDC();
// wait maximally 3 seconds, before starting bootloader
qInfo() << "resetting device controller...OK";
return true;
#endif
}
QByteArray Update::loadBinaryDCFile(QString filename) const {
qDebug() << "loading dc binary" << filename << "...";
QFile file(filename); // closed in destructor call
if (!file.exists()) {
qCritical() << file.fileName() << "does not exist";
return QByteArray();
}
if (!file.open(QIODevice::ReadOnly)) {
qCritical() << "cannot open file" << file.fileName();
return QByteArray();
}
qInfo() << "loading dc binary" << filename << "...OK";
return file.readAll();
}
bool Update::downloadBinaryToDC(QString const &bFile) const {
qDebug() << "sending" << bFile << "to dc...";
QByteArray const dcBinary = loadBinaryDCFile(bFile);
if (dcBinary.size() > 0) {
if (dc_downloadBinary(dcBinary) != DownloadResult::OK) {
qCritical() << "sending" << bFile << "to dc...FAILED";
return false;
} else {
qInfo() << "sending" << bFile << "to dc...OK";
}
} else {
qCritical() << "sending" << bFile << "to dc...FAILED";
qCritical() << "loading binary" << bFile << "FAILED";
return false;
}
return true;
}
/*
///////////////////////////////////////////////////////////////////////////////
@ -482,111 +243,78 @@ bool Update::downloadBinaryToDC(QString const &bFile) const {
// There is no problem to repeat this command until the
// bootloader is really not running anymore.
*/
bool Update::updateBinary(char const *fileToSendToDC) {
bool Update::updateBinary(QString const &fileToSendToDC) {
qInfo() << "UPDATING DEVICE CONTROLLER FIRMWARE BINARY" << fileToSendToDC;
return false;
QFile fn(fileToSendToDC);
bool r;
if ((r = fn.exists()) == true) {
QFileInfo fi(fn);
if ((r = updateDC(fileToSendToDC)) == true) {
Utils::printInfoMsg(
QString(" UPDATING BINARY ") + fi.fileName()
+ QString(" (size=%1").arg(fi.size()) + ") DONE");
} else {
Utils::printCriticalErrorMsg(
QString(" UPDATING BINARY ") + fi.fileName()
+ QString(" (size=%1").arg(fi.size()) + ") FAILED");
}
} else {
Utils::printCriticalErrorMsg(
QString(fileToSendToDC) + " DOES NOT EXIST -> NO UPDATE OF DC FIRMWARE");
}
return r;
}
bool Update::updateDC(QString bFile) const {
qDebug() << "IN UPDATEDC: UPDATING DC: FILE TO SEND" << bFile;
m_worker->mainWindow()->setUpdateStep(UpdateDcEvent::UpdateStep::NONE);
QApplication::postEvent( // step 1: reset device controller
m_worker->mainWindow(),
new UpdateDcEvent(m_worker, UpdateDcEvent::UpdateStep::DC_REBOOT, 1));
QThread::sleep(1);
for (int i=1; i <= MainWindow::BL_START_COUNT; ++i) {
QApplication::postEvent( // step 2: start bootloader (5x)
m_worker->mainWindow(),
new UpdateDcEvent(m_worker, UpdateDcEvent::UpdateStep::BL_START, i));
QThread::sleep(1);
}
int const cntLimit = 100; // wait until its for sure that bl_startBL()
int cnt = 0; // has been excuted
while (++cnt < cntLimit &&
m_worker->mainWindow()->updateStep() != UpdateDcEvent::UpdateStep::BL_START) {
// wait until all bl_startBL() are done
QThread::msleep(200);
}
if (cnt == cntLimit) {
// start events not received ???
Utils::printCriticalErrorMsg("BL_START EVENT NOT RECEIVED AFTER 20 SECS");
if (!fn.exists()) {
// output via CONSOLE() etc
return false;
}
m_worker->mainWindow()->setUpdateStep(UpdateDcEvent::UpdateStep::BL_CHECK);
for (int i=1; i <= MainWindow::BL_IS_UP_COUNT; ++i) {
QApplication::postEvent(m_worker->mainWindow(), new UpdateDcEvent(m_worker, UpdateDcEvent::UpdateStep::BL_CHECK, i));
QThread::sleep(1);
QApplication::postEvent(m_worker->mainWindow(), new UpdateDcEvent(m_worker, UpdateDcEvent::UpdateStep::BL_IS_UP, i));
if (m_worker->mainWindow()->updateStep() == UpdateDcEvent::UpdateStep::BL_IS_UP) {
bool bl_isUp = false;
if (m_hw->bl_completeStart()) {
int cnt = 5;
while (--cnt > 0) {
if (m_hw->bl_isUp()) {
bl_isUp = true;
break;
}
QThread::sleep(1);
}
}
cnt = 0;
while (++cnt < cntLimit &&
m_worker->mainWindow()->updateStep() != UpdateDcEvent::UpdateStep::BL_IS_UP) {
// wait until all bl_startBL() are done
QThread::msleep(200);
}
if (cnt == cntLimit) {
// really not up
Utils::printCriticalErrorMsg("BL_IS_UP EVENT NOT RECEIVED AFTER 20 SECS");
stopBootloader(); // try to stop bootloader whichhas been already started
if (!bl_isUp) {
return false;
}
if (m_worker->mainWindow()->updateStep() == UpdateDcEvent::UpdateStep::BL_IS_UP) {
// bootloader MUST be running to download device-controller
#if 0
if (!downloadBinaryToDC(bFile)) {
Utils::printCriticalErrorMsg(
QString("UPDATING DC: ") + bFile + " ...DOWNLOAD FAILED");
}
#endif
} else {
Utils::printCriticalErrorMsg(
QString("UPDATING DC: ") + bFile + " BOOT LOADER NOT RUNNING -> NO DOWNLOAD ("
+ QThread::currentThread()->objectName() + ")");
if (!m_hw->bl_storeFirmware(fileToSendToDC)) {
m_hw->bl_stopBL();
return false;
}
// do this unconditionally, even if bootloader is not running at all ->
// the controller possibly tells us nonsense.
if (!stopBootloader()) {
Utils::printCriticalErrorMsg(
QString("UPDATING DC: ") + bFile + " BOOT LOADER STILL RUNNING ("
+ QThread::currentThread()->objectName() + ")");
uint16_t const nrOfFirmwareBlocks = m_hw->bl_getNrOfFirmwareBlocks();
for (uint16_t blockNr = 0; blockNr <= nrOfFirmwareBlocks; ++blockNr) {
m_hw->bl_blockAutoLoad(blockNr);
int sleepTime = 0;
while (1) {
if (sleepTime > 1500) {
m_hw->bl_stopBL();
return false;
}
Utils::printInfoMsg(QString("UPDATING DC: ") + bFile + " ...OK");
int8_t const r = m_hw->bl_blockAutoResponse();
// after every "bl_blockAutoLoad()" call this until response
// retval 0: wait 1: OK, blk was sent 2: OK, transfer complete
// 3: error despite repeating, cancel. probably bin file corrupted
// Max duration: 3x no response from BL = 900ms
switch(r) {
case 1:
/* fall through */
case 2:
sleepTime = 0;
break;
case 0: {
QThread::msleep(100);
sleepTime += 100;
} break;
case 3:
m_hw->bl_stopBL();
return false;
default:
m_hw->bl_stopBL();
return false; // unknown error code
}
}
m_hw->bl_stopBL();
}
return true;
}
@ -606,13 +334,6 @@ bool Update::downloadJson(enum FileTypeJson type,
int templateIdx,
QString jsFileToSendToDC) const {
Utils::printInfoMsg(
QString("UPDATING JSON-FILE=%1, TEMPLATE-INDEX=%2, JSON-TYPE=%3")
.arg(jsFileToSendToDC)
.arg(templateIdx)
.arg(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
@ -641,7 +362,25 @@ bool Update::downloadJson(enum FileTypeJson type,
if (m_hw->sys_sendJsonFileToDc((uint8_t)(type),
templateIdx,
(uint8_t *)ba.data())) {
QThread::sleep(1);
QThread::msleep(1000);
// testing
//m_hw->request_ReadbackMachineID();
//QThread::msleep(500);
//uint8_t data[64];
//memset(data, 0x00, sizeof(data));
//uint8_t length = 0;
//m_hw->readback_machineIDdata(&length, data);
//QThread::msleep(500);
//QByteArray ba((const char*)data, length);
//qCritical() << length << "MACHINE ID =" << ba.toHex(':');
ret = true;
}
} else {
@ -758,28 +497,20 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
for (it = filesToWorkOn.cbegin(); it != filesToWorkOn.cend(); ++it) {
m_worker->startProgressLoop();
QString const &fToWorkOn = QDir::cleanPath(m_customerRepository + QDir::separator() + it->trimmed());
#if UPDATE_DC == 1
static const QRegularExpression version("^.*dc2c[.][0-9]{1,2}[.][0-9]{1,2}[.]bin.*$");
if (fToWorkOn.contains(version)) {
Utils::printInfoMsg("DO-UPDATE FILE-TO-WORK-ON " + fToWorkOn);
QFile fn(fToWorkOn);
QFileInfo finfo(fn);
if (!fn.exists()) { // check for broken link
Utils::printCriticalErrorMsg("DO-UPDATE FILE-TO-WORK-ON "
+ fToWorkOn + " DOES NOT EXIST");
res = false;
} else {
bool updateBinaryRes = true;
qInfo() << "DOWNLOADING" << finfo.completeBaseName() << "TO DC";
// CONSOLE()
m_hw->dc_autoRequest(false);// default: turn auto-request setting off
QThread::sleep(1); // wait to be sure that there are no more
// commands sent to dc-hardware
qInfo() << "SET AUTO-REQUEST=FALSE";
if ((updateBinaryRes = updateBinary(fToWorkOn.toStdString().c_str())) == true) {
qCritical() << "downloaded binary" << fToWorkOn;
if ((updateBinaryRes = updateBinary(fToWorkOn)) == true) {
// qCritical() << "downloaded binary" << fToWorkOn;
++displayIndex;
emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(2, ' ') + QString(")")
+ QString(" Update ") + QFileInfo(fToWorkOn).fileName(),
@ -787,7 +518,8 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
}
m_hw->dc_autoRequest(true); // turn auto-request setting on
qInfo() << "SET AUTO-REQUEST=TRUE";
// qInfo() << "SET AUTO-REQUEST=TRUE";
QStringList const &versions = Update::getDcSoftAndHardWareVersion();
if (versions.size() >= 2) {
@ -799,10 +531,10 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
qInfo() << "dc-firmware-version (NOT UPDATED)" << versions[1];
}
}
res = updateBinaryRes;
}
#endif
if (fToWorkOn.contains("DC2C_print", Qt::CaseInsensitive)
} else if (fToWorkOn.contains("DC2C_print", Qt::CaseInsensitive)
&& fToWorkOn.endsWith(".json", Qt::CaseInsensitive)) {
res = true;
int i = fToWorkOn.indexOf("DC2C_print", Qt::CaseInsensitive);

View File

@ -72,23 +72,14 @@ public:
private:
static QString jsonType(enum FileTypeJson type);
DownloadResult sendStatus(int ret) const;
DownloadResult sendNextAddress(int bNum) const;
DownloadResult sendNextDataBlock(QByteArray const &b, int bNum) const;
DownloadResult dc_downloadBinary(QByteArray const &binary) const;
bool startBootloader() const;
bool stopBootloader() const;
bool openSerial(int br, QString baudrate, QString comPort) const;
void closeSerial() const;
bool isSerialOpen() const;
bool resetDeviceController() const;
QByteArray loadBinaryDCFile(QString filename) const;
bool downloadBinaryToDC(QString const &bFile) const;
bool updateDC(QString bFile) const;
bool updatePrinterTemplate(int templateIdx, QString fname) const;
bool updateBinary(char const *fileToSendToDC);
bool updateBinary(QString const &fileToSendToDC);
bool updateConfig(QString jsFileToSendToDC);
bool updateCashConf(QString jsFileToSendToDC);
bool updateDeviceConf(QString jsFileToSendToDC);

View File

@ -116,6 +116,8 @@ Worker::Worker(int customerNr,
QString pluginName,
QString workingDirectory,
bool noUpdatePsaHardware,
bool alwaysDownloadConfig,
bool alwaysDownloadDC,
bool dryRun,
QObject *parent,
char const *serialInterface,
@ -131,6 +133,8 @@ Worker::Worker(int customerNr,
, m_customerRepositoryPath(QString("%1/%2.git").arg(repositoryUrl).arg(m_customerNrStr))
, m_customerRepository(QDir::cleanPath(m_workingDirectory + QDir::separator() + m_customerNrStr))
, m_noUpdatePsaHardware(noUpdatePsaHardware)
, m_alwaysDownloadConfig(alwaysDownloadConfig)
, m_alwaysDownloadDC(alwaysDownloadDC)
, m_dryRun(dryRun)
, m_parent(parent)
, m_serialInterface(serialInterface)
@ -638,6 +642,39 @@ bool Worker::filesToUpdate() {
// always execute contents of opkg_commands-file
m_filesToUpdate << "etc/psa_update/opkg_commands";
if (m_alwaysDownloadConfig) {
#if 0
QStringList lst(QString("m_alwaysDownloadConfig NOT TESTED"));
CONSOLE(lst) << UPDATE_STEP::UPDATE_REPOSITORY;
// always download all json-config files, even if none of them have been
// changed in the git repository. useful for first installation.
QDir dir(QDir::cleanPath(m_customerRepository + QDir::separator() + "etc/psa_config"));
if (dir.exists()) {
QStringList jsons = dir.entryList(QStringList() << "DC2C*.json", QDir::Files);
if (!jsons.isEmpty()) {
m_filesToUpdate << jsons;
}
}
#endif
}
if (m_alwaysDownloadDC) {
#if 0
QStringList lst(QString("m_alwaysDownloadDC NOT TESTED"));
CONSOLE(lst) << UPDATE_STEP::UPDATE_REPOSITORY;
// always download the last dc-binary, even if not changed in the
// git repository. useful for first installation.
QDir dir(QDir::cleanPath(m_customerRepository + QDir::separator() + "etc/psa_update"));
if (dir.exists()) {
QStringList dc = dir.entryList(QStringList() << "dc2c*.bin", QDir::Files,
QDir::SortFlag::Time | QDir::SortFlag::Reversed);
if (!dc.isEmpty()) {
m_filesToUpdate << dc.first();
}
}
#endif
}
if (std::optional<QString> changes = m_gc.gitPull()) {
if (!changes.value().contains("Already up to date")) {
if (std::optional<QStringList> changedFileNames = m_gc.gitDiff(changes.value())) {
@ -652,7 +689,6 @@ bool Worker::filesToUpdate() {
return false;
}
return true;
}

View File

@ -124,6 +124,8 @@ class Worker : public QThread{
QString const m_customerRepositoryPath;
QString const m_customerRepository;
bool const m_noUpdatePsaHardware;
bool const m_alwaysDownloadConfig;
bool const m_alwaysDownloadDC;
bool const m_dryRun;
QObject *m_parent;
QString const m_serialInterface;
@ -331,6 +333,8 @@ public:
QString pluginName,
QString workingDir = ".",
bool noUpdatePsaHardware = false,
bool alwaysDownloadConfig = false,
bool alwaysDownloadDC = false,
bool dryRun = false,
QObject *parent = nullptr,
char const *serialInterface = SERIAL_PORT,
@ -572,18 +576,24 @@ private:
Utils::printUpdateStatusMsg(debug, lst);
break;
case UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS:
lst << instance->m_debugMsg;
Utils::printUpdateStatusMsg(debug, lst);
break;
case UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_FAILURE:
break;
case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY:
break;
case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_SUCCESS:
lst << instance->m_debugMsg;
Utils::printUpdateStatusMsg(debug, lst);
break;
case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_FAILURE:
break;
case UPDATE_STEP::SAVE_LOGS:
break;
case UPDATE_STEP::SAVE_LOGS_SUCCESS:
lst << instance->m_debugMsg;
Utils::printUpdateStatusMsg(debug, lst);
break;
case UPDATE_STEP::SAVE_LOGS_FAILURE:
break;
@ -591,12 +601,18 @@ private:
// SEND_LAST_VERSION_CORRECTION
break;
case UPDATE_STEP::UPDATE_SUCCEEDED:
lst << instance->m_debugMsg;
Utils::printUpdateStatusMsg(debug, lst);
break;
case UPDATE_STEP::UPDATE_ACTIVATED:
lst << instance->m_debugMsg;
Utils::printUpdateStatusMsg(debug, lst);
break;
case UPDATE_STEP::UPDATE_FAILED:
break;
case UPDATE_STEP::FINISHED:
lst << instance->m_debugMsg;
Utils::printUpdateStatusMsg(debug, lst);
break;
case UPDATE_STEP::DEBUG: {
lst << instance->m_debugMsg;
@ -924,33 +940,77 @@ private:
case UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER:
ismasClient.setProgressInPercent(_DOWNLOAD_DEVICE_CONTROLLER);
break;
case UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER_SUCCESS:
case UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER_SUCCESS: {
ismasClient.setProgressInPercent(_DOWNLOAD_DEVICE_CONTROLLER_SUCCESS);
break;
QString const &ismasUpdateNews =
QString("#M=APISM#C=CMD_EVENT#J=") +
ismasClient.updateNewsToIsmas(
_ISMAS_CONTINUE,
ismasClient.getProgressInPercent(),
IsmasClient::RESULT_CODE::SUCCESS,
smap[step],
instance->m_ismasMsg.join(' ').toStdString().c_str(),
"");
ismasClient.sendRequestReceiveResponse(
IsmasClient::APISM::DB_PORT, ismasUpdateNews);
} break;
case UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER_FAILURE:
ismasClient.setProgressInPercent(_DOWNLOAD_DEVICE_CONTROLLER_FAILURE);
break;
case UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS:
case UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS: {
ismasClient.setProgressInPercent(_DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS);
break;
QString const &ismasUpdateNews =
QString("#M=APISM#C=CMD_EVENT#J=") +
ismasClient.updateNewsToIsmas(
_ISMAS_CONTINUE,
ismasClient.getProgressInPercent(),
IsmasClient::RESULT_CODE::SUCCESS,
smap[step],
instance->m_ismasMsg.join(' ').toStdString().c_str(),
"");
ismasClient.sendRequestReceiveResponse(
IsmasClient::APISM::DB_PORT, ismasUpdateNews);
} break;
case UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_FAILURE:
ismasClient.setProgressInPercent(_DOWNLOAD_FILES_TO_PSA_HARDWARE_FAILURE);
break;
case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY:
ismasClient.setProgressInPercent(_SYNC_CUSTOMER_REPOSITORY);
break;
case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_SUCCESS:
case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_SUCCESS: {
ismasClient.setProgressInPercent(_SYNC_CUSTOMER_REPOSITORY_SUCCESS);
break;
QString const &ismasUpdateNews =
QString("#M=APISM#C=CMD_EVENT#J=") +
ismasClient.updateNewsToIsmas(
_ISMAS_CONTINUE,
ismasClient.getProgressInPercent(),
IsmasClient::RESULT_CODE::SUCCESS,
smap[step],
instance->m_ismasMsg.join(' ').toStdString().c_str(),
"");
ismasClient.sendRequestReceiveResponse(
IsmasClient::APISM::DB_PORT, ismasUpdateNews);
} break;
case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_FAILURE:
ismasClient.setProgressInPercent(_SYNC_CUSTOMER_REPOSITORY_FAILURE);
break;
case UPDATE_STEP::SAVE_LOGS:
ismasClient.setProgressInPercent(_SAVE_LOGS);
break;
case UPDATE_STEP::SAVE_LOGS_SUCCESS:
case UPDATE_STEP::SAVE_LOGS_SUCCESS: {
ismasClient.setProgressInPercent(_SAVE_LOGS_SUCCESS);
break;
QString const &ismasUpdateNews =
QString("#M=APISM#C=CMD_EVENT#J=") +
ismasClient.updateNewsToIsmas(
_ISMAS_CONTINUE,
ismasClient.getProgressInPercent(),
IsmasClient::RESULT_CODE::SUCCESS,
smap[step],
instance->m_ismasMsg.join(' ').toStdString().c_str(),
"");
ismasClient.sendRequestReceiveResponse(
IsmasClient::APISM::DB_PORT, ismasUpdateNews);
} break;
case UPDATE_STEP::SAVE_LOGS_FAILURE:
ismasClient.setProgressInPercent(_SAVE_LOGS_FAILURE);
break;