добавление обновлений OTA для TDMA терминала
This commit is contained in:
parent
70a2257255
commit
71bd388dce
@ -52,6 +52,18 @@
|
|||||||
}
|
}
|
||||||
this.submitStatus.firmwareUpgrade = false
|
this.submitStatus.firmwareUpgrade = false
|
||||||
},
|
},
|
||||||
|
{% if modem == 'tdma' %}
|
||||||
|
async settingsPerformFirmwareUpgradeOta() {
|
||||||
|
if (this.submitStatus.firmwareUpgradeOta) { return }
|
||||||
|
this.submitStatus.firmwareUpgradeOta = true
|
||||||
|
try {
|
||||||
|
await fetch('/api/doFirmwareUpgrade?ota=1', { method: 'POST' })
|
||||||
|
} catch (e) {
|
||||||
|
console.log("failed to perform upgrade firmware: ", e)
|
||||||
|
}
|
||||||
|
this.submitStatus.firmwareUpgradeOta = false
|
||||||
|
},
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
doModemReboot() {
|
doModemReboot() {
|
||||||
if (this.submitStatus.modemReboot !== null) {
|
if (this.submitStatus.modemReboot !== null) {
|
||||||
|
@ -21,14 +21,21 @@
|
|||||||
<div>
|
<div>
|
||||||
<button class="dangerous-button" onclick="fetch('/api/resetSettings', { method: 'POST' }).then((r) => { window.location.reload(); })">Сбросить модем до заводских настроек</button>
|
<button class="dangerous-button" onclick="fetch('/api/resetSettings', { method: 'POST' }).then((r) => { window.location.reload(); })">Сбросить модем до заводских настроек</button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<h3>Обновление ПО</h3>
|
<h2>Обновление ПО</h2>
|
||||||
|
<div class="settings-set-container statistics-container">
|
||||||
|
<h3>Ручное обновление</h3>
|
||||||
<label>
|
<label>
|
||||||
<span>Файл {{ this.uploadFw.progress !== null ? `(${this.uploadFw.progress}%)` : '' }}</span>
|
<span>Файл {{ this.uploadFw.progress !== null ? `(${this.uploadFw.progress}%)` : '' }}</span>
|
||||||
<input type="file" accept="application/zip" @change="(e) => { this.uploadFw.filename = e.target.files[0] }">
|
<input type="file" accept="application/zip" @change="(e) => { this.uploadFw.filename = e.target.files[0] }">
|
||||||
<span v-if="uploadFw.sha256 !== null">SHA256: {{ uploadFw.sha256 }}</span>
|
<span v-if="uploadFw.sha256 !== null">SHA256: {{ uploadFw.sha256 }}</span>
|
||||||
</label>
|
</label>
|
||||||
<button class="action-button" @click="settingsUploadUpdate()">Загрузить<span class="submit-spinner" v-show="submitStatus.firmwareUpload"></span></button>
|
<button class="action-button" @click="settingsUploadUpdate()">Загрузить<span class="submit-spinner" v-show="submitStatus.firmwareUpload"></span></button>
|
||||||
<button class="dangerous-button" v-show="uploadFw.sha256 !== null" @click="settingsPerformFirmwareUpgrade()">Обновить встроенное ПО <span class="submit-spinner" v-show="submitStatus.firmwareUpgrade"></span></button>
|
<button class="dangerous-button" v-show="uploadFw.sha256 !== null" @click="settingsPerformFirmwareUpgrade()">Обновить встроенное ПО<span class="submit-spinner" v-show="submitStatus.firmwareUpgrade"></span></button>
|
||||||
</div>{% endraw %}
|
{% endraw %}{% if modem == 'tdma' %}
|
||||||
|
<h3 v-show="statDevice.upgradePercent >= 100">Обновление "по воздуху"</h3>
|
||||||
|
<button class="dangerous-button" v-show="statDevice.upgradePercent >= 100" @click="settingsPerformFirmwareUpgradeOta()">Обновить встроенное ПО<span class="submit-spinner" v-show="submitStatus.firmwareUpgradeOta"></span></button>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -97,6 +97,9 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
firmwareUpload: false,
|
firmwareUpload: false,
|
||||||
firmwareUpgrade: false,
|
firmwareUpgrade: false,
|
||||||
|
{% if modem == 'tdma' %}
|
||||||
|
firmwareUpgradeOta: false,
|
||||||
|
{% endif %}
|
||||||
// когда модем перезагружается, тут должен быть счетчик. Направление счета - к нулю
|
// когда модем перезагружается, тут должен быть счетчик. Направление счета - к нулю
|
||||||
modemReboot: null
|
modemReboot: null
|
||||||
},
|
},
|
||||||
|
29
src/main.cpp
29
src/main.cpp
@ -26,6 +26,7 @@ namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
|
|||||||
|
|
||||||
constexpr const char* REBOOT_COMMAND = "web-action reboot";
|
constexpr const char* REBOOT_COMMAND = "web-action reboot";
|
||||||
constexpr const char* UPGRADE_COMMAND = "web-action upgrade";
|
constexpr const char* UPGRADE_COMMAND = "web-action upgrade";
|
||||||
|
constexpr const char* FIRMWARE_LOCATION = "/tmp/firmware.zip";
|
||||||
|
|
||||||
|
|
||||||
namespace mime_types = http::server::mime_types;
|
namespace mime_types = http::server::mime_types;
|
||||||
@ -63,7 +64,7 @@ class ServerResources {
|
|||||||
bool upgradeOrRebootRunning = false;
|
bool upgradeOrRebootRunning = false;
|
||||||
|
|
||||||
static void onUploadFirmware(const http::server::Request& req) {
|
static void onUploadFirmware(const http::server::Request& req) {
|
||||||
std::ofstream f("/tmp/firmware.zip", std::ios::binary);
|
std::ofstream f(FIRMWARE_LOCATION, std::ios::binary);
|
||||||
|
|
||||||
if (f.is_open()) {
|
if (f.is_open()) {
|
||||||
f.write(req.payload.data(), static_cast<long>(req.payload.size()));
|
f.write(req.payload.data(), static_cast<long>(req.payload.size()));
|
||||||
@ -76,11 +77,27 @@ class ServerResources {
|
|||||||
void doTerminalUpgrade() const {
|
void doTerminalUpgrade() const {
|
||||||
api->executeInApi([](TSID sid) {
|
api->executeInApi([](TSID sid) {
|
||||||
CP_SetDmaDebug(sid, "begin_save_config", "");
|
CP_SetDmaDebug(sid, "begin_save_config", "");
|
||||||
system(UPGRADE_COMMAND);
|
std::string cmd(UPGRADE_COMMAND);
|
||||||
|
cmd += " ";
|
||||||
|
cmd += FIRMWARE_LOCATION;
|
||||||
|
system(cmd.c_str());
|
||||||
CP_SetDmaDebug(sid, "save_config", "");
|
CP_SetDmaDebug(sid, "save_config", "");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef MODEM_IS_TDMA
|
||||||
|
void doTerminalUpgradeOta() const {
|
||||||
|
api->executeInApi([&](TSID sid) {
|
||||||
|
CP_SetDmaDebug(sid, "begin_save_config", "");
|
||||||
|
std::string cmd(UPGRADE_COMMAND);
|
||||||
|
cmd += " ";
|
||||||
|
cmd += api->getOtaFileLocation();
|
||||||
|
system(cmd.c_str());
|
||||||
|
CP_SetDmaDebug(sid, "save_config", "");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
#if defined(MODEM_IS_TDMA)
|
#if defined(MODEM_IS_TDMA)
|
||||||
static constexpr const char* INDEX_HTML = "/main-tdma.html";
|
static constexpr const char* INDEX_HTML = "/main-tdma.html";
|
||||||
@ -432,7 +449,15 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this->upgradeOrRebootRunning = true;
|
this->upgradeOrRebootRunning = true;
|
||||||
|
#ifdef MODEM_IS_TDMA
|
||||||
|
if (req.url->params.find("ota") != req.url->params.end()) {
|
||||||
|
doTerminalUpgradeOta();
|
||||||
|
} else {
|
||||||
doTerminalUpgrade();
|
doTerminalUpgrade();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
doTerminalUpgrade();
|
||||||
|
#endif
|
||||||
rep.status = http::server::ok;
|
rep.status = http::server::ok;
|
||||||
rep.headers.clear();
|
rep.headers.clear();
|
||||||
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
|
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
|
||||||
|
@ -1377,6 +1377,15 @@ void api_driver::ApiDriver::executeInApi(const std::function<void(TSID sid)>& ca
|
|||||||
BOOST_LOG_TRIVIAL(error) << "ApiDriver::executeInApi(): failed to exec with error: " << e.what();
|
BOOST_LOG_TRIVIAL(error) << "ApiDriver::executeInApi(): failed to exec with error: " << e.what();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef MODEM_IS_TDMA
|
||||||
|
std::string api_driver::ApiDriver::getOtaFileLocation() const {
|
||||||
|
device_state s{};
|
||||||
|
daemon->getState(nullptr, nullptr, &s);
|
||||||
|
return s.cur_image;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef MODEM_IS_SCPC
|
#ifdef MODEM_IS_SCPC
|
||||||
std::string api_driver::ApiDriver::getLoggingStatisticsSettings() {
|
std::string api_driver::ApiDriver::getLoggingStatisticsSettings() {
|
||||||
return this->daemon->statsLogs.getSettings();
|
return this->daemon->statsLogs.getSettings();
|
||||||
|
@ -87,6 +87,10 @@ namespace api_driver {
|
|||||||
void readLoggingStatistics(std::vector<uint8_t>& out, int timeStart = -1, int timeEnd = -1, bool ordering = false, int maxItems = -1);
|
void readLoggingStatistics(std::vector<uint8_t>& out, int timeStart = -1, int timeEnd = -1, bool ordering = false, int maxItems = -1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MODEM_IS_TDMA
|
||||||
|
std::string getOtaFileLocation() const;
|
||||||
|
#endif
|
||||||
|
|
||||||
static std::string loadSysInfo();
|
static std::string loadSysInfo();
|
||||||
|
|
||||||
~ApiDriver();
|
~ApiDriver();
|
||||||
|
@ -538,16 +538,20 @@
|
|||||||
<div>
|
<div>
|
||||||
<button class="dangerous-button" onclick="fetch('/api/resetSettings', { method: 'POST' }).then((r) => { window.location.reload(); })">Сбросить модем до заводских настроек</button>
|
<button class="dangerous-button" onclick="fetch('/api/resetSettings', { method: 'POST' }).then((r) => { window.location.reload(); })">Сбросить модем до заводских настроек</button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<h3>Обновление ПО</h3>
|
<h2>Обновление ПО</h2>
|
||||||
|
<div class="settings-set-container statistics-container">
|
||||||
|
<h3>Ручное обновление</h3>
|
||||||
<label>
|
<label>
|
||||||
<span>Файл {{ this.uploadFw.progress !== null ? `(${this.uploadFw.progress}%)` : '' }}</span>
|
<span>Файл {{ this.uploadFw.progress !== null ? `(${this.uploadFw.progress}%)` : '' }}</span>
|
||||||
<input type="file" accept="application/zip" @change="(e) => { this.uploadFw.filename = e.target.files[0] }">
|
<input type="file" accept="application/zip" @change="(e) => { this.uploadFw.filename = e.target.files[0] }">
|
||||||
<span v-if="uploadFw.sha256 !== null">SHA256: {{ uploadFw.sha256 }}</span>
|
<span v-if="uploadFw.sha256 !== null">SHA256: {{ uploadFw.sha256 }}</span>
|
||||||
</label>
|
</label>
|
||||||
<button class="action-button" @click="settingsUploadUpdate()">Загрузить<span class="submit-spinner" v-show="submitStatus.firmwareUpload"></span></button>
|
<button class="action-button" @click="settingsUploadUpdate()">Загрузить<span class="submit-spinner" v-show="submitStatus.firmwareUpload"></span></button>
|
||||||
<button class="dangerous-button" v-show="uploadFw.sha256 !== null" @click="settingsPerformFirmwareUpgrade()">Обновить встроенное ПО <span class="submit-spinner" v-show="submitStatus.firmwareUpgrade"></span></button>
|
<button class="dangerous-button" v-show="uploadFw.sha256 !== null" @click="settingsPerformFirmwareUpgrade()">Обновить встроенное ПО<span class="submit-spinner" v-show="submitStatus.firmwareUpgrade"></span></button>
|
||||||
</div> </div>
|
</div>
|
||||||
|
</div>
|
||||||
<p>Последнее обновление статистики: {{ lastUpdateTime }}</p>
|
<p>Последнее обновление статистики: {{ lastUpdateTime }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -274,16 +274,22 @@
|
|||||||
<div>
|
<div>
|
||||||
<button class="dangerous-button" onclick="fetch('/api/resetSettings', { method: 'POST' }).then((r) => { window.location.reload(); })">Сбросить модем до заводских настроек</button>
|
<button class="dangerous-button" onclick="fetch('/api/resetSettings', { method: 'POST' }).then((r) => { window.location.reload(); })">Сбросить модем до заводских настроек</button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<h3>Обновление ПО</h3>
|
<h2>Обновление ПО</h2>
|
||||||
|
<div class="settings-set-container statistics-container">
|
||||||
|
<h3>Ручное обновление</h3>
|
||||||
<label>
|
<label>
|
||||||
<span>Файл {{ this.uploadFw.progress !== null ? `(${this.uploadFw.progress}%)` : '' }}</span>
|
<span>Файл {{ this.uploadFw.progress !== null ? `(${this.uploadFw.progress}%)` : '' }}</span>
|
||||||
<input type="file" accept="application/zip" @change="(e) => { this.uploadFw.filename = e.target.files[0] }">
|
<input type="file" accept="application/zip" @change="(e) => { this.uploadFw.filename = e.target.files[0] }">
|
||||||
<span v-if="uploadFw.sha256 !== null">SHA256: {{ uploadFw.sha256 }}</span>
|
<span v-if="uploadFw.sha256 !== null">SHA256: {{ uploadFw.sha256 }}</span>
|
||||||
</label>
|
</label>
|
||||||
<button class="action-button" @click="settingsUploadUpdate()">Загрузить<span class="submit-spinner" v-show="submitStatus.firmwareUpload"></span></button>
|
<button class="action-button" @click="settingsUploadUpdate()">Загрузить<span class="submit-spinner" v-show="submitStatus.firmwareUpload"></span></button>
|
||||||
<button class="dangerous-button" v-show="uploadFw.sha256 !== null" @click="settingsPerformFirmwareUpgrade()">Обновить встроенное ПО <span class="submit-spinner" v-show="submitStatus.firmwareUpgrade"></span></button>
|
<button class="dangerous-button" v-show="uploadFw.sha256 !== null" @click="settingsPerformFirmwareUpgrade()">Обновить встроенное ПО<span class="submit-spinner" v-show="submitStatus.firmwareUpgrade"></span></button>
|
||||||
</div> </div>
|
<h3 v-show="statDevice.upgradePercent >= 100">Обновление "по воздуху"</h3>
|
||||||
|
<button class="dangerous-button" v-show="statDevice.upgradePercent >= 100" @click="settingsPerformFirmwareUpgradeOta()">Обновить встроенное ПО<span class="submit-spinner" v-show="submitStatus.firmwareUpgradeOta"></span></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<p>Последнее обновление статистики: {{ lastUpdateTime }}</p>
|
<p>Последнее обновление статистики: {{ lastUpdateTime }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -326,6 +332,7 @@
|
|||||||
network: false,
|
network: false,
|
||||||
firmwareUpload: false,
|
firmwareUpload: false,
|
||||||
firmwareUpgrade: false,
|
firmwareUpgrade: false,
|
||||||
|
firmwareUpgradeOta: false,
|
||||||
// когда модем перезагружается, тут должен быть счетчик. Направление счета - к нулю
|
// когда модем перезагружается, тут должен быть счетчик. Направление счета - к нулю
|
||||||
modemReboot: null
|
modemReboot: null
|
||||||
},
|
},
|
||||||
@ -744,6 +751,16 @@
|
|||||||
}
|
}
|
||||||
this.submitStatus.firmwareUpgrade = false
|
this.submitStatus.firmwareUpgrade = false
|
||||||
},
|
},
|
||||||
|
async settingsPerformFirmwareUpgradeOta() {
|
||||||
|
if (this.submitStatus.firmwareUpgradeOta) { return }
|
||||||
|
this.submitStatus.firmwareUpgradeOta = true
|
||||||
|
try {
|
||||||
|
await fetch('/api/doFirmwareUpgrade?ota=1', { method: 'POST' })
|
||||||
|
} catch (e) {
|
||||||
|
console.log("failed to perform upgrade firmware: ", e)
|
||||||
|
}
|
||||||
|
this.submitStatus.firmwareUpgradeOta = false
|
||||||
|
},
|
||||||
|
|
||||||
doModemReboot() {
|
doModemReboot() {
|
||||||
if (this.submitStatus.modemReboot !== null) {
|
if (this.submitStatus.modemReboot !== null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user