Skip to content

Commit 0292cb2

Browse files
committed
Optimize and clean up a couple extra things
1 parent 03d2c01 commit 0292cb2

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

src/GatewayClient.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,10 @@ void GatewayClient::_sendBootStatus()
137137
return;
138138
}
139139

140+
using namespace std::string_view_literals;
141+
140142
OpenShock::SemVer version;
141-
if (!OpenShock::TryParseSemVer(OPENSHOCK_FW_VERSION, version)) {
143+
if (!OpenShock::TryParseSemVer(OPENSHOCK_FW_VERSION ""sv, version)) {
142144
OS_LOGE(TAG, "Failed to parse firmware version");
143145
return;
144146
}

src/OtaUpdateManager.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,6 @@ static void _otaUpdateTask(void* arg)
320320
OS_LOGE(TAG, "Failed to get requested version");
321321
continue;
322322
}
323-
324-
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
325323
} else {
326324
OS_LOGD(TAG, "Checking for updates");
327325

@@ -330,15 +328,17 @@ static void _otaUpdateTask(void* arg)
330328
OS_LOGE(TAG, "Failed to fetch firmware version");
331329
continue;
332330
}
333-
334-
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
335331
}
336332

337-
if (version.toString() == OPENSHOCK_FW_VERSION) { // TODO: This is abusing the SemVer::toString() method causing alot of string copies, fix this
333+
std::string versionStr = version.toString(); // TODO: This is abusing the SemVer::toString() method causing alot of string copies, fix this
334+
335+
if (versionStr == OPENSHOCK_FW_VERSION ""sv) {
338336
OS_LOGI(TAG, "Requested version is already installed");
339337
continue;
340338
}
341339

340+
OS_LOGD(TAG, "Updating to version: %.*s", versionStr.length(), versionStr.data());
341+
342342
// Generate random int32_t for this update.
343343
int32_t updateId = static_cast<int32_t>(esp_random());
344344
if (!Config::SetOtaUpdateId(updateId)) {
@@ -369,24 +369,24 @@ static void _otaUpdateTask(void* arg)
369369

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

378378
// Get available app update partition.
379379
const esp_partition_t* appPartition = esp_ota_get_next_update_partition(nullptr);
380380
if (appPartition == nullptr) {
381-
OS_LOGE(TAG, "Failed to get app update partition"); // TODO: Send error message to server
381+
OS_LOGE(TAG, "Failed to get app update partition");
382382
_sendFailureMessage("Failed to get app update partition"sv);
383383
continue;
384384
}
385385

386386
// Get filesystem partition.
387387
const esp_partition_t* filesystemPartition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, "static0");
388388
if (filesystemPartition == nullptr) {
389-
OS_LOGE(TAG, "Failed to find filesystem partition"); // TODO: Send error message to server
389+
OS_LOGE(TAG, "Failed to find filesystem partition");
390390
_sendFailureMessage("Failed to find filesystem partition"sv);
391391
continue;
392392
}

src/SemVer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,12 @@ std::string SemVer::toString() const
252252

253253
if (!prerelease.empty()) {
254254
str.push_back('-');
255-
str.append(prerelease.data(), prerelease.length());
255+
str.append(prerelease);
256256
}
257257

258258
if (!build.empty()) {
259259
str.push_back('+');
260-
str.append(build.data(), build.length());
260+
str.append(build);
261261
}
262262

263263
return str;

0 commit comments

Comments
 (0)