2021-07-20 20:27:32 -07:00
|
|
|
#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>
|
2021-07-20 20:27:32 -07:00
|
|
|
|
|
|
|
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) {
|
2022-04-10 18:37:33 -07:00
|
|
|
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) {
|
2022-04-04 21:47:15 -07:00
|
|
|
log("OTA update is available!", className);
|
2021-08-25 10:16:41 -07:00
|
|
|
emit canOtaUpdate(true);
|
2021-08-19 05:23:18 -07:00
|
|
|
}
|
2021-08-25 10:16:41 -07:00
|
|
|
else {
|
2022-04-04 21:47:15 -07:00
|
|
|
log("No OTA update available.", className);
|
2021-08-25 10:16:41 -07:00
|
|
|
emit canOtaUpdate(false);
|
2021-08-19 05:23:18 -07:00
|
|
|
}
|
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));
|
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();
|
2021-08-19 05:23:18 -07:00
|
|
|
}
|
|
|
|
else {
|
2022-04-10 18:37:33 -07:00
|
|
|
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) {
|
2022-04-04 21:47:15 -07:00
|
|
|
log("Download succeeded.", className);
|
2021-08-25 10:16:41 -07:00
|
|
|
emit downloadedOtaUpdate(true);
|
|
|
|
global::otaUpdate::downloadOta = false;
|
|
|
|
}
|
|
|
|
else {
|
2022-04-04 21:47:15 -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();
|
2021-08-19 05:23:18 -07:00
|
|
|
}
|
2021-07-20 20:27:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
otaManager::~otaManager()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|