Skip to content

Commit

Permalink
Revert removed boolean telemetry constructor #143
Browse files Browse the repository at this point in the history
  • Loading branch information
MathewHDYT committed Aug 1, 2023
1 parent 9fc291f commit 5ff6a7f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ Telemetry::Telemetry() :
// Nothing to do
}

Telemetry::Telemetry(const char *key, bool val) :
m_type(DataType::TYPE_BOOL),
m_key(key),
m_value()
{
m_value.boolean = val;
}

Telemetry::Telemetry(const char *key, float value) :
m_type(DataType::TYPE_REAL),
m_key(key),
Expand All @@ -31,6 +39,10 @@ bool Telemetry::IsEmpty() const {
bool Telemetry::SerializeKeyValue(const JsonVariant &jsonObj) const {
if (m_key) {
switch (m_type) {
case DataType::TYPE_BOOL:
jsonObj[m_key] = m_value.boolean;
return true;
break;
case DataType::TYPE_INT:
jsonObj[m_key] = m_value.integer;
return true;
Expand All @@ -51,6 +63,9 @@ bool Telemetry::SerializeKeyValue(const JsonVariant &jsonObj) const {
}

switch (m_type) {
case DataType::TYPE_BOOL:
return jsonObj.set(m_value.boolean);
break;
case DataType::TYPE_INT:
return jsonObj.set(m_value.integer);
break;
Expand Down
7 changes: 7 additions & 0 deletions src/Telemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class Telemetry {
m_value.integer = value;
}

/// @brief Constructs telemetry record from boolean value
/// @param key Key of the key value pair we want to create
/// @param val Value of the key value pair we want to create
Telemetry(const char *key, bool val);

/// @brief Constructs telemetry record from float value
/// @param key Key of the key value pair we want to create
/// @param value Value of the key value pair we want to create
Expand All @@ -66,13 +71,15 @@ class Telemetry {
// Data container
union Data {
const char *str;
bool boolean;
int integer;
float real;
};

// Data type inside a container
enum class DataType: const uint8_t {
TYPE_NONE,
TYPE_BOOL,
TYPE_INT,
TYPE_REAL,
TYPE_STR
Expand Down

0 comments on commit 5ff6a7f

Please sign in to comment.