Skip to content

Commit

Permalink
Merge branch 'beta' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc committed Jan 20, 2024
2 parents c990044 + 4bd73ec commit efb9e2c
Show file tree
Hide file tree
Showing 16 changed files with 220 additions and 73 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Version 1.1.0-rc.4 Release Notes

Bugfixes:

- Make OTA update status reporting smoother.

# Version 1.1.0-rc.3 Release Notes

Bugfixes:

- Fixed updateID not being sent with BootStatus message.

# Version 1.1.0-rc.2 Release Notes

This is the RC (Release Candidate) 2 for version 1.1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export { CaptivePortalConfig } from './configuration/captive-portal-config';
export { Config } from './configuration/config';
export { OtaUpdateChannel } from './configuration/ota-update-channel';
export { OtaUpdateConfig } from './configuration/ota-update-config';
export { OtaUpdateStep } from './configuration/ota-update-step';
export { RFConfig } from './configuration/rfconfig';
export { SerialInputConfig } from './configuration/serial-input-config';
export { WiFiConfig } from './configuration/wi-fi-config';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import * as flatbuffers from 'flatbuffers';

import { OtaUpdateChannel } from '../../../open-shock/serialization/configuration/ota-update-channel';
import { FirmwareBootType } from '../../../open-shock/serialization/types/firmware-boot-type';
import { OtaUpdateStep } from '../../../open-shock/serialization/configuration/ota-update-step';


