diff --git a/Firmware/GPAD_API/GPAD_API/GPAD_HAL.cpp b/Firmware/GPAD_API/GPAD_API/GPAD_HAL.cpp index 0de718a..b82ebfb 100644 --- a/Firmware/GPAD_API/GPAD_API/GPAD_HAL.cpp +++ b/Firmware/GPAD_API/GPAD_API/GPAD_HAL.cpp @@ -26,6 +26,8 @@ #include "WiFiManagerOTA.h" #include "GPAD_menu.h" +using namespace gpad_hal; + extern IPAddress myIP; // Use Serial1 for UART communication @@ -424,24 +426,24 @@ void interpretBuffer(char *buf, int rlen, Stream *serialport, PubSubClient *clie printError(serialport); return; } - char C = buf[0]; + Command command = static_cast(buf[0]); serialport->print(F("Command: ")); - serialport->println(C); - switch (C) + serialport->println(F(command)); + switch (command) { - case 's': + case Command::MUTE: serialport->println(F("Muting Case!")); currentlyMuted = true; break; - case 'u': + case Command::UNMUTE: serialport->println(F("UnMuting Case!")); currentlyMuted = false; break; - case 'h': // help + case Command::HELP: // help printInstructions(serialport); break; - case 'a': + case Command::ALARM: { // In the case of an alarm state, the rest of the buffer is a message. // we will read up to 60 characters from this buffer for display on our @@ -462,7 +464,7 @@ void interpretBuffer(char *buf, int rlen, Stream *serialport, PubSubClient *clie break; } - case 'i': // Information. Firmware Version, Mute Status, + case Command::INFO: // Information. Firmware Version, Mute Status, { // Firmware Version // 81+23 = Maximum string length @@ -474,6 +476,14 @@ void interpretBuffer(char *buf, int rlen, Stream *serialport, PubSubClient *clie strcat(onInfoMsg, FIRMWARE_VERSION); client->publish(publish_Ack_Topic, onInfoMsg); serialport->println(onInfoMsg); + onInfoMsg[0] = '\0'; + + // Report API version + strcat(onInfoMsg, "GPAD API Version: "); + strcat(onInfoMsg, gpadApi.getVersion().toString().c_str()); + client->publish(publish_Ack_Topic, onInfoMsg); + serialport->println(onInfoMsg); + onInfoMsg[0] = '\0'; // Up time onInfoMsg[0] = '\0'; @@ -748,3 +758,31 @@ void annunciateAlarmLevel(Stream *serialport) playNotBusyLevel(currentLevel); } } + +GPAD_API::GPAD_API(SemanticVersion version) + : version(version) +{ +} + +const SemanticVersion &GPAD_API::getVersion() const +{ + return this->version; +} + +SemanticVersion::SemanticVersion(uint8_t major, uint8_t minor, uint8_t patch) + : major(major), + minor(minor), + patch(patch) +{ +} + +std::string SemanticVersion::toString() const +{ + std::string versionString = std::to_string(this->major); + versionString.push_back('.'); + versionString.append(std::to_string(this->minor)); + versionString.push_back('.'); + versionString.append(std::to_string(this->patch)); + + return versionString; +} \ No newline at end of file diff --git a/Firmware/GPAD_API/GPAD_API/GPAD_HAL.h b/Firmware/GPAD_API/GPAD_API/GPAD_HAL.h index d8baef2..aba0f8e 100644 --- a/Firmware/GPAD_API/GPAD_API/GPAD_HAL.h +++ b/Firmware/GPAD_API/GPAD_API/GPAD_HAL.h @@ -18,8 +18,8 @@ */ -#ifndef GPAD_HAL -#define GPAD_HAL 1 +#ifndef GPAD_HAL_H +#define GPAD_HAL_H #include // #include #include @@ -122,6 +122,60 @@ extern HardwareSerial uartSerial1; #define UART2_BAUD_RATE 9600 extern HardwareSerial uartSerial1; +namespace gpad_hal +{ + + static const uint8_t API_MAJOR_VERSION = 0; + static const uint8_t API_MINOR_VERSION = 1; + static const uint8_t API_PATCH_VERSION = 0; + + enum class Command : char + { + MUTE = 's', + UNMUTE = 'u', + HELP = 'h', + ALARM = 'a', + INFO = 'i', + }; + + /** + * SemanticVersion stores a version following the "semantic versioning" convention + * defined here: https://semver.org/ + * + * In summary: + * - Major version defines breaking an incompatible changes with different versions + * - Minor version adds new functionality in a backwards capability + * ie v2.4.1 and v2.5.1 are still compatible but v2.5.1 may have additional functionality + * - Patch version simply addresses bugs with no new features again in a backwards + * compatible way + */ + class SemanticVersion + { + public: + SemanticVersion(uint8_t major, uint8_t minor, uint8_t patch); + + std::string toString() const; + + private: + uint8_t major; + uint8_t minor; + uint8_t patch; + }; + + class GPAD_API + { + public: + GPAD_API(SemanticVersion version); + + const SemanticVersion &getVersion() const; + + private: + const SemanticVersion version; + }; + + const GPAD_API gpadApi = GPAD_API(SemanticVersion(API_MAJOR_VERSION, API_MINOR_VERSION, API_PATCH_VERSION)); +} + // SPI Functions.... void setup_spi(); void receive_byte(byte c); diff --git a/Firmware/GPAD_API/pre_extra_script.py b/Firmware/GPAD_API/pre_extra_script.py index e83baff..023a37e 100644 --- a/Firmware/GPAD_API/pre_extra_script.py +++ b/Firmware/GPAD_API/pre_extra_script.py @@ -3,7 +3,7 @@ cpp_defines = [ ("COMPANY_NAME", "PubInv "), # For the Broker ID for MQTT ("PROG_NAME", "GPAD_API "), # This program - ("FIRMWARE_VERSION", "0.46 "), # Initial Menu implementation + ("FIRMWARE_VERSION", "0.45 "), # Initial Menu implementation ("MODEL_NAME", "KRAKE_"), ("LICENSE", "GNU Affero General Public License, version 3 "), ("ORIGIN", "US"),