quill/otamanager.cpp

67 lines
2.4 KiB
C++
Raw Normal View History

#include "otamanager.h"
#include "ui_otamanager.h"
#include "functions.h"
#include <QTimer>
2021-08-20 14:12:51 -07:00
#include <QDebug>
2022-02-18 08:06:09 -08:00
#include <QDateTime>
otaManager::otaManager(QWidget *parent) :
QWidget(parent),
ui(new Ui::otaManager)
{
ui->setupUi(this);
2021-08-25 10:16:41 -07:00
QThread::msleep(500);
if(global::otaUpdate::downloadOta == false) {
log("Checking for available OTA update ...", className);
2021-08-25 10:16:41 -07:00
string_writeconfig("/opt/ibxd", "ota_update_check\n");
QTimer * otaCheckTimer = new QTimer(this);
otaCheckTimer->setInterval(100);
connect(otaCheckTimer, &QTimer::timeout, [&]() {
if(QFile::exists("/run/can_ota_update") == true) {
if(checkconfig("/run/can_ota_update") == true) {
log("OTA update is available!", className);
2021-08-25 10:16:41 -07:00
emit canOtaUpdate(true);
}
2021-08-25 10:16:41 -07:00
else {
log("No OTA update available.", className);
2021-08-25 10:16:41 -07:00
emit canOtaUpdate(false);
}
2022-02-18 08:06:09 -08:00
unsigned long currentEpoch = QDateTime::currentSecsSinceEpoch();
string_writeconfig("/external_root/opt/storage/update/last_sync", std::to_string(currentEpoch));
2021-08-25 10:16:41 -07:00
otaManager::close();
}
} );
otaCheckTimer->start();
}
else {
log("Downloading OTA update ...", className);
2021-08-25 10:16:41 -07:00
QFile::remove("/run/can_install_ota_update");
string_writeconfig("/opt/ibxd", "ota_update_download\n");
QTimer * otaDownloadTimer = new QTimer(this);
otaDownloadTimer->setInterval(100);
2021-08-29 12:05:07 -07:00
connect(otaDownloadTimer, &QTimer::timeout, [&]() {
2021-08-25 10:16:41 -07:00
if(QFile::exists("/run/can_install_ota_update") == true) {
if(checkconfig("/run/can_install_ota_update") == true) {
log("Download succeeded.", className);
2021-08-25 10:16:41 -07:00
emit downloadedOtaUpdate(true);
global::otaUpdate::downloadOta = false;
}
else {
log("Download failed.", className);
2021-08-25 10:16:41 -07:00
emit downloadedOtaUpdate(false);
global::otaUpdate::downloadOta = false;
}
2022-02-18 08:06:09 -08:00
QFile::remove("/external_root/opt/storage/update/last_sync");
2021-08-25 10:16:41 -07:00
otaManager::close();
}
} );
otaDownloadTimer->start();
}
}
otaManager::~otaManager()
{
delete ui;
}