export class OtaUpdateConfig {
Expand Down Expand Up @@ -101,11 +101,11 @@ updateId():number {
}

/**
* Indicates what kind of firmware boot is happening (normal boot, booting into new firmware, rolling back to old firmware, etc.)
* Indicates what step of the update process the device is currently in, used to detect failed updates for status reporting.
*/
bootType():FirmwareBootType {
updateStep():OtaUpdateStep {
const offset = this.bb!.__offset(this.bb_pos, 22);
return offset ? this.bb!.readUint8(this.bb_pos + offset) : FirmwareBootType.Normal;
return offset ? this.bb!.readUint8(this.bb_pos + offset) : OtaUpdateStep.None;
}

static startOtaUpdateConfig(builder:flatbuffers.Builder) {
Expand Down Expand Up @@ -148,16 +148,16 @@ static addUpdateId(builder:flatbuffers.Builder, updateId:number) {
builder.addFieldInt32(8, updateId, 0);
}

static addBootType(builder:flatbuffers.Builder, bootType:FirmwareBootType) {
builder.addFieldInt8(9, bootType, FirmwareBootType.Normal);
static addUpdateStep(builder:flatbuffers.Builder, updateStep:OtaUpdateStep) {
builder.addFieldInt8(9, updateStep, OtaUpdateStep.None);
}

static endOtaUpdateConfig(builder:flatbuffers.Builder):flatbuffers.Offset {
const offset = builder.endObject();
return offset;
}

static createOtaUpdateConfig(builder:flatbuffers.Builder, isEnabled:boolean, cdnDomainOffset:flatbuffers.Offset, updateChannel:OtaUpdateChannel, checkOnStartup:boolean, checkPeriodically:boolean, checkInterval:number, allowBackendManagement:boolean, requireManualApproval:boolean, updateId:number, bootType:FirmwareBootType):flatbuffers.Offset {
static createOtaUpdateConfig(builder:flatbuffers.Builder, isEnabled:boolean, cdnDomainOffset:flatbuffers.Offset, updateChannel:OtaUpdateChannel, checkOnStartup:boolean, checkPeriodically:boolean, checkInterval:number, allowBackendManagement:boolean, requireManualApproval:boolean, updateId:number, updateStep:OtaUpdateStep):flatbuffers.Offset {
OtaUpdateConfig.startOtaUpdateConfig(builder);
OtaUpdateConfig.addIsEnabled(builder, isEnabled);
OtaUpdateConfig.addCdnDomain(builder, cdnDomainOffset);
Expand All @@ -168,7 +168,7 @@ static createOtaUpdateConfig(builder:flatbuffers.Builder, isEnabled:boolean, cdn
OtaUpdateConfig.addAllowBackendManagement(builder, allowBackendManagement);
OtaUpdateConfig.addRequireManualApproval(builder, requireManualApproval);
OtaUpdateConfig.addUpdateId(builder, updateId);
OtaUpdateConfig.addBootType(builder, bootType);
OtaUpdateConfig.addUpdateStep(builder, updateStep);
return OtaUpdateConfig.endOtaUpdateConfig(builder);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// automatically generated by the FlatBuffers compiler, do not modify

/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */

export enum OtaUpdateStep {
None = 0,
Updating = 1,
Updated = 2,
Validating = 3,
Validated = 4,
RollingBack = 5
}
3 changes: 3 additions & 0 deletions include/OtaUpdateManager.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "FirmwareBootType.h"
#include "OtaUpdateChannel.h"
#include "SemVer.h"
#include "StringView.h"
Expand All @@ -25,7 +26,9 @@ namespace OpenShock::OtaUpdateManager {

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

FirmwareBootType GetFirmwareBootType();
bool IsValidatingApp();

void InvalidateAndRollback();
void ValidateApp();
} // namespace OpenShock::OtaUpdateManager
44 changes: 44 additions & 0 deletions include/OtaUpdateStep.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

#include "serialization/_fbs/ConfigFile_generated.h"

#include <cstdint>
#include <cstring>

namespace OpenShock {
typedef OpenShock::Serialization::Configuration::OtaUpdateStep OtaUpdateStep;

inline bool TryParseOtaUpdateStep(OtaUpdateStep& channel, const char* str) {
if (strcasecmp(str, "none") == 0) {
channel = OtaUpdateStep::None;
return true;
}

if (strcasecmp(str, "updating") == 0) {
channel = OtaUpdateStep::Updating;
return true;
}

if (strcasecmp(str, "updated") == 0) {
channel = OtaUpdateStep::Updated;
return true;
}

if (strcasecmp(str, "validating") == 0) {
channel = OtaUpdateStep::Validating;
return true;
}

if (strcasecmp(str, "validated") == 0) {
channel = OtaUpdateStep::Validated;
return true;
}

if (strcasecmp(str, "rollingback") == 0) {
channel = OtaUpdateStep::RollingBack;
return true;
}

return false;
}
} // namespace OpenShock
4 changes: 2 additions & 2 deletions include/config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ namespace OpenShock::Config {

bool GetOtaUpdateId(std::int32_t& out);
bool SetOtaUpdateId(std::int32_t updateId);
bool GetOtaFirmwareBootType(FirmwareBootType& out);
bool SetOtaFirmwareBootType(FirmwareBootType bootType);
bool GetOtaUpdateStep(OtaUpdateStep& out);
bool SetOtaUpdateStep(OtaUpdateStep updateStep);

bool HasBackendAuthToken();
bool GetBackendAuthToken(std::string& out);
Expand Down
5 changes: 3 additions & 2 deletions include/config/OtaUpdateConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "config/ConfigBase.h"
#include "FirmwareBootType.h"
#include "OtaUpdateChannel.h"
#include "OtaUpdateStep.h"

#include <string>

Expand All @@ -19,7 +20,7 @@ namespace OpenShock::Config {
bool allowBackendManagement,
bool requireManualApproval,
std::int32_t updateId,
FirmwareBootType bootType
OtaUpdateStep updateStep
);

bool isEnabled;
Expand All @@ -31,7 +32,7 @@ namespace OpenShock::Config {
bool allowBackendManagement;
bool requireManualApproval;
std::int32_t updateId;
FirmwareBootType bootType;
OtaUpdateStep updateStep;

void ToDefault() override;

Expand Down
66 changes: 53 additions & 13 deletions include/serialization/_fbs/ConfigFile_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ static_assert(FLATBUFFERS_VERSION_MAJOR == 23 &&
FLATBUFFERS_VERSION_REVISION == 26,
"Non-compatible flatbuffers version included");

#include "FirmwareBootType_generated.h"

namespace OpenShock {
namespace Serialization {
namespace Configuration {
Expand Down Expand Up @@ -76,6 +74,48 @@ inline const char *EnumNameOtaUpdateChannel(OtaUpdateChannel e) {
return EnumNamesOtaUpdateChannel()[index];
}

enum class OtaUpdateStep : uint8_t {
None = 0,
Updating = 1,
Updated = 2,
Validating = 3,
Validated = 4,
RollingBack = 5,
MIN = None,
MAX = RollingBack
};

inline const OtaUpdateStep (&EnumValuesOtaUpdateStep())[6] {
static const OtaUpdateStep values[] = {
OtaUpdateStep::None,
OtaUpdateStep::Updating,
OtaUpdateStep::Updated,
OtaUpdateStep::Validating,
OtaUpdateStep::Validated,
OtaUpdateStep::RollingBack
};
return values;
}

inline const char * const *EnumNamesOtaUpdateStep() {
static const char * const names[7] = {
"None",
"Updating",
"Updated",
"Validating",
"Validated",
"RollingBack",
nullptr
};
return names;
}

inline const char *EnumNameOtaUpdateStep(OtaUpdateStep e) {
if (::flatbuffers::IsOutRange(e, OtaUpdateStep::None, OtaUpdateStep::RollingBack)) return "";
const size_t index = static_cast<size_t>(e);
return EnumNamesOtaUpdateStep()[index];
}

struct RFConfig FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
typedef RFConfigBuilder Builder;
struct Traits;
Expand Down Expand Up @@ -514,7 +554,7 @@ struct OtaUpdateConfig FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
VT_ALLOW_BACKEND_MANAGEMENT = 16,
VT_REQUIRE_MANUAL_APPROVAL = 18,
VT_UPDATE_ID = 20,
VT_BOOT_TYPE = 22
VT_UPDATE_STEP = 22
};
/// Indicates whether OTA updates are enabled.
bool is_enabled() const {
Expand Down Expand Up @@ -552,9 +592,9 @@ struct OtaUpdateConfig FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
int32_t update_id() const {
return GetField<int32_t>(VT_UPDATE_ID, 0);
}
/// Indicates what kind of firmware boot is happening (normal boot, booting into new firmware, rolling back to old firmware, etc.)
OpenShock::Serialization::Types::FirmwareBootType boot_type() const {
return static_cast<OpenShock::Serialization::Types::FirmwareBootType>(GetField<uint8_t>(VT_BOOT_TYPE, 0));
/// Indicates what step of the update process the device is currently in, used to detect failed updates for status reporting.
OpenShock::Serialization::Configuration::OtaUpdateStep update_step() const {
return static_cast<OpenShock::Serialization::Configuration::OtaUpdateStep>(GetField<uint8_t>(VT_UPDATE_STEP, 0));
}
bool Verify(::flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
Expand All @@ -568,7 +608,7 @@ struct OtaUpdateConfig FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
VerifyField<uint8_t>(verifier, VT_ALLOW_BACKEND_MANAGEMENT, 1) &&
VerifyField<uint8_t>(verifier, VT_REQUIRE_MANUAL_APPROVAL, 1) &&
VerifyField<int32_t>(verifier, VT_UPDATE_ID, 4) &&
VerifyField<uint8_t>(verifier, VT_BOOT_TYPE, 1) &&
VerifyField<uint8_t>(verifier, VT_UPDATE_STEP, 1) &&
verifier.EndTable();
}
};
Expand Down Expand Up @@ -604,8 +644,8 @@ struct OtaUpdateConfigBuilder {
void add_update_id(int32_t update_id) {
fbb_.AddElement<int32_t>(OtaUpdateConfig::VT_UPDATE_ID, update_id, 0);
}
void add_boot_type(OpenShock::Serialization::Types::FirmwareBootType boot_type) {
fbb_.AddElement<uint8_t>(OtaUpdateConfig::VT_BOOT_TYPE, static_cast<uint8_t>(boot_type), 0);
void add_update_step(OpenShock::Serialization::Configuration::OtaUpdateStep update_step) {
fbb_.AddElement<uint8_t>(OtaUpdateConfig::VT_UPDATE_STEP, static_cast<uint8_t>(update_step), 0);
}
explicit OtaUpdateConfigBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) {
Expand All @@ -629,12 +669,12 @@ inline ::flatbuffers::Offset<OtaUpdateConfig> CreateOtaUpdateConfig(
bool allow_backend_management = false,
bool require_manual_approval = false,
int32_t update_id = 0,
OpenShock::Serialization::Types::FirmwareBootType boot_type = OpenShock::Serialization::Types::FirmwareBootType::Normal) {
OpenShock::Serialization::Configuration::OtaUpdateStep update_step = OpenShock::Serialization::Configuration::OtaUpdateStep::None) {
OtaUpdateConfigBuilder builder_(_fbb);
builder_.add_update_id(update_id);
builder_.add_cdn_domain(cdn_domain);
builder_.add_check_interval(check_interval);
builder_.add_boot_type(boot_type);
builder_.add_update_step(update_step);
builder_.add_require_manual_approval(require_manual_approval);
builder_.add_allow_backend_management(allow_backend_management);
builder_.add_check_periodically(check_periodically);
Expand All @@ -660,7 +700,7 @@ inline ::flatbuffers::Offset<OtaUpdateConfig> CreateOtaUpdateConfigDirect(
bool allow_backend_management = false,
bool require_manual_approval = false,
int32_t update_id = 0,
OpenShock::Serialization::Types::FirmwareBootType boot_type = OpenShock::Serialization::Types::FirmwareBootType::Normal) {
OpenShock::Serialization::Configuration::OtaUpdateStep update_step = OpenShock::Serialization::Configuration::OtaUpdateStep::None) {
auto cdn_domain__ = cdn_domain ? _fbb.CreateString(cdn_domain) : 0;
return OpenShock::Serialization::Configuration::CreateOtaUpdateConfig(
_fbb,
Expand All @@ -673,7 +713,7 @@ inline ::flatbuffers::Offset<OtaUpdateConfig> CreateOtaUpdateConfigDirect(
allow_backend_management,
require_manual_approval,
update_id,
boot_type);
update_step);
}

struct Config FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
Expand Down
15 changes: 11 additions & 4 deletions schemas/ConfigFile.fbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
include "./Types/FirmwareBootType.fbs";

namespace OpenShock.Serialization.Configuration;

table RFConfig {
Expand Down Expand Up @@ -57,6 +55,15 @@ enum OtaUpdateChannel:uint8 {
Develop = 2
}

enum OtaUpdateStep:uint8 {
None = 0,
Updating = 1,
Updated = 2,
Validating = 3,
Validated = 4,
RollingBack = 5,
}

// Represents configuration for Over-The-Air (OTA) updates.
table OtaUpdateConfig {
/// Indicates whether OTA updates are enabled.
Expand Down Expand Up @@ -86,8 +93,8 @@ table OtaUpdateConfig {
/// Update process ID, used to track the update process server-side across reboots.
update_id:int32;

/// Indicates what kind of firmware boot is happening (normal boot, booting into new firmware, rolling back to old firmware, etc.)
boot_type:Types.FirmwareBootType;
/// Indicates what step of the update process the device is currently in, used to detect failed updates for status reporting.
update_step:OtaUpdateStep;
}

table Config {
Expand Down
13 changes: 10 additions & 3 deletions src/GatewayClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "config/Config.h"
#include "event_handlers/WebSocket.h"
#include "Logging.h"
#include "OtaUpdateManager.h"
#include "serialization/WSGateway.h"
#include "Time.h"
#include "util/CertificateUtils.h"
Expand Down Expand Up @@ -119,8 +120,8 @@ void GatewayClient::_sendBootStatus() {
return;
}

OpenShock::FirmwareBootType bootType;
if (!Config::GetOtaFirmwareBootType(bootType)) {
OpenShock::OtaUpdateStep updateStep;
if (!Config::GetOtaUpdateStep(updateStep)) {
ESP_LOGE(TAG, "Failed to get OTA firmware boot type");
return;
}
Expand All @@ -131,7 +132,13 @@ void GatewayClient::_sendBootStatus() {
return;
}

s_bootStatusSent = Serialization::Gateway::SerializeBootStatusMessage(updateId, bootType, version, [this](const std::uint8_t* data, std::size_t len) { return m_webSocket.sendBIN(data, len); });
s_bootStatusSent = Serialization::Gateway::SerializeBootStatusMessage(updateId, OtaUpdateManager::GetFirmwareBootType(), version, [this](const std::uint8_t* data, std::size_t len) { return m_webSocket.sendBIN(data, len); });

if (s_bootStatusSent && updateStep != OpenShock::OtaUpdateStep::None) {
if (!Config::SetOtaUpdateStep(OpenShock::OtaUpdateStep::None)) {
ESP_LOGE(TAG, "Failed to reset firmware boot type to normal");
}
}
}

void GatewayClient::_handleEvent(WStype_t type, std::uint8_t* payload, std::size_t length) {
Expand Down
Loading

0 comments on commit efb9e2c

Please sign in to comment.