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(QFile::exists("/mnt/onboard/onboard/.inkbox/SKIP_OTACHECK") == false) {
qDebug() << "Checking for available OTA update ...";
if(global::otaUpdate::downloadOta != true) { if(global::otaUpdate::downloadOta != true) {
string_writeconfig("/opt/ibxd", "ota_update_check\n"); string_writeconfig("/opt/ibxd", "ota_update_check\n");
QTimer *otaCheckTimer = new QTimer(); while(true) {
otaCheckTimer->setInterval(100);
connect(otaCheckTimer, &QTimer::timeout, [&]() {
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 { else {
emit canOtaUpdate(false); emit canOtaUpdate(false);
qDebug() << "No OTA update available.";
break;
}
}
}
QThread::msleep(500);
otaManager::close(); otaManager::close();
} }
}
} );
}
else { else {
string_writeconfig("/opt/ibxd", "ota_update_download\n"); string_writeconfig("/opt/ibxd", "ota_update_download\n");
QTimer *otaDownloadTimer = new QTimer(); while(true) {
otaDownloadTimer->setInterval(500);
connect(otaDownloadTimer, &QTimer::timeout, [&]() {
if(QFile::exists("/run/can_install_ota_update") == true) { if(QFile::exists("/run/can_install_ota_update") == true) {
if(checkconfig("/run/can_install_ota_update") == true) { if(checkconfig("/run/can_install_ota_update") == true) {
emit downloadedOta(true); emit downloadedOta(true);
global::otaUpdate::downloadOta = false; global::otaUpdate::downloadOta = false;
otaManager::close(); break;
} }
else { else {
emit downloadedOta(false); emit downloadedOta(false);
global::otaUpdate::downloadOta = false; global::otaUpdate::downloadOta = false;
break;
}
}
}
QThread::msleep(500);
otaManager::close(); otaManager::close();
} }
} }
} ); else {
qDebug() << "Skip OTA update check!";
} }
} }