40 std::string helpstring =
"\n";
46 helpstring.append(
info.name);
47 helpstring.push_back(
'(');
49 helpstring.push_back(
'.');
54 if(!handlerHelp.empty()){
55 helpstring.append(handlerHelp).append(
"\n");
59 helpstring +=
"No commands.";
61 helpstring +=
"cmd\tflags\tdescription\n\n";
63 if(cmd.helpstring !=
nullptr && cmd.cmd !=
nullptr){
64 helpstring += std::string(cmd.cmd);
67 if(cmd.flags & CMDFLAG_GET){
70 if(cmd.flags & CMDFLAG_SET){
73 if(cmd.flags & CMDFLAG_SETADR){
76 if(cmd.flags & CMDFLAG_GETADR){
79 if(cmd.flags & CMDFLAG_INFOSTRING){
82 if(cmd.flags & CMDFLAG_STR_ONLY){
85 if(cmd.flags & CMDFLAG_DEBUG){
88 helpstring.append(
" )\t").append(std::string(cmd.helpstring)).append(
"\n");
102 std::string helpstring =
"\nPrefix,Class ID, Class description\n";
115 helpstring += std::string(clshex);
118 helpstring.append(
info.name);
122 if(!handlerHelp.empty()){
123 helpstring.append(
": ").append(handlerHelp).append(
"\n");
129 helpstring +=
"No commands.";
131 helpstring +=
"Command name,CMD ID, Description, Flags\n";
133 if(cmd.helpstring !=
nullptr && cmd.cmd !=
nullptr){
135 std::snprintf(cmdhex,11,
"0x%lX",cmd.cmdId);
136 helpstring.append(cmd.cmd);
138 helpstring += std::string(cmdhex);
140 helpstring.append(cmd.helpstring);
142 if(cmd.flags & CMDFLAG_GET){
145 if(cmd.flags & CMDFLAG_SET){
148 if(cmd.flags & CMDFLAG_SETADR){
151 if(cmd.flags & CMDFLAG_GETADR){
154 if(cmd.flags & CMDFLAG_INFOSTRING){
157 if(cmd.flags & CMDFLAG_STR_ONLY){
158 helpstring+=
" (STR)";
160 if(cmd.flags & CMDFLAG_DEBUG){
161 helpstring+=
" (DEBUG)";
190 if(cmdItem.cmd == cmd && !(cmdItem.flags & ignoredFlags) && (
SystemCommands::debugMode || !(cmdItem.flags & CMDFLAG_DEBUG))){
203 if(cmdItem.cmdId ==
id && !(cmdItem.flags & ignoredFlags) && (
SystemCommands::debugMode || !(cmdItem.flags & CMDFLAG_DEBUG))){
226 replies.emplace_back(this->
getInfo().
id);
252 replies.emplace_back(command_p ? command_p->
flags : (int64_t)-1);
309 return cmdhandlerinfo->
clsname;
320 if(cls->getCommandHandlerID() == cmdhandlerID){
359 std::vector<CommandHandler*> reply;
363 reply.push_back(cls);
372 std::vector<CommandHandler*> reply;
376 reply.push_back(cls);
394 if(cmd.cmdId == cmdid && !(cmd.flags & ignoredFlags) && ((cmd.flags & requiredFlags) == requiredFlags) && (
SystemCommands::debugMode || !(cmd.flags & CMDFLAG_DEBUG))){
423 std::vector<CommandReply> replies = {reply};
435 if(interface ==
nullptr){
440 std::vector<CommandReply> replies = {reply};
451 std::string reply =
"[>!" +
string +
"\n]";
static uint16_t cdcSend(std::string *reply, uint8_t itf)
virtual std::string getHelpstring()
static bool logsEnabled()
static std::vector< CommandHandler * > getHandlersFromClassName(const char *name)
static std::vector< uint16_t > & getCommandHandlerIds()
virtual uint8_t getCommandHandlerInstance()
void registerCommand(const char *cmd, const ID cmdid, const char *help=nullptr, uint32_t flags=0)
static void logSerial(std::string string)
Send a log formatted sequence.
virtual void addCommandHandler()
std::vector< CmdHandlerCommanddef > registeredCommands
virtual CmdHandlerCommanddef * getCommandFromId(const uint32_t id, uint32_t ignoredFlags=0)
virtual void setCommandsEnabled(bool enable)
static void setLogsEnabled(bool enabled)
static const char * getClassNameFromId(const uint32_t id)
static bool isInHandlerList(CommandHandler *handler)
virtual bool hasCommands()
virtual uint16_t getCommandHandlerID()
virtual CommandStatus internalCommand(const ParsedCommand &cmd, std::vector< CommandReply > &replies)
void setInstance(uint8_t instance)
virtual const ClassIdentifier getInfo()=0
Command handlers always have class infos. Works well with ChoosableClass.
static CommandHandler * getHandlerFromClassName(const char *name, const uint8_t instance=0xFF)
CmdHandlerInfo cmdHandlerInfo
virtual ~CommandHandler()
static void logSerialDebug(std::string string)
Send a log formatted sequence if debug is on.
virtual CommandStatus command(const ParsedCommand &cmd, std::vector< CommandReply > &replies)
static CommandHandler * getHandlerFromHandlerId(const uint16_t cmdhandlerID)
void sendCommandReplyAsync(CommandReply reply, uint32_t cmdId, CMDtype type, CommandInterface *interface=nullptr)
virtual CmdHandlerCommanddef * getCommandFromName(const std::string &cmd, uint32_t ignoredFlags=0)
virtual std::string getCommandsHelpstring()
void broadcastCommandReply(CommandReply reply, uint32_t cmdId, CMDtype type)
virtual CmdHandlerInfo * getCommandHandlerInfo()
virtual void removeCommandHandler()
static CommandHandler * getHandlerFromId(const uint16_t id, const uint8_t instance=0xFF)
static std::vector< CommandHandler * > getHandlersFromId(const uint16_t id)
static uint32_t getClassIdFromName(const char *name)
CommandHandler(const char *clsname, uint16_t clsid, uint8_t instance=0)
static std::vector< CommandHandler * > & getCommandHandlers()
virtual bool isValidCommandId(uint32_t cmdid, uint32_t ignoredFlags=0, uint32_t requiredFlag=0)
virtual std::string getCsvHelpstring()
virtual void sendReplyAsync(std::vector< CommandReply > &reply, CommandHandler *handler, uint32_t cmdId, CMDtype type)
static void broadcastCommandReplyAsync(const std::vector< CommandReply > &reply, CommandHandler *handler, uint32_t cmdId, CMDtype type=CMDtype::get)
void addCallbackHandler(std::vector< C > &vec, C instance)
void removeCallbackHandler(std::vector< C > &vec, C instance)
uint16_t commandHandlerID