![]() |
Open FFBoard
Open source force feedback firmware
|
#include <CommandHandler.h>
Public Member Functions | |
virtual const ClassType | getClassType () |
CommandHandler (const char *clsname, uint16_t clsid, uint8_t instance=0) | |
virtual | ~CommandHandler () |
virtual bool | hasCommands () |
virtual void | setCommandsEnabled (bool enable) |
virtual CommandStatus | command (const ParsedCommand &cmd, std::vector< CommandReply > &replies) |
void | registerCommands () |
virtual CommandStatus | internalCommand (const ParsedCommand &cmd, std::vector< CommandReply > &replies) |
virtual const ClassIdentifier | getInfo ()=0 |
Command handlers always have class infos. Works well with ChoosableClass. More... | |
virtual std::string | getHelpstring () |
virtual std::string | getCommandsHelpstring () |
virtual std::string | getCsvHelpstring () |
virtual uint8_t | getCommandHandlerInstance () |
void | broadcastCommandReply (CommandReply reply, uint32_t cmdId, CMDtype type) |
void | sendCommandReplyAsync (CommandReply reply, uint32_t cmdId, CMDtype type, CommandInterface *interface=nullptr) |
virtual uint16_t | getCommandHandlerID () |
virtual CmdHandlerInfo * | getCommandHandlerInfo () |
virtual bool | isValidCommandId (uint32_t cmdid, uint32_t ignoredFlags=0, uint32_t requiredFlag=0) |
virtual CmdHandlerCommanddef * | getCommandFromName (const std::string &cmd, uint32_t ignoredFlags=0) |
virtual CmdHandlerCommanddef * | getCommandFromId (const uint32_t id, uint32_t ignoredFlags=0) |
template<typename ID > | |
void | registerCommand (const char *cmd, const ID cmdid, const char *help=nullptr, uint32_t flags=0) |
Static Public Member Functions | |
static void | logSerial (std::string string) |
Send a log formatted sequence. More... | |
static void | logSerialDebug (std::string string) |
Send a log formatted sequence if debug is on. More... | |
static bool | logsEnabled () |
static void | setLogsEnabled (bool enabled) |
static uint32_t | getClassIdFromName (const char *name) |
static const char * | getClassNameFromId (const uint32_t id) |
static CommandHandler * | getHandlerFromHandlerId (const uint16_t cmdhandlerID) |
static CommandHandler * | getHandlerFromId (const uint16_t id, const uint8_t instance=0xFF) |
static CommandHandler * | getHandlerFromClassName (const char *name, const uint8_t instance=0xFF) |
static std::vector< CommandHandler * > | getHandlersFromClassName (const char *name) |
static std::vector< CommandHandler * > | getHandlersFromId (const uint16_t id) |
static bool | isInHandlerList (CommandHandler *handler) |
static std::string | getAllHelpstrings () |
static std::vector< CommandHandler * > & | getCommandHandlers () |
template<typename TVal > | |
static CommandStatus | handleGetSet (const ParsedCommand &cmd, std::vector< CommandReply > &replies, TVal &value) |
template<typename TVal , class cls , class cls1 > | |
static CommandStatus | handleGetSetFunc (const ParsedCommand &cmd, std::vector< CommandReply > &replies, TVal &value, void(cls1::*setfunc)(TVal), cls *obj) |
template<typename TVal , class cls , class cls1 , class cls2 > | |
static CommandStatus | handleGetFuncSetFunc (const ParsedCommand &cmd, std::vector< CommandReply > &replies, TVal(cls1::*getfunc)(), void(cls2::*setfunc)(TVal), cls *obj) |
template<typename TVal , class cls , class cls1 > | |
static CommandStatus | handleGetFuncSet (const ParsedCommand &cmd, std::vector< CommandReply > &replies, TVal &value, TVal(cls1::*getfunc)(), cls *obj) |
Static Public Attributes | |
static bool | logEnabled = true |
Protected Member Functions | |
void | setInstance (uint8_t instance) |
virtual void | addCommandHandler () |
virtual void | removeCommandHandler () |
Static Protected Member Functions | |
static std::vector< uint16_t > & | getCommandHandlerIds () |
Protected Attributes | |
bool | commandsEnabled = true |
std::vector< CmdHandlerCommanddef > | registeredCommands |
CmdHandlerInfo | cmdHandlerInfo |
Implements an interface for parsed command handlers.
Adds itself to a global vector of handlers that can be called from the main class when a command gets parsed.
For example motor drivers and button sources can implement this to easily get serial commands
Definition at line 128 of file CommandHandler.h.
CommandHandler::CommandHandler | ( | const char * | clsname, |
uint16_t | clsid, | ||
uint8_t | instance = 0 |
||
) |
clsname and clsid identify this class in commands additionally to the unique instance field which can be assigned at runtime
Definition at line 25 of file CommandHandler.cpp.
|
virtual |
Definition at line 30 of file CommandHandler.cpp.
|
protectedvirtual |
Registers a command handler in the global callback list and assigns a unique index number
Definition at line 490 of file CommandHandler.cpp.
void CommandHandler::broadcastCommandReply | ( | CommandReply | reply, |
uint32_t | cmdId, | ||
CMDtype | type | ||
) |
Broadcasts an unrequested reply to all command interfaces in the name of this class
[in] | reply | a command reply to be sent |
[in] | cmdId | the command id in which name to reply |
[in] | type | type of the command to create (normally get) |
Definition at line 422 of file CommandHandler.cpp.
|
virtual |
[in] | cmd | The parsed command to be executed. |
[out] | replies | A vector to return one or multiple reply objects into. Replies to the interface will be generated based on the reply objects. A string reply may not contain start, end and separation markers: [,],| Other characters are allowed. |
Reimplemented in Axis, CANPort_2B, EffectsCalculator, I2CPort, SerialFFB, ADS111X_AnalogSource, CanAnalogBase, CanBridge, CanButtons, CustomMain, EncoderBissC, EncoderLocal, EncoderSSI, FFBHIDMain, FFBoardMain, LocalAnalog, LocalButtons, MidiMain, MotorPWM, MtEncoderSPI, TMC4671, TMCDebugBridge, VescCAN, MotorSimplemotion, ODriveCAN, PCF8574Buttons, RmdMotorCAN, ShifterAnalog, and SPI_Buttons.
Definition at line 410 of file CommandHandler.cpp.
|
static |
|
static |
Searches cmd handlers and returns its class id if the classname matches To be used to convert from string commands to ids
Definition at line 290 of file CommandHandler.cpp.
|
static |
Returns a pointer to the name of a class corresponding to an id or nullptr if not found
Definition at line 304 of file CommandHandler.cpp.
|
inlinevirtual |
Type of this class. Mainclass, motordriver... Should be implemented by the parent class so it is not in the info struct
Reimplemented in SystemCommands, LocalButtons, Axis, CANPort_2B, EffectsCalculator, I2CPort, ADS111X_AnalogSource, FFBoardMain, LocalAnalog, PCF8574Buttons, ShifterAnalog, SPI_Buttons, and TMC4671.
Definition at line 138 of file CommandHandler.h.
|
virtual |
Returns the string name of a command from an ID Ignores commands that match ignoredFlags
Definition at line 201 of file CommandHandler.cpp.
|
virtual |
Returns the ID of a command from a string Ignores commands that match ignoredFlags
Definition at line 188 of file CommandHandler.cpp.
|
inlinevirtual |
Definition at line 166 of file CommandHandler.h.
|
inlinestaticprotected |
Definition at line 280 of file CommandHandler.h.
|
virtual |
Returns a pointer to this classes command handler info struct containing its name and ids
Definition at line 476 of file CommandHandler.cpp.
|
virtual |
Returns the instance number of this class
Definition at line 483 of file CommandHandler.cpp.
|
inlinestatic |
Definition at line 191 of file CommandHandler.h.
|
virtual |
Generates a readable list of all commands with help information Warning: Large string returned
Definition at line 39 of file CommandHandler.cpp.
|
virtual |
Generates a csv list of all commands with help information Warning: Large string returned
Definition at line 101 of file CommandHandler.cpp.
|
static |
Returns a command handler from a classname and instance numer or nullptr if not found
Definition at line 344 of file CommandHandler.cpp.
|
static |
Returns a command handler with a specific unique handler id or nullptr if not found
Definition at line 318 of file CommandHandler.cpp.
|
static |
Returns a command handler which matches the class id and instance number or nullptr if not found
Definition at line 330 of file CommandHandler.cpp.
|
static |
Returns all command handlers with a supplied classname
Definition at line 358 of file CommandHandler.cpp.
|
static |
Returns all command handlers with a supplied class id
Definition at line 371 of file CommandHandler.cpp.
|
virtual |
Returns a description of this class
Reimplemented in Axis, EffectsCalculator, ADS111X_AnalogSource, CanAnalogBase, CanBridge, CustomMain, EncoderLocal, EncoderSSI, FFBHIDMain, FFBoardMain, LocalAnalog, LocalButtons, MidiMain, MotorPWM, MotorSimplemotion, ODriveCAN, PCF8574Buttons, ShifterAnalog, SPI_Buttons, TMC4671, TMCDebugBridge, and VescCAN.
Definition at line 469 of file CommandHandler.cpp.
|
pure virtual |
Command handlers always have class infos. Works well with ChoosableClass.
Implemented in Axis, CANPort_2B, EffectsCalculator, I2CPort, SerialFFB, SystemCommands, ADS111X_AnalogSource, CanAnalogBase, CanButtons, CustomMain, EncoderBissC, EncoderLocal, EncoderSSI, FFBHIDExt, FFBJoystick, FFBoardMain, FFBWheel, LocalAnalog, LocalButtons, MidiMain, MotorPWM, MotorSimplemotion1, MotorSimplemotion2, MtEncoderSPI, ODriveCAN1, ODriveCAN2, PCF8574Buttons, RmdMotorCAN1, RmdMotorCAN2, ShifterAnalog, TMC4671, TMCDebugBridge, VESC_1, VESC_2, CanBridge, SPI_Buttons_1, SPI_Buttons_2, FFBHIDMain, MotorSimplemotion, ODriveCAN, and RmdMotorCAN.
|
inlinestatic |
Reads from a member function and writes to a variable
Definition at line 243 of file CommandHandler.h.
|
inlinestatic |
Reads from a member function and sets to a member function
Definition at line 229 of file CommandHandler.h.
|
inlinestatic |
Reads or writes a variable
Definition at line 201 of file CommandHandler.h.
|
inlinestatic |
Reads from a variable and passes set commands to a member callback
Definition at line 215 of file CommandHandler.h.
|
virtual |
Definition at line 268 of file CommandHandler.cpp.
|
virtual |
Some standard commands most classes will need
Reimplemented in SystemCommands.
Definition at line 221 of file CommandHandler.cpp.
|
static |
Returns true if a command handler pointer is in the list of active command handlers
Definition at line 385 of file CommandHandler.cpp.
|
virtual |
Returns true if the command id is valid for this command handler and does NOT contain ignoredFlags but contains all requiredFlags
Definition at line 392 of file CommandHandler.cpp.
|
static |
Definition at line 275 of file CommandHandler.cpp.
|
static |
Send a log formatted sequence.
Sends log info back via cdc. UNUSED
Definition at line 448 of file CommandHandler.cpp.
|
static |
Send a log formatted sequence if debug is on.
Sends log info back via cdc if debug mode is on
Definition at line 459 of file CommandHandler.cpp.
|
inline |
Registers a command for this command handler
[in] | cmd | string name of command for serial interface |
[in] | cmdid | id enum for command for HID |
[in] | help | help message displayed on serial interface |
[in] | flags | what access methods are available for a command (see CMDFLAG definitions) |
Definition at line 262 of file CommandHandler.h.
void CommandHandler::registerCommands | ( | ) |
Registers commonly used internal commands to identify a class
Definition at line 174 of file CommandHandler.cpp.
|
protectedvirtual |
Removes a class from the global callback list and frees its id
Definition at line 517 of file CommandHandler.cpp.
void CommandHandler::sendCommandReplyAsync | ( | CommandReply | reply, |
uint32_t | cmdId, | ||
CMDtype | type, | ||
CommandInterface * | interface = nullptr |
||
) |
Broadcasts an unrequested reply to a specific command interface in the name of this class
[in] | interface | Must be a valid interface pointer from a previously received command or nullptr (treated like a broadcast) |
[in] | reply | a command reply to be sent |
[in] | cmdId | the command id in which name to reply |
[in] | type | type of the command to create (normally get) |
Definition at line 434 of file CommandHandler.cpp.
|
virtual |
Definition at line 271 of file CommandHandler.cpp.
|
protected |
Changes the command handler instance number for addressing. Should only be called in the constructor
Definition at line 214 of file CommandHandler.cpp.
|
static |
Enables or disables logs sent by "logSerial"
Definition at line 282 of file CommandHandler.cpp.
|
protected |
Definition at line 288 of file CommandHandler.h.
|
protected |
Definition at line 276 of file CommandHandler.h.
|
static |
Definition at line 163 of file CommandHandler.h.
|
protected |
Definition at line 286 of file CommandHandler.h.