Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config improvements #140

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ static getSizePrefixedRootAsBackendConfig(bb:flatbuffers.ByteBuffer, obj?:Backen
return (obj || new BackendConfig()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
}

host():string|null
host(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
host(optionalEncoding?:any):string|Uint8Array|null {
/**
* Domain name of the backend server, e.g. "api.shocklink.net"
*/
domain():string|null
domain(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
domain(optionalEncoding?:any):string|Uint8Array|null {
const offset = this.bb!.__offset(this.bb_pos, 4);
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
}

/**
* Authentication token for the backend server
*/
authToken():string|null
authToken(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
authToken(optionalEncoding?:any):string|Uint8Array|null {
Expand All @@ -38,8 +44,8 @@ static startBackendConfig(builder:flatbuffers.Builder) {
builder.startObject(2);
}

static addHost(builder:flatbuffers.Builder, hostOffset:flatbuffers.Offset) {
builder.addFieldOffset(0, hostOffset, 0);
static addDomain(builder:flatbuffers.Builder, domainOffset:flatbuffers.Offset) {
builder.addFieldOffset(0, domainOffset, 0);
}

static addAuthToken(builder:flatbuffers.Builder, authTokenOffset:flatbuffers.Offset) {
Expand All @@ -51,9 +57,9 @@ static endBackendConfig(builder:flatbuffers.Builder):flatbuffers.Offset {
return offset;
}

static createBackendConfig(builder:flatbuffers.Builder, hostOffset:flatbuffers.Offset, authTokenOffset:flatbuffers.Offset):flatbuffers.Offset {
static createBackendConfig(builder:flatbuffers.Builder, domainOffset:flatbuffers.Offset, authTokenOffset:flatbuffers.Offset):flatbuffers.Offset {
BackendConfig.startBackendConfig(builder);
BackendConfig.addHost(builder, hostOffset);
BackendConfig.addDomain(builder, domainOffset);
BackendConfig.addAuthToken(builder, authTokenOffset);
return BackendConfig.endBackendConfig(builder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ static getSizePrefixedRootAsCaptivePortalConfig(bb:flatbuffers.ByteBuffer, obj?:
return (obj || new CaptivePortalConfig()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
}

/**
* Whether the captive portal is forced to be enabled
* The captive portal will otherwise shut down when a gateway connection is established
*/
alwaysEnabled():boolean {
const offset = this.bb!.__offset(this.bb_pos, 4);
return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,33 @@ static getSizePrefixedRootAsConfig(bb:flatbuffers.ByteBuffer, obj?:Config):Confi
return (obj || new Config()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
}

/**
* RF Transmitter configuration
*/
rf(obj?:RFConfig):RFConfig|null {
const offset = this.bb!.__offset(this.bb_pos, 4);
return offset ? (obj || new RFConfig()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
}

/**
* WiFi configuration
*/
wifi(obj?:WiFiConfig):WiFiConfig|null {
const offset = this.bb!.__offset(this.bb_pos, 6);
return offset ? (obj || new WiFiConfig()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
}

/**
* Captive portal configuration
*/
captivePortal(obj?:CaptivePortalConfig):CaptivePortalConfig|null {
const offset = this.bb!.__offset(this.bb_pos, 8);
return offset ? (obj || new CaptivePortalConfig()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
}

/**
* Backend configuration
*/
backend(obj?:BackendConfig):BackendConfig|null {
const offset = this.bb!.__offset(this.bb_pos, 10);
return offset ? (obj || new BackendConfig()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ static getSizePrefixedRootAsRFConfig(bb:flatbuffers.ByteBuffer, obj?:RFConfig):R
return (obj || new RFConfig()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
}

/**
* The GPIO pin connected to the RF modulator's data pin for transmitting (TX)
*/
txPin():number {
const offset = this.bb!.__offset(this.bb_pos, 4);
return offset ? this.bb!.readUint8(this.bb_pos + offset) : 0;
}

/**
* Whether to transmit keepalive messages to keep the devices from entering sleep mode
*/
keepaliveEnabled():boolean {
const offset = this.bb!.__offset(this.bb_pos, 6);
return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,29 @@ static getSizePrefixedRootAsWiFiConfig(bb:flatbuffers.ByteBuffer, obj?:WiFiConfi
return (obj || new WiFiConfig()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
}

/**
* Access point SSID
*/
apSsid():string|null
apSsid(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
apSsid(optionalEncoding?:any):string|Uint8Array|null {
const offset = this.bb!.__offset(this.bb_pos, 4);
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
}

/**
* Device hostname
*/
hostname():string|null
hostname(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
hostname(optionalEncoding?:any):string|Uint8Array|null {
const offset = this.bb!.__offset(this.bb_pos, 6);
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
}

/**
* WiFi network credentials
*/
credentials(index: number, obj?:WiFiCredentials):WiFiCredentials|null {
const offset = this.bb!.__offset(this.bb_pos, 8);
return offset ? (obj || new WiFiCredentials()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,27 @@ static getSizePrefixedRootAsWiFiCredentials(bb:flatbuffers.ByteBuffer, obj?:WiFi
return (obj || new WiFiCredentials()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
}

/**
* ID of the WiFi network credentials, used for referencing the credentials with a low memory footprint
*/
id():number {
const offset = this.bb!.__offset(this.bb_pos, 4);
return offset ? this.bb!.readUint8(this.bb_pos + offset) : 0;
}

/**
* SSID of the WiFi network
*/
ssid():string|null
ssid(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
ssid(optionalEncoding?:any):string|Uint8Array|null {
const offset = this.bb!.__offset(this.bb_pos, 6);
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
}

/**
* Password of the WiFi network
*/
password():string|null
password(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
password(optionalEncoding?:any):string|Uint8Array|null {
Expand Down
1 change: 1 addition & 0 deletions include/config/BackendConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace OpenShock::Config {
struct BackendConfig : public ConfigBase<Serialization::Configuration::BackendConfig> {
std::string domain;
std::string authToken;

void ToDefault() override;
Expand Down
40 changes: 28 additions & 12 deletions include/serialization/_fbs/ConfigFile_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ struct RFConfig FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
VT_TX_PIN = 4,
VT_KEEPALIVE_ENABLED = 6
};
/// The GPIO pin connected to the RF modulator's data pin for transmitting (TX)
uint8_t tx_pin() const {
return GetField<uint8_t>(VT_TX_PIN, 0);
}
/// Whether to transmit keepalive messages to keep the devices from entering sleep mode
bool keepalive_enabled() const {
return GetField<uint8_t>(VT_KEEPALIVE_ENABLED, 0) != 0;
}
Expand Down Expand Up @@ -106,12 +108,15 @@ struct WiFiCredentials FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
VT_SSID = 6,
VT_PASSWORD = 8
};
/// ID of the WiFi network credentials, used for referencing the credentials with a low memory footprint
uint8_t id() const {
return GetField<uint8_t>(VT_ID, 0);
}
/// SSID of the WiFi network
const ::flatbuffers::String *ssid() const {
return GetPointer<const ::flatbuffers::String *>(VT_SSID);
}
/// Password of the WiFi network
const ::flatbuffers::String *password() const {
return GetPointer<const ::flatbuffers::String *>(VT_PASSWORD);
}
Expand Down Expand Up @@ -192,12 +197,15 @@ struct WiFiConfig FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
VT_HOSTNAME = 6,
VT_CREDENTIALS = 8
};
/// Access point SSID
const ::flatbuffers::String *ap_ssid() const {
return GetPointer<const ::flatbuffers::String *>(VT_AP_SSID);
}
/// Device hostname
const ::flatbuffers::String *hostname() const {
return GetPointer<const ::flatbuffers::String *>(VT_HOSTNAME);
}
/// WiFi network credentials
const ::flatbuffers::Vector<::flatbuffers::Offset<OpenShock::Serialization::Configuration::WiFiCredentials>> *credentials() const {
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<OpenShock::Serialization::Configuration::WiFiCredentials>> *>(VT_CREDENTIALS);
}
Expand Down Expand Up @@ -279,6 +287,8 @@ struct CaptivePortalConfig FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Tabl
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_ALWAYS_ENABLED = 4
};
/// Whether the captive portal is forced to be enabled
/// The captive portal will otherwise shut down when a gateway connection is established
bool always_enabled() const {
return GetField<uint8_t>(VT_ALWAYS_ENABLED, 0) != 0;
}
Expand Down Expand Up @@ -327,19 +337,21 @@ struct BackendConfig FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
return "OpenShock.Serialization.Configuration.BackendConfig";
}
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_HOST = 4,
VT_DOMAIN = 4,
VT_AUTH_TOKEN = 6
};
const ::flatbuffers::String *host() const {
return GetPointer<const ::flatbuffers::String *>(VT_HOST);
/// Domain name of the backend server, e.g. "api.shocklink.net"
const ::flatbuffers::String *domain() const {
return GetPointer<const ::flatbuffers::String *>(VT_DOMAIN);
}
/// Authentication token for the backend server
const ::flatbuffers::String *auth_token() const {
return GetPointer<const ::flatbuffers::String *>(VT_AUTH_TOKEN);
}
bool Verify(::flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyOffset(verifier, VT_HOST) &&
verifier.VerifyString(host()) &&
VerifyOffset(verifier, VT_DOMAIN) &&
verifier.VerifyString(domain()) &&
VerifyOffset(verifier, VT_AUTH_TOKEN) &&
verifier.VerifyString(auth_token()) &&
verifier.EndTable();
Expand All @@ -350,8 +362,8 @@ struct BackendConfigBuilder {
typedef BackendConfig Table;
::flatbuffers::FlatBufferBuilder &fbb_;
::flatbuffers::uoffset_t start_;
void add_host(::flatbuffers::Offset<::flatbuffers::String> host) {
fbb_.AddOffset(BackendConfig::VT_HOST, host);
void add_domain(::flatbuffers::Offset<::flatbuffers::String> domain) {
fbb_.AddOffset(BackendConfig::VT_DOMAIN, domain);
}
void add_auth_token(::flatbuffers::Offset<::flatbuffers::String> auth_token) {
fbb_.AddOffset(BackendConfig::VT_AUTH_TOKEN, auth_token);
Expand All @@ -369,11 +381,11 @@ struct BackendConfigBuilder {

inline ::flatbuffers::Offset<BackendConfig> CreateBackendConfig(
::flatbuffers::FlatBufferBuilder &_fbb,
::flatbuffers::Offset<::flatbuffers::String> host = 0,
::flatbuffers::Offset<::flatbuffers::String> domain = 0,
::flatbuffers::Offset<::flatbuffers::String> auth_token = 0) {
BackendConfigBuilder builder_(_fbb);
builder_.add_auth_token(auth_token);
builder_.add_host(host);
builder_.add_domain(domain);
return builder_.Finish();
}

Expand All @@ -384,13 +396,13 @@ struct BackendConfig::Traits {

inline ::flatbuffers::Offset<BackendConfig> CreateBackendConfigDirect(
::flatbuffers::FlatBufferBuilder &_fbb,
const char *host = nullptr,
const char *domain = nullptr,
const char *auth_token = nullptr) {
auto host__ = host ? _fbb.CreateString(host) : 0;
auto domain__ = domain ? _fbb.CreateString(domain) : 0;
auto auth_token__ = auth_token ? _fbb.CreateString(auth_token) : 0;
return OpenShock::Serialization::Configuration::CreateBackendConfig(
_fbb,
host__,
domain__,
auth_token__);
}

Expand All @@ -406,15 +418,19 @@ struct Config FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
VT_CAPTIVE_PORTAL = 8,
VT_BACKEND = 10
};
/// RF Transmitter configuration
const OpenShock::Serialization::Configuration::RFConfig *rf() const {
return GetPointer<const OpenShock::Serialization::Configuration::RFConfig *>(VT_RF);
}
/// WiFi configuration
const OpenShock::Serialization::Configuration::WiFiConfig *wifi() const {
return GetPointer<const OpenShock::Serialization::Configuration::WiFiConfig *>(VT_WIFI);
}
/// Captive portal configuration
const OpenShock::Serialization::Configuration::CaptivePortalConfig *captive_portal() const {
return GetPointer<const OpenShock::Serialization::Configuration::CaptivePortalConfig *>(VT_CAPTIVE_PORTAL);
}
/// Backend configuration
const OpenShock::Serialization::Configuration::BackendConfig *backend() const {
return GetPointer<const OpenShock::Serialization::Configuration::BackendConfig *>(VT_BACKEND);
}
Expand Down
27 changes: 26 additions & 1 deletion schemas/ConfigFile.fbs
Original file line number Diff line number Diff line change
@@ -1,34 +1,59 @@
namespace OpenShock.Serialization.Configuration;

table RFConfig {
/// The GPIO pin connected to the RF modulator's data pin for transmitting (TX)
tx_pin:uint8;

/// Whether to transmit keepalive messages to keep the devices from entering sleep mode
keepalive_enabled:bool;
}

table WiFiCredentials {
/// ID of the WiFi network credentials, used for referencing the credentials with a low memory footprint
id:uint8;

/// SSID of the WiFi network
ssid:string;

/// Password of the WiFi network
password:string;
}

table WiFiConfig {
/// Access point SSID
ap_ssid:string;

/// Device hostname
hostname:string;

/// WiFi network credentials
credentials:[WiFiCredentials];
}

table CaptivePortalConfig {
/// Whether the captive portal is forced to be enabled
/// The captive portal will otherwise shut down when a gateway connection is established
always_enabled:bool;
}

table BackendConfig {
host:string;
/// Domain name of the backend server, e.g. "api.shocklink.net"
domain:string;

/// Authentication token for the backend server
auth_token:string;
}

table Config {
/// RF Transmitter configuration
rf:RFConfig;

/// WiFi configuration
wifi:WiFiConfig;

/// Captive portal configuration
captive_portal:CaptivePortalConfig;

/// Backend configuration
backend:BackendConfig;
}
Loading