Skip to content
Open
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
54 changes: 46 additions & 8 deletions Firmware/GPAD_API/GPAD_API/GPAD_HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "WiFiManagerOTA.h"
#include "GPAD_menu.h"

using namespace gpad_hal;

extern IPAddress myIP;

// Use Serial1 for UART communication
Expand Down Expand Up @@ -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<Command>(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
Expand All @@ -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
Expand All @@ -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';
Expand Down Expand Up @@ -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;
}
58 changes: 56 additions & 2 deletions Firmware/GPAD_API/GPAD_API/GPAD_HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

*/

#ifndef GPAD_HAL
#define GPAD_HAL 1
#ifndef GPAD_HAL_H
#define GPAD_HAL_H
#include <Stream.h>
// #include <Arduino.h>
#include <PubSubClient.h>
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Firmware/GPAD_API/pre_extra_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down