добавление обновлений OTA для TDMA терминала
This commit is contained in:
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* UPGRADE_COMMAND = "web-action upgrade";
|
||||
constexpr const char* FIRMWARE_LOCATION = "/tmp/firmware.zip";
|
||||
|
||||
|
||||
namespace mime_types = http::server::mime_types;
|
||||
@@ -63,7 +64,7 @@ class ServerResources {
|
||||
bool upgradeOrRebootRunning = false;
|
||||
|
||||
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()) {
|
||||
f.write(req.payload.data(), static_cast<long>(req.payload.size()));
|
||||
@@ -76,11 +77,27 @@ class ServerResources {
|
||||
void doTerminalUpgrade() const {
|
||||
api->executeInApi([](TSID sid) {
|
||||
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", "");
|
||||
});
|
||||
}
|
||||
|
||||
#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:
|
||||
#if defined(MODEM_IS_TDMA)
|
||||
static constexpr const char* INDEX_HTML = "/main-tdma.html";
|
||||
@@ -432,7 +449,15 @@ public:
|
||||
return;
|
||||
}
|
||||
this->upgradeOrRebootRunning = true;
|
||||
#ifdef MODEM_IS_TDMA
|
||||
if (req.url->params.find("ota") != req.url->params.end()) {
|
||||
doTerminalUpgradeOta();
|
||||
} else {
|
||||
doTerminalUpgrade();
|
||||
}
|
||||
#else
|
||||
doTerminalUpgrade();
|
||||
#endif
|
||||
rep.status = http::server::ok;
|
||||
rep.headers.clear();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
#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
|
||||
std::string api_driver::ApiDriver::getLoggingStatisticsSettings() {
|
||||
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);
|
||||
#endif
|
||||
|
||||
#ifdef MODEM_IS_TDMA
|
||||
std::string getOtaFileLocation() const;
|
||||
#endif
|
||||
|
||||
static std::string loadSysInfo();
|
||||
|
||||
~ApiDriver();
|
||||
|
Reference in New Issue
Block a user