Added helper functions. Update will be used heavily by the Worker-class in a later stage.

This commit is contained in:
Gerhard Hoffmann 2023-07-14 13:34:48 +02:00
parent 9ed51d60e4
commit f963b61ebc

View File

@ -81,9 +81,14 @@ hwinf *Update::loadDCPlugin(QDir const &plugInDir, QString const &fname) {
Update::Update(hwinf *hw,
QString update_ctrl_file,
QString repositoryPath,
QString customerId,
QString branchName,
QString workingDir,
bool maintenanceMode,
bool testMode,
bool executeScriptOnly,
bool dryRun,
QObject *parent,
char const *serialInterface,
char const *baudrate)
@ -93,11 +98,19 @@ Update::Update(hwinf *hw,
, m_baudrate(baudrate)
, m_update_ctrl_file(update_ctrl_file)
, m_update_ctrl_file_copy(update_ctrl_file + ".copy")
, m_repositoryPath(repositoryPath)
, m_customerId(customerId)
, m_branchName(branchName)
, m_workingDir(workingDir)
, m_maintenanceMode(maintenanceMode)
, m_testMode(testMode)
, m_executeScriptOnly(executeScriptOnly)
, m_dryRun(dryRun)
//, m_apismClient(nullptr, nullptr, nullptr)
, m_init(true) {
// m_apismClient.sendSelfTest();
if (!m_testMode) {
// make sure the files are empty
if (m_update_ctrl_file.exists()) {
@ -213,7 +226,7 @@ Update::DownloadResult Update::sendNextAddress(int bNum) const {
int noAnswerCount = 0;
int errorCount = 0;
if ( bNum==0 || bNum==1024 || bNum==2048 || bNum==3072 || bNum==4096 ) {
qDebug() << "addr-block" << bNum << "...";
// qDebug() << "addr-block" << bNum << "...";
while (noAnswerCount <= 250) {
m_hw->bl_sendAddress(bNum);
QThread::msleep(100);
@ -225,7 +238,7 @@ Update::DownloadResult Update::sendNextAddress(int bNum) const {
return res;
}
} else { // res == DownloadResult::OK
qInfo() << "addr-block" << bNum << "...OK";
// qInfo() << "addr-block" << bNum << "...OK";
return res;
}
} else {
@ -285,13 +298,20 @@ Update::DownloadResult Update::dc_downloadBinary(QByteArray const &b) const {
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;
@ -619,8 +639,15 @@ void Update::finished(int /*exitCode*/, QProcess::ExitStatus /*exitStatus*/) {
disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(readyReadStandardError()));
}
// bool Update::executeProcess(QString const &cmd);
bool Update::doUpdate() {
//
// ACHTUNG !!!
//
return true;
/*
The file referred to by 'update_data' has the following structure for
each line:
@ -643,6 +670,10 @@ bool Update::doUpdate() {
return false;
}
if (m_executeScriptOnly) { // basically a test flag for executing only the
return true; // update script.
}
bool serialOpened = false;
bool serialOpen = false;
@ -709,10 +740,11 @@ bool Update::doUpdate() {
if (!linkTarget.exists()) { // check for broken link
res = false;
} else {
if (fwVersion.startsWith(linkTarget.completeBaseName())) {
qCritical() << "current dc-firmware-version" << fwVersion
<< "already installed";
res = false;
if (false) {
//if (fwVersion.startsWith(linkTarget.completeBaseName())) {
// qCritical() << "current dc-firmware-version" << fwVersion
// << "already installed";
// res = false;
} else {
res = true;