-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Clean up SerialInputHandler * Pass isAutomated to command handlers * Ignore non-printable characters in command * Implement custom SerialBuffer instead of std::string * Update formatting
- Loading branch information
Showing
26 changed files
with
1,272 additions
and
833 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#pragma once | ||
|
||
#include <string_view> | ||
#include <vector> | ||
|
||
namespace OpenShock::Serial { | ||
typedef void (*CommandHandler)(std::string_view arg, bool isAutomated); | ||
|
||
class CommandArgument { | ||
public: | ||
std::string_view name; | ||
std::string_view constraint; | ||
std::string_view exampleValue; | ||
std::vector<std::string_view> constraintExtensions; | ||
}; | ||
|
||
class CommandEntry { | ||
public: | ||
CommandEntry(std::string_view description, CommandHandler commandHandler); | ||
CommandEntry(std::string_view name, std::string_view description, CommandHandler commandHandler); | ||
|
||
inline std::string_view name() const { return m_name; } | ||
inline std::string_view description() const { return m_description; } | ||
inline const std::vector<CommandArgument>& arguments() const { return m_arguments; } | ||
inline const CommandHandler commandHandler() const { return m_commandHandler; } | ||
|
||
CommandArgument& addArgument(std::string_view name, std::string_view constraint, std::string_view exampleValue, std::vector<std::string_view> constraintExtensions = {}); | ||
|
||
private: | ||
std::string_view m_name; | ||
std::string_view m_description; | ||
std::vector<CommandArgument> m_arguments; | ||
CommandHandler m_commandHandler; | ||
}; | ||
|
||
class CommandGroup { | ||
public: | ||
CommandGroup() = default; | ||
CommandGroup(std::string_view name); | ||
CommandGroup(CommandGroup&& other) = default; | ||
CommandGroup(const CommandGroup& other) = default; | ||
CommandGroup& operator=(CommandGroup&& other) = default; | ||
CommandGroup& operator=(const CommandGroup& other) = default; | ||
|
||
inline std::string_view name() const { return m_name; } | ||
inline const std::vector<CommandEntry>& commands() const { return m_commands; } | ||
|
||
CommandEntry& addCommand(std::string_view description, CommandHandler commandHandler); | ||
CommandEntry& addCommand(std::string_view name, std::string_view description, CommandHandler commandHandler); | ||
|
||
private: | ||
std::string_view m_name; | ||
std::vector<CommandEntry> m_commands; | ||
}; | ||
} // namespace OpenShock::Serial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include "serial/command_handlers/index.h" | ||
|
||
#include "Logging.h" | ||
|
||
#include <Arduino.h> | ||
|
||
#define SERPR_SYS(format, ...) ::Serial.printf("$SYS$|" format "\n", ##__VA_ARGS__) | ||
#define SERPR_RESPONSE(format, ...) SERPR_SYS("Response|" format, ##__VA_ARGS__) | ||
#define SERPR_SUCCESS(format, ...) SERPR_SYS("Success|" format, ##__VA_ARGS__) | ||
#define SERPR_ERROR(format, ...) SERPR_SYS("Error|" format, ##__VA_ARGS__) | ||
|
||
using namespace std::string_view_literals; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#pragma once | ||
|
||
#include "serial/command_handlers/CommandEntry.h" | ||
|
||
#include <vector> | ||
|
||
namespace OpenShock::Serial::CommandHandlers { | ||
OpenShock::Serial::CommandGroup VersionHandler(); | ||
OpenShock::Serial::CommandGroup RestartHandler(); | ||
OpenShock::Serial::CommandGroup SysInfoHandler(); | ||
OpenShock::Serial::CommandGroup EchoHandler(); | ||
OpenShock::Serial::CommandGroup ValidGpiosHandler(); | ||
OpenShock::Serial::CommandGroup RfTxPinHandler(); | ||
OpenShock::Serial::CommandGroup ESStopPinHandler(); | ||
OpenShock::Serial::CommandGroup DomainHandler(); | ||
OpenShock::Serial::CommandGroup AuthTokenHandler(); | ||
OpenShock::Serial::CommandGroup LcgOverrideHandler(); | ||
OpenShock::Serial::CommandGroup HostnameHandler(); | ||
OpenShock::Serial::CommandGroup NetworksHandler(); | ||
OpenShock::Serial::CommandGroup KeepAliveHandler(); | ||
OpenShock::Serial::CommandGroup JsonConfigHandler(); | ||
OpenShock::Serial::CommandGroup RawConfigHandler(); | ||
OpenShock::Serial::CommandGroup RfTransmitHandler(); | ||
OpenShock::Serial::CommandGroup FactoryResetHandler(); | ||
|
||
inline std::vector<OpenShock::Serial::CommandGroup> AllCommandHandlers() { | ||
return { | ||
VersionHandler(), | ||
RestartHandler(), | ||
SysInfoHandler(), | ||
EchoHandler(), | ||
ValidGpiosHandler(), | ||
RfTxPinHandler(), | ||
ESStopPinHandler(), | ||
DomainHandler(), | ||
AuthTokenHandler(), | ||
LcgOverrideHandler(), | ||
HostnameHandler(), | ||
NetworksHandler(), | ||
KeepAliveHandler(), | ||
JsonConfigHandler(), | ||
RawConfigHandler(), | ||
RfTransmitHandler(), | ||
FactoryResetHandler(), | ||
}; | ||
} | ||
} // namespace OpenShock::Serial::CommandHandlers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.