Skip to content

Commit caa18c0

Browse files
(#206): API version is now printed out, leveraged const for methods
1 parent 3acf4d6 commit caa18c0

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

Firmware/GPAD_API/GPAD_API/GPAD_HAL.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828

2929
using namespace gpad_hal;
3030

31-
GPAD_HAL gpadHal(SemanticVersion(0, 1, 0));
32-
3331
extern IPAddress myIP;
3432

3533
// Use Serial1 for UART communication
@@ -481,7 +479,8 @@ void interpretBuffer(char *buf, int rlen, Stream *serialport, PubSubClient *clie
481479
onInfoMsg[0] = '\0';
482480

483481
// Report API version
484-
strcat(onInfoMsg, gpadHal.getVersion().toString().c_str());
482+
strcat(onInfoMsg, "GPAD API Version: ");
483+
strcat(onInfoMsg, gpadApi.getVersion().toString().c_str());
485484
client->publish(publish_Ack_Topic, onInfoMsg);
486485
serialport->println(onInfoMsg);
487486
onInfoMsg[0] = '\0';
@@ -760,12 +759,12 @@ void annunciateAlarmLevel(Stream *serialport)
760759
}
761760
}
762761

763-
GPAD_HAL::GPAD_HAL(SemanticVersion version)
762+
GPAD_API::GPAD_API(SemanticVersion version)
764763
: version(version)
765764
{
766765
}
767766

768-
SemanticVersion &GPAD_HAL::getVersion()
767+
const SemanticVersion &GPAD_API::getVersion() const
769768
{
770769
return this->version;
771770
}
@@ -777,11 +776,13 @@ SemanticVersion::SemanticVersion(uint8_t major, uint8_t minor, uint8_t patch)
777776
{
778777
}
779778

780-
std::string SemanticVersion::toString()
779+
std::string SemanticVersion::toString() const
781780
{
782-
std::string versionString;
783-
784-
versionString.append("0.0.0");
781+
std::string versionString = std::to_string(this->major);
782+
versionString.push_back('.');
783+
versionString.append(std::to_string(this->minor));
784+
versionString.push_back('.');
785+
versionString.append(std::to_string(this->patch));
785786

786787
return versionString;
787788
}

Firmware/GPAD_API/GPAD_API/GPAD_HAL.h

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ extern HardwareSerial uartSerial1;
124124

125125
namespace gpad_hal
126126
{
127+
128+
static const uint8_t API_MAJOR_VERSION = 0;
129+
static const uint8_t API_MINOR_VERSION = 1;
130+
static const uint8_t API_PATCH_VERSION = 0;
131+
127132
enum class Command : char
128133
{
129134
MUTE = 's',
@@ -133,30 +138,42 @@ namespace gpad_hal
133138
INFO = 'i',
134139
};
135140

141+
/**
142+
* SemanticVersion stores a version following the "semantic versioning" convention
143+
* defined here: https://semver.org/
144+
*
145+
* In summary:
146+
* - Major version defines breaking an incompatible changes with different versions
147+
* - Minor version adds new functionality in a backwards capability
148+
* ie v2.4.1 and v2.5.1 are still compatible but v2.5.1 may have additional functionality
149+
* - Patch version simply addresses bugs with no new features again in a backwards
150+
* compatible way
151+
*/
136152
class SemanticVersion
137153
{
138154
public:
139155
SemanticVersion(uint8_t major, uint8_t minor, uint8_t patch);
140156

141-
std::string toString();
157+
std::string toString() const;
142158

143159
private:
144160
uint8_t major;
145161
uint8_t minor;
146162
uint8_t patch;
147163
};
148164

149-
class GPAD_HAL
165+
class GPAD_API
150166
{
151167
public:
152-
GPAD_HAL(SemanticVersion version);
168+
GPAD_API(SemanticVersion version);
153169

154-
SemanticVersion &getVersion();
170+
const SemanticVersion &getVersion() const;
155171

156172
private:
157-
SemanticVersion version;
173+
const SemanticVersion version;
158174
};
159175

176+
const GPAD_API gpadApi = GPAD_API(SemanticVersion(API_MAJOR_VERSION, API_MINOR_VERSION, API_PATCH_VERSION));
160177
}
161178

162179
// SPI Functions....

0 commit comments

Comments
 (0)