OTA improvements

This commit is contained in:
Nicolas Mailloux 2021-08-20 17:12:51 -04:00
parent 5dcc72f8b1
commit c791da9fbf

View file

@ -3,47 +3,56 @@
#include "functions.h" #include "functions.h"
#include <QTimer> #include <QTimer>
#include <QDebug>
otaManager::otaManager(QWidget *parent) : otaManager::otaManager(QWidget *parent) :
QWidget(parent), QWidget(parent),
ui(new Ui::otaManager) ui(new Ui::otaManager)
{ {
ui->setupUi(this); ui->setupUi(this);
if(global::otaUpdate::downloadOta != true) { if(QFile::exists("/mnt/onboard/onboard/.inkbox/SKIP_OTACHECK") == false) {
string_writeconfig("/opt/ibxd", "ota_update_check\n"); qDebug() << "Checking for available OTA update ...";
QTimer *otaCheckTimer = new QTimer(); if(global::otaUpdate::downloadOta != true) {
otaCheckTimer->setInterval(100); string_writeconfig("/opt/ibxd", "ota_update_check\n");
connect(otaCheckTimer, &QTimer::timeout, [&]() { while(true) {
if(QFile::exists("/run/can_ota_update") == true) { if(QFile::exists("/run/can_ota_update") == true) {
if(checkconfig("/run/can_ota_update") == true) { if(checkconfig("/run/can_ota_update") == true) {
emit canOtaUpdate(true); emit canOtaUpdate(true);
otaManager::close(); qDebug() << "OTA update is available!";
} break;
else { }
emit canOtaUpdate(false); else {
otaManager::close(); emit canOtaUpdate(false);
qDebug() << "No OTA update available.";
break;
}
} }
} }
} ); QThread::msleep(500);
otaManager::close();
}
else {
string_writeconfig("/opt/ibxd", "ota_update_download\n");
while(true) {
if(QFile::exists("/run/can_install_ota_update") == true) {
if(checkconfig("/run/can_install_ota_update") == true) {
emit downloadedOta(true);
global::otaUpdate::downloadOta = false;
break;
}
else {
emit downloadedOta(false);
global::otaUpdate::downloadOta = false;
break;
}
}
}
QThread::msleep(500);
otaManager::close();
}
} }
else { else {
string_writeconfig("/opt/ibxd", "ota_update_download\n"); qDebug() << "Skip OTA update check!";
QTimer *otaDownloadTimer = new QTimer();
otaDownloadTimer->setInterval(500);
connect(otaDownloadTimer, &QTimer::timeout, [&]() {
if(QFile::exists("/run/can_install_ota_update") == true) {
if(checkconfig("/run/can_install_ota_update") == true) {
emit downloadedOta(true);
global::otaUpdate::downloadOta = false;
otaManager::close();
}
else {
emit downloadedOta(false);
global::otaUpdate::downloadOta = false;
otaManager::close();
}
}
} );
} }
} }