Skip to content

Commit

Permalink
Refactor OTA Update Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc committed Oct 10, 2024
1 parent 68a22e4 commit 93585f9
Show file tree
Hide file tree
Showing 16 changed files with 850 additions and 703 deletions.
10 changes: 10 additions & 0 deletions include/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
#endif

#define OPENSHOCK_FW_CDN_URL(path) "https://" OPENSHOCK_FW_CDN_DOMAIN path
#define OPENSHOCK_FW_CDN_CHANNEL_URL(ch) OPENSHOCK_FW_CDN_URL("/version-" ch ".txt")
#define OPENSHOCK_FW_CDN_STABLE_URL OPENSHOCK_FW_CDN_CHANNEL_URL("stable")
#define OPENSHOCK_FW_CDN_BETA_URL OPENSHOCK_FW_CDN_CHANNEL_URL("beta")
#define OPENSHOCK_FW_CDN_DEVELOP_URL OPENSHOCK_FW_CDN_CHANNEL_URL("develop")
#define OPENSHOCK_FW_CDN_BOARDS_BASE_URL_FORMAT OPENSHOCK_FW_CDN_URL("/%s")
#define OPENSHOCK_FW_CDN_BOARDS_INDEX_URL_FORMAT OPENSHOCK_FW_CDN_BOARDS_BASE_URL_FORMAT "/boards.txt"
#define OPENSHOCK_FW_CDN_VERSION_BASE_URL_FORMAT OPENSHOCK_FW_CDN_BOARDS_BASE_URL_FORMAT "/" OPENSHOCK_FW_BOARD
#define OPENSHOCK_FW_CDN_APP_URL_FORMAT OPENSHOCK_FW_CDN_VERSION_BASE_URL_FORMAT "/app.bin"
#define OPENSHOCK_FW_CDN_FILESYSTEM_URL_FORMAT OPENSHOCK_FW_CDN_VERSION_BASE_URL_FORMAT "/staticfs.bin"
#define OPENSHOCK_FW_CDN_SHA256_HASHES_URL_FORMAT OPENSHOCK_FW_CDN_VERSION_BASE_URL_FORMAT "/hashes.sha256.txt"

#define OPENSHOCK_GPIO_INVALID -1

Expand Down
4 changes: 2 additions & 2 deletions include/config/OtaUpdateConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include "config/ConfigBase.h"
#include "FirmwareBootType.h"
#include "OtaUpdateChannel.h"
#include "OtaUpdateStep.h"
#include "ota/OtaUpdateChannel.h"
#include "ota/OtaUpdateStep.h"

#include <string>

Expand Down
28 changes: 28 additions & 0 deletions include/http/FirmwareCDN.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include "http/HTTPRequestManager.h"
#include "ota/FirmwareBinaryHash.h"
#include "ota/OtaUpdateChannel.h"
#include "SemVer.h"

#include <string_view>

namespace OpenShock::HTTP::FirmwareCDN {
/// @brief Fetches the firmware version for the given channel from the firmware CDN.
/// Valid response codes: 200, 304
/// @param channel The channel to fetch the firmware version for.
/// @return The firmware version or an error response.
HTTP::Response<OpenShock::SemVer> GetFirmwareVersion(OtaUpdateChannel channel);

/// @brief Fetches the list of available boards for the given firmware version from the firmware CDN.
/// Valid response codes: 200, 304
/// @param version The firmware version to fetch the boards for.
/// @return The list of available boards or an error response.
HTTP::Response<std::vector<std::string>> GetFirmwareBoards(const OpenShock::SemVer& version);

/// @brief Fetches the binary hashes for the given firmware version from the firmware CDN.
/// Valid response codes: 200, 304
/// @param version The firmware version to fetch the binary hashes for.
/// @return The binary hashes or an error response.
HTTP::Response<std::vector<FirmwareBinaryHash>> GetFirmwareBinaryHashes(const OpenShock::SemVer& version);
} // namespace OpenShock::HTTP::FirmwareCDN
13 changes: 13 additions & 0 deletions include/ota/FirmwareBinaryHash.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <cstdint>
#include <string>

namespace OpenShock
{
struct FirmwareBinaryHash
{
std::string name;
uint8_t hash[32];
};
} // namespace OpenShock
14 changes: 14 additions & 0 deletions include/ota/FirmwareReleaseInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <cstdint>
#include <string>

namespace OpenShock
{
struct FirmwareReleaseInfo {
std::string appBinaryUrl;
uint8_t appBinaryHash[32];
std::string filesystemBinaryUrl;
uint8_t filesystemBinaryHash[32];
};
} // namespace OpenShock
File renamed without changes.
20 changes: 20 additions & 0 deletions include/ota/OtaUpdateClient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include "SemVer.h"

#include <freertos/task.h>

namespace OpenShock {
class OtaUpdateClient {
public:
OtaUpdateClient(const OpenShock::SemVer& version);
~OtaUpdateClient();

bool Start();
private:
void _task();

OpenShock::SemVer m_version;
TaskHandle_t m_taskHandle;
};
}
12 changes: 2 additions & 10 deletions include/OtaUpdateManager.h → include/ota/OtaUpdateManager.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "FirmwareBootType.h"
#include "FirmwareReleaseInfo.h"
#include "OtaUpdateChannel.h"
#include "SemVer.h"

Expand All @@ -12,16 +13,7 @@
namespace OpenShock::OtaUpdateManager {
[[nodiscard]] bool Init();

struct FirmwareRelease {
std::string appBinaryUrl;
uint8_t appBinaryHash[32];
std::string filesystemBinaryUrl;
uint8_t filesystemBinaryHash[32];
};

bool TryGetFirmwareVersion(OtaUpdateChannel channel, OpenShock::SemVer& version);
bool TryGetFirmwareBoards(const OpenShock::SemVer& version, std::vector<std::string>& boards);
bool TryGetFirmwareRelease(const OpenShock::SemVer& version, FirmwareRelease& release);
bool TryGetFirmwareRelease(const OpenShock::SemVer& version, FirmwareReleaseInfo& release);

bool TryStartFirmwareInstallation(const OpenShock::SemVer& version);

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/GatewayClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const char* const TAG = "GatewayClient";
#include "config/Config.h"
#include "event_handlers/WebSocket.h"
#include "Logging.h"
#include "OtaUpdateManager.h"
#include "ota/OtaUpdateManager.h"
#include "serialization/WSGateway.h"
#include "Time.h"
#include "util/CertificateUtils.h"
Expand Down
Loading

1 comment on commit 93585f9

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cpp-Linter Report ⚠️

Some files did not pass the configured checks!

clang-format (v18.1.8) reports: 7 file(s) not formatted
  • include/Common.h
  • include/ota/FirmwareBinaryHash.h
  • include/ota/FirmwareReleaseInfo.h
  • include/ota/OtaUpdateClient.h
  • src/http/FirmwareCDN.cpp
  • src/ota/OtaUpdateClient.cpp
  • src/ota/OtaUpdateManager.cpp

Have any feedback or feature suggestions? Share it here.

Please sign in to comment.