quill/src/otaUpdate/otamanager.cpp

68 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);
2023-07-11 06:22:48 -07:00
writeFile("/opt/ibxd", "ota_update_check\n");
2021-08-25 10:16:41 -07:00
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) {
2022-06-27 15:14:20 -07:00
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 {
2022-06-27 15:14:20 -07:00
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();
2023-07-11 06:22:48 -07:00
writeFile("/external_root/opt/storage/update/last_sync", QString::number(currentEpoch));
2022-05-16 20:57:35 -07:00
QFile::remove("/run/can_ota_update");
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");
2023-07-11 06:22:48 -07:00
writeFile("/opt/ibxd", "ota_update_download\n");
2021-08-25 10:16:41 -07:00
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) {
2022-06-27 15:14:20 -07:00
log("Download succeeded", className);
2021-08-25 10:16:41 -07:00
emit downloadedOtaUpdate(true);
global::otaUpdate::downloadOta = false;
}
else {
2022-06-27 15:14:20 -07:00
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;
}