Skip to content

Commit

Permalink
Optimize and clean up a couple extra things
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc committed Jan 26, 2025
1 parent 03d2c01 commit 0292cb2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/GatewayClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ void GatewayClient::_sendBootStatus()
return;
}

using namespace std::string_view_literals;

OpenShock::SemVer version;
if (!OpenShock::TryParseSemVer(OPENSHOCK_FW_VERSION, version)) {
if (!OpenShock::TryParseSemVer(OPENSHOCK_FW_VERSION ""sv, version)) {
OS_LOGE(TAG, "Failed to parse firmware version");
return;
}
Expand Down
20 changes: 10 additions & 10 deletions src/OtaUpdateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,6 @@ static void _otaUpdateTask(void* arg)
OS_LOGE(TAG, "Failed to get requested version");
continue;
}

OS_LOGD(TAG, "Update requested for version %s", version.toString().c_str()); // TODO: This is abusing the SemVer::toString() method causing alot of string copies, fix this
} else {
OS_LOGD(TAG, "Checking for updates");

Expand All @@ -330,15 +328,17 @@ static void _otaUpdateTask(void* arg)
OS_LOGE(TAG, "Failed to fetch firmware version");
continue;
}

OS_LOGD(TAG, "Remote version: %s", version.toString().c_str()); // TODO: This is abusing the SemVer::toString() method causing alot of string copies, fix this
}

if (version.toString() == OPENSHOCK_FW_VERSION) { // TODO: This is abusing the SemVer::toString() method causing alot of string copies, fix this
std::string versionStr = version.toString(); // TODO: This is abusing the SemVer::toString() method causing alot of string copies, fix this

if (versionStr == OPENSHOCK_FW_VERSION ""sv) {
OS_LOGI(TAG, "Requested version is already installed");
continue;
}

OS_LOGD(TAG, "Updating to version: %.*s", versionStr.length(), versionStr.data());

// Generate random int32_t for this update.
int32_t updateId = static_cast<int32_t>(esp_random());
if (!Config::SetOtaUpdateId(updateId)) {
Expand Down Expand Up @@ -369,24 +369,24 @@ static void _otaUpdateTask(void* arg)

// Print release.
OS_LOGD(TAG, "Firmware release:");
OS_LOGD(TAG, " Version: %s", version.toString().c_str()); // TODO: This is abusing the SemVer::toString() method causing alot of string copies, fix this
OS_LOGD(TAG, " App binary URL: %s", release.appBinaryUrl.c_str());
OS_LOGD(TAG, " Version: %.*s", versionStr.length(), versionStr.data());
OS_LOGD(TAG, " App binary URL: %.*s", release.appBinaryUrl.length(), release.appBinaryUrl.data());
OS_LOGD(TAG, " App binary hash: %s", HexUtils::ToHex<32>(release.appBinaryHash).data());
OS_LOGD(TAG, " Filesystem binary URL: %s", release.filesystemBinaryUrl.c_str());
OS_LOGD(TAG, " Filesystem binary URL: %.*s", release.filesystemBinaryUrl.length(), release.filesystemBinaryUrl.data());
OS_LOGD(TAG, " Filesystem binary hash: %s", HexUtils::ToHex<32>(release.filesystemBinaryHash).data());

// Get available app update partition.
const esp_partition_t* appPartition = esp_ota_get_next_update_partition(nullptr);
if (appPartition == nullptr) {
OS_LOGE(TAG, "Failed to get app update partition"); // TODO: Send error message to server
OS_LOGE(TAG, "Failed to get app update partition");
_sendFailureMessage("Failed to get app update partition"sv);
continue;
}

// Get filesystem partition.
const esp_partition_t* filesystemPartition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, "static0");
if (filesystemPartition == nullptr) {
OS_LOGE(TAG, "Failed to find filesystem partition"); // TODO: Send error message to server
OS_LOGE(TAG, "Failed to find filesystem partition");
_sendFailureMessage("Failed to find filesystem partition"sv);
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/SemVer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,12 @@ std::string SemVer::toString() const

if (!prerelease.empty()) {
str.push_back('-');
str.append(prerelease.data(), prerelease.length());
str.append(prerelease);
}

if (!build.empty()) {
str.push_back('+');
str.append(build.data(), build.length());
str.append(build);
}

return str;
Expand Down

0 comments on commit 0292cb2

Please sign in to comment